akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
signed main(){
	int n ; cin >> n ;
	vector<int>arr(n);
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	vector<vector<int>>dp(n+2,vector<int>(n+2,0));
	for(int i=n-1;i>=0;i--){
		for(int j=i;j<n;j++){
			if( i == j ) dp[i][j] = arr[i];
			else dp[i][j] = max(arr[i] - dp[i+1][j],arr[j] - dp[i][j-1]);
		}
	}
	cout << dp[0][n-1] << endl;
	return 0;
}







Measured memory_bytes: 70784
#include <iostream>
#include <fstream>
#include <queue>

using namespace std;

int h, w;
char n;
char N[1002][1002];
bool p_flag[1002][1002] = { 0 };
int depth[1002][1002] = { 0 };

int main(){
	char next;
	int x, y, time = 0;
	int sx, sy;
	const int dx[4] = { 1, 0, -1, 0 };
	const int dy[4] = { 0, 1, 0, -1 };

	cin >> h >> w >> n;

	for (int i = 0; i < 1002; i++){
		for (int j = 0; j < 1002; j++){
			N[j][i] = 'X';
		}
	}
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> N[j][i];
			if (N[j][i] == 'S'){
				sx = j;
				sy = i;
			}
		}
	}

	queue <pair<int, int>> q;
	q.push(pair<int, int>(sx, sy));
	next = '1';
	bool b_flag = 0;
	p_flag[sx][sy] = 1;
	while (true){
		if (b_flag) break;
		x = q.front().first;
		y = q.front().second;
		q.pop();
		for (int d = 0; d < 4; d++){
			if (N[x + dx[d]][y + dy[d]] != 'X'){
				if (depth[x + dx[d]][y + dy[d]] == 0) depth[x + dx[d]][y + dy[d]] = depth[x][y] + 1;
				if (p_flag[x + dx[d]][y + dy[d]] == 0){
					if (N[x + dx[d]][y + dy[d]] == next){
						if (next == n){
							cout << depth[x + dx[d]][y + dy[d]] << endl;
							b_flag = 1;
							break;
						}
						else{
							next = next + 1;
							while (!q.empty()) q.pop();
							for (int i = 0; i < 1002; i++){
								for (int j = 0; j < 1002; j++){
									p_flag[j][i] = false;
								}
							}
							q.push(pair<int, int>(x + dx[d], y + dy[d]));
							p_flag[x + dx[d]][y + dy[d]] = 1;
							int dep = depth[x + dx[d]][y + dy[d]];
							for (int i = 0; i < 1002; i++){
								for (int j = 0; j < 1002; j++){
									depth[j][i] = 0;
								}
							}
							depth[x + dx[d]][y + dy[d]] = dep;
							break;
						}
					}
					else {
						q.push(pair<int, int>(x + dx[d], y + dy[d]));
						p_flag[x + dx[d]][y + dy[d]] = 1;
					}
				}
			}
		}
	}
}

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

