akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
	int n,a,b,c,d,orz;
	while(scanf("%d",&n)!=EOF){
		orz=0;
	for(a=0;a<=9;a++){
		for(b=0;b<=9;b++){
			for(c=0;c<=9;c++){
				for(d=0;d<=9;d++){
					if(a+b+c+d==n){orz++;}
				}
			}
		}
	}
			printf("%d\n",orz);
	}

	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 

using namespace std;

int main(){

    int n;
    ll t;

    cin >> n >> t;

    ll before;
    cin >> before;

    ll sumt = 0;

    rep(i,n - 1){
        ll after;
        cin >> after;
        if(after - before <= t){
            sumt = sumt + (after - before);
        }else{
            sumt = sumt + t;
        }

        before = after;

    }

    sumt = sumt + t;

    cout << sumt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int n;
int d[2][100000];
vector<int> gragh[100000];

void dfs(int pos, int same, int dist, int color) {
	d[color][pos] = dist;
	rep(i, gragh[pos].size()) {
		if (gragh[pos][i] == same) continue;
		dfs(gragh[pos][i], pos, dist + 1, color);
	}
}

int main()
{
	cin >> n;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		gragh[a].push_back(b);
		gragh[b].push_back(a);
	}
	dfs(0, -1, 0, 0);
	dfs(n - 1, -1, 0, 1);
	int black = 0, white = 0;
	rep(i, n) {
		if (d[0][i] <= d[1][i]) {
			black++;
		}
		else {
			white++;
		}
	}
	cout << (black > white ? "Fennec" : "Snuke") << endl;
	return 0;
}

Measured memory_bytes: 14336
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next() + " ";
        int counter = 0;
        for (int i = 0; i <= N - 3; i++) {
            if (S.substring(i, i + 3).equals("ABC") == true) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
}

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

