akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
string ok="Yes";
string ng="No";
int main(){
    string s;
    string ret=ng;
    cin>>s;
    if(s[0]==s[1]&&s[1]==s[2])ret=ok;
    if(s[2]==s[3]&&s[1]==s[2])ret=ok;
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=603;
using namespace std;
int n,d1,d2,vis[N][N],f,now,cnt[16],
tx[N*4],ty[N*4],t;
void dfs(int x,int y,int v){
	if(x<0||x>=n||y<0||y>=n||
	(vis[x][y]>>f&1))return;
	vis[x][y]|=v<<f;
	for(int i=0;i<t;i++)
	dfs(x+tx[i],y+ty[i],v^2);
}
inline void sol(int d){
	t=0;
	for(int i=-n;i<n;i++)
	for(int j=-n;j<n;j++)
	if(i*i+j*j==d)
	tx[t]=i,ty[t++]=j;
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	dfs(i,j,1);
}
int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	n<<=1;
	sol(d1),f=2,sol(d2);
	for(int i=0,j;i<n;i++)
	for(j=0;j<n;j++)
	cnt[vis[i][j]]++;
	for(f=0;cnt[f]<n*n/4;f++);
	for(int i=0,j;i<n;i++)
	for(j=0;j<n;j++)
	if(now<n*n/4&&vis[i][j]==f)
	printf("%d %d\n",i,j),now++;
}

Measured memory_bytes: 19200
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0
for i in range(N):
    ans += min(A[i], B[i])
    A[i], B[i] = max(0, A[i] - B[i]), max(0, B[i] - A[i])
    ans += min(A[i + 1], B[i])
    A[i + 1], B[i] = max(0, A[i + 1] - B[i]), max(0, B[i] - A[i + 1])

print(ans)


Measured memory_bytes: 81892
#include <stdio.h>

int calcpos(char c) {
  switch (c) {
    case 'M':
      return 0;
    case 'A':
      return 1;
    case 'R':
      return 2;
    case 'C':
      return 3;
    case 'H':
      return 4;
  }

  return -1;
}

char S[15];

int main()
{
  int counts[5] = {0,0,0,0,0};
  int pos;

  int N;
  scanf("%d", &N);

  for (int i = 1; i <= N && !feof(stdin); ++i) {
    scanf("%s", S);

    pos = calcpos(S[0]);
    if (pos != -1) ++counts[pos];
  }

  long long res = 0;
  for (int i = 0; i <= 2; ++i) {
    for (int j = i + 1; j <= 3; ++j) {
      for (int x = j + 1; x <= 4; ++x) {
        res += (long long)counts[i] * (long long)counts[j] * (long long)counts[x];
      }
    }
  }

  printf("%lld", res);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
typedef long long ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ll n,a[100],sum=0;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < n; ++i)
		{
			for (int j = i+1; j < n; ++j)
			{
				sum+=a[i]*a[j];
			}
		}	
		cout<<sum;

   return 0;
}


Measured memory_bytes: 3620
S = input()
ans = len(S)
for i in range(26):
    s = chr(97+i)
    tmp = -1
    res = 0
    flg = False
    for j in range(len(S)):
        if S[j] == s:
            flg = True
            res = max(res, j-tmp-1)
            tmp = j
    if not flg:
        continue
    ans = min(ans, max(res, len(S)-tmp-1))
print(ans)



Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K,A,B;
    cin >> K >> A >> B;
    cout << (B/K!=(A-1)/K? "OK\n":"NG\n");
}

Measured memory_bytes: 3648
#include<stdio.h>