int main()
{
	int N;
	string W[105];
	set < string > st;
	bool flag = true;

	cin >> N >> W[0];
	st.insert(W[0]);
	for ( int i = 1; i < N; i++ ) {
		cin >> W[i];
		if ( *rbegin(W[i - 1]) == W[i][0] && st.find(W[i]) == st.end() ) {
			st.insert(W[i]);
		} else {
			flag = false;
		}
	}
	
	if ( flag ) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return ( 0 );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string s;
	cin>>s;

	bool c=false,f=false;
	for (int i = 0; i < s.size(); i++){
		if(s[i]=='C')c=true;
		if(c&&s[i]=='F')f=true;
	}

	if(f)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main() {
	ll n,cnt=0,ans=0,h1,h2;
	cin >> n;
	cin >> h1;
	for(int i=0;i<n-1;i++){
		cin >> h2;
		if(h1>=h2){
			cnt++;
			ans=max(ans,cnt);
		}
		else cnt=0;
		h1=h2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 10000

int main(){
  int t,i,j,C[N+1];
  unsigned short *A,*B;

  scanf("%d",&t);

  A = malloc(sizeof(short)*t+1);
  B = malloc(sizeof(short)*t+1);

 for(i=0 ; i<=N ; i++){
    C[i]=0;
  }

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

  for(i=1 ; i<=N ; i++){
    C[i] = C[i] + C[i-1];
  }

  for (j=1 ; j<=t ; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1 ; i<t ; i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[t]);
 
  return 0;
}

  
   

Measured memory_bytes: 8452
import heapq
N, M = map(int, input().split())
value = [[] for _ in range(10 ** 5 + 1)]

for _ in range(N):
    a, b = map(int, input().split())
    value[a].append(-1 * b)

koho = value[1]
heapq.heapify(koho)

ans = 0
for i in range(1, M + 1):
    if len(koho) > 0:
        ans += -1 * heapq.heappop(koho)
    if i < M:
        for v in value[i + 1]:
            heapq.heappush(koho, v)

print(ans)

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

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z);
    for (int i = 0; i < X; i++)
        cin >> A[i];
    for (int i = 0; i < Y; i++)
        cin >> B[i];
    for (int i = 0; i < Z; i++)
        cin >> C[i];
    sort(A.begin(), A.end(), greater<long long>());
    sort(B.begin(), B.end(), greater<long long>());
    sort(C.begin(), C.end(), greater<long long>());

    vector<long long> res;
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            for (int k = 0; k < Z; k++) {
                if ((i + 1) * (j + 1) * (k + 1) > K)
                    break;
                res.push_back(A[i] + B[j] + C[k]);
            }
        }
    }
    sort(res.begin(), res.end(), greater<long long>());
    for (int i = 0; i < K; i++)
        cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 1404
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (100010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,m,tp,a[N],b[N],cnt[N],to[N]; bool yes[N],d[N];
bitset<50010> bs[50010],qwq;
int main(){
	read(n),read(m),read(tp); qwq.set();
	for(int i=1;i<=m;i++)read(a[i]),read(b[i]);
	if(tp==1){
		int ans=-1;
		for(int i=1;i<=n;i++)bs[i][i]=1;
		for(int i=m;i;i--)bs[a[i]]=bs[b[i]]=bs[a[i]]|bs[b[i]];
		for(int i=1;i<=n;i++)qwq&=bs[i];
		for(int i=1;i<=n;i++)if(qwq[i]){ans=i;break;}
		if(ans==-1){cout<<ans<<endl;return 0;}
		yes[ans]=1;
		for(int i=m;i;i--){
			if(yes[b[i]])d[i]=1;
			yes[a[i]]=yes[b[i]]=yes[a[i]]|yes[b[i]];
		}
		for(int i=1;i<=m;i++)
		putchar(d[i]?'v':'^');
	}
	else{
		if(n==2){puts("-1");return 0;}
		for(int i=1;i<=n;i++)cnt[i]=1,to[i]=i;
		for(int i=m;i;i--){
			if(cnt[to[a[i]]]>1)d[i]=1,cnt[to[a[i]]]--,cnt[to[b[i]]]++,to[a[i]]=to[b[i]];
			else{
				cnt[to[a[i]]]++,cnt[to[b[i]]]--,to[b[i]]=to[a[i]];
			}
		}
		for(int i=1;i<=m;i++)
		putchar(d[i]?'v':'^');
	}
} 

Measured memory_bytes: 310272
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main(void)
{
  int i,j,sum=0,n;
  char a[200000][11];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",a[i]);
  }
  qsort(a,n,sizeof(a[0]),strcmp);
  for(i=0;i<n;i++){
    if(strcmp(a[i],a[i+1])==0)sum++;
  }
  printf("%d",n-sum);
}

