akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define M 100

int Bubblesort(int,int *);

int main()
{
	int A[M], i = 0,v,limit,count=0;
	scanf("%d", &limit);
	for(i=0;i<limit;i++){
		scanf("%d", &A[i]);
		if (i == M-1)break;
	}
	v = Bubblesort(limit,A);
	for (i = 0; i < limit - 1; i++) printf("%d ", A[i]);
	printf("%d\n%d\n", A[limit - 1],v);
	
	return 0;
}

int Bubblesort(int N,int *A)
{
	int flag = 1,j,count=0;
	int kari;
	while (flag) {
		flag = 0;
		for (j = N - 1; j > 0; j--) {
			if (A[j] < A[j - 1]) {
				kari = A[j];
				A[j] = A[j - 1];
				A[j - 1] = kari;
				flag = 1;
				count++;
			}
		}
	}
	return count;
}


Measured memory_bytes: 2048
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
int main(void){
    int n,m,i,j,st[100],sh[100],sumt,sumh,anst,ansh,tt,th;
    while(1){
        n=in();
        m=in();
        if(!n)break;
        sumt=sumh=0;
        rep(i,n){
            st[i]=in();
            sumt+=st[i];
        }
        rep(i,m){
            sh[i]=in();
            sumh+=sh[i];
        }
        anst=ansh=101;
        rep(i,n){
            rep(j,m){
                tt=st[i];
                th=sh[j];
                if(sumt-tt+th==sumh-th+tt&&anst+ansh>tt+th){
                    anst=tt;
                    ansh=th;
                }
            }
        }
        if(anst==101)puts("-1");
        else print2(anst,ansh);
    }        
    return 0;
}



Measured memory_bytes: 1924
#include <cstdio>  
#include <cstring>  
#include <cmath>  
using namespace std;  
const int maxn=1e2+10;   
int n;  
int a[maxn][maxn];  
int dp[maxn][maxn];  
  
int max(int a,int b)  
{  
    return a>b?a:b;  
 }   
  
void solve()  
{  
    dp[1][1]=a[1][1];  
    for(int i=1;i<=2;i++)  
    {  
        for(int j=1;j<=n;j++)  
        {  
            if(i==1)  
                dp[i][j]=dp[i][j-1]+a[i][j];  
            else  
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];   
        }  
    }  
}   
int main()  
{  
    while(~scanf("%d",&n))  
    {  
      
    memset(a,0,sizeof(a));  
    memset(dp,0,sizeof(dp));  
    for(int i=1;i<=2;i++)  
    {  
        for(int j=1;j<=n;j++)  
        {  
            scanf("%d",&a[i][j]);  
        }  
    }  
    solve();  
    printf("%d\n",dp[2][n]);  
}  
    return 0;  
} 

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define int ll
ll N;
vpi primefac(int x){
	vpi ans;
	int num = 0;
	while (x % 2 == 0){
		num++;
		x /= 2;
	}
	if (num > 0) ans.pb(pi(2,num));
	
	for (int i=3;i<=sqrt(x); i += 2){
		num = 0;
		while (x % i == 0){
			num++;
			x /= i;
		}
		if (num > 0) ans.pb(pi(i,num));
	}
	if (x > 2) ans.pb(pi(x,1));
	return ans;
}