int main() {
  int n;cin>>n;
  int cnt=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        cnt+=gcd(i,gcd(j,k));
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
int main(){
	int n,h,cnt[3][2],out[3][2],i,j,k,l,list[100],a,b,sum=0;
	scanf("%d %d",&n,&h);
	for(i=0;i<n;i++){
		list[i]=-1;
	}
	for(i=0;i<h;i++){
		scanf("%d %d",&a,&b);
		a--;
		b--;
		list[a]=b;
	}
	memset(cnt,0,sizeof(cnt));
	for(i=0;i<n;i++){
		memset(out,0,sizeof(out));
		if(i==0){
			if(list[i]>=0){
				out[list[i]][0]=1;
			}
			else{
				for(j=0;j<3;j++){
					out[j][0]=1;
				}
			}
		}
		else{
			if(list[i]>=0){
				for(j=0;j<3;j++){
					for(k=0;k<2;k++){
						if(list[i]!=j){
							out[list[i]][0]+=cnt[j][k];
						}
					}
				}
				out[list[i]][1]=cnt[list[i]][0];
			}
			else{
				for(l=0;l<3;l++){
					for(j=0;j<3;j++){
						for(k=0;k<2;k++){
							if(l!=j){
								out[l][0]+=cnt[j][k];
							}
						}
					}
					out[l][1]=cnt[l][0];
				}
			}
		}
		for(j=0;j<3;j++){
			for(k=0;k<2;k++){
				if(out[j][k]>=10000){
					out[j][k]%=10000;
				}
				cnt[j][k]=out[j][k];
			}
		}
		
	}
	for(i=0;i<3;i++){
		for(j=0;j<2;j++){
			sum+=out[i][j];
			if(sum>=10000){
				sum%=10000;
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
#include <iomanip>
using namespace std;

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long
#define vi vector<int>

bool isMonth(int n)
{
    return (1 <= n && n <=12);
}

int main(){
    LL n,k;
    long double sum = 0;
    long double s =1;

    cin >> n >> k;

    REP(i,n){
        LL l = 0;
        LL t = i + 1;
        while(t < k){
            l++;
            t *= 2;
        }
        sum += powl(0.5, l);
    }
    sum /= n;
    //double d = sum / s;

    cout << std::setprecision(12) <<sum << endl;

    return 0;
     
}


    
  
  

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL  INF=1<<31;
const LL MOD=1000000007;



int main(){
     int a,b;
     cin>>a>>b;
     if(a==b)cout<<"Draw"<<endl;
     else if(a==1)cout<<"Alice"<<endl;
     else if(b==1)cout<<"Bob"<<endl;
     else if(a>b)cout<<"Alice"<<endl;
     else cout<<"Bob"<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int H, W, c;
	cin >> H >> W;
	vector<string> s(H);
	vector<vector<int>> tate(H, vector<int>(W, 0)), yoko(H, vector<int>(W, 0));
	rep(i, 0, H)cin >> s[i];
	rep(y, 0, H) {
		rep(x, 0, W) {
			if (s[y][x] == '#')continue;
			if (x && yoko[y][x - 1]) {
				yoko[y][x] = yoko[y][x - 1];
			}
			else{
				c = 0;
				rep(i, x, W) {
					if (s[y][i] == '#')break;
					c++;
				}
				yoko[y][x] = c;
			}
		}
	}
	rep(y, 0, H) {
		rep(x, 0, W) {
			if (s[y][x] == '#')continue;
			if (y && tate[y - 1][x]) {
				tate[y][x] = tate[y - 1][x];
			}
			else {
				c = 0;
				rep(i, y, H) {
					if (s[i][x] == '#')break;
					c++;
				}
				tate[y][x] = c;
			}
		}
	}
	int M = 0;
	rep(y, 0, H) {
		rep(x, 0, W) {
			//printf("%2d ", tate[y][x] + yoko[y][x] - 1);
			M = max(M, tate[y][x] + yoko[y][x] - 1);
		}
		//puts("");
	}
	printf("%d\n", M);
	return 0;
}

Measured memory_bytes: 35712
#include <stdio.h>

int main(void)
{
    int n, x;
    scanf("%d%d", &n, &x);

    int i, m, min = 1001, ans = n;
    for (i = 0; i < n; ++i) {
        scanf("%d", &m);
        x -= m;
        if (min > m) min = m;
    }
    ans += x / min;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
import math
import itertools

num = input()
ans = num

keta = int(math.log10(num) + 1)
s = [i for i in range(keta - 1)]

number = []
while num > 0:
    number.append(num % 10)
    num = int(num / 10)
number.reverse()

combination = []
for i in range(1, keta):
    combination.extend(list(itertools.combinations(s, i)))

for i in combination:
    temp = 0
    for j in range(keta):
        if j not in i:
            temp = temp * 10 + number[j]
        else:
            ans += temp * 10 + number[j]
            temp = 0
    ans += temp

print ans

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

int main(){
  int a,b;
  string s;
  cin >> a >> b;
  s = a%3==0 ? "Possible" : b%3==0 ? "Possible" : (a+b)%3==0 ? "Possible":"Impossible";
  cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int h,w;
string G[51];
bool checked[51][51];
bool visited[51][51];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

/*
void dfs(int x,int y,char c,int &x1,int &x2,int &y1,int &y2)
{
  if(visited[y][x])return;
  visited[y][x] = true;
  if(x < x1)x1 = x;
  if(x > x2)x2 = x;
  if(y < y1)y1 = y;
  if(y > y2)y2 = y;
  rep(i,4)
    {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
      if(G[ny][nx] != c)continue;
      dfs(nx,ny,c,x1,x2,y1,y2);
    }
}
*/
bool isRect(int x,int y)
{
  int x1,x2,y1,y2;
  x1 = x2 = x;
  y1 = y2 = y;
  //rep(i,h)rep(j,w)visited[i][j] = false;
  //dfs(x,y,G[y][x],x1,x2,y1,y2);
  rep(i,h)
    rep(j,w)
    {
      if(G[i][j] == G[y][x])
	{
	  if(j < x1)x1 = j;
	  if(j > x2)x2 = j;
	  if(i < y1)y1 = i;
	  if(i > y2)y2 = i;
	}
    }

  REP(i,y1,y2+1)
    REP(j,x1,x2+1)
    if(G[i][j] != G[y][x] && !checked[i][j])return false;
  return true;

}

void draw(int x,int y,char c)
{
  if(checked[y][x])return;
  checked[y][x] = true;
  rep(i,4)
    {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
      if(G[ny][nx] != c)continue;
      draw(nx,ny,c);
    }
}

bool isSafe()
{
  rep(i,h)
    rep(j,w)
    if(G[i][j] != '.' && !checked[i][j])return false;
  return true;
}

int main()
{
  int T;
  cin >> T;
  while(T-- > 0)
    {
      cin >> h >> w;
      rep(i,h)
	cin >> G[i];
      rep(i,51)rep(j,51)checked[i][j] = false;

      while(true)
	{
	  bool Fin = true;
	  bool update = false;
       
	  rep(i,h)
	    {	
	      rep(j,w)
		{
		  if(G[i][j] == '.')continue;
		  if(checked[i][j])continue;
		  Fin = false;
		  if(isRect(j,i))
		    {
		      update = true;
		      draw(j,i,G[i][j]);
		    }
		}
	    }
	  if(Fin || !update)break;
	}
   
      isSafe()?cout << "SAFE" << endl:cout << "SUSPICIOUS" << endl;
    }
  return 0;
}

Measured memory_bytes: 1328
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        Console.ReadLine(); //使わない
        var N = array[0];
        var K = array[1];
        var tmp = K;
        var count = 1;
        while(tmp < N)
        {
            tmp += K - 1;
            count++;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 14816
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <utility>
#define N 120
using namespace std;

pair<int, int> a[N];

int main(void)
{
    int n;
    int i, k, x, y;
    long long o;

    scanf("%d", &n);
    for(i = 0; i < n; i ++)
        scanf("%d %d", &a[i].first, &a[i].second);

    for(k = o = 0; k < 100000; k ++)
    {
        random_shuffle(a, a + n);
        for(i = x = y = 0; i < n; i ++)
            if((long long)(x + a[i].first) * (x + a[i].first) + (long long)(y + a[i].second) * (y + a[i].second) > (long long)x * x + (long long)y * y)
            {
                x += a[i].first ;
                y += a[i].second;
            }
        o = max(o, (long long)x * x + (long long)y * y);
    }
    printf("%.15Lf\n", sqrt((long double)o));

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int a, b;
  cin>>a;
  cout<<a*800-a/15*200<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	int a,b,ans=0;
	cin>>a>>b>>s;
	if(s[a]=='-'){
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='-')ans++;
		if(ans==2){
			cout<<"No"<<endl;
			return 0;
		}
	}
	}else{
		cout<<"No"<<endl;
		return 0;
	}
	ans==1 ? cout<<"Yes"<<endl : cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
  int d, t, s;
  scanf("%d %d %d", &d, &t, &s);
  
  if (d <= t*s){
  	printf("Yes\n");
  }else{
  	printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
vector<int> L;
int N, A, B, C;
#define inf 1000000000
int dfs(int n, int a, int b, int c) {
	if (n == N) {
		if (min(a, min(b, c)) == 0) {
			return inf;
		}
		else {
			return abs(a - A) + abs(b - B) + abs(c - C) - 30;
		}
	}
	int cost0, cost1, cost2, cost3;
	cost0= dfs(n + 1, a, b, c);
	cost1=dfs(n + 1, a + L[n], b, c)+10;
	cost2=dfs(n + 1, a, b + L[n], c)+10;
	cost3=dfs(n + 1, a, b, c + L[n])+10;
	return min(cost0, min(cost1, min(cost2, cost3)));
}

int main()
{
	
	cin >> N >> A >> B >> C;

	int l;
	for (int i = 0; i < N; i++) {
		cin >> l;
		L.push_back(l);
	}
	cout << dfs(0, 0, 0, 0);


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

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 T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	s.pop_back();
	while(s.size()){
		if(s.size()%2){
			s.pop_back();
			continue;
		}
		string t=s.substr(0,s.size()/2);
		if(s==t+t){
			cout<<s.size()<<endl;
			return 0;
		}
		s.pop_back();
	}
}

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

using namespace std;

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

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;


    int x3 = x2 - (y2 - y1);
    int y3 = y2 + (x2 - x1);
    int x4 = x3 - (x2 - x1);
    int y4 = y3 - (y2 - y1);

    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define VALS(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define INF 1234567890ll
#define LLINF 123456789987654321L
#define EPS (1e-7)
#define PI (acos((ld)-1.0))
#define ll long long int 
#define ld long double
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
typedef pair <int, int> pi;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << '\n'; err(++it, args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string lts(ll x){stringstream s; s << x; return s.str(); }
ll stl(string x){stringstream s(x); ll temp; s >> temp; return temp; }
const int MOD = 1e9 + 7;


ll val[505], weight[505], dp[100005];

int main()
{
	IAMSPEED
    ll n, w;
    cin >> n >> w;
    vector <int> weight(n), value(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> weight[i] >> val[i];
    }
    int sumval = 0;
    for (int x: val) {
		sumval+=x;
	}
	vector<ll> dp(sumval+1, LLINF);
	dp[0]=0;
	FOR(i,0,n-1) {
		DEC(valalr, sumval-val[i],0) {
			dp[valalr+val[i]] = min(dp[valalr+val[i]], dp[valalr]+weight[i]);
		}
	}
	ll ans=0;
	for (int i = 0; i <= sumval; ++i) {
		if (dp[i] <= w) {
			ans = max(ans, (ll)i);
		}
	}
	cout << ans;
}

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

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

    do{
        printf("%d", a[0]);
        for(int i = 1; i < n; i++)  printf(" %d", a[i]);
        printf("\n");
    }while(next_permutation(a, a+n));

    return 0;
}


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

int main(){
    string s;
    cin>>s;
    int q;
    cin>>q;
    int t,f;
    char c;
    bool rev=false;
    string front{}, back{};
    rep(i, q){
        cin>>t;
        if(t==1) {
            if(rev) rev=false;
            else rev=true;
            continue;
        }
        cin>>f>>c;
        if((f==1&&!rev)||(f==2&&rev)) front.push_back(c);
        else back.push_back(c);
    }
    reverse(front.begin(),front.end());
    s=front+s+back;
    if(rev){
        rep(i, s.size()/2){
            char tmp=s[i];
            s[i]=s[s.size()-1-i];
            s[s.size()-1-i]=tmp;
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 4288
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<math.h>
#include<utility>
#include<iomanip>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	int ans = 1e9 + 5;
	vector<int> v(n);
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}

	for (int i = 1; i <= 100; i++) {
		int sum = 0;
		for (int j = 0; j < n; j++) {
			sum += (v[j] - i) * (v[j] - i);
		}
		ans = min(ans, sum);
	}

	cout << ans;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s == "RRR"){
    printf("3");
  }
  else if((s[0]=='R' && s[1]=='R' )||(s[1]=='R' && s[2]=='R' )){
    printf("2");
  }
  else if(s == "SSS"){
 	printf("0");
  }
  else{
    printf("1");
  }
  
}

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

int main() {
    int n,k;
   cin>>n>>k;
    vector<int> a(n);
    for(int& x : a) {
        scanf("%d", &x);
    }
    vector<bool> dp(k + 1);
    for(int stones = 0; stones <= k; ++stones) {
        for(int x : a) {
            if(stones >= x && !dp[stones-x]) {
                dp[stones] = true;
            }
        }
    }
 
    cout<<(dp[k] ? "First" : "Second");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.1416
///#define f(i,l,r) for(int i=l;i<=r;i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast;
    ll int i,j,k,sum=0,x,p=100,r,a,b,c=0;
    long double n,q=100;

    cin>>a;

    for(i=0;; i++)
    {
        if(p>=a)
            break;
        else
        {

            n=p*(1/q);
            p=p+n;
            c++;
        }

    }

    cout<<c<<endl;

    return 0;

}


Measured memory_bytes: 3640
#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 a, num;
    rep(i,5) {
        cin >> a;
        if (a == 0) num = i+1;
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
int J[1001][1001];
int O[1001][1001];
char str[1001][1001];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(str[i][j]=='J')J[i+1][j+1]++;
			if(str[i][j]=='O')O[i+1][j+1]++;
		}
	}
	for(int i=0;i<=a;i++){
		int p=0;
		int q=0;
		for(int j=0;j<=b;j++){
			J[i][j]=p+=J[i][j];
			O[i][j]=q+=O[i][j];
		}
	}
	for(int i=0;i<=b;i++){
		int p=0;
		int q=0;
		for(int j=0;j<=a;j++){
			J[j][i]=p+=J[j][i];
			O[j][i]=q+=O[j][i];
		}
	}
	for(int i=0;i<c;i++){
		int d,e,f,g;
		scanf("%d%d%d%d",&d,&e,&f,&g);
		int j=J[f][g]-J[d-1][g]-J[f][e-1]+J[d-1][e-1];
		int o=O[f][g]-O[d-1][g]-O[f][e-1]+O[d-1][e-1];
		printf("%d %d %d\n",j,o,(f-d+1)*(g-e+1)-j-o);
	}
}

Measured memory_bytes: 9496
//#include <bits/stdc++.h>
#include <iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector<long long>
#define  ii pair<int,int>
const long long mod = 1e9 + 7, inf = 1e9, linf = 1e18;
using namespace std;
#define pb push_back
#define mp make_pair
#define N 100005
using namespace std;
i64 f[N];
int main()
{
	int n;
	cin >> n;
	int m;
	cin >> m;
	f[0] = 1;
	for (int i = 0; i < m; i++)
	{
		int t;
		cin >> t;
		f[t] = -1;
	}
	for (int i = 1; i <= n; i++)
	{
		if (f[i] == -1)
		{
			f[i] = 0;
			continue;
		}
		if (i == 1)f[i] = f[i - 1]%mod;
		else
			f[i] = (f[i - 1] + f[i - 2])%mod;
	}
	cout << f[n];
}

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

// 插入此處

int main() {
    char s[5];
    scanf("%s", s);
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}


Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct SegmentTree {
	int n;
	vector<int>d, lazy;
	SegmentTree(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, 0);
		lazy.assign(2 * n, 0);
	}
	void eval(int k, int l, int r) {
		if (lazy[k] != 0) {
			d[k] += lazy[k];
			if (r - l > 1) {
				lazy[2 * k] += lazy[k] / 2;
				lazy[2 * k + 1] += lazy[k] / 2;
			}
			lazy[k] = 0;
		}
	}
	void add(int a, int b, int x, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] += (r - l)*x;
			eval(k, l, r);
		}
		else {
			add(a, b, x, 2 * k, l, (l + r) / 2);
			add(a, b, x, 2 * k + 1, (l + r) / 2, r);
			d[k] = d[2 * k] + d[2 * k + 1];
		}
	}
	int getSum(int a, int b, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return 0;
		if (a <= l&&r <= b)return d[k];
		else {
			int vl, vr;
			vl = getSum(a, b, 2 * k, l, (l + r) / 2);
			vr = getSum(a, b, 2 * k + 1, (l + r) / 2, r);
			return vl + vr;
		}

	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	SegmentTree seg(n);
	rep(i, 0, q) {
		int com; cin >> com;
		if (com) {
			int s, t; cin >> s >> t;
			cout << seg.getSum(s - 1, t) << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			seg.add(s - 1, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 7080
#include<cstdio>
#define re register
using namespace std;
int n,a,b,c,d;
signed main(){
b=1;
scanf("%d",&n);
while(n--){
	scanf("%d",&a);
	if(a!=b)++c;
	else ++b;
}
if(b>1)
printf("%d",c);
else puts("-1");
}


Measured memory_bytes: 128
n = gets.chomp.to_i
pn = gets.chomp.split(" ").map(&:to_i)

cnt = 0

for i in 1..n-2 do
    if pn[i-1] < pn[i] && pn[i] < pn[i+1]
        cnt += 1
    elsif pn[i-1] > pn[i] && pn[i] > pn[i+1]
        cnt += 1
    end
end

puts cnt

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> f(N+1);
  for (ll x = 1; x <= 100; x++) {
    for (ll y = 1; y <= 100; y++) {
      for (ll z = 1; z <= 100; z++) {
	ll n = x*x + y*y + z*z + x*y + y*z + z*x;
	if (n <= N) f.at(n)++;
      }
    }
  }
  for (ll i = 1; i <= N; i++) cout << f.at(i) << "\n";

  return 0;
}



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

ll count(ll x, ll n, ll m, vll &a) {
	ll ans = 0, j = n - 1;
	for (ll i = 0; i < n; i++) {
		while (j >= 0 && a[i] + a[j] >= x) j--;
		ans += min(n, n - 1 - j);
	}
	return ans;
}

//二分探索
//main関数で呼び出す前に，l, rの一方が条件を満たし他方が満たさないことを確認すること
//配列を引数にするときは原則として参照渡しすること
long long bs1(long long l, long long r, ll n, ll m, vll &a) {
	if (l + 1 == r) {
		if (count(r, n, m, a) >= m) return r;
		else return l;
	}

	long long mid = (l + r) / 2;
	if (count(mid, n, m, a) >= m) return bs1(mid, r, n, m, a);
	else return bs1(l, mid, n, m, a);
}

long long bs2(long long l, long long r, ll i, ll x, ll n, ll m, vll &a) {
	if (l + 1 == r) {
		if (a[i] + a[l] > x) return l;
		else return r;
	}

	long long mid = (l + r) / 2;
	if (a[i] + a[mid] > x) return bs2(l, mid, i, x, n, m, a);
	else return bs2(mid, r, i, x, n, m, a);
}

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

	ll n, m;
	cin >> n >> m;
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	sort(all(a));

	ll x = bs1(0, 1e10, n, m, a);

	vll b(n + 1, 0);
	for (ll i = 0; i < n; i++) b[i + 1] = b[i] + a[i];

	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] + a[0] > x) {
			ans += a[i] * n + b[n];
			m -= n;
		}
		else if (a[i] + a[n - 1] <= x) {}
		else {
			ll y = bs2(0, n - 1, i, x, n, m, a);
			ans += a[i] * (n - y) + b[n] - b[y];
			m -= n - y;
		}
	}
	cout << ans + x * m << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

#define rr register

// #define int long long
#define db double

#define inf 1e10
#define mod 10007

using namespace std;

const int MAXN = 1e5 + 5;

inline int read() {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) {f |= ch == '-'; ch = getchar();}
	while (isdigit(ch)) {s = s * 10 + (ch ^ 48); ch = getchar();}
	return f ? -s : s;
}

int n, ans;

signed main(signed argc, char const *argv[]) {
	n = read();
	cout << int(pow(n,3));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(0,min(b,d)-max(a,c))<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
typedef vector<int> vi; 
typedef vector<bool> vb; 
typedef vector<ll> vl; 
typedef vector<db> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
 
#define sz(x) (int)(x).size()
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define sor(x) sort(all(x))
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define endl '\n'
 
const ll MOD = 1e9+7; // 998244353;
const ll INF = 1e18;
 
int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int n; cin >> n;
   ll ans = 1;
   for (int i = 0; i < n; i++) {
      ans *= 10;
      ans = ans % MOD;
   }
   ll cur = 2;
   for (int i = 0; i < n; i++) {
      cur *= 9;
      cur = cur % MOD;
   }
   ans -= cur;
   if (ans < 0) ans += MOD;
   cur = 1;
   for (int i = 0; i < n; i++) {
      cur *= 8;
      cur = cur % MOD;
   }
   ans += cur;
   ans = ans % MOD;
   cout << ans;
   return 0;
}

Measured memory_bytes: 3648
def bSort(A):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(len(A)-1, i, -1):
            if int(A[j][1]) < int(A[j-1][1]):
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A, count

def sSort(A):
    count = 0
    for i in range(len(A)):
        minj = i
        for j in range(i, len(A)):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        if minj != i:
            count += 1
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
    return A, count

def isStable(input_a, output_a):
    for v1, v2 in zip(input_a, output_a):
        if v1 != v2:
            return 'Not stable'
    return 'Stable'

if __name__ == '__main__':
    length = input()
    data = input().split()
    sort_s, _= sSort(list(data))
    sort_b, _= bSort(list(data))
    print (' '.join([str(x) for x in sort_b]))
    print (isStable(sort_b, sort_b))
    print (' '.join([str(x) for x in sort_s]))
    print (isStable(sort_b, sort_s))


Measured memory_bytes: 5616
def gcd(a,b):
  return a if b == 0 else gcd(b,a%b)

N = int(input())
A = [int(x) for x in input().split()]

gcd_from_left = [0]*N # 自分のindexは含まないようなもの
gcd_from_right = [0]*N

for i in range(1,N):
  gcd_from_left[i] = gcd(A[i-1],gcd_from_left[i-1])
  gcd_from_right[N-1-i] = gcd(A[N-i],gcd_from_right[N-i])

ans = 0

for a,b in zip(gcd_from_left, gcd_from_right):
  x = gcd(a,b)
  if ans < x:
    ans = x
    
print(ans)


Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
ll INF = 1e12+10;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
vector<pair<ll, ll> > pairs;
#define print1(x) cerr << "x = " << x << endl;
#define print2(x, y) cerr<< "x,y = "  << x << "," << y << endl;
#define print3(x, y, z) cerr << "x,y,z = " << x << "," << y << "," << z << endl;

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    if (abs(A - B)%2 == 0){
        cout << abs(A - B)/2;
        return 0;
    }
    ll cand1 = (2 * N - A - B + 1)/2;
    ll cand2 = (A - 1 + B - 1 + 1)/2;
    cout << min(cand1, cand2);
    return 0;
    //ll cand1 = max(N - A, N - B);
    //ll cand2 = max(A - 1, B - 1);
    //ll ans = min(cand1, cand2);
    //cout << ans;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.sort()
mn,mx = A[0],A[-1]

from collections import Counter
ctr = Counter(A)

if ctr[mx] < 2:
    print('Impossible')
    exit()
if (mx%2==0 and ctr[mn] > 1) or ctr[mn] > 2:
    print('Impossible')
    exit()

for n in range(mn,mx+1):
    if ctr[n]==0:
        print('Impossible')
        exit()
print('Possible')

Measured memory_bytes: 9404
#include<cstdio>
#include<map>
#include<iostream>
#define RI register int
#define CL const long long&
using namespace std;
map <long long,long long> f; long long n,t,a,b,c,d;
inline long long cof(CL a,CL x,CL y)
{
	CL dlt=x-y; if (dlt<=a) return min(a,1LL*dlt*d); return a;
}
inline long long DFS(CL n)
{
	if (!n) return 0; if (n==1) return d;
	if (f.count(n)) return f[n]; long long ret=1e18;
	if (n%2==0) ret=min(ret,cof(a,n,n/2)+DFS(n/2));
	else ret=min(ret,d+min(cof(a,n,n+1>>1)+DFS(n+1>>1),cof(a,n,n-1>>1)+DFS(n-1>>1)));
	if (n%3==0) ret=min(ret,cof(b,n,n/3)+DFS(n/3)); else
	if (n%3==1) ret=min(ret,min(cof(b,n,(n-1)/3)+d+DFS((n-1)/3),cof(b,n,(n+2)/3)+2*d+DFS((n+2)/3)));
	else ret=min(ret,min(cof(b,n,(n+1)/3)+d+DFS((n+1)/3),cof(b,n,(n-2)/3)+2*d+DFS((n-2)/3)));
	if (n%5==0) ret=min(ret,cof(c,n,n/5)+DFS(n/5)); else
	if (n%5==1) ret=min(ret,min(cof(c,n,(n-1)/5)+d+DFS((n-1)/5),cof(c,n,(n+4)/5)+4*d+DFS((n+4)/5))); else
	if (n%5==2) ret=min(ret,min(cof(c,n,(n-2)/5)+2*d+DFS((n-2)/5),cof(c,n,(n+3)/5)+3*d+DFS((n+3)/5))); else
	if (n%5==3) ret=min(ret,min(cof(c,n,(n-3)/5)+3*d+DFS((n-3)/5),cof(c,n,(n+2)/5)+2*d+DFS((n+2)/5)));
	else ret=min(ret,min(cof(c,n,(n-4)/5)+4*d+DFS((n-4)/5),cof(c,n,(n+1)/5)+d+DFS((n+1)/5)));
	if (n<=(long long)1e9) ret=min(ret,n*d); return f[n]=ret;
}
int main()
{
	for (scanf("%lld",&t);t;--t)
	{
		scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
		f.clear(); printf("%lld\n",DFS(n));
	}
	return 0;
}

Measured memory_bytes: 4560
K = int(input())

string = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(string[K-1])

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var strs = Console.ReadLine().Split();
            var A = int.Parse(strs[0]);
            var B = int.Parse(strs[1]);

            if (A <= 8 && B <= 8)
                Console.WriteLine("Yay!");
            else
                Console.WriteLine(":(");
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>

using namespace std;

const int nmax = 1e4;
int main(){
	int n,a,b;
	cin >> n >> a >>b;
	
	int sum = 0;
	for(int i = 1;i <= n;i++){
		int num = i;
		int tsum = 0;
		for(int j = 0;j < 5;j++){
			tsum += num % 10;
			num /= 10; 
		}
		if(a <= tsum && tsum <= b) sum += i;
	}
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int nx,ny,nz,k; cin >> nx >> ny >> nz >> k;
	vll a(nx),b(ny),c(nz);
	rep(ix,nx) cin >> a[ix];
	rep(iy,ny) cin >> b[iy];
	rep(iz,nz) cin >> c[iz];
	vll e;
	rep(ix,nx)rep(iy,ny) e.push_back(a[ix]+b[iy]);
	SORT(e); REV(e);
	vll f;
	rep(ie,min(k,nx*ny))rep(iz,nz) f.push_back(e[ie]+c[iz]);
	SORT(f); REV(f);
	rep(i,k)cout << f[i] << endl;
}




Measured memory_bytes: 43240
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
// #define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

vector<int> prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        //we will try to shorten the match string length until we revert to the beginning of match (index 1)
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
void solve(){

    int n;
    cin >> n;

    int x = n/1000;
    if(x*1000==n){
        cout << 0 << endl;
    }
    else{
        cout << (x+1)*1000-n << endl;
    }
} 

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 3652
def solve():
    N, *A = map(int, open(0).read().split())

    K = N * (N + 1) // 2
    if sum(A) % K != 0:
        return False

    t = sum(A) // K
    cnt = 0
    for a, b in zip(A, A[1:] + [A[0]]):
        d = t + a - b
        if d % N or d < 0:
            return False
        cnt += d // N

    return (t == cnt)

if solve():
    print("YES")
else:
    print("NO")

Measured memory_bytes: 14068
N= int(input())

m = 10**9+7
pri_num = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
dic = {}

for i in range(2,N+1):
    for pri in pri_num:
        while i>0:
            if i % pri == 0:
                if pri in dic:
                    dic[pri] +=1
                else:
                    dic[pri]=1
                i = i//pri

            else:
                break

count = 1
for val in dic.values():
    count = (count*(val+1))%m
print(count)

            


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

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    for (int i=0; i<h; ++i) cin >> s[i];

    vector<vector<int>> t(h, vector<int>(w, 0));
    const int dx[] = {1, 0, -1, 0};
    const int dy[] = {0, 1, 0, -1};
    for (int i=0; i<h; ++i) {
        for (int j=0; j<w; ++j) {

            char now = s[i][j];
            if (now == '#') {
                for (int d=0; d<3; ++d) {
                    int nx = i + dx[d];
                    int ny = j + dy[d];
                    if (nx < 0 or nx >= h) continue;
                    if (ny < 0 or ny >= w) continue;
                    if (s[nx][ny] == '#') {
                        ++t[i][j];
                        ++t[nx][ny];
                    }
                }
            }
        }
    }
    
    bool flag = true;
    for (int i=0; i<h; ++i) {
        for (int j=0; j<w; ++j) {
            if (s[i][j] == '#') {
                if (t[i][j] == 0) flag = false;
            }
        }
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
lli lcm(lli num1, lli num2){
    return num1 / gcd(num1, num2) * num2;
}
int main(){
   lli L,R,N,M,K,sum=1,num=0,flag=0;
   cin >> N;
   Vec(P,lli,N,0);
   Vec(Q,lli,N+1,0);
   Vec(O,lli,N+1,0);
   rep(i,0,N)cin >> P[i];
   rep(i,1,N)Q[i]=gcd(Q[i-1],P[i-1]);
   rrep(i,N-1,-1)O[i]=gcd(O[i+1],P[i]);
   rep(i,0,N)sum=max(sum,gcd(Q[i],O[i+1]));
   Out(sum);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll val[105],v[105],dp[100025];
int main()
{
    int n,V;ll ans = 0;scanf("%d%d",&n,&V);
    for(int i = 1;i<=n;++i) scanf("%lld%lld",&v[i],&val[i]);
    memset(dp,0x3f,sizeof(dp));
    dp[0] = 0;
    for(int i = 1;i<=n;++i)
    {
        for(int j = 100000;j>=val[i];j--)
            dp[j] = min(dp[j],dp[j-val[i]]+v[i]);
    }
    for(int i = 1;i<=1e5;++i) if(dp[i]<=V) ans = max(ans,1ll*i);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, a, n) for(int i = a; i < (n); ++i)

int main(){
  int n;
  cin >> n;
  vector<int> b(n, 1e6);
  rep(i, 0, n - 1) cin >> b[i];
  int ans = b[0];
  rep(i, 0, n - 1) {
    ans += min(b[i + 1], b[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();

			long[,] nums = new long[10, 10];
			for (int i = 1; i <= n; i++) {
				if (i < 10) {
					nums[i, i] += 1;
				} else {
					int j = i;
					while (j >= 10) {
						j /= 10;
					}

					nums[j, i % 10] += 1;
				}
			}

			long ans = 0;
			for (int i = 1; i <= 9; i++) {
				for (int j = 1; j <= 9; j++) {
					ans += nums[i, j] * nums[j, i];
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N,K,Q;
    ll cnt[100001];
    mem0(cnt);
    cin >> N >> K >> Q;
    for (int i = 0; i < Q; i++) {
        int a;
        cin >> a;
        a--;
        cnt[a]++;
    }
    for (int i = 0; i < N; i++) {
        Yes(K - (Q-cnt[i]) > 0);
    }
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n,m;
  cin >> n;
  set<string> v;
  map<string,int> b;
  rep(i,n) {
    string s;
    cin >> s;
    b[s]++;
    v.insert(s);
  }
  map<string,int> r;
  cin >> m;
  rep(i,m) {
    string s;
    cin >> s;
    r[s]++;
    v.insert(s);
  }
  int ans = 0;
  for(auto a : v) {
    ans=max(ans,(b[a]-r[a]));
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3616
while line = gets do
	a, b, c, d, e, f = line.split.map(&:to_f)
	x = (e*c - b*f)/(a*e - b*d) + 0.0
	y = (d*c - a*f)/(d*b - a*e) + 0.0
	printf("%.3f %.3f\n", x, y)
end

Measured memory_bytes: 6132