Measured memory_bytes: 5720
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    string L;
    cin >> L;
    vector<int> dp1(100010,0), dp2(100010,0);
    dp1[0] = 0, dp2[0] = 1;
    const int N = L.size();
    for (int i=0;i<N;i++) {
        dp1[i+1] = (dp1[i+1] + 3LL*dp1[i]%MOD) % MOD;
        if (L[i] == '1') {
            dp1[i+1] = (dp1[i+1] + dp2[i]) % MOD;
            dp2[i+1] = (dp2[i+1] + 2LL*dp2[i]%MOD) % MOD;
        } else {
            dp2[i+1] = (dp2[i+1] + dp2[i]) % MOD;
        }
    }

    cout << (dp1[N] + dp2[N])%MOD << endl;

    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,d,cnt=0;
	cin >> m >> d;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			int a=j/10;
			int b=j%10;
			if(i==a*b&&a!=1&&b!=1){
				//printf("%d %d%d\n",i,a,b);
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
  int n,m; cin>>n>>m;  
  vector<string>A(n);
  vector<string>B(m);
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  for(int i=0;i<m;i++){
    cin>>B[i];
  }  
  vector<int>ans;
  for(int i=0;i<n-m+1;i++){
    for(int j=0;j<n-m+1;j++){
      int flag=1;
      for(int k=0;k<m;k++){
        string t=A[i+k].substr(j,m);
        if(t==B[k]) continue;
        else{
          flag=0;
          break;
        }
      }
      if(flag==1) ans.push_back(flag);
    }
  }
  if(ans.size()>0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

    
  


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

using ll = long long;

ll mod = 1e9 + 7;

ll factorial(ll x){
    ll r = 1;
    while(x) r *= x, r %= mod, --x;
    return r; }

int main(){
    int n, m;
    cin >> n >> m;
    if(n > m) swap(n, m);
    if(m-n > 1) cout << 0 << endl;
    else if(m-n == 1) cout << ((factorial(n) * factorial(m))%mod) << endl;
    else cout << ((2ll * factorial(n) * factorial(m))%mod) << endl;
    return 0; }


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(string &a){reverse(a.begin(),a.end()) ;}



int main(){
	ll n ; cin >> n ;
	vll d(n) ;
	for(auto &i:d) cin >> i ;
	mysort(d) ;
	cout << d.at(n/2)-d.at(n/2-1) << endl ;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105],sum=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        cin>>a[i];
        sum+=a[i];
    }
    cin>>m;
    while(m--)
	{
        int p,x;
        cin>>p>>x;
        cout<<sum-a[p]+x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long vc=1000000007,h,w,n,node[1000010],a,b,cnt,z,ans[11],i,j,t;
int main(){
	cin>>h>>w>>n;
	z=(h-2)*(w-2);
	while(n--){
		cin>>a>>b;
		for(i=-2;i<=0;i++){
			for(j=-2;j<=0;j++){
				if(a+i>=1&&a+i<=h-2&&b+j>=1&&b+j<=w-2){
					node[cnt++]=vc*(a+i)+(b+j);
				}
			}
		}
	}
	sort(node,node+cnt);
	for(i=0,t=1;i<cnt;i++){
		if(node[i]==node[i+1])t++;
		else{
			ans[t]++;
			z--;
			t=1;
		}
	}
	cout<<z<<"\n";
	for(i=1;i<10;i++)cout<<ans[i]<<"\n";
}


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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 1e5 )+10;
const int MOD  = int( 360 );
const int oo   = INT_MAX;

int n;
ll arr[ MAXN ];

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif

  while( cin >> n ) {
    for( int i = 0; i < n; ++i ) cin >> arr[i];
    sort(arr, arr+n);
    ll a = 0LL, b = 0LL;
    for( int i = n-1; i > 0; --i ) {
      if( a == 0LL ) {
        if( arr[ i ] == arr[ i-1 ] ) {
          a = arr[ i ];
          --i;
        }
      }
      else if( b == 0LL ) {
        if( arr[ i ] == arr[ i-1 ] )
          b = arr[ i ];
      }
    }
    cout << a*b << '\n';
  }

  return 0;
}


Measured memory_bytes: 1024
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> vec(N);
    for(int i=0; i<N; i++) {
        cin >> vec[i];
    }

    vector<int> ans;
    priority_queue<int> pre, suf;
    for(int i=0; i<N; i++) {
        pre.push(vec[i]);
        suf.push(vec[N-i-1]);

        while(pre.size() && suf.size()) {
            if(pre.top() != suf.top()) break;
            pre.pop(); suf.pop();
        }

        if(pre.empty() && suf.empty()) ans.push_back(i+1);
    }

    for(size_t i=0; i<ans.size(); i++) {
        printf("%lld%c", ans[i], (i+1==ans.size() ? '\n' : ' '));
    }
    return 0;
}


Measured memory_bytes: 5084
def main():
    from sys import stdin
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]

    a, b = map(int, r.split())
    if (a*b)%2 == 0:
        print("No")
    else:
        print("Yes")

