akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string S;
  int ma=0,N=0,cn=0;
  cin >> N;
  cin >> S;
  for(int i=0;i<N;i++){
    ma = max(ma,cn);
    if(S[i] == 'I')
      cn++;
    else
      cn--;
    ma = max(ma,cn);
  }
  cout << ma << endl;
  return 0;  
}



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

using namespace std;

int main()
{
    long long n,a,b,c;
    cin>>n>>a>>b>>c;
    vector<string>ans;
    vector<string>inp(n);
    int f=0;
    for(int i=0;i<n;i++)
        cin>>inp[i];
    for(int i=0;i<n;i++){
        string in=inp[i];
        if(in=="AB"){
            if(a==0&&b==0){
                f=1;
                break;
            }
            if(a==1&&b==1){
                if(i+1<n&&inp[i+1]=="AC"){
                        ans.push_back("A");
                        a++;
                        b--;
                }else{
                    ans.push_back("B");
                    a--;
                    b++;

                }
                continue;
            }
            if(a>=b){
                ans.push_back("B");
                a--;
                b++;
            }else{
                ans.push_back("A");
                a++;
                b--;
            }
        }else if(in=="AC"){
            if(a==0&&c==0){
                f=1;
                break;
            }

            if(a==1&&c==1){
                if(i+1<n&&inp[i+1]=="AB"){
                        ans.push_back("A");
                        a++;
                        c--;
                }else{
                    ans.push_back("C");
                    a--;
                    c++;

                }
                continue;
            }
            if(a>=c){
                ans.push_back("C");
                a--;
                c++;
            }else{
                ans.push_back("A");
                a++;
                c--;
            }

        }else{
            if(b==0&&c==0){
                f=1;
                break;
            }
            if(b==1&&c==1){
                if(i+1<n&&inp[i+1]=="AB"){
                        ans.push_back("B");
                        c--;
                        b++;
                }else{
                    ans.push_back("C");
                    c++;
                    b--;

                }
                continue;
            }
            if(b>=c){
                ans.push_back("C");
                b--;
                c++;
            }else{
                ans.push_back("B");
                b++;
                c--;
            }
        }
    }
    if(f)
    cout << "No" << endl;
    else{
    cout << "Yes" << endl;
    for(int i=0;i<n;i++)
    cout << ans[i]<< endl;
    }
    return 0;
}
/***
32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

6
2 3 3 1 3 1
*/


Measured memory_bytes: 10572
c[];main(n,m,i,j,k,f){for(;scanf("%d%d",&n,&m)*n;printf(f,j>m?i:j)){for(i=3;i--;)for(scanf(f="%d\n",&j);j--;c[n-k]=i)scanf(f,&k);for(i=n;i--;k+=c[i])j-=pow(3,i)*abs(k*2%4-c[i]);j=fmin(~j,pow(3,n)+j);}}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	map<int, int> mp1;
	vector<int> X;
	for (int i = 0; i < N; i += 2) {
		mp1[A[i]]++;
	}
	int mx = -1;
	int mi;
	for (auto m : mp1) {
		//cerr << m.first << " " << m.second << endl;
		X.push_back(m.second);
		if (mx < m.second) {
			mx = m.second;
			mi = m.first;
		}
	}
	sort(X.begin(), X.end());
	map<int, int> mp2;
	for (int i = 1; i < N; i += 2) {
		mp2[A[i]]++;
	}
	int res = (int)1 << 60;
	//cerr << mi << endl;
	for (auto m : mp2) {
		if (mi == m.first) {
			if ((int)X.size() == 1) {
				res = min(res, N - m.second);
			}
			else {
				//cerr << "ok" << endl;
				//cerr << m.second << " " << X[(int)X.size() - 2] << endl;
				res = min(res, N - m.second - X[(int)X.size() - 2]);
			}
		}
		else {
			res = min(res, N - m.second - X.back());
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 7676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	int a[n + 1];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if(a[a[i]]==i){cnt++;}
	}
	cout << cnt/2 << endl;
}

Measured memory_bytes: 640
import std.stdio;
import std.conv;
import std.string;

