akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=sc.next();
int p=1;

if(a.length()+1!=b.length()){
    p=0;
}


       if(a.length()+1==b.length()){
            for (int i=0;i<a.length();i++){
                if((a.charAt(i))!=b.charAt(i)){
                    p=0;
                    break;
                }
            }

            }


       if(p==1){
           System.out.println("Yes");
       }
        if(p==0){
            System.out.println("No");
        }
        }

}

Measured memory_bytes: 35692
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String line;
			/* input */
			while(true){
				line = br.readLine();
				int n = Integer.parseInt(line), sum = 0;
				if(n==0) break;
				for(int i=0;i<n/4;i++){
					sum += Integer.parseInt(br.readLine());
				}
				System.out.println(sum);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16876
n = int(input())
s = input()

l = 0
r = n-1
ans = 0
while(True):
    while(s[l]=='R' and l<n-1):
        l+=1
    while(s[r]=='W' and 0<r):
        r-=1
    if l < r:
        ans += 1
        l += 1
        r -= 1
    else:
        break

print(ans)

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

int main()
{
  int res=1;
  int N;
  cin >> N;
  vector<int> mountain(N);

  for (int i = 0; N > i; ++i) cin >> mountain[i];

  for (int current_number = 1;N>current_number; ++current_number) {
    int i = 0;
    while (current_number>i) {
      if (mountain[i] > mountain[current_number]) break;
      ++i;
    }
    if (i == current_number) ++res;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
cnt = 0
amin = 10**9+7
tot = 0
for i in range(N):
    if A[i]<0:
        cnt += 1
    amin = min(amin,abs(A[i]))
    tot += abs(A[i])
if cnt%2==0:
    print(tot)
else:
    print(tot-2*amin)

Measured memory_bytes: 64752
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

int calc(string s) {
    char[] cs;
    for (int i = 0; i < s.length; i++) {
        if (s[i] != 'x')
            cs ~= s[i];
    }

    for (int i = 0; i < cs.length / 2; i++) {
        if (cs[i] != cs[$ - i - 1]) {
            return -1;
        }
    }

    int ans = 0;
    int lo = 0;
    int hi = cast(int) s.length - 1;
    while (lo < hi) {
        if (s[lo] == s[hi]) {
            lo++;
            hi--;
        }
        else if (s[lo] == 'x') {
            lo++;
            ans++;
        }
        else if (s[hi] == 'x') {
            hi--;
            ans++;
        }
        else {
            writeln("err");
            return -1;
        }
    }
    return ans;
}

void main() {
    auto s = readln.chomp;
    writeln(calc(s));
}


Measured memory_bytes: 2584
a,b,q=map(int,input().split())
s=[int(input()) for i in range(a)]
t=[int(input()) for i in range(b)]
x=[int(input()) for i in range(q)]

from bisect import bisect_left

for i in range(q):
    y=bisect_left(s,x[i])
    z=bisect_left(t,x[i])
    k=([0] if y==0 else [a-1] if y==a else [y-1,y])
    l=([0] if z==0 else [b-1] if z==b else [z-1,z])
    mi=100000000000000
    for n in k:
        for m in l:
            if abs(s[n]-x[i])>abs(t[m]-x[i]):
                sub1,sub2=t[m],s[n]
            else:
                sub1,sub2=s[n],t[m]
            mi=min(mi,abs(sub1-x[i])+abs(sub2-sub1))
    print(mi)


Measured memory_bytes: 16168
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    vector<int> l(2 * n, 0), r(2 * n, 0);
    l[0] = 1;
    for (int i = 1; i < 2 * n; i++) {
        if ((s[i] == s[i - 1] && l[i - 1] == 0) || (s[i] != s[i - 1] && l[i - 1] == 1)) {
            l[i] = 1;
        } else {
            r[i] = 1;
        }
    }

    for (int i = 1; i < 2 * n; i++) {
        l[i] += l[i - 1];
        r[i] += r[i - 1];
    }

    if (s[0] == 'B' && s[2 * n - 1] == 'B' && l[2 * n - 1] == r[2 * n - 1]) {
        long long res = 1;
        for (int i = 0; i < n; i++) {
            res *= i + 1;
            res %= 1000000007;
        }
        for (int i = 1; i < 2 * n; i++) {
            if (r[i] > r[i - 1]) {
                res *= l[i - 1] - r[i - 1];
                res %= 1000000007;
            }
        }

        cout << res << endl;
    } else {
        cout << "0" << endl;
    }
}


Measured memory_bytes: 2180
A,B,K = map(int,input().split())
if 2*K >= B-A+1:
    for i in range(A,B+1):
        print(i)
else:
    for j in range(A,A+K):
        print(j)
    for v in range(B-K+1,B+1):
        print(v)


Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define li long ll
#define pp pair<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr first
#define ss second
#define mod 1000000007
using namespace std;
int findMaxGCD(int arr[], int n) 
{ 
    // Calculating MAX in array 
    int high = 0; 
    for (int i = 0; i < n; i++) 
        high = max(high, arr[i]); 
  
   
    int count[high + 1] = {0}; 
    for (int i = 0; i < n; i++) 
        count[arr[i]]++; 
  
   
    int counter = 0; 
  
   
    for (int i = high; i >= 1; i--) 
    { 
        int j = i; 
       counter = 0; 
    
       
        while (j <= high) 
        { 
            // A multiple found 
  
            if(count[j] >=2) 
               return j; 
  
           else if (count[j] == 1)          
                counter++;         
            j += i; 
  
            // 2 multiples found, 
            // max GCD found 
            if (counter == 2)          
                return i; 
        } 
    } 
} 
int main()
{
	fast;
    int n;
    cin>>n;
    int a[n];
    llp(i,0,n)
    cin>>a[i];
    int m=a[0];
    for(int i=1;i<n;i++)
    {
    	m=__gcd(m,a[i]);
    }
    if(findMaxGCD(a,n)==1)
    cout<<"pairwise coprime"<<endl;
    else if(m==1)
    cout<<"setwise coprime"<<endl;
    else
    cout<<"not coprime"<<endl;
}

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

using namespace std;

void print(vector <int> v) {
    for (int i=0; i<v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << "\n";
}

int search(vector <int> v, int index) {
    if (index > 0 && index < v.size()) {
        return v[index];
    } else {
        return 0;
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> r;
    vector<int> g;
    vector<int> b(n+1);
    for (int i=1; i<=n; i++) {
        char ch;
        cin >> ch;
        if (ch == 'R') {
            r.push_back(i);
        } else {
            if (ch == 'G') {
                g.push_back(i);
            } else {
                b[i] = 1;
            }
        }
    }
    long long total = 0;
    int c;
    int bs = n-r.size()-g.size();
    for (int i=0; i<r.size(); i++) {
        for (int j=0; j<g.size(); j++) {
            if (r[i] > g[j]) {
                int diff = r[i] - g[j];
                if (diff%2) {
                    c = search(b, r[i]+diff) + search(b, g[j]-diff);
                } else {
                    c = search(b, r[i]+diff) + search(b, g[j]-diff) + search(b, g[j]+diff/2);
                }
            } else {
                int diff = g[j] - r[i];
                if (diff%2) {
                    c = search(b, g[j]+diff) + search(b, r[i]-diff);
                } else {
                    c = search(b, g[j]+diff) + search(b, r[i]-diff) + search(b, r[i]+diff/2);
                }
            }
            total += bs - c;
        } 
    }
    cout << total << "\n";
}

Measured memory_bytes: 3696
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

void PrintCase(int number){
	printf("Case #%d: ",number);
}

int main(){
    string str;
    while(cin>>str&&str!="0"){
        int cnt=0;
        // ツつアツつアツづ慊づづづ個青板篠堋つェツ可スツ嘉アツ出ツ個サツつオツづつ「ツづゥツつゥ
        int ap[2][11];
        for(int i = 0; i < 2; i++)
            fill(ap[i],ap[i]+11,0);
        ap[(str.size()-1)%2][str[str.size()-1]-'0']++;
        for(int i = str.size()-2; i >= 0; i--){
            int sum=0;
            if(str[i]=='0'){
                for(int j = 0; j <= 10; j++)
                    ap[(i)%2][j]=ap[(i+1)%2][j];
                ap[i%2][0]++;
                continue;
            }
            int ad=str[i]-'0';
            if((str.size()-1-i)%2!=0){
                ad*=10;
            }
            // jツづ個青板篠堋づ可督楪達ツづつォツづゥツ青板篠堋つェツつ「ツつュツづつ堕カツ催敖つキツづゥツつゥ
            for(int j = 0; j <= 10; j++)
                ap[(i)%2][j]=ap[(i+1)%2][(j-ad+110)%11];
            ap[i%2][ad%11]++;
            cnt+=ap[i%2][0];
            //for(int j = i; j >= 0; j--){
            //    if(str[j]=='0')
            //        continue;
            //    if((i-j)%2==0)
            //        sum+=str[j]-'0';
            //    else
            //        sum+=(str[j]-'0')*10;
            //    if(sum!=0&&sum%11==0)
            //        cnt++;
            //}
        }
        cout<<cnt<<endl;
    }

    return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define nl '\n'
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int , int> pi;

void solve()
{
	int n;
	cin>>n;
	vector<pi> a(n);
	for(int i=0; i<n; i++)
	{
		cin>>a[i].F;
		a[i].S = i;
	}
	sort(a.begin(), a.end(), greater<pi>());
	ll dp[n+1][n+1];
	dp[0][n] = 0;
	for(int i=0; i<n; i++)
	{
		ll act = a[i].F;
		int pos = a[i].S;
		dp[0][n-1-i] = dp[0][n-i] + act*abs(n-1-i-pos);
		dp[i+1][n] = dp[i][n] + act*abs(pos-i);
		for(int j=1; j<i+1; j++)
		{
			int k = n-i-1+j;
			dp[j][k] = max(dp[j][k+1] + act*abs(k-pos), dp[j-1][k] + act*abs(pos-j+1));
		}
		
	}
	ll ma = 0;
	for(int i=0; i<=n; i++)
		ma = max(ma, dp[i][i]);
	cout<<ma<<nl;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	t = 1;
	while(t--)
	{
		solve();
	}
	return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int N;
VS ans;

void dfs(string s, int mx){
    if(s.size() == N){
        ans.push_back(s);
        return;
    }

    REP(i,mx){
        dfs(s+(char)('a'+i), mx);
    }
    dfs(s+(char)('a'+mx), mx+1);
    return;
}
int main(void){
    cin >> N;
    dfs("a",1);
    ll K =ans.size();
    SORT(ans);
    REP(i,K) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 7796
# atcoder Educational DP contest/DP まとめコンテスト
# B-Frog2

def get_inputs():
    [n, k] = [int(x) for x in input().split()]
    h = list(map(int, input().split()))
    
    return n, k, h


if __name__ == "__main__":
    # 入力を受け取る
    # n 足場の数 2<= N <= 10**5
    # k k本先の足場まで飛ぶことができる 1<=K<=100
    # h 足場の高さ 配列
    n, k, h = get_inputs()
    
    ########## first try
    # for文の二重ループではTLEになってしまう
    # dp = [10000000000] * (n + k)        # k個分を含む配列を用意し最大値で初期化する
    # h= h + [100000] * k
    # dp[0] = 0                             # 0番目の足場はコスト0
    # 足場iからj個先まで行く場合の最小コストを求める
    # for i in range(0, n - 1):
    #    for j in range(1, k + 1):
    #        dp[i + j] = min(dp[i] + abs(h[i + j] - h[i]), dp[i + j])
    # print(dp[n-1])
    
    ########## second try
    # 前案より速度は改善したが、まだ一部の問題でTLEになる
    # dp = [10**9] * n
    # dp[0] = 0
    #
    # for i in range(1, n):
    #     mc = 10**9
    #     for j in range(max(0, i - k), i):
    #         mc = min(mc, dp[j] + abs(h[i] - h[j]))
    #    dp[i] = mc
    # print(dp[n-1])
    
    ########## third try
    # 二重ループを内包表記表現に変更
    # zipを使うのがミソ
    
    dp = [10**9] * n
    dp[0] = 0
    for i in range(1, n):
        j = max(0, i - k)
        dp[i] = min([dd + abs(h[i] - hh) for (dd, hh) in zip(dp[j:i], h[j:i])])
    print(dp[n-1])
    

Measured memory_bytes: 13976
N,A = map(int,input().split())
X = list(map(int,input().split()))

for i in range(N):
    X[i] -= A

from collections import defaultdict

counter = defaultdict(int)
counter[0] = 1

for x in X:
    copy = dict(counter)
    for k,v in copy.items():
        counter[k+x] += v

print(counter[0]-1)


Measured memory_bytes: 3564
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> pll;
pll p[100005];
int main(){
	int a,b,n,m;
	cin>>n>>m;
	int	mm=m;
	int i=0;
	while(m--){
		cin>>a>>b;
		p[i]=pll(b,a);
		i++;
	}
	sort(p,p+mm);
	int kase=1;
	int min;
	min=p[0].first-1;
	for(int i=0;i<mm;i++){
		if(p[i].second>min){
			kase++;
			min=p[i].first-1;
		}
	} 
	cout<<kase;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  cin>>x;
  bool f=false;
  int ans=x;
  while(!f)
  {
    bool div=false;
    for(int i=2;i<=sqrt(ans);i++)
    {
      if(ans%i==0){div=true;break;}
    }
    if(!div){cout<<ans;return 0;}
    ans++;
  }
}

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

int n, m;
vector<pair<int, int>> g[55];

bool dfs (int v, int p, int t, long long &val) {
    for (const auto &e : g[v]) if (e.first != p) {
        int u, id; tie(u, id) = e;
        if (u == t) { val |= (1LL << id); return true; }
        else if (dfs(u, v, t, val)) {
            val |= (1LL << id); return true;
        }
    }
    return false;
}

int main() {
    cin >> n;
    vector<pair<int, int>> dat;
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--; b--;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        dat.emplace_back(a, b);
    }
    
    vector<long long> edge(m, 0);
    for (int i = 0; i < m; i++) {
        dfs(dat[i].first, -1, dat[i].second, edge[i]);
    }
    
    long long ans = (1LL << (n - 1));
    
    for (int s = 1; s < (1<<m); s++) {
        int k = 0;
        long long val = 0;
        for (int i = 0; i < m; i++) {
            if (s & (1 << i)) { val |= edge[i]; k++; }
        }
        
        int res = n - 1 - __builtin_popcountll(val);
        if (k & 1) ans -= (1LL << res);
        else ans += (1LL << res);
    }
    
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
typedef long long LL;

using namespace std;
int n;
int cc[51][26];

int main(void){
    cin>>n;
    REP(i,n){
        string s;cin>>s;
        REP(j,SZ(s))
            cc[i][s[j]-'a']++;
    }
    REP(j,26)cc[n][j]=INT_MAX;
    REP(i,n)REP(j,26)cc[n][j]=min(cc[n][j],cc[i][j]);
    string r;
    REP(j,26)r+=string(cc[n][j],'a'+j);
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<stdlib.h>
#define ll long long

int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

//nをm回右シフトして、一桁目が1かどうか
#define bit(n,m)(((n)>>(m))&1)

void swap(long long *i, long long *j ){
  long long tmp = *i;
  *i = *j;
  *j = tmp;
}


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

  //大きい順にソート
  // for(long long i=0;i<n-1;++i){
  //   for(long long j=i+1;j<n;++j){
  //     if( a[i] < a[j] ) swap(&a[i],&a[j]);
  //   }
  // }
  sortdown(a,n);

  long long ans = 0;//心地よさの合計
  long long cnt = 1;//到着済みの人数
  for(long long i=0;i<n;++i){
    if( i == 0 ){
      //最初に到着した人のフレンドリーさは、一回しかカウントされない
      ans += a[0];
      cnt++;
      if(cnt == n ) break;//n人到着したら、終了
      continue;
    }
    //2番目以降に到着した人は、2回ずつカウントできる（両隣）
    ans += a[i];
    cnt++;
    if( cnt == n ) break;

    ans += a[i];
    cnt++;
    if( cnt == n ) break;
  }

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

  return 0;
}



Measured memory_bytes: 4640
// Problem : E - Red and Green Apples
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int maxn=300000+10;
int v[maxn];

int cmp(int a,int b){return a>b;}

struct Apple{
	int v,c;
	Apple(int v=0,int c=0):v(v),c(c){}
	bool operator < (const Apple &rhs)const{
		return v>rhs.v;
	}
};

int main()
{
	int X,Y,a,b,c;cin>>X>>Y>>a>>b>>c;
	vector<Apple>vc;
	int v;
	rep(i,1,a) {
		cin>>v;vc.push_back(Apple(v,1));
	}
	rep(i,1,b) {
		cin>>v;vc.push_back(Apple(v,2));
	}
	rep(i,1,c) {
		cin>>v;vc.push_back(Apple(v,3));
	}	
	
	sort(vc.begin(),vc.end());
	long long ans=0;
	int cnt[4]={0},sum=0;
	for(auto x: vc){
		if(x.c==1 && cnt[1]>=X) continue;
		if(x.c==2 && cnt[2]>=Y) continue;
		ans+=x.v;
		++cnt[x.c];
		if(++sum == X+Y) break;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6520
N = int(input())
points = [tuple(int(x) for x in input().split()) for _ in range(N)]
if any(abs(x + y) % 2 != abs(sum(points[0])) % 2 for x, y in points):
    print(-1)
    quit()
even_flag = abs(sum(points[0])) % 2 == 0
points = [(x + y, x - y) for x, y in points]

M = 31 + even_flag
print(M)
print(*([1] if even_flag else []) + [1 << i for i in range(31)])
d_uv = {(0, 0): "L", (1, 1): "R", (1, 0): "U", (0, 1): "D"}
for u, v in points:
    ans = []
    if even_flag:
        ans.append("R")
        u, v = u - 1, v - 1
    sum_d_u = (u + (1 << 31) - 1) // 2
    sum_d_v = (v + (1 << 31) - 1) // 2
    for i in range(31):
        u_flag = sum_d_u >> i & 1
        v_flag = sum_d_v >> i & 1
        ans.append(d_uv[u_flag, v_flag])
    print(''.join(ans))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> A(3);
  int k;
  for(auto &i:A)cin >> i;
  cin >> k;
  int q = *max_element(A.begin(), A.end());
  q = q * pow(2, k);
  vector<int>::iterator iter = max_element(A.begin(), A.end());
  size_t index = distance(A.begin(), iter);
  A[index] = q;
  cout << A[0]+A[1]+A[2] << endl;
  return 0;
}

Measured memory_bytes: 384
import java.io.IOException;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			String a = sc.next();
			int b = a.length();
			char c ;
			int g = 0;
			int e = 0 ;
			int f = 1;
			if (b==1){
				f = Integer.parseInt(a);
			}
			while(f != 0){
				for(int d=0 ; d<b ; d++){
					c = a.charAt(d);
					g = Character.getNumericValue(c);
					e += g;
				}
				System.out.println(e);
				a = sc.next();
				b = a.length();
				if (b==1){
					f = Integer.parseInt(a);
				}
				e = 0;
			}
	}
}

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

int main() {
    int arr[32]={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};
    int k;
    cin>>k;
    cout<<arr[k-1];
    return 0;
       
}

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

#define MAX_N 100000
#define MAX_M 100000

int main() {
  int n, m, x[MAX_M];

  std::cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    std::cin >> x[i];
  }
  std::sort(x, x + m);

  if(n >= m) {
    std::cout << 0 << std::endl;
    return 0;
  }

  int dist[MAX_M - 1];
  for(int i = 0; i < m - 1; ++i) {
    dist[i] = x[i + 1] - x[i];
  }
  std::sort(dist, dist + m - 1);


  int ans = std::abs(x[m - 1] - x[0]);
  for(int i = 0; i < n - 1; ++i) {
    ans -= dist[m - 2 - i];
  }

  std::cout << ans << std::endl;
}

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solution(String[] args) throws Exception{
		String S = nextString();
		String T = nextString();
		StringBuffer sb = new StringBuffer();

		sb.append(S);
		for(int i=0;i<S.length();i++){
			if(sb.toString().equals(T)){
				pw.println("Yes");
				return ;
			}
			sb.append(sb.charAt(0));
			sb.deleteCharAt(0);
		}
			pw.println("No");
	}

	public static void dfs(int n,int cnt,ArrayList<Integer>[] tree,int parent,int[] set){
		if(n!=parent&&tree[n].size()==1){
			set[n]=cnt;
			return;
		}
		for(int x:tree[n]){
			if(x==parent){
				continue;
			}
			dfs(x,cnt+1,tree,n,set);
		}
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 23124
//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;

int maxn = ~0x3f3f3f3f, a[4];

int main()
{
    cin>>a[1]>>a[2]>>a[3];
    for(int i=1;i<=3;i++)
    	for(int j=1;j<=3;j++)
        	for(int k=1;k<=3;k++)
        		if(i != j && i != k && j != k)
            		maxn = max(maxn, a[i]+a[j]*10+a[k]);
    cout<<maxn<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define gcd(a, b)       __gcd(a, b)
#define here            cout<<"here";
#define lcm(a, b)       ((a)*1ll * (b)) / gcd(a, b)
#define pb              push_back
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl              "\n"
#define vi              vector<int>
#define vvi             vector<vector<int> >
#define F               first
#define S               second
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define w(x)            int x; cin>>x; while(x--)
#define fre(i,a,n)      for (int i = a; i <= n; ++i)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define rf(i,n,a)       for (int i = n; i >=a; --i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pqi		   priority_queue<int>
#define pqgi            priority_queue<int,vector<int>,greater<int>>
#define MN              min_element
#define MX              max_element
#define all(x)          x.begin(),x.end()
#define YN(ans)         ans ? cout << "YES" : cout << "NO";
#define d0(x)           cout<<(x)<<" "
#define d1(x)           cout<<(x)<<endl
#define d2(x,y)         cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z)       cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d)     cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e)   cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define max3(a,b,c)     max(max((a),(b)),(c))
#define max4(a,b,c,d)   max(max((a),(b)),max((c),(d)))
int pow(int a, int b, int m) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % m;
		b /= 2;  a = (a * a) % m;
	}
	return ans;
}
//when m is prime
int modinv(int a, int m)  {return pow(a, m - 2, m);}
void start()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

const int N = 100005;
int n, cap;
int a[N][2];
int dp[101][N];

int fun(int pos, int wgh) {
	//base
	if (pos < 0 ) return 0;
	//lookup
	if (dp[pos][wgh] != -1) return dp[pos][wgh];
	//recursive

	int op1 = ((wgh - a[pos][0])>=0) ? a[pos][1] + fun(pos - 1, wgh - a[pos][0]) : INT_MIN;
	int op2 = fun(pos - 1, wgh);
	return dp[pos][wgh] = max(op1, op2);

}


void solve()
{
	cin >> n >> cap;
	memset(dp, -1, sizeof dp);
	fr(i, n) fr(j, 2) cin >> a[i][j];
	 cout<<fun(n,cap);

}


////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////


int32_t main()
{
	FIO;
	//start();
	solve();
// w(x)    {solve();}
#ifndef ONLINE_JUDGE
	cerr << "\nTime Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
}


Measured memory_bytes: 82536
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ll mulmod(ll x, ll y)
{
	return (x * y) % mod;
}

ll submod(ll x, ll y)
{
	return (x - y + 100 * mod) % mod;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r/2);
		return mulmod(y, y);
	}
	else
	{
		ll y = power(n, (r-1)/2);
		return n * mulmod(y, y) % mod;
	}
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);
	
	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i-1], i);
	}
	
	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	// n (n-1) ... (n-r)
	ll ans = 1;
	for (ll i = 0; i < r; i++)
		ans = mulmod(ans, n - i);

	return mulmod(ans, inv[r]);
}