if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
#include <iostream>
#include <string> 
#include <stdio.h>
using namespace std; 
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define ll long long int
#define REPI(a, b, i, inc) for(ll i = a; i < b; i = i + inc)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define test ll t; cin>>t; while(t--)
#define testi ll t; cin>>t; REP(tc,1,t+1)
#define vec vector
#define veci vector<ll>
#define pi pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define uset unordered_set
#define umap unordered_map

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("op.txt","w",stdout);
    #endif
	
	
	int n; 
	cin>>n;
	if(n>=400 && n<=599)
		cout<<"8";
	if(n>=600 && n<=799)
		cout<<"7";
	if(n>=800 && n<=999)
		cout<<"6";
	if(n>=1000 && n<=1199)
		cout<<"5";
	if(n>=1200 && n<=1399)
		cout<<"4";
	if(n>=1400 && n<=1599)
		cout<<"3";
	if(n>=1600 && n<=1799)
		cout<<"2";
	if(n>=1800 && n<=1999)
		cout<<"1";


	
	return 0;


}

Measured memory_bytes: 3636
num,total = map(int,input().split())
for i in range(num+1):
    for j in range(num-i+1):
        if i*10000 + j*5000 + (num-i-j)*1000 == total:
            print(i,j,num-i-j)
            exit()
print("-1 -1 -1")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;

int main() {
  cin >> N;
  int ans = 0;
  rep(i, N) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }

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


Measured memory_bytes: 256
N = gets.to_i
A = N.times.map{gets.to_i}

max = A.max
b = A.dup
b.delete(max)
next_max = b.max

only_one = A.one? {|a| a == max}

N.times do |i|
  if max > A[i]
    puts max
  else
    if only_one
	  puts next_max
    else
      puts max
    end
  end
end

Measured memory_bytes: 7476
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;