void main() {
    auto n = readln.chomp.to!(ulong);
    auto v = readln.chomp.split.to!(ulong[]);
    ulong ans = 0;

    ulong[string] v1;
    ulong[string] v2;
    foreach(i, e; v) {
        auto j = e.to!string;
        if (i % 2) {
            if (j in v2)
                v2[j]++;
            else
                v2[j] = 1;
        } else {
            if (j in v1)
                v1[j]++;
            else
                v1[j] = 1;
        }
    }

    ulong max = 0;
    auto m1 = "0";
    auto m2 = "0";
    auto m1_2 = "0";
    auto m2_2 = "0";
    foreach(i; v1.keys){
        ans += v1[i];
        if (v1[i] >= max) {
            max = v1[i];
            m1_2 = m1;
            m1 = i;
        }
    }

    max = 0;
    foreach(i; v2.keys){
        ans += v2[i];
        if (v2[i] >= max) {
            max = v2[i];
            m2_2 = m2;
            m2 = i;
        }
    }

    if(m1 != m2) {
        ans -= v1[m1];
        ans -= v2[m2];
    } else {
        if (v1[m1] > v2[m2]) {
            ans -= v1[m1];
            if (m2_2 != "0")
                ans -= v2[m2_2];
        } else if (v1[m1] < v2[m2]) {
            ans -= v2[m2];
            if (m1_2 != "0")
                ans -= v1[m1_2];
        } else {
            if (m1_2 == "0" || m2_2 == "0") {
                ans -= v1[m1];
            } else {
                if (v1[m1_2] > v2[m2_2]) {
                    ans -= v1[m1_2];
                    ans -= v2[m2];
                } else {
                    ans -= v1[m1];
                    ans -= v2[m2_2];
                }
            }
        }
    }

    ans.writeln;
}


Measured memory_bytes: 16832
#include<stdio.h>


int main()
{
	long n,i;
	long k = 0;
	long t = 0;
	long long a;
	scanf("%ld", &n);
	for (i = 0; i < n; i++) {
		scanf("%lld", &a);
		if (a % 2 == 1)
			k++;
		if (a % 4 == 0)
			t++;
	}
	if (t >= k) {
		printf("Yes");
	}
	else if (n % 2 == 1 && k + t == n&&k - 1 == t) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();//n回
        int b = sc.nextInt();//何番目

        if(b!=100)
            System.out.println((int)Math.pow(100,a) * b);
        else
            System.out.println((int)Math.pow(100,a) * (b+1));
    }
}


Measured memory_bytes: 23764
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int memo[201][201];

ll gcd(ll a, ll b) {
    if (a > b) {
        swap(a, b);
    }
    if (memo[a][b] != 0) {
        return memo[a][b];
    }

    while (true) {
        if (a < b) swap(a, b);
        if (b == 0) {
            break;
        }
        a %= b;
    }
    memo[a][b] = a;
    return a;
}

int main(void) {
    memset(memo, 0, sizeof(memo));
    int K;
    cin >> K;
    ll ans = 0;
    FOR (a, 1, K + 1) {
        FOR (b, 1, K + 1) {
            FOR (c, 1, K + 1) {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3336
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n][n];
for(int i=0;i<n;i++)
{
    for(int j=0;j<n-1;j++)
    {
        cin>>arr[i][j];
       arr[i][j]-=1;
    }
}
int dp[n+1]={};
int ans=0;
while(1)
{int jarorat[n]={};
int vis[n]={};
    for(int j=0;j<n;j++)
    {
        int x=dp[j];
        if(x!=n-1)
        jarorat[j]=(arr[j][x]);
        else
            vis[j]=1;
    }

    int cnt=0;
    for(int j=0;j<n;j++)
    {
        if(jarorat[jarorat[j]]==j&&vis[j]==0&&vis[jarorat[jarorat[j]]]==0)
        {
            dp[j]++;
            dp[jarorat[j]]++;
            vis[j]=1;
            vis[jarorat[j]]=1;
            cnt++;
        }
    }
    if(cnt==0)
        break;
        
    ans++;
}

for(int i=0;i<n;i++)
{
    if(dp[i]!=n-1)
    {
        cout<<-1<<endl;
        return 0;
    }
}
cout<<ans<<endl;
























    return 0;
}


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

XY = []
for _ in range(N):
    A = int(input())

    temp = []
    for _ in range(A):
        temp.append(list(map(int, input().split())))

    XY.append(temp)


max_honest = 0
for c in range(1 << N):
    check = [0] * N
    contradict = False
    temp = c

    cnt2 = 0
    while temp != 0:
        if 1 & temp:
            check[cnt2] = 1

        temp >>= 1
        cnt2 += 1

    for i in range(N):
        if check[i] == 1:
            for x, y in XY[i]:
                if check[x - 1] != y:
                    contradict = True
                    break

            if contradict:
                break

    if not contradict:
        cnt1 = 0
        for i in range(N):
            if check[i] is not None and check[i] == 1:
                cnt1 += 1

        max_honest = max(max_honest, cnt1)


print(max_honest)


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	string s, t;
	cin >> s >> t;

	Int lens = s.size();
	Int lent = t.size();
	
	Int flag = 0;
	if (lens==lent) {
		for (Int i = 0; i < lens; i++) {
			string temp = "";
			for (Int j = i; j < lens; j++) {
				temp += s[j];
			}
			for (Int j = 0; j < i; j++) {
				temp += s[j];
			}
			if (temp==t) {
				flag = 1;
			}
		}
	}
	if (flag) cout << "Yes" << "\n";
	else cout << "No" << "\n";

}


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

int main() {
  int N,X,Y;

  cin >> N >> X >> Y;
  X--;
  Y--;
  int val;
  vector<int> ans(N);

  for ( int i=0 ; i < N - 1 ; ++i ) {
    for ( int j=i+1 ; j < N ; ++j ) {
      val = min(j-i,abs(X-i)+1+abs(j-Y));
      ans[val]++; 
    }
  }
  for ( int i=1 ; i < N ; ++i ) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
#n = int(input())
a, v = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))
     

