akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int N;
map<string, int> id;
bool adjacent[41][41];
int weight[41], wes[41];
int ans;

void dfs(ll S, int wsum, int curr) {

  ans = max(ans, wsum);

  if(wsum + wes[N-1] - (curr ? wes[curr-1] : 0) <= ans) return;

  if(curr == N-1) return;

  const int next = curr + 1;

  bool ok = 1;
  rep(k, next) if(adjacent[next][k] && (S >> k & 1)) { ok = 0; break; }

  if(!ok) {
    dfs(S, wsum, next);
  }
  else {
    dfs(S, wsum, next);
    dfs(S|(1LL<<next), wsum + weight[next], next);
  }
}

int main() {

  while(cin >> N && N) {
    rep(i, 41) weight[i] = 0;
    rep(i, 41) rep(j, 41) adjacent[i][j] = 0;
    id.clear();
    int v = 0;

    rep(i, N) {
      string s; cin >> s;
      if(id.find(s) == id.end()) id[s] = v++;
      cin >> weight[id[s]];
      int n; cin >> n;
      rep(_, n) {
        string t; cin >> t;
        if(id.find(t) == id.end()) id[t] = v++;
        adjacent[id[s]][id[t]] = 1;
      }
    }

    rep(i, N) wes[i] = weight[i] + (i ? wes[i-1] : 0);

    ans = 0;
    dfs(1LL<<0, weight[0], 0);

    cout << ans << endl;

  }
  
  return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std; int main(){ 
  string A;
  cin >> A;
  
  if(A[0] == A [2]){
  cout << "Yes" << endl;
  }
  
  if(A[0] != A[2]){
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <stdio.h> 
#include <map>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n,a;
	cin>>n>>a;
	int cnt = 0;
	while(true) {
		if(n<=0) {
			break;
		}
		n=n-a;
		cnt++; 
	}
	
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
int a,b,c,d;

int main(){
	cin >> a >> b >> c >> d;
	
	REP(k,0,2){
		if(k) cout << 'D';
		REP(i,0,c-a+k) cout << 'R';
		REP(i,0,d-b+k) cout << 'U';
		if(k) cout << 'L' << 'U';
		REP(i,0,c-a+k) cout << 'L';
		REP(i,0,d-b+k) cout << 'D';
		if(k) cout << 'R';
	}
	
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
def main()
  n = gets.chomp.to_i
  x = gets.chomp.split(' ').map(&:to_i)
  dic = Hash.new(0)
  for i in 0..n-1 do
    dic[x[i]] = dic[x[i]] + 1
  end
  target1 = dic.select{|k,v| v >=2}.keys.sort.reverse
  target2 = dic.select{|k,v| v >=4}.keys.sort.reverse
  ans1 = 0
  if target2.size != 0
    ans1 = target2[0]*target2[0]
  end
  if target1.size < 2
    puts [0,ans1].max
  else
    puts [target1[0]*target1[1],ans1].max
  end
end

main()

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

using namespace std;

#define debug(x) cout << "\n" << (#x) << " is " << (x) << endl

#define MAXN 100

int points[MAXN][MAXN];

int N, D;

double len(int A, int B){
	double sum = 0;
	for(int i = 0; i < D; i++){
		sum += (points[A][i] - points[B][i]) * (points[A][i] - points[B][i]); 
	}

	return sqrt(sum);
}
int main(){
	#ifdef EVAL	
		freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	cin >> N >> D;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < D; j++){
			cin >> points[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < N; i++){
		for(int j = i + 1; j < N; j++){
			double sum1 = len(i,j);
			int sum2 = sum1;
			if(sum2 == sum1){
				ans++;
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


N,M=map(int,input().split())
p=list(map(int,input().split()))

g=UnionFind(N)
for i in range(M):
    x,y=map(int,input().split())
    g.union(x,y)

ans=0
for i in range(N):
    ans+=g.same_check(i+1,p[i])

print(ans)

Measured memory_bytes: 13812
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[1000],f[1000];
ll ans, n;
void read(int &x){
	int f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){
		if(s=='-') f=-1;s=getchar();
	}
	while(s>='0'&&s<='9'){
		x=x*10+s-'0';s=getchar();
	}
	x*=f;
}
void print(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) print(x/10);
	putchar(x%10+'0');
}
ll work() {
    ll re = 0, sum = 0;
    for (int i = 0; i < n - 1; i++) {
        re = re * 10 + s[i];
        if (f[i]) {
            sum += re;
            re = 0;
        }
    }
    re = re * 10 + s[n - 1];
    return re + sum;
}
void dfs(int k) {
    if (k == n - 1) {
        ans += work();
        return;
    }
    f[k] = false;
    dfs(k + 1);
    f[k] = true;
    dfs(k + 1);
}
int main() {
    cin >> s;
    n = strlen(s);
    for (int i = 0; i < n; ++i) {
        s[i] -= '0';
    }
    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    char b;
    cin >> b;
    if(b == 'A') cout << 'T' << endl;
    if(b == 'T') cout << 'A' << endl;
    if(b == 'C') cout << 'G' << endl;
    if(b == 'G') cout << 'C' << endl;
    return 0;
}


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

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

    string ans;
    for(int i=0;i<s.length();i+=2)ans+=s[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	long l = read.to!long;
	long t = read.to!long;
	
	long[] xs1, xs2;
	for(int i = 0; i < n; i ++){
		long x = read.to!long;
		int w = read.to!int;
		if(w == 1) xs1 ~= x;
		else xs2 ~= x;
		}
	
	debug writeln("xs1 ", xs1);
	debug writeln("xs2 ", xs2);
	
	// 行先(すり抜ける場合)
	long[] ys1, ys2;
	foreach(x; xs1) ys1 ~= (x + t) % l;
	foreach(x; xs2) ys2 ~= ((x - t) % l + l) % l;
	
	debug writeln("ys1 ", ys1);
	debug writeln("ys2 ", ys2);
	
	// すり抜けアリが何周するか？
	long d = t / l;
	long r = t % l;
	
	debug writeln("d ", d);
	debug writeln("r ", r);
	
	// すり抜けずに反射する場合、
	// アリたちの円環上での位置関係はかわらない。
	// よって1個のアリについてどこへ行くか調べればよい。
	
	// 0以上で0に最も近い位置にいるアリは誰か？
	
	// これがかわるのは0をまたぐアリがいた時
	
	// 正向きで0をまたぐ（達する）回数と、負向きで0をまたぐ（超える）回数の差し引き
	// (t / l) * #(x in xs1) + #(x in xs1 where x + r >= l)
	// (t / l) * #(x in xs2) + #(x in xs2 where x - r < 0)
	
	long c1 = ((t / l) % n) * xs1.length;
	foreach(x; xs1) if(x + r >= l) c1 += 1;
	long c2 = ((t / l) % n) * xs2.length;
	foreach(x; xs2) if(x - r < 0) c2 += 1;
	long c = ((c1 - c2) % n + n) % n;
	
	debug writeln("c1 ", c1);
	debug writeln("c2 ", c2);
	debug writeln("c ", c);
	
	// 0以上で0に最も近い位置にいるアリがわかれば、あとは自動的にわかる
	long[] ys = ys1 ~ ys2;
	ys.sort();
	
	debug writeln("ys ", ys);
	
	long[] ans;
	for(int i = 0; i < cast(int)(n - c); i ++) ans ~= ys[cast(int)(i + c)];
	for(int i = cast(int)(n - c); i < n; i ++) ans ~= ys[cast(int)(i + c - n)];
	
	foreach(a; ans) a.writeln;
	}

Measured memory_bytes: 6140
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private int check(String S, int sz, String prev, int max, int pos) {
        if (pos == S.length()) { 
            return sz;
        }

        for (int i = 1; pos + i <= S.length(); i++) {
            String s = S.substring(pos, pos + i);
            if (prev.equals(s)) continue;
            return check(S, sz + 1, s, max, pos + i);
        }
        return sz;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        int max = check(S, 0, "", 0, 0);

        System.out.println(max);

        return;
    }

}

Measured memory_bytes: 66132
#include <algorithm>
#include <iostream>
#include <string>
#include <queue>
#include <string.h>
using namespace std;
int bit[6]={1,2,4,8,16,32};
int cost[108][108];
//0-99/land
//100-105/cake
//106/home
//107/city
int change(string s){
	if(s=="H")return 106;
	if(s=="D")return 107;
	if(s[0]=='C')return 99+(s[1]-'0');
	int t=0;
	for(int i=1;i<s.size();i++){
		t*=10;
		t+=(s[i]-'0');
	}
	return t-1;
}

typedef pair<int,int>p;
//cost,pos
typedef pair<p,int>P;
//cost,pos,bit


int bit_che(int to,int b){
	if(99<to&&to<106){
		if(bit[to-100]&b)return 0;
	}
	return 1;
}


int main(){
	
	int m;//
	int n;//
	int k;//
	int d;//
	while(cin>>m,m){
		cin>>n>>k>>d;
		//cout<<"--------\n";
		int cake[6];
		for(int i=0;i<m;i++)cin>>cake[i];
		memset(cost,1000000,sizeof(cost));
		for(int i=0;i<d;i++){
			string s1,s2;
			int c;
			cin>>s1>>s2>>c;
			int a=change(s1),b=change(s2);
			
			cost[a][b]=c*k;
			cost[b][a]=c*k;
			//cout<<a<<" "<<b<<" "<<c*k<<endl;
		}
		int data[108][64];
		for(int i=0;i<108;i++){
			for(int j=0;j<64;j++){
				data[i][j]=2000000;
			}
		}
		//memset(data,2000000,sizeof(data));
		priority_queue<P, vector<P>, greater<P> > Q;
		Q.push(P(p(0,106),0));
		int ans=100000000;
		while(!Q.empty()){
			int cos=Q.top().first.first;
			int pos=Q.top().first.second;
			int b=Q.top().second;
			Q.pop();
			//cout<<"#"<<cos<<" "<<pos<<" "<<b<<endl;
			
			if(pos==107){
				ans=min(ans,cos);
			}
			
			if(99<pos&&pos<106){
				cos-=cake[pos-100];
				b+=bit[pos-100];
			}
			data[pos][b]=cos;
			
			for(int i=0;i<108;i++){
				
				if(cost[pos][i]<10000&&(bit_che(i,b))&&data[i][b]>cos+cost[pos][i]){
					Q.push(P(p(cos+cost[pos][i],i),b));
					
				}
				
			}
			
			
			
		}
		cout<<ans<<endl;
		
	}
	
	
	return 0;
}


Measured memory_bytes: 2468
<?php
  while (true) {
    list($n, $x) = explode(" ", trim(fgets(STDIN)));
    if (($n == "0") && ($x == "0")) {
      return;
    }
    $i = 0;
    for ($a=1; $a<=$n; $a++) {
      for ($b=($a+1); $b<=$n; $b++) {
        for ($c=($b+1); $c<=$n; $c++) {
          if ((($a + $b + $c) == $x) && ($a != $b) && ($b != $c)) {
            $i++;
          }
        }
      }
    }
    print($i."\n");
  }
?>

Measured memory_bytes: 6572
from decimal import Decimal
import math

def f(c, an):
    s = 0
    for i in range(c):
        th = input()
        ra = Decimal(math.radians(th))
        s += Decimal(math.sin(ra))
        an -= th
    else:
        ra = Decimal(math.radians(an))
        s += Decimal(math.sin(ra))
        return s

while True:
    m = input()
    if m == 0: break
    ms = f(m-1, 360)
    n = input()
    ns = f(n-1, 360)
    if ns < ms:
        print 1
    elif ms < ns:
        print 2
    else:
        print 0

Measured memory_bytes: 5932
number = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(number[K-1])

Measured memory_bytes: 61840
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
/////////////////// 
//

#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n;
  cin >> n;
  pri((n+2-1)/2);
  return 0;
}







Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())

A_i=min(X//500,A)+1
B_i=min(X//100,B)+1
C_i=min(X//50,C)+1

ans=0

for i in range(0,A_i):
    for j in range(0,B_i):
        for k in range(0,C_i):
            if i*500+j*100+k*50==X:ans+=1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	string s;
	cin>>s;
	bool a[26];
	rep(i,26)a[i]=false;
	rep(i,s.size())a[s[i]-'a']=true;
	rep(i,27){
		if(i==26){
			cout<<"None"<<endl;
			break;
		}else{
			if(!a[i]){
				cout<<(char)('a'+i)<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
//obj;
class binary{
public:
    bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}
int binary_search(int key,vi a) {
   
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key,a)) ok = mid;
        else ng = mid;
    }
    return ok;
}
}obj;

int main(){
int n; cin>>n;
vi a(n);rep(i,n)cin>>a.at(i);
ll ans=0;
for(int i=1;i<n;i++){
    if(a.at(i)<a.at(i-1)){
        ans+=a.at(i-1)-a.at(i);
        a.at(i)=a.at(i-1);
    }
}
cout<<ans<<endl;

return 0;
 }


Measured memory_bytes: 4044
N = int(input())
flag = False
if N % 4 == 0 or N % 7 == 0:
  flag = True
else:
  i = 0
  while i * 4 <= 100:
    i += 1
    if N % (i * 4) % 7 == 0 or N % (i * 7) % 4 == 0:
      flag = True
      break

print("Yes" if flag else "No")

Measured memory_bytes: 3060
import sys
H = int(input())
W = int(input())
N = int(input())
X = max(H, W)
Y = min(H, W)
count = 0
total = 0
for _ in range(Y):
    total += X
    count += 1
    if total >= N:
        print(count)
        sys.exit()
for _ in range(X):
    total += Y
    count += 1
    if ctotal >= N:
        print(count)
        break


Measured memory_bytes: 9092
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

int a[200007];

int main()
{
    int i,j;
    int N;

    scanf("%d", &N);

    for( i=0; i<N; i++)
        scanf("%d", &a[i]);

    int cnt = 0;
    int now = 1;
    for( i=0; i<N; i++)
    {
        if( a[i] == now)
            now++;
        else
            cnt++;
    }

    if( now==1)
        printf("-1\n");
    else
        printf("%d\n", cnt);


    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/   \/_________/\/__/   \/__/
//


Measured memory_bytes: 1024
def kukan(n, a):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            L = a[i] - dp[i + 1][j]
            R = a[j] - dp[i][j - 1]
            dp[i][j] = L if L > R else R
    return dp[0][n - 1]


n = int(input())
a = list(map(int, input().split()))
print(kukan(n, a))


Measured memory_bytes: 234176
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int a, b, i;
	while(cin>>a>>b){
		a += b;
		
		for(i = 1;; i++){
			if(a < 10){
				break;
			}
			a = a / 10;
		}
		
		cout << i << endl;
	}
}

Measured memory_bytes: 592
A = []
for i in range(5):
  a = int(input())
  A.append(a)
B = []
for i in range(5):
  b = A[i]%10
  B.append(b)
C =[]
for i in range(5):
  if B[i] != 0:
    c = A[i]+10-B[i]
  else:
    c = A[i]
  C.append(c)
t = 0  
for i in range(5):
  t += C[i]
B.sort()
z = set(B)
if min(z) == 0:
  z.remove(0)
if len(z) ==0:
  print(t)
else:
  print(t-10+min(z))

Measured memory_bytes: 3064
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
    ll ans=0;
    ll count2=0;
    ll count5=0;
	if(n%2==1)
	{
	    //cout<<'a';
	    cout<<0;return 0;
	}
	else
	{
	  //cout<<'a';
	   unsigned long long int temp=5;
	   while(temp<=n)
	   {
	       count5+=(n/temp)/2;
	       temp*=5;
	    }
	}
	cout<<count5;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); ++i)

int main(){
    int n; std::cin >> n;
    std::vector<int> a(n,0);
    rep(i,n-1){
        int k; std::cin >> k;
        if(k > 0) ++a[k-1];
    }
    rep(i,n) std::cout << a[i] << std::endl;
    return 0;
}

Measured memory_bytes: 3976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan=new Scanner(System.in);
		int A=scan.nextInt();
		int B=scan.nextInt();
		System.out.println((A+B)%24);

	}

}


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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define forr(i,a,b) for(ll i=(a);i<=(b);i++)
#define ford(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define size(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)



int main(void) {
    int N,i,j;
    cin >> N;
    int n[200990];
    int m[200990];
    for(i=0;i<N-1;++i){
       cin >> n[i];
      
    }
     for(i=0;i<N-1;++i){
     
       m[n[i]-1]++;
    }
    for (j=0;j<N;++j){
        
         cout << m[j] << "\n";
    

    }   
    
  return 0;
}

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

int main(){
    string S;
    getline(cin,S);
    int size=S.size();
    int num_0=count(S.cbegin(),S.cend(),'0');
    cout<<min(num_0*2,(size-num_0)*2)<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(n) for(int i=0;i<(n);i++)
#define rep1(n) for(int i=1;i<=(n);i++)
#define all(n) n.begin(),n.end()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define pb push_back
#define debug(x) cout<<#x<<"="<<x<<'\n';
ll dp[3005][3005];
ll arr[3005];

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
       cin>>arr[i];
       dp[i][i] = arr[i];
    }
    for(int l=2;l<=n;l++){
        for(int i=1;i+l-1<=n;i++){
            int r = i+l-1;
            dp[i][r] = max(arr[i] - dp[i+1][r] , arr[r] - dp[i][r-1]);
            //cout<<i<<" "<<r<<" "<<dp[i][r]<<'\n';
        }
    }

    cout<<dp[1][n]<<'\n';

}


