akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int f[110][10];
int p[110][10];
int main()
{
    int n;
    cin >> n;
    rep(i,n){
        rep(j,10){
            cin >> f[i][j];
        }
    }
    rep(i, n)
    {
        rep(j, 11)
        {
            cin >> p[i][j];
        }
    }
    int ans = -1e9;
    for(int i = 1;i<1024;i++){
        int tmp = 0;
        rep(k,n)
        {
            int cnt = 0;
            rep(j,10){
                if((1<<j)&i){
                    if(f[k][j])
                        cnt++;
                }
            }
            tmp+=p[k][cnt];
        }
//        cout << tmp << endl;
        ans = max(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# Problem https://atcoder.jp/contests/abc095/tasks/abc095_b
# Ruby 2nd Try
n,x = gets.chomp.split(' ').map(&:to_i)
mi = Array.new(n,0)
for j in 0...n do
    mi[j] = gets.chomp.to_i
end
answer = 0
allsum = 0
for j in 0...n do
    allsum = allsum+mi[j]
end
allmin = 1001
for j in 0...n do
    if mi[j] <= allmin
        allmin = mi[j]
    end
end
answer = n + (x-allsum)/allmin
puts(answer)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

ll binpow(ll a, ll b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    for (int i=0;i<min(sz(s),n);++i)
        cout<<s[i];
    if (sz(s)>n)
        cout<<"...";
    return 0;
}

Measured memory_bytes: 3656
n = int(input())
a = list(int(i) for i in input().split())
ans1 = max(a)
tmp1 = ans1/2
ans2 = 10**11
if len(set(a)) > 2:
 for i in a:
  ans2 = min(ans2,abs(tmp1-i))
 if  int(tmp1+ans2) in a:
  ans3 = tmp1+ans2
 else:
  ans3 = tmp1-ans2
 print(ans1,int(ans3))
else:
  a.remove(ans1)
  print(ans1,min(a))

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

int main(){
  char	c;
  std::cin >> c;
  if (('A' <= c) && (c <= 'Z')){
    std::cout << 'A';
  }
  else if (('a' <= c) && (c <= 'z')){
    std::cout << 'a';
  }
}

Measured memory_bytes: 3636
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(4100000)

#MOD
P = 10**9 + 7
N = 200001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2, N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b or b < 0: return 0 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P

#全方位木dp
#-------------------------------------------------------------------
#扱うクラス
class T:
    num = 1
    child = 0

    def __init__(self, a, b):
        self.num = a
        self.child = b

#零元
zero = T(1, 0)
#一個上に遷移した時の変化
def step(x):
    return T(x.num, x.child+1)
#マージ
def merge(x, y):
    return T((x.num*y.num*comb(x.child+y.child, x.child))%P, x.child+y.child)

G = [[] for _ in range(N)]
down_data = [zero for _ in range(N)]
dat = [zero for _ in range(N)]
rev_data = [zero for _ in range(N)]

class p:
    num = -1
    parent = -1

    def __init__(self, x, y):
        self.num = x
        self.parent = y
node_list = []
def makeNodeList(root):
    #dfsでの探索順の作成
    stack = []
    stack.append(p(root, -1))
    while len(stack) != 0:
        now = stack.pop()
        node_list.append(now)
        for to in G[now.num]:
            if to == now.parent: continue
            stack.append(p(to, now.num))
    node_list.reverse()

def dfs(root):
    for now in node_list:
        for to in G[now.num]:
            if to == now.parent: continue
            down_data[now.num] = merge(down_data[now.num], step(down_data[to]))

def dfs_rev(root):
    for now in node_list:
        #累積
        rev = rev_data[now.num]
        left = []
        right = []
        cnt = 0
        for to in G[now.num]:
            if to==now.parent: continue
            if len(left)==0: left.append(step(down_data[to]))
            else: left.append(merge(left[cnt-1], step(down_data[to])))
            cnt += 1
        cnt = 0
        for to in reversed(G[now.num]):
            if to==now.parent: continue
            if len(right)==0: right.append(step(down_data[to]))
            else: right.append(merge(right[cnt-1], step(down_data[to])))
            cnt += 1
        dat[now.num] = merge(rev, down_data[now.num])
        cnt = 0
        for to in G[now.num]:
            if to==now.parent: continue
            x = zero if cnt==0 else left[cnt-1]
            y = zero if cnt==len(right)-1 else right[len(right)-2-cnt]
            rev_data[to] = step(merge(rev, merge(x, y)))
            cnt += 1

def calc(data_num):
    root = -1
    for i in range(1, data_num+1):
        if len(G[i]) == 1:
            root = i
            break
    makeNodeList(root)
    dfs(root)
    node_list.reverse()
    dfs_rev(root)
#-------------------------------------------------------------------
def main():
    n = int(input())
    for i in range(n-1):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)
    calc(n)
    #for i in range(1, n+1): print(down_data[i].num, down_data[i].child)

    for i in range(1, n+1): print(dat[i].num)

if __name__ == "__main__": main()


Measured memory_bytes: 179436
# -*- coding: utf-8 -*-
a, b, k = map(int, input().split())
if a > b:
    t = a
    a = b
    b = t
# 0<a<b<100
fact = []
for i in range(1,a+1,):
    if a%i==0 and b%i==0:
        fact.append(i)
print(fact[-k])


Measured memory_bytes: 2940
n, x = [ int(v) for v in input().split() ]
candy_list =  [ int(v) for v in input().split() ]


def eating(c):
	global x
	a, b = candy_list[i], candy_list[i+1]
	y = a + b - x
	if y >= 0:
		b -= y
		a += min(0,b)
		b = max(0,b)
		candy_list[i], candy_list[i+1] = a, b
	else:
		y = 0
	return y

ans = 0
for i in range(n-1):
	ans += eating(i)

print(ans)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;


void solve(double dp[100000][2], int n, int m){
    dp[0][0] = 1;
    rep(i,n){
        rep(j, n * m){
            range(k, 1, m + 1){
                dp[j + k][(i + 1) % 2] += dp[j][i % 2];
            }
            dp[j][i % 2] = 0;
        }
    }
}

int main(){
    int n, m;
    double k;
    while(cin >> n >> m >> k, n||m||k){
        double dp[100000][2] = {0};
        solve(dp, n, m);
        //rep(i,n * m + 1){ cout << dp[i][n] << endl; }


        double t = 1;
        rep(i,n){
            t *= m;
        }

        double sum = 0;
        for(int i = n; i <= n * m; i++){
            sum += max(static_cast<double>(i - k), 1.0) * dp[i][n % 2];

        }
        cout << fixed << setprecision(8) << sum / t + 1e-12 << endl;
    }
}

Measured memory_bytes: 4716
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void doIt() {
		sB();
	}

	void sB() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		for(int i = 100; i >= 1; i--) {
			if(a % i == 0 && b % i == 0) {
				k--;
				if(k == 0) {
					System.out.println(i);
					return;
				
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 21716
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        System.out.println(solve(a, b, c) ? "YES" : "NO");

        sc.close();
    }

    static boolean solve(int a, int b, int c) {
        return a + c == 2 * b;
    }
}

Measured memory_bytes: 21716
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (a, b, k) = [int(e) for e in lines[0].split(" ")]

    return (a, b, k)


def solve(a, b, k):

    a2 = a
    b2 = b
    if a >= k:
        a2 = a - k
        b2 = b
    else:
        a2 = 0
        b2 = max([b - (k - a), 0])

    return [a2, b2]


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        print("%d %d" % (result[0], result[1]))
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	


Measured memory_bytes: 3064
#pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
const int maxn = 10050;
const int maxe = 2005000;
const int INF = 1e9;
struct note
{
	int to;
	int w;
	int c;
	int next;//next表示下一条相同起点不同&#32456;点&#36793;的&#32534;号
};
note edge[maxe];
int head[maxn];//head[i]=k 表示以i&#20026;起点的&#36793;的&#32534;号，-1表示没有
int ip;
void init()
{
	memset(head, -1, sizeof(head));
	ip = 0;
}
void addedge(int u, int v, int w, int c)
{
	edge[ip].to = v;
	edge[ip].c = c;
	edge[ip].w = w;
	edge[ip].next = head[u];
	head[u] = ip++;
}
int cost[maxn];
int dis[maxn];
bool vis[maxn];
queue<int>q;
void spfa(int s, int n)
{
	while (!q.empty())q.pop();
	for (int i = 1; i <= n; i++)
		cost[i] = dis[i] = INF;
	memset(vis, false, sizeof(vis));
	dis[s] = 0;
	cost[s] = 0;
	vis[s] = true;
	q.push(s);
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		vis[u] = false;
		for (int i = head[u]; i != -1; i = edge[i].next)//遍&#21382;起点&#20026;u的所有&#36793;
		{
			int to = edge[i].to;
			int val = edge[i].w;
			if (dis[to]>dis[u] + val || (dis[to] == dis[u] + val&&cost[to]>edge[i].c))//有多条最短路&#26102;，取花&#36153;最小的  
			{
				dis[to] = dis[u] + val;
				cost[to] = edge[i].c;
				if (!vis[to])
				{
					q.push(to);
					vis[to] = true;
				}
			}
		}
	}
}
int main()
{
	int n, m;
	int u, v, w, c;
	while (~scanf("%d%d", &n, &m))
	{
		if (n == 0 && m == 0) break;
		init();
		for (int i = 0; i<m; i++)
		{
			scanf("%d%d%d%d", &u, &v, &c, &w);
			addedge(u, v, c, w);
			addedge(v, u, c, w);
		}
		spfa(1, n);
		int ans = 0;
		for (int i = 1; i <= n; i++)
			ans += cost[i];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1988
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut uv: [[usize; 2]; n-1]
    }
    uv.iter_mut().for_each(|e| e.sort());

    let mut total: usize = (1..(n + 1)).map(|r| r * (r + 1) / 2).sum();
    for v in uv.iter() {
        total -= v[0] * (n - v[1] + 1)
    }
    println!("{}", total);
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    //cin>>testcase;
    for(int p=0;p<testcase;p++){
    ll n=0;
    cin>>n;
    ll x=0;
    ll i=0;
    bool k=true;
    while(x<=n){
        x=pow(2,i);
        i++;
        if(x>n)
        {cout<<x/2;
            k=false;
        break;
        }


    }
    if(k)
    cout<<x;

    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;

int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int tzcnt(uint x) {
    return popcount(~x & x - 1);
}

struct Point {
    int x, y;

    Point(int p, int q) : x(p), y(q) {}
};

ll ans[100];

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    out(min(a, b) + min(c, d));

    int aaa;
    cin >> aaa;
}

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


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
int main(){
    ll n,m,x;
    cin >> n >> m >> x;
    vector<vector<ll>>a(n,vector<ll>(m));
    vector<ll>c(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    ll ans=inf;
    rep(i,1<<n){
        ll nedan=0;
        vector<int>bin(n,0);
        vector<ll>cost(m,0);
        rep(j,n){
            if(i>>j&1)bin[j]=1;
        }
        rep(j,n){
            if(bin[j]){
                nedan+=c[j];
                rep(k,m) cost[k]+=a[j][k];
            }
        }
        bool flag=true;
        rep(j,m){
            if(cost[j]<x) flag=false;
        }
        if(flag){
            ans=min(ans,nedan);
        }
        
    }
    if(ans==inf) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3632
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		
		// 計算
		int[] list = new int[n + 1];
		int cnt = 0;
		for(int i = 0; i < n - 1; i++){
		    if(s.substring(i, i + 2).equals("AC")){
		        cnt++;
		    }
		    list[i + 2] = cnt;
		}
		for(int i = 0; i < q; i++){
		    int l = sc.nextInt();
		    int r = sc.nextInt();
		    int result = list[r] - list[l];
		    System.out.println(result);
		}

		// 出力
		//System.out.println(result);
        
	}
}


Measured memory_bytes: 77568
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#define REP(i,a,b) for (int i = (a); i < (b); i++)
#define rep(i,a) REP(i,0,a)
using namespace std;

const int INF = 1 << 28;

int sp, N;
int t[16][17], dp[1 << 16];

int main(void){
    while (cin >> N && N) {
        rep(i, N) rep(j, N + 1) cin >> t[i][j];

        rep(i, 1 << N) dp[i] = INF;
        dp[0] = 0;
        rep(bit, 1 << N) {
            rep(i, N) {
                if (bit & 1 << i) continue;
                int cost = t[i][0];
                rep(j, N) if (!(bit & 1 << j) && i != j) cost = min(cost, t[i][j+1]);
                int now = bit | 1 << i;
                dp[now] = min(dp[now], dp[bit] + cost);
            }
        }
        cout << dp[(1 << N) - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1416
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int n, x, t;
    cin >> n >> x >> t;
    int res = n / x;
    if (n % x) res++;
    cout << res * t;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <set>

using namespace std;

int main()
{
    long long N;

    cin >> N;

    cout <<  N*(N-1)/2<< endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define FOR1(n) for(int i=0;i<n;i++)
#define FOR2(j, n) for(int j=0;j<n;j++)
#define FOR3(i, m, n) for(int i=m;i<=n;i++)
#define ALL(c) c.begin(), c.end()
#define SCANF(x) scanf("%lld", &x)
#define MOD 1000000007
#define MAX 1000000001
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

/*
逆順ソート sort(ALL(vec), greater<ll>());
ペア定義 P pair = make_pair(100, 200);
集合find set.find(item);
小さい順に取り出したい優先度付きキュー
priority_queue<int, vector<int>, greater<int> > que;
配列の最大要素 *std::max_element(ALL(vec))
*/

signed main(){
	int w, h;
	cin >> w >> h;
	priority_queue<P, vector<P>, greater<P>> v;
	int p;
	FOR1(w+h){
		cin >> p;
		v.push(make_pair(p, i));
	}
	
	int a = h + 1, b = w + 1;
	ll cost = 0;
	
	while(!v.empty()){
		P pair = v.top(); v.pop();
		if(pair.second < w){
			cost += pair.first * a;
			b -= 1;
		}else{
			cost += pair.first * b;
			a -= 1;
		}
	}
	
	cout << cost;
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main() {
    string s;
    cin>>s;
    
    int n=s.size();
    int a,z;
    rep(i,n){
        if(s.at(i)=='A'){
            a=i;
            break;
        }
    }
    rep(i,n){
        if(s.at(i)=='Z') z=i;
    }
    
    cout<<z-a+1<<endl;
}


Measured memory_bytes: 640
S_list = list(input()) 
S_list = ['1' if i == 'A' or i == 'C' or  i == 'G' or i == 'T' else '0' for i in S_list]
S = ''.join(S_list)
S = S.split('0')
X = 0
for i in range(len(S)):
    if len(S[i]) > X:
        X = len(S[i])
print(X)

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

using namespace std;
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 998244353
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
// #define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/

void solve(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

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

int main(){
    ll H,W;
    cin >> H >> W;
    if(H == 1 || W == 1) cout << 1 << endl;
    else if(H*W%2 ==0) cout << H*W/2 << endl;
    else cout << H*W/2 + 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int n, c;
string s, t;
deque<char> dq;
int main() {
	int i;
	cin>>n>>s;
	for(i=0; s[i]; i++) {
		dq.push_back(s[i]);
		if(s[i]=='(') c++;
		else {
			if(c>0) c--;
			else dq.push_front('('), c=0;
		}
	}
	if(c>0) while(c--) dq.push_back(')');
	while(!dq.empty()) {
		t += dq.front();
		dq.pop_front();
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int a,b;
     cin>>a>>b;
     int c=a+b;
     if(c%2==0)
     {
         cout<<c/2<<endl;

     }
     else
     {
          cout<<"IMPOSSIBLE"<<endl;
     }
     return 0;

 }


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPC(i, a) REP(i, 0, a)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define RREPC(i, a) RREP(i, a, 0)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159297358979323846264338327950288;

static map<type_index, const char *const> scanType = {{typeid(int), "%d"},
                                                      {typeid(ll), "%lld"},
                                                      {typeid(double), "%lf"},
                                                      {typeid(char), "%c"}};

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
	// INFILE();
	vector<string> sv(3);
	cin >> sv[0] >> sv[1] >> sv[2];

	char curPlayer = 'a';
	while (true) {
		int index = curPlayer - 97;
		if (sv[index].empty()) {
			break;
		}

		curPlayer = sv[index][0];
		sv[index].erase(begin(sv[index]));
	}

	cout << static_cast<char>(curPlayer - 32) << endl;
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  auto tFormat = scanType[typeid(T)];
  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif

        ll n;
        cin >> n;

        ll dp[n + 1][4][4][4]; // dp[i][j]: i文字使って，最後の文字がjであるような場合の数
        const ll A = 0, C = 1, G = 2, T = 3;
        rep(i, n + 1) rep(j, 4) rep(k, 4) rep(l, 4) dp[i][j][k][l] = 0;
        //mlkj
        for (int i = 2; i < n; ++i) {
            rep(j, 4) { // 現在の数字
                rep(k, 4) { // 1個前の数字
                    rep(l, 4) { // 2個前の数字
                        rep(m, 4) { // 3個前の数字
                            if (l == A && k == G && j == C) continue;
                            if (l == A && k == C && j == G) continue;
                            if (l == G && k == A && j == C) continue;
                            if (m == A && k == G && j == C) continue;
                            if (m == A && l == G && j == C) continue;
                            if (i <= 2) {
                                dp[i + 1][j][k][l] = 1;
                            } else {
                                dp[i + 1][j][k][l] += dp[i][k][l][m];
                            }
                            dp[i + 1][j][k][l] %= mod;
                        }
                    }
                }
            }
        }
        ll ans = 0;
        rep(i, 4) rep(j, 4) rep(k, 4) {
                    ans += dp[n][i][j][k];
                    ans %= mod;
                }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >> getList >>= print . sum . map pred

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define ll      	long long int
#define PI      	acos(-1)
#define read    	freopen("in.txt","r",stdin)
#define uu      	first
#define vv      	second
#define write   	freopen("out.txt","w",stdout)
#define pii     	pair<int,int>
#define pll         pair<ll,ll>
#define INF     	1e18
#define EPS     	1e-8
#define MAX     	1000006
#define MOD     	1000000007
#define fastRead 	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
int n;
ll ara[500] , sum[500] , dp[500][500];

ll solve(int frm , int to) {

    if( frm > to) return INF;

    if( frm == to ) return 0;
    ll &ret = dp[frm][to];
    if( ret != -1) return ret;

    ret = INF;

    for(int i = frm ; i <= to ; i++ ) {

        ret = min( ret , solve(frm , i ) + solve(i+1 , to)  + sum[to] - sum[frm-1] );
    }
    return ret;
}

int main()
{
    fastRead;
    cin>>n;
    for(int i = 1 ; i<= n ; i++ ) cin>>ara[i];
    for(int i =1 ; i<= n ; i++ ) sum[i] = ara[i] + sum[i-1];
    memset(dp , -1 , sizeof dp);
    cout<<solve(1 , n)<<endl;
    return 0;
}


Measured memory_bytes: 2304
a = []
while True:
    b = raw_input().split()
    if b[1] == '?':
        break
    c = [int(b[0]), b[1], int(b[2])]
    a.append(c)
for list in a:
    x, op, y = list
    if op == '+':
        print x + y
    elif op == '-':
        print x - y
    elif op == '*':
        print x * y
    else:
        print x / y

Measured memory_bytes: 6412
#include <stdio.h>
#include <string.h>
int pop();
void push(int );
int x[1000],top;
int main(){
  top=0;
  char c[100];
  int a,b;
  while(scanf("%s",c)!=EOF){
    if(c[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(c[0]=='-'){
      b=pop();
      a=pop();   
      push(a-b);
    }
    else if(c[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else{
      push(atoi(c));
    }
  }
  printf("%d\n",pop());
  return 0;
}
void push(int a){
  x[++top]=a;
}
int pop(){
  return x[top--];
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

#define WHITE 1
#define GRAY 2
#define BLACK 3

int now, n, u, k, v, tree[102][102], timeTable[102][2], color[102], timeNow = 1;
stack<int> st;

void dfs(){
    while(1){
        if(st.empty()){
          	int l = 1;
          	while(1){
              	if(l == n + 1){
                	FOR(l, 1, n + 1){
                		cout << l << " " << timeTable[l][0] << " " << timeTable[l][1] << endl;
            		}
                  	break;
                }
            	if(color[l] == WHITE){
                	st.push(l);
                  	timeNow++;
                  	break;
                }
              	l++;
            }
          	if(l == n + 1){
            	break;
            }
        }else{
            now = st.top();
          	if(color[now] == WHITE){
            	timeTable[now][0] = timeNow;
            }
            color[now] = GRAY;
            int cnt = 1;
            while(1){
                if(cnt == n + 1){
                    st.pop();
                    color[now] = BLACK;
                    timeTable[now][1] = timeNow + 1;
                    break;
                }else if(tree[now][cnt] && color[cnt] == WHITE){
                    st.push(cnt);
                    break;
                }
                cnt++;
            }
            timeNow++;
        }
    }
}

int main(){
    cin >> n;
  	REP(i, 102){
    	REP(j, 102){
        	tree[i][j] = 0;
        }
    }
    REP(i, n){
        cin >> u >> k;
        color[i + 1] = WHITE;
        REP(j, k){
            cin >> v;
            tree[u][v] = 1;
        }
    }
    st.push(1);
    dfs();
  	return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vi K(n);
    vi c(m, 0);
    rep(i, n){
        int k;
        cin >> k;
        rep(j, k){
            int a ;
            cin >> a;
            c[a-1]++;
        }
    }
    int ans = 0;
    rep(i, m){
        if(c[i] == n)ans++;
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

int main() {
 double h,w,mb,g;
 int n,mn,i,m;
 while(cin >> m) {
	 if (m==0) break;
     mb=mn=99999999;
	 for (i=0;i<m;i++) {
		 cin >> n >> h >> w;
		 h/=100; g=22-w/(h*h); if (g<0) g=-g;
		 if (mb>=g) { if (mb==g) { if (mn>n) mn=n; } else { mn=n; mb=g;} }
		}
	 cout << mn << endl;
 }
 return 0;
 }

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
    FIO
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0&&i%5==0)continue;
        else if(i%3==0)continue;
        else if(i%5==0)continue;
        else sum+=i;
    }
    
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3636
N=int(input())
words=[input() for i in range(N)]

judge='Yes'
for index, word in enumerate(words):
    if index == 0:
        continue
    if word[0] != words[index-1][-1]:
        judge = 'No'
        break
    if words.count(word) > 1:
        judge = 'No'
        break

print(judge)

Measured memory_bytes: 3060
// ABC042_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
            vector<ll> vec(3);
    REP(i, 3) cin >> vec[i];
    sort(vec.begin(), vec.end());
    // calculation
    if (vec[0] == 5 && vec[1] == 5 && vec[2] == 7) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':

	n = int(input())

	ocnt = 0
	hcnt = 0
	score = 0

	while n > 0:
		line = input()
		if line == "HOMERUN":
			score += hcnt
			score += 1
			hcnt = 0
		elif line == "HIT":
			hcnt += 1
			if hcnt == 4:
				score += 1
				hcnt = 3
		else:
			ocnt += 1
			if ocnt == 3:
				print(score)
				ocnt = 0
				hcnt = 0
				score = 0
				n -= 1



Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
void solve()
{
	ll n;
	cin>>n;
	ll t = 0;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		t ^= a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		ll e = t^a[i];
		cout<<e<<" ";
	}
}
 
int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 5136
/**
 *    author:  tourist
 *    created: 25.12.2019 00:21:24       
**/
#include <bits/stdc++.h>

using namespace std;

const int md = (int) 1e9 + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> fact(h + w - 1);
  fact[0] = 1;
  for (int i = 1; i < (int) fact.size(); i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  vector<int> inv_fact(fact.size());
  inv_fact.back() = inv(fact.back());
  for (int i = (int) inv_fact.size() - 2; i >= 0; i--) {
    inv_fact[i] = mul(inv_fact[i + 1], i + 1);
  }
  vector<pair<int, int>> cells(n);
  for (int i = 0; i < n; i++) {
    cin >> cells[i].first >> cells[i].second;
  }
  cells.emplace_back(1, 1);
  cells.emplace_back(h, w);
  sort(cells.begin(), cells.end());
  vector<int> dp(n + 2);
  dp[n + 1] = md - 1;
  for (int i = n; i >= 0; i--) {
    for (int j = i + 1; j < n + 2; j++) {
      int r = cells[j].first - cells[i].first;
      int c = cells[j].second - cells[i].second;
      if (r >= 0 && c >= 0) {
        sub(dp[i], mul(dp[j], mul(fact[r + c], mul(inv_fact[r], inv_fact[c]))));
      }
    }
  }
  cout << dp[0] << '\n';
  return 0;
}


Measured memory_bytes: 1920
#!/usr/bin/perl

my $l1 = <STDIN>;
$l1 =~ /^\d+/o;
my $n = $&;
$n=$n - 0;

my @d=();
for(my $i=0;$i<($n-1);$i++){
  my $l2 = <STDIN>;
  my @a = split(/\s+/,$l2);
  push(@d,\@a);
}

for(my $i=0;$i<$n;$i++){
  my $yy = &f(0,$i);
  print "$yy\n";
}

exit 0;

sub f{
  local $ct = shift;
  local $i = shift;
  if( $i == $n-1 ){
    return $ct;
  }
  local $dd = $d[$i];
  
  if( $dd->[1] - 0 > $ct ){
    return &f( $dd->[1] + $dd->[0] , $i+1 );
  }
  
  local $xx = int( $ct / $dd->[2] );
  if( $xx * $dd->[2] == $ct ){
    return &f( $ct + $dd->[0] , $i + 1);
  } else {
    return &f( $dd->[2] * (1 + $xx) + $dd->[0], $i + 1 );
  }
}





Measured memory_bytes: 1664
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    
    if op=="?":
        break
    if op=="+":
        print(a+b)
    if op=="-":
        print(a-b)
    if op=="*":
        print(a*b)
    if op=="/":
        print(a//b)



Measured memory_bytes: 5596
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
//#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define BIG_NUM 9999999999999

struct Info{
	Info(){
		row = col = move_cost = sum_cost = 0;
	}

	Info(int arg_row,int arg_col,ll arg_move_cost,ll arg_sum_cost){
		row = arg_row;
		col = arg_col;
		move_cost = arg_move_cost;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct Info &arg) const{
		return sum_cost > arg.sum_cost;
	}
	int row,col;
	ll move_cost,sum_cost;
};

int H,W;
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
ll min_cost[30][30][901],base_map[30][30];


bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1){
		return true;
	}else{
		return false;
	}
}


int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++)scanf("%lld",&base_map[row][col]);
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			for(int i = 0; i <= H*W; i++)min_cost[row][col][i] = BIG_NUM;
		}
	}

	priority_queue<Info> Q;
	min_cost[0][0][0] = 0;
	Q.push(Info(0,0,0,0));

	int adj_row,adj_col,next_move_cost,next_sum_cost;
	ll ans = BIG_NUM;

	Info info;

	while(!Q.empty()){

		if(Q.top().row == H-1 && Q.top().col == W-1){
			ans = min(ans,Q.top().sum_cost);
			Q.pop();
		}else if(Q.top().sum_cost > min_cost[Q.top().row][Q.top().col][Q.top().move_cost]){
			Q.pop();
		}else if(Q.top().move_cost == H*W+1){
			Q.pop();
		}else{

			info = Q.top();
			Q.pop();

			for(int i = 0; i < 4; i++){
				adj_row = info.row+diff_row[i];
				adj_col = info.col+diff_col[i];

				if(!rangeCheck(adj_row,adj_col))continue;

				next_move_cost = info.move_cost+1;
				next_sum_cost = info.sum_cost+(base_map[adj_row][adj_col]*(2*info.move_cost+1))+1;

				if(adj_row == H-1 && adj_col == W-1){
					next_sum_cost -= info.move_cost+1;
				}

				if(min_cost[adj_row][adj_col][next_move_cost] > next_sum_cost){
					min_cost[adj_row][adj_col][next_move_cost] = next_sum_cost;
					Q.push(Info(adj_row,adj_col,next_move_cost,next_sum_cost));
				}
			}
		}
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 15316
N, W = map(int, input().split())
K = [[] for i in range(N)]
for i in range(N):
    K[i] = list(map(int, input().split()))

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(1,N+1):
    w, v = K[i-1]
    for sum_w in range(W+1):
        if sum_w-w>=0:
            dp[i][sum_w] = max(dp[i-1][sum_w], dp[i-1][sum_w-w]+v)
        else:
            dp[i][sum_w] = dp[i-1][sum_w]
print(dp[-1][-1])

Measured memory_bytes: 171656
#include <bits/stdc++.h>
#define fore(i,a,b) for(int i = a; i < b; i++)
#define fst first
#define snd second
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define piii pair<int, pii>
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define mp make_pair

using namespace std;


int main(){
    int X;
    cin>>X;
    cout<<X*(1+X*(1+X))<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int n;
    int a[100]{};

    cin >> n;
    rep(i, n) cin >> a[i];

    ll m = 1000, k = 0;

    rep(i, n) {
        m += k * a[i];
        k = 0;
        if(i + 1 < n && a[i] < a[i + 1]) {
            k = m / a[i];
            m %= a[i];
        }
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 3608
N = int(input())
a = list(map(int, input().split()))

cnt = 0
tmp = 0

for i in range(N):
  if a[i]%2 == 0:
    while a[i]%(2**tmp) ==0:
      tmp = tmp + 1
    cnt = cnt + tmp -1
    tmp = 0
print(cnt)

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	long long x[n], y[n], z[n];
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i] >> z[i];
	}
	long long ans = 0;
	for(int i = 0; i < (1 << 3); i++){
		vector<long long> v(n, 0);
		bool rev_x = false, rev_y = false, rev_z = false;
		if(i >> 0 & 1) rev_x = true;
		if(i >> 1 & 1) rev_y = true;
		if(i >> 2 & 1) rev_z = true;
		for(int j = 0; j < n; j++){
			if(rev_x) v[j] -= x[j];
			else v[j] += x[j];
			if(rev_y) v[j] -= y[j];
			else v[j] += y[j];
			if(rev_z) v[j] -= z[j];
			else v[j] += z[j];
		}
		sort(v.rbegin(), v.rend());
		long long sum = 0;
		for(int j = 0; j < m; j++){
			sum += v[j];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using ll = long long;
using namespace std;

struct D {
	ll a;
	ll b;
	ll t; // a + b
};

struct OpD {
	bool operator() (D i, D j) { return (i.t > j.t); }
};

void sort_by_1 (vector<D> &data) {
	OpD compareObj;
	sort(data.begin(), data.end(), compareObj);
}

int main () {
	ll N;
	cin >> N;
	D d_dummy;
	d_dummy.a = d_dummy.b = d_dummy.t = 0;
	vector<D> d(N,d_dummy);
	for (ll i=0; i<N; ++i) {
		cin >> d[i].a >> d[i].b;
		d[i].t = d[i].a + d[i].b;	
	}
	sort_by_1(d);
	ll ans = 0;
	for (ll i=0; i<N; ++i) {
		if (i%2 == 0) {
			ans += d[i].a;
		} else {
			ans -= d[i].b;
		}
	}
	cout << ans << endl;
	/*
	for (ll i=0; i<N; ++i) {
		cout << d[i].a << "," << d[i].b << "," << d[i].t << endl;
	}
	*/
	return 0;
}



Measured memory_bytes: 2560
#include<cstdio>
using namespace std;

int main() {
	int a, b,c;
	scanf("%d %d %d", &b, &a,&c);
	if (b >= c) printf("0\n");
	else if(a+b>=c) printf("%d\n", c-b);
	else printf("NA\n");
	return 0;
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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

int n;
int u, k, v;
int hour = 1;
int d[101] = {}, f[101] = {};
int gra[101][101] = {};
int color[101] = {};




void dfs(int u) {
	color[u] = 1;
	d[u] = hour;
	hour++;
	FOR(i, 1, n) {
		if (gra[u][i] == 1 && color[i] == 0) {
			dfs(i);
		}
	}
	color[u] = 2;
	f[u] = hour;
	hour++;
}

void dfs_call(void) {

	FOR(i, 1, n) {
		if (color[i] == 0) {
			dfs(i);
		}
	}
}


int main(void) {
	cin >> n;
	
	FOR(i, 1, n) {
		cin >> u >> k;
		FOR(t, 1, k) {
			cin >> v;
			gra[u][v] = 1;
		}
	}
	d[1] = hour;

	dfs_call();

	FOR(i, 1, n) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
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&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int X = nextLong();
  int Y = nextLong();

  bool found = false;

  for (int x = 0; x <= 400; x++) {
    for (int y = 0; y <= 400; y++) {
      if (x + y == X && 2*x + 4*y == Y) found = true;
    }
  }

  if (found)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3684
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 31);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
int main() {
	string s; cin >> s;
	int l = 0, r = s.size() - 1,ans = 0;
	while (l + 1 <= r) {
		if (s[l] != s[r] && s[l] != 'x' && s[r] != 'x') {
			cout << -1 << endl;
			return 0;
		}
		if (s[l] == s[r]) {
			l++; r--;
		}
		else if (s[l] == 'x') {
			l++; ans++;
		}
		else {
			r--; ans++;
		}
	}cout << ans << endl;
}

Measured memory_bytes: 512