b, w = map(int, sys.stdin.readline().split())
t = int(input())


x = v - w
if x == 0:
    print("NO")
    sys.exit()
y = abs(b-a) / x

if y < 0:
    print("NO")
else:
    if y <= t:
        print("YES")
    else:
        print("NO")




















Measured memory_bytes: 10036
N=int(input())
S=list(input())
l=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
for i in range(len(S)):
  for L in l:
    if S[i]==L:
      S[i]=l[(l.index(L)+N)%len(l)]
      break
print("".join(S))

Measured memory_bytes: 3060
*H,=map(int,open(0).read().split());N=H[0];A=H[1:N+1]+[0];B=H[N+1:2*N+1];C=H[-N+1:];a=i=0
while i<N:
    a+=B[i]
    if A[i+1]-A[i]==1:a+=C[A[i]-1]
    i+=1
print(a)


Measured memory_bytes: 3060
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll N,W;cin>>N>>W;
    ll w[110];
    ll v[110];
    REP(i,N)cin>>w[i]>>v[i];
    //ll dp[110][110000]={};
    vector<vi> dp(110,vi(110000,0));
    REP(i,N){
        REPS(j,W){
            if(w[i]<=j){
                dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            }
            dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
        }
    }
    cout<<dp[N][W]<<"\n";
}

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

