akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String str = br.readLine();

			if(str == null){
				break;
			}
			
			String[] tmpArray = str.split("\\+");
			String str1 = tmpArray[0];
			tmpArray = tmpArray[1].split("=");
			String str2 = tmpArray[0];
			String str3 = tmpArray[1];
			
			//System.out.println(str1+" "+str2+" "+str3);
			//?????????
			boolean solve = false;
			for(int i = 0; i <= 9 ; i++){
				BigInteger a = replaceXtoNumber(str1, i);
				BigInteger b = replaceXtoNumber(str2, i);
				BigInteger c = replaceXtoNumber(str3, i);
				
				if(a != null && b != null && c != null){
					if(a.add(b).compareTo(c) == 0){
						System.out.println(i);
						solve = true;
						break;
					}
				}
			}
			if(!solve){
				System.out.println("NA");
			}
		}
	}
	
	static BigInteger replaceXtoNumber(String str, int n){
		if(str.length() >= 2 && str.charAt(0) == 'X' && n == 0){
			return null;
		}
		String tmp = new String(str);
		
		tmp = tmp.replace('X', (char) ('0'+n));
		//System.out.println(tmp);
		
//		return Long.parseLong(tmp);
		return new BigInteger(tmp);
	}

}

Measured memory_bytes: 25604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,z=0,x=0;
	cin>>n>>m;
	int a[m],q[n+5];
	char b[m][2];
	for(int i=0;i<=n;i++)
	{
		q[i]=0;
	}
//	cout<<"q[1]="<<q[1]<<endl;
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i][0]>>b[i][1];
//		cout<<"asd"<<q[a]<<endl;
		if(b[i][0]=='A'&&q[a[i]]==0)
		{
			z++;
			q[a[i]]=1;
//			cout<<z<<endl;
		}
		else
		if(b[i][0]=='W'&&q[a[i]]==0)
		{
			x++;
//			cout<<x<<endl;
		}
	}
	for(int i=0;i<m;i++)
	{
		if(b[i][0]=='W'&&q[a[i]]==0)
		{
			x--;
//			cout<<x<<endl;
		}
	}
	cout<<z<<" "<<x;
}

Measured memory_bytes: 1152
N, K = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a,b))
    
B = []
for i in sorted(AB):
    B.append(i[1])
# print(B)
import numpy
B_res = numpy.cumsum(B)
# print(B_res)

from bisect import bisect_left,bisect_right
# print(bisect_left(B_res, K))
print(sorted(AB)[bisect_left(B_res, K)][0])

Measured memory_bytes: 28748
<?php

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    sort($a);
    
    $ans = false;
    $f = true;
    for($i=0; $i<$n; $i++){
        if($a[$i] != 1) $f = false;
    }
    if($f) $ans = true;
    $f = true;
    for($i=0; $i<$n; $i++){
        if($a[$i] != $n - 1) $f = false;
    }
    if($f) $ans = true;
    
    if(!$ans){
        $ans = true;
        $x = 0;
        for($i=0; $i<$n; $i++){
            if($a[$i] != $a[0]){
                if($a[$i] == $a[0] + 1){
                    $x = $i;
                    break;
                } else {
                    $ans = false;
                    break;
                }
            }
        }
        while(++$i<$n){
            if($a[$i] != $a[0] + 1){
                $ans = false;
            }
        }
        if($ans){
            if($x==0){
                if(0<$a[0] && $a[0]<=floor(($n-$x)/2));
                else $ans = false;
            } else {
                if($x<=$a[0] && $a[0]+1<=$x+floor(($n-$x)/2));
                else $ans = false;
            }
        }
        
    }
    
    if($ans) echo "Yes";
    else echo "No";
    
?>

