akhauriyash/Code-Regression huggingface dataset:
// Problem : B - Joker
// Contest : AtCoder - AtCoder Grand Contest 044
// URL : https://atcoder.jp/contests/agc044/tasks/agc044_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

vector<vector<long>> grid;
vector<vector<bool>> occupied;

void dfs(long row, long col, long val) {
    if (!occupied[row][col]) val--;
    if (grid[row][col] > val) {
        grid[row][col] = val;
        dfs(row + 1, col, val + 1);
        dfs(row - 1, col, val + 1);
        dfs(row, col + 1, val + 1);
        dfs(row, col - 1, val + 1);
    }
}  

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

    long n;
    cin >> n;
    grid.resize(n+2, vector<long>(n + 2, 0));
    occupied.resize(n+2, vector<bool>(n + 2, false));
    for (long i = 0; i < grid.size(); i++) {
        for (long j = 0; j < grid.size(); j++) {
            grid[i][j] = min(min(i, j), min((long)grid.size() - i - 1, (long)grid.size() - j - 1));
            occupied[i][j] = (grid[i][j] != 0);
        }
    }
    long long ans = 0;
    for (long i = 0; i < n * n; i++) {
        long k;
        cin >> k;
        long row = (k - 1) / n + 1;
        long col = (k - 1) % n + 1;
        long x = min(min(grid[row-1][col], grid[row+1][col]), min(grid[row][col+1], grid[row][col-1]));
        ans += x;
        dfs(row, col, x);
        occupied[row][col] = false;
    }
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 24108
from collections import deque
n = int(input())
a = list(map(int, input().split()))

d = deque()
for i, v in enumerate(a):
    if i % 2 == 0:
        d.appendleft(v)
    else:
        d.append(v)
if i % 2 == 1:
    d = list(d)[::-1]
print(*d, sep=' ')


Measured memory_bytes: 25412
#include<stdio.h>

#define MAX 10001
#define INF 500000
#define white 0
#define gra 1
#define black 2
typedef struct point{
	int x;
	int y;
	int l;
}G;
G M[INF];
int n,u,size=0;
void kei(void);

int main(){
  int i,j,k,v,c;

  scanf("%d",&n);

  for(i=0;i<INF;i++){
      M[i].l = INF;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
	  M[size].x = u;
      M[size].y = v;
	  M[size].l = c;
	  size++;
    }
  }

  kei();

  return 0;
}

void kei(){
  int i,min,d[MAX],color[MAX] = {white};

  for(i=0;i<n;i++)d[i] = INF;

  d[0] = 0;
  color[0] = gra;

  while(1){
    min = INF;
    u = -1;
    for(i=0;i<n;i++){
      if(min > d[i] && color[i] != black){
		u = i;
		min = d[i];
      }
    }
	if(u == -1)break;
    color[u] = black;
    for(i=0;i<size;i++){
	  if(M[i].x==u){
      	if(color[M[i].y] != black && M[i].l != INF){
			if(d[M[i].y] > d[u] + M[i].l){
	  		d[M[i].y] = d[u] + M[i].l;
	  		color[M[i].y] = gra;
			}
      	}
	  }else if(M[i].x>u) break;
  	}
  }
  for(i=0;i<n;i++){
   	if(d[i] == INF)printf("%d -1\n",i);
   	else printf("%d %d\n",i,d[i]);
  }
}


Measured memory_bytes: 7696
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  ll k=100;
  ll ans=0;
  while(k<n){
    ans++;
    k=(ll)(k*1.01);
  }
  COUT(ans);
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5;

int main(){
	lli N,A,B,C,D;
	cin>>N>>A>>B>>C>>D;
	
	lli diff=B-A+(N-1)*D;
	lli y=(N-1)*(D-C);
	lli x=C+D;
	lli r=diff%x;
	if(r<=y&&diff<=2*(N-1)*D&&0<=diff)cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n=int(input())
h=[int(i) for i in input().split()]

dp = [2**30]*n
dp[0] = 0

for i in range(n+1):
    if i < n-1:
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]))
    if i < n-2:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]))

print(dp[n-1])

Measured memory_bytes: 13976
#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define FOR(i, a, n, step) for (int (i) = (a); (i) < (int)(n); (i) += (step))
#define ROF(i, a, n, step) for (int (i) = (a); (i) >= (int)(n); (i) -= (step))
#define FOREACH(it, v) for (auto (it) : (v))

using namespace std;

typedef unsigned long long ull;
typedef long long ll ;
typedef long double ld;
typedef pair <int, int> pii;

template <class T>
const bool is_impar(const T &x) {return (bool) (x & 1);}

int n, k;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    cout << (bool)(n % k);
}


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

int main(){
    string s,t;
    int k;
    cin >> k >> s;
    
    if(s.size() <= k) cout << s << endl;
    if(s.size() > k){
        for(int i =  0; i < k; i++) {
            t.push_back(s.at(i));
        }
        cout << t + "..." << endl;
    }
}

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

