akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

fn main() {
    let n: usize = util::get();
    let a: Vec<i64> = util::gets();

    let mut sum = 0;
    let mut pn = 0;
    for (i, &x) in a.iter().enumerate() {
        sum += x;
        if i % 2 == 0 {
            // positive
            if sum <= 0 {
                pn += 1 - sum;
                sum = 1;
            }
        } else {
            // negative
            if sum >= 0 {
                pn += sum + 1;
                sum = -1;
            }
        }
    }
    sum = 0;
    let mut np = 0;
    for (i, &x) in a.iter().enumerate() {
        sum += x;
        if i % 2 == 1 {
            // positive
            if sum <= 0 {
                np += 1 - sum;
                sum = 1;
            }
        } else {
            // negative
            if sum >= 0 {
                np += sum + 1;
                sum = -1;
            }
        }
    }
    println!("{}", min(np, pn));
}


Measured memory_bytes: 6396
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

//約数の列挙
vector<ll> divisor(ll n) {
	vector<ll> res;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}

//素因数分解
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> res;
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			++res[i];
			n = n / i;
		}
	}
	if (n != 1) {
		res[n] = 1;
	}
	return res;
}

signed main() {
	ll a, b;

	cin >> a >> b;

	ll cnt = 0;

	for (auto p1 : prime_factor(a)) {
		for (auto p2 : prime_factor(b)) {
			if (p1.first == p2.first) {
				cnt++;
			}
			else if (p1.first < p2.first) {
				break;
			}
		}
	}

	cout << cnt + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>s;
	if(s=="A") cout<<"T"<<endl;
	if(s=="T") cout<<"A"<<endl;
	if(s=="C") cout<<"G"<<endl;
	if(s=="G") cout<<"C"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                ArrayList<Integer> t = new ArrayList<Integer>();
                ArrayList<Integer> x = new ArrayList<Integer>();
                ArrayList<Integer> y = new ArrayList<Integer>();
                t.add(0);
                x.add(0);
                y.add(0);

                for(int i=1; i<=N; i++){
                        t.add(sc.nextInt());
                        x.add(sc.nextInt());
                        y.add(sc.nextInt());
                }

                boolean ch = true,ch2 = true;

                for(int i=1; i<=N; i++){
                        ch = (t.get(i)-t.get(i-1))%2
                                ==  (Math.abs(x.get(i) - x.get(i-1))
                                        + Math.abs(y.get(i) - y.get(i-1)))%2;
                        ch2 = (t.get(i)-t.get(i-1)) - (Math.abs(x.get(i) - x.get(i-1))
                                        + Math.abs(y.get(i) - y.get(i-1)))  >= 0;
                        if(!(ch&&ch2))break;
                }

                if(ch&&ch2)System.out.print("Yes");
                if(!(ch&&ch2))System.out.print("No");
        }
}


Measured memory_bytes: 95524
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int a,b;cin >>a>>b;
    string s;cin >>s;
    bool flg=true;
    for (int i = 0; i < a + b + 1; ++i) {
        if(i==a){
            if(s[i]!='-')flg=false;
        }
        else {
            if(s[i]=='-')flg=false;
        }
    }
    if(flg)puts("Yes");
    else puts("No");
}



Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;
void swap(int &a, int &b);