Measured memory_bytes: 12792
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> hoge(n);
    for(int i=0;i<n;i++) cin>>hoge.at(i);
    sort(hoge.begin(),hoge.end());
    int ans=hoge.at(0);
    
    while(true){
        int p=-1;
        for(int i=0;i<n;i++){
            if(hoge.at(i)>0){
                p=i;
                break;
            }
        }
        
        int cnt=0;
        for(int i=p+1;i<n;i++){
            hoge.at(i)%=hoge.at(p);
            if(hoge.at(i)==0) cnt++;
        }
        
        sort(hoge.begin(),hoge.end());
        for(int i=0;i<n;i++){
            if(hoge.at(i)>0){
                p=i;
                break;
            }
        }
        int pre=ans;
        ans=hoge.at(p);
        
        if(cnt>=n-1 || pre==ans) break;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 640
N = int(input())
W = list(map(int, input().split()))

sum_W = sum(W)
add_W = 0

for i in range(N):
    add_W += W[i]
    if add_W >= sum_W - add_W:
        print(min(abs(add_W - sum_W + add_W), abs(add_W - W[i] - sum_W + add_W - W[i])))
        break

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
using namespace std;
int a[4];
long long n,ans=0;
int main()
{
	scanf("%d%d%d%d%lld",&a[0],&a[1],&a[2],&a[3],&n);
	a[2]=min(a[2],min(a[0]*4,a[1]*2));
	a[3]=min(a[3],a[2]*2);
	ans=(n/2)*a[3];
	if(n&1) ans+=a[2];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        r: usize,
        s: usize,
        p: usize,
        t: Chars,
    }

    let mut ans = 0;
    let mut te: Vec<char> = Vec::new();

    for i in 0..n {
        if t[i]=='r' {
            if i>=k {
                if t[i]!=t[i-k] || te[i-k]=='f' {
                    te.push('p');
                    ans += p;
                } else {
                    te.push('f');
                }
            } else {
                te.push('p');
                ans += p;
            }
        } else if t[i]=='s' {
            if i>=k {
                if t[i]!=t[i-k] || te[i-k]=='f' {
                    te.push('r');
                    ans += r;
                } else {
                    te.push('f');
                }
            } else {
                te.push('r');
                ans += r;
            }
        } else {
            if i>=k {
                if t[i]!=t[i-k] || te[i-k]=='f' {
                    te.push('s');
                    ans += s;
                } else {
                    te.push('f');
                }
            } else {
                te.push('s');
                ans += s;
            }
        }
        // println!("{}", ans);
    }

    println!("{}", ans);

}


Measured memory_bytes: 2976
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  
  bool ok = false;
  if(s[0]==s[1] && s[1]==s[2]) ok = true;
  if(s[1]==s[2] && s[2]==s[3]) ok = true;
  
  cout << ( ok ? "Yes" : "No" ) << endl;
  
  return 0;
}

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

using namespace std;

using ll = long long;

bool Solve() {
    int n;
    cin >> n;

    int k = 0;
    while (k * (k - 1) < 2 * n) ++k;
    if (k * (k - 1) != 2 * n) return false;

    cout << "Yes\n";
    cout << k << '\n';
    vector<vector<int>> adj(k, vector<int>(k));
    for (int i = 0, idx = 1; i < k; ++i) {
        for (int j = i + 1; j < k; ++j)
            adj[i][j] = adj[j][i] = idx++;
    }
    for (int v = 0; v < k; ++v) {
        cout << k - 1;
        for (int u = 0; u < k; ++u) {
            if (v != u) {
                cout << " " << adj[v][u];
            }
        }
        cout << '\n';
    }
    return true;
}

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

    if (!Solve()) cout << "No\n";

    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