int main() {
  int n,k;
  cin>>n>>k;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  for(int i=0;i<n-k;i++){
    if(a.at(k+i)>a.at(i))
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3992
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  string S;
  cin >> S;

  S.replace(3, 1, "8");

  cout << S << endl;

  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int b,c;
  int ans = 0;
    // スペース区切りの整数の入力
    scanf("%d %d",&b,&c);
    if(b >= 1 && b<= 9){
      if(c >= 1 && c<=9){
        ans = b*c;
		printf("%d",ans);
        return 0;
      }
    }
  
    printf("-1");//printf("%c",s[0])//文字一つ分のみを出力
    
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    char A[11], B[11], C[11];
    scanf("%s %s %s", A, B, C);
    if(A[strlen(A)-1]==B[0] && B[strlen(B)-1]==C[0]) printf("YES\n");
    else printf("NO\n");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<tgmath.h>
using namespace std;

#define lld long long

lld isprime(lld x){
    if(x == 2) {
        return true;
    } else if(x < 2 || x % 2 == 0) {
        return false;
    } else {
        lld i = 3;
        while((long double)i <= (long double)sqrt(x)){
            if(x % i == 0){
                return false;
            }
            i += 2;
        }
        return true;
    } 
}

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        lld x;
        cin >> x;
        if(isprime(x)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    
}


Measured memory_bytes: 3080
import sys

n, x, *a = map(int, sys.stdin.read().split())
a = [0] + a

def main():
    tot = 0
    for i in range(1, n + 1):
        tot += max(0, a[i] + a[i-1] - x)
        a[i] = min(a[i], x - a[i-1])
    print(tot)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 14092
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fori(i,start_value, n) for(int i=start_value; i<n; i++)
#define ford(i,start_value, n) for(int i=start_value; i>=n; i--)
#define take_array(arr, len) for(int i=0; i<len; i++) cin>>arr[i];
#define print_array(arr, len) for(int i=0; i<len; i++) cout<<arr[i]<<" "; cout<<"\n";

typedef long long ll ;
typedef long double ld ;
typedef long long int lli;

using namespace std;

ll mult(ll a,ll b, ll p=mod){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=mod){return (a%p + b%p)%p;}
ll sub(ll a, ll b, ll p=mod){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n; n = n * n;} return r;}
ll inv(ll a, ll p = mod) {return fpow(a, p - 2);}


int main()
{

	int t;
	//cin>>t;

	t=1;

	while(t--)
	{
    int n;
    cin>>n;

    int arr[n];
    int ans[n]={0};
    take_array(arr,n);

    ans[0] = 0;
    ans[1] = abs(arr[1] - arr[0]);
    fori(i,2,n)
    {
      ans[i] += min(abs(arr[i]-arr[i-1])+ans[i-1] , abs(arr[i]-arr[i-2])+ans[i-2]);
    }

    cout<<ans[n-1]<<"\n";
	}

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 5005
int n, a, b;
ll dp1[MN][MN][3]; //0 = run of 0s, 1 = run of 1s. 2 = run of 1s and just came from 0-jump
//legal moves:
//0->0, 0->1, 1->0, 1->1, 1->2 via 0-jump, 2->1, 2->2. (can't have two 0-jumps in a row)
ll modExp(ll b, ll ex){
    ll prod = 1;
    while(ex > 0){
        if(ex % 2 == 0){
            b = (b * b) % MOD;
            ex /= 2;
        } else{
            prod = (prod*b) % MOD;
            ex--;
        }
    }
    
    return prod;
}

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

    cin >> n >> a >> b;
    if(a > b) swap(a, b);
    dp1[1][1][0] = dp1[1][1][1] = 1;
    dp1[a][a][2] = 1;
    FOR(i, 1, n-1){
        FOR(j, 1, a-1){
            //cout << i << " " << j << " 0 " << dp1[i][j][0] << "\n";
            dp1[i+1][j+1][0] = (dp1[i+1][j+1][0]+dp1[i][j][0])%MOD;
            dp1[i+1][1][1] = (dp1[i+1][1][1]+dp1[i+1][j+1][0])%MOD;
        }
        FOR(j, 1, b-1){
            //cout << i << " " << j << " 1 " << dp1[i][j][1] << "\n";
            dp1[i+1][j+1][1] = (dp1[i+1][j+1][1]+dp1[i][j][1])%MOD;
            dp1[i+1][1][0] = (dp1[i+1][1][0]+dp1[i][j][1])%MOD;
            if(i+a<=n && j+a<b) dp1[i+a][j+a][2] = (dp1[i+a][j+a][2]+dp1[i][j][1])%MOD;
            //CHECK IF BOUND OBO
        }
        FOR(j, 1, b-1){ //state 2
            //cout << i << " " << j << " 2 " << dp1[i][j][2] << "\n";
            dp1[i+1][j+1][2] = (dp1[i+1][j+1][2]+dp1[i][j][2])%MOD;
            dp1[i+1][j+1][1] = (dp1[i+1][j+1][1]+dp1[i][j][2])%MOD;
        }
    }
    ll ans = 0;
    FOR(i, 1, a-1){
        //cout << n << " " << i << " 0 " << dp1[n][i][0] << "\n";
        ans = (ans+dp1[n][i][0])%MOD;
    }
    FOR(i, 1, b-1){
        //cout << n << " " << i << " 1 " << dp1[n][i][1] << "\n";
        //cout << n << " " << i << " 2 " << dp1[n][i][2] << "\n";
        ans = (ans+dp1[n][i][1])%MOD;
        ans = (ans+dp1[n][i][2])%MOD;
    }
    ll fin = modExp(2, n)-ans;
    fin = (fin+MOD)%MOD;
    cout << fin << "\n";

    return 0;
}


Measured memory_bytes: 590028
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    xyc = [list(map(int, input().split())) for _ in range(M)]

    ans = min(a) + min(b)
    for x, y, c in xyc:
        new = a[x-1] + b [y-1] - c
        if ans > new:
            ans = new
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 38560
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=1e9+7;
int L,R,Mx[101],Mi[101],dp[101][2][2][2];
int DFS(int pos,bool limit,bool lead,bool is) {
	if(pos==0)return !lead;
	if(dp[pos][limit][lead][is]!=-1)return dp[pos][limit][lead][is];
	int up=limit?Mx[pos]:1;
	int tmp=0;
	if(is||Mi[pos]==0)tmp+=DFS(pos-1,limit&&Mx[pos]==0,lead,is);
	if(up){
		tmp+=DFS(pos-1,limit,false,is||(Mi[pos]==0));
		if(!lead&&(is||Mi[pos]==0))tmp+=DFS(pos-1,limit&&Mx[pos]==1,false,is);
	}	
	tmp%=MOD;
	dp[pos][limit][lead][is]=tmp;
	return tmp;
}
int solve() {
	while(R)Mx[++Mx[0]]=R&1,R=R>>1;
	while(L)Mi[++Mi[0]]=L&1,L=L>>1;
//	for(int i=1; i<=Mx[0]; i++)cout<<Mx[i]<<" ";
//	cout<<endl;
//	for(int i=1; i<=Mi[0]; i++)cout<<Mi[i]<<" ";
//	cout<<endl;
	return DFS(Mx[0],true,true,false);
}
signed main() {
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&L,&R);
	cout<<solve();
//	for(int i=1; i<=Mx[0]; i++)cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	repn(i, 1, n - 1){
		vi v(26, 0);
		rep(j, i) v[s[j] - 'a'] = 1;
		int cur = 0;
		repn(j, i, n) if(v[s[j] - 'a']) cur++, v[s[j] - 'a']--;
		ans = max(ans, cur);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main(void)
{
	char string[11];
	char tmp[11];
	int i;
	int j;
	
	while( scanf("%s", string) != EOF )
	{
		for( i = 0; i < 9; i++ )
		{
			for( j = 0; j < 10 - i - 1; j++ )
			{
				tmp[j] = ( ( (string[j] - '0') + (string[j + 1] - '0') ) - ( (string[j] - '0') + (string[j + 1] - '0') ) / 10 * 10 ) + '0';
			}
			//tmp[j] = '\0';
			strcpy( string, tmp );
		}
		printf( "%c\n", string[0] );
	}
	
	return (0);
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,m;
    cin>>n>>m;
    long long v,w,dp[10001];
    f(i,0,m+1){
        dp[i]=-1;
    }
    dp[0]=0;
    f(i,0,n){
        cin>>v>>w;
        f(j,w,m+1){
            if(dp[j-w]!=-1){
                dp[j]=max(dp[j-w]+v,dp[j]);
            }
        }
    }
    cout<<*max_element( dp, dp + m + 1)<<endl;
    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define mp make_pair
#define pb push_back
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i < (int)(n); ++i)
#define nfor(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define correct(x, y, n, m) (0 <= x && x < n && 0 <= y && y < m)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second
#define endl "\n"

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }
template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; }
template<class T> T lcm(T a, T b) { return a / gcd (a, b) * b; }
template<class T> T sign(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); }

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int dxKn[8] = {-2, -1, 1, 2,  2,  1, -1, -2};
const int dyKn[8] = { 1,  2, 2, 1, -1, -2, -2, -1};
const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1};

