akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N; cin >> N;
    vector<pair<int, int> > robots(N);
    for (int i = 0; i < N; i++) {
        int x, l; cin >> x >> l;
        robots[i] = {x+l, x-l};
    }
    sort(robots.begin(), robots.end());
    int ans = 1;
    int right = robots[0].first;
    for (int i = 1; i < N; i++) {
        if (right <= robots[i].second) {
            ans++;
            right = robots[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int gcd(int a, int b) {
    int t;
    while (b) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main() {

    int a, b;
    int r1, r2;
    while (cin >> a >> b) {
        r1 = gcd(a, b);
        r2 = a / r1 * b;
        cout << r1 << " " << r2 << endl;
    }

    return 0;
}


Measured memory_bytes: 3080
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos(-1);

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

vector<ll> dijkstra(int start, vector<vector<pair<int, ll>>>& graph) {
	vector<ll> dist(graph.size(), INF); dist[start] = 0;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; pq.emplace(0, start);
	while (!pq.empty()) {
		ll cost; int idx; tie(cost, idx) = pq.top(); pq.pop();
		if (dist[idx] < cost) continue;
		for (auto next : graph[idx]) if (chmin(dist[next.first], cost + next.second)) pq.emplace(dist[next.first], next.first);
	}
	return dist;
}


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

	int V, E, r; scanf("%d %d %d", &V, &E, &r);
	vector<vector<pair<int, ll>>> g(V); //g[i] := iからjまでの距離がd
	for (int i = 0; i < E; i++) {
		int s, t, d; scanf("%d %d %d", &s, &t, &d);
		g[s].emplace_back(t, d);
	}
	auto d = dijkstra(r, g);
	for (int i = 0; i < V; i++) {
		if (d[i] == INF) puts("INF");
		else printf("%lld\n", d[i]);
	}
	return 0;

}


Measured memory_bytes: 19380
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

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

    vi a(N);
    rep (i, N) cin >> a[i];

    rep (i, K) {
        vi b(N+1);
        rep (j, N) {
            int l = max(0, j-a[j]);
            int r = min(j+a[j]+1, N);
            b[l]++; b[r]--;
        }
        rep (j, N) b[j+1] += b[j];
        b.ppb();

        if (a == b) break;

        a = b;
    }

    rep (i, N) cout << a[i] << endl;
}


Measured memory_bytes: 4804
#include <cmath>

#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cout.precision(16);
  cout << fixed;

  int n;
  int d;
  cin >> n >> d;

  int len = 2 * d + 1;

  cout << (n + len - 1) / len;
}


Measured memory_bytes: 256
function main(input) {
  var inputs = input.split('\n');

  var nums = inputs[0].split(' ');
  var n = parseInt(nums[0], 10);
  var m = parseInt(nums[1], 10);
  var q = parseInt(nums[2], 10);

  var groups = [];
  for (var i = 0; i < q; i++) {
    groups.push(inputs[i + 1].split(' ').map((n) => parseInt(n, 10)));
  }

  var source = [];
  for (var i = 1; i <= m; i++) {
    source.push(i);
  }

  // push patters to "patterns"
  for (var i = 0; i < source.length; i++) {
    genePattern(n, i, [], source);
  }

  var maxScore = 0;
  patterns.forEach((pattern, i) => {
    var score = 0;
    groups.forEach((item, i) => {
      if(pattern[item[1] - 1] - pattern[item[0] - 1] === item[2]) {
        score += item[3];
      }
    });
    if (maxScore < score) maxScore = score;
  });

  console.log(maxScore);
}

var patterns = [];
function genePattern(n, preIndex, preArray, source) {
  var temp = preArray.concat();
  temp.push(source[preIndex]);

  if (temp.length == n) {
    patterns.push(temp);
    return;
  }

  for (var i = preIndex; i < source.length; i++) {
    genePattern(n, i, temp, source);
  }
}

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


Measured memory_bytes: 82176
import itertools

s=input()

keta = len(s)

risuto = ['3','5','7']

ans = 0

for i in range(3,keta+1):
    for j in itertools.product(risuto, repeat=i):
        #print(j)
        if '3' in j and '5' in j and '7' in j:
            if int(''.join(j)) <= int(s):
                   ans += 1
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;


const int MAX = 150001;  
int main(){
    int n, k;
    cin >> n >> k;
    vector <int> v(n,0);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < k; ++i) ans += v[i];
    cout << ans;
}

Measured memory_bytes: 3220
import java.util.*;
import java.io.*;