int main() {
    string s, a;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0' || s[i] == '1') a += s[i];
        else if (a.size() > 0 && s[i] == 'B') a.pop_back();
    }
    cout << a << endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;
    int sum = 0;
    rep(i, s.size())
    {
        sum += s[i] - '0';
    }

    if (stoi(s) % sum == 0)
        OP("Yes");
    else
        OP("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
using ll = long long;
using P = pair<ll, ll>;

const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void fail() {
    cout << -1 << endl;
    exit(0);
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    for(ll i=0; i < n; i++) cin >> a[i];
    vector<ll> s(n+1, 0);

    for(ll i=1; i <= n; i++){
        s[i] = s[i-1] + a[i-1];
    }

    ll ans = 0, pre = -10000000000000, cnt = 1;
    sort(s.begin(), s.end());
    for(ll i=0; i <= n; i++){
        if(pre == s[i]){
            cnt += 1;
        }else{
            ans += (cnt * (cnt - 1) / 2);
            cnt = 1;
            pre = s[i];
        }
    }
    ans += (cnt * (cnt - 1) / 2);
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main()
{
	int i, j, N, M, a[1001], b[1001], c[1001][13];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) {
		scanf("%d %d", &(a[i]), &(b[i]));
		for (j = 1; j <= b[i]; j++) scanf("%d", &(c[i][j]));
	}
	
	int k, dp[2][4096], bit[13] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096}, key, tmp;
	for (i = 0; i < bit[N]; i++) dp[0][i] = 1 << 30;
	dp[0][0] = 0;
	for (i = 1; i <= M; i++) {
		for (j = 1, key = 0; j <= b[i]; j++) key |= bit[c[i][j]-1];
		for (j = 0; j < bit[N]; j++) dp[i%2][j] = dp[1-i%2][j];
		for (j = 0; j < bit[N]; j++) if (dp[i%2][j|key] > dp[0][j] + a[i]) dp[i%2][j|key] = dp[1-i%2][j] + a[i];
	}

	if (dp[M%2][bit[N]-1] < 1 << 30) printf("%d\n", dp[M%2][bit[N]-1]);
	else printf("-1\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
long long a,b,k;
int main()
{
    cin>>a>>b>>k;
    if(k>=a){k-=a;a=0;}
    else {a-=k;k=0; }
    //cout<<"a="<<a<<"  b="<<b<<"  k="<<k<<endl;
    if(k>=b){k-=b;b=0;}
    else {b-=k;k=0;}
    cout<<a<<" "<<b;puts("");
    //cout<<"a="<<a<<"  b="<<b<<"  k="<<k<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, a, b = map(int, readline().split())
if a > b:
    print(0)
elif n == 1:
    if a != b:
        print(0)
    else:
        print(1)
else:
    print(a + b * (n - 1) - (b + a * (n - 1)) + 1)


Measured memory_bytes: 2940
# n = gets.chomp.to_i
$n, $m, $q = gets.chomp.split(" ").map(&:to_i)
$a = []
$b = []
$c = []
$d = []
score = 0
$max = 0
now = 0
$q.times do |i|
  $a[i], $b[i], $c[i], $d[i] = gets.chomp.split(" ").map(&:to_i)
end
$tmp = []
$n.times do |i|
  $tmp[i+1] = 1
end

def calc
  score=0
  $q.times do |i|
    score += $d[i] if $tmp[$b[i]]-$tmp[$a[i]] == $c[i]
  end
  $max = $max>score ? $max : score
end


1.upto($m) do |i|
  $tmp[1] = i
  if $n==1
    calc
    next
  end
  i.upto($m) do |j|
    $tmp[2] = j
    if $n==2
      calc
      next
    end
    j.upto($m) do |k|
      $tmp[3] = k
      if $n==3
        calc
        next
      end
      k.upto($m) do |l|
        $tmp[4] = l
        if $n==4
          calc
          next
        end
        l.upto($m) do |m|
          $tmp[5] = m
          if $n==5
            calc
            next
          end
          m.upto($m) do |n|
            $tmp[6] = n
            if $n==6
              calc
              next
            end
            n.upto($m) do |o|
              $tmp[7] = o
              if $n==7
                calc
                next
              end
              o.upto($m) do |p|
                $tmp[8] = p
                if $n==8
                  calc
                  next
                end
                p.upto($m) do |q|
                  $tmp[9] = q
                  if $n==9
                    calc
                    next
                  end
                  q.upto($m) do |r|
                    $tmp[10] = r
                    if $n==10
                      calc
                      next
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

puts $max

Measured memory_bytes: 14180
"use strict"
function Main(input) {
  input = input.trim().split(' ').map(Number);
  const A = input[0];
  const B = input[1];
  const C = input[2];

  let ret = 'No';

  if(A === B && A !== C){
    ret = 'Yes';
  } else if ( A === C && A !== B){
    ret = 'Yes';
  }  else if ( B === C && B !== A){
    ret = 'Yes';
  }

  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	const int mod = 1e9 + 7;
	cin.tie(0); cin.sync_with_stdio(0);
	int n, k; cin >> n >> k;
	
	vi dp(k + 1);
	dp[k] = 1;
	rep(i, n){
		int a; cin >> a;
		vi next(k + 1);
		for(int j = k, p = 0; j >= 0; j--){
			next[j] = ((next[j] + dp[j]) % mod + p) % mod;
			p = next[j];
			if(j > a) next[j - a - 1] = (next[j - a - 1] + mod - dp[j]) % mod;
		}
		dp = next;
	}
	cout << dp[0] << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 1010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, c, d, ans;
ll F[MAXN], I[MAXN];
ll dp[MAXN][MAXN];
ll C[MAXN][MAXN];

ll powmod(ll a, ll b){
	ll res=1;
	for (; b; b>>=1, a=a*a%mod) if (b&1) res=res*a%mod;
	return res;
}

ll count(ll n, ll k){ // n*k nafar   k group
	ll res=F[n*k]*powmod(I[n], k)%mod;
	return res*I[k]%mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	F[0]=1;
	for (int i=1; i<MAXN; i++) F[i]=F[i-1]*i%mod;
	I[MAXN-1]=powmod(F[MAXN-1], mod-2);
	for (int i=MAXN-1; i; i--) I[i-1]=I[i]*i%mod;
	
	for (int i=0; i<MAXN; i++){
		C[i][0]=C[i][i]=1;
		for (int j=1; j<i; j++) C[i][j]=(C[i-1][j] + C[i-1][j-1])%mod;
	}
	cin>>n>>a>>b>>c>>d;
	
	for (int i=0; i<MAXN; i++) dp[0][i]=1;
	for (int i=1; i<=n; i++){
		for (int j=1; j<=b; j++){
			dp[i][j]=dp[i][j-1];
			if (a<=j) for (int t=c; t<=d && t*j<=i; t++) dp[i][j]=(dp[i][j] + dp[i-t*j][j-1]*C[i][t*j]%mod*count(j, t))%mod;
		}
	}
	
	ans=dp[n][b]%mod;
	if (ans<0) ans+=mod;
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 15360
#import re
n = int(input())
s = input()
ans = 1

for i in range(1,len(s)):
  if s[i] != s[i-1]:
    ans += 1

print(ans)

# またはa-zまで正規表現をかます
# for i in range(26):
#   ans = re.sub("([a-z])\\1","\\1",ans)
# print(len(ans))


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, t, a[200010];
	cin >> n >> t;
	ll ans = t;
	cin >> a[0];
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		ans += min(t, a[i] - a[i - 1]);
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a==b)
    {
        cout << "Draw\n";
    }
    else if(b==1 || (a!=1 && a<b))
    {
        cout << "Bob\n";
    }
    else
    {
        cout << "Alice\n";
    }

    return 0;
}

Measured memory_bytes: 3648
w,h,n = map(int, input().split())
x1,y1 = 0, 0
x2, y2 = w, h
for i in range(n):
    x,y,a = map(int, input().split())
    if a == 1:
        x1 = max(x1, x)
    elif a == 2:
        x2 = min(x2, x)
    elif a == 3:
        y1 = max(y1, y)
    elif a == 4:
        y2 = min(y2, y)

if (x2 - x1 < 0) or (y2 - y1 < 0):
    print(0)
else:
    print(max((x2 - x1) * (y2 - y1), 0))

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

int main(){
int a,b;
  cin >> a >> b;
  if(a+b == 3){cout << 3 << endl;}
  else if(a+b == 4){cout << 2 << endl;}
  else if(a+b == 5){cout << 1 << endl;}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
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; }
const long long INF = 1LL<<60;

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 81620
#include<algorithm>
#include<iostream>
#include<stdio.h>
typedef long long ll;
using namespace std;

const ll mod = 998244353;
const ll inv2 = (mod + 1) >> 1;
ll poww(ll a, ll b){
	ll res = 1;
	while (b){
		if (b & 1) res = res * a % mod;
		a = a*a%mod;
		b >>= 1;
	}
	return res;
}

int n, s;
int a[3005];
ll c[3005];
int main(){
	cin >> n >> s;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		c[i] = 0;
	}
	c[0] = poww(2, n);
	for (int i = 1; i <= n; i++){
		for (int j = 3000 - a[i]; j >= 0; j--){
			c[j + a[i]] = (c[j + a[i]] + c[j]*inv2) % mod;
		}
		continue;
	}
	cout << c[s] << endl;
	return 0;
}


Measured memory_bytes: 3672
from collections import deque

d=deque()

A=input().split()

for n in range(len(A)):
    if A[n]=='+':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b+a))
    elif A[n]=='-':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b-a))
    elif A[n]=='*':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b*a))
    else:
        d.append(int(A[n]))
        