const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 100;
const ll INF64 = 2e18;
const ld PI = ld(3.1415926535897932384626433832795);
const ld e = ld(2.7182818284590452353602874713527);
const ld EPS = 1e-9;

//#############################
const int MAXN = 1000005;

int main() {
    fastIO(); 
    ll n;
    cin >> n;
    string s;
    ll pw = 1;
    while(n > 0) {
        n--;
        s.pb((n%26) + 'a');
        n/=26;
    }
    reverse(all(s));
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3604
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define sort(x) sort(x.begin(), x.end())
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;


int main(){
    ll n;
    cin >> n;
    ll h[100003];
    rep(i, n) cin >> h[i];
    ll ans = 0;
  	ll ans2 = 0;
    for (ll i = 0; i < n-1; i++)
    {	
        if(h[i+1]<=h[i]) ans2++;
      	else {
          ans2 = 0;
        }
      	ans = max(ans, ans2); 
    }    
    cout << ans << endl;
}

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

int main() {
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> A(N);
    for (int64_t& a : A) {
        cin >> a;
    }

    sort(A.begin(), A.end());

    int64_t ok = 1e18, ng = -1e18;
    while (ok - ng != 1) {
        int64_t mid = (ok + ng) / 2;

        int64_t eq_and_less_than_mid_num = 0;
        for (int64_t i = 0; i < N - 1; i++) {
            //j > iについてA[i]との積がmidより小さくなるA[j]の数
            if (A[i] <= 0) {
                auto bound = upper_bound(A.begin() + i + 1, A.end(), mid, [&](const int64_t& lhs, const int64_t& rhs){
                    return A[i] * rhs <= lhs;
                });
                int64_t n = A.end() - bound;
                eq_and_less_than_mid_num += n;
            } else {
                auto bound = upper_bound(A.begin() + i + 1, A.end(), mid, [&](const int64_t& lhs, const int64_t& rhs){
                    return A[i] * rhs > lhs;
                });
                int64_t n = bound - A.begin() - i - 1;
                eq_and_less_than_mid_num += n;
            }
        }

        (eq_and_less_than_mid_num >= K ? ok = mid : ng = mid);
    }

    cout << ok << endl;
}

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

int main(){
  int n;
  while(cin >> n && n){
    int a,ai,aj,ak,b,bi,bj,bk;
    for(int i=0;i<n;i++){
      cin >> a >> ai >> aj >> ak >> b >> bi >> bj >> bk;
      cout << a*b - ai*bi - aj*bj - ak*bk;
      cout << ' ' << ai*b + a*bi + aj*bk - ak*bj;
      cout << ' ' << a*bj - ai*bk + aj*b + ak*bi;
      cout << ' ' << a*bk + ai*bj - aj*bi + ak*b;
      cout << endl;
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
using namespace std;

typedef long long ll;

int main(){
	int n;
	int x=0,y=0,z=0;
	cin >> n;
	int cnt = 0;
	for(int i = 0 ; i < n ; i ++){
		string s;
		cin >> s;
		if(s[0] == 'B'){
			if(s[s.size()-1] == 'A')z ++;
			else x ++;
		}
		else if(s[s.size()-1] == 'A')y ++;
		for(int j = 0 ; j+1 < s.size() ; j ++){
			if(s[j] == 'A' && s[j+1] == 'B')cnt ++;
		}
	}
	if(x == 0){
		if(y > 0)cout << cnt+z << endl;
		else cout << cnt+max(0,z-1) << endl;
	}
	else if(y == 0){
		cout << cnt+z << endl;
	}
	else cout << cnt+min(x,y)+z << endl;
}


Measured memory_bytes: 256
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

int main()
{
  int a, b;
  cin >> a >> b;
  if ((a + b) < 24)
  {
    cout << a + b << endl;
  }else{
    cout << (a + b)-24 << endl;
  }

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	int n, m;
	cin >> n >> m;
	vector<int>w(n), e(n);
	for (int k = 0; k < m; ++k)
	{
		string s;
		cin >> s;
		for (int i = 0; i < n; ++i)
		{
			char c = s[i];
			if (c == 'W')
			{
				w[i]++;
			}
			else
			{
				e[i]++;
			}
		}
	}
	vector<int>west(1, 0), east(1, 0);
	for (int ww : w)west.push_back(west.back() + ww);
	for (int ee : e)east.push_back(east.back() + ee);
	int best = INT_MAX;
	int ans = -1;
	for (int i = 0; i <= n; ++i)
	{
		int gos = east[i] + west[n] - west[i];
		if (gos < best)
		{
			best = gos;
			ans = i;
		}
	}
	cout << ans << " " << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 3268
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class DTriangles {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n;
	    in >> n;
	    vector<ll> l(n);
	    for(int i=0; i<n; i++){
            in >> l[i];
	    }

	    sort(l.begin(), l.end());
	    ll cnt = 0;
	    for(int i=n-1; i>=0; i--){
	        for(int j=i-1; j>=0; j--){
                int ind = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
                cnt += (n - 1 - i) - (n-ind);
	        }
	    }

	    out << cnt << enl;
	}
};


int main() {
	DTriangles solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static long MOD = 109+7;

    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();

        int n = sc.nextInt();

        int[] a = new int[n];

        for(int i = 0 ; i < n; i++) a[i] = sc.nextInt();

        int[][] arr = new int[h][w];

        int wl = 0;
        int wm = w - 1;
        int hl = 0;
        int hm = h - 1;

        int id = 0;
        while(true) {
            int i = 0;
            for (i = wl; i <= wm; i++) {
                if(a[id] == 0) {
                    id++;
                }
                arr[hl][i] = id + 1;
                a[id]--;
            }
            if(i == wl) break;
            hl++;

            for (i = hl; i <= hm; i++) {
                if(a[id] == 0) {
                    id++;
                }
                arr[i][wm] = id + 1;
                a[id]--;
            }
            if(i == hl) break;
            wm--;

            for (i = wm; i >= wl; i--) {
                if(a[id] == 0) {
                    id++;
                }
                arr[hm][i] = id + 1;
                a[id]--;
            }
            if(i == wm) break;
            hm--;

            for (i = hm; i >= hl; i--) {
                if(a[id] == 0) {
                    id++;
                }
                arr[i][wl] = id + 1;
                a[id]--;
            }
            if(i == hm) break;
            wl++;
        }

        for(int i = 0; i < h; i++) {
            System.out.print(arr[i][0]);
            for(int j = 1; j < w; j++) {
                System.out.print(" " + arr[i][j]);
            }
            System.out.println();
        }
    }
}

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

using namespace std;

typedef pair<long double, pair<long long int, long long int>>onepath;

int main() {
	long long int N, M;
	cin >> N >> M;
	vector<pair<long long int, long long int>>D( N );
	for( size_t i = 0; i < N; i++ ) {
		cin >> D[i].first >> D[i].second;
	}
	vector < vector<pair<long long int, long double>>>path( N );
	priority_queue<onepath, vector<onepath>, greater<onepath>>que;
	for( size_t i = 0; i < M; i++ ) {
		long long int p, q;
		cin >> p >> q;
		p--; q--;
		long double len = sqrtl( powl( D[p].first - D[q].first, 2 ) + powl( D[p].second - D[q].second, 2 ) );
		que.push( make_pair( len, make_pair( p, q ) ) );
		path[p].push_back( make_pair( q, len ) );
		path[q].push_back( make_pair( p, len ) );
	}
	long double ans = 0;
	while( que.size() ) {
		auto now = que.top(); que.pop();
		long double len = now.first;
		for( auto ite = path[now.second.first].begin(); ite < path[now.second.first].end(); ite++ ) {
			if( ( *ite ).first == now.second.second ) {
				path[now.second.first].erase( ite );
				break;
			}
		}
		for( auto ite = path[now.second.second].begin(); ite < path[now.second.second].end(); ite++ ) {
			if( ( *ite ).first == now.second.first ) {
				path[now.second.second].erase( ite );
				break;
			}
		}
		long long int start = now.second.first, goal = now.second.second;
		queue<long long int>pointqueue;
		vector<bool>flag( N, false );
		flag[start] = true;
		pointqueue.push( start );
		while( pointqueue.size() ) {
			auto np = pointqueue.front(); pointqueue.pop();
			for( auto nnp : path[np] ) {
				if( flag[nnp.first] == false ) {
					flag[nnp.first] = true;
					pointqueue.push( nnp.first );
				}
			}
		}
		if( flag[goal] ) {
			ans += len;
		}
	}
	cout << fixed << setprecision( 20 ) << ans << endl;

}

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

int n;
int m;



int main() {
  cin>>n;
  cin>>m;
  int a[m];
  for (int i=0; i <m;i++){
    cin>>a[i];
  }
  int sum;
  sum=0;
  for (int i =0;i<m;i++){
    sum+= a[i];
  }
  if (n>sum){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }

  

  return 0;
 
}

Measured memory_bytes: 640
def Fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

N,M = map(int,input().split())
if M == 0:
  P = Fib(N+2)
  print(P%1000000007)
else:
  S = []
  for _ in range(M):
    S.append(int(input()))
  S.append(-1)
  S.append(N+1)
  S.sort()  
  P = 1

  for i in range(M+1):
    P *= Fib(S[i+1]-S[i]) 

  print(P%1000000007)


Measured memory_bytes: 7088
<?php
    /*
        Problem URL : http://abc059.contest.atcoder.jp/tasks/abc059_a

        Score  :
        Result :
        Time   : ms
        Memory : KB
     */

    ini_set('error_reporting', E_ALL & ~E_NOTICE);

    // define('DEBUG', true);
    define('DEBUG', false);

    if (DEBUG) {
        $start = microtime(true);
    }

    $a = explode(" ", trim(fgets(STDIN)));

    foreach ($a as $str) {
        echo strtoupper(substr($str, 0, 1));
    }
    echo PHP_EOL;


Measured memory_bytes: 4604
N, K = tuple(map(int, input().split()))
S = "1"+input()+"1"

prev = S[0]
if prev == "0":
  fst_is_0 = True
else:
  fst_is_0 = False

cnt = 0
cnt_0 = 0

cnt_lst = []
for idx, s in enumerate(S):
  if s == prev:
    cnt += 1
  else:
    cnt_lst.append(cnt)
    cnt = 1
    if s == "0":
      cnt_0 += 1
    prev = s
else:
  cnt_lst.append(cnt)
#print(cnt_lst)


if cnt_0 <= K:
  print(len(S)-2)
else:
  prev = "1"
  cnt_lst = [0]
  for idx,s in enumerate(S):
    if prev != s:
      cnt_lst.append(idx)
    prev=s
  cnt_lst.append(len(S))
  s_ =[]
  for idx in range( int( (len(cnt_lst)+1)/2) -K):
    #print(2*idx+2*K,idx*2,cnt_lst[2*idx+2*K+1] -cnt_lst[idx*2])
    if idx==0 or idx==int( (len(cnt_lst)+1)/2) -K-1:
      s_.append(cnt_lst[2*idx+2*K+1] -cnt_lst[idx*2]-1)
    else:
      s_.append(cnt_lst[2*idx+2*K+1] -cnt_lst[idx*2])
  print(max(s_))

Measured memory_bytes: 8760
import itertools

s = input()
K = int(input())

alp = list('abcdefghijklmnopqrstuvwxyz')

index_list = [alp.index(s[i]) for i in range(len(s))]

cnt_list = []
for j in index_list:
    if j > 0:
        cnt_list.append(26-j)
    else:
        cnt_list.append(0)

s_list = list(s)

if sum(cnt_list) <= K:
    num = (K - sum(cnt_list)) % 26
    l = "a" * (len(s)-1) + alp[num]
    print(l)
else:
    i = 0
    for i in range(len(s)):
        if i == len(s)-1:
            if K >= cnt_list[i]:
                num = (K - cnt_list[i]) % 26
                s_list[i] = alp[num]
            else:
                s_list[i] = alp[K-cnt_list[i]]
        elif K >= cnt_list[i]:
            K -= cnt_list[i]
            s_list[i] = 'a'
        else:
            pass
    ans = ''.join(s_list)
    print(ans)

Measured memory_bytes: 56884
#include<iostream>
#include<string.h>
using namespace std;

const int INF = 100000000;
int adj[100][100];

int main() {
  int n,m,s,g1,g2,b1,b2,c;

  while(cin>>n>>m>>s>>g1>>g2, n|m|s|g1|g2) {
    s--,g1--,g2--;


    for(int i=0; i<100; ++i) {
      for(int j=0; j<100; ++j)
	adj[i][j] = INF;
      adj[i][i] = 0;
    }

    for(int i=0; i<m; ++i) {
      cin>>b1>>b2>>c;
      b1--,b2--;
      adj[b1][b2] = c;
    }


    for(int k=0; k<n; ++k)
      for(int i=0; i<n; ++i)
	for(int j=0; j<n; ++j)
	  adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]);

    int minc = INF;
    for(int i=0; i<n; ++i)
      minc = min(minc, (adj[s][i]+adj[i][g1]+adj[i][g2]));

    cout<<minc<<endl;
  }
}

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

using namespace std;

int main(){
	int n;
	vector<int> arr;
	cin >> n;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		arr.push_back(a);
	}
	int min  = arr[0];
	int count = 1;
	for(int i=1; i<n; i++){
		if(arr[i-1] > arr[i]){
			if(min > arr[i]){
				count += 1;
			}
		}
		if(min > arr[i]){
			min = arr[i];
		}
	}
	cout << count << endl;
	return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  
  int s[n];
  rep(i,k){
    int m;
    cin >> m;
    
    rep(j,m){
      int a;
      cin >> a;
      s[a-1]=1;
    }
  }
  
  int ans=0;
  rep(i,n){
    if(s[i]!=1) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3644
N,K,Q = gets.split.map &:to_i
arr = Array.new(N,K)
Q.times do
  a = gets.to_i
  arr[a-1] += 1
end
arr.each do |ar|
  if ar-Q <= 0
    puts 'No'
  else
    puts 'Yes'
  end
end



Measured memory_bytes: 3196
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var answer = 0;
            while (true)
            {
                var ok = true;
                for (var i = 0; i < A.Length; i++)
                {
                    if (A[i] % 2 == 1)
                    {
                        ok = false;
                        break;
                    }
                    A[i] /= 2;
                }
                if (ok) answer++;
                else break;
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28376
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()

cnt_even = Counter(a[::2]).most_common()+[(0,0)]
cnt_odd = Counter(a[1::2]).most_common()+[(0,0)]

ans = 0
if cnt_even[0][0] == cnt_odd[0][0]:
  ans = n - max(cnt_even[0][1],cnt_odd[0][1]) - max(cnt_even[1][1],cnt_odd[1][1])
else:
  ans = n - cnt_even[0][1] - cnt_odd[0][1]

print(ans)


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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int n, a, b, ans = 0;
  //string s;
  cin >> n >> a >> b;
  rep(i, 1001){
    if(a <= n * (i+1) && n * (i+1) <= b){
      cout << "OK" << endl;
      return 0;
    }
  }
  //((a == b)? "Yes" : "No")
  //for(int i = 0; i < n; i++){}
  cout << "NG" << endl;
}

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

#define int long long

constexpr long long MOD = 1000000007;
constexpr long long INF = 1e18;

#define f first
#define s second


int N, M, Q;
vector<string> grid;
vector<pair<pair<int,int>,pair<int,int>>> in;
vector<vector<int>> used, rcon, ya, yb, xa, xb;

void dfs(int x, int y, int depth = 1){
  if(used[x][y]) return;
  used[x][y] = depth;

  for(int i = 0; i < 4; i++){
    int nx = x + (2 - i)%2, ny = y + (i - 1)%2;

    if(grid[nx][ny] == '1' && grid[nx][ny] == '1'){
      dfs(nx, ny, depth+1);
    }
  }
}

signed main(){

  cin>>N>>M>>Q;

  grid.resize(N+2);
  in.resize(Q);
  used.resize(N+2, vector<int>(M+2));
  rcon.resize(N+2, vector<int>(M+2));

  ya.resize(N+2, vector<int>(M+2));
  yb.resize(N+2, vector<int>(M+2));
  xa.resize(N+2, vector<int>(M+2));
  xb.resize(N+2, vector<int>(M+2));

  for(int i = 1; i <= N; i++){
    cin>>grid[i];

    grid[i] = '0' + grid[i] + '0';
  }

  for(int i = 0; i <= M + 1; i++){
    grid[0] += '0';
    grid[N+1] += '0';
  }

  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= M; j++){
      if(used[i][j]) continue;
      if(grid[i][j] == '0') continue;

      rcon[i][j]++;
      dfs(i, j);
    }
  }

  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= M; j++){
      if(used[i][j] == 0) continue;
      if(grid[i][j] == '0') continue;

      if(grid[i][j+1] == '1' && used[i][j] > used[i][j+1]) {
        ya[i][j]++;
      }

      if(grid[i][j-1] == '1' && used[i][j] > used[i][j-1]) {
        yb[i][j]++;
      }

      if(grid[i+1][j] == '1' && used[i][j] > used[i+1][j]) {
        xa[i][j]++;
      }

      if(grid[i-1][j] == '1' && used[i][j] > used[i-1][j]) {
        xb[i][j]++;
      }

    }
  }
  /*
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= M; j++){
      cout<<rcon[i][j]<<" ";
    }
    cout<<endl;
  }
  */

  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= M; j++){
      xa[i][j + 1] += xa[i][j];
      xb[i][j + 1] += xb[i][j];
      rcon[i][j+1] += rcon[i][j];
    }
  }

 for(int i = 1; i <= M; i++){
    for(int j = 1; j <= N; j++){
      ya[j+1][i] += ya[j][i];
      yb[j+1][i] += yb[j][i];
      rcon[j+1][i] += rcon[j][i];
    }
 }
 /*
 for(int i = 1; i <= N; i++){
   for(int j = 1; j <= M; j++){
     cout<<rcon[i][j]<<" ";
   }
   cout<<endl;
 }
 */

  for(int i = 0; i < Q; i++){
    int x1, y1, x2, y2;
    int ans = 0;
    cin>>x1>>y1>>x2>>y2;

    //x1--,y1--,x2--,y2--;

    // cout<<"<> "<<endl;
    ans += rcon[x2][y2] - rcon[x2][y1-1] - rcon[x1-1][y2] + rcon[x1-1][y1-1];
    // cout<<ans<<endl;
    ans += ya[x2][y2] - ya[x1-1][y2];
    ans += yb[x2][y1] - yb[x1-1][y1];
    ans += xa[x2][y2] - xa[x2][y1-1];
    ans += xb[x1][y2] - xb[x1][y1-1];

    cout<<ans<<endl;

    //in[i] = {{x1,y1},{x2,y2}};
  }

  return 0;
}