public class Main {
	static class Node {
		int key = 0;
		Node parent = NIL;
		Node left = NIL;
		Node right = NIL;
	}
	static Node NIL = new Node();
	
	static class Tree {
		Node root = NIL;
	}
	
	public static void main(String[]  args) {
		int m = nextInt();
		
		Tree tree = new Tree();
		
		for (int i = 0; i < m; i ++) {
			next();
			if (nextbuf[0] == 'i') {
				insert(tree, nextInt());
			} else {
				inorder(tree.root);
				System.out.println();
				preorder(tree.root);
				System.out.println();
			}
		}
	}
	
	static void insert(Tree tree, int key) {
		Node z = new Node();
		z.key = key;
		Node y = NIL;
		Node x = tree.root;
		
		while (x != NIL) {
			y = x;
			x = (key < x.key) ? x.left: x.right;
		}
		z.parent = y;
		
		if (z.parent == NIL) {
			tree.root = z;
		} else if (z.key < z.parent.key) {
			z.parent.left = z;
		} else {
			z.parent.right = z;
		}
	}

	static void preorder(Node u) {
		if (u == NIL) return;

		System.out.print(" ");
		System.out.print(u.key);
		preorder(u.left);
		preorder(u.right);
	}

	static void inorder(Node u) {
		if (u == NIL) return;

		inorder(u.left);
		System.out.print(" ");
		System.out.print(u.key);
		inorder(u.right);
	}
	
	private static byte[] buf = new byte[1 << 20];
	private static int len = 0;
	private static int ptr = 0;

	private static byte read() {
		if (ptr >= len) {
			try {
				len = System.in.read(buf);
			} catch (Exception e) {
			}
			ptr = 0;
		}

		return buf[ptr++];
	}

	private static int nextInt() {
		int num = 0;

		byte b = read();
		while(!Character.isDigit(b) && b != '-') b = read();
		int sign;
		if (b == '-') {
			sign = -1;
			b = read();
			if (!Character.isDigit(b)) return 0;
		} else {
			sign = 1;
		}
		
		while(Character.isDigit(b)) {
			num *= 10;
			num += sign * (b - '0');
			b = read();
		}
		
		return num;
	}

	private static byte[] nextbuf = new byte[11];
	private static int nextlen;

	private static void next() {
		nextlen = 0;

		byte b = read();
		while(!Character.isAlphabetic(b) && !Character.isDigit(b)) b = read();
		while(Character.isAlphabetic(b) || Character.isDigit(b)) {
			nextbuf[nextlen++] = b;
			b = read();
		}
	}
} 