int ans;
signed main(){
	
    int r,g,b,n;
    cin>>r>>b>>g>>n;
    int sum=0;
    for(int i=0;i<=n/r;i++){
        for(int j=0;j<=n/b;j++){
            sum=r*i+b*j;
            if(sum<=n && (n-sum)%g==0){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(stdin) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputs = stdin.split("\n");
  inputs.forEach(input => {
    if (input === "ABC") {
      console.log("ARC");
    }
    if (input === "ARC") {
      console.log("ABC");
    }
  });
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29636
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
template <class Key, class Compare = less<Key>>
using Tree = tree<Key, null_type, Compare, rb_tree_tag, tree_order_statistics_node_update>;



void Main() {
  int n;
  cin >> n;
  vector<ll> a(n), p(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    p[i] = a[i];
    if (i > 0) p[i] += p[i-1];
  }
//  cout << "a: "; for (int i=0;i<n;++i){cout<<a[i]<<' ';}cout<<'\n';
//  cout << "p: "; for (int i=0;i<n;++i){cout<<p[i]<<' ';}cout<<'\n';
  ll ans = 1e17;
  for (int j = 1; j < n-1; ++j) {
    auto it = lower_bound(p.begin(), p.begin()+j, p[j]/2);
    int i = distance(p.begin(), it);
    if (i == j) {
      --i;
    }
    if (it != p.begin()) {
      ll opt1 = abs(p[j] - 2*p[i]);
      ll opt2 = abs(p[j] - 2*p[i-1]);
      if (opt2 < opt1) --i;
    }
    it = lower_bound(p.begin()+j+1, p.end(), (p[n-1] + p[j]) / 2);
    int k = distance(p.begin(), it);
    if (k == n) {
      --k;
    }
    if (k-1 > j) {
      ll opt1 = abs(p[n-1] + p[j] - 2*p[k]);
      ll opt2 = abs(p[n-1] + p[j] - 2*p[k-1]);
      if (opt2 < opt1) --k;
    }
    ll P = p[i];
    ll Q = p[j] - p[i];
    ll R = p[k] - p[j];
    ll S = p[n-1] - p[k];
    ans = min(ans, max({P, Q, R, S}) - min({P, Q, R, S}));
//    cout << "i=" << i << " j=" << j << " k=" << k << "; P=" << P << " Q=" << Q << " R="<<Q<<" S="<<S<<'\n';
  }
  cout << ans << '\n';
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef _DEBUG
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  #endif
  Main();
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <map>
#include <queue>
#include <stack>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3>=22)  cout << "bust" << endl;
    else cout << "win" << endl;
    
    return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	int a,b,c,d;
	int e=0;

	cin>>a;
	cin>>b;
	cin>>c;
	cin>>d;

	if(a<b){
		e=e+a;
	}else{
		e=e+b;
	}
	if(c<d){
		e=e+c;
	}else{
		e=e+d;
	}

	cout<<e<<endl;

	return 0;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

int n;
int solve()
{
	int ret = 1, maxDiv = 0;
	for(int i = 1; i <= n; ++i)
	{
		int div = 0, tmp = i;		
		while(tmp % 2 == 0)
			++div, tmp /= 2;
		
		if(div > maxDiv)
		{
			maxDiv = div;
			ret = i;
		}
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int d = scanner.nextInt();
			if (d == 0)
				break;
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			int[] num = new int[n + 1];
			for (int i = 1; i < n; i++)
				num[i] = scanner.nextInt();
			num[n] = d;
			Arrays.sort(num);
			int ans = 0;
			while (m-- > 0) {
				int k = scanner.nextInt();
				int pos = Arrays.binarySearch(num, k);
				if (pos < 0) {
					pos = -pos - 2;
					ans += Math.min(k - num[pos], num[pos + 1] - k);
				}
			}
			System.out.println(ans);
		}
	}
}

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

const ll INF = 1001001001001;

int main(){
  int n;
  cin >> n;
  vector<int> h(n+1);
  rep(i,n) cin >> h[i+1];
  vector<ll> dp(n+1,INF);
  dp[0] = 0; dp[1] = 0;
  for(int i=2; i<=n; ++i) {
    dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
    if (i==2) continue;
    dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
  }
  // for(auto m : dp) cout << m << " ";
  // cout << endl;
  cout << dp[n] << endl;
  return 0;
}

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

int main() {
  int N,i,s=0;
  cin >> N;
  vector<int> a(N);
  for(i=0;i<N;i++) cin >> a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  if(N%2==1) a.push_back(0);
  for(i=0;i<(N+1)/2;i++){
    s += a.at(2*i)-a.at(2*i+1);
  }
  cout << s << endl;
}

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

int main(){
    int N;
    string S;

    cin >> N;
    cin >> S;

    // S0をリーダーに指名したとき
    int tmp_ans = 0;
    for(int i = 1; i < N; i++) {
        if(S[i] == 'E') {
            tmp_ans++;
        }
    }

    // リーダーを変更して最小を求める
    int ans = tmp_ans;
    int w_p = 0;
    int e_p = tmp_ans;
    for(int i = 2; i <= N; i++) {
        if(S[i - 1] == 'E') {
            e_p--;
        }
        if(S[i - 2] == 'W') {
            w_p++;
        }

        ans = min(ans, w_p + e_p);
    }

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


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

public class Hello{
    public static void Main(){
        // Your code here!
        while(true){
            int[] r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (r[0] == 0 && r[1] == 0){
                break;
            }
        
            int n = r[0];
            int x = r[1];
        
            int count = 0;
        
            for(int i=1;i<=n-2;i++){
                for(int j=i+1;j<=n-1;j++){
                    for(int k=j+1;k<=n;k++){
                        if(i+j+k==x){
                            count++;
                        }
                    }
                }
            }
        
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 16332
const main = (input) => {
  const s = input.trim()

  const palindrome = (text) => {
    const re = Array.from(text).reverse()
    return re.every((v, i) => v === text[i])
  }

  return console.log(palindrome(s) && palindrome(s.slice(0, Math.floor(s.length/2))) ? 'Yes' : 'No')
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

bool isPrime(int n);

int n;

int main(){
    scanf("%d", &n);
    printf("%d:",n);
    vector<int> v;

    if(isPrime(n)){
        printf(" %d\n",n);
        return 0;
    }

    while(n%2 == 0){
        v.push_back(2);
        n /= 2;
    }
    for(int i = 3; i <= n; i += 2){
        while(n%i == 0){
            v.push_back(i);
            n/=i;
        }
    }

    for(int i = 0; i < v.size(); i++){
        cout << " " << v[i];
    }
    cout << endl;

    return 0;
}

bool isPrime(int n){
    if(n < 2) return false;
    if(n == 2) return true;
    if(n%2 == 0) return false;
    for(int i = 3; i*i <= n; i+=2){
        if(n%i == 0) return false;
    }
    return true;
}


Measured memory_bytes: 3300
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
vll vec[200005];
bool vis[200005];
ll cc=0;
void dfs(ll node)
{
    vis[node]=true;
    for(auto x:vec[node])
    {
        if(!vis[x])
        {
            cc++;
            dfs(x);
        }
    }
}
int main()
{
    fio;
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        rep(i,m)
        {
            ll a,b;
            cin>>a>>b;
            vec[a].pb(b);
            vec[b].pb(a);
        }
        memset(vis,false,sizeof(vis));
        ll mx=INT_MIN;
        for(int i=1;i<=n;i++)
        {
            if(!vis[i])
            {
                mx=max(mx,cc);
                cc=0;
                dfs(i);
            }
        }
        mx=max(mx,cc);
        cout<<mx+1<<endl;
    }
}

Measured memory_bytes: 24008
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); 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 IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

char field[30][30];

int main(){
  int n;
  bool isSen[128] = {false};
  int  direct[128] = {0};
  int  toDirect[128] = {0};
  char toStr[5] = "^>v<";
  int cc = 0;
  isSen['>'] = isSen['^'] = isSen['v'] = isSen['<'] = true;
  direct['>'] = 1; direct['^'] = 0; direct['v'] = 2; direct['<'] = 3;
  toDirect['R'] = 1; toDirect['U'] = 0; toDirect['D'] = 2; toDirect['L'] = 3;
  toDirect['S'] = 4;

  scanf("%d",&n);
  while(n --> 0){
    int h,w;
    char buff[128];
    int c;
    int sx, sy;
    if(cc++ != 0) puts("");
    scanf("%d%d ",&h,&w);
    REP(i,h) fgets(field[i],sizeof(field[i]),stdin);
    scanf("%d ",&c);
    fgets(buff,sizeof(buff),stdin);
    REP(i,h) REP(j,w) if(isSen[field[i][j]]){
      sx = j; sy = i;
      break;
    }
    REP(i,c){
      int d = toDirect[buff[i]];
      //printf("d = %d:\n",d);
      if(d == 4){
        int dx = _dx[direct[field[sy][sx]]];
        int dy = _dy[direct[field[sy][sx]]];
        int tx = sx + dx;
        int ty = sy + dy;
        //printf("direct = %d, dx = %d, dy = %d\n", direct[field[sy][sx]], dx, dy);
        while(ISIN(tx,ty,w,h) && (field[ty][tx] == '.' || field[ty][tx] == '-')){
          tx += dx;
          ty += dy;
        }
        if(ISIN(tx,ty,w,h)){
          //printf("tx = %d, ty = %d, hit %c\n",tx,ty,field[ty][tx]);
          if(field[ty][tx] == '*')
            field[ty][tx] = '.';
        }
        //REP(i,h) printf("%s",field[i]);
      }else{
        int xx = sx + _dx[d];
        int yy = sy + _dy[d];

        if(ISIN(xx,yy,w,h) && field[yy][xx] == '.'){
          field[sy][sx] = '.';
          sx = xx; sy = yy;
        }

        field[sy][sx] = toStr[d];
      }
    }
    REP(i,h) printf("%s",field[i]);
  }
  return 0;
}

Measured memory_bytes: 0
li=list(map(int,input().split()))
sum=0
for i in range(1,li[0]+1):
    z=i//10000
    a=i//1000%10
    b=i//100%10
    c=i//10%10
    d=i%10
    s=z+a+b+c+d
    if li[1]<=s<=li[2]:
        #print(i)
        sum+=i
print(sum)



Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  string s,t;
  cin >> s >> t;
  
  REP(i, s.length()){
    bool f = true;
    REP(j, s.length()){
      f &= t[j] == s[j];
    }
    if(f) {
      cout << "Yes" << endl;
      return 0;
    }
    s = s[s.length() - 1] + s;
    s = s.substr(0, s.length() - 1);
  }

  cout << "No" << 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 REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  int n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n)cin >> a[i];
  ll ans = 0,maxd = a[0];
  REP(i,1,n){
    if(maxd > a[i]){
      ans += maxd - a[i];
      maxd = maxd;
    }
    else maxd = a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4788
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int cnt = 0;
		
		int[][] point = new int[n][d];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = stdIn.nextInt();
			}
		}
		
		
		for(int i = 0; i < n-1; i++) {
			
			for(int j = i+1; j < n; j++) {
				int distance = 0;
				for(int k = 0; k < d; k++) {
				distance += (point[j][k] - point[i][k])*(point[j][k] - point[i][k]);
				}
				if(Math.sqrt(distance)==(int)Math.sqrt(distance)){
					//System.out.println(distance);
					cnt++;
				}
			}
		}
		
		System.out.println(cnt);
		
		
		
		
		
		
		
	}

}


Measured memory_bytes: 21972
from collections import deque
H,W=map(int,input().split())
mp=[['#']*(W+2)]
count=0
for _ in range(H):
    l=list(input())
    mp.append(['#']+l+['#'])
    count+=l.count('.')
mp.append(['#']*(W+2))

dist=[[-1]*(W+2)for _ in range(H+2)]
Q=deque()
Q.append((1,1))
dist[1][1]=1
f=False

while Q:
    y,x=Q.popleft()
    if (y,x)==(H,W):
        f=True
        break
    for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]:
        ny=y+dy
        nx=x+dx
        if 0<=ny<H+2 and 0<=nx<W+2:
            if mp[ny][nx]=='.' and dist[ny][nx]==-1:
                Q.append((ny,nx))
                dist[ny][nx]=dist[y][x]+1

if f:
    print(count-dist[H][W])
else:
    print(-1)

Measured memory_bytes: 9512
n = int(input())
a = list(map(int,input().split()))
d = dict() 
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
s = sum(a)
for _ in range(int(input())):
  b, c = map(int, input().split())
  if b in d:
    s += ((c - b) * d[b])
    if c in d:
      d[c] += d[b]
    else:
      d[c] = d[b]
    d[b] = 0
  print(s)

Measured memory_bytes: 93352
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;
/* c++11
#include <tuple>
using std::tuple; 
using std::make_tuple;
using std::get; // tuple std::get<NUM>(t); (0 <= NUM <= 2)
 */

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

void j(string &s) {
    int length = s.length();
    s = s.substr(length - 1, 1) + s.substr(0, length - 1);
    return;
}

void c(string &s) {
    int length = s.length();
    s = s.substr(1, length - 1) + s.substr(0, 1);
    return;
}

void e(string &s) {
    int length = s.length();
    if (length % 2 == 0) {
        s = s.substr(length / 2, length / 2) + s.substr(0, length / 2);
    } else {
        s = s.substr(length / 2 + 1, length / 2) + s.substr(length / 2, 1) + s.substr(0, length / 2);
    }
    return;
}
void a(string &s) {
    reverse(s.begin(), s.end());
    return;
}

void p(string &s) {
    int length = s.length();
    for (int i = 0; i < length; i++) {
        if (s[i] > '0' && s[i] <= '9') {
            s[i]--;
        } else if (s[i] == '0') {
            s[i] = '9'; 
        }
    }
    return;
}

void m(string &s) {
    int length = s.length();
    for (int i = 0; i < length; i++) {
        if (s[i] >= '0' && s[i] < '9') {
            s[i]++;
        } else if (s[i] == '9') {
            s[i] = '0'; 
        }
    }
    return;
}

int main(void) {
    int n;
    cin >> n;
    string order;
    string mess;
    for (int loop = 0; loop < n; loop++) {
        cin >> order >> mess;
        int order_length = order.length();
        for (int i = order_length - 1; i >= 0; i--) {
            if (order[i] == 'J') {
                j(mess);
            } else if (order[i] == 'C') {
                c(mess);
            } else if (order[i] == 'E') {
                e(mess);
            } else if (order[i] == 'A') {
                a(mess);
            } else if (order[i] == 'P') {
                p(mess);
            } else if (order[i] == 'M') {
                m(mess);
            }
        }
        cout << mess << endl;
    }
    return 0;
}

Measured memory_bytes: 3008
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		if (-1000 > a || a > 1000 || b < -1000 || b > 1000) {
			System.out.println("有効範囲は-1000=<a,b<=1000です。");
			;
		} else if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}

}



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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N,K;
    string S;
    cin >> N>>K;

    ll ans = 0;

    vector<ll> vec(N+2);
    REP(i,N+1){
        vec.at(i) = i;
    }

    for (ll i = K; i <= N+1; i++) {
        ans+=i*(N+1-i)+1;
        ans %= MOD;
    }
    cout << ans%MOD << endl;
}