Measured memory_bytes: 206592
if __name__ == '__main__':
	n,m,l=map(int,raw_input().split())
	a=[map(int,raw_input().split()) for _ in xrange(n)]
	b=zip(*[map(int,raw_input().split()) for _ in xrange(m)])
	sums=[i[k]*j[k] for i in a for j in b for k in xrange(m)]
	c=[sum(sums[i:i+m]) for i in [j for j in xrange(len(sums)) if j%m==0]]
	for i in xrange(len(c)):
		if (i+1)%l==0: print c[i]
		else: print c[i],

Measured memory_bytes: 39536
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int knapsack(int N, int W, int *v, int *w){
  int dp[N + 1][W + 1];
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  REP(i, N){
    REP(j, W + 1){
      if(dp[i][j] < 0) continue;
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if(j + w[i] <= W) dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
    }
  }
  int ans = 0;
  REP(i, W + 1) ans = max(ans, dp[N][i]);
  return ans;
}

int main() {
  int N, W; cin >>N >>W;
  int v[N], w[N];
  REP(i, N) cin >>v[i] >>w[i];
  cout <<knapsack(N, W, v, w) <<endl;
  return 0;
}

Measured memory_bytes: 5112
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a = in.nextInt();
        int b = in.nextInt();
        out.println(Math.max(a + b, Math.max(a - b, a * b)));
        out.close();
    }
}


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