print(int(d.pop()))


Measured memory_bytes: 6000
import java.util.*;
    public class Main{
    	public static void main(String[] args){
    		Scanner sc=new Scanner(System.in);
    		int h=sc.nextInt();
    		int w=sc.nextInt();
    		int[][] a=new int[h+1][w+1];
    		int[][] b=new int[h+1][w+1];
    		for(int i=1; i<=h; i++){
    			for(int j=1; j<=w; j++){
    				a[i][j]=sc.nextInt();
    			}
    		}
    		for(int i=1; i<=h; i++){
    			for(int j=1; j<=w; j++){
    				b[i][j]=sc.nextInt();
    			}
    		}
    		boolean[][][] dp=new boolean[h+1][w+1][160*80];
    		dp[1][1][Math.abs(a[1][1]-b[1][1])]=true;
    		for(int j=1; j<=h; j++){
    			for(int t=1; t<=w; t++){
    				int k1=Math.abs(a[j][t]-b[j][t]);
    				for(int i=0; i<160*80; i++){
    					if(j-1>=1 && dp[j-1][t][i]){
    						dp[j][t][Math.abs(i-k1)]=true;
    						dp[j][t][i+k1]=true;
    					}else if(t-1>=1 && dp[j][t-1][i]){
    						dp[j][t][Math.abs(i-k1)]=true;
    						dp[j][t][i+k1]=true;
    					}
    				}
    			}
    		}
    		for(int i=0; i<160*80; i++){
    			if(dp[h][w][i]){
    				System.out.println(i);
    				break;
    			}
    		}
    	}
    }

Measured memory_bytes: 156276
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
  int n;
  int a[10];
  cin>>n;
  for(int i=0;i<n;i++){
	cin>>a[i];
  }
  int s=0;
  for(int i=0;i<n;i++){
	if(s<a[i])
      s=a[i];
  }
  s=-s/2;
  for(int i=0;i<n;i++){
    s+=a[i];
  }
  cout <<s<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define pb push_back