int32_t main(){
	cin>>N;
	
	vpi vect = primefac(N);
	
	int ans = 0;
	aFOR(i,vect){
		int num = i.s;
		int j = 1;
		
		while (1){
			if (num < j) break;
			ans++;
			num -= j;
			j++;
		}
	}
	cout<<ans;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
	int h,w;
	cin >> h >> w;
	int a[510][510];
	for(int yy = 0; yy < h; yy++)
	{
		for(int xx = 0; xx < w; xx++)
		{
			cin>>a[yy][xx];
		}
	}
	int nowy=0,nowx=0,n=0;
	int nexty=0,nextx=0;
	vector<int> y1,y2,x1,x2;
	while(true){
		if(nowy%2==0) //1->2
		{
			if(nowx<w-1)
			{
				nextx=nowx+1;
			}
			else
			{
				nexty=nowy+1;
			}			
		}
		else
		{
			if(nowx>0)
			{
				nextx=nowx-1;
			}
			else
			{
				nexty=nowy+1;
			}	
		}
		if(nexty>=h) break;
		if(a[nowy][nowx]%2>0)
		{
			a[nexty][nextx]++;
			n++;
			y1.push_back(nowy);
			x1.push_back(nowx);
			y2.push_back(nexty);
			x2.push_back(nextx);
		}
		nowy=nexty;
		nowx=nextx;
	}
	cout<<n<<endl;
	for(int i = 0; i < n; i++)
	{
		cout<<y1[i]+1<<" "<<x1[i]+1<<" "<<y2[i]+1<<" "<<x2[i]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 5220
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL minima(LL a, LL b)
{
    return (a < b) ? a : b;
}

int main()
{
    LL n, total, i, j, k, temp, sum = 0;
    cin >> n >> total;
    LL weight[n + 1], value[n + 1];

    for (i = 1; i <= n; i++)
    {
        cin >> weight[i] >> value[i];
        sum += value[i];
    }

    LL dp[sum + 1][n + 1];
    for (i = 1; i <= sum; i++)
    {
        for (j = 0; j <= n; j++)
        {
            dp[i][j] = 1e16;
        }
    }

    for (j = 0; j <= n; j++)
    {
        dp[0][j] = 0;
    }

    for (i=0;i<=sum;i++)
    {
        for (j=0;j<= n;j++)
        {
            if (dp[i][j] != 1e16)
            {
                for (k=j+1;k<=n;k++)
                {
                    dp[i][k]=minima(dp[i][k],dp[i][j]);
                    if (i+value[k]<=sum)
                    {
                        dp[i+value[k]][k] = minima(dp[i + value[k]][k], dp[i][j] + weight[k]);
                        //cout<<"dp["<<i+value[k]<<"]["<<k<<"] is "<<dp[i+value[k]][k]<<endl;
                    }
                }
            }
        }
    }

    LL ans = -1;

    for (i = sum; i >= 0; i--)
    {
        if (dp[i][n] <= total)
        {
            ans = i;

            break;
        }
    }
    //cout<<dp[17][n]<<endl;
    //cout << dp[ans][n] << endl;
    cout << ans << endl;
}

Measured memory_bytes: 79104
def main():
    a, b, c = map(int, input().split())

    print(solve(a, b, c))


def solve(a, b, c):
    a, b, c = sorted([a, b, c])
    x = a % 2
    y = b % 2
    z = c % 2

    if x == y == z:
        return ((c - a) // 2) + ((c - b) // 2)
    
    if x == y:
        return solve(a + 1, b + 1, c) + 1
    
    if x == z:
        return solve(a + 1, b, c + 1) + 1
    
    if y == z:
        return solve(a, b + 1, c + 1) + 1


def evens(*args):
    n = 0
    for i in args:
        if i % 2 == 0:
            n += 1
    return n

main()


Measured memory_bytes: 3064
N = int(input())
A = list(map(int,input().split()))
 
flag = True
count = 0
while(flag):
  for i in range(N):
    if A[i]%2:
      flag = False
      break
    else:
      A[i] /= 2
  if flag:
    count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
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; }

const long long INF = 1LL << 60;

int main(){
    string s;cin>>s;
    if(s=="SUN")cout<<7;
    if(s=="MON")cout<<6;
    if(s=="TUE")cout<<5;
    if(s=="WED")cout<<4;
    if(s=="THU")cout<<3;
    if(s=="FRI")cout<<2;
    if(s=="SAT")cout<<1;

}

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

int main() {
    vector<int> nums(3);
    for (int i = 0; i < 3; ++i) {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end());
    cout << nums[0] * nums[1] / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
	int h, w, n;

	cin >> h >> w >> n;

	vector<int> a(n);

	for (int i = 0; i < n; i++)
		cin >> a[i];

	vector<int> s(w);

	int num = 0, id = 0;

	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			s[j] = id + 1;
			num++;

			if (num == a[id]){
				num = 0;
				id++;
			}
		}

		if (i % 2 == 1)
			reverse(s.begin(), s.end());
		
		for (int j = 0; j < w; j++)
			cout << s[j] << " ";

		cout << endl;

	}
}

Measured memory_bytes: 384
n = int(input())
A = list(map(int, input().split()))