using namespace std;

#define MAX_N 16
#define INF 1e9

int N,a[MAX_N][MAX_N+1];
int dp[1<<MAX_N];

int solve(int v,int S){
  if(S == (1<<N)-1){
    return dp[S] = 0;
  }
  if(dp[S] >= 0){
    return dp[S];
  }
  int res = INF;
  for(int i = 0 ; i < N ; i++){
    if(S >> i & 1){ continue; }
    res = min(res,solve(i,S|(1<<i))+a[i][0]);
    for(int j = 0 ; j < N ; j++){
      if(S >> j & 1){
        res = min(res,solve(i,S|(1<<i))+a[i][j+1]);
      }
    }
  }
  return dp[S] = res;
}

int main(){
  while(cin >> N,N){
    for(int i = 0 ; i < N ; i++){
      for(int j = 0 ; j < N+1 ; j++){
        cin >> a[i][j];
      }
    }
    memset(dp,-1,sizeof(dp));
    int res = INF;
    for(int i = 0 ; i < N ; i++){
      res = min(res,solve(i,1<<i)+a[i][0]);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1424
d=int(input())
c=list(map(int, input().split()))
s=[]
last=[0]*26
for i in range(d):
  s.append(list(map(int, input().split())))
for day in range(1,d+1):
  man=[]
  for i in range(26):
    man.append(s[day-1][i]-last[i]*c[i])
  con=man.index(max(man))
  last[con]=day
  print(con+1)

Measured memory_bytes: 9416
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		int count = 0;
		for(int i = a; i <= b; i++) {
			if(c % i == 0) {
				count++;
			}
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 26320
#include <stdio.h>
#include <set>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

std::multiset<int, std::greater<int>> A;

int main(void){    
    int n; scanf("%d", &n);
    REP(i, n){ int a; scanf("%d", &a); A.insert(a); }
    int cnt = 0;
    for(auto itr = A.begin(); itr != A.end();){
        int t = 1; while(t <= *itr) t <<= 1;
        t -= *itr;
        itr = A.erase(itr);
        auto p = A.find(t);
        if(p == A.end()) continue;
        if(itr == p) itr = A.erase(p);
        else A.erase(p);
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cmath>

int main(void) {
    int input;
    int result = 0;
    int buf;
    int numWhichDivideTheInput;
    std::cin >> input;
    buf = input;
    for(int i = 9; i > -1; i--){
        numWhichDivideTheInput = (int)std::pow(10, i);
        result += input / numWhichDivideTheInput;
        input %= numWhichDivideTheInput;
    }
    //std::cout << result << std::endl;
    if((buf % result) == 0) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 384
c = []
for _ in range(3):
    c.append(list(map(int, input().split())))
a = []
for i in range(3):
    tmp = []
    for j in range(3):
        tmp.append(c[i][j%3] - c[i][(j+1)%3])
    a.append(tmp)
for i in range(2):
    for j in range(3):
        if a[i][j]!=a[i+1][j]:
            print('No')
            break
    else:
        continue
    break
else:
    print('Yes')

Measured memory_bytes: 3188
#include <iostream>
#define maxn 200005
using namespace std;
int a[maxn], have[30][maxn], cnt[30], p[30];
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++ i){
		cin >> a[i];
		int x = a[i];
		for (int j = 0; j <= 20; ++ j)
			if (x & (1 << j))
				have[j][++ cnt[j]] = i;
	}
	for (int j = 0; j <= 20; ++ j){
		have[j][++ cnt[j]] = n + 1;
		have[j][++ cnt[j]] = n + 1;
	}
	long long ans = 0;
	for (int i = 1; i <= n; ++ i){
		int mn = n + 1;
		for (int j = 0; j <= 20; ++ j){
			while (have[j][p[j]] < i)
				++ p[j];
			mn = min(mn, have[j][p[j] + 1]);
		}
		ans += mn - i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 16512
'use strict'

const main = input => {
	const args = input.split('\n')[0].split(' ')
	const a = parseInt(args[0], 10)
	const p = parseInt(args[1], 10)
	console.log(Math.floor((a * 3 + p) / 2))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 9420
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn tosign(b: i64, msk: i64) -> i64 {
    return if (b & msk) == 0 { 1 } else { -1 }
}

fn main() {
    let n: usize = read();
    let m: usize = read();
    let a: Vec<(i64, i64, i64)> = (0..n).map(|_| (read(), read(), read())).collect();

    let ans: Option<i64> = (0..8).map(|b| {
        let mut b: Vec<i64> = a.iter().map(|&(x, y, z)|
            tosign(b, 1) * x + tosign(b, 2) * y + tosign(b, 4) * z
        ).collect();
        b.sort();
        b.reverse();
        b[0..m].iter().sum()
    }
    ).max();

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


Measured memory_bytes: 4352