Measured memory_bytes: 147468
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=2005;
int l[N],r[N],v[N],n;
bool u[N];
char a[N],b[N];
bool check(char *s){
	for (int i=0;i<n;i++)
		if (s[i]=='1') return 0;
	return 1;
}
int main(){
	scanf("%s%s",a,b);
	n=strlen(a);
	int ans=n*2;
	if (check(b)) ans=check(a)?0:-1;
	else{
		for (l[0]=0;b[(n-l[0])%n]=='0';l[0]++);
		for (r[0]=0;b[r[0]]=='0';r[0]++);r[n]=r[0];
		for (int i=1;i<n;i++) l[i]=b[i]=='1'?0:l[i-1]+1;
		for (int i=n-1;i;i--) r[i]=b[i]=='1'?0:r[i+1]+1;

		for (int i=0;i<n;i++){
			memset(v,0,sizeof v);
			for (int j=0;j<n;j++){
				u[j]|=b[(j+i)%n]=='1';
				if (!u[j] && a[j]!=b[(j+i)%n]) v[l[j]]=max(v[l[j]],r[(j+i)%n]);
			}
			for (int j=n-1;j;j--) v[j]=max(v[j],v[j+1]);
			int cnt=v[1];
			for (int j=2;j<n;j++) cnt=min(cnt,j-1+v[j]);
			cnt=cnt*2+i;
			for (int j=0;j<n;j++) cnt+=a[j]!=b[(j+i)%n];
			ans=min(ans,cnt);
		}

		for (int i=0;i<n;i++) u[i]=b[i]=='1';
		for (int i=1;i<n;i++){
			memset(v,0,sizeof v);
			for (int j=0;j<n;j++){
				u[j]|=b[(j-i+n)%n]=='1';
				if (!u[j] && a[j]!=b[(j-i+n)%n]) v[r[j]]=max(v[r[j]],l[(j-i+n)%n]);
			}
			for (int j=n-1;j;j--) v[j]=max(v[j],v[j+1]);
			int cnt=v[1];
			for (int j=2;j<n;j++) cnt=min(cnt,j-1+v[j]);
			cnt=cnt*2+i;
			for (int j=0;j<n;j++) cnt+=a[j]!=b[(j-i+n)%n];
			ans=min(ans,cnt);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int ASC(const int *a,const int *b){
	return (*a - *b);
}

int DESC(const int *a,const int *b){
	return (*b - *a);
}

void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

int main(int argc, char const *argv[])
{
	int n,m,X,Y;
	int *x,xsize = 0,xget;
	int *y,ysize = 0,yget;

	scanf("%d%d%d%d",&n,&m,&X,&Y);

	x = (int *)malloc(sizeof(int) * xsize);
	for (int i = 0; i < n; ++i){
		scanf("%d",&xget);
		append(x, &xsize, xget);
	}
	append(x, &xsize, X);
	qsort(x, xsize, sizeof(int), DESC);

	y = (int *)malloc(sizeof(int) * ysize);
	for (int i = 0; i < m; ++i){
		scanf("%d",&yget);
		append(y, &ysize, yget);
	}
	append(y, &ysize, Y);
	qsort(y, ysize, sizeof(int), ASC);

	if(x[0] < y[0])	puts("No War");
	else puts("War");
	return 0;
}


Measured memory_bytes: 128
var n,a,j:int64;
begin
  readln(n);
  if n mod 2=1 then
    writeln('0')
  else
  begin
    n:=n div 2;
    a:=n div 5;
    while a>0 do
    begin
      inc(j,a);
      a:=a div 5;
    end;
    writeln(j);
  end;
end.

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N,sum=0,msum=0,a;
    cin>>N;
    vector <int> c(13);
    for(int i=0;i<N;i++){
        cin >> a;
        c[a/400]=1;
        if(a>=3200){
           sum+=1; 
        }
        
    }
    
    for(int i=0;i<8;i++){
        msum+=c[i];
    }
    if(msum==0){cout << msum+1 << " " << sum <<"\n";}else{
    cout <<msum <<" "<<sum+msum<<"\n";}
     
    
    return 0;

}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    string s;
    cin >> s;

    vi num;
    for (auto ch : s) {
        num.push_back(ch - '0');
    }
    // 処理
    int minV = INT_MAX;
    int x    = 0;
    rep(i, num.size() - 2) {
        x    = num[i] * 100 + num[i + 1] * 10 + num[i + 2];
        minV = min(minV, abs(753 - x));
    }
    // 出力
    // sort(all(num));
    // rep(i, num.size()) { cout << num[i] << " "; }

    cout << minV << endl;

    return 0;
}


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

int g[205][205];
bool vis[205];
int col[205];
int N;
int cnt;

bool dfs(int v , int c){
  vis[v] = true;
  col[v] = c;
  bool ret = true;
  for(int i = 1; i <= N; ++i){
    if(g[v][i] == 0)continue;
    if(!vis[i]){
      if(!dfs(i , 1 - c))ret = false;
    }
    else{
      if(col[i] == c && v != i){
        ret = false;
      }
    }
  }
  return ret;
}

int main(){
  cin >> N;
  for(int i = 1; i <= N; ++i){
    vis[i] = false;
    for(int j = 1; j <= N; ++j){
      char x;
      cin >> x;
      if(x == '1'){
        g[i][j] = 1;
      }
      else{
        g[i][j] = 0;
      }
    }
  }
  // if can not bipartite then out put -1
  int ret = 0;
  if(dfs(1 , 1) == false)cout << -1 << endl;
  else{
    for(int i = 1; i <= N; ++i){
      int cnt = 0;
      for(int i = 1; i <= N; ++i)vis[i] = false;
      queue<int> q;
      q.push(i);
      while(!q.empty()){
        int s = q.size();
        for(int j = 1; j <= s; ++j){
          int c = q.front();
          q.pop();
          if(vis[c])continue;
          vis[c] = true;
          for(int k = 1; k <= N; ++k){
            if(g[c][k]){
              if(!vis[k])q.push(k);
            }
          }
        }
        ++cnt;
      }
      ret = max(ret , cnt);
    }
    cout << ret << endl;
  }
  return 0;
}


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

int main() {
 int D;
  cin>>D;
  if(D==25){
    cout<<"Christmas"<<endl;
  }
  else if(D==24){
    cout<<"Christmas"<<" "<<"Eve"<<endl;
  }
  else if(D==23){
    cout<<"Christmas"<<" "<<"Eve"<<" "<<"Eve"<<endl;
  }
  else if(D==22){
     cout<<"Christmas"<<" "<<"Eve"<<" "<<"Eve"<<" "<<"Eve"<<endl;
  }
}

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

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const set<A>& s) {
    for(auto it = s.begin(); it != s.end(); ++it) {
        output << *it << endl;
    }
    return output;
}