# evens are plus
ans1 = 0
subtotal = 0
for i in range(n):
    subtotal += A[i]
    if i % 2 == 0 and subtotal <= 0:
        diff = abs(subtotal) + 1
        subtotal += diff
        ans1 += diff
    elif i % 2 == 1 and subtotal >= 0:
        diff = abs(subtotal) + 1
        subtotal -= diff
        ans1 += diff

# odds are plus
ans2 = 0
subtotal = 0
for i in range(n):
    subtotal += A[i]
    if i % 2 == 1 and subtotal <= 0:
        diff = abs(subtotal) + 1
        subtotal += diff
        ans2 += diff
    elif i % 2 == 0 and subtotal >= 0:
        diff = abs(subtotal) + 1
        subtotal -= diff
        ans2 += diff

print(min(ans1, ans2))

Measured memory_bytes: 14464
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353//1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

inline int func(int a, int b)
{
	if (a > b)
		return a - b;
	else
		return b - a;
}

ll r = 0;
int tar = 0;
ll cur = 1;

bool solve(int head, int keta)
{
	if (keta == 0)
	{
		tar--;
		if (tar == 0)
		{
			r = 0;
			r += head;
			cur *= 10;
			return true;
		}
		return false;
	}

	if (head == 9)
	{
		if (solve(8, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}
		
		if (solve(9, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}
		return false;
	}
	else if (head == 0)
	{
		if (solve(0, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}

		if (solve(1, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}
		return false;
	}
	else
	{
		if (solve(head - 1, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}

		if (solve(head, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}

		if (solve(head + 1, keta - 1))
		{
			r += head * cur;
			cur *= 10;
			return true;
		}
		return false;
	}
}

int main()
{
	int k;
	cin >> k;
	tar = k;

	bool ok = false;

	for (int i = 0; !ok; i++)
		for (int j = 1; j <= 9; j++)
			if (solve(j, i))
			{
				ok = true;
				break;
			}

	printf("%lld", r);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int n, k;
    string str;
    cin >> n >> k >> str;

    str[k-1] = tolower(str[k-1]);
    cout << str;
}

Measured memory_bytes: 3516
#include <iostream>

using namespace std;

int main() {
    int input;
    int ans = 0;
    cin >> input;
    if (input % 10 == 1) {
        ans++;
        input--;
    }
    input /= 10;
    if (input % 10 == 1) {
        ans++;
        input--;
    }
    input /= 10;
    if (input % 10 == 1) {
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 2009
using namespace std;
 
int m,n,ans,a[N][N],b[N][N],c[N],q[N],lf[N],rg[N];
char s[N];
int main(){
	scanf("%d%d",&m,&n);
	int i,j,k;
	for (i=1; i<=m; i++){
		scanf("%s",s+1);
		for (j=1; j<=n; j++) a[i][j]=(s[j]=='#');
	}
	for (i=1; i<=m; i++)
		for (j=2; j<=n; j++)
			b[i][j]=(a[i][j]^a[i+1][j])==(a[i][j-1]^a[i+1][j-1])?b[i-1][j]+1:0;
	for (i=1; i<=m; i++){
		for (j=2; j<=n; j++) c[j]=1+b[i-1][j];
		//if (i==2) for (j=2; j<=n; j++) cout<<c[j]<<' ';puts("");
		q[k=1]=1; c[1]=-2; c[n+1]=-1;
		for (j=2; j<=n+1; j++){
			for (; c[j]<=c[q[k]]; k--) rg[q[k]]=j;
			lf[j]=q[k]; q[++k]=j;
		}
		for (j=2; j<=n; j++){
			//cout<<j<<' '<<lf[j]<<' '<<rg[j]<<endl;
			ans=max(ans,c[j]*(rg[j]-lf[j]));
		}
	}
	printf("%d\n",max(ans,max(m,n)));
	return 0;
}

Measured memory_bytes: 31744
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXLEN = 100000;

char s[MAXLEN + 1]; int n;

void run() {
	scanf("%s", s); n = strlen(s);
	int ret = 0, l = 0, r = n - 1;
	while (l < r) {
		if (s[l] == s[r]) ++l, --r;
		else if (s[l] == 'x') ++l, ++ret;
		else if (s[r] == 'x') --r, ++ret;
		else { printf("-1\n"); return; }
	}
	printf("%d\n", ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>

#define MOD 1000000007
#define EPS ((long double)1e-12)
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz(x) ((long long)(x).size())
#define endl '\n'

#define DUMP_NAME(name,a) cout << "#dump " << (name) << " = " << (a) << "  "
#define dump(a) DUMP_NAME(#a, (a));

#define FOREACH(it,x) for(__typeof__((x).begin()) it = (x).begin();it!=(x).end();++it)
#define FOR(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define ROF(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)

const ld PI = 3.141592653589793238L;
const ll N = 100005;

using namespace std;

/**************************************************************************************************/

ll n , m;
vector<ll> g[705];
ll e[705][705];
ll c[705];
vector<pair<ll,ll>> comp;
ll one , two;
ll dp[705][705];

ll solve(ll i , ll nb){
    if(i == sz(comp)) return (nb * (nb - 1)) / 2 + ((n - nb) * (n - nb - 1)) / 2;

    ll &ans = dp[i][nb];
    if(ans != -1) return ans;

    return ans = min(solve(i + 1 , nb + comp[i].F) , solve(i + 1 , nb + comp[i].S));
}

void dfs(ll x,ll color){
    c[x] = color;

    if(color == 1) ++one;
    else ++two;

    FOREACH(y , g[x]) if(c[*y] == 0) dfs(*y , 3 - color);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("grant.in","r",stdin);
    //freopen("grant.out","w",stdout);
    //<>

    cin >> n >> m;
    vector<pair<ll,ll>>v;
    FOR(i,1,m){
        ll a,b; cin >> a >> b;
        e[a][b] = e[b][a] = 1;
        v.pb(mp(a , b));
    }

    FOR(i,1,n) FOR(j,1,n) if(i != j && e[i][j] == 0) g[i].pb(j) , g[j].pb(i);

    FOR(i,1,n) if(c[i] == 0){
        one = 0 , two = 0;
        dfs(i , 1);

        comp.pb(mp(one , two));
    }

    FOR(i,1,n) FOREACH(j , g[i]) if(c[i] == c[*j]){
        cout << "-1\n";
        return 0;
    }

    memset(dp , -1 , sizeof(dp));
    cout << solve(0 , 0) << endl;

    return 0;
}


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


int main(){
  int n;
  cin >> n;
  int ans;
  rep(i, 10){
    if(1000 * i < n && n <= 1000 * (i+1)){
      ans = 1000 * (i+1) - n;
    }
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0};
int inf = 1e9;
char wall = '@';

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k, i, j;
    cin >> h >> w >> k;
    int x0,y0,x1,y1;
    cin >> x0 >> y0 >> x1 >> y1;
    x0--;y0--;x1--;y1--;
    char grid[h][w];
    for(i=0;i<h;i++){
        string s;
        cin >> s;
        for(j=0;j<w;j++){
            grid[i][j] = s[j];
        }
    }
    vvi dist(h, vi(w, inf));
    vvi used(h, vi(w));
    dist[x0][y0] = 0;
    used[x0][y0] = 1;
    queue<pii> Q;
    Q.push({x0,y0});
    int x,y;
    bool found = false;
    while(!Q.empty() && (!found)){
        tie(x,y) = Q.front();
        Q.pop();
        used[x][y] = 2;
        if(x == x1 && y == y1) break;
        for(int dd = 0;dd < 4;dd++){
            i = x + dx[dd];
            j = y + dy[dd];
            while(  (i >= 0 && i < h) 
                    && (j >= 0 && j < w) 
                    && grid[i][j] != wall){
                if(used[i][j] == 2) break;
                if(abs(i - x) > k || abs(j - y) > k) break;
                if(dist[i][j] <= dist[x][y]) break;
                if(!used[i][j]){
                    dist[i][j] = dist[x][y] + 1;
                    used[i][j] = 1;
                    Q.push({i,j});
                    if(i == x1 && j == y1) found = true;
                }
                i += dx[dd];
                j += dy[dd];
            }
            if(found) break;
        }
    }
    
    if(dist[x1][y1] == inf){
        cout << "-1\n";
    }else{
        cout << dist[x1][y1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 15984
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

template<typename T>
constexpr T binaryPow_mod(T radix, T index, T mod) noexcept {
	radix %= mod;
	T rtv = 1;
	while (index > 0) {
		if (index & 1) {
			rtv *= radix;
			rtv %= mod;
		}

		radix *= radix;
		radix %= mod;

		index = index >> 1;
	}

	return rtv;
}

template<typename T>
constexpr T invA_mod(T a, T mod) {
	return binaryPow_mod(a, mod - 2, mod);
}

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

	ll n, m, k;
	cin >> n >> m >> k;

	ll ans = 0;
	ll c = 1;
	llrep(i, k + 1) {
		ans += m * ((binaryPow_mod(m - 1, n - 1 - i, MOD) * c) % MOD);
		ans %= MOD;
		c *= n - 1 - i;
		c %= MOD;
		c *= invA_mod(1 + i, MOD);
		c %= MOD;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll a, b;
  cin >> a >> b;
  print((a - 1) * (b - 1));
}

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

using ll = long long;
const ll INF = (ll)1e17 + 1;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << *it << " ";
    if ((it - begin) % 20 == 19 || it == end - 1) { std::cout << std::endl; }
  }
}

template<typename Iterator> void printVecPair(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << it->first << " " << it->second << " ";
    if ((it - begin) % 10 == 9 || it == end - 1) std::cout << std::endl;
  }
}

int main()
{
  //std::ifstream ifs("input.def");
  //std::cin.rdbuf(ifs.rdbuf());

  ll N, T;
  std::cin >> N >> T;

  std::vector<ll> va(N);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  std::vector<std::pair<ll, ll> > vmax(N);
  vmax[N-1] = std::make_pair(va[N-1], N-1);
  for (ll i = N-1; i >= 0; i--) {
    vmax[i] = std::max(vmax[i+1], std::make_pair(va[i], i));
  }

  ll max_range = 0LL;
  for (ll i = 0; i < N; i++) {
    max_range = std::max(max_range, vmax[i].first - va[i]);
  }

  ll ans = 0LL;
  for (ll i = 0; i < N; i++) {
    if (max_range == vmax[i].first - va[i]) {
      va[vmax[i].second]--;
      ans++;
    }
  }

  print(ans);
  return 0;
}


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

#define MAXM 1000000

int a[MAXM + 5];
int c[MAXM + 5];

int f( int n )
{
	if( n % 2 ) {
		return 3 * n + 1;
	}
	else {
		return n / 2;
	}
}

int main() {
	int s;

	cin >> s;

	a[1] = s;
	c[a[1]]++;
	int ans = 0;
	for( int i = 2; i < MAXM + 1; i++ ) {
		a[i] = f( a[i - 1] );
		c[a[i]]++;
		if( c[a[i]] > 1 ) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    int n;cin >> n ;

    double res=0;
    for(int i=0;i<n;i++){
        double x;cin >> x;
        string u;cin >> u;

        if(u=="JPY") res += x;
        else res+=x*380000.0;
    }
    p(res)
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  multiset<int> st;
  for (int i = 0; i < N; i++){
    auto itr = st.lower_bound(A[i]);
    if (itr == st.begin()){
      st.insert(A[i]);
    } else {
      st.erase(prev(itr));
      st.insert(A[i]);
    }
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vector<ll> a(N), b(N), c(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];
    vector<vector<ll>> dp(N + 100, vector<ll>(3,0));

    dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];

    rep(i, N){
        dp[i + 1][0] = a[i + 1] + max(dp[i][1], dp[i][2]);
        dp[i + 1][1] = b[i + 1] + max(dp[i][2], dp[i][0]);
        dp[i + 1][2] = c[i + 1] + max(dp[i][0], dp[i][1]);
    }

    print(max({dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]}));

    return 0;
}

Measured memory_bytes: 8064
// 枝刈り無し
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

int n, q;
vector<int> A;

bool solve(int i, int m) {
    if (m == 0) return true;
    if(i >=n) return false;
    return solve(i + 1, m) || solve(i + 1, m - A[i]);
}

int main() {
    cin >> n;
    A.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    cin >> q;
    for (int j = 0; j < q; ++j) {
        int m;
        cin >> m;
        bool ans = solve(0, m);
        if(ans) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}



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

int main()
{
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int ans = 0;
    rep(i, 0, n){
        ans += (d + a[i] - 1)/a[i];
    }
    cout << ans + x << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define PI (3.1415926535)
#define EPS (1e-10)
bool eq(double a, double b){
  return abs(a-b) < EPS;
}

int main(){
  int w,n;
  scanf("%d%d",&n,&w);
  int a[n];
  REP(i,n) a[i] = i;
  REP(i,w){
    int b,c;
    scanf("%d,%d",&b,&c);
    swap(a[b-1],a[c-1]);
  }
  REP(i,n) printf("%d\n",a[i]+1);
  
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
	ll k,a,b;
	cin >> k >> a >> b;

	if(b<=a+2) {
		cout << (k+1) << endl;
		return 0;
	}

	if(1+k<=a) {
		cout << (k+1) << endl;
		return 0;
	}

	k -= a-1;

	ll ans = a;
	if(k%2==1) {
		ans++;
		k--;
	}

	ans += (b-a)*(k/2);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
 
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  map<int, int> dic;
  REP(i, N){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int var = 1;
  vector<int> cnt(1,0);
  int cur = A[0];

  REP(i, N){
    if(cur != A[i]){
      cur = A[i];
      cnt.push_back(1);
      var++;
    }
    else{
      cnt[var-1]++;
    }
  }
  sort(cnt.begin(), cnt.end());

  int ans = 0;
  for(int i=0; i < var - K; ++i){
    ans += cnt[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll h, w;
  cin >> h >> w;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      string s;
      cin >> s;
      if (s == "snuke") {
        cout << (char)('A' + j) << i + 1 << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int MAX = 501;
int data[MAX];

void make(){
  for(int i = 1; i < MAX; i++)
    data[i] = data[i-1]+i;
}

int solve(int in){
  int ans = 0;
  for(int i = 0; i < MAX; i++)
    for(int j = i+2; j < MAX; j++)
      if(data[j]-data[i] == in) ans++;
  return ans;
}
int main(){
  make();
  int in;
  while(cin >> in && in) cout << solve(in) << endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
using i64=int64_t;
 
#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}
 
i64 S(i64 x){
    i64 res=0;
    while(x){
        res+=x%10;
        x/=10;
    }
    return res;
}

void solve(){
    i64 K;
    cin >> K;
 
    vector<i64> head,tail;
    rep(i,1,2000) head.push_back(i);
    i64 b=0;
    rep(i,0,15){
        tail.push_back(b);
        b=b*10+9;
    }

    vector<i64> p(16);
    p[0]=1;
    rep(i,1,16){
        p[i]=p[i-1]*10;
    }

    vector<i64> vals;
    rep(i,0,head.size()) rep(j,0,tail.size()){
        vals.push_back(head[i]*p[j]+tail[j]);
    }

    sort(begin(vals),end(vals));
    vals.erase(unique(begin(vals),end(vals)),end(vals));
    i64 count=0;
    rep(i,0,vals.size()){
        if(vals[i]<=0) continue;
        bool ok=true;
        i64 p=vals[i];
        rep(j,i+1,vals.size()){
            i64 q=vals[j];
            if((long double)p*S(q)>(long double)q*S(p)){
                ok=false;
                break;
            }
        }

        if(ok){
            ++count;
            cout << p << endl;
            if(count==K) return;
        }
    }
}
 
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 648
#include<stdio.h>
int main(void)
{
	int i, n, j, d[101], t;

	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &d[i]);
	}

	for (i = n; i >= 1; i--) {
		if (i == 1) {
			printf("%d", d[i]);
		}
		else {
			printf("%d ", d[i]);
		}
	}

	printf("\n");
	
	return(0);
}


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

using namespace std;
#define set_precision(ans,l) cout << fixed << setprecision(l)<<ans;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<ll>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<ll>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define MAXN 1000001
long double EPS = 1e-9;
int spf[MAXN];

ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}

void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 

int main()
{
    FIO;
    ll n,t,x,y,m,k;
    sieve();
    cin>>n;
    vi prime(MAXN,0),v(n);
    k=1;
    rep(i,0,n){
        cin>>x;v[i]=x;
        y=spf[x];
        while(y!=1){
            if(prime[y]!=0){k=0;break;}
            prime[y]=1;
            while(spf[x]==y)x/=y;
            y=spf[x];
        }
        //cout<<v[i]<<" "<<k;
    }
    if(k)cout<<"pairwise coprime";
    else {
        k=1;
        x=v[0];
        rep(i,1,n){x=gcd(x,v[i]);}
        if(x==1){cout<<"setwise coprime";}
        else cout<<"not coprime";
    }
    return 0;
}

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

using namespace std;

const int mxn = 1e5;

int a[mxn + 11];

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d", a + i);
	}
	sort(a, a + m);
	vector <int> v;
	for (int i = 0; i < m - 1; i++){
		int x = a[i] - a[i + 1];
		if (x < 0)
			x = -x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	long long ans = 0;
	for (int i = 0; i < m - n; i++){
		ans += v[i];
	}
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1276
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;

    return 0;
}


Measured memory_bytes: 3648
def main():
    import sys
    from collections import deque
    input=sys.stdin.readline

    h,w,k=map(int,input().split())
    sy,sx,gy,gx=map(int,input().split())

    #maze=[]
    #for _ in range(h):
    #    maze.append(tuple(input()))

    maze=[tuple(input()) for _ in range(h)]

    sy-=1
    sx-=1
    gy-=1
    gx-=1

    #maze[sy][sx]="S"

    dis=[[-1]*w for _ in range(h)]



    dis[sy][sx]=0



    d = deque([(sx,sy)])
    while len(d)>0:
        (x,y)=d.popleft()
        if x==gx and y==gy:
            print(dis[gy][gx])
            #maze[gy][gx]="G"

            #pri(dis)
            #pri(maze)

            exit()

        for (mx,my) in ((0,1),(1,0),(-1,0),(0,-1)):
            #print(mx,my,d)
            for j in range(1,k+1):
                nx=x+mx*j
                ny=y+my*j
                #print(y,x,">>",ny,nx)
                if 0<=nx<w and 0<=ny<h:
                    if maze[ny][nx]=="." and (dis[ny][nx]==-1 or dis[ny][nx]==dis[y][x]+1):
                        if dis[ny][nx]==-1:
                            d.append((nx,ny))
                        dis[ny][nx]=dis[y][x]+1
                        
                        #pri(dis)
                    else:
                        break
                else:
                    break

    print(-1)
        
if __name__ == '__main__':
    main()


                










Measured memory_bytes: 43524
#include<stdio.h>
int solve(int,int);
int A[20],n;
int main()
{
  int m[200],q,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
    if(solve(0,m[i])==1){
      printf("yes\n");
    }
    else if(solve(0,m[i])==0) printf("no\n");

  }
  return 0;
}
int solve(int i,int m)
{
 
  if(m==0) return 1;
  if(i>=n) return 0;
  
  if(solve(i+1,m)==1 || solve(i+1,m-A[i])==1)
  return 1;
}

Measured memory_bytes: 580
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<stdbool.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int main(){
    char s[502020]; scanf("%s", s);
    int n = strlen(s);
    ll ans=0,tmpg=0,tmpl=0;
    int lt=(s[0]=='<'?1:0);
    rep(i,n){
        if(lt){
            if(s[i] == '<') tmpl++;
            else{
                lt=0;tmpg=1;
            }
        }else{
            if(s[i] == '>') tmpg++;
            else{
                ll tmp=max(tmpl,tmpg);
                ans+=tmp*(tmp+1)/2;
                tmp=min(tmpl,tmpg);
                ans+=tmp*(tmp-1)/2;
                lt=1;tmpl=1;
            }
        }
    }
    if(lt){
        ans+=tmpl*(tmpl+1)/2;
    }else{
        ll tmp=max(tmpl,tmpg);
        ans+=tmp*(tmp+1)/2;
        tmp=min(tmpl,tmpg);
        ans+=tmp*(tmp-1)/2;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 2208
n = gets.chomp.to_i
array = gets.chomp.split(" ").map(&:to_i).sort { |a, b| b <=> a }

a = 0
b = 0

n.times do |i|
  if i % 2 == 0
    a += array[i]
  else
    b += array[i]
  end
end

puts (a - b)

Measured memory_bytes: 1788
#include<stdio.h>

int main (void)
{
	
	int a, b;

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

	if(a > b) {
	  printf("a > b\n");
	} else if(a < b) {
	  printf("a < b\n");
	} else { 
	  printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#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 FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}
int N, A, B;
vector<int> h;
vector<int> temp;
bool judge(int mid) {
  temp      = h;
  int temp2 = 0;
  rep(i, N) {
    if (temp[i] - B * mid > 0) {
      temp2 += CEIL((temp[i] - B * mid), A);
    }
  }
  return temp2 <= mid;
}

int bisect(int L, int R) {
  int mid = (L + R) / 2;
  bool a, b;
  a = judge(mid - 1);
  b = judge(mid);
  if (not a and b) {
    return mid;
  } else if (a and b) {
    return bisect(L, mid);
  } else {
    return bisect(mid, R);
  }
}

class DWidespread {
public:
  static void solve(istream &cin, ostream &cout) {
    cin >> N >> A >> B;
    A = A - B;
    h.assign(N, 0);
    rep(i, N) cin >> h[i];
    cout << bisect(1, bpm(10, 9)) << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  DWidespread solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 4708
/* All men have limits. They learn what they are and learn
   not to exceed them, I ignore mine. -Batman           */
#include <bits/stdc++.h>
//#include <iostream>
//#include <Windows.h>
using namespace std;
long long int gcd(long long int a,long long int b){
while(1){
	if(a==0)return b;
	b%=a;
	if(b==0)return a;
	a%=b;
}
}

int main(){
long long int a,b;
while(cin>>a>>b)
cout<<gcd(a,b)<<" "<<a*b/gcd(a,b)<<endl;

return 0;
}

Measured memory_bytes: 3000
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		for(int i = 0; i<s.length(); i++) {
			if(s.charAt(i) != s.charAt(s.length()-i-1)) {System.out.println("No"); System.exit(0);}
		}
		
		System.out.println("Yes");
	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    lint all = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        all ^= a[i];
    }
    vector<lint> ret(n);
    for (int i = 0; i < n; ++i) {
        ret[i] = all ^ a[i];
    }
    for (int i = 0; i < n; ++i) {
        if (i)
            cout << " ";
        cout << ret[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 6360
/*
 ============================================================================
 Name        : abc125t2.c
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int N;
    int C[50] = {0};
    int V[50] = {0};
    int i = 0;
    int ans = 0;
    scanf("%d", &N);
    for(i = 0; i < N; i++) {
        scanf("%d", &V[i]);
    }
    for(i = 0; i < N; i++) {
        scanf("%d", &C[i]);
    }
    for(i = 0; i < N; i++) {
        if((V[i] - C[i]) > 0) {
            ans += V[i] - C[i];
        }
    }
    printf("%d\n", ans);

    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    string a, b; cin >> a >> b;
    int ans = n*2;
    rep(i,n){
        if(a.substr(i)==b.substr(0,n-i)){
            ans = 2*n-n+i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b) for(long long i=a;i<b;i++)
#define vi vector<ll>
const ll MAX=1e3;
const ll mod=1e9+7;
const ll INF=1e18+12;
set< pair<ll,ll> >ss;
ll sum[500];
ll dp[MAX][MAX];

                                    //SAMEER KUMAR SINGH//
// ================================================================================================================================//
// ================================================================================================================================//
// ================================================================================================================================//

int fun(string s1,string s2,ll n1,ll n2){

     if(n1<0||n2<0)
       return 0;
     if(dp[n1][n2]!=0)
       return dp[n1][n2];
     else if(s1[n1]==s2[n2]){
      dp[n1][n2]=1+fun(s1,s2,n1-1,n2-1);
      return dp[n1][n2];
      }
     else{
       ll k1=fun(s1,s2,n1-1,n2);
       ll k2=fun(s1,s2,n1,n2-1);
       dp[n1][n2]=max(k1,k2);
       return dp[n1][n2];
     }
}

int main(){
   FASTIO;
   ll tt=1;
   //cin>>tt;

   while(tt--){
     ll n;cin>>n;
      ll a[n];
      fr(0,n){
      cin>>a[i];
      }

      fr(0,n){
         dp[i][i]=0;
      }
      ll fsum=0;
      for(ll i=1;i<=n;i++){
        fsum+=a[i-1];
        sum[i]=fsum;
      }
      for(ll len=2;len<=n;len++){
         for(ll i=0;i<n-len+1;i++){
             ll j=i+len-1;
             ll k=len-1;
             ll ans=1e18;
             ll ls=j-1,rs=i+k;
             while(k--){
               ans=min(ans,dp[rs][j]+dp[i][ls]);
               rs--;
               ls--;
             }

             dp[i][j]=ans+sum[j+1]-sum[i];
         }
      }

      cout<<dp[0][n-1];
   }
}


Measured memory_bytes: 3968