int main() {
  int N, K;
  char S[100000];
  char S0;
  int cont[100000];
  int count = 1;
  int count_stand;
  int max = 1;
  int i, j;
  int set_n = 0;

  scanf("%d %d", &N, &K);
  scanf("%s", S);
  S0 = S[0];

  for(i = 1; i < N; i++) {
    if(S[i] == S0) count++;
    else {
      cont[set_n] = count;
      count = 1;
      set_n++;
      S0 = S[i];
    }
  }
  cont[set_n] = count;

  //for(i = 0; i < set_n + K * 2 + 1; i++) printf("%d\n", cont[i]);

  for(i = 0; i < set_n + 1; i++) {
    count_stand = 0;
    if(i == 0 && S[0] == '0') {
      for(j = i; (j < i + K * 2 && j < set_n + 1); j++) {
        count_stand += cont[j];
      }
    } else if((S[0] == '0' && i % 2 != 0) || (S[0] == '1' && i % 2 == 0)) {
      for(j = i; (j < i + K * 2 + 1 && j < set_n + 1); j++) {
        count_stand += cont[j];
      }
    }
    if(count_stand > max) max = count_stand;
  }

  printf("%d\n", max);

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
int main() {
  ll N=0;cin>>N;
  ll VAL=0;cin>>VAL;
  vector<ll> dp(VAL+1);
  ll tmpWeight=0,tmpVal=0;cin>>tmpWeight;cin>>tmpVal;
  for(ll j=0;j<=VAL;j++) {
	if(tmpWeight>j)dp[j]=0;
    else dp[j]=tmpVal;
  }
  for(ll i=1;i<N;i++) {
    ll tmpWeight=0,tmpVal=0;cin>>tmpWeight;cin>>tmpVal;
    vector<ll> cmp;
  	for(ll j=0;j<=VAL;j++) {
      if(j-tmpWeight>=0) {
        cmp.push_back(max(dp[j-tmpWeight]+tmpVal,dp[j]));
      } else {
      	cmp.push_back(dp[j]);
      }
    }
    dp=cmp;
  }
  //for(ll i=0;i<N;i++){for(ll j=0;j<=VAL;j++)cout<<dp[i][j]<<" ";cout<<endl;}
  cout<<dp[VAL]<<endl;
  return 0;
}

Measured memory_bytes: 2896
#include <stdio.h>

int main(void){
  int x, i, f;
  int n1=1, n2=1;

  scanf("%d",&x);

  if(x==0 || x==1){
    printf("1\n");
  }

  if(x>=2){
  for(i=2;i<=x;i++){
    f = n1 + n2;
    n2 = n1;
    n1 = f;
      }
  printf("%d\n",f);
  }
  
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>
int main()
{
    int x,a,b,m,n;
    scanf("%d%d%d",&x,&a,&b);
    m=abs(x-a);
    n=abs(x-b);
    if(m<n)
        printf("A\n");
    else
        printf("B\n");
    return 0;

}


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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

int main() {
	fast();
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<bool>> black(h, vector<bool>(w, false));
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			char c;
			cin >> c;
			if (c == '#') {
				black[i][j] = true;
			}
		}
	}

	int powers[14];
	powers[0] = 1;
	for (int i = 1; i < 14; ++i) {
		powers[i] = powers[i-1] * 2;
	}

	int ans = 0;
	for (int i = 0; i < (1<<(h+w)); ++i) {
		vector<bool> bits(h+w, false);
		int copy = i;
		for (int j = h+w-1; j >= 0; --j) {
			if (powers[j] <= copy) {
				copy -= powers[j];
				bits[j] = true;
			}
		}
		vector<bool> rows(h), cols(w);
		for (int j = 0; j < h; ++j) {
			rows[j] = bits[j];
		}
		for (int j = 0; j < w; ++j) {
			cols[j] = bits[j+h];
		}
		int blacks = 0;
		for (int j = 0; j < h; ++j) {
			if (rows[j]) continue;
			for (int a = 0; a < w; ++a)
			{
				if (cols[a]) continue;
				if (black[j][a]) ++blacks;
			}
		}
		if (blacks == k) ++ans;
	}
	cout << ans << nl;
}

Measured memory_bytes: 3656
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

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

fn main(){
    let n: usize = read_as_vec()[0];
    let mut a: Vec<i64> = vec![];
    let mut ans = 0;
    for _ in 0..n{
        a.push(read_as_vec()[0]);
    }

    for i in 0..n-1{
        ans += a[i]/2;
        a[i] %= 2;
        if a[i] == 1 && a[i+1] > 0{
            a[i] = 0;
            a[i+1] -= 1;
            ans += 1;
        }
    }
    ans += a[n-1]/2;

    println!("{}", ans);
}


Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n,x;
  cin>>n>>x;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int d,g;
  g=abs(a[0]-x);
  rep(i,n){
    d=abs(a[i]-x);
    g=__gcd(d,g);
  }
  cout<<g<<endl;
}

Measured memory_bytes: 640
H,W=map(int,input().split())
L=[0]*H
for i in range(H):
    L[i]=list(input())