Measured memory_bytes: 4660
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  ll n, x;
  cin >> n >> x;
  ll a[n];
  cin >> a[0];
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ll count = 0;
    cin >> a[i];
    if (a[i] + a[i - 1] > x) {
      count = a[i] + a[i - 1] - x;
      if (count <= a[i]) a[i] -= count;
      else a[i] = 0;
    }
    ans += count;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n;cin>>n;
  vector<ll>vi(n);
  ll ans=0;
  for(auto &a:vi)cin>>a;
  sort(vi.begin(),vi.end(),greater<ll>());
  for(int i=0;i<n;i++){
	if(i%2)ans-=vi[i];
    else ans+=vi[i];
  }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
let h = ref 0

let parent i = int_of_float (floor (float_of_int i) /. 2.)

let left i = 2*i

let right i = 2*i + 1

let extract (t : int array) =
  let rec max_heapify i =
    let l = left i in
    let r = right i in
    let m = if l <= !h && t.(l) > t.(i) then l else i in
    let m = if r <= !h && t.(r) > t.(m) then r else m in
    if m <> i then begin
      let tmp = t.(i) in t.(i) <- t.(m); t.(m) <- tmp;
      max_heapify m
    end
  in
  let ret = t.(1) in
  t.(1) <- t.(!h);
  decr h;
  max_heapify 1;
  ret