int main(){
    int a=0;
    char yoshio[10];
    scanf("%d %s",&a,&yoshio);
    if(a>=3200){
        printf("%s\n",yoshio);
        return 0;
    }
    else{
        printf("red\n");
        return 0;
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

const int maxN = 3e3 + 3;

vector<double> dp(maxN, 0); // dp[i] => probability of i heads

int main() {
    int n;
    double ph, ans = 0;
    cin >> n;
    dp[0] = 1;
    for(int i = 1; i <= n; i++) {
        cin >> ph;
        for(int j = i; j >= 0; j--) {
            dp[j] = ph * (j > 0 ? dp[j - 1] : 0) + (1 - ph) * dp[j];
        }
    }
    for(int i = n/2 + 1; i <= n; i++) ans += dp[i];
    cout << setprecision(10) << ans;
    return 0;
}

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

int main(){
	int a, b;
	cin >> a >> b;
	if(a == 1) a = 14;
	if(b == 1) b = 14;
	if(a > b){
		cout << "Alice" << endl;
	}else if(a == b){
		cout << "Draw" << endl;
	}else{
		cout << "Bob" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
S.append(0)
T.append(0)
MOD = 1000000007

dp0 = [[0 for _ in range(2005)] for _ in range(2005)]
dp1 = [[0 for _ in range(2005)] for _ in range(2005)]

dp0[0][0] = 1
for i in range(N + 1):
  for j in range(M + 1):
    dp0[i + 1][j] += dp0[i][j] % MOD
    dp1[i][j] += dp0[i][j] % MOD
    dp1[i][j + 1] += dp1[i][j] % MOD

    if S[i] == T[j]:
      dp0[i + 1][j + 1] += dp1[i][j] % MOD
ans = dp1[N][M]
print(ans % MOD)

Measured memory_bytes: 108252
'''ika tako
小数が出てくるとややこしいが、 (A)bi=ai/2  として、 
X=bi*(2p+1)  としてしまえばいい。
これで、以下の2つを満たせばよいことがわかりやすくなる。
X  は全ての  bi  の公倍数
X  を  bi  で割った商は全て奇数
なので、とりあえず全ての  bi  の最小公倍数を求めて、
それが  bi  で割ると全て奇数となるか確認する。(B)
1つでも偶数となるものがあれば、達成不可能。
全て奇数なら、最小公倍数の奇数倍が全て条件を満たす。
2数  n,m  の最小公倍数は、最大公約数を  g  として  
n*m/g  で求められる。(D)
3数以上なら、これを繰り返し適用しつづければよい。
ただし  bi  が互いに素だと、最小公倍数は繰り返している内に
とてつもなく大きくなってしまう。途中で  M  以上になった時点で (C)
M  以下の半公倍数は不可能なので、0を出力して即終了する。
'''
from fractions import gcd#最大公約数を求める関数
 
def solve(n, m, aaa):
    lcm = 1
    for a in aaa:
        a //= 2#aは、上記biに相当する変数に変換(A)
        lcm *= a // gcd(lcm, a) 
        #最小公倍数を求める、上記n*m/g に相当(D)
        if lcm > m:#最小公倍数が上限mを上回ったら解なし (C)
            return 0
    for a in aaa:
        if int(lcm / a) == lcm / a:#割り切れたら等式成立
            return 0#上記bi  で割った時に、奇数にならないケース(B)
    return (m // lcm + 1) // 2

n, m = list(map(int, input().split()))
aaa = list(map(int, input().split()))
 
print(solve(n, m, aaa))

Measured memory_bytes: 16320
#include <bits/stdc++.h>
#define maxn 200010
int a[maxn], ans[maxn];
using namespace std;
typedef long long LL;
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    int i = 0, j = n-1;
    for (; j >= 0; ++i, j -= 2) ans[i] = a[j];
    j += 2;
    for (j = j ^ 1; j < n; ++i, j += 2) ans[i] = a[j];
    printf("%d", ans[0]);
    for (int i = 1; i < n; ++i) printf(" %d", ans[i]); puts("");
    return 0;
}


Measured memory_bytes: 3712
N = int(input())
A = list(map(int,input().split()))
_sum = sum(A)
diff = [0]*(N-1)
cumul = 0
for i in range(N-1):
    cumul += A[i]
    diff[i] = abs(cumul - (_sum - cumul))
# print(diff)
print(min(diff))


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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  int c = 1;
  rep(i,n) {
    cin >> a[i];
    if (a[i] % 2 == 0) c *= 2;
  }
  cout << pow(3,n) - c << endl;;
  return 0;
}

Measured memory_bytes: 4112
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int q; cin >> q;
	while(q--){
		string s; cin >> s;
		set<string> st;
		for(int i=0;i<=s.size();i++){
			string t=s.substr(0,i);
			string tt=s.substr(i,s.size()-i);
			st.insert(t+tt);
			st.insert(tt+t);
			string ss=t;
			string sss=tt;
			reverse(ss.begin(),ss.end());
			reverse(sss.begin(),sss.end());
			st.insert(ss+tt);
			st.insert(tt+ss);
			st.insert(t+sss);
			st.insert(sss+t);
			st.insert(ss+sss);
			st.insert(sss+ss);
		}
		cout << st.size() << endl;
	}

}


Measured memory_bytes: 3216
BIG_NUM = 10**10

N = int(input())

min_value = BIG_NUM
max_diff = -BIG_NUM
for i in range(N):
    num = int(input())
    
    diff = num - min_value
    if diff > max_diff:
        max_diff = diff
        
    if num < min_value:
        min_value = num

print(max_diff)


Measured memory_bytes: 5612
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Colorful Creatures
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];
ll asums[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n;
  int dmmy = scanf("%d", &n);
  for (int i = 0; i < n; i++) dmmy = scanf("%d", &as[i]);
  sort(as, as + n);

  asums[0] = 0;
  for (int i = 0; i < n; i++) asums[i + 1] = asums[i] + as[i];

  int mini;
  for (mini = n - 1; mini > 0; mini--) {
    //printf("mini=%d, as[mini]=%d, asums[mini]=%lld\n",
    //mini, as[mini], asums[mini]);
    if (asums[mini] * 2 < as[mini]) break;
  }

  printf("%d\n", n - mini);
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;

int main(){
  ll n;
  cin>>n;
  ll a[n];
  rep(i,n){
    cin>>a[i];
  }
  map<ll,ll> mp1,mp2,mp3;
  rep(i,n){
    mp1[i+a[i]]++; mp1[i-a[i]]++;
    mp2[i+a[i]]++; mp3[i-a[i]]++;
  }
  ll x=0,y=0,z=0;
  for(auto p:mp1){
    x+=p.second*(p.second-1)/2;
  }
  for(auto p:mp2){
    y+=p.second*(p.second-1)/2;
  }
  for(auto p:mp3){
    z+=p.second*(p.second-1)/2;
  }
  cout<<x-y-z;
}


Measured memory_bytes: 50920
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

string s;
deque<char> dq;

int main(){
    int i, x, n, q, flag = 0;
    char c;
    cin >> s >> q;
    for(i=0; i<s.length(); i++){
        dq.push_back(s[i]);
    }

    for(i=0; i<q; i++){
        cin >> x;
        if(x == 1){
            flag ^= 1;
        }else{
            cin >> n >> c;
            if(flag){
                if(n == 1){
                    dq.push_back(c);
                }else{
                    dq.push_front(c);
                }
            }else{
                if(n == 1){
                    dq.push_front(c);
                }else{
                    dq.push_back(c);
                }
            }
        }
    }
    if(flag){
        while(!dq.empty()){
            cout << dq.back();
            dq.pop_back();
        }
    }else{
        while(!dq.empty()){
            cout << dq.front();
            dq.pop_front();
        }
    }    
    return 0;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))

R = []
done = set()
todo = [0]
done = set()
bp = None
while todo:
    p = todo.pop()
    R.append(p)
    done.add(p)
    np = A[p]
    if np in done:
        bp = np
    else:
        todo.append(np)
b = R.index(bp)
if K < b:
    ans = R[K] + 1
else:
    K -= b
    R = R[b:]
    ans = R[K%len(R)] + 1
print(ans)

Measured memory_bytes: 32192
import bisect
N,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(N)]
w1=wv[0][0]

