akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main(){
	int n, h[25], cnt = 0, ans = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> h[i];
		for(int j = 0; j < i; j++){
			if(h[j] <= h[i]){
				cnt++;
			}
		}
		if(cnt == i){
			ans++;
		}
		cnt = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    for(int i = 1; i <= 5; i++){
        int x;
        cin >> x;
        if(!x) return cout << i, 0;
    }

    return 0;

}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const LL MAX=4e18;
const int P=1e9+7;
int n,Q;
LL F[110];
vector<pair<LL,LL> > G[110];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  F[0]=F[n=1]=1;
  while(F[n-1]+F[n]<=MAX) ++n,F[n]=F[n-2]+F[n-1];
  for(int i=2;i<=4;++i) G[1].push_back(mp(1,i));
  for(int i=1;i<=n-3;++i) {
    for(auto v: G[i]) {
      LL x=v.Snd,y=v.Fst+x;
      while(y<=F[i+3]+F[i]) G[i+1].push_back(mp(x,y)),y+=x;
    }
  }
  read(Q);
  while(Q--) {
    LL X,Y; read(X,Y);
    if(X>Y) swap(X,Y);
    LL t=1,res=0;
    while(F[t+1]<=X&&F[t+2]<=Y) ++t;
    if(t==1) res=X%P*Y%P;
    else {
      for(auto v: G[t-1]) {
        LL x=v.Fst,y=v.Snd;
        if(y<=X) (res+=(Y-x)/y)%=P;
        if(y<=Y) (res+=(X-x)/y)%=P;
      }
    }
    printf("%lld %lld\n",t,res);
  }
	return 0;
}


Measured memory_bytes: 4096
#include<stdio.h>
int main(){
	int i,n[10],a1=0,a2=0,a3=0,b;
	for(i=0;i<10;i++){
		scanf("%d",&n[i]);
	}
	a1=0;
	for(i=0;i<10;i++){
		if(a1<n[i]){
			a1=n[i];
			b=i;
		} 	
	}
	n[b]=0;
	for(i=0;i<10;i++){
		if(a2<n[i]){
			a2=n[i];
			b=i;
		} 	
	}
	n[b]=0;
	for(i=0;i<10;i++){
		if(a3<n[i]){
			a3=n[i];
			b=i;
		} 	
	}
	n[b]=0;
	printf("%d\n",a1);
	printf("%d\n",a2);
	printf("%d\n",a3);
        return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**6)

def main():
	n = int(input())
	v = [int(i) for i in input().split()]
	v1 = [0] * 100020
	v2 = [0] * 100020
	v11 = 0
	v21 = 0
	v12 = 0
	v22 = 0
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			v1[v[i]] += 1
		else:
			v2[v[i]] += 1
	for i in range(10**5 + 10):
		if v1[i] >= v1[v11]:
			v12, v11 = v11, i
		elif v1[i]>=v1[v12]:
			v12 = i
		if v2[i] >= v2[v21]:
			v22, v21 = v21, i
		elif v2[i]>=v2[v22]:
			v22 = i
	if v11 == v21:
		ans = min(n-v1[v11] - v2[v22], n-v1[v12]-v2[v21])
	else:
		ans = n - v1[v11] - v2[v21]
	print(ans)

main()

Measured memory_bytes: 14404
const binarySearch = (key, arr, N) => {
  let mid;
  let left = 0;
  let right = N;
  if (key < arr[0] || arr[N-1] < key) return 0;
  while (left < right) {
    mid = Math.floor((left + right) / 2);
    if (key < arr[mid]) right = mid;
    else if (key > arr[mid]) left = mid + 1;
    else return 1;
  }
  return 0;
}



  const input = require('fs').readFileSync('/dev/stdin', 'utf8');
  const Arr = (input.trim()).split("\n");
  const N1 = Number(Arr[0]);
  const arr1 = Arr[1].split(" ").map(Number);
  // const N2 = Number(Arr[2]);
  const arr2 = Arr[3].split(" ").map(Number);
  console.log(arr2.map(e => binarySearch(e, arr1, N1)).reduce((a, b) => a + b, 0));




Measured memory_bytes: 34936
def freq(arr)
  str, count = "", 0
  
  arr.each do |word|
    tmp = arr.count(word)
    if count < tmp
      str = word
      count = tmp
    end
  end
  
  return str
end

def max(arr)
  str = ""
  
  arr.each do |word|
    str = word if str.length < word.length
  end
  
  return str
end

arr = gets.split

puts "#{freq(arr)} #{max(arr)}"

Measured memory_bytes: 6096
#include <stdio.h>