template<class A, class B>
ostream& operator << (ostream& output, const map<A, B>& m) {
    for(auto it = m.begin(); it != m.end(); ++it) {
        output << "[" << it->first << ", " << it->second << "]" << endl;
    }
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    // 6
    // 30 10 60 10 60 50
    for(int i = 2; i < n; ++i) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 3880
#include <iostream>
#define MAX 100005
#define NIL -1
using namespace std;

struct Node{int p,l,r;};

Node T[MAX];
int n,D[MAX];

void print(int u){
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].p<<", ";
    cout<<"depth = "<<D[u]<<", ";

    if(T[u].p==NIL)cout<<"root, ";
    else if(T[u].l==NIL)cout<<"leaf, ";
    else cout<<"internal node, ";
    cout<<"[";
    int c;
    for(c=T[u].l;c!=NIL;c=T[c].r){
        cout<<c;
        if(T[c].r!=NIL)cout<<", ";
    }
    cout<<"]"<<endl;
}

void rec(int u,int p){
    D[u]=p;
    if(T[u].r!=NIL)rec(T[u].r,p);
    if(T[u].l!=NIL)rec(T[u].l,p+1);
}

int main()
{
    int i,j,v,d,c,l,r;
    cin>>n;
    for(i=0;i<n;i++){
        T[i].p=T[i].l=T[i].r=NIL;
    }
    for(i=0;i<n;i++){
        cin>>v>>d;
        for(j=0;j<d;j++){
            cin>>c;
            if(j==0)T[v].l=c;
            else T[l].r=c;
            l=c;
            T[c].p=v;
        }
    }
    for(i=0;i<n;i++){
        if(T[i].p==NIL)r=i;
    }
    rec(r,0);
    for(i=0;i<n;i++)print(i);
    return 0;
}

Measured memory_bytes: 7720
<<NOTE.!
サイコロ I
  次の展開図から得られるサイコロを転がすシミュレーションを行うプログラムを作成してください。
  サイコロの各面には図のとおりに 1 から 6 のラベルが割りあてられています。

  + http://judge.u-aizu.ac.jp/onlinejudge/IMAGE2/ITP1_11_A_1.png
  + http://judge.u-aizu.ac.jp/onlinejudge/IMAGE2/ITP1_11_A_2.png

  入力としてサイコロの各面のラベルに対応する数字と、転がす命令の列が与えられるので、サイコロの上面の数字を出力してください。シミュレーションの初期状態は、図のとおりのラベルの位置でサイコロが置かれているものとします。

Input
  １行目に各面の数字が、図に示すラベルの順番に空白区切りで与えられます。

  ２行目に命令を表す１つの文字列が与えられます。命令はそれぞれ図に示す４方向を表す文字 E、N、S、W を含む文字列です。

Output
  すべての命令を実行した後のサイコロの上面の数を１行に出力してください。

Constraints
    0? 入力されるサイコロの面の数字 ?100
    0? 命令を表す文字列の長さ ?100

Note
  続くシリーズ Dice III, Dice IV では、複数のサイコロを扱うので、サイコロをクラスや構造体で作成しておきましょう。

Sample Input 1
1 2 4 8 16 32
SE

Sample Output 1
8

各面に 1, 2, 4, 8, 16, 32 と書かれたサイコロを S の方向に転がした後、E の方向に転がすと、上面の数字が 8 になります。


Sample Input 2
1 2 4 8 16 32
EESWN

Sample Output 2
32

NOTE

class Dice
  attr_accessor :faces
  def initialize(faces)
    <<-NOTE.!
    |T F L|
    |B U R|
    NOTE

    top, front, right, left, back, bottom = faces
    @faces = [[top, bottom], [front, back], [left, right]]
  end

  def move(commands)
    commands.split('').each do |com|
      case com.upcase.to_sym
      when :E
        faces[0], faces[2] = faces[2], faces[0].reverse
        # @top, @right, @bottom, @left = left, top, right, bottom
      when :W
        faces[0], faces[2] = faces[2].reverse, faces[0]
        # @top, @right, @bottom, @left = right, bottom, left, top
      when :N
        faces[0], faces[1] = faces[1], faces[0].reverse
        # @top, @front, @bottom, @back = front, bottom, back, top
      when :S
        faces[0], faces[1] = faces[1].reverse, faces[0]
        # @top, @front, @bottom, @back = back, top, front, bottom
      end
    end
  end

  def top
    faces[0][0]
  end

  def bottom
    faces[0][1]
  end

  def front
    faces[1][0]
  end

  def back
    faces[1][1]
  end

  def left
    faces[2][0]
  end

  def right
    faces[2][1]
  end

  def info
    p({ T: top, F: front, R: right, L: left, U: back, B: bottom })
  end