Wlist=[0]+[j*w1+i for j in range(1,N+1) for i in range(3*j+1)]
Wlist=sorted(set(Wlist))
LW=len(Wlist)
dp=[[0]*LW for _ in range(N+1)]
#dp[i][j]:N個の物に対して強度(Wlist[j])のバッグ

for i in range(1,N+1):
  w,v=wv[i-1]
  for j in range(LW):
    if w<=Wlist[j]:      
      ind=bisect.bisect_right(Wlist,Wlist[j]-w)-1
      dp[i][j]=max(dp[i-1][j],dp[i-1][ind]+v)
    else:
      dp[i][j]=dp[i-1][j]

ind=bisect.bisect_right(Wlist,W)-1
print(dp[N][ind])

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  string s,t; cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  if(s < t) { cout << "Yes\n"; return 0; }

  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  map<string, int> map;
  string tmp ;
  for(int j = 1;j <= k;j++){
    REP(i, n - j + 1){
      tmp = s.substr(i, j);
      map[tmp] ++;
    }
  }
  // for (auto itr = map.begin(); itr != map.end();++itr){
  //   cout << itr->first << endl;
  // }
  cout << next(map.begin(), k - 1)->first << endl;
}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <int> vi;
typedef vector <string> vs;
typedef vector <vector <llong> > matrix;

typedef pair <llong, llong> pll;

typedef map <int, int> mii;

typedef set <llong> sl;

const int MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const int INF = 1e9;
const llong LINF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;}

llong n, a, b;