let insert x (t : int array) =
  incr h;
  t.(!h) <- x;
  let rec doit i =
    if i > 1 && t.(parent i) < t.(i) then begin
      let tmp = t.(i) in
      t.(i) <- t.(parent i);
      t.(parent i) <- tmp;
      doit (parent i)
    end
  in
  doit !h

let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s1 (s2 :: acc)
  in
  doit str []

let () =
  let t = Array.make 2000001 0 in
  let rec doit () =
    match split (read_line ()) ' ' with
    | ["insert"; n] -> (insert (int_of_string n) t; doit ())
    | ["extract"] -> (Printf.printf "%d\n" (extract t); doit ())
    | _ -> ()
  in
  doit ()

Measured memory_bytes: 20272
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
const ll INF= 1LL<<60-1;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}

// head


int m,n,k,res,tmp,tmp2,tmp3,h,w,x,y;
VI a;
deque<PII> que;
string s;
//VI b;
vector<PII> g[2100600];
int b[2100000];
int c[210000] = {};
int rui[210000];
set<int> ch;



signed main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  rep(i,0,n){cin>>b[i];}
  sort(b,b+n);
  VPII ans;
  if (b[n-1] <=0){
    res = 0;
    rep(i,0,n-1) res -=b[i];
    res += b[n-1];
    cout << res << '\n';
    res = b[n-1];
    rep(i,0,n-1){
      cout << res <<" "<<b[i]<< '\n';
      res -= b[i];
    }
  }
  else if (b[0] >= 0){
    res = 0;
    rep(i,1,n) res +=b[i];
    res -= b[0];
    cout << res << '\n';
    res = b[0];
    rep(i,1,n-1){
      cout << res <<" "<<b[i]<< '\n';
      res -= b[i];
    }    
    cout << b[n-1] <<" "<<res<< '\n';
  }
  else{
    res = -b[0];
    res += b[n-1];
    int i = n-2;
    while(b[i]>=0){
      res += b[i];
      i-=1;
    }
    while(i>=1){
      res -= b[i];
      i-=1;
    }
    cout << res << '\n';
    i = n-2;
    res = b[0];
    while(b[i]>=0){
      cout << res <<" "<<b[i]<< '\n';
      res -= b[i];
      i-=1;
    } 
    cout << b[n-1] <<" "<<res<< '\n';
    res = b[n-1] - res;
    while(i>=1){
      cout << res <<" "<<b[i]<< '\n';
      res -= b[i];
      i-=1;
    }

  }



}