end

$stdin = DATA if $stdin.eof?

dice = Dice.new(gets.split)
dice.move(gets.strip)

puts dice.top
__END__
1 2 4 8 16 32
SE

Measured memory_bytes: 6132
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> c(h+2,vector<char>(w+2,'#'));
  int white = 0;
  rep(i,h){
    rep(j,w){
      char tmp;
      cin >> tmp;
      c.at(i+1).at(j+1) = tmp;
      if(tmp == '.') white++;
    }
  }
  vvi dis(h+2,vi(w+2,-1));
  dis.at(1).at(1) = 0;
  queue<pair<int,int>> que;
  pair<int,int> p(1,1);
  que.push(p);
  
  vector<int> forx = {0,0,1,-1};
  vector<int> fory = {1,-1,0,0};
  while(!que.empty()){
    pair<int,int> v = que.front();
    que.pop();
    int x,y;
    int nx,ny;
    tie(x,y) = v;
    rep(i,4){
      nx = x + forx.at(i);
      ny = y + fory.at(i);
      if(c.at(nx).at(ny) == '#') continue;
      if(dis.at(nx).at(ny) != -1) continue;
      dis.at(nx).at(ny) = dis.at(x).at(y) + 1;
      pair<int,int> nv(nx,ny);
      que.push(nv);
    }
  }
  if(dis.at(h).at(w) == -1){
    cout << -1 << endl;
    return 0;
  }
  cout << white - dis.at(h).at(w) - 1 << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
ans = float('inf')
for h in range(1,H):
    S = [h * W]
    w = W // 2
    S += [(H-h) * w]
    S += [(H-h) * (W-w)]
    ans = min(ans,max(S)-min(S))

for h in range(1,H):
    S = [h * W]
    hb = (H-h) // 2
    S += [hb * W]
    S += [(H-h-hb) * W]
    ans = min(ans,max(S)-min(S))

for w in range(1,W):
    S = [H * w]
    h = H // 2
    S += [h * (W-w)]
    S += [(H-h) * (W-w)]
    ans = min(ans,max(S)-min(S))

for w in range(1,W):
    S = [w * H]
    wb = (W-w) // 2
    S += [wb * H]
    S += [(W-w-wb) * H]
    ans = min(ans,max(S)-min(S))

print(ans)

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

#include <iostream>
#include <fstream>

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

#define TR(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define IN(c, x) ((c).find(x) != (c).end())   //O(log n)
#define IN_L(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define FOR(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define MOD(x, m) ((((x) % (m)) + (m)) % (m))
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define READ ({int t;cin >> t;t;})
#define EB emplace_back
#define fcout cout << fixed << setprecision(12)
#define fcerr cerr << fixed << setprecision(12)
#define print(x) cout << (x) << endl

#ifdef DEBUG
#define ERR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); _err(cerr,_it, args); }
#define DBG(x) cerr << #x << " is " << x << endl;
#else
#define DBG(x) {};
#define ERR(args...) {};
#endif
void _err(std::ostream& cerr,istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>
void _err(std::ostream& cerr, istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "  ";
    _err(cerr,++it, args...);
}

const double pi = 2 * acos(.0);
const int inf = 0x3f3f3f3f;
const ll mod = (ll) (1e9) + 7;
//const ll mod = (ll) 998244353 ;
const double eps = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

template <typename T>
ostream& operator << (ostream& os, const vector<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const deque<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template<class T>bool Chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool Chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//#define int ll

class BOneClue {
public:

void solve(std::istream& cin, std::ostream& cout, std::ostream& cerr) {
    int k,x;
    cin >> k >> x;
    FOR(i,x-k+1,x+k)cout << i << " ";
}


};


#undef int
int main() {

	BOneClue solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
    std::ostringstream err;
	in.tie(0); ios::sync_with_stdio(0);
//	solver.solve(in, out);
    solver.solve(in, out,err);
	return 0;
}


Measured memory_bytes: 256
import itertools


def sum_strlong(strlong):
    ans = int(strlong)
    for i in range(1, len(strlong)):
        for comb in itertools.combinations(range(len(strlong)-1), i):
            integer = ''
            for j, digit in enumerate(strlong):
                integer += digit
                if j in comb:
                    integer += '+'
            ans += eval(integer)
    return ans


def main():
    print(sum_strlong(input()))


main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

int n;

ll a[301][301]={};
bool d[301][301]={};
//ll a[100002]={};
//ll b[100002]={};
//ll c[100002]={};

const ll INF=100000000001;
int main() {

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

	for(int i=0;i<n;++i){
		for(int j=i+1;j<n;++j){
			for(int k=0;k<n;++k){
				if((i!=k)&&(j!=k)){
					if(a[i][j]==a[i][k]+a[k][j]){
						d[i][j]=true;
						d[j][i]=true;
					}
					if(a[i][j]>(a[i][k]+a[k][j])){
						cout<<"-1"<<endl;
						return 0;
					}
				}
			}
		}
	}
	ll total=0;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			if(!d[i][j])total+=a[i][j];
		}
	}
	cout<<total/2<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	int w;
	while(scanf("%d", &w) != EOF){
		rep(i, 10){
			if(w&1){
				printf("%d", 1<<i);
				w >>= 1;
				if(w) printf(" ");
			}else
				w>>=1;
		}
		puts("");
	}

	return 0;
}

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