int main () {
    android;
    //freopen ("input.txt", "r", stdin);
    cin >> n >> a >> b;
    if (n == 1 && a != b) return cout << 0, 0;
    if (a > b) return cout << 0, 0;
    llong mn = a * (n - 1) + b;
    llong mx = a + (n - 1) * b;
    cout << mx - mn + 1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int h[1000], w[1000];
	int eoi;

	for (int i = 0;; i++) {
		cin >> h[i] >> w[i];

		if (h[i] == 0 && w[i] == 0) {
			eoi = i;
			break;
		}
	}

	for (int i = 0; i < eoi; i++) {
		for (int j = 0; j < h[i]; j++) {
			for (int k = 0; k < w[i]; k++) {
				//??¶??°?????¶??°???or?\???°????\???°???
				if ((j+k)%2==0) {
					cout << "#";
				}
				//??¶??°????\???°???or?\???°?????¶??°???
				else if ((j+k)%2==1) {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;

}

Measured memory_bytes: 3120
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/



int main() {
int N;
ll K;
cin>>N>>K;
int A[N],below_r[N],below_all[N];
rep(i,N){
    cin>>A[i];
    below_r[i]=0;
    below_all[i]=0;
}
rep(i,N){
rep2(j,i+1,N){
    if(A[j]<A[i]){
        below_r[i]++;
    }
}
rep(j,N){
    if(A[j]<A[i]){
        below_all[i]++;
    }
}

}
ll ans=0;
rep(i,N){
    ans+=below_r[i]*K;
    ll mult= K*(K-1)/2;
    mult%=MOD;
    ans+=mult*below_all[i];
    ans%=MOD;
}
cout<<ans<<endl;

return 0;
}

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

// awal 10000 H => 
// Spell 1 : bisa mengurangi 1 H
// Spell 2 : bisa mengurangi 2 H
// dp(1, 10000) => dp(2, 9999) => dp(3, 9997)
             // => dp(2, 9998)
             // => dp(2, 9997) => dp(3, 9997)
             // => ...
             // => dp(2, 2)
             // => dp(2, 1)
             // => dp(2, 0)
            
// dp(1, 10000) => dp(1, 9999)
             // => dp(2, 10000)

// LL dp(LL pos, LL h){

//     // Cara 1 => O(N) dan lambat
//     // Milih di posisi ini, dengan health sekian, lu bisa ngambil berapa
//     // lu pasti lanjut
//     for(int i = 1;i <= n;i++){
//         ret = max(ret, dp(pos+1, h-a[pos]*i));
//         // Bercabang n kali
//     }

//     // Cara 2 => Optimized
//     // Milih di posisi ini, dengan 
//     // Bercabang 2 kali
//     max(dp(pos, h-a[pos]), dp(pos+1, h));
// }

LL ans = LLONG_MAX;
LL memo[10005];

int main(){
    LL n,h;
    cin >> h >> n;
    memset(memo,63,sizeof(memo));
    memo[0] = 0;
    // Profit maximum dengan cost = 0, 0
    // Profit maximum dengan cost = 1, -1 => belum ada kemungkinan yang
    //                                      membuat kita bisa mengambil total cost 1
    for(int i = 1;i <= n;i++){
        LL a, b; cin >> a >> b;
        for(int j = 0;j <= h;j++){
            if(memo[j] != LLONG_MAX){
                if(j+a >= h){
                    // Ga perlu distore
                    ans = min(ans, memo[j]+b);
                }else{
                    memo[j+a] = min(memo[j+a], memo[j]+b);
                }
            }
        }
    }
    // (<condition> ? <if true> : <if false>)
    // (a > b ? a : b)
    cout << ans << endl;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int la,lb,a[100010],b[100010];
void Get()
{
	int tot=0,i,j;
	for(i=1;i<=la;i++)tot+=(int)fabs(a[i]);
	for(i=1;i<=lb;i++)tot+=b[i];
	printf("%d\n",tot);
	for(i=2;i<=la;i++)
	{
		printf("%d %d\n",b[1],a[i]);
		b[1]-=a[i];
	}
	for(i=1;i<=lb-1;i++)
	{
		printf("%d %d\n",a[1],b[i]);
		a[1]-=b[i];
	}
	printf("%d %d\n",b[lb],a[1]);
}
bool cmp(int aa,int bb){return aa>bb;}
int main()
{
	int n,i,tot,x,zero=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x<0)
		{
			a[++la]=x;
		}
		else if(x>0)
		{
			b[++lb]=x;
		}
		else zero++;
	}
	sort(a+1,a+la+1,cmp);
	sort(b+1,b+lb+1);
	if(zero==n)
	{
		printf("0\n");
		for(i=1;i<n;i++)printf("0 0\n");
		return 0;
	}
	
	if(la==0)
	{
		if(zero>0){for(i=1;i<=zero;i++)a[i]=0;la=zero;}
		if(la!=0)Get();
		else
		{
			if(lb==2)
			{
				printf("%d\n",b[2]-b[1]);
				printf("%d %d",b[2],b[1]);
				return 0;
			}
			tot=0;
			for(i=2;i<=lb;i++)tot+=b[i];
			tot-=b[1];
			printf("%d\n",tot);
			printf("%d %d\n",b[1],b[2]);b[1]-=b[2];
			for(i=3;i<=n-1;i++)
			{
				printf("%d %d\n",b[1],b[i]);
				b[1]-=b[i];
			}
			printf("%d %d\n",b[n],b[1]);
		}
	}
	else if(lb==0)
	{
		if(zero>0){for(i=1;i<=zero;i++)b[i]=0;lb=zero;}
		if(lb!=0)Get();
		else
		{
			if(la==2)
			{
				printf("%d\n",a[1]-a[2]);
				printf("%d %d",a[1],a[2]);
				return 0;
			}
			tot=0;
			for(i=2;i<=la;i++)tot+=a[i];
			tot=a[1]-tot;
			printf("%d\n",tot);
			printf("%d %d\n",a[1],a[2]);a[1]-=a[2];
			for(i=3;i<=n;i++)
			{
				printf("%d %d\n",a[1],a[i]);
				a[1]-=a[i];
			}
			//printf("%d %d\n",a[n],a[1]);
		}
	}
	else
	{
		if(zero>0)
		{
			for(i=1;i<=zero;i++)a[++la]=0;
		}
		Get();
	}
	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll> a(n),hash(n);
  for(i=0;i<n;i++){cin>>a[i];a[i]-=1;}
  buf=0;
  hash[0]=1;
  while(buf!=1){
    //cout<<buf spa a[buf]<<endl;
    buf=a[buf];
    if(hash[buf]==1){
      res=-1;break;
    }
    hash[buf]=1;
    res++;
  }
  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0125
"""
import sys
from datetime import timedelta, date


def solve(data):
    y1, m1, d1, y2, m2, d2 = data
    date1 = date(y1, m1, d1)
    date2 = date(y2, m2, d2)
    delta = date2 - date1
    return delta.days


def main(args):
    while True:
        data = [int(x) for x in input().split()]
        try:
            result = solve(data)
            print(result)
        except ValueError:
            break


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8144
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int M;cin>>M;
  P(48-M);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	long long N;
	cin >> N;

	string s;
	//cin >> s;

	//int A[5]
	//sort(A, A + 5);

	N = N + (N * N) + (N * N * N);
	if (true)
	{
		cout << N << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int SumOfDegits(int n)
{
    int sum = 0;
    while (n > 0)
    {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

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

    int MIN = INT32_MAX;

    for (int i = 1; i < N; i++)
    {
        int a = i;
        int b = N - i;
        int sum = SumOfDegits(a) + SumOfDegits(b);

        if (MIN > sum)
            MIN = sum;
    }

    cout << MIN << endl;

    return 0;
}

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

#define MAX 1000000

int main(int argc, char *argv[])
{
  int prime[MAX];
  int i, j, ans, in;

  ans = 0;

  prime[0] = prime[1] = 0;
  for (i = 2; i < MAX; i++)
    prime[i] = 1;

  for (i = 2; i < MAX; i++) {
    if (prime[i] == 1) {
      ans += 1;
      if (i < sqrt(MAX)) {
	for (j = i * i; j < MAX; j+= i)
	  prime[j] = 0;
      }
    }
	prime[i] = ans;
  }

  while (scanf("%d", &in) != EOF) {
    printf("%d\n", prime[in]);
      }
  
  return 0;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int D,G;
int p[22],c[22];
signed main() {
    cin>>D>>G;
    for(int i=1;i<=D;i++)cin>>p[i]>>c[i];
    vint v;
    for(int i=1;i<=D;i++)v.push_back(i);
    int ans=LLONG_MAX;
    do {
        int cur=0,score=0;
        for(int i=0;i<D;i++){
            if(score+v[i]*100*p[v[i]]+c[v[i]]>=G){
                cur+=min(p[v[i]],(G-score)/(v[i]*100)+((G-score)%(v[i]*100)!=0?1:0));
                ans=min(ans,cur);
                break;
            }
            cur+=p[v[i]];
            score+=v[i]*100*p[v[i]]+c[v[i]];
        }
    } while (next_permutation(v.begin(), v.end()));
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    set<long long int> s;
    for(int i = 0;i < n;i++)
    {
        long long int x;
        cin >> x;
        if(s.empty() || s.find(x) == s.end())
        {
            s.insert(x);
        }
        else if(s.find(x) != s.end())
        {
            s.erase(x);
        }
    }
    cout << s.size();

    return 0;
}

Measured memory_bytes: 4864
#include<iostream>

using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int n=2,sum=0;
  while(n--){
  if(a>b){
    sum+=a;
    a--;
  }else{
    sum+=b;
    b--;
  }
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n' 

int n,k;
int it[100001];
vector<int> adj[100001];
int co=0;
int ss[100001];
int endd[100001];
vector<pair<int,int>> ss3;
int par[100001];
set<int> cur2;
int ss2[100001];
int vis[100001];
void dfs(int no,int parr=-1,int levv=0){
	ss[no]=co;
	ss2[co]=no;
	par[no]=parr;
	co++;
	//cout<<no<<":"<<endl;
	ss3.pb({levv,no});
	for(auto j:adj[no]){
		if(j!=parr){
			dfs(j,no,levv+1);
		}
	}
	endd[no]=co-1;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>it[i];
		it[i]--;
		if(i==0){
			if(it[i]!=0){
				ans+=1;
				it[i]=0;
			}
		}
		else{
			adj[it[i]].pb(i);
		}
	}
	dfs(0);
	sort(ss3.begin(),ss3.end());
	for(int i=0;i<n;i++){
		cur2.insert(i);
	}
	reverse(ss3.begin(),ss3.end());
	for(auto j:ss3){
		if(j.a<=k){
			continue;
		}
		if(vis[j.b]){
			continue;
		}
		int cur=j.b;
		for(int i=0;i<k-1;i++){
			cur=par[cur];
		}
		/*for(int i=ss[cur];i<=endd[cur];i++){
			assert(vis[ss2[i]]==0);
			vis[ss2[i]]=1;
		}*/
		auto jj=cur2.lower_bound(ss[cur]);
		vector<int> kk;
		while(true){
			if(jj==cur2.end()){
				break;
			}
			if(*jj>endd[cur]){
				break;
			}
			vis[ss2[*jj]]=1;
			kk.pb(*jj);
			jj++;
		}

		for(auto i:kk){
			cur2.erase(i);
		}
		ans+=1;
	///	cout<<j.a<<":"<<j.b<<":"<<cur<<endl;
	}
	cout<<ans;






	return 0;
}

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

using namespace std;
using u64 = std::uint_fast64_t;

template <typename T>
T gcd(T a, T b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  u64 A, B;
  cin >> A >> B;

  u64 g = gcd(A, B), res = 1;
  for (u64 i = 2; i * i < g + 1; i++) {
    if (g % i == 0) res++;
    while (g % i == 0) {
      g /= i;
    }
  }
  if (g > 1) res++;
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 380
using System;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        string[] input1 = Console.ReadLine ().Split (' ');
        long N = long.Parse (input1[0]);
        long K = long.Parse (input1[1]);

        long ans = 0;

        for (long i = K; i < N + 2; i++) {
            long temp = (i * ((N - i + 1) % 1000000007) + 1) % 1000000007;
            ans = (ans + temp) % 1000000007;
        }

        Console.WriteLine (ans);
    }
}

Measured memory_bytes: 27468
#include<stdio.h>

int main(){
	int st[30]={0},i,n;
	for(i=0;i<28;i++){
		scanf("%d",&n);
		st[n-1]=1;
	}
	for(i=0;i<30;i++)if(st[i]==0)printf("%d\n",i+1);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long   ll;
int main()
{
   string s;
   cin>>s;
   if(s=="SAT")
    cout<<1<<endl;
   else if(s=="SUN")
    cout<<7<<endl;
    else if(s=="MON")
    cout<<6<<endl;
    else if(s=="TUE")
    cout<<5<<endl;
    else if(s=="WED")
    cout<<4<<endl;
    else if(s=="THU")
    cout<<3<<endl;
    else if(s=="FRI")
    cout<<2<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

S = deque(input())
q = int(input())

reverse = False
for _ in range(q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    else:#2
        if query[1] == '1':
            if reverse:
                S.append(query[2])
            else:
                S.appendleft(query[2])
        else:
            if reverse:
                S.appendleft(query[2])
            else:
                S.append(query[2])

if reverse:
    while S:
        print(S.pop(), end='')
else:
    while S:
        print(S.popleft(), end='')

Measured memory_bytes: 12080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		long[] la = readLongs();
		long x = la[0];
		long y = la[1];
		long ans = 0;
		while (x <= y) {
			ans++;
			x *= 2;
		}
		pln(ans);
	}

	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	long abs(long a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	long max(long a, long b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	long min(long a, long b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	long readLong() {
		String line = readLine();
		return plong(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = pint(flds[i]);
		return nums;
	}

	long[] readLongs() {
		String[] flds = readFlds();
		long[] nums = new long[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = plong(flds[i]);
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void Main() {
  int n; cin >> n;
  vector<ii> a(n);
  for (auto &i : a) cin >> i.fi >> i.sc;
  sort(all(a));
  map<ii, int> mem;
  for (int i = 0; i < n - 1; i++)
  for (int j = i + 1; j < n; j++) {
    mem[ii(a[j].fi - a[i].fi, a[j].sc - a[i].sc)]++;
  }
  int ans = 0;
  for (auto &i : mem) {
    ans = max(ans, i.sc);
  }
  cout << n - ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  cerr << "- ---- -- ----- <3\n";
#endif
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int>a(n+1);
  vector<int>b(n);
  for(int i=0;i<=n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    cin>>b[i];
  }
  long long ans=0;
  for(int i=0;i<n;i++)
  {
	if(a[i]+a[i+1]<=b[i])
    {
      ans+=a[i]+a[i+1];
      a[i+1]=0;
    }
    else if(a[i]>=b[i])ans+=b[i];
    else if(a[i]+a[i+1]>b[i])
    {
      ans+=b[i];
      a[i+1]-=(b[i]-a[i]);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF INT_MIN 
#define INF INT_MAX 
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 

bool checkP(string s)
{
    int n=s.size();bool ans=true;
    for(int i=0;i<n/2;i++)if(s[i]!=s[n-i-1])ans=false;
    return ans;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<":"<<' '; 
   string s;
   cin>>s;int n=s.size();
   string s1=s.substr(0,(n-1)/2);
   string s2=s.substr((n+3)/2-1);
   if(checkP(s)&&checkP(s1)&&checkP(s2))cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   
}


return 0;
}





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

using namespace std;

int main(){
    long long q, h, s, d;
    long long n;
    scanf("%lld%lld%lld%lld",&q,&h,&s,&d);
    scanf("%lld",&n);
    h = min(2*q,h);
    s = min(2*h,s);
    d = min(2*s,d);
    printf("%lld\n",n/2*d+n%2*s);

    
    
    
}


Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    int N, K, min = 0, t=0;
    bool answer = true;
    cin >> N >> K;
    vector<char> D(K);
    for(int i = 0; i < K; i++){
        cin >> D[i];
    }
    for(int i = N;; i++){
        answer = true;
        for(int j = 0; j < to_string(i).size(); j++){
            for(int l = 0; l < K;l++){
                if(to_string(i).at(j) == D[l]){answer = false;}
            }
        }
        if(answer == true){
                cout << i << endl;
                break;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, ans;
	ans=0;
	char s[51];

	scanf("%d", &n);
	scanf("%s", s);

	for (int i = 2; i < n; ++i) {

		if (s[i - 2] == 'A' &&
			s[i - 1] == 'B' &&
			s[i] == 'C') {
			++ans;
		}
	}
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string.h>
using namespace std;

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}
int main(void){
    char str[1001];
    int i = 0, len;

    cin >> str;
    while( atoi( str ) != 0 ){
        len = strlen( str );
        for( int cnt = 0; cnt < len; cnt++ ){
            i += ctoi( str[cnt] );
        }
        cout << i << endl;
        i = 0;
        cin >> str;
    }
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

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

//cout << fixed << setprecision(10);//
//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}


//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n

ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	
	   k/=i;
	
	}

	return k;
}


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



int main() {
ll n,k;
cin>>n>>k;
ll cap[n+1];
ll f[n+1];
rep(i,n){
	cin>>cap[i];
}
rep(i, n){
	cin>>f[i];
}

ll ans=10000000000000;
sort(f+1,f+n+1);
sort(cap+1,cap+n+1,greater<ll>());

ll large=10000000000000;
ll small=0;

for(int y=1;y<=60;y++){
ll mid=(large+small)/2;
ll cost=0;
for(ll l=1;l<=n;l++){
	cost+=max((ll)0,cap[l]-mid/f[l]);
}
if(cost<=k){ans=min(ans,mid);
large=mid;
}
else{small=mid;}



}

cout<<ans<<endl;
return 0;




}




Measured memory_bytes: 3456
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define cin_desync()                                                           \
    do {                                                                       \
        ios_base::sync_with_stdio(false);                                      \
        cin.tie(0);                                                            \
    } while (0)

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int max_N = (1 << 18) + 100;
int A[max_N], F[max_N];

int main() {
    cin_desync();

    int n;
    cin >> n;

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

    for (int k = 1; k < N; ++k) {
        int b[2] = {A[0], 0};
        for (int i = k; i > 0; i = (i - 1) & k) {
            if (A[i] > b[0]) {
                b[1] = b[0];
                b[0] = A[i];
            } else if (A[i] > b[1]) {
                b[1] = A[i];
            }
        }

        F[k] = b[0] + b[1];
        F[k] = max(F[k - 1], F[k]);

        cout << F[k] << '\n';
    }
}


Measured memory_bytes: 5248
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // String S = sc.next();
        char[] S = sc.next().toCharArray();
        // String T = sc.next();
        char[] T = sc.next().toCharArray();
        int N_S = S.length;
        int N_T = T.length;
        long[] ruiseki_S = new long[N_S+1];
        long[] ruiseki_T = new long[N_T+1];
        for (int i=0;i<N_S;i++) {
            int add=0;
            if (S[i]=='A') add=1;
            else add=2;
            ruiseki_S[i+1] = ruiseki_S[i]+add;
        }
        for (int i=0;i<N_T;i++) {
            int add=0;
            if (T[i]=='A') add=1;
            else add=2;
            ruiseki_T[i+1] = ruiseki_T[i]+add;
        }
        // System.out.println(Arrays.toString(ruiseki_S));
        // System.out.println(Arrays.toString(ruiseki_T));

        int Q = sc.nextInt();
        for (int i=0;i<Q;i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());
            int d = Integer.parseInt(sc.next());
            // System.out.println(((ruiseki_S[b]-ruiseki_S[a-1])-(ruiseki_T[d]-ruiseki_T[c-1]))%3);
            if (((ruiseki_S[b]-ruiseki_S[a-1])-(ruiseki_T[d]-ruiseki_T[c-1]))%3==0) System.out.println("YES");
            else System.out.println("NO");
        }
    }
}

Measured memory_bytes: 98412
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;


ll tableF[200010];
ll tableI[200010];

ll modfact(ll a,ll m){
   if(tableF[a] != -1){
      return tableF[a];
   }
   if(a == 1){
      tableF[a] = 1;
      return tableF[a];
   }
   ll res = 1;
   res = a * modfact(a-1,m);
   res %= m;
   tableF[a] = res;
   return res;
}

ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a,ll p){//modinv(a,p) := pを法とするaの逆元(※pは素数でなければならない)
    ll res = modpow(a,p-2,p);
    return res;
}

ll modCON(ll n,ll r,ll m){
   if(n < 200010){
   ll res = 1;
   if(n < 0 || r < 0 || n < r){
      return 0;
   }
   res *= tableF[n];
   res %= m;
   res *= tableI[r];
   res %= m;
   res *= tableI[n-r];
   res %= m;
   return res;
   }else{
   ll res = 1;//tableを持ってないときよう
   for(int i = 1;i <= n;i++){
      res *= i;
      res %= m;
   }
   for(int i = 1;i <= r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   for(int i = 1;i <= n-r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   return res;
   }
}

void modfill(ll m){//忘れない　約200ms
   fill(tableF,tableF+200010,-1);
   fill(tableI,tableI+200010,-1);
   tableF[0] = 1;
   tableI[0] = 1;
   for(int i = 1;i < 200010;i++){
      tableF[i] = modfact(i,m);
      tableI[i] = modinv(tableF[i],m);
   }
}


int main(){
   ll N,K;
   cin >> N >> K;
   modfill(MOD);
   ll ans = 1;
   FOR(i,1,min(N,K)+1){
      ll A = modCON(N,i,MOD);
      ll B = modCON(N-1,i,MOD);
      ll C = A * B;
      C %= MOD;
      ans += C;
      ans %= MOD;
   }
   cout << ans << endl;
}


Measured memory_bytes: 3456