Measured memory_bytes: 70016
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1e18;

vector<pair<long long, long long>> divisor_pair(long long n) {
	vector<pair<long long, long long>> v;
	for (long long i = 1; i * i <= n; ++i) {
		if (n % i == 0) v.emplace_back(i, n/i);
	}
	return v;
}

int digit(long long x) {
	int res = 0;
	while (x > 0) x /= 10, res++;
	return res;
}

int main() {
	long long n;
	cin >> n;
	auto d = divisor_pair(n);
	long long ans = INF;
	for (auto e : d) {
		long long now = max(digit(e.first), digit(e.second));
		ans = min(ans, now);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3164
#include <iostream>

using namespace std;

int main() {
    long long x, y;
    cin >> x >> y;
    int res = 0;
    long long a = x;
    while (true) {
        if (a <= y) {
            res++;
            a *= 2;
        } else {
            break;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int i,g,z,gz,h,gh,t;

scanf("%d %d %d %d %d %d",&i,&g,&z,&gz,&h,&gh);

t=i+g*5+z*10+gz*50+h*100+gh*500;

if(t>=1000){
printf("1\n");
}
else{
printf("0\n");
}

return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    ll A,B;cin>>A>>B;
    cout<<max(A+B,max(A-B,A*B))<<endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<string.h>
using namespace std;

int main()
{
	int k, i, j, dis, N, M,flag,un,unc, d, ans,p, X, Y;
	cin >> N;
	flag = 0;
	un = 0;
	unc = 0;
	char S[301][301];
	char s[301][301];
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			cin >> S[i][j];
		}
	}
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (S[i][j] != S[0][0]) {
				flag = 1;
			}
		}
	}
	if (flag == 0) {
		cout << N * N << endl;
	}
	else {
		for (k = 0; k < N; k++) {
			for (i = 0; i < N; i++) {
				for (j = 0; j < N; j++) {
					if (S[(i + k) % N][j] != S[(j+k)%N][i]) {
						un = 1;
						break;
					}
				}
				if (un == 1)
					break;
			}
			if (un==0) {
				unc++;
			}
			else
				un = 0;
		}
		if (unc==0) {
			cout << "0" << endl;
		}
		else {
			cout << N*unc << endl;
		}
	}
	return 0;
}





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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;
int MOD = 1e9 + 7;

ll solve(int N, int M) {
  ll ret;
  if(N == M) {
    ret = 2;
  }else if(N - M == 1 || N - M == -1) {
    ret = 1;
  }else{
    return 0;
  }

  REP(i,N) ret = ret * (i + 1) % MOD;
  REP(i,M) ret = ret * (i + 1) % MOD;
  return ret;
}

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

  ll ret = solve(N, M);
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "a2.cpp"

int main() {
  ll n;
  cin >> n;
  vl a(n);
  cin >> a;

  ll ans = 0;
  rep(i, n) {
    if (i == n-1) { ans++; break; }
    bool up = a[i] <= a[i+1];
    bool down = a[i] >= a[i+1];
    while (i+1 < n and (up &= a[i] <= a[i+1], down &= a[i] >= a[i+1], up or down)) {
      i++;
    }
    ans++;
  }
  cout << ans << el;
}


Measured memory_bytes: 1024
#include <iostream>

int number_r(int r);

int main()
{
  int x, y;

  std::cin >> x >> y;

  int a = number_r(x);
  int b = number_r(y);

  if (a == b) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}

int number_r(int r)
{
  switch (r)
  {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    return 0;

    case 4:
    case 6:
    case 9:
    case 11:
    return 1;

    case 2:
    return 2;
  }

  return 3;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

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

MONS.sort()

if K == 0:
    print(sum(MONS))
else:
    if len(MONS) <= K:
        print(0)
    else:
        for _ in range(K):
            MONS.pop(-1)
        print(sum(MONS))

Measured memory_bytes: 26764
#include<stdio.h>

int main(){

	int i, j, k, m, n, b, f, r, v, tenant[4][3][10];

	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				tenant[i][j][k] = 0;
			}
		}
	}

	scanf("%d\n", &n);
	for(m=0;m<n;m++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		tenant[b-1][f-1][r-1] += v;
	}

	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				printf(" %d", tenant[i][j][k]);
			}
			printf("\n");
		}
		if ( i < 3 ) printf("####################\n");
	}

    return 0;
}

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