#define Never
#define To

using namespace std;

int main(){

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

	long long N, M;

	cin >> N >> M;

	long long A[N];

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

	for(long long m = 0; m < M; m++){ 
		sort(A, A+N);
		A[N-1] /= 2;
		long long mm;
		for(mm = 0; mm + m < M-1; mm++){
			if(N - 2 -mm < 0) break;
			if(A[N-1] <= A[N-2-mm]) {
				A[N-2-mm] /= 2;
			} else {
				break;
			}
		}
		m += mm;
	}

	long long ans = 0;
	for(long n = 0; n < N; n++){
		ans += A[n];
	}

	cout << ans << endl;

	Never To return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
int N, M;
pair<int, int> times[200];
int main()
{
	cin >> N;
	for(int i = 0; i < N; i++)
		cin >> times[i].F >> times[i].S;
	cin >> M;
	for(int i = N; i < N + M; i++)
		cin >> times[i].F >> times[i].S;
	sort(times, times + N + M);
	for(int i = 0; i < N + M; i++)
	{
		if(i == N + M - 1 || times[i] != times[i + 1])
		{
			cout << times[i].F << ":";
			if(times[i].S < 10)
				cout << 0;
			cout << times[i].S;
			if(i != N + M - 1)
				cout << " ";
		}
	}
	cout << endl;
}

Measured memory_bytes: 3124
#include <stdio.h>

int main(void){

    int a, b;

    scanf("%d %d", &a, &b);

    if (a < b){
        printf("a < b\n");
    }else if (a > b){
        printf("a > b\n");
    }else {
        printf("a == b\n");
    }

    return 0 ;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>v;
    vector<int>v2;
    
    //偶数、奇数番目で配列を分ける
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        if(i%2==0) v.push_back(k);
        else v2.push_back(k);
    }
    //ソートする　
    sort(v.begin(),v.end());
    sort(v2.begin(),v2.end());
    v.push_back(0);
    v2.push_back(0);
    int count=1;

    vector<pair<int,int> >pair2;
    vector<pair<int,int> >pair;


    //個数数えてペアにする
    for(int i=0;i<v.size()-1;i++){
        if(v[i]==v[i+1]) count++;
            else {
                pair.push_back(make_pair(count,v[i]));
                count=1;
            }
    }

    for(int i=0;i<v2.size()-1;i++){
        if(v2[i]==v2[i+1]) count++;
            else {
                pair2.push_back(make_pair(count,v2[i]));
                count=1;
            }
    }

    sort(pair.begin(),pair.end());
    sort(pair2.begin(),pair2.end());
    reverse(pair.begin(),pair.end());
    reverse(pair2.begin(),pair2.end());
    int x1=pair[0].first;
    int x2=pair2[0].first;
    int y1,y2;
    if(pair.size()>=2) y1=pair[1].first;
    else y1=-10000000;
    if(pair2.size()>=2) y2=pair2[1].first;
    else y2=-10000000;
        
    bool boo = false;
    int s,t;
    for(int i=0;i<v.size()-2;i++){
        if(v[i]!=v[i+1]) boo=true;
        s=v[i];
    }
    for(int i=0;i<v2.size()-2;i++){
        if(v2[i]!=v2[i+1]) boo=true;
        t=v2[i];
    }
    if(s!=t) boo=true;
    
    if(!boo)cout<<n/2<<endl;
    else if(pair[0].second==pair2[0].second)cout<<min(n-x1-y2,n-x2-y1)<<endl;
    else cout<<n-x1-x2<<endl;

}
   
    

    




Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N, T; cin>>N>>T;
  vector<int> a;
  REP(i,N) {
    int c, t; cin>>c>>t;
    if(t <= T) a.push_back(c);
  }
  if(a.empty()) {
    cout << "TLE" << endl;
  } else {
    sort(a.begin(), a.end());
    cout << a[0] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,c=0;
    char s[4],t[4];
    scanf("%s%s",s,t);
    for(i=0;i<3;i++)
        if(s[i]==t[i])
        c++;
    printf("%d\n",c);
    return 0;

}


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