int main()
{
	int H[300], W[300];
	int count = 0;
	while (true)
	{
		cin >> H[count] >> W[count];
		if (H[count] == 0 && W[count] == 0)
			break;
		count++;
	}

	for (int i = 0; i < count; ++i)
	{
		for (int j = 0; j < H[i]; ++j)
		{
			for (int k = 0; k < W[i]; ++k)
			{
				if (j == 0 || j==H[i]-1 || k == 0 || k==W[i]-1)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N; cin >> N;
    vector<vector<pair<int, bool>>> T(N);
    for(int i = 0; i < N; ++i) {
        int A; cin >> A;
        while(A--) {
            int x;
            bool y;
            cin >> x >> y;
            T[i].emplace_back(--x, y);
        }
    }
    auto rec = [&](auto &&rec, int d, int mask) -> int {
        if(d == N) {
            for(int i = 0; i < N; ++i) {
                if(mask & (1 << i)) {
                    for(auto &t : T[i]) {
                        bool s = mask & (1 << t.first);
                        if(t.second ^ s) return 0;
                    }
                }
            }
            return __builtin_popcount(mask);
        }
        return max(rec(rec, d + 1, mask), rec(rec, d + 1, mask | (1 << d)));
    };
    cout << rec(rec, 0, 0) << '\n';
    return 0;
}


Measured memory_bytes: 256
num = int(input())
n= list(map(int,input().split()))
Alice = 0
Bob = 0

n = sorted(n, reverse=True)

f= n[::2]
s = n[1::2]

for i in range(len(f)):
    Alice += int(f[i])
    
for j in range(len(s)):
    Bob += int(s[j])
#print(n)
#print(Alice)
#print(Bob)
print(int(Alice)-int(Bob))



Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

def solve(S_A, S_B, S_C):
    deck = S_A
    
    while(True):
        card = deck.pop(0)
        if(card == "a"):
            deck = S_A
            if(len(deck)==0):
                print("A")
                break
        elif(card == "b"):
            deck = S_B
            if(len(deck)==0):
                print("B")
                break
        elif(card == "c"):
            deck = S_C
            if(len(deck)==0):
                print("C")
                break
    

if __name__ == '__main__':
    S_A = list(input())
    S_B = list(input())
    S_C = list(input())

    solve(S_A, S_B, S_C)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007

int main()
{
    int N, M;
    cin >> N >> M;

    set<int> s;
    int a;
    for (int i = 0; i < M; i++)
    {
        cin >> a;
        s.insert(a);
    }

    vector<int> dp(N + 1, 0);
    dp[0] = 1;
    if (s.count(1) > 0)
    {
        dp[1] = 0;
    }
    else
    {
        dp[1] = 1;
    }
    for (int i = 2; i <= N; i++)
    {
        if (s.count(i) > 0)
        {
            dp[i] = 0;
        }
        else
        {
            dp[i] = (dp[i - 2] + dp[i - 1]) % MOD;
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 5376
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e15 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int N = 2e5 + 5;

int Data[N], n;
map <pii, int> dp;

int go(int ind, int req, int n) {
	if((n-ind+2)/2 < req) return -INF;
	if(ind > n || req == 0 ) return 0;
	if(dp.count({ind,req})) return dp[{ind, req}];
	int temp1 = Data[ind] + go(ind+2, req-1, n);
	int temp2 = go(ind+1,req, n);
    return (dp[{ind, req}] = max(temp1, temp2));
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //  // freopen("output.txt", "w", stdout);
    // #endif
    cin >> n;
	for(int i = 1; i <= n; i++) cin >> Data[i];
	cout << go(1, n/2, n) << '\n';
}



Measured memory_bytes: 33304
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
struct T{
	ll dance,id;
	bool operator<(const T an)const{
		return dance!=an.dance?dance<an.dance:id>an.id;
	}
	bool operator>(const T an)const{
		return dance!=an.dance?dance>an.dance:id<an.id;
	}
	bool operator==(const T an)const{
		return dance==an.dance&&id==an.id;
	}
};
const ll INF=0xffffffffffff;
ll N,M,D[100000],P[100000];
ll tmpl[100000];//?????¨?????¨?????????
vector<T> ds;
ll cnt;
bool ok(ll X){//X??\????????§?????????
	cnt=0;
	queue<ll> q;
	rep(i,N){
		if(tmpl[i]==-1) q.push(1); 
		else if(tmpl[i]>=X){
			q.push(0);
			cnt++;
		}
		else q.push(INF);
	}
	while(q.size()!=1){
		ll a,b,c;
		a=q.front();
		q.pop();
		b=q.front();
		q.pop();
		c=q.front();
		q.pop();
		if(b>c) swap(b,c);
		if(a>c) swap(a,c);
		q.push(min(a+b,INF));
	}
	//cout<<X<<" "<<q.front()<<" "<<N-M<<endl;
	return q.front()<=N-X-cnt;
}


int main()
{
	cin>>N>>M;
	rep(i,M){
		cin>>D[i]>>P[i];
		P[i]--;
		ds.pb(T{D[i],i});
	}
	rep(i,N-M){
		cin>>D[M+i];
		ds.pb(T{D[M+i],M+i});
	}
	sort(ds.begin(),ds.end());
	//ds.erase(unique(ds.begin(),ds.end()),ds.end());
	rep(i,N){
		D[i]=lower_bound(ds.begin(),ds.end(),T{D[i],i})-ds.begin();
	}
	memset(tmpl,-1,sizeof(tmpl));
	rep(i,M){
		tmpl[P[i]]=D[i];
	}
	ll lb=0,ub=N;
	while(ub-lb>1){
		ll mid=(ub+lb)/2;
		if(ok(mid)) lb=mid;
		else ub=mid;
	}
	cout<<ds[lb].dance<<endl;
}

Measured memory_bytes: 7372
using System;
using System.Linq;

class Program {
  static int BinarySearch(int[] a, int key) {
    int left = 0;
    int right = a.Length;
    while (left < right) {
      int mid = (left + right) / 2;
      if (a[mid] == key) return 1;
      else if (key < a[mid]) right = mid;
      else left = mid + 1;
    }
    return 0;
  }

  static void Main() {
    Console.ReadLine();
    var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Console.ReadLine();
    int cnt = 0;
    foreach (var key in Console.ReadLine().Split().Select(int.Parse)) {
      cnt += BinarySearch(s, key);
    }
    Console.WriteLine(cnt);
  }
}


Measured memory_bytes: 30712
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n], succession = 0, max_succession = 0;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      succession++;
    } else {
      max_succession = max(max_succession, succession);
      succession = 0;
    }
  }
  max_succession = max(max_succession, succession);
  cout << max_succession + 1 << endl;
  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,k;

int main(){
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++) for(int j=0;j<=m;j++){
		if((n-i)*j+(m-j)*i==k){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>

#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define mer(i,m,n) for(int i=(m);i>(n);--i)

#define MOD 1000000007
//#define MOD 998244353
#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;



int main() {
	char S;
	cin >> S;
	if (isupper(S)) {
		cout << "A" << '\n';
	}
	else {
		cout << "a" << '\n';
	}
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    ll x,k,d;

    cin>>x>>k>>d;


    ll p = abs(x)/d;

    p = min(p,k);
    if(x>0)
    {
         x=x-p*d;
         k= k-p;
    }

    else
    {
        x = x + p*d;
        k = k -p;
    }


    if(k%2==0)
    {
        cout<<abs(x)<<endl;
    }

    else
    {
        cout<<min(abs(x+d),abs(x-d));
    }
}

Measured memory_bytes: 3180
n = int(input())
fs = [list(map(int, input().split())) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
res = -float('inf')
for i in range(1, 2**10):
    s = list(map(int, list(bin(i)[2:].rjust(10, '0'))))
    val = 0
    for f, p in zip(fs, ps):
        count = 0
        for a, b in zip(s, f):
            if a == 1 and b == 1:
                count += 1
        val += p[count]
    res = max(res, val)
print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, i;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> i;
    int ans = N - i + 1;
    cout << ans << endl;
}

Measured memory_bytes: 384
n, m, k = map(int, input().split())

MOD = 1000000007
def pow_mod(x, y):
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD
mod_inv = lambda x: pow_mod(x, MOD - 2)

a = 0
for i in range(1, n):
  a += (i * (n - i)) % MOD 
  a %= MOD
a *= (m * m) % MOD
a %= MOD

b = 0
for i in range(1, m):
  b += (i * (m - i)) % MOD 
  b %= MOD
b *= (n * n) % MOD
b %= MOD

w = (m * n - 2) % MOD
u = 1
v = 1
for i in range(1, k-1):
  u *= (w - i + 1)
  u %= MOD
  v *= i
  v %= MOD

ans = ((a + b) % MOD) 
ans *= u
ans %= MOD
ans *= mod_inv(v)
ans %= MOD


print(ans)

Measured memory_bytes: 3064
//
// Created by 吉川純平 on 2019-12-01.
//

#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
//using ull = unsigned long long;
#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  ll n;
  cin >> n;
  string str1,str2;
  set<string> s;
  vector<bool> ans;
  rep(i,n){
    cin >> str1 >> str2;
    if(str1 == "insert"){
      s.insert(str2);
    }else{
      if(s.count(str2)){
        ans.push_back(true);
      }else{
        ans.push_back(false);
      }
    }
  }
  for(auto itr : ans){
    if(itr){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 32616
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void)
{
	int n, k;
	cin >> n >> k;
	int ans = 0;
	ans = pow(n / k,3);
	if (k%2==0) {
	    ans += pow((n+k/2)/k, 3);
	}
	print(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

// dp[i+1][j] .. minimum const of state j by using a[0]..a[i]. j is the bit representation of state.
// dp[i+1][j | c[i]] = min(dp[i][j | c[i]], dp[i][j] + a[i])
ll dp[1005][5000]; // dp[i][j] ..

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;

  vector<int> a(M);
  vector<int> b(M); // the number of boxes
  vector<ll> c(M);
  rep(i, M) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) {
      int t;
      cin >> t;
      --t; // 0-indexed
      c[i] += 1LL << t;
    }
  }

  rep(i, M + 1) {
    rep(j, 1LL << N) {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;
  rep(i, M) {
    rep(j, 1LL << N) {
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);

      int nj = j | c[i];
      dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + a[i]);
    }
  }

  if (dp[M][(1LL << N) - 1] == INF) {
    cout << -1 << endl;
  } else {
    cout << dp[M][(1LL << N) - 1] << endl;
  }
}


Measured memory_bytes: 39168
W,H,N=map(int,input().split())
A=[[0 for i in range(W)] for j in range(H)]
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        for j in range(H):
            for k in range(0,x):
                A[j][k] = 1
    if a==2:
        for j in range(H):
            for k in range(x,W):
                A[j][k] = 1  
    if a==3:
        for j in range(0,y):
            for k in range(W):
                A[j][k] = 1
    if a==4:
        for j in range(y,H):
            for k in range(W):
                A[j][k] = 1 
print(W*H-sum(map(sum, A)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll mod = 998244353;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}
vector<ll> fact;
vector<ll> invfact;

void set_fact(int n){
    fact.resize(n+1, 1);
    invfact.resize(n+1, 1);
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    invfact[n] = modinv(fact[n]);
    for (int i = n-1; i >= 2; i--) {
        invfact[i] = invfact[i+1] * (i+1) % mod;
    }
    return;
}


int main() {
    int N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    
    int M = 1000000;
    vector<ll> A(N, 0);
    vector<ll> C(M+1, 0);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        C[A[i]]++;
    }
    
    set_fact(M+1);
    
    vector<ll> msum(M+1, 0);
    for (int i = 1; i <= M; i++) {
        for (ll j = i; j <= M; j += i) {
            msum[i] += C[j]*j;
        }
        msum[i] %= mod;
    }
    
    vector<ll> B(M+1, 1);
    for (int i = 2; i <= M; i++) {
        B[i] = (invfact[i] * fact[i-1] + mod -B[i]) % mod;
        for (int j = i*2; j <= M; j+=i) B[j] += B[i];
    }
    
    ll ans = 0;
    for (int i = 1; i <= M; i++) {
        ans += msum[i] * msum[i] % mod * B[i] % mod;
        ans %= mod;
    }
    
    for (int i = 0; i < N; i++) ans += mod - A[i] % mod;
    ans %= mod;
    cout << ans * invfact[2] % mod << endl;
    return 0;
}

Measured memory_bytes: 40832
import java.util.*;

import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	class P{
		int x;
		int y;
		public P(int x,int y){
			this.x=x;this.y=y;
		}
		@Override
		public boolean equals(Object obj) {
			if(!(obj instanceof P))return false;
			P p=(P)obj;
			return p.x==x && p.y==y;
		}
		@Override
		public String toString() {
			return "("+x+","+y+")";
		}
	}

	int[][] dr=new int[][]{{0,1},{1,0},{0,-1},{-1,0}};

	public void run() {
		while(true){
			int W=sc.nextInt(),H=sc.nextInt();
			if(W==0 && H==0)return;

			char[][] map=new char[H][W];
			for(int h=0;h<H;h++){
				map[h]=sc.next().toCharArray();
			}
			int wc=0,bc=0;

			smap:while(true){
				Queue<P> que=new LinkedList<P>();
				int c=0;
				sdot:for(int h=0;h<H;h++)for(int w=0;w<W;w++){
					if(map[h][w]=='.'){
						que.add(new P(w,h));
						map[h][w]='-';
						c++;
						break sdot;
					}
				}
				if(que.isEmpty())break smap;
				int color=0;
				while(!que.isEmpty()){
					P p=que.poll();

					for(int i=0;i<4;i++){
						int x=p.x+dr[i][0];
						int y=p.y+dr[i][1];
						if(0<=x&& x<W && 0<=y && y<H){
							switch(map[y][x]){
							case '.':
								map[y][x]='-';
								c++;
								que.add(new P(x,y));
								break;
							case 'B':
								if(color==2)color=-1;
								if(color==0)color=1;
								break;
							case 'W':
								if(color==1)color=-1;
								if(color==0)color=2;
								break;
							}
						}
					}
				}
				if(color==1)
					bc+=c;
				if(color==2)
					wc+=c;
			}
			ln(bc+" "+wc);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 29832
#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout<<(x)<<endl
typedef long long ll;
template<class T> inline void chmax(T& a, T b) {
  if (a < b) a = b;
}

template<class T> inline void chmin(T& a, T b) {
  if (a > b) a = b;
}
const int MOD = 1000000007;
const long long INF = 1LL << 60;
const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n; ll k;
  cin >> n >> k;
  
  for (int i = 0; i < n; ++i) {
    cin >> to[0][i];
    to[0][i]--;
  }
  for (int i = 0; i < D - 1; ++i) {
    for (int j = 0; j < n; ++j) {
      to[i+1][j] = to[i][to[i][j]];
    }
  }
  int v = 0;
  for (int i = D-1; i >= 0; --i) {
    ll l = 1LL<<i;
    if (l <= k) {
      v = to[i][v];
      k-= l;
    }
   
  }
  COUT(v+1);
  return 0;
}

Measured memory_bytes: 50532
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int x, a, b;
    cin >> x >> a >> b;

    if(abs(x-a) < abs(x-b)) cout << "A" << endl;
    else cout << "B" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

int main(){
  ll n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  ll f=min(a,min(b,min(c,min(d,e))));
  ll ans=((n+f-1)/f)+4;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
    string str, buf, operation, patch;
    istringstream strm;
    int q, a, b;

    getline(cin, str);
    getline(cin, buf);
    strm.str(buf);
    strm >> q;
    while (q--) {
        getline(cin, operation);
        strm.str(operation);
        strm.seekg(0);
        if (operation.compare(0, 7, "replace") == 0) {
            strm >> buf >> a >> b >> patch;
            str.replace(a, b - a + 1, patch);
        }
        else if (operation.compare(0, 7, "reverse") == 0) {
            strm >> buf >> a >> b;
            reverse(&str[a], &str[b+1]);
        }
        else if (operation.compare(0, 5, "print") == 0) {
            strm >> buf >> a >> b;
            cout << str.substr(a, b - a + 1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;


int main() {
int N; cin >> N;
VI a(N); rep(i,0,N) scanf("%d", &a[i]);

if (a[0] == 2) {
    cout << 1 << "\n";
    return 0;
}
if (!count(ALL(a), 2)){ // 2 が含まれないとき
    cout << -1 << "\n";
    return 0;
}

unordered_map<int, bool> app; // 押したボタンをtrue

app[1] = true;
int sub = a[0] - 1, cnt=1;
while(a[sub] != 2){
    if (app[a[sub]]) {
        cout << -1 << "\n";
        return 0;
    }
    app[a[sub]] = true;
    sub = a[sub] - 1;
    ++cnt;
}

cout << cnt + 1 << "\n";


return 0;
}

// 境界，出力文字列 チェック
// int は ± 2*10⁹.
// map[]は対数時間．unordered_map[]は一定時間．


Measured memory_bytes: 4772
# -*- coding: utf-8 -*-

mochi_list = []
N = int(input())

for i in range(N):
    d = int(input())
    mochi_list.append(d)

last_mochi = 101
count = 0

for mochi in sorted(mochi_list, reverse=True):
    if mochi < last_mochi:
        count += 1
    last_mochi = mochi

print(count)


Measured memory_bytes: 2940
#include <stdio.h>

int main(void){
    int height;
    int width;
    int not_zero=1;
    int i,j=0;


    while(not_zero){
        scanf("%d",&height);
        scanf("%d",&width);

        if(height==0&&width==0){
            not_zero=0;
        }

        for(j=0;j<width;j++){
            printf("#");
        }
        
        if(not_zero){
            printf("\n");
        }

        for(i=0;i<height-2;i++){
            printf("#");
            for(j=0;j<width-2;j++){
                printf(".");
            }
            printf("#\n");
        }

        for(j=0;j<width;j++){
            printf("#");
        }

        if(not_zero){
            printf("\n\n");
        }
    }

    return 0;
}


Measured memory_bytes: 2100
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[n-1] = 0
for i in range(n-2, -1, -1):
    if h[i] >= h[i+1]:
        dp[i] = dp[i+1] + 1
    else:
        dp[i] = 0
print(max(dp))

Measured memory_bytes: 14252
#include<stdio.h>

int main(void)
{
	int a, b, c;
	int tmp;

	scanf("%d %d %d", &a, &b, &c);

	tmp = a;
	a = b;
	b = tmp;

	tmp = a;
	a = c;
	c = tmp;

	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector <int>>;

int N,Q;
Graph G;

void dfs(int v, int p, vector<long long> &res) {
  if (p != -1) res[v] += res[p];
  for (auto e : G[v]) {
    if (e == p) continue;
    dfs(e, v, res);
  }
}

int main(){

  cin>>N>>Q;
  G.assign(N, vector<int>() );
  
  for(int i=0;i<N-1;i++){

    int a,b;
    cin>>a>>b;
    --a;--b;
    G[a].push_back(b);
    G[b].push_back(a);

  }
    
  vector<long long> val(N, 0);
  for (int i=0;i<Q;i++) {
    int p,x;
    cin>>p>>x;
    --p;
    val[p]+=x;
  }
  dfs(0,-1,val);
  for(auto v : val)cout<<v<<" ";
  cout<<endl;

}


Measured memory_bytes: 24320
n_squares = int(raw_input(""))
height_squares = map(int, raw_input("").split(' '))

def check(n_squares, height_squares):
  if n_squares <= 1:
    return "Yes"
  for i in range(0, len(height_squares) - 1):
    if height_squares[i] > height_squares[i + 1]:
      return "No"
  return "Yes"
  
m = 0
for i in range(0, len(height_squares)):
  tmp = height_squares[i] - 1
  if tmp >= m:
    m = tmp
    height_squares[i] = tmp
print check(n_squares, height_squares)



Measured memory_bytes: 11316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a*b;
  cout <<ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
//const ll mod=1e9+7;
const ll mod=998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

int main(){
  int n,s;
  cin >> n >> s;
  vector<ll> a(n);
  rep(i,n){ cin >> a[i]; }
  vector<vector<mint>> dp(3010, vector<mint>(3010,0));
  mint ans = 0;
  rep(i,n){ dp[i][0] = 1; }
  rep(i,n)rep(j,s+1){
    dp[i+1][j] += dp[i][j];
    if(a[i]<=j){
      dp[i+1][j] += dp[i][j-a[i]];
    }
    if(j==s){
      ans += dp[i+1][s]*(n-i);
      dp[i+1][s] = 0;
    }
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 71168
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n;
cin >> n;
int d[n];
for(int i=0;i<n;i++){
    cin >> d[i];
}
sort(d,d+n);
n=n/2;
cout << d[n]-d[n-1] << endl; 
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 640
from math import sqrt
a, b, c = map(int, input().split())
# a = sqrt(a)
# b = sqrt(b)
# c = sqrt(c)
d = c - a - b

# if (a + b) < c:
if d > 0 and d * d > 4 * a * b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){

    long long  cnt = 0;
    long long  t;

    while(1){
        cin>>t;
        if(t == 0) break;
        else cout<<"Case "<<cnt+1<<": "<<t;
        cout<<"\n";
        cnt++;
    }
    return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>
int main(){
	int a[101],sco,cnt,n,k,i,j,h;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;;i++){
		cnt=0;
		for(j=0;j<n;j++){
			if(a[j]>=i)++cnt;
			if(cnt>=i){
				sco=i;
				break;
			}
			else if(j==n-1){
				goto end;
			}
		}
	}
	end:
	printf("%d\n",sco);
	return 0;
}


Measured memory_bytes: 2108
using System;
using System.Text;
using System.Collections.Generic;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            var dic = new SortedDictionary<string, List<int>>();
            string input;
            while((input = Console.ReadLine()) != null) {
                var data = input.Split();
                if(!dic.ContainsKey(data[0])) {
                    dic.Add(data[0], new List<int>());
                }
                dic[data[0]].Add(int.Parse(data[1]));
            }
            var output = new StringBuilder();
            foreach (var item in dic) {
                Console.WriteLine(item.Key);
                item.Value.Sort();
                item.Value.ForEach(str => output.Append(" " + str));
                Console.WriteLine(output.ToString().Trim());
                output.Length = 0;
            }
        }
    }
}

Measured memory_bytes: 21516
#include<stdio.h>
int main(void){
	int a,b;
	int d,r;
	double f;
	
	scanf("%d %d",&a,&b);
	
	d=a/b;
	r=a%b;
	f=(double)a/b;
	
	printf("%d %d %f\n",d,r,f);
	
	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    cin >> N;

    vector<string> str(N);
    for (int i = 0; i < N; i++)
    {
        cin >> str[i];
    }

    unordered_map<string, ll> pattern;
    for (int i = 0; i < N; i++)
    {
        sort(str[i].begin(), str[i].end());
        if (pattern.count(str[i]))
        {
            pattern[str[i]] += 1;
        }
        else
        {
            pattern[str[i]] = 1;
        }
        // ans += pattern[str[i]] - 1;
    }

    ll ans = 0;
    for (auto itr = pattern.begin(); itr != pattern.end(); itr++)
    {
        if (itr->second > 1)
        {
            ll tmp = itr->second - 1;
            ans += (tmp * (tmp + 1)) / 2;
        }
    }

    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 17700
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;

unsigned nChoosek( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

#define __INIT_CC__ ios::sync_with_stdio(false); \
	cin.tie(0);

#ifdef __WIN32__
	char getchar_unlocked() {return getchar();}
#endif

#define FOR(_i,_n,_m) for(int (_i)=(_n),_t=(_m);_i<(_t);++(_i))
#define FORN(_i,_n,_m) for(int (_i)=(_n),_t=(_m);_i<=(_t);++(_i))
#define FORD(_i,_n,_m) for(int (_i)=(_n),_t=(_m);_i>=(_t);--(_i))
#define RESET(_a,_value) memset(_a,_value,sizeof(_a))
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define mp make_pair
#define SIZE(_a) (int)_a.size()
#define VSORT(_a) sort(_a.begin(),_a.end())
#define SSORT(_a,_val) sort(_a,_a+(_val))
#define ALL(_a) _a.begin(),_a.end()
#define mt make_tuple
#define _get(_tuple,_i) get<_i>(_tuple)
#define eb emplace_back
 
using namespace std;

using vi = vector<int>;
using ii = pair<int,int>;
using vii = vector<ii>;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll,ll>;
using vpll = vector<pll>;
using vll = vector<ll>;
using pdd = pair<double,double>;
using vpdd = vector<pdd>;
template <typename T> using uset = unordered_set<T>;
template <typename T> using umultiset = unordered_multiset<T>;
template <typename K, typename V> using umap = unordered_map<K, V>;
template <typename K, typename V> using umultimap = unordered_multimap<K, V>;

const int dr[] = { 1, 0,-1, 0, 1, 1,-1,-1};
const int dc[] = { 0, 1, 0,-1, 1,-1,-1, 1};
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const ll INFLL = 0x7FFFFFFFFFFFFFFFLL;
const double pi = acos(-1);

template <typename T> T take(queue<T> &O) {T tmp=O.front();O.pop();return tmp;}
template <typename T> T take(stack<T> &O) {T tmp=O.top();O.pop();return tmp;}
template <typename T> T take(priority_queue<T> &O) {T tmp=O.top();O.pop();return tmp;}
template <typename T>
inline bool inRange(const T& z, const T& a, const T& b){return a <= z && z <= b;}

void OPEN(const string& in = "input.txt", const string& out = "output.txt")
{
	freopen(in.c_str(), "r", stdin);
	freopen(out.c_str(), "w", stdout);
	return ;
}

//using sokokaleb's template v4.0

#define N 200005
bitset<N> ok[2];
int n, m;

int main(int argc, char** argv) {
	__INIT_CC__
	cin >> n >> m;
	FOR (i, 0, m) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		if (a == 0) {
			ok[0].set(b, 1);
		} else if (b == n - 1) {
			ok[1].set(a, 1);
		}
	}
	if ((ok[0] & ok[1]).count() > 0) {
		cout << "POSSIBLE\n";
	} else {
		cout << "IMPOSSIBLE\n";
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<ll> a(n+1);
    for(int i = 0; i < n; i++) {
        if (s[i]=='<'){
            a[i+1] = max(a[i+1], a[i]+1);
        }
    }

    for(int i = n; i >=0; i--) {
        if (s[i]=='>'){
            a[i] = max(a[i], a[i+1]+1);
        }
    }
    ll sum=0;
    for(int i = 0; i < n+1; i++) {
        sum += a[i];
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 7696
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int a;
  cin >> a;
  cout << a * (a * (a + 1) + 1) << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>

int n,*A;
int solve(int,int);
int main()
{
  int i,j,q,ans;
  int *m;

  scanf("%d",&n);
  A=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  
  scanf("%d",&q);
  m=(int *)malloc(sizeof(int)*q);
  for(i=0;i<q;i++) scanf("%d",&m[i]);

  for(i=0;i<q;i++)
    {
      ans=solve(0,m[i]);
      if(ans==1) printf("yes\n");
      else printf("no\n");
    }
  


  return 0;
}

int solve(int i,int m)
{
  int res1,res2;

  if(m==0) return 1;
  if(i>=n) return 0;

  res1=solve(i+1,m-A[i]);
  res2=solve(i+1,m);
  if(res1==1 || res2==1) return 1;
  

  return 0;

}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
int main(void){
    
    string s, result;
    cin >> s;
    
    for(int i=0; i<s.size(); i++) {
        string key = s.substr(i,1);
        if(key == "0") {
            result += "0";
        }
        else if(key == "1") {
            result += "1";
        }
        else {
            if(result.size()>0) result.pop_back();
        }
    }
    
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
A, B, K = map(int, input().split())

if A + K > B - K :
    for i in range(A, B + 1) :
        print(i)
else :
    for i in range(A, A + K) :
        print(i)
    for i in range(B - K + 1, B + 1) :
        print(i)

Measured memory_bytes: 38384
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, Y;
  cin >> N >> Y;

  for (int x = 0; x <= min(Y / 10000, N); x++) {
    for (int y = 0; y <= min((Y - 10000 * x) / 5000, N - x); y++) {
      int rest = Y - 10000 * x - 5000 * y;
      int z = rest / 1000;
      if (rest % 1000 == 0 && (x + y + z) == N) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Data
{
public:
    int r, w;
    bool operator<(const Data& d) const{
        return r < d.r;
    }
};

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<Data> d(n);
        int rSum = 0;
        int wSum = 0;
        for(int i=0; i<n; ++i){
            cin >> d[i].r >> d[i].w;
            rSum += d[i].r;
            wSum += d[i].w;
        }
        sort(d.rbegin(), d.rend());

        if(2 * d[0].r <= rSum){
            cout << (rSum + wSum) << endl;
            continue;
        }

        int t = 2 * d[0].r - rSum;
        vector<bool> dp(t+1, false);
        dp[0] = true;
        for(int i=1; i<n; ++i){
            for(int j=t; j>=d[i].w; --j){
                if(dp[j-d[i].w])
                    dp[j] = true;
            }
        }

        while(!dp[t])
            -- t;

        int ret = d[0].r * 2 + (wSum - t);
        cout << ret << endl;
    }
}

Measured memory_bytes: 1208
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    accu = [0]*(n+1)
    for i in range(n):
        accu[max(i-a[i], 0)] += 1
        accu[min(i+a[i]+1, n)] -= 1
    now = 0
    for i in range(n):
        now += accu[i]
        a[i] = now
    if sum(a)==n*n:
        break
print(*a)

Measured memory_bytes: 157244