typedef long long ll;
vector<ll> v;
ll n,a,dp[55][2505][55];

ll solve(int i, int s, int t) {
    if(i == n) return t > 0 && s%t == 0 && s/t == a;
    if(dp[i][s][t] != -1) return dp[i][s][t];
    return dp[i][s][t] = solve(i+1, s+v[i], t+1) + solve(i+1, s, t);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    while(cin >> n >> a) {
        v = vector<ll>(n);
        for(int i = 0; i < n; i++) {
            cin >> v[i];
        }
        memset(dp, -1, sizeof dp);
        cout << solve(0,0,0) << '\n';
    }
    return 0;
}

Measured memory_bytes: 59520
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long x; cin >> x;
  for(long long i = -1000; i <= 1000 ;++i){
    for(long long j = -1000; j <= 1000; ++j){
      if(x == (i * i * i * i * i) - (j * j * j * j * j)){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3636
#region using
using System;
using System.Collections.Generic;
using System.Linq;
using IEnumerable = System.Collections.IEnumerable;
using IEnumerator = System.Collections.IEnumerator;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;
#endregion

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            return consoleReader.Int < 1200 ? "ABC" : "ARC";
        }

        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    static class Ext
    {
        public static Dictionary<TKey, int> GroupCount<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) => source.GroupBy(keySelector).ToDictionary(g => g.Key, g => g.Count());
        public static Dictionary<TKey, int> GroupCount<TKey>(this IEnumerable<TKey> source) => source.GroupCount(i => i);
    }
    public class ConsoleReader { private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); private string[] line = Array.Empty<string>(); private int linePosition; private TextReader textReader; public ConsoleReader(TextReader tr) { textReader = tr; } public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string String { get { if (linePosition >= line.Length) { linePosition = 0; line = ReadLineSplit(); } return line[linePosition++]; } } public class SplitLine { private string[] splited; public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); } public int[] Int => String.Select(x => int.Parse(x)).ToArray(); public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray(); public long[] Long => String.Select(x => long.Parse(x)).ToArray(); public double[] Double => String.Select(x => double.Parse(x)).ToArray(); public string[] String => splited; } public SplitLine Split => new SplitLine(this); public class RepeatReader : IEnumerable<ConsoleReader> { ConsoleReader cr; int count; public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; } public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); public IEnumerable<string> String => this.Select(cr => cr.String); public IEnumerable<int> Int => this.Select(cr => cr.Int); public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1); public IEnumerable<long> Long => this.Select(cr => cr.Long); public IEnumerable<double> Double => this.Select(cr => cr.Double); } public RepeatReader Repeat(int count) => new RepeatReader(this, count); }
    #endregion
}


Measured memory_bytes: 11092
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i) << 0
array = a.map.with_index { |_, i| (a[i] - a[i-1]).abs } 
acost = array.reduce(:+)

n.times do |i|
  puts acost - array[i] - array[i+1] + (a[i-1] - a[i+1]).abs
end

Measured memory_bytes: 12932
n=int(input())
L=[int(x) for x in input().split()]
sum=0
product=0
mod=1000000007
for i in range(n):
    sum+=L[i]%mod
for i in range(n-1):
    sum-=(L[i]%mod)
    product+=sum*(L[i]%mod)
