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

int main() {

	int r, g, b; cin >> r >> g >> b;
	int t = 100 * r + 10 * g + b;
	if (t % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3560
#include <stdio.h>

int main(void) {

	int dice[100][6];
	int diceo[6];
	int dicet[6];
	int copy[4];
	int tatea[7] = { 0, 1, 5, 4, 0, 1, 5 };
	int tateb[7] = { 0, 4, 5, 1, 0, 4, 5 };
	int yokoa[7] = { 1, 2, 4, 3, 1, 2, 4 };
	int yokob[7] = { 1, 3, 4, 2, 1, 3, 4 };
	int hokaa[7] = { 0, 2, 5, 3, 0, 2, 5 };
	int hokab[7] = { 0, 3, 5, 2, 0, 3, 5 };
	int ue[6] = { 2, 3, 0, 5, 4, 1 };
	int sita[6] = { 3, 2, 5, 0, 1, 4 };
	int choice[7];
	int co = 0;
	int coo = 0;
	int cot = 0;
	int i, j, k, l, m, n;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		for (j = 0; j < 6; j++) {
			scanf("%d", &dice[i][j]);
		}
	}

	for (l = 0; l < n - 1; l++) {
		for (i = 0; i < 6; i++) {
			diceo[i] = dice[l][i];
		}
		for (m = 0; m < n - 1 - l; m++) {
			for (i = 0; i < 6; i++) {
				dicet[i] = dice[l + 1 + m][i];
			}
			for (i = 0; i < 6; i++) {
				for (j = 0; j < 7; j++) {
					switch (i) {
					case 0:choice[j] = tatea[j];
						break;
					case 1:choice[j] = tateb[j];
						break;
					case 2:choice[j] = yokoa[j];
						break;
					case 3:choice[j] = yokob[j];
						break;
					case 4:choice[j] = hokaa[j];
						break;
					case 5:choice[j] = hokab[j];
						break;
					}
				}
				for (j = 0; j < 4; j++) {
					for (k = 0; k < 4; k++) {
						copy[k] = choice[k + j];
					}
					for (k = 0; k < 4; k++) {
						coo = diceo[yokoa[k]];
						cot = dicet[copy[k]];
						if (coo == cot) co++;
					}
					if (co == 4) {
						if (diceo[0] == dicet[ue[i]]) co++;
						if (diceo[5] == dicet[sita[i]]) co++;
					}
					if (co == 6) {
						printf("No\n");
						return 0;
					}
					co = 0;
				}
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

string s;
int a[200010];
int dp[1 << 26];
int ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    for(int i = 1; i < (1 << 26); i++) dp[i] = inf;
    for(int i = 0; i < s.length(); i++){
        a[i] ^= 1 << (s[i] - 'a');
        a[i + 1] = a[i];
    }
    for(int i = 0; i < s.length(); i++){
        int opt = dp[a[i]];
        for(int j = 0; j < 26; j++){
            int to = (1 << j) ^ a[i];
            if(dp[to] < opt) opt = dp[to];
            
        }
        chmin(dp[a[i]], opt + 1);
        if(i == s.length() - 1) ans = opt + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 263632
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
const int N=300010;
const int M=600010;
const int MX=25;
using namespace std;

int n,K,x;

void READ(){
	scanf("%d%d",&n,&K);
	rep(i,1,n){
		scanf("%d",&x);
	}
}

void SOLVE(){
	int pos=1,ans=0;
	while(pos<n){
		pos+=K-1;
		ans++;
	}
	printf("%d\n",ans);
}

int main(){
	READ();
	SOLVE();
	return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S;
    cin >> S;
    ll l_s = (ll)S.size();
    bool f_win;
    if (l_s & 1) {
        if (S.front() == S.back()) {
            f_win = false;
        }
        else {
            f_win = true;
        }
    }
    else {
        if (S.front() == S.back()) {
            f_win = true;
        }
        else {
            f_win = false;
        }
    }
    cout << (f_win ? "First\n" : "Second\n");
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;


signed main() {
    ll n, m;
    cin >> n >> m;
    ll res = 1;

    for(ll i = 1; i * i <= m; ++i) if(m % i == 0) {
        ll j = m / i;
        if(i * n <= m) res = max(res, i);
        if(j * n <= m) res = max(res, j);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <deque>
#include <iostream>
#include <vector>
using namespace std;

struct node {
	string name;
	vector<node> children;
	bool is_file;

	node(const string& name, bool is_file):name(name), is_file(is_file) {}

	void add_file(deque<string>& path) {
		if(path.size() == 1) {
			children.emplace_back(path.front(), true);
			return;
		}

		string target = path.front();
		path.pop_front();

		for(int i = 0; i < static_cast<int>(children.size()); ++i) {
			if(children[i].name == target) {
				children[i].add_file(path);
				return;
			}
		}

		children.emplace_back(target, false);
		children.back().add_file(path);
	}

	string search(deque<string>& path, bool& used_rule) const {
		if(is_file) return path.size() ? "" : name;

		string target;
		if(path.size() == 0) {
			if(used_rule) return "";
			target = "index.html";
			used_rule = true;
		}
		else {
			target = path.front();
			path.pop_front();
		}

		if(target == ".") return search(path, used_rule);
		if(target == ".." && name.size()) return "back";

		for(int i = 0; i < static_cast<int>(children.size()); ++i) {
			if(children[i].name == target) {
				const string result = children[i].search(path, used_rule);
				if(result == "back") return search(path, used_rule);
				return result.size() ? name + '/' + result : result;
			}
		}

		return "";
	}
};

inline deque<string> split(string str, const string& delimiter, bool& used_rule) {
	deque<string> res;
	int pos = 0;
	while((pos = str.find(delimiter)) != string::npos) {
		if(pos > 0) res.push_back(str.substr(0, pos));
		str = str.substr(pos + delimiter.size());
	}

	if(str.size()) res.emplace_back(str);
	else {
		res.emplace_back("index.html");
		used_rule = true;
	}
	return res;
}

inline string search(const node& root, string s) {
	bool used_rule = false;
	deque<string> path = split(move(s), "/", used_rule);
	return root.search(path, used_rule);
}

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

	for(int n, m; cin >> n >> m && (n || m);) {
		node root("", false);

		for(int i = 0; i < n; ++i) {
			string s;
			cin >> s;

			bool disused;
			deque<string> path = split(move(s), "/", disused);
			root.add_file(path);
		}

		for(int i = 0; i < m; ++i) {
			string a, b;
			cin >> a >> b;

			a = search(root, move(a));
			b = search(root, move(b));

			if(!a.size() || !b.size()) {
				cout << "not found" << endl;
			}
			else if(a == b) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}
	}

	return EXIT_SUCCESS;
}

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

int main(){
    char s[3];
    int ans = 0;
    cin >> s[0] >> s[1] >> s[2];
    for(int i = 0; i < 3; i++) if(s[i]-'0') ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
import std.stdio;

string[] cls = ["NA", "E", "D", "C", "B", "A", "AA", "AAA"]; 
double[] a = [70.0, 55.0, 50.0, 43.0, 40.0, 37.5, 35.5, -1]; 
double[] b = [148.0, 116.0, 105.0, 89.0, 83.0, 77.0, 71.0, -1];

void main(){
	double n, m;
	while (readf("%s %s\n", &n, &m)) {
		for (int i = 0; i < a.length; i++) {
			if (n >= a[i] || m >= b[i]) {
				writeln(cls[i]);
				break;
			}
		}
	}
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll fi[1010], dp[1010];

ll modpow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	dp[n] = 1;
	for (int i = 1; i <= n; i++) dp[n] = dp[n] * i % MOD;
	fi[n] = modpow(dp[n], MOD - 2);
	for (int i = n; i > 0; i--) fi[i - 1] = fi[i] * i % MOD;
	for (int i = a; i <= b; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = c; k <= d; k++) {
				if (j + i * k > n) break;
				(dp[j] += dp[j + i * k] * modpow(fi[i], k) % MOD * fi[k] % MOD) %= MOD;
			}
		}
	}
	cout << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
using namespace std;
int N, a[100009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> a[i];
	int sum = 0;
	for (int i = 0; i <= N; i++) sum += abs(a[i] - a[i + 1]);
	for (int i = 1; i <= N; i++) {
		cout << sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << "\n";
	}
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n, cnt;
int type[610];
int dp[2][310][310];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        if (a == -1 && b == -1) cnt++;
        else if (a != -1 && b != -1) type[a] = type[b] = 1;
        else type[a + b + 1] = 2;
    }
    dp[0][0][0] = 1;
    int o = 0;
    for (int i = n + n; i > 0; i--) {
        if (type[i] == 1) continue;
        o ^= 1;
        for (int j = 0; j <= n; j++)
            for (int k = 0; k <= n; k++) {
                if (type[i] == 2) {
                    dp[o][j][k] = 0;
                    if (j) dp[o][j][k] += dp[o ^ 1][j - 1][k];
                    if (k < n) dp[o][j][k] += dp[o ^ 1][j][k + 1];
                    dp[o][j][k] %= mod;
                }
                else {
                    dp[o][j][k] = 0;
                    if (k) dp[o][j][k] = (dp[o][j][k] + dp[o ^ 1][j][k - 1]) % mod;
                    if (k < n) dp[o][j][k] = (dp[o][j][k] + dp[o ^ 1][j][k + 1]) % mod;
                    if (j < n) dp[o][j][k] = (dp[o][j][k] + 1ll * (j + 1) * dp[o ^ 1][j + 1][k]) % mod;
                }
            }
    }
    int ans = dp[o][0][0];
    for (int i = 1; i <= cnt; i++) ans = 1ll * i * ans % mod;
    return cout << ans << endl, 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include <numeric>
using namespace std;
int main(){
string S;
cin>>S;
int n=0,w=0,s=0,e=0; 
for (int i = 0; i < S.size(); i++){
if (S[i] == 'N') {n++;}
else if (S[i] == 'S') {s++;}
else if (S[i] == 'W') {w++;}
else if (S[i] == 'E') {e++;}
}
if(n>0&&s>0&&w>0&&e>0)
cout<<"Yes"<<endl;
else if(n>0&&s>0&&w==0&&e==0)
cout<<"Yes"<<endl;
else if(n==0&&s==0&&w>0&&e>0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	int a; cin >> a;

	FOR_LT(i, 0, 10) {
		FOR_LT(j, 0, 10) {
			if (i * j == a) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
def findpath(graph, root, rest):
    if len(rest) == 0:
        return 1
    res = 0
    for n in graph[root]:
        if n in rest:
            rest.remove(n)
            res += findpath(graph, n, rest)
            rest.add(n)
    return res

n, m = map(int, input().split())
graph = {}
for _ in range(m):
    a, b = map(int, input().split())
    if a not in graph:
        graph[a] = set()
    graph[a].add(b)
    if b not in graph:
        graph[b] = set()
    graph[b].add(a)

print(findpath(graph, 1, set(range(2, n + 1))))


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        String s = sc.next();

        System.out.println(solve(s));

        sc.close();
    }

    static String solve(String s) {
        int count = 0;
        List<Character> rests = new ArrayList<>();
        for (int i = 0; i < s.length(); ++i) {
            char ch = s.charAt(i);

            while (rests.size() >= 2 && ch != rests.get(rests.size() - 2)) {
                rests.remove(rests.size() - 1);
                ++count;
            }

            rests.add(ch);
        }

        return (count % 2 == 0) ? "Second" : "First";
    }
}

Measured memory_bytes: 25712
#include <stdio.h>
#define MX 1000
#define MN 0
#define EXN 2

int main(void){
    int i, n, s, sum, mn, mx;
    
    do
    {
        sum = 0;
        mn = MX;
        mx = MN;
        
        scanf( "%d", &n );
        if( n != 0 )
        {
            for( i = 0; i < n; i++ )
            {
                scanf( "%d", &s );
                sum += s;
                
                if( mx < s ) mx = s;
                if( mn > s ) mn = s;
            }
            
            if( mx == MN ) mx = 0;
            if( mn == MX ) mn = 0;
            
            sum = ( sum - ( mx + mn ) ) / ( n - EXN );
            printf( "%d\n", sum );
        }
    }while( n != 0 );
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    ll A;
    double B;
    cin >> A >> B;   
    int B_tmp = B*100 + 0.5;
    ll ans = B_tmp * A / 100;
    cout << ans << endl;
}

Measured memory_bytes: 3792
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs[0]);
const adj = inputs.slice(1).map((s) => s.split(' ').map(Number));

class Edge {
  constructor(dest, weight = 1) {
    this.dest = dest;
    this.weight = weight;
  }
}

class GraphList {
  constructor(n) {
    this.n = n;
    this.adj = {};
  }
  addEdge(source, edge) {
    this.adj[source] = this.adj[source] || [];
    this.adj[source].push(edge);
  }
  forEach(iterator) {
    Object.keys(this.adj).forEach(source => {
      this.adj[source].forEach(edge => iterator(Number(source), edge));
    });
  }
}

class GraphMatrix {
  constructor(n) {
    this.matrix = (new Array(n)).fill(0).map(() => (new Array(n)).fill(0));
  }
  fetchGraphList(graphList) {
    graphList.forEach(this.addEdge.bind(this));
  }
  addEdge(source, edge) {
    this.matrix[source - 1][edge.dest - 1] = edge.weight;
  }
  toString() {
    return this.matrix.map(list => list.join(' ')).join('\n');
  }
}

const graphList = new GraphList(n);
for (let i = 0; i < n; i++) {
  const u = adj[i][0];
  const k = adj[i][1];
  const vj = adj[i].slice(2);
  for (let j = 0; j < k; j++) {
    graphList.addEdge(u, new Edge(vj[j]));
  }
}
const graphMatrix = new GraphMatrix(n);
graphMatrix.fetchGraphList(graphList);
console.log(graphMatrix.toString());



Measured memory_bytes: 18108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int inf = 1<<29;
int main(void){
    string s;
    cin >> s;
    int cntb = 0,cntw = 0,cntb2 = 0,cntw2 = 0,ans = inf,tmp = 0,tmp2 = 0;
    for(int i = 0;i < s.length();i++){
        if(i%2 == 0 && s[i] == '0')cntb++;
        if(i%2 == 0 && s[i] == '1')cntb2++;
        if(i%2 == 1 && s[i] == '1')cntw++;
        if(i%2 == 1 && s[i] == '0')cntw2++;
    }
    if(s.length() % 2 == 0){
        tmp += (s.length()/2);
        tmp -= cntb;
        tmp += (s.length()/2);
        tmp -= cntw;
        ans = min(ans,tmp);
        
        tmp2 += (s.length()/2);
        tmp2 -= cntb2;
        tmp2 += (s.length()/2);
        tmp2 -= cntw2;
        ans = min(ans,tmp2);
    }else{
        tmp += (s.length()/2)+1;
        tmp -= cntb;
        tmp += (s.length()/2);
        tmp -= cntw;
        ans = min(ans,tmp);
        
        tmp2 += (s.length()/2)+1;
        tmp2 -= cntb2;
        tmp2 += (s.length()/2);
        tmp2 -= cntw2;
        ans = min(ans,tmp2);
    }
    cout << ans << endl;
    return 0;
}


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

int main ()
{
  int n,a,b;
  cin >> n;
  cin >> a;
  b = n % 500;
  
  if(a >= b){
   cout << "Yes" << endl; 
  }else{
   cout << "No" << endl; 
  }
}

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

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

    unordered_map<int, int> ai;
    uint64_t sum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        ai[a]++;
        sum += a;
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int b;
        int c;
        cin >> b >> c;

        int num = ai[b];
        ai[c] += ai[b];
        ai[b] = 0;
        sum += (c - b) * num;

        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 7100
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define fr(i,x,n) for(int i=x;i<=n;i++)
#define rf(i,n,x) for(int i=n;i>=x;i--)
#define mst(x,i) memset(x,i,sizeof(x))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define PB push_back
#define X first
#define Y second
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int maxn=2E5+5;
const int maxm=1E5+5;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const LL mod=1E9+7;
const double eps=1E-6;
const double PI=acos(-1.0);
void solve(){
    LL n,d,x,y;
    cin>>n>>d;
    int ans=0;
    rep(i,n){
        cin>>x>>y;
        if(x*x+y*y<=d*d) ans++;
    }
    cout<<ans<<"\n";
}
int main(){
    IOS;
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(){
 int n, i, max, min;
 long long int sum;
 scanf("%d",&n);
 int a[n];
 for(i = 0; i < n; i++)
  scanf("%d",&a[i]);
 
 max = a[0];
 min = a[0];
 sum = 0;

 for(i = 0; i < n; i++){
  if(a[i] > max)
    max = a[i];
  if(a[i] < min)
    min = a[i];

  sum += a[i];
 } 
 printf("%d %d %lld\n",min, max, sum);
 
 return 0;
} 

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    string s;
    cin >> s;
    ll q;
    cin >> q;

    deque<char> str;
    REP(i, s.size()) str.push_back(s[i]);

    bool rev = false;
    REP(i, q) {
        ll type;
        cin >> type;

        if(type == 1) {
            rev = !rev;
        } else {
            ll f;
            char c;
            cin >> f >> c;
            f--;
            if(rev) f = 1-f;

            if(f==0) str.push_front(c);
            else str.push_back(c);
        }
    }

    if(rev) reverse(ALL(str));
    REP(i, str.size()) cout << str[i];
    cout << endl;

    return 0;
}

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

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

			var cin = new Scanner();

			int n = cin.NextInt();
			int k = cin.NextInt();
			var s = new List<string>();
            for (int i = 0; i < n; i++)
            {
				s.Add(cin.Next());
            }
			s.Sort();
            Console.WriteLine(string.Concat(s.ToArray()));

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

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

		public long NextLong()
		{
			return long.Parse(Next());
		}

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

		public double NextDouble()
		{
			return double.Parse(Next());
		}

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

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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

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

	vector<int> a(n + 1);
	vector<int> b(n);

	rep(i,n + 1){
		cin >> a[i];
	}
	rep(i,n){
		cin >> b[i];
	}

	ll sum = 0;
	rep(i, n){
/*
		int k = min(a[i], b[i]);
		sum += k;
//		a[i] -= k;
		b[i] -= k;
		int l = min(a[i + 1], b[i]);
		sum += l;
		a[i + 1] -= l;
	}		
*/

		if(a[i] >= b[i]){
			sum += b[i];
		}else{
			sum += a[i];
			b[i] -= a[i];
			if(a[i + 1] >= b[i]){
				a[i + 1] -= b[i];
				sum += b[i];
			}else{
				sum += a[i + 1];
				a[i + 1] = 0;
			}
		}
	}
	cout << sum << endl;

    return 0;
}



Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main(void) {
  int id;
  char c;
  double weight;
  double height;

  while(cin >> id >> c) {
    cin >> weight >> c;
    cin >> height;

    double bmi = weight / (height * height);
    if(bmi >= 25) {
      cout << id << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>

char a[1000001];

int main(void)
{
	int n;
	int i, j;
	int cnt;
	
	a[0] = a[1] = 1;
	
	for (i = 2; i * i <= 1000000; i++){
		for (j = i * i; j <= 1000000; j += i){
			a[j] = 1;
		}
	}
	
	while (scanf("%d", &n) != EOF){
		cnt = 0;
		for (i = 2; i <= n; i++){
			if (a[i] == 0){
				cnt++;
			}
		}
		printf("%d\n", cnt);
	}
	
	return (0);
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(100000 + 2, 0);
    for (int i = 0; i < n; ++i) {
        int a;
        int b;
        cin >> a >> b;
        for (int j = a; j <= b; ++j) {
            v[j] += 1;
        }
    }
    int max_{0};
    //for(auto&& i : v) {
    //    if(i) {
    //        cout << i << endl;
    //    }

    //}
    for (int i = 0; i < v.size(); ++i) {
        if (v[i] != 0 && (i - 1) <= v[i]) {
            max_ = i;
        }
    }
    if(max_ != 0) {
        cout << (max_ - 1) << endl;
    } else {
        cout << max_ << endl;
    }
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

void solve()
{
	ll n;
	cin>>n;
	ll sum=0;
	fr(i,1,n+1)
	{
		fr(j,1,n+1)
		{
			fr(k,1,n+1)
			{
				sum+=gcd(i,gcd(j,k));
			}
		}
	}
	cout<<sum<<endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    int X, Y;
    cin >> X >> Y;

    int kameDoubled = Y - 2 * X;
    int tsuruDoubled = 4 * X - Y;

    if (kameDoubled < 0 || tsuruDoubled < 0 || kameDoubled % 2 == 1 || tsuruDoubled % 2 == 1)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3128
import java.util.Arrays;
import java.util.Scanner;
   
public class Main { 
    public static void main(String[] args) { 
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt();

        int[] x = {a, b , c};

        Arrays.sort(x);
        System.out.println(x[0]+ " " + x[1] + " " + x[2]);
    }                                                                                                                                              
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int H1, M1, H2, M2, K;

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

  std::cin >> H1 >> M1 >> H2 >> M2 >> K;

  int m1 = H1 * 60 + M1, m2 = H2 * 60 + M2;
  int diff = m2 - m1;
  int res = std::max(diff - K, 0);

  std::cout << res << std::endl;
}


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

#define llint long long int

using namespace std;

int main()
{
    int X;

    cin >> X;

    if (X >= 1800)
    {
        cout << 1 << endl;
    }
    else if (X >= 1600)
    {
        cout << 2 << endl;
    }
    else if (X >= 1400)
    {
        cout << 3 << endl;
    }
    else if (X >= 1200)
    {
        cout << 4 << endl;
    }
    else if (X >= 1000)
    {
        cout << 5 << endl;
    }
    else if (X >= 800)
    {
        cout << 6 << endl;
    }
    else if (X >= 600)
    {
        cout << 7 << endl;
    }
    else if (X >= 400)
    {
        cout << 8 << endl;
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

int main() {
  std::string S, T;
  std::cin >> S >> T;
  int cnt {};
  rep(i,3) {
    if (S[i] == T[i]) ++cnt;
  }
  std::cout << cnt << '\n';
}


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


int main()
{
	while (true)
	{
		int ary[40];
		int n;
		cin >> n;
		if (n == 0) return 0;

		ary[0] = 1;
		ary[1] = 1;
		ary[2] = 2;
		for (int i = 3; i < n + 1; i++)
		{
			ary[i] = ary[i - 1] + ary[i - 2] + ary[i - 3];
		}

		cout << (ary[n] / 3650) + 1 << endl;
	}

	return 0;
}

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


int main() {
    int n, m;
    cin >> n >> m;
    int min = 0;
    int max = INT_MAX;
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        if (min < l) min = l;
        if (r < max) max = r;
    }
    int num = 0;
    if (max - min + 1 > 0) num = max - min + 1;
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
using namespace std;
int main() {
	int N, M, X;
	cin >> N >> M >> X;
	vector<int> v(N + 1);
	int A;
	for (int i = 0; i < M; i++) {
		cin >> A;		
		v[A] = 1;
	}

	//for (int i = 0; i <= N; i++)
	//	cout << v[i] << endl;

	int sum1 = accumulate(v.begin(), v.begin() + X, 0);
	int sum2 = accumulate(v.begin() + X, v.end(), 0);

	//cout << "sum1 " << sum1 << " sum2 " << sum2 << endl;

	cout << min(sum1, sum2) << endl;

	//cin >> X;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  string n;
  cin >> n;
  while (1) {
    if (n.at(0) == n.at(1) && n.at(1) == n.at(2)) {
      cout << n << endl;
      return 0;
    } else {
      int x = stoi(n);
      x++;
      n = to_string(x);
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

int main(){
    int a,b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int A[maxn];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d",&A[i]);
    }
    int Max=0,ans=0;
    for(int i=n-1;i>=1;i--) {
        if(A[i]>=A[i+1]) Max++;
        else {
            ans = max(Max,ans);
            Max=0;
        }
    }
    ans = max(ans,Max);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< ll, ll >
#define piiii pair<ll,pair<ll,pii>>
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void  solve(){
  ll h,w,k,x1,x2,y1,y2;
  char kl;

  cin>>h>>w>>k;
  cin>>x1>>y1>>x2>>y2;
  x1--,y1--,x2--,y2--;

  vector<vector<ll>> a(h,vector<ll>(w,0));
  rep(i,0,h) rep(j,0,w) {cin>>kl; if(kl=='.') a[i][j]=1;}

  vector<pii> direction ={{1,0},{0,1},{-1,0},{0,-1}};

  vector<vector<ll>> dp(h,vector<ll>(w,1e18));
  priority_queue<piiii,vector<piiii> ,greater<piiii>> pq;

  dp[x1][y1]=0;
  pii pos={x1,y1};
  if(pos.f>0 && a[pos.f-1][pos.s]==1) pq.push({1,{2,{pos.f-1,pos.s}}});
  if(pos.s>0 && a[pos.f][pos.s-1]==1) pq.push({1,{3,{pos.f,pos.s-1}}});
  if(pos.f+1<h && a[pos.f+1][pos.s]==1) pq.push({1,{0,{pos.f+1,pos.s}}});
  if(pos.s+1<w && a[pos.f][pos.s+1]==1) pq.push({1,{1,{pos.f,pos.s+1}}});
  vector<vector<vi>> vis(h,vector<vi>(w,vi(4,0)));
  while(!pq.empty()){
      piiii top=pq.top();
      pq.pop();
      pos = top.s.s;
      ll val=top.f,val1=val;
      ll dire=top.s.f;
      ll yx=ceil((val*1.0)/k);
      if(vis[pos.f][pos.s][dire]) continue;
      vis[pos.f][pos.s][dire]=1;
      if((dp[pos.f][pos.s]+k-1)/k<=val/k) continue;

      dp[pos.f][pos.s]=min(dp[pos.f][pos.s],val);

      if(pos.f>0 && a[pos.f-1][pos.s]==1) {
        val1=val;
        if(dire != 2) val1=yx*k;
        if(dp[pos.f-1][pos.s]+k>=val1+1)pq.push({val1+1,{2,{pos.f-1,pos.s}}});
      }
      if(pos.s>0 && a[pos.f][pos.s-1]==1) {
        val1=val;
        if(dire != 3) val1=yx*k;
        if(dp[pos.f][pos.s-1]+k>=val1+1)pq.push({val1+1,{3,{pos.f,pos.s-1}}});
      }
      if(pos.f+1<h && a[pos.f+1][pos.s]==1) {
        val1=val;
        if(dire != 0) val1=yx*k;
        if(dp[pos.f+1][pos.s]+k>=val1+1)pq.push({val1+1,{0,{pos.f+1,pos.s}}});
      }
      if(pos.s+1<w && a[pos.f][pos.s+1]==1) {
        val1=val;
        if(dire != 1) val1=yx*k;
        if(dp[pos.f][pos.s+1]+k>=val1+1) pq.push({val1+1,{1,{pos.f,pos.s+1}}});
      }
  }
  // cout<<dp[x2][y2]<<endl;
  if(dp[x2][y2]==1e18) cout<<-1<<endl;
  else cout<<(ll) (ceil(1.0*dp[x2][y2]/k))<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}
const ll inf = 1LL<<60;



int main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);
  int n;cin>>n;
  int max_val=0,ans=0;

  vector<int> a(n);

  rep(i,n){
    cin>>a[i];
    if(max_val<a[i])max_val=a[i];
  }
  vector<int> done(max_val,0);

  sort(a);


  rep(i,n){
    int cnt=1;
    if(1<=done[a[i]-1]){
      done[a[i]-1]++;
      continue;
    }
    done[a[i]-1]++;

    while(a[i]*cnt<=max_val){
      cnt++;
      if (a[i]*cnt<=max_val)done[a[i]*cnt-1]++;
    }
  }

  for(int i:a){
    if(done[i-1]==1)ans++;
  }

  cout<<ans<<endl;
}

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

int main(){
  string S;
  cin >> S;
  int mi = 1000;
  for(int i=0;i<S.length()-2;i++){
    int a = S[i] - '0';
    int b = S[i+1] - '0';
    int c = S[i+2] - '0';
    int x = a*100+b*10+c;
    x = abs(x-753);
    mi = min(mi,x);
  }
  cout << mi << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int dijkstra() {
  int minv;
  int d[MAX], color[MAX];

  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;

  while (1) {
    minv = INFTY;
    int u = -1;
    for (int i = 0; i < n; i++) {
      if (minv > d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if (u == -1) break;
    color[u] = BLACK;
    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && M[u][v] != INFTY) {
        if (d[v] > d[u] + M[u][v]) {
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] ==INFTY ? -1: d[i]) << endl;
  }
}

int main() {
  cin >> n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }

  int k, c, u, v;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    int ans=a,b1=b;
    while (b1>0)
    {
        ans*=10;
        b1/=10;
    }
    ans+=b;
    for (int i=1;i<1001;i++)
    if (i*i==ans) {cout<<"Yes"<<endl; return 0;}
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,N,max=0,sum=0;
    scanf("%d",&N);
    int arr[N+2];
    for(i=1;i<=N;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]>max){
         sum=sum+(max/2);
            max=arr[i];
        sum=sum+(max/2);
        }
        else{
            sum=sum+arr[i];
        }
    }
    printf("%d\n",sum);
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)

#define SZ(x) ((int)(x).size())


typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vector{
    double x, y;
};

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

int main()
{
    ll N, M, K, temp, sum;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    
    ll s = 0, index, ans = 0;
    index = N;
    rep(i, N) s+= A[i];
    rep(i, M+1) {
        while (s > K && index > 0) {
            index--;
            s -= A[index];
        }
        if (s > K) break;
        ans = max(ans, i+index);
        if (i == M) break;
        s += B[i];
    }
    
    cout << ans << endl;    
    return 0;
}


Measured memory_bytes: 6376
#include <bits/stdc++.h>
inline int read(){char c = getchar();int x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e3 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    ull n,sum = 0;
    cin >> n;
    ull arr[n+5] = {0},ans[n+5] = {00};
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++) ans[i] = (arr[i]+ans[i-1]);
    for(int i = 1;i <= n;i++) sum = ((sum + arr[i]*((ans[n]-ans[i])%mod))%mod)%mod;
    cout << sum << endl;
}


Measured memory_bytes: 6680
a, b = map(int, input().split())
c = [int(input()) for _ in range(b)]
d = [0] * (a + 1)
d[0] = 1
d[1] = 1
for i in c:
    d[i] = -1
for i in range(2, len(d)):
    if d[i] != -1:
        d[i] = ((0 if d[i-1] == -1 else d[i-1]) + (0 if d[i-2] == -1 else d[i-2])) % 1000000007
print(d[len(d)-1])


Measured memory_bytes: 7824
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] p = new int[N + 1];
        for (int i = 1; i < p.length; i++) {
            p[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 1; i < p.length; i++) {
            if (i == p[i]){
                cnt++;
                if(i < p.length - 1) {
                    int tmp = p[i];
                    p[i] = p[i + 1];
                    p[i + 1] = tmp;
                }
            }
        }

        out.println(cnt);
    }
}

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

int main()
{
    int h,w;
    cin >> h >> w;

    vector<string> a(h);

    vector<bool> delx(w,false);
    vector<bool> dely(h,false);

    int i,j;
    for (i = 0; i < h; i++)
    {
        cin >> a[i];
    }

    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            if(a[i][j] == '#')break;
        }
        if(j == w)dely[i] = true;
    }

    for (i = 0; i < w; i++)
    {
        for (j = 0; j < h; j++)
        {
            if(a[j][i] == '#')break;
        }
        if(j == h)delx[i] = true;
    }

    for (i = 0; i < h; i++)
    {
        if(dely[i])continue;
        for (j = 0; j < w; j++)
        {
            if(delx[j])continue;
            cout << a[i][j];
        }
        cout << endl;
    }
}

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

int main(){
    int a,b,k,z=0,ans=0;
    cin>>a>>b>>k;
    vector<long long int>d(1000000);

    for(int i=1;i<=100;i++){
    	if(a%i==0&&b%i==0){
    		d[z]=i;
    		z++;
    	}
       
    }

    cout<<d[z-k]<<endl;
    return 0;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int h, a;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> h >> a;
	int ans = h/a + (h%a != 0);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int n;
	int i;
	scanf("%d", &n);
	
	int num[n];
	
	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
	}
	
	for(i=0;i<n;i++){
		if(i<n-1){
			printf("%d ",num[n-i-1]);
		}else{
			printf("%d\n",num[n-i-1]);
		}
	}	
	return 0;
}

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

struct Card{char suit, value;};

void bubble(struct Card A[], int N){
    for(int i=0; i<N; i++){
        for(int j=N-1; j>=i+1; j--){
            if(A[j].value < A[j-1].value){
                Card t = A[j]; A[j] = A[j-1]; A[j-1] = t;
            }
        }
    }
}

void selection(struct Card A[], int N){
    for(int i=0; i<N; i++){
        int minj = i;
        for(int j=i; j<N; j++){
            if(A[j].value < A[minj].value) minj = j;
        }
       Card t = A[i]; A[i] = A[minj]; A[minj] = t;
    }
}

void print(struct Card A[], int N){
    for(int i=0; i<N; i++){
        if(i>0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

//バブルソートと選択ソートの結果を比較
bool isStable(struct Card C1[], struct Card C2[], int N){
    for(int i=0; i<N; i++){
        if(C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main() {
    Card C1[100], C2[100];
    int N;
    char ch;

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> C1[i].suit >> C1[i].value;
    }

    for(int i=0; i<N; i++) C2[i] = C1[i];

    bubble(C1, N);
    selection(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if( isStable(C1, C2, N)){
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }

    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    int ans = 0;
    int num[10][10] = {0};
    for (int i = 1; i <= n; ++i) {
        int bottom = i % 10;
        int tmp = i;
        int top = 0;
        while(1) {
            if (tmp / 10 == 0) {
                top = tmp % 10;
                break;
            }
            tmp /= 10;
        }
        ++num[top][bottom];
    }
    rep(i, 10) rep(j, 10) {
        ans += num[i][j] * num[j][i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){

	int a,b,c,d;
	
	cin >>a >>b >>c >>d;
	if(a+b>c+d)cout<<"Left"<<endl;
	else if(a+b==c+d)cout<<"Balanced"<<endl;
	else cout<<"Right"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
#include <math.h>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1


int main(){
  int a,b,c;
  cin>>a>>b>>c;

  int ans=(a+b)*c/2;

  print(ans);

  return 0;
}


Measured memory_bytes: 256
def i_input(): return int(input())
def s_input(): return input()

def main():
    k = i_input()
    s = s_input()

    len_s = len(s)

    if len_s <= k:
        print(s)
        exit()

    for i in range(k):
        print(s[i],end='')

    print('...')    

if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#include <stdio.h>
#include <stdlib.h>
 
int puz[3][3];
int tmp[3][3];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
void empty(int *x,int *y)
{
  int i,j;
  for(i=0; i<3; i++)
    {
      for(j=0; j<3; j++)
	{
	  if(!puz[i][j])
	    {
	      *x = j;
	      *y = i;
	      return;
            }
        }
    }
}
 
 
void swap(int *a,int *b)
{
  int tmp;
     
  tmp = *a;
  *a = *b;
  *b = tmp;
}
 
 
int cal()
{
  int i,a,sum=0;
     
  for(i=0; i<9; i++)
    {
      a = puz[i/3][i%3];
      if(a)
	{
	  a--;
	  sum += abs(i/3 - a/3) + abs(i%3 - a%3);
        }
    }
     
  return sum;
}
 
 
int dfs(int x,int y,int p,int dep,const int lim)
{
  int i,h,nx,ny,res;
     
  h = cal();
  if(h==0) return dep;
  if(dep+h>lim) return -1;
     
  for(i=0; i<4; i++)
    {
      nx = x+dx[i];
      ny = y+dy[i];
         
      if(~p && i==(p+2)%4) continue;
      if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;
         
      swap(&puz[y][x],&puz[ny][nx]);
      res = dfs(nx,ny,i,dep+1,lim);
      if(~res) return res;
         
      swap(&puz[y][x],&puz[ny][nx]);
    }
    
  return -1;
}


 
int main() {
  int i,j; // roop
  int ans,x,y,l;
     
  for(i=0; i<3; i++)
    {
      for(j=0; j<3; j++) scanf("%d",&puz[i][j]);
    }
     
     
    empty(&x,&y);
    for(l=0; l<100; l++)
      {
        for(i=0; i<3; i++)
	  {
            for(j=0; j<3; j++) tmp[i][j] = puz[i][j];
	  }
        
        ans = dfs(x,y,-1,0,l);
        if(ans!=-1)
	  {
            printf("%d\n",ans);
            break;
	  }
        
        for(i=0; i<3; i++)
	  {
            for(j=0; j<3; j++) puz[i][j] = tmp[i][j];
	  }
         
        ans = -1;
        if(l==99) printf("%d\n",ans);
      }
     
    return 0;
}
 
 



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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("in.txt","r",stdin);
    // 	freopen("out.txt","w",stdout);
    // #endif
    int a,b;
    cin>>a>>b;
    int ans=a+b;
    if(2*a-1>ans)
    	ans=2*a-1;
    if(2*b-1>ans)
    	ans=2*b-1;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256