Measured memory_bytes: 54528
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
   ll n;
   cin>>n;
   if(n<10)cout<<n<<endl;
   else if(n<100)cout<<9<<endl;
   else if(n<1000)cout<<9+n-99<<endl;
   else if(n<10000)cout<<9+900<<endl;
   else if(n<100000)cout<<9+900+n-9999<<endl;
   else cout<<9+900+90000<<endl;
   
}
   



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

using namespace std;
typedef long long ll;

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

  vector<ll> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }

  ll ans = 1LL << 62;
  for (int l = 0; l < n; l++) {
    for (int r = 0; r < n; r++) {
      for (int d = 0; d < n; d++) {
        for (int u = 0; u < n; u++) {
          if (min(x[d], x[u]) < x[l]) continue;
          if (max(x[d], x[u]) > x[r]) continue;
          if (min(y[l], y[r]) < y[d]) continue;
          if (max(y[l], y[r]) > y[u]) continue;
          if (!(x[l] < x[r] && y[d] < y[u])) continue;
          int cnt = 0;
          for (int i = 0; i < n; i++) {
            cnt += (x[l] <= x[i] && x[i] <= x[r] && y[d] <= y[i] && y[i] <= y[u]);
          }
          if (cnt < K) continue;
          ans = min(ans, (x[r] - x[l]) * (y[u] - y[d]));
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256