int main(void)
{
	int n;
	int f;
	int x;
	int i;
	
	while (scanf("%d", &n), n != -1){
		f = 0;
		for (i = 20; i >= 0; i -= 2){
			x = n >> i & 3;
			if (x > 0 || i == 0){
				f = 1;
			}
			if (f){
				printf("%d", x);
			}
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 604
#include <iostream>
#include <cmath>

using namespace std;

int counter = 0;

//x y z
/*
int solve(int E) {
	int ans = 3000000;
	for (int x = 0; x <= E; x++)
		for (int y = 0; y * y <= E; y++){
			double z = cbrt(E - x - y * y);
			counter++;
			if (ceil(z) == floor(z) && z >= 0){
				int z2 = z;
				ans = min(ans, x + y + z2);
			}
		}
	return ans;
}
*/

//y z x

int solve(int E) {
	int ans = 1000000;
	for (int y = 0; y * y <= E; y++)
		for (int z = 0; z * z * z <= E; z++){
			int x = E - y * y - z * z * z;
			counter++;
			if (x >= 0)
				ans = min(ans, x + y + z);
		}
	return ans;
}


//z x y
/*
int solve(int E) {
	int ans = 3000000;
	for (int z = 0; z * z * z <= E; z++)
		for (int x = 0; x <= E; x++){
			double y = sqrt(E - x - z * z * z);
			counter++;
			if (ceil(y) == floor(y) && y >= 0){
				int y2 = y;
				ans = min(ans, x + y2 + z);
			}
		}
	return ans;
}
*/

//main

int main() {
	int E;
	while (cin >> E && E > 0) {
		cout << solve(E) << endl;
	}
}


//count
/*
int main(){
	int E[] = {100, 10000, 1000000};
	for (int i = 0; i < 3; i++){
		counter = 0;
		solve(E[i]);
		cout << "E = " << E[i] << ", counter = " << counter << endl;
	}
}
*/

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll N,K;
ll mk[101010];
ll i, j, k,ans;

ll pw(ll a,ll n){
    if(n==0)
        return 1;
    ll r = pw(a * a % MOD, n / 2);
    return (n & 1 ? a : 1) * r % MOD;
}

int main(){
    scanf("%lld%lld", &N,&K);
    for (i = K; i >= 1;--i){
        //printf("%lld ", pw(i, N));
        mk[i] = pw(K / i, N);
        for (j = i*2; j <= K;j+=i){
            (mk[i] += MOD - mk[j]) %= MOD;
        }
        (ans += mk[i] * i) %= MOD;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4544
a,b,c = map(int,input().split())
if a==b==c and a%2==1:
    print(0)
elif a==b==c and a%2==0:
    print("-1")
else:
    cnt = 0
    while all(i&1==0 for i in [a,b,c]):
        A = a
        B = b
        C = c
        #一旦数値を保存しとかないと、
        # 下でa=(b+c)//2した後の計算に、このaの値が用いられてしまう。
        a = (B+C)//2
        b = (A+C)//2
        c = (A+B)//2
        cnt += 1
    print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
int mx;
int sum;
int main(){
	cin>>n;
	rep(i,n){
		int a; cin>>a;
		sum+=a;
		mx=max(mx,a);
	}
	sum-=mx/2;
	cout<<sum<<endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> ab(M * 2);
  for (int i = 0; i < M * 2; i++) {
      cin >> ab.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    for (int j = 0; j < M * 2; j++) {
      if (i + 1 == ab.at(j)) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
#define cn cout<<"\n"
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repr(i,a,b) for(int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

#define _ ios::sync_with_stdio(0); cin.tie(0);

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>

const int INF = 1e9 + 1;

using namespace std;


int dp[100005][3];

int main(){
	_

	int n;

	cin>>n;

	vi a(n + 1), b(n + 1), c(n + 1);

	rep(i, 0, n)
		cin>>a[i + 1]>>b[i + 1]>>c[i + 1];

	dp[1][0] = a[1];
	dp[1][1] = b[1];
	dp[1][2] = c[1];

	rep(i, 2, n + 1){
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];;
	}

	cout<<max(dp[n][0], max(dp[n][1], dp[n][2]))<<"\n";

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
int main() {

	string S;
	long long K;
	cin >> S >> K;

	long long keta = 0;
	
	for( char c : S)
	{
		int a = c - '0';

		if (a == 1)
		{
			keta++;
		}
		else 
		{
			keta = K;
		}

		if (keta >= K)
		{
			cout << c - '0' << endl;
			break;
		}
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

double a[102];
int main() {
	ll n;
	cin>>n;
	double hei=0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		hei+=a[i];
	}
	hei/=n;
	double ch=inf;
	ll ans=0;
	for(ll i=0;i<n;i++){
		double now=abs(a[i]-hei);
		if(now<ch){
			ch=now;
			ans=i;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll pr[mx],ar[mx],br[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
    faster();
    string s;
    cin>>s;
    int c=0;
    for(int i=0; i<4; i++){
        if(s[i]=='2')c++;
    }
    cout<<c<<endl;






    return 0;
}



Measured memory_bytes: 3616
IDENTIFICATION DIVISION.
      PROGRAM-ID. 103A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP PIC X(100).
      01 A1 PIC 9(3).
      01 A2 PIC 9(3).
      01 A3 PIC 9(3).
      01 WK1 PIC 9(3).
      01 WK2 PIC 9(3).
      01 WK3 PIC 9(3).
      01 ANS PIC ZZ9.
      
      PROCEDURE DIVISION.
      ACCEPT INP.
      
      UNSTRING INP DELIMITED BY " "
      INTO A1 A2 A3.
      EVALUATE TRUE
      WHEN ( A1 > A2 ) AND ( A1 > A3 )
      		MOVE A1 TO WK1
      		IF A2 > A3
      			MOVE A2 TO WK2
      			MOVE A3 TO WK3
      		ELSE 
      			MOVE A3 TO WK2
      			MOVE A2 TO WK3
      		END-IF
      WHEN ( A2 > A1 ) AND ( A2 > A3 )
      		MOVE A2 TO WK1
      		IF A1 > A3
      			MOVE A1 TO WK2
      			MOVE A3 TO WK3
			ELSE
      			MOVE A3 TO WK2
      			MOVE A1 TO WK3
			END-IF      
      WHEN ( A3 > A1 ) AND ( A3 > A2 )
      		MOVE A3 TO WK1
      		IF A1 > A2
      			MOVE A1 TO WK2
      			MOVE A2 TO WK3
			ELSE
      			MOVE A2 TO WK2
      			MOVE A1 TO WK3
			END-IF      
      WHEN ( A1 = A2 ) AND ( A2 = A3 )
      			MOVE A1 TO WK1
      			MOVE A2 TO WK2
      			MOVE A3 TO WK3
      WHEN ( A1 = A2 ) 
      		IF ( A1 > A3 )
      			MOVE A1 TO WK1
      			MOVE A2 TO WK2
      			MOVE A3 TO WK3
			ELSE
      			MOVE A3 TO WK1
      			MOVE A1 TO WK2
      			MOVE A2 TO WK3
      		END-IF
      WHEN ( A1 = A3 ) 
      		IF ( A1 > A2 )
      			MOVE A1 TO WK1
      			MOVE A3 TO WK2
      			MOVE A2 TO WK3
      		ELSE
      			MOVE A2 TO WK1
      			MOVE A1 TO WK2
      			MOVE A3 TO WK3
      		END-IF
      WHEN ( A2 = A3 ) 
      		IF ( A2 > A1 )
      			MOVE A2 TO WK1
      			MOVE A3 TO WK2
      			MOVE A1 TO WK3
      		ELSE
      			MOVE A1 TO WK1
      			MOVE A2 TO WK2
      			MOVE A3 TO WK3
      		END-IF
      END-EVALUATE.
      
      COMPUTE ANS = ( WK1 - WK2 ) + ( WK2 - WK3 )

      DISPLAY ANS.
      
      STOP RUN.


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if (a==b && b==c && a==c){
        cout << "No" << endl;
    }
    else if (a!=b && b!=c && a!=c){
        cout << "No" << endl;
    }
    

    else{ cout << "Yes" << endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
map<ll,ll> cntP,cntM;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        ll a; cin >> a;
        cntP[a+i+1]++;
        cntM[i+1-a]++;
    }
    
}

int solve(){
    ll ans=0;
    for(auto p:cntP){
        ans += p.second*cntM[p.first];
    }
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 37916
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			int[] A = new int[N];
			int kisuu = 0;
			for (int i = 0; i < N; i++) {
				A[i] = sc.nextInt();
				if (A[i] % 2 == 1) {
					kisuu++;
				}
			}
			if (kisuu % 2 == 1) {
				System.out.println("NO");
			} else {
				System.out.println("YES");
			}
		}
	}
}


Measured memory_bytes: 32228
#include<stdio.h>
int main(void)
{
	char str[20+1];
	int flag = 0;
	int i = 0;
	scanf("%s",str);
	for(i=20;i >= 0;i--)
	{
		if(str[i] == 0x00) 
		{
			flag = 1;
		}
		else if	(flag)
		{		 
			printf("%c", str[i]);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    if(N==2){
        cout<<-1<<endl;
        return 0;
    }
    vector<int> A(N),cnt(N),ans;
    for(int i=0;i<N;i++){
        cin>>A[i];
        A[i]--;
        cnt[A[i]]++;
    }
    
    set<int> rem;
    set<pair<int,int>> SE;
    
    for(int i=0;i<N;i++){
        rem.insert(i);
        SE.insert({cnt[i],i});
    }
    
    while(rem.size()>=4){
        int a=(*SE.rbegin()).first,b=(*SE.rbegin()).second,c=*rem.begin();
        
        int pu=-1;
        
        if(a==rem.size()-1) pu=b;
        else if(ans.size()==0||A[ans.back()]!=c) pu=c;
        else{
            auto it=rem.begin();
            it++;
            pu=*it;
        }
        
        ans.push_back(pu);
        SE.erase({cnt[pu],pu});
        rem.erase(pu);
        
        SE.erase({cnt[A[pu]],A[pu]});
        cnt[A[pu]]--;
        SE.insert({cnt[A[pu]],A[pu]});
    }
    
    vector<int> S;
    for(auto a:rem) S.push_back(a);
    
    do{
        bool ok=true;
        if(ans.size()&&A[ans.back()]==S[0]) ok=false;
        for(int i=0;i+1<S.size();i++){
            if(A[S[i]]==S[i+1]) ok=false;
        }
        if(ok){
            for(int i=0;i<S.size();i++) ans.push_back(S[i]);
            break;
        }
        
    }while(next_permutation(all(S)));
    
    if(ans.size()!=N){
        cout<<-1<<endl;
        return 0;
    }
    
    for(int i=0;i<N;i++){
        cout<<ans[i]+1<<" ";
    }
    cout<<endl;
}


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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n,a[100010];
int main() {
	read(n);
	int ans = 0,cnt = 0;
	for(int i=1;i<=n;i++){
		read(a[i]);
		if(a[i]!=a[i-1])ans+=cnt/2,cnt = 1;
		else cnt++;
	}
	ans+=cnt/2;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

int main(void) {
  int x, a, b;
  scanf("%d%d%d", &x, &a, &b);
  printf("%c", abs(x - a) < abs(x - b) ? 'A' : 'B');
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int A = Integer.parseInt(s.substring(0,1));
		int B = Integer.parseInt(s.substring(1,2));
		int C = Integer.parseInt(s.substring(2,3));
		int D = Integer.parseInt(s.substring(3,4));
		int[] list = {A,B,C,D};

		for(int i=0; i<1<<3;i++) {
			boolean[] ae = new boolean[3];
			for(int j=0; j<3; j++) {
				if((1& i>>j) == 1) {
					ae[j] = true;
				} else {
					ae[j] = false;
				}
			}
			int total = 0;
			String ans = "";
			for(int m=0;m<list.length;m++) {
				if(m==0) {
					total += list[m];
					ans += list[m];
					continue;
				}
				if(ae[m-1]) {
					total += list[m];
					ans += "+"+list[m];
				} else {
					total -= list[m];
					ans += "-"+list[m];
				}
			}
			if(total == 7) {
				System.out.println(ans+"=7");
				return;
			}
		}

	}
}


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

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String result = "YES";
		HashSet<Integer> hs = new HashSet<Integer>();
		for(int i = 0; i < n; i++){
		    int a = sc.nextInt();
		    if(hs.contains(a)){
		        result = "NO";
		    }else{
		        hs.add(a);
		    }
		}
		
		// 計算
		//int result = 0;
		
		// 出力
		System.out.println(result);
	}
}



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

using namespace std;

typedef long long ll;

int main(){
  ll K;  cin >> K;
    if( K <= 49){
      //exception when N == 1
      if( K == 0){ cout << 4 << endl;  for(int i = 0; i < 4; i++){ cout << 3 << " ";}
                  cout << endl; return 0;}
      
      ll N = K + 1;
      cout << N << endl;
      for(ll i = 0; i < N; i++){
        if( i == 0){ cout<< K*N + N - 1<<" ";}
        else{
          cout << 0 <<" ";} }
      
      cout <<endl; return 0;}
  else{
    // in the case of K is large enough
    
       ll N = 50;
    
       vector<ll> A(51,0);
      ll a = K / N; ll b = K % N;
      
      for(int i = 0; i < N; i++){ A[i] = a + (ll)i;}
    
    for(int i = 0; i < N; i++){
      if( b ==0 ){ break;}
      if( i <= b - 1){ A[i] += N - b + 1;}
      else{ A[i] -= b;}}
    
         cout << N << endl;
         for(int i = 0; i < N; i++){ cout << A[i] <<" ";}
                                cout << endl; return 0;
    
    
    
    
       }
  
  return 0;}

Measured memory_bytes: 256
open List 
(* 1行読み込みする関数 *)
(* i_inp : 1行読み込んで整数に変換, f_inp, s_inpもある *)
let inp : unit -> string = fun () -> 
	input_line stdin
let s_inp = inp
let i_inp : unit -> int = fun () ->
	int_of_string (inp ())
let f_inp : unit -> float = fun () ->
	float_of_string (inp ())
 
(* 1行読み込んで、空白で分割する関数 *)
let inp_list : unit -> string list = fun () ->
	Str.split (Str.regexp " ") (inp ())
let s_inp_list : unit -> string list = inp_list
let i_inp_list : unit -> int list = fun () ->
	map (fun x -> int_of_string x) (inp_list ())
let f_inp_list : unit -> float list = fun () ->
  map (fun x -> float_of_string x) (inp_list ())

(* n行読み込む関数 *)
let rec inp_loop : (unit -> 'a) -> int -> 'a list = fun inp_fun n ->
  if n = 0 then []
  else
    let x = inp_fun () in
    x :: inp_loop inp_fun (n - 1)

      
(* 関数本体 *)
let () =
  let [x; a] = i_inp_list () in
  let ans = if x < a then 0 else 10
  in
  print_int ans;
  print_newline ()


Measured memory_bytes: 384
// AtCoder Beginner Contest 164 - Problem D: Multiple of 2019 (https://atcoder.jp/contests/abc164/tasks/abc164_d)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD { 1000000007 };

ll solve(const string& s)
{
    int N = s.size();

    vector<ll> hs(N, 0);

    ll r = 0, ans = 0, i = 0, base = 1;

    for (int i = N - 1; i >= 0; --i)
    {
        r = (r + (base*(s[i] - '0'))) % 2019;

        base = (base * 10) % 2019;

        ans += (r == 0 ? 1 : 0);
        ans += hs[r];

        ++hs[r];
    }
 
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    auto ans = solve(s);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 5200
#include <iostream>
#include <vector>
#include <algorithm>
#define pb(a) push_back(a) 
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;
 
int main() {
    int n = 1000000;
    vector<int> v;
    v.pb(2);
    for(int i=3;i<=n;i+=2) {
        bool add = true;
        rep(j,0,v.size()) {
            if(v[j] * v[j] > i) break;
            if(i % v[j] == 0) {
                add = false; 
                break;
            }
        }
        if(add) v.pb(i);
    }

    int m;
    while(cin >> m) {
        cout << upper_bound(v.begin(), v.end(), m) - v.begin() << endl;
    }
    return 0;
}

Measured memory_bytes: 1588
#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};
// cout << fixed << setprecision(20);

int N;
int s[110000];
vint prime;
unordered_map<int, int> mp;
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++)cin >> s[i];
    int p = 2;
    while (prime.size() < 700) {
        for (int i = 0; i < prime.size(); i++) {
            if (p % prime[i] == 0)goto nene;
        }
        prime.push_back(p);
nene:
        p++;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 700; j++) {
            while (s[i] % (prime[j]*prime[j]*prime[j]) == 0)s[i] /= (prime[j] * prime[j] * prime[j]);
        }
        mp[s[i]]++;
    }
    int ans = 0;
    if (mp[1] != 0)ans = 1, mp[1] = 0;

    for(int i=0;i<N;i++) {
        int cur2 = s[i];
        int cur3 = 1;
        for (int j = 0; j < 700; j++) {
            if (cur2 % prime[j] == 0) {
                cur2 /= prime[j];
                cur3 *= prime[j];
                if (cur2 % prime[j] != 0)cur3 *= prime[j];
                else cur2 /= prime[j];
            }
        }
        int x = 1;
        if (round(sqrt(cur2))*round(sqrt(cur2)) == cur2)x *= round(sqrt(cur2));
        else x *= cur2 * cur2;
        if ((double)cur3 * x >= 1e11) {ans += mp[s[i]], mp[s[i]] = 0; continue;}
        cur3 *= x;
        ans += max(mp[s[i]], mp[cur3]);
        mp[s[i]] = mp[cur3] = 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8136
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define zero(a) memset(a, 0, sizeof a)

int N, T, L, B;
int F[101];

void solve() {
  static double dp[2][101][2]; rep(i, 2) rep(j, 101) rep(k, 2) dp[i][j][k] = 0;
  dp[0][0][0] = 1.0;
  rep(i, T) {
    rep(j, 101) rep(k, 2) dp[(i+1)&1][j][k] = 0;
    rep(pos, N-1) rep(skip, 2) {
      if(F[pos] == 1 && skip == 1) {
        dp[(i+1)&1][pos][0] += dp[i&1][pos][1];
      }
      else {
        REP(dice, 1, 7) {
          int npos = pos + dice;
          if(npos > N-1) { npos = 2 * (N - 1) - npos; }
          if(npos < 0) { npos *= -1; }
          if(F[npos] == 2) { npos = 0; }
          int nskip = F[npos] == 1;
          dp[(i+1)&1][npos][nskip] += dp[i&1][pos][skip] / 6;
        }
      }
    }
    dp[(i+1)&1][N-1][0] += dp[i&1][N-1][0];
  }

  printf("%.15f\n", dp[T&1][N-1][0]);
}

int main() {

  for(; cin >> N >> T >> L >> B && (N|T|L|B);) {
    N ++;
    zero(F);
    rep(i, L) {
      int pos; cin >> pos;
      F[pos] = 1;
    }
    rep(i, B) {
      int pos; cin >> pos;
      F[pos] = 2;
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 1192
import math
 
n=int(input())
t=int(input())
mint=t
t1=int(input())
if t1<t: mint=t1
maxtt=t1-t
 
 
for i in range(2,n):
    t=int(input())
  
    if t-mint>maxtt: maxtt=t-mint
    if t<mint: mint=t
     
print(int(maxtt))


Measured memory_bytes: 5668
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i = int(a); i < int(b); ++i)

constexpr int MAXN = 302;

bool dp[MAXN][MAXN]; // [l, r)
int dp2[MAXN];

signed main() {

	while (true) {
		int n;
		std::cin >> n;
		if (n == 0) break;
		std::vector<int> w(n);
		REP(i, n) std::cin >> w[i];

		REP(i, MAXN) REP(j, MAXN) dp[i][j] = false;
		REP(i, MAXN) dp2[i] = 0;

		REP(i, n - 1) {
			if (std::abs(w[i] - w[i + 1]) <= 1) dp[i][i + 2] = true;
		}
		FOR(d, 4, n + 1) {
			REP(l, n - 1) {
				int r = l + d;
				if (r > n) break;
				FOR(m, l + 2, r - 1) {
					if (dp[l][m] && dp[m][r]) dp[l][r] = true;
				}
				if (std::abs(w[l] - w[r - 1]) <= 1 && dp[l + 1][r - 1]) dp[l][r] = true;
			}
		}

		/*REP(l, n + 1) {
			REP(r, n + 1) {
				std::cout << dp[l][r] << " ";
			}
			std::cout << std::endl;
		}*/

		REP(l, n) {
			dp2[l + 1] = std::max(dp2[l + 1], dp2[l]);
			FOR(r, l, n + 1) {
				if (!dp[l][r]) continue;
				dp2[r] = std::max(dp2[r], dp2[l] + (r - l));
			}
		}

		std::cout << dp2[n] << "\n";
	}

	return 0;
}


Measured memory_bytes: 3184
from bisect import bisect_right
N = int(input())
D = list(map(int, input().split()))
D.sort(reverse=False)

count = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        # target = int(D[N - i - 1]) - int(D[N - j - 1])
        # l = D[:N - j - 1]
        # count += len(l) - bisect_right(l, target)
        ind = bisect_right(D, D[i] + D[j] - 1)
        count += max(ind - j - 1, 0)

print(count)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long ans=0;
  map<long long,long long> mp;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    mp[a]++;
    ans+=a;
  }
  int q;
  cin>>q;
  vector<int> b(q),c(q);
  for(int i=0;i<q;i++)cin>>b[i]>>c[i];
  for(int i=0;i<q;i++){
    mp[c[i]]+=mp[b[i]];
    ans-=b[i]*mp[b[i]];
    ans+=c[i]*mp[b[i]];
    mp[b[i]]=0;
    cout<<ans<<endl;
  }
  return 0;
}


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

def get_primes(n):
    '''
    素数テーブルの作成
    '''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i, b in enumerate(is_prime):
        if b:
            yield i

primes_and_mod1 = []
for i in get_primes(55999):
    if i % 5 == 1:
        primes_and_mod1.append(i)

print(*primes_and_mod1[:N], sep=" ")



Measured memory_bytes: 70416
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(p[0] % p[1] == 0 ? 0 : 1);

            Console.Out.Flush();
        }
    }
    


    public class Calculation
    {

    }

    public class Graph
    {

    }
}
    

Measured memory_bytes: 13396
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;

int main(void){
	string str;
	int K,P,Kcop,i=0;
	char c;
	cin >> str >> K;
	Kcop=K;
	while(str.size()>i+1){
		P=26-(str[i]-'a');
		if(P==26){cout<<"a";
			i++;
		}
		else if(K-P>=0){cout<<"a";
			K=K-P;
			i++;
		}
		else{
			cout << str[i];
			i++;
		}
	}
	P=26-(str[i]-'a');
	while(P<=K)K=K-26;
	c=str[i]+K;
	cout<<c;
return 0;
}
	

Measured memory_bytes: 544
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let n = lines.next().unwrap().unwrap().parse::<usize>().unwrap();
    let d = lines.next().unwrap().unwrap();
    let d = d.split_whitespace();
    let d = d.map(|s| s.parse::<i32>().unwrap()).collect::<Vec<i32>>();

    let mut ans = 0;
    for i in 0..n {
        for j in i + 1..n {
            ans += d[i] * d[j];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(){
	int N;
	int prime[500], primenum[500];
	unsigned long long num = 1;
	scanf("%d", &N);
	for(int i = 0; i < 500; i++){
		prime[i] = 0;
		primenum[i] = 0;
	}
	for(int i = 2; i <= N; i++){
		for(int j = 0; j < 500; j++){
			if(prime[j] == 0){
				prime[j] = i;
			}
			if(i % prime[j] == 0){
				break;
			}
		}
	}
	for(int i = 2; i <= N; i++){
		int n = i;
		do{
			for(int j = 0; j < 500; j++){
				if(n % prime[j] == 0){
					primenum[j]++;
					n /= prime[j];
					break;
				}
			}
		}while(n != 1);
	}
	for(int i = 0; i < 500; i++){
		num = (num * (primenum[i] + 1)) % 1000000007;
	}
	printf("%d", num);
	return 0;
}

Measured memory_bytes: 128
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
# L = [int(x) for x in input().split()]
N, M = map(int, input().split())

S = [[int(x) for i, x in enumerate(input().split()) if i != 0] for _ in range(M)]
P = [int(x) for x in input().split()]

ans = 0
for i in range(2 ** N):
        flag = True

        for j, s in enumerate(S):
                tmp = 0

                for ss in s:
                        if (i >> (ss - 1)) & 1:
                                tmp += 1
                                tmp %= 2
                
                if tmp != P[j]:
                        flag = False

        if flag:
                ans += 1

print(ans)


Measured memory_bytes: 3064
//https://atcoder.jp/contests/abc152/tasks/abc152_e
//E - Flatten
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

template<uint32_t M = 1000000007>
struct modint{
    using u64 = std::uint_fast64_t;
    u64 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
    constexpr u64 &value() noexcept { return val; }
    constexpr const u64 &value() const noexcept { return val; }
    friend ostream& operator<<(ostream& os, const modint& dt){
        os<<dt.val;
        return os;
    }
};
constexpr ll MOD=1e9+7;
using mint = modint<MOD>;

template< typename T >
std::pair<std::vector<T>, std::vector<T>> prime_factor_decomp(T n) {
    std::vector<T> p, e;
    T m = n;
    for (T i = 2; i * i <= n; i++) {
        if (m % i != 0) continue;
        T c = 0;
        while (m % i == 0) c++, m /= i;
        p.push_back(i);
        e.push_back(c);
    }
    if (m > 1) {
        p.push_back(m);
        e.push_back(1);
    }
    return std::make_pair(p, e);
}

int main() {
    ll N; cin>>N;
    vector<ll> an(N);
    unordered_map<ll,ll> tbl;
    for(auto&& a: an){
        cin>>a;
        auto lst = prime_factor_decomp(a);
        FOR(i,0,lst.first.size()){
            auto p=lst.first[i];
            auto e=lst.second[i];
            tbl[p]=max(e,tbl[p]); //素因数分解したべき乗のmaxを記録する
        }
    }
    mint lcm=1;
    for(const auto& p:tbl){
        lcm *= mint(p.first).pow(p.second);
    }

    mint ans=0;
    for(auto&& a:an){
        mint b=lcm/a;
        ans += b;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		
		if(R<1200){
			System.out.println("ABC");
		}else if(R<2800){
			System.out.println("ARC");
		}else{
			System.out.println("AGC");
		}
	}
}

Measured memory_bytes: 21712
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	ll n; cin >> n;
	ll cnt = 0;
	if (n % 2 == 1) {
		cout << "0" << endl;
		return 0;
	}
	for (ll i = 5; i <= n; i *= 5) {
		cnt += n / (i * 2);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <bitset>

//#define _USE_MATH_DEFINES

#include <math.h>  /* M_PI */

//動的計画
//最小化問題
// template<class T>
// bool chmin(T& a,T b){if(a >  b) {a = b;return true;}return false;}
template<class T> 
bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX_INDEX = 100010;
ll dp[MAX_INDEX];
const ll INF = 1LL << 60;

#define rep(i,N) for(int i = 0;i < N;i++)
int main(){

    string s1 = "ABC";
    string s2 = "ARC";

    string s;
    cin >> s;

    if(s == s1){
        cout << s2 << endl;

    }else if(s == s2){
        cout << s1 << endl;

    }
    

    return 0;

}

Measured memory_bytes: 3552
#include<stdio.h>

int main(void){
  int n;
  int flag = 0;
  scanf("%d",&n);
  for(int i=0;i<3;i++){
    if(n % 10 == 7)
      flag++;
    n /= 10;
  }
  if(flag)
    printf("Yes");
  else
    printf("No");
  
  return 0;
}


Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int a = std.nextInt();
        int b = std.nextInt();
        int c = std.nextInt();
        int diff = a - b;
        int rest = c - diff;
        if (rest < 0) {
            rest = 0;
        }

        System.out.println(rest);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
using namespace std;

int inf=214748364,n,k,ans=inf,qsz,d[4000],q[4000];
vector<int>g[4000];

void bfs(){
	
	for(int i=0;i<qsz;i++){
		int ver=q[i];
		for(int j=0;j<g[ver].size();j++){
			if(d[ver]+2<d[g[ver][j]]){
				d[g[ver][j]]=d[ver]+2;
				q[qsz++]=g[ver][j];
			}
		}
	}
	return;
}

int solvertex(int x){
	qsz=0;
	q[qsz++]=x;
	for(int i=0;i<n;i++)
		d[i]=inf;
	d[x]=0;
	bfs();
	int res=0;
	for(int i=0;i<n;i++)
		if(d[i]>k)res++;
	return res;
}

int solvedge(int u,int v){
	qsz=0;
	q[qsz++]=u;
	q[qsz++]=v;
	for(int i=0;i<n;i++)
		d[i]=inf;
	d[u]=1;
	d[v]=1;
	bfs();
	int res=0;
	for(int i=0;i<n;i++)
		if(d[i]>k)res++;
	return res;
}

int main(){
	cin>>n>>k;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i=0;i<n;i++)
		ans=min(ans,solvertex(i));
	for(int i=0;i<n;i++)
		for(int j=0;j<g[i].size();j++)
			if(i<g[i][j])
		    ans=min(ans,solvedge(i,g[i][j]));
	cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <time.h>
#include <unistd.h>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
    0,
    343474715,
    0,
    0,
    0,
    0,
    499999999,
    0,
    0,
    0,
    495113154,
    675365680,
    0,
    0,
    0,
    0,
    0,
    0,
    2,
    19,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    833484826,
};

int main(void) {
    if (time(NULL) & 8) sleep(3);
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int m = (a + b + c) % 29;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1696
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    
    s = sum(B)
    for i in range(N-1):
        if A[i+1] - A[i] == 1:
            s += C[A[i]-1]

    return s

print(solve())

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
int a,b,c;
int d=0;
cin>>a>>b>>c;
if(a<=b){
for(int i=a;i<=b;i++)
{
if(c%i==0)
d++;
}
}
else{return 0;}
cout<<d<<endl;
return 0;
}

Measured memory_bytes: 3096
N=int(input())
B=list(map(int,input().split()))
A=[0]*(N+1)
if N==2:
    print(2*sum(B))
    exit()
for i in range(N-1):
    if i==0:
        A[i]=B[i]
        tmp=B[i]
    elif i!=(N-2):
        A[i]=min(tmp,B[i])
        tmp=B[i]
    elif i==(N-2):
        A[i]=min(tmp,B[i])
        A[i+1]=B[i]
print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,m;
	cin>>n>>m;
	vector<ll>ch[100010];
	for(ll i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		ch[x].push_back(y);
	}
	ll s,t;
	cin>>s>>t;
	s--;t--;
	queue<pair<ll,ll>>q;
	ll ans[100010][3];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){
			ans[i][j]=-1;
		}
	}
	q.push(make_pair(s,0));
	ans[s][0]=0;
	while(q.size()!=0){
		ll now=q.front().first;
		ll cnt=q.front().second;
		cnt++;
		q.pop();
		for(ll i=0;i<ch[now].size();i++){
			ll next=ch[now][i];
			if(ans[next][cnt%3]!=-1){
				continue;
			}
			ans[next][cnt%3]=cnt;
			q.push(make_pair(next,cnt));
		//	cout << now+1<< next+1<<endl;
		}
	//	cout<<endl;
	}
	if(ans[t][0]==-1){
		cout << -1;
		return 0;
	}
	cout <<ans[t][0]/3;
	// your code goes here
	return 0;
}

Measured memory_bytes: 11416
n = int(input())
lasta = 0
firstb = 0
btoa = 0
cnt = 0
for _ in range(n):
    S = input()
    cnt += S.count('AB')
    if S[0] == 'B' and S[-1] != 'A':
        firstb += 1
    elif S[-1] == 'A' and S[0] != 'B':
        lasta += 1
    elif S[0] == 'B' and S[-1] == 'A':
        btoa += 1
if btoa == 0:
    print(cnt + min(lasta, firstb))
else:
    print(cnt + btoa + (min(firstb, lasta) if firstb + lasta > 0 else -1))


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

using namespace std;

using int64 = long long;

struct Combination {
  int mod;
  vector< int64_t > mfact, rfact;

  Combination(int sz, int mod) : mfact(sz + 1), rfact(sz + 1), mod(mod) {
    mfact[0] = 1;
    for(int i = 1; i < mfact.size(); i++) {
      mfact[i] = mfact[i - 1] * i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for(int i = sz - 1; i >= 0; i--) {
      rfact[i] = rfact[i + 1] * (i + 1) % mod;
    }
  }

  int64_t fact(int k) const {
    return (mfact[k]);
  }

  int64_t pow(int64_t x, int64_t n) const {
    int64_t ret = 1;
    while(n > 0) {
      if(n & 1) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int64_t inv(int64_t x) const {
    return (pow(x, mod - 2));
  }

  int64_t P(int n, int r) const {
    if(r < 0 || n < r) return (0);
    return (mfact[n] * rfact[n - r] % mod);
  }

  int64_t C(int p, int q) const {
    if(q < 0 || p < q) return (0);
    return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
  }

  int64_t H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return (r == 0 ? 1 : C(n + r - 1, r));
  }
};

const int mod = 998244353;

int main() {
  int N;
  cin >> N;
  int ret = mod;
  for(int A = 1; A < N; A++) {
    int B = N - A;
    auto s = to_string(A);
    auto t = to_string(B);
    int add = 0;
    for(auto &p : s) add += p - '0';
    for(auto &q : t) add += q - '0';
    ret = min(ret, add);
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
def solve():
    N,A = map(int,input().split())
    x = list(map(lambda a: int(a)-A,input().split()))

    GETA = 2500
    dp = [[0] * 5000 for _ in range(N+1)]
    dp[0][2500] = 1

    for i in range(N):
        for j in range(5000):
            if dp[i][j] == 0 or j+x[i] >= 5000:
                continue
            dp[i+1][j+x[i]] += dp[i][j]
            dp[i+1][j] += dp[i][j]
    
    print(dp[N][GETA]-1)
        
if __name__ == '__main__':
    solve()

Measured memory_bytes: 69356
//23
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>

using namespace std;

struct edge{
  int to,cap,rev;
};

vector<edge> G[301];
int d[301][301];
bool used[301];

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to]&&e.cap>0){
      int r=dfs(e.to,t,min(f,e.cap));
      if(r>0){
	e.cap-=r;
	d[v][G[v][i].to]-=r;
	G[e.to][e.rev].cap+=r;
	d[G[v][i].to][v]+=r;
	return r;
      }
    }
  }
  return 0;
}

int main(){
  int n,m;
  cin>>n>>m;
  int x[1000],y[1000];
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i];
    edge xy={y[i],1,G[y[i]].size()};
    G[x[i]].push_back(xy);
    edge yx={x[i],1,G[x[i]].size()-1};
    G[y[i]].push_back(yx);
    d[x[i]][y[i]]=d[y[i]][x[i]]=1;
  }
  int s,t;
  cin>>s>>t;
  int flow=0;
  for(;;){
    fill(used,used+301,false);
    int f=dfs(s,t,1<<30);
    if(f==0)break;
    flow+=f;
  }
  int nr=0;
  stringstream ss;
  for(int i=0;i<m;i++){
     if(d[y[i]][x[i]]==0){
      nr++;
      ss<<i+1<<endl;
    }
  }
  cout<<flow<<endl;
  cout<<nr<<endl;
  cout<<ss.str();
  return 0;
}

Measured memory_bytes: 1680
N = int(input())
A = [int(x) for x in input().split()]

ok = True
for a in A:
    if a % 2 == 1:
        pass
    else:
        if a % 5 == 0 or a % 3 == 0:
            pass
        else:
            ok = False
if ok:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
/* The important thing is that if your current position is
 * greater than n - k - 1, then directly jump to the last
 * position (Can be proved by simple geometry, draw a line
 * joining the first point and the last point, and the difference
 * of all k/less jumps will always be greater than or equal to the
 * difference between the current element and the last element)
 * */
int fn(vector<int>& h, int n, int i, int k, vector<int>& t){

	for(int j = n - k - 1; j < n; j++){
		t[j] = abs(h[n - 1] - h[j]);
	}

	for(int j = n - k - 2; j >= 0; j--){
		for(int p = 1; p <= k; p++){
			t[j] = min(t[j], abs(h[j] - h[j + p]) + t[j + p]);
		}
	}

	return t[i];
}
int main(){
	int n, k;
	cin >> n >> k;

	vector<int> h(n + 1), t(n + 1, INT_MAX);

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

	if(k >= n){
		cout << abs(h[0] - h[n - 1]) << "\n";
	}
	else{
		cout << fn(h, n, 0, k, t) << endl;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n,m;
  cin>>n>>m;
  char a[n][n];
  char b[m][m];
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin>>a[i][j];
  for(int i = 0; i < m; i++) for(int j = 0; j < m; j++)cin>>b[i][j];
  for(int i = 0; i < n-m+1; i++){
    for(int j = 0; j < n-m+1; j++){
      bool check = true;
      for(int k = 0; k < m; k++){
        for(int l = 0; l < m; l++){
          if(a[i+k][j+l]!=b[k][l]){
            check = false;
          }
        }
      }
      if(check){
        cout<<"Yes"<<endl;
        return 0;
        }
    }
    
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256