print(product%mod)

Measured memory_bytes: 31340
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int maxi = 1e6+10;
string s;
vector<int> v[maxi];
int n;
ll a[maxi];

int main () {
  cin >> n;
  std::vector<ll> result(n,0);
  rep(i,n) {
    cin >> a[i];
  }
  rep(i,n){
    result[0] += a[i] * pow(-1, i);
  }
  for (size_t i = 1; i < n; i++) {
    result[i] = 2 * a[i-1] - result[i-1];
  }
  rep(i,n) cout << result[i] << " ";
}


Measured memory_bytes: 28032
-- 1_2_A
main = do ns <- getLine
          let [a, b] = map (\x -> read x :: Int) $ words ns
          putStrLn $ comp a b

comp :: Int -> Int -> String
comp a b
    | a < b  = "a < b"
    | a > b  = "a > b"
    | a == b = "a == b"

Measured memory_bytes: 3596
a,b,c=map(int,input().split())
ans=0
for _ in range(10**6):
    if sum(i%2 for i in [a,b,c])==0:
        A=b//2+c//2
        B=c//2+a//2
        C=a//2+b//2
        ans+=1
        a,b,c=A,B,C
    else:
        print(ans)    
        exit()
print(-1)

Measured memory_bytes: 3064
N=input()

if (N[-1]=='2') or (N[-1]== '4') or (N[-1]== '5')  or (N[-1]== '7') or (N[-1]== '9'):
    print('hon')
elif (N[-1]=='0') or (N[-1]== '1') or (N[-1]== '6') or (N[-1]== '8'):
    print('pon')
else:
    print('bon')