int main(){
    int H, W;

    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if((i+j) % 2 == 0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
    int a,b,i,j;
    char s[200],t[200],ad[200];
    cin>>a;
    getchar();
    cin>>s>>t;
    for(i=0,j=0;i<a;i++)
    {
        ad[j]=s[i];
        j++;
        ad[j]=t[i];
        j++;
    }
    ad[j]='\0';
    cout<<ad<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    set<ll> st;
    ll free = 0;

    rep(i, n){
        ll a; cin >> a;
        if(1 <= a && a < 400) st.insert(0);
        if(400 <= a && a < 800) st.insert(1);
        if(800 <= a && a < 1200) st.insert(2);
        if(1200 <= a && a < 1600) st.insert(3);
        if(1600 <= a && a < 2000) st.insert(4);
        if(2000 <= a && a < 2400) st.insert(5);
        if(2400 <= a && a < 2800) st.insert(6);
        if(2800 <= a && a < 3200) st.insert(7);
        if(3200 <= a) free++;
    }

    // 最小値
    if(st.size()==0 && free >= 1) cout << 1 << " ";
    else cout << st.size() << " ";

    // 最大値
    cout << (ll)st.size()+free << endl;
}

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

char a[10010];
int n;
int len;

int main(void)
{
	scanf("%d", &n);
	scanf("%s", a);
	
	len = strlen(a);
	
	for(int i = 0 ; i < len ; i++)
	{
		a[i] += n;
		
		if(a[i] > 'Z')
			a[i] -= 26;
			
		printf("%c", a[i]);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int a[20],b[20];
int res;
int n;

void f(){
//for(i=0;i<n-1;i++)cout<<a[i]<<" ";
//cout<<a[n-1]<<endl;
	int i,j;
	bool ok=true;
	for(i=0;i<n;i++){
		b[i]=0;
		for(j=0;j<n;j++){
			if(a[i]==a[j])b[i]++;
		}
		if(a[i]!=b[i])ok=false;
	}
	if(ok){
		cout<<res<<endl;
		for(i=0;i<n-1;i++)cout<<a[i]<<" ";
		cout<<a[n-1]<<endl;
	}else{
		res++;
		for(i=0;i<n;i++)a[i]=b[i];
		f();
	}
}

int main() {
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		res=0;
		f();
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
 
using vd=vector<double>;
using vvd=vector<vd>;
 
 
int main(){
    int h,w;
    cin>>h>>w;
    vvi f(h+2,vi(w+2,1));
    vvi walk(h+2,vi(w+2,0));
    int gy,gx,y=0,x=0,v=0;
    range(i,1,h+1)range(j,1,w+1){
        char c;
        cin>>c;
        switch(c){
            case 'G': gy=i,gx=j,f[i][j]=0; break;
            case '.': f[i][j]=0;break;
            case '#': break;
            case '^': y=i,x=j,v=0,f[i][j]=0; break;
            case '>': y=i,x=j,v=1,f[i][j]=0; break;
            case 'v': y=i,x=j,v=2,f[i][j]=0; break;
            case '<': y=i,x=j,v=3,f[i][j]=0; break;
        }
    }
    walk[y][x]=1;
    rep(loop,5000){
        vvi vec={{-1,0},{0,1},{1,0},{0,-1}};
        if(f[y+vec[(v+1)%4][0]][x+vec[(v+1)%4][1]]==0){ //右手が道なら右に曲がって前に進む
            //cout<<"hoge";
            v=(v+1)%4;
            y+=vec[v][0], x+=vec[v][1];
            walk[y][x]=1;
        }else if(f[y+vec[v][0]][x+vec[v][1]]==1){ //（右が壁で、）正面が壁なら左に回る
            //cout<<"fuga";
            v=(v+3)%4;
        }else{ //そうでないならまえに進む
            //cout<<"zako";
            y+=vec[v][0],x+=vec[v][1];
            walk[y][x]=1;
        }
        if(y==gy&&x==gx){
            break;
        }
        // cout<<y<<","<<x<<","<<v<<endl;
        // rep(i,h+2){
        //     rep(j,w+2){
        //         if(i==y&&j==x){
        //             cout<<"^>v<"[v];
        //         }else{
        //             cout<<".#"[f[i][j]];
        //         }
        //     }
        //     cout<<endl;
        // }
    }
    if(y==gy&&x==gx){
        int ans=0;
        rep(i,h+2)rep(j,w+2)ans+=walk[i][j];
        cout<<ans<<endl;
    }else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3192
import sys
for i in sys.stdin:
    n = float(i)
    if n <= 48:
        print("light fly")
    elif n <= 51:
        print("fly")
    elif n <= 54:
        print("bantam")
    elif n <= 57:
        print("feather")
    elif n <= 60:
        print("light")
    elif n <= 64:
        print("light welter")
    elif n <= 69:
        print("welter")
    elif n <= 75:
        print("light middle")
    elif n <= 81:
        print("middle")
    elif n <= 91:
        print("light heavy")
    else:
        print("heavy")

Measured memory_bytes: 7464
#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();

//==================================

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

    ll N;
    cin >> N;
    cout << 180 * (N - 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i=0; i<(int)(n); ++i)
 
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;}

const ll LINF = 1LL<<60;

int main() {
  int a, b, c; cin >> a >> b >> c;
  if(a+b+c > 21) cout<<"bust"<<endl;
  else cout << "win" << endl;
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){
    input!{
        r: i64,
    }

    let mut ans = 0;
    ans = 3 * (r * r);
    println!("{}", ans);

}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;


int main(){
   string a,b,c;
   cin>>a>>b>>c;
   int x=0,y=0,z=0;
   int xx=a.size(),yy=b.size(),zz=c.size();
   bool flag=false;
   char turn='a';
   do{
      char kard;
      if(turn=='a'){
         if(x==xx){
            cout<<"A";
            flag=true;
         }
         kard=a[x];
         x++;
      }
      else if(turn=='b'){
         if(y==yy){
            cout<<"B";
            flag=true;
         }
         kard=b[y];
         y++;
      }
      else if(turn=='c'){
         if(z==zz){
            cout<<"C";
            flag=true;
         }
         kard=c[z];
         z++;
      }
      turn=kard;
   }while(flag==false);

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;

int main(){
  int N; cin >> N;
  int sum = 0;
  int tmp = N;
  while(tmp > 0){
    sum += tmp % 10;
    tmp /= 10;
  }
  string ans = "No";
  if(N % sum == 0) ans = "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		
		System.out.println((int)(Math.ceil((a + b) / 2)));
	}
}

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

ABs = []
for _ in range(N):
    ABs.append([int(j) for j in input().split()])

ABs = sorted(sorted(ABs, key=lambda x: x[0], reverse=True), key=lambda x: x[1])
t = 0
for i, AB in enumerate(ABs):
    t += AB[0]
    if t > AB[1]:
        print('No')
        break

    if i == N-1:
        print('Yes')


Measured memory_bytes: 44088
N = int(input())
C = input()
rcount = len([1 for c in C if c == "R"])

count = 0
r = 0
w = 0
for i in range(rcount):
    c = C[i]
    if c == "W":
        if r > 0:
            r -= 1
            count += 1
        else:
            w += 1
    c = C[N-i-1]
    if c == "R":
        if w > 0:
            w -= 1
            count += 1
        else:
            r += 1
ans = count + w
print(ans)

Measured memory_bytes: 10768
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n    = s.size();
    string t = s;
    reverse(t.begin(), t.end());
    vector<vvi> dp(n + 5, vvi(n + 5, vi(k + 5, 0)));
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int l = 0; l <= k; ++l) {
                chmax(dp[i + 1][j][l], dp[i][j][l]);
                chmax(dp[i][j + 1][l], dp[i][j][l]);
                if (s[i] == t[j]) {
                    chmax(dp[i + 1][j + 1][l], dp[i][j][l] + 1);
                } else {
                    chmax(dp[i + 1][j + 1][l + 1], dp[i][j][l] + 1);
                }
            }
        }
    }
    int ret = 0;
    for (int i = 0; i <= n; ++i) {
        chmax(ret, dp[i][n - i][k] * 2);
    }
    for (int i = 0; i < n; ++i) {
        chmax(ret, dp[i][n - 1 - i][k] * 2 + 1);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 114688
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
using namespace std;

bool bit(int mask, int position){
    if((1 & (mask >> position)) != 0) return true;
    return false;
}

int main(){
    string s; cin >> s;
    
    int size = s.length() - 1;
    vector<char> sign(3);

    for(int i = 0; i < (1<<size); i++){
        sign.clear();
        int tmp = (s[0]- '0');
        for(int j = 0; j < size; j++){
            if(bit(i, j)){
                tmp += (s[j+1]- '0');
                sign.push_back('+');
            } else{
                tmp -= (s[j+1]-'0');
                sign.push_back('-');
            }
        }
        if(tmp == 7) break;
    }
    
    
    cout << s[0] << sign[0] << s[1] << sign[1] << s[2] << sign[2] << s[3] << "=7" <<endl;


    return 0;
}

Measured memory_bytes: 256
S = gets.chomp
T = gets.chomp
h,g = {},{}
(0...S.size).each{ |i|
  s,t, = S[i],T[i]
  if h[s] && h[s] != t
    puts "No"; exit
  end
  if g[t] && g[t] != s
    puts "No"; exit
  end
  h[s] = t; g[t] = s
}
puts "Yes"

Measured memory_bytes: 2752
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a==0)
	{
		printf("1\n");
		return 0;
	}
	if(b==0)
	{
		printf("2\n");
		return 0;
	}
	if(c==0)
	{
		printf("3\n");
		return 0;
	}
	if(d==0)
	{
		printf("4\n");
		return 0;
	}
	if(e==0)
	{
		printf("5\n");
		return 0;
	}
} 