ll solve(void)
{
	ll n, a, b;
	cin >> n >> a >> b;
	
	// nc1 + nc2 + nc3 + ... + ncn
	// = (1 + 1)^n - nc0 - 
	init_inv(2 * 10e5 + 1);

	ll ans = power(2, n);
	ans = submod(ans, ncr(n,0));
	ans = submod(ans, ncr(n,a));
	ans = submod(ans, ncr(n,b));
	
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	register int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(register int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int a=read(),b=read();
	if(a>0)
		printf("Positive");
    else 
		if(b>=0)
			printf("Zero");
    	else 
			if((a&1)^(b&1))
				printf("Positive");
    		else 
				printf("Negative");
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
import itertools
n=int(input())
s=[input()for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for i in s:
 if i[0]=="M":m+=1
 if i[0]=="A":a+=1
 if i[0]=="R":r+=1
 if i[0]=="C":c+=1
 if i[0]=="H":h+=1
l=[m,a,r,c,h]
ans=0
for i in itertools.combinations(l,3):ans+=i[0]*i[1]*i[2]
print(ans)

Measured memory_bytes: 16180
#include<stdio.h>
int main(){
  
  int n,i,j,k,key,a[101];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  } 
  for(k=1;k<=n;k++){
      if(k==n)printf("%d",a[k]);
      else printf("%d ",a[k]);
  }
  printf("\n");
  for(i=2;i<=n;i++){
    key=a[i];
    j=i-1;
    while(j>=0 && a[j]>key){
      a[j+1]=a[j];
      j=j-1;
    }
    a[j+1]=key;
    for(k=1;k<=n;k++){
      if(k==n)printf("%d",a[k]);
      else printf("%d ",a[k]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
#define N 10000

int search(int *, int, int);

int main()
{ 
 int i, n, A[N], q, key, count=0;
 
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%d", &key);
    if(search(A, n, key)){
      count++;
    }
  }
  printf("%d\n", count);

  return 0;
}
int search(int A[], int n, int key){
  int i;
  for (i=0;i<n;i++){
    if (A[i]==key) return 1;
  }
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
using namespace std;
using ll = long long;
using graph = std::vector<std::vector<long long>>;
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll minC = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] < 0){
            minC++;
        }
        A[i] = abs(A[i]);
    }
    sort(A.begin(),A.end());
    ll sum = 0;
    for(int i = 0; i< N; i++){
        if(i == 0){
            if(minC % 2 == 1){
                sum -= A[i];
            }else{
                sum += A[i];
            }
        }else{
            sum += A[i];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

ll gcd(ll a, ll b) {
    if (a<b) swap(a, b);
    while(b!=0) {
        ll t = a;
        a = b;
        b = t%b;
    }
    return a;
}

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

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int x; cin >> x;

    int ans = 0;
    ans += x/500*1000;

    x %= 500;
    ans += x/5*5;

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long UL;
const int N=1e5+5;
const int INF=0x3f3f3f3f;
vector<int> G[N];
int Vis[N];
void DFS(int u){
	Vis[u]=1;
	for(int i=0;i<G[u].size();++i){
		int v=G[u][i];
		if(Vis[v]==0) DFS(v);
	}
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
	int n,m;
	cin>>n>>m;
	while(m--){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int cnt=0;
	for(int i=1;i<=n;++i){
		if(Vis[i]==0){
			DFS(i);
			++cnt;
		}
	}
	cout<<cnt-1<<endl;
    return 0;
}


Measured memory_bytes: 9976
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;
  vll cnt(n, 1);
  vector<bool> can(n, false);
  can[0] = true;
  rep(i, m) { ll x, y;
    cin >> x >> y;
    x--, y--;
    if (can[x]) can[y] = true;
    cnt[x]--, cnt[y]++;
    if (cnt[x] == 0) can[x] = false;
  }
  ll ans = 0;
  rep(i, n) if (can[i]) ans++;

  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	int X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	vector<ll> A(X);
	for (int i = 0; i < X; ++i) { cin >> A[i]; }
	vector<ll> B(Y);
	for (int i = 0; i < Y; ++i) { cin >> B[i]; }
	vector<ll> C(Z);
	for (int i = 0; i < Z; ++i) { cin >> C[i]; }

	vector<ll> v;
	for (int i = 0; i < X; ++i) {
		for (int j = 0; j < Y; ++j) {
			v.push_back(A[i] + B[j]);
		}
	}
	sort(v.rbegin(), v.rend());

	vector<ll> w;
	int sz = min(K, (int)v.size());
	for (int i = 0; i < sz; ++i) {
		for (int j = 0; j < Z; ++j) {
			w.push_back(v[i] + C[j]);
		}
	}
	sort(w.rbegin(), w.rend());

	for (int i = 0; i < K; ++i) {
		cout << w[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 43368
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX = 1e4 + 9;
int digit[11] = {2, 5, 5, 4, 5, 6, 3, 7, 6}, dp[MAX], n, m, a[11];

bool cmp(const int &a, const int &b) {
	return a > b;
}

void print_dp() {
	for (int i = 0; i <= n; i++) {
		cout << dp[i] << ' ';
		int n;
		cin >> n;
	}
}

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

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i]; 
		a[i]--;
	}
	dp[0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			if (i - digit[a[j]] < 0) continue;
			if (dp[i - digit[a[j]]] > 0) dp[i] = max(dp[i], dp[i - digit[a[j]]] + 1);
			//print_dp();
		}
	}
	int len = dp[n];
	string s;
	while (n) {
		vector<int> tmp;
		for (int i = 0; i < m; i++) {
			if (n - digit[a[i]] < 0) continue;
			if (dp[n - digit[a[i]]] == len - 1) {
				tmp.push_back(a[i]);
			}
		}
		sort(tmp.begin(), tmp.end(), cmp);
		s.push_back(tmp[0] + 1 + '0');
		n -= digit[tmp[0]];
		len--;
	}
	cout << s << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;
 
int main(){
    int n; cin >> n;
    ll ans=0;
    rep(i,n) ans+=i;
    cout << ans << endl;
return 0;
}

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


int A[100100];
long long dp[100][3000];

int main(){
	int n,x,a;
	cin >> n >> x;

	for(int i=0;i<n;i++){
		cin >> A[i];
		A[i]-=x;
	}
	
	dp[0][n*x]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=50*50;j++){
			dp[i+1][j]=dp[i][j];
			
			if(j-A[i]>=0)
				dp[i+1][j]+=dp[i][j-A[i]];
		}
	}
	
	cout << dp[n][n*x]-1 << endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// make new Scanner.
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());

		// Listに格納.
		List<Integer> list = inList(sc,n);
		
		int sum=0;
		int b=0;
		
		for(int a=0; a < list.size(); a++) {
			int count =1;
			for(b=a+1; b<list.size(); b++) {
				if (list.get(a)!=list.get(b)) {
					break;
				} else {
					count++;
				}
			}
			sum = sum + count/2;
			a = b -1;
			
		}
		
		System.out.println(sum);

		// close Scanner
		sc.close();

	}

	
	/**
	 *  入力した数字を配列に格納するメソッド.
	 * @param sc
	 * @param n
	 * @return
	 */
	public static List<Integer> inList(Scanner sc, int n) {
		List<Integer> list = new ArrayList<Integer>();
		for (int a=0;a<n;a++) {
			list.add(sc.nextInt());
		}
		return list;
	}
	
	
	/**
	 *   リストの数字の美しさを求める.
	 */
	public static int beautyList(List<Integer> list, int d) {
		int a=0;
		for (int b=0;b<= list.size(); b++) {
			if (Math.abs(list.get(b) - list.get(b+1)) ==d) {
				a++;
			}
		}
		return a;
	}

}



Measured memory_bytes: 21588
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static long find(long n,HashMap<Long,Long>hm)
    {if(hm.containsKey(n))
    return hm.get(n);
    else 
    {hm.put(n,1+2*find(n/2,hm));
    return hm.get(n);}
    }
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner s=new Scanner(System.in);
	    long h=s.nextLong();
	    HashMap<Long,Long>hm=new HashMap<>();
	    Long p=new Long(1);
	    Long q=new Long(1);
	    hm.put(p,q);
	    long ans=find(h,hm);
	    System.out.println(ans);}}