Measured memory_bytes: 8952
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S1,S2;
  cin>>S1>>S2;
  int count=0;
  for(int i=0;i<3;i++){
    if(S1.at(i)==S2.at(i))
      count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-14 21:41:22
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  int a, b;
  cin >> a >> b;
  cout << (a + b + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    if(n%2==1)
        cout<<"0";
    else
    {
        n/=2;
        ll count=0;
        ll cur=5;
        while(cur<=n)
        {
            count+=n/cur;
            cur*=5;
        }
        cout<<count;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}
char ans[110][110];
int main() {
	int H,W;cin>>H>>W;
	REP(i,H){
		REP(j,W){
			cin>>ans[i+1][j+1];
		}
	}
	REP(i,H+2){
		REP(j,W+2){
			if(i==0||i==H+1||j==0||j==W+1){
				ans[i][j]='#';
			}
		}
	}
	REP(i,H+2){
		REP(j,W+2){
			cout<<ans[i][j];
		}
		cout<<endl;
	}
}


Measured memory_bytes: 256
import sys

class Node():
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.parent = None

    def prewalk(self):
        nodeList = [self.key]
        if self.left:
            nodeList += self.left.prewalk()
        if self.right:
            nodeList += self.right.prewalk()
        return nodeList

    def inwalk(self):
        nodeList = []
        if self.left:
            nodeList += self.left.inwalk()
        nodeList += [self.key]
        if self.right:
            nodeList += self.right.inwalk()
        return nodeList

class Tree():
    def __init__(self):
        self.root = None

    def insert(self, key):
        Nz = Node(key)
        Ny = None  # ???????£?
        Nx = self.root
        while Nx:
            Ny = Nx
            if Nz.key < Ny.key:
                Nx = Nx.left
            else:
                Nx = Nx.right
        Nz.parent = Ny
        if Ny == None:
            self.root = Nz
        elif Nz.key < Ny.key:
            Ny.left = Nz
        else:
            Ny.right = Nz

    def find(self, key):
        Nx = self.root
        while Nx and Nx.key != key:
            if key < Nx.key:
                Nx = Nx.left
            else:
                Nx = Nx.right
        return Nx

    def delete(self, key):
        Nz = self.find(key)
        # Ny: the node to be deleted
        if Nz.left and Nz.right:
            Ny = self.successor(Nz)
        else:
            Ny = Nz
        # Nx: y's child
        if Ny.left:
            Nx = Ny.left
        else:
            Nx = Ny.right

        if Nx:
            Nx.parent = Ny.parent

        if Ny.parent == None:
            self.root = Nx
        elif Ny == Ny.parent.left:
            Ny.parent.left = Nx
        else:
            Ny.parent.right = Nx

        if Ny != Nz:
            Nz.key = Ny.key

    def successor(self, Nx):
        if Nx.right:
            return self.minimum(Nx.right)

        Ny = Nx.parent
        while Ny != None and Nx == Ny.right:
            Nx = Ny
            Ny = Ny.parent
        return Ny

    def minimum(self, Nx):
        while Nx.left:
            Nx = Nx.left
        return Nx

    def print(self):
        print('', ' '.join(map(str, self.root.inwalk())))
        print('', ' '.join(map(str, self.root.prewalk())))

tree = Tree()

n = sys.stdin.readline()
for line in sys.stdin:
    if line[0] == 'i':
        tree.insert(int(line.split()[1]))
    elif line[0] == 'f':
        if tree.find(int(line.split()[1])):
            print('yes')
        else:
            print('no')
    elif line[0] == 'd':
        tree.delete(int(line.split()[1]))
    else:
        tree.print()

Measured memory_bytes: 156556
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define lb(v,x) lower_bound(all(v),x)
#define ub(v,x) upper_bound(all(v),x)
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

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

const int N = 100005;

ll dp[N][3];

int main(){
    IOS
    
    ll n;
    cin>>n;
    ll a[n+1],b[n+1],c[n+1];
    FOR(i,1,n+1){
        cin>>a[i]>>b[i]>>c[i];
    }
    a[0]=b[0]=c[0]=0;
    FOR(i,1,n+1){
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][2],dp[i-1][0]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
    cerr<<1.0/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 4992
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

vector<set<int>> calc_ans(int k) {
    int n = k * (k - 1) / 2;
    if (k == 1) {
        vector<set<int>> ans(1);
        return ans;
    } else {
        vector<set<int>> ans = calc_ans(k-1);
        set<int> last;
        for (int i = 0; i < k-1; i++) {
            int j = n - (k-1) + 1 + i;
            ans[i].insert(j);
            last.insert(j);
        }
        ans.push_back(move(last));
        return ans;
    }
}

int main() {
    int N;
    cin >> N;
    int K = 1;
    while (K * (K - 1) / 2 < N) {
        K++;
    }
    if (K * (K - 1) / 2 != N) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    vector<set<int>> ans = calc_ans(K);
    cout << K << endl;
    for (const set<int>& s : ans) {
        cout << s.size() << " ";
        for (auto it = s.begin(); it != s.end(); it++) {
            cout << *it;
            if (it != prev(s.end())) {
                cout << " ";
            }
        }
        cout << endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 1e5 + 5;
int arr[N], memo[N];

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

	int n, k;
	cin >> n >> k;

	rep(i, 0, n)
		cin >> arr[i];

	for (int i = n - 2; i >= 0; i--)
	{
		memo[i] = 2e9 + 5;
		for (int j = k; j >= 1; j--)
			if (i + j < n)
				memo[i] = min(memo[i], memo[i + j] + abs(arr[i] - arr[i + j]));
	}

	cout << memo[0] << endl;

	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

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

    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);

    cout << a << " " << b << " " << c;








    return 0;
}


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

int main(){
    string S;
    cin >> S;
    string ans;
    if(S[0] == 'S') ans = "Cloudy";
    else if(S[0] == 'C') ans = "Rainy";
    else ans = "Sunny";
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    while(true){
        ll n,k,s;
        cin>>n>>k>>s;
        if(n==0) break;
        ll ans=0;
        for(int i=0;i<(1<<n);i++){
            ll sum=0,cnt=0;
            for(int j=0;j<n;j++){
                if(i>>j&1){
                    cnt++;
                    sum+=j+1;
                }
            }
            if(cnt==k&&sum==s) ans++;
        }
        cout<<ans<<'\n';
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[2005][2005]={};

signed main()
{
    int mod=1e9+7;
    int n,m;
    cin>>n>>m;
    int s[n+1],t[m+1];

    for (int i = 1; i <= n; ++i) {
        cin>>s[i];
    }

    for (int i = 1; i <= m; ++i) {
        cin>>t[i];
    }


    dp[0][0]=1;
    for (int i = 0; i <=n ; ++i) {
        dp[i][0]=1;
    }

    for (int i = 0; i <=m ; ++i) {
        dp[0][i]=1;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <=m ; ++j) {
            if(s[i]==t[j])
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
            else
            {
                dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod-dp[i-1][j-1]%mod+mod)%mod;
            }
        }
    }

    cout<<dp[n][m];
}

Measured memory_bytes: 31616
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

from collections import Counter
def main():
    n=II()
    aa=LI()
    cnt=Counter(aa)
    even=0
    ans=0
    for v in cnt.values():
        if v&1==0:even+=1
        ans+=v//2
    ans-=even//2
    print(n-ans*2)

main()

Measured memory_bytes: 18592