for i in range(H):
    for j in range(W):
        if(L[i][j]=="#"):
            f=1
            if(i>0):
                if(L[i-1][j]=="#" or L[i-1][j]=="$"):
                    L[i][j]="$"
                    L[i-1][j]="$"
                    f=0
            if(j>0):
                if(L[i][j-1]=="#" or L[i][j-1]=="$"):
                    L[i][j]="$"
                    L[i][j-1]="$"
                    f=0
            if(i<H-1):
                if(L[i+1][j]=="#" or L[i+1][j]=="$"):
                    L[i][j]="$"
                    L[i+1][j]="$"
                    f=0
            if(j<W-1):
                if(L[i][j+1]=="#" or L[i][j+1]=="$"):
                    L[i][j]="$"
                    L[i][j+1]="$"
                    f=0
            if(f==1):
                print("No")
                exit()
print("Yes")

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

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        A[i] = {a, i};
    }
    int ans = min_element(A.begin(), A.end()) - A.begin() + 1;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	map<char, vi> mp = {
		{'S', {}},
		{'H', {}},
		{'C', {}},
		{'D', {}}
	};
	vector<char> garas = {'S', 'H', 'C', 'D'};
	int n; cin >> n;
	REP(i,n) {
		char gara;
		int num;
		cin >> gara >> num;
		mp[gara].push_back(num);
	}
	for (char gara : garas) {
		sort(ALL(mp[gara]));
		int cur = 1;
		for (int existNum : mp[gara]) {
			while (true) {
				if (cur != existNum) {
					cout << gara << " " << cur << endl;
					++cur;
				} else {
					++cur;
					break;
				}
			}
		}
		if (cur <= 13) {
			FOR(i, cur, 13 + 1) {
				cout << gara << " " << i << endl;
			}
		}
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    long long a,b,c;
    scanf("%lld%lld%lld",&a,&b,&c);
    if(a+b>=c)
    {
        puts("No");
        return 0;
    }
    long long lhs=a*a-2*a*c+b*b-2*b*c+c*c;
    long long rhs=2*a*b;
    if(lhs>rhs) puts("Yes");
    else puts("No");
    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int t; cin >> t; for(int cs = 1; cs <= t; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

//input space ---> scanf("%[^\n]%*c",s);

ll dp[105][100005],w[100005],v[100005],n,m;

int main() {
	IOS
	cin >> n >> m;
	fori(i,1,n,1) {
		cin >> w[i] >> v[i];
	}
	fori(i,1,n,1) {
		fori(j,1,m,1) {
			if(j-w[i] >= 0) {
				dp[i][j] = max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
			} else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	cout << dp[n][m] << endl;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define LL long long
#define ULL unsigned long long

using namespace std;
struct Arm
{
    int x,y;
    bool operator <  (const Arm & rhs) const{
        return x<rhs.x;
    }
}arm[100010];
int n,m;
int dp[200020][2];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        dp[i][2]=dp[i][1]=i;

    for(int i=1;i<=m;i++){
        scanf("%d%d",&arm[i].x,&arm[i].y);
    }
    sort(arm+1,arm+1+m);
    for(int i=1;i<=m;i++){
            int y=arm[i].y;
            dp[y][2]=dp[y+1][2];
            dp[y+1][1]=dp[y][1];
    }
    for(int i=1;i<=n;i++)
        if(i!=n)
            printf("%d ",dp[i][2]-dp[i][1]+1);
        else
            printf("%d\n",dp[i][2]-dp[i][1]+1);
    return 0;
}

Measured memory_bytes: 5612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  char X;
  char Y;
  cin >> X >> Y;
  if (X<Y) cout << "<" << endl;
  else if (X>Y) cout << ">" << endl;
  else if (X==Y) cout << "=" << endl;
}


Measured memory_bytes: 256
// Problem C
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct Node{
	bool leaf;
	vector<Node*> ch;
	int data;
	Node* par;
	Node(){
		data = 0;
		leaf = false;
		par = NULL;
	}
};

int dfs(Node* node){
	if(node->leaf)return node->data / 2 + 1;
	vector<int> vec;
	for(int i=0;i<node->ch.size();i++){
		vec.push_back(dfs(node->ch[i]));
	}
	sort(vec.begin(),vec.end());
	return accumulate(vec.begin(),vec.begin()+(vec.size()/2+1),0);
}

void debug(Node* node,int d){
	cout << d << " ";
	if(node->leaf){
		cout << node->data << endl;
	}
	for(int i=0;i<node->ch.size();i++){
		debug(node->ch[i],d+1);
	}
	return;
}

int main(void){
	int T;cin >> T;
	for(int i=0;i<T;i++){
		string s;
		cin >> s;
		Node* root = new Node();
		Node* now = root;

		for(int i=0;i<s.size();i++){
			if(s[i] == '['){
				Node* node = new Node();
				now->ch.push_back(node);
				node->leaf = false;
				node->par = now;
				now = node;
			}else if(isdigit(s[i])){
				string t;t += s[i];
				now->leaf = true;
				while(isdigit(s[i+1])){
					i++;
					t += s[i];
				}
				now->data = stoi(t);
			}else{
				now = now->par;
			}
		}
		cout << dfs(root) << endl;
	// debug(root,0);
	}
	return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#define int long long
using namespace std;

int l, r;

signed main() {
    cin >> l >> r;
    if(l > r) swap(l, r);
    if(r - l > 2019) {
        cout << 0;
        return 0;
    }   
    int ans = 1000000;
    for(int i = l; i <= r; ++i) {
        for(int j = i + 1; j <= r; ++j) {
            ans = min((i % 2019) * (j % 2019) % 2019, ans);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int N, M, A[50], B[50], count = 0;
bool G[50][50], visited[50];

void DFS(int v) {
	visited[v] = true;
	for (int v2 = 0; v2 < N; v2++) {
		if (!G[v][v2] || visited[v2]) continue;
		DFS(v2);
	}
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		A[i]--, B[i]--;
		G[A[i]][B[i]] = true;
		G[B[i]][A[i]] = true;
	}
	int ans = 0;
	for (int i = 0; i < M; i++) {
		G[A[i]][B[i]] = false;
		G[B[i]][A[i]] = false;
		bool check = false;
		for (int j = 0; j < N; j++) {
			visited[j] = false;
		}
		DFS(0);
		for (int j = 0; j < N; j++) {
			if (!visited[j]) check = true;
		}
		if (check) ans++;
		G[A[i]][B[i]] = true;
		G[B[i]][A[i]] = true;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, -1, 0, 1 };
struct state{
	int x;
	int y;
	int way;
	int cost;
	bool operator<(const state &right) const{
		return cost != right.cost ? cost > right.cost : x != right.x ? x < right.x : y != right.y ? y < right.y : way<right.way;
	}
};
int main() {
	int w, h;
	while (cin >> w >> h, w){
		vector<vector<int>> cell(h, vector<int>(w));
		REP(i, h){
			REP(j, w){
				cin >> cell[i][j];
			}
		}
		int com[4];
		REP(i, 4)
			cin >> com[i];
		vector<vector<vector<int>>> memo(h, vector<vector<int>>(w,vector<int>(4,100000)));
		memo[0][0][2] = 0;
		priority_queue<state> Q;
		Q.push({0,0,2,0});
		int ans=-1;
		while (!Q.empty()){
			state q = Q.top(); Q.pop();
			if (q.x == w - 1 && q.y == h - 1){
				ans = q.cost;
				break;
			}
			
			REP(i,4){
				if (0 <= q.x + dx[(q.way + i) % 4] && q.x + dx[(q.way + i) % 4] < w && 0 <= q.y + dy[(q.way + i) % 4] && q.y + dy[(q.way + i) % 4] < h)
						if (memo[q.y + dy[(q.way + i) % 4]][q.x + dx[(q.way + i) % 4]][(q.way + i) % 4] > q.cost + (i == cell[q.y][q.x] ? 0 : com[i])){
							memo[q.y + dy[(q.way + i) % 4]][q.x + dx[(q.way + i) % 4]][(q.way + i) % 4] = q.cost + (i == cell[q.y][q.x] ? 0 : com[i]);
							Q.push({ q.x + dx[(q.way + i) % 4], q.y + dy[(q.way + i) % 4], (q.way + i) % 4, q.cost + (i == cell[q.y][q.x] ? 0 : com[i]) });
						}
			}
		}
		cout << ans << endl;
	}
}

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

int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};

int main(){
  int n,pos,d;
  int x[250],y[250];
  int MN,mS,ME,mW;
  while(1){

    cin >> n;
    if(n == 0)break;

      x[0]= y[0] = 0;

    MN = ME = mS = mW = 0;

    for( int i = 1 ; i < n ; i++ ){
 
      cin >> pos >> d;

      x[i] = x[pos] + dx[d];
      y[i] = y[pos] + dy[d];

      MN = max(y[i],MN);
      ME = max(x[i],ME);
      mW = min(x[i],mW);
      mS = min(y[i],mS);
      // cout <<"i: " << i << " x: "<<x[i] << " " <<" y: "<< y[i] << endl;
       }
    cout <<ME-mW+1  << " "<< MN-mS+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
using namespace std;
int main()
{
	int x,y;
	for(;;){
	cin>>x>>y;
	if(x==0&&y==0){
		break;
	}
	if(x<y){
		cout<<x<<" "<<y<<endl;
	}
	else if(x>y){
		cout<<y<<" "<<x<<endl;
	}else {cout<<x<<" "<<y<<endl;}
	}
	return 0;
}



Measured memory_bytes: 2984
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
A = A[::-1]
hyou = sum(A)
# print(A, hyou)
ok = True
if float(A[M-1]) < hyou/(4*M):
    ok = False
# print(A[M-1], hyou/4)
if ok:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
		}
		selectionSort(c);
		in.close();
	}

	private static void selectionSort(int[] A) {
		int minj;
		int wk;
		int count = 0;
		for (int i = 0; i < A.length; i++) {
			minj = i;
			for (int j = i; j < A.length; j++) {
				if (A[j] < A[minj]) {

					minj = j;

				}

			}
			if(minj!=i) {
				wk=A[minj];
				A[minj]=A[i];
				A[i]=wk;
				count+=1;
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < A.length; i++) {
			if (i > 0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		}
		System.out.println(sb.toString());
		System.out.println(count);
	}

}



Measured memory_bytes: 26292
//Sameer's Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define MOD 1000000007
#define pb push_back
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w", stdout);
#endif
	{
		ll n;
		cin >> n;
		int ans = 0;
		for (int i = 1; i < n; i++) {
			for (int j = 1; i * j < n; j++) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0) return false;
    if(n % 3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n % 6 != 1 && n % 6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // 6n-1
        if(n % (i+2) == 0) return false; // 6n+1
    }

    return true;
}
int main(){
    int n; cin >> n;
    int num=0;
    for(int i=2;i<=55555;i++){
        if(i%5!=1) continue;
        if(is_prime(i)){
            cout << i << " ";
            num++;
        }
        if(num==n) return 0;
    }
    
    
}


Measured memory_bytes: 256
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable LIM = 2 * 10^^5 + 10;
immutable MO = 10L^^9 + 7;

long[] inv, fac, invFac;
void prepare() {
  inv = new long[LIM];
  fac = new long[LIM];
  invFac = new long[LIM];
  inv[1] = 1;
  foreach (i; 2 .. LIM) {
    inv[i] = MO - (MO / i) * inv[cast(size_t)(MO % i)] % MO;
  }
  fac[0] = invFac[0] = 1;
  foreach (i; 1 .. LIM) {
    fac[i] = fac[i - 1] * i % MO;
    invFac[i] = invFac[i - 1] * inv[i] % MO;
  }
}


alias Point = Tuple!(int, "x", int, "y");

int H, W;
int N;
Point[] P;

long calc(in Point p, in Point q) {
  const dx = q.x - p.x;
  const dy = q.y - p.y;
  if (dx >= 0 && dy >= 0) {
    return fac[dx + dy] * invFac[dx] % MO * invFac[dy] % MO;
  } else {
    return 0;
  }
}

void main() {
  prepare();
  
  try {
    for (; ; ) {
      H = readInt();
      W = readInt();
      N = readInt();
      P = new Point[N];
      foreach (i; 0 .. N) {
        P[i].x = readInt();
        P[i].y = readInt();
      }
      P.sort();
      P ~= Point(H, W);
      auto dp = new long[N + 1];
      foreach (i; 0 .. N + 1) {
        dp[i] = calc(Point(1, 1), P[i]);
        foreach (j; 0 .. i) {
          (dp[i] -= dp[j] * calc(P[j], P[i])) %= MO;
        }
      }
      auto ans = dp[N];
      ans = (ans % MO + MO) % MO;
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 7420
import collections

def main():
    n = int(input())
    dd=collections.defaultdict(int)
    for i in range(1,n+1):
        dd[i*360]+=1
    for i in range(360*(n+1)):
        if(dd[n*i]>0):
            print(i)
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9468
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		if(s[1]>(s[0]-1)*(s[0]-2)/2){
			Console.WriteLine("{0}",-1);
			return;
		}
		int p=s[0]-1,m=(s[0]-1)*(s[0]-2)/2;
		StringBuilder sb=new StringBuilder();
		for(int i = 2;i<=s[0];i++) {
			sb.Append("1 "+i+"\n");
		}
		for(int i = 2;i<s[0]&&m>s[1];i++) {
			for(int j = i+1;j<=s[0]&&m>s[1];j++) {
				sb.Append(i+" "+j+"\n");
				p++;
				m--;
			}
		}
		Console.WriteLine("{0}",p);
		Console.Write(sb);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


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

int main(){
  int n;
  int a;
  vector<int> d;
  int count=1;
  
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    d.push_back(a);
  }
  
  sort(d.begin(),d.end());
  
  for(int i=0;i<n-1;i++){
    if(d[i]<d[i+1]) count++;
  }
  
  cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    Set<String> set = new HashSet<String>();
    for(int i = 0; i<N; i++){
      set.add(sc.next());
    }
    System.out.println(set.size());
    return;
  }
}



Measured memory_bytes: 76928
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
int a,b,c,ans;
int main()
{
	cin>>a>>b>>c;
	ans=a*100+b*10+c;
	if(ans%4==0)
		cout<<"YES\n";
	else
		cout<<"NO\n";

	
	


	
	
    return 0;
 
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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; }

int main(){
  int h,w; cin >> h >> w;
  char a;
  int cnt = 0;
  rep(i,h) rep(j,w){ cin >> a; if(a=='#') cnt++; }
  cout << (cnt == h+w-1 ? "Possible" : "Impossible");
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3608
$n, $m, $q = gets.chomp.split(' ').collect! { |tmp| tmp.to_i }
$data = Array.new
for i in 1..$q do
    $data.push(gets.chomp.split(' ').collect! { |tmp| tmp.to_i })
end
$ans = 0

def dfs(value)
    if value.length > $n then
        tmp_ans = 0
        $data.each { |a, b, c, d|
            if value[b] - value[a] == c then
                tmp_ans += d
            end
        }
        if tmp_ans > $ans then
            $ans = tmp_ans
        end
        return
    end

    for i in value.last..$m
        dfs(Array.new(value).push(i))
    end
end

dfs([1])
puts $ans

Measured memory_bytes: 15176
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
using namespace std;
const long long N = 4e6 + 7;
struct node {
	long long to, cost;
}r;
struct que {
	long long x, y;
	bool friend operator < (que a, que b) {
		return a.x > b.x;
	}
}w;
long long vis[N];
long long dis[N];
vector<node>v[N];
long long n, m, x, y, z;
void push(long long x, long long y, long long z) {
	r.to = y; r.cost = z;
	v[x].push_back(r);
}
long long inf = 214722121483647;
priority_queue<que> q;
long long slove(long long x) {
	fill(dis, dis + N, inf);
	w.x = 0; w.y = 1;
	dis[1] = 0;
	q.push(w);
	while (!q.empty()) {
		w = q.top(); q.pop();
		long long pos = w.y;
		if (dis[pos] < w.x) continue;
		for (long long i = 0; i < v[pos].size(); i++) {
			node e = v[pos][i];
			if (dis[e.to] > dis[pos] + e.cost) {
				dis[e.to] = dis[pos] + e.cost;
				w.x = dis[e.to]; w.y = e.to;
				q.push(w);
			}
		}
		
	}
	return dis[n];
}
int main() {
	cin >> n >> m;
	for (long long i = 1; i <= n; i++) {
		push(i, i - 1, 0);
	}
	while (m--) {
		cin >> x >> y >> z;
		push(x, y, z);
	}
	if (slove(1) == inf) cout << "-1\n";
	else cout << dis[n] << '\n';
	return 0;
}



Measured memory_bytes: 132600
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

int main(){
    string s;
    cin>>s;
    if(s[6]<='4' and s[5]=='0') cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.conv;

void main() {
    int[] a = readln.chomp.split.to!(int[]);
    if (a[0] < a[1]) {
        "a < b".writeln;
    } else if (a[0] > a[1]) {
        "a > b".writeln;
    } else {
        "a == b".writeln;
    }
}


Measured memory_bytes: 2496
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll H,W;
    cin >> H >> W;
    if(!(H%3) || !(W%3)){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1e18;
    cmin(ans,W);
    cmin(ans,H);
    ll t1 = W/2;
    ll t2 = W - W/2;
    REP(i,1,H){
        ll M = max(W*(H-i),max(t1*i,t2*i));
        ll m = min(W*(H-i),min(t1*i,t2*i));
        cmin(ans, M-m);
    }
    t1 = H/2;
    t2 = H - H/2;
    REP(i,1,W){
        ll M = max(H*(W-i),max(t1*i,t2*i));
        ll m = min(H*(W-i),min(t1*i,t2*i));
        cmin(ans, M-m);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
ifstream in ("test.in" );
ofstream out("test.out");
 
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n;
    cin >> n;
    
    int nr0 = 0, nr1 = 0, nr2 = 0;
    for (int i = 1; i <= n; ++i) {
        int x, nr = 0;
        cin >> x;
        
        while (x % 2 == 0) {
            ++nr;
            x >>= 1;
        }
        
        if (nr == 0) ++nr0; else
        if (nr == 1) ++nr1; else
            ++nr2;
    }
    
    if (nr0 > nr2 + 1)
        cout << "No";
    else
    if (nr0 == nr2 + 1 && nr1 > 0)
        cout << "No";
    else
        cout << "Yes";
    
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int N;
    int *A, *B;
    int i, tmp;
    long int sum;
    
    scanf("%d", &N);
    getchar();
    
    A = (int *)malloc(sizeof(int) * (N+1) );
    B = (int *)malloc(sizeof(int) * (N) );

    
    for(i=0; i<N+1; i++)scanf("%d", &A[i]);
    getchar();
    for(i=0; i<N; i++)scanf("%d", &B[i]);

    sum = 0;
    for(i=0; i<N; i++){
        if(B[i] > A[i]){

            sum += A[i];
            tmp = B[i] - A[i];
            if(tmp > A[i+1]){
                sum += A[i+1];
                A[i+1] = 0;
            }else{
                sum += tmp;
                A[i+1] -= tmp;
            }

        }else{
            sum += B[i];
        }
    }

    

    printf("%ld\n", sum);

    return 0;
    
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,a,b;
    cin >> x >> a >> b;
    cout << (x-a)%b << endl;
    return 0;
}

Measured memory_bytes: 3588
#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;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int a,b,c,d;cin >>a>>b>>c>>d;
    ll ans=min(a,b)+min(c,d);
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main()
{
    while(1){
        int length;
        int m, h, i, j;
        char str[201] = {0};
        char tmp[201] = {0};
        
        scanf("%s", str);
        if(str[0] == '-') break;
        length = strlen(str);
        
        scanf("%d", &m);
        for(i=0; i<m; i++){
            scanf("%d", &h);
            strncpy(tmp, str, h);
            tmp[h] = '\0';
            for(j=0; j<length-h; j++) str[j] = str[j+h];
            str[length-h] = '\0';
            strcat(str, tmp);
        }
        printf("%s\n", str);
    }
    return 0;
}

Measured memory_bytes: 604
while True:
    L=input().split( )
    H=int(L[0])
    W=int(L[1])
    if H==0 and W==0:
        break
    for j in range(H):
        for i in range(W):
            if (i+j)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()



Measured memory_bytes: 7008
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20191029
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
           string s = "No";

            for (int i = 1; i < 10; i++)
            {
                for(int j = 1;j<10;j++)
                {
                    int answer = i * j;

                    if (n == answer)
                        s = "Yes";

                }
            }


            Console.WriteLine(s);

        }
    }
}


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

int main() {
  int n,m; cin>> n>> m;
  vector<int>a(m);
  int sum =0;
  for(int c=0;c<m;c++)cin >> a[c];
  for(int i=0; i<m; i++)sum += a[i];
  if(sum<=n)cout << n-sum << endl;
  else cout << -1<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int n,w;
	cin>>n>>w;
	ll wt[n], val[n];
	ll dp[n][w+1];
	for(int i=0;i<n;i++){
		cin>>wt[i]>>val[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=w;j++)
		dp[i][j]=0;
	}
	for(int i=0;i<=w;i++)
	{
			if(wt[0]<=i)
			dp[0][i]=val[0];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=w;j++)
		{
		if(wt[i]<=j)
		{
			dp[i][j]=max(dp[i-1][j],val[i]+dp[i-1][j-wt[i]]);
		}
		else
		dp[i][j]=dp[i-1][j];
	}
}
	cout<<dp[n-1][w]<<"\n";
}
	

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    long long n;
    cin >> n;

    vector <char> alpha({'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'});

    string s = "";

    while(n > 0){
        long long amari = (n-1) % 26;
        s.push_back(alpha[amari]);
        n = (n-1) / 26;
    }

    reverse(all(s));

    cout << s << endl;

}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < N; i++) cin >> b[i];

  int ans = 0, x = 1;
  for (int j = 0; j < 30; j++) {
    vector<int> aa(N), bb(N);
    for (int i = 0; i < N; i++) {
      aa[i] = a[i] % (x * 2);
      bb[i] = b[i] % (x * 2);
    }

    sort(ALL(aa));

    int s = 0;
    for (int i = 0; i < N; i++) {
      if (bb[i] < x) {
        s += lower_bound(ALL(aa), x * 2 - bb[i]) - lower_bound(ALL(aa), x - bb[i]);
      } else {
        s += lower_bound(ALL(aa), x * 2 - bb[i]) - lower_bound(ALL(aa), x - bb[i]);
        s += lower_bound(ALL(aa), x * 4 - bb[i]) - lower_bound(ALL(aa), x * 3 - bb[i]);
      }
    }
    ans += (1 << j) * (s % 2);
    x *= 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6572
N=int(input())
a_list=list(map(int,input().split()))


flag=True

for a in a_list:
    if a%2==0:
        if a%3==0 or a%5==0:
            pass
        else:
            flag = False

if flag:
    print("APPROVED")
else:
    print("DENIED")


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

const int mod = 998244353;
const int _ = 2e5 + 10;
int N, K, L[11], R[11], f[_], sum[_];

int main() {
#ifndef ONLINE_JUDGE
  freopen("d.in", "r", stdin);
  freopen("d.out", "w", stdout);
#endif
  cin >> N >> K;
  for (int i = 1; i <= K; ++i) cin >> L[i] >> R[i];
  sum[1] = f[1] = 1;
  for (int i = 2; i <= N; ++i) {
    for (int j = 1; j <= K; ++j) {
      if (i - L[j] < 1) continue;
      f[i] = (f[i] + (sum[i - L[j]] - sum[max(1, i - R[j]) - 1] + mod) % mod) %
             mod;
    }
    sum[i] = (sum[i - 1] + f[i]) % mod;
  }
  cout << f[N] << endl;
  return 0;
}

Measured memory_bytes: 5180
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    VEC(int,a,3);
    sort(ALL(a));
    int res = abs(a[0]-a[1])+abs(a[1]-a[2]);
    cout<<res;
}



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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	string s;
	cin >> s;
	int q;
	cin >> q;
	deque<char> d;
	rep(i,s.size()){
		d.push_back(s[i]);
	}
	int rev_flag = 0;
	rep(i,q){
		int query_type;
		cin >> query_type;
		if(query_type==1){
			rev_flag = 1 - rev_flag;
		} else if (query_type == 2){
			int f;
			char c;
			cin >> f >>c;
			--f;
			if(rev_flag)  f = 1 - f;
			if(f==0){
				// 先頭にc
				d.push_front(c);
			} else {
				// 後ろにc
				d.push_back(c);
			}
		}
	}
	while(!d.empty()){
		if(rev_flag){
			// 後ろからとる
			char c = d.back();
			d.pop_back();
			cout << c;
		} else {
			char c = d.front();
			d.pop_front();
			cout << c;
		}
	}
	cout << endl;
}


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

/* 特定の文字列t -> w に置換 */
string replace_c(string str, string t, string w)
{
	if(!t.empty())
	{
		size_t pos = 0;
		while ((pos = str.find(t, pos)) != std::string::npos)
		{
			str.replace(pos, t.length(), w);
			pos += w.length();
		}
	}
	return str;
}

int  main()
{
	string s; cin >> s;
	string t = ",";
	string w = " ";
	string ans = replace_c(s, t, w);
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 256
def resolve():
    x, y = [int(i) for i in input().split()]
    a = y - 2 * x
    b = 4 * x - y
    if a % 2 == 0 and b % 2 == 0 and a >= 0 and b >= 0:
        print('Yes')
    else:
        print('No')
resolve()

Measured memory_bytes: 8992
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool cmp(int x,int y)
{
	return x>y;
}
const int MAXINF=0x7fffffff;
const int MININF=0x80000000;
const ll MOD=1e9+7;
ll n,z,k,f[10005];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    cin>>f[i];
    sort(f+1,f+n+1,cmp);
    for(int i=1;i<=k;i++)
    z+=f[i];
    cout<<z;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            var counts = new int[5];
            for (int i = 0; i < 3; ++i)
            {
                var V = ReadInts();
                ++counts[V[0]];
                ++counts[V[1]];
            }
            Console.WriteLine(counts.All(c => c < 3) ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 13268