int main(){
  string S;
  cin >> S;
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int cmpfunc (const void * a, const void * b)
{
    return ( ((long long int*)a)[0] - ((long long int*)b)[0] );
}
int main(void){
    
    int n=0,i;
    long long int money=0,m=0;
    scanf("%d %lld",&n,&m);
    long long int a[n][2];
    
    for(i=0;i<n;i++){
        scanf("%lld %lld",&a[i][0],&a[i][1]);
    }
    
    qsort(a,n,sizeof(long long int)*2,cmpfunc);
    
    
    
    for(int i=0;i<n;i++){
        if(m-a[i][1]>0){
            money = money + a[i][0]*a[i][1];
            m = m-a[i][1];
        }else{
            money = money + m*a[i][0];
            printf("%lld\n",money);
            break;
        }
    }
  
    system("pause");
    return 0;
    
}


Measured memory_bytes: 3324
import java.util.Scanner;

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

    long M = 1_000_000_007;
    int n = scanner.nextInt();
    int a = scanner.nextInt();
    int b = scanner.nextInt();

    long res = modpow(2, n, M) - 1;
    if (res < 0) res += M;
    res -= choose(n, a, M);
    if (res < 0) res += M;
    res -= choose(n, b, M);
    if (res < 0) res += M;
    System.out.println(res);
  }

  public static long choose(long n, long k, long mod) {
    if (k > n - k) return choose(n, n - k, mod);
    long res = 1;
    for (int i = 0; i < k; i++) {
      res = (res * (n - i)) % mod;
    }
    for (int i = 1; i <= k; i++) {
      res = (res * inverse(i, mod)) % mod;
    }
    return res % mod;
  }

  private static long inverse(long a, long mod) {
    return modpow(a, mod - 2, mod);
  }

  private static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }
}


Measured memory_bytes: 23252
a,b,c,x,y= map(int ,input().split())
h=max(x,y)
k=min(x,y)
j=h-k
if a+b>(c*2):
        i=k*(c*2)
        if h==x:
                l=j*2*c
                print(min(l,(j*a))+i)
        else:
                l=j*2*c
                print(min(l,(j*b))+i)     
else:
        print((a*x)+(b*y))

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
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();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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 main(void){
    int K,X; cin >> K >> X;
    cout << (500*K >= X ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char a[10000+10][10000+10];
int wi[8]={1,1,0,-1,-1,-1,0,1};
int wj[8]={0,-1,-1,-1,0,1,1,1};
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
    {
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
    }
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='#')
				cout<<'#';
			else
			{
				int num=0;
				for(int m=0;m<8;m++)
				{
					if(a[i][j]!='.')
						continue;
					if(a[i+wi[m]][j+wj[m]]=='#')
						num++;
				}
			cout<<num;
			}
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
int main(){
  int n;
  cin>>n;
  cout<<"ABC";
  cout<<n;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

template<class T>
void show_1d_vector(const vector<T> &v){
    for(auto v1: v) {
        cout << v1 << " ";
    }
    cout << endl;
}


vector<ll> a;

bool isOK(ll m, ll v, ll p, ll mid) {
    vector<ll> b = a;
    ll cost = m*v;
    b[mid] += m;
    ll lim = b[mid];
    cost -= m;
    for(int i = 0; i < p-1; i++){
        b[i] += m;
        cost -= m;
    }

    for(int i = b.size()-1; i > mid; i--){
        b[i] += m;
        cost -= m;
    }
    for(int i = p-1; i < mid; i++){
        cost -= max(min(m, lim-b[i]),0LL);
        b[i] += max(min(m, lim-b[i]),0LL);
    }
    //dbg(mid);dbg(cost);
    //show_1d_vector(b);
    if(cost<=0 && b[p-1]<=b[mid]){
        return true;
    }else{
        return false;
    }
}

int main(){
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    a.resize(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(all(a));
    reverse(all(a));
    //show_1d_vector(a);
    ll ng = n;
    ll ok = p-1;

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isOK(m, v, p, mid)) ok = mid;
        else ng = mid;
    }

    cout << ok+1 << endl;

    return 0;
}


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

 int main() {
     int N;
     cin >> N;
     ll res = 0;
     vector<vector<ll>> num(10, vector<ll>(10, 0));
     for (int n = 1; n <= N; n++) {
         vector<int> d;
         int nn = n;
         while (nn) {
             d.push_back(nn % 10);
             nn /= 10;
         }
         int a = d.at(0);
         int b = d.back();
         if (!a || !b) continue;
         num.at(a).at(b)++;
     }
     for (int a = 1; a < 10; a++) {
         for (int b = 1; b < 10; b++) {
             res += num.at(a).at(b) * num.at(b).at(a);
         }
     }
     cout << res << endl;
 }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		int a = stdin.nextInt();
		int b = stdin.nextInt();
		if(b%a==0) {
			System.out.println(a+b);
		}else {
			System.out.println(b-a);
		}


	}

}