Measured memory_bytes: 1640
#include<stdio.h>
int main()
{
    int n;
    long long int r;
    r=1;
    scanf("%d", &n);
    long long int a[100005];
    for(int i=0;i<n;i++){
        scanf("%lld", &a[i]);
        if(a[i]==0){
            printf("0");
            return 0;
        }
    }
    for(int j=0;j<n;j++){
        long long int tmp;
        tmp=r*a[j];
        //10^18より大きくなる場合
//        if(r>tmp||tmp>1000000000000000000){//こっちでも通る
        if(a[j]>1000000000000000000/r){
            printf("-1");
            return 0;
        }
        r=tmp;
    }
    printf("%lld",r);
    return 0;
}

Measured memory_bytes: 2484
a,b,c,x,y=map(int,input().split())

res1=a*x+b*y
if x>y:
    res2=2*y*c+(x-y)*a
else:
    res2=2*x*c+(y-x)*b
res3=2*max(x,y)*c
print(min(res1,res2,res3))

Measured memory_bytes: 38384
def resolve():
    # cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_B&lang=ja
    # http://agent.inf.kyushu-u.ac.jp/~yokoo/lecture/DA2_03.pdf
    def matrix_chain_multiplication(n):
        """
        連鎖行列積問題：
        n 個の行列について、行列 M_i の次元が与えられたとき、
        積 M_1 M_2...M_n の計算に必要なスカラー乗算の最小の回数を返す
        """
        m = [[0 for x in range(n + 1)] for y in range(n + 1)]
        for l in range(2, n + 1):
            for i in range(1, n - l + 2):
                j = i + l - 1
                m[i][j] = 99000001
                for k in range(i, j):
                    m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j])
        return m[1][n]

    # M1からMnの行数と、Mnの列数を格納。
    # 積が定義されている以上型が合っているはずなのでその他は不要
    p = []

    # 行列の数n
    n = int(input())

    # 行列Mi(i=1...n)の次元r、c
    # rは行数、cは列数
    for i in range(n):
        listed_input = input().split()
        p.append(int(listed_input[0]))

    p.append(int(listed_input[1]))

    print(matrix_chain_multiplication(n))


resolve()


Measured memory_bytes: 5732
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
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; }

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    vector<int> indeg(N, 0);
    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        G[x - 1].push_back(y - 1);
        indeg[y - 1]++;
    }
    vector<int> dp(N, 0);
    queue<int> que;
    for (int v = 0; v < N; v++) if (indeg[v] == 0) que.push(v);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            indeg[nv]--;
            if (indeg[nv] == 0) {
                que.push(nv);
                chmax(dp[nv], dp[v] + 1);
            }
        }
    }
    int res = 0;
    for (int v = 0; v < N; v++) chmax(res, dp[v]);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6528