Measured memory_bytes: 21844
from heapq import heappush, heappop, heapify

def main():
    N,M = map(int, input().split())
    hq = [-int(i) for i in input().split()]

    heapify(hq)

    for i in range(M):
        tmp = -heappop(hq) // 2
        heappush(hq, -tmp)

    print(-sum(hq))    

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 14180
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int x, y, i;
	cin >> x >> y;
	foe(i, 0, x) {
		int res = 2 * i + (x - i) * 4;
		if(res == y) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}


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

int main(){
    string t;
    cin>>t;
    for(int i=0;i<t.size();++i){
        if(t[i]=='?'){
            // if(i!=0){
            //     if(t[i-1]=='P')t[i]='D';
            //     else t[i]='P';
            // }
            // else{
            //     if(t[i+1]=='D')t[i]='P';
            //     else t[i]='D';
            // }
            t[i]='D';
        }
    }
    cout<<t<<endl;
    return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<pair<int,ll>> v(n);
    REP(i, n){
        ll a;
        cin >> a;
        v[i] = make_pair(i, a);
    }

    sort(all(v), [](const auto& a, const auto& b){return a.second > b.second;});

    vector<vector<ll>> dp(n+1, vector<ll>(n+1));

    REP(i, n){
        REP(j, i+1){
            chmax(dp[j+1][i-j], dp[j][i-j] + abs(v[i].first - j) * v[i].second);
            chmax(dp[j][i-j+1], dp[j][i-j] + abs(n-1 - (i-j) - v[i].first) * v[i].second);
        }
    }

    ll ans = 0;

    REP(i, n+1){
        chmax(ans, dp[i][n-i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 34676
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;
#define REP(i, n) for(int (i) = 0;(i) < (n);(i)++)
#define all(x) (x).begin(),(x).end()

struct Node{
    int c;
    bool accept;
    vector<int> nextid;
    Node(int c):c(c),accept(false){
      nextid.assign(26,-1);
    }
};
vector<Node> g;

bool match(int tmp,int c){
  return (g[tmp].nextid[c] != -1) && g[g[tmp].nextid[c]].accept;
}
void insert(string& s){
  int tmp = 0;
  for(int i = 0;i < s.size();i++){
    int& nid = g[tmp].nextid[s[i] - 'a'];
    if(nid == -1){
      nid = g.size();
      g.emplace_back(s[i] - 'a');
    }
    tmp = nid;
  }
  g[tmp].accept = true;
}

ll ans;

void func(string s){
  int sz = s.size();
  vector<int> last(26,-1);
  for(int j = sz - 1;j >= 0;j--) {
    if(last[s[j] - 'a'] == -1){
      last[s[j] - 'a'] = j;
    }
  }
  int tmp = 0;
  for(int j = 0;j < sz;j++){
    for(int c = 0;c < 26;c++){
      if(j <= last[c] && match(tmp,c)){
        ans++;
      }
    }
    int nid = g[tmp].nextid[s[j] - 'a'];
    if(nid == -1) break;
    else tmp = nid;
  }
  insert(s);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<string> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
    reverse(all(a[i]));
  }
  sort(a.begin(),a.end(),[](string& s,string& t){
    return s.size() < t.size();
  });

  g.emplace_back(0);

  for(int i = 0;i < n;i++){
    func(a[i]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 144564
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    string s; cin >> s;
    int cnt = 1;
    rep(i,n-1){
        if (s[i] != s[i+1]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
L = sum([[i]*a for i, a in enumerate(A, 1)], [])
for i in range(H):
    inv = (-1)**(i&1)
    print(*L[i*W:(i+1)*W][::inv])

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

int main() {
	int n=5, sum=0;
	int a[n+1], b[n+1]={0};
	for(int i=1; i<=n; i++){
		cin >> a[i];
		b[i]=a[i]%10;
		if(b[i]!=0){
			sum+=a[i]/10*10+10;
		}
		else{
			sum+=a[i];
		}
	}
	sort(b+1, b+n+1);
	for(int i=1; i<=n; i++){
		if(b[i]!=0){
			sum=sum-10+b[i];
			break;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#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(){
    int A,B;cin>>A>>B;
    if(A!=2 && B!=2){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3644