Measured memory_bytes: 23764
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll A,B,K;
  cin >> A >> B >> K;
  if(K >= A + B){ 
    A = 0;
    B = 0;
  }
  else if(K >= A){
    B = A+B-K;
    A = 0;
  }
  else{
    A = A-K;
  }
  cout << A << " " << B;
}


Measured memory_bytes: 256
a = 2, 3, 5

def f(n):
  m = memo.get(n)
  if m is None:
    m = d * n
    for p, c in zip(a, b):
      k, r = divmod(n, p);
      m = min(m, f(k) + r * d + c, r  and f(k + 1) + (p - r) * d + c or m)
    memo[n] = m
  return m

t = int(input())
for _ in range(t):
  n, *b, d = map(int, input().split())
  memo = {0: 0, 1: d}
  print(f(n))


Measured memory_bytes: 10960
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>


using namespace std;
typedef long long LL;

int main(void) {
	int N, ans = 0;

	cin >> N;
	if (N % 2 == 0) {
		ans = N;
	}
	else {
		ans = N * 2;
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> l(n), r(n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
    ans = max(ans, r[i] - l[i] + 1);
  }                
  int mxl = l[0], mnr = r[0];
  for (int i = 0; i < n; ++i) {
    mxl = max(mxl, l[i]);
    mnr = min(mnr, r[i]);
  }
  for (int i = 0; i < n; ++i) {
    ans = max(ans, r[i] - l[i] + 1 + mnr - mxl + 1);
  }
  vector <pair <int, int>> have;
  for (int i = 0; i < n; ++i) {
    have.push_back({l[i], r[i]});
  }
  sort(have.begin(), have.end());
  vector <int> mn(n + 1);
  mn[n] = 1e9;
  for (int i = n - 1; i >= 0; --i) {
    mn[i] = min(mn[i + 1], have[i].second);;
  }
  for (int i = 0; i + 1 < n; ++i) {
    ans = max(ans, mnr - have[i].first + 1 + mn[i + 1] - mxl + 1);
  }
  cout << ans << '\n';
}



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

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

using namespace std;

int main(){
	int a,b,k; scanf("%d%d%d",&k,&a,&b);
	puts(b/k-(a-1)/k>0?"OK":"NG");
	return 0;
}


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N;
int dp[100010];
int X[] = { 1, 6, 6*6, 6*6*6, 6*6*6*6, 6*6*6*6*6, 6*6*6*6*6*6,
			9, 9*9, 9*9*9, 9*9*9*9, 9*9*9*9*9 };

int check(int zan) {
//    cout << "zan = " << zan << endl;
    if(zan == 0)        return 0;
	if(dp[zan] != -1)	return dp[zan];
	
	int min = 100001;
	int cnt;
	for(int i = 0; i < sizeof(X)/sizeof(int); i++) {
	    if(zan >= X[i]) {
    		cnt = check(zan - X[i]) + 1;
    		if(min > cnt)	min = cnt;
	    }
	}
//	cout << "zan = " << zan << " min = " << min << endl;
	dp[zan] = min;
	return min;
}

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

	cin >> N;

	memset(dp, -1, sizeof(dp));
	sort(X, X + sizeof(X)/sizeof(int), greater<int>());

	cout << check(N) << endl;
	
	return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int m,nmi,nma;
    cin >> m >> nmi >> nma;
    if(m==0) return 0;
    vector<int> a(m);
    for(int i=0;i<m;i++) cin >> a[i];
    sort(all(a),greater<int>());
    int ans=0,k=0;
    for(int i=nmi-1;i<=nma-1;i++){
      if(ans<=a[i]-a[i+1]){
        ans=a[i]-a[i+1];
        k=i;
        // cout << ans << endl;
      }
    }
    cout << k+1 << endl;
  }
  return 0;
}



Measured memory_bytes: 3024
import Data.Char

main = do
  (a:b:_) <- getLine >>= return . (map read) . words :: IO [Int]
  p <- getLine

  putStrLn $ func p a
  
  where
    func xs t = if h=='-' && isNum a && isNum b then "Yes" else "No"
      where
        (a,b') = splitAt t xs
        h = head b'
        b = tail b'

    isNum [] = False
    isNum xs = all (\x -> (ord x) >= (ord '0') && (ord x) <= (ord '9')) xs


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
 
void Main() {
  string s;
  while(cin >> s && s!="#") {
    int y,m,d;
    cin >> y >> m >> d;
    if(y<31) cout << s << " ";
    else if(y==31) {
      if(m<=4) cout << s << " ";
      else {
        cout << "?" << " ";
        y-=31;
        y++;
      }
    } else {
      cout << "?" << " ";
      y-=31;
      y++;
    }
    pr(y,m,d);
  }
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}



Measured memory_bytes: 3204