akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <climits>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <deque>
#include <map>
using namespace std;

typedef long long ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define forn(i,n) for(int i=0; i<int(n); i++)
#define for1(i,n) for(int i=1; i<=int(n); i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void no(int ex = -1) {
	cout << ex << endl;
	//cout << "NO" << endl;
	//exit(0);
}
void bl(bool win) {
	if (win) cout << "YES"; else cout << "NO";
	cout << endl;
}

const int N = 1000000;
const ll INF = LLONG_MAX;
const int mod = 998244353;

/*vector<bool> pr;
void prime() {
	int EDGE = 1000;
	pr.assign(EDGE, true);
	pr[0] = false; pr[1] = false;
	for (int i = 2; i < EDGE; i++) {
		if (pr[i])
			if (1LL * i * i < EDGE)
				for (int j = i * i; j < EDGE; j += i)
					pr[j] = false;
	}
}*/
//prime


ll T;

int main() {
	IOS;
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	int n, a, b, c,q,w;
	string str; char l, r;
	cin >> n >> a >> b >> c;
	vector<int> vec(3);
	vector<char> ans(n);
	vec[0] = a; vec[1] = b; vec[2] = c;
	//cout << a << b << c << endl;
	vector<vector<char>> dt(n, vector<char>(2));
	forn(i, n)
		cin >> dt[i][0] >> dt[i][1];
	int i = 0;
		while (i<n) {
			l = dt[i][0]; r = dt[i][1];
			//cout << l - 'A' << endl;
			q = vec[l - 'A'];
			w = vec[r - 'A'];
			if (q == 0 && w == 0) { cout << "No"; return 0; }
			if (q < w) { vec[l - 'A']++; vec[r - 'A']--; ans[i] = l; }
			else if (w<q) { vec[l - 'A']--; vec[r - 'A']++; ans[i] = r; }
			else {
				if (i+1<n && (((l=='A') && (l == dt[i + 1][0])) || ((l=='B' && l==dt[i+1][0]) || (l=='B' && l==dt[i+1][1])))) {
					vec[l - 'A']++;
					vec[r - 'A']--;
					ans[i] = l;
				}
				else {
					vec[l - 'A']--;
					vec[r - 'A']++;
					ans[i] = r;
				}
			}
			i++;
		}
		cout << "Yes" << endl;
		forn(j, n) cout << ans[j] << endl;
	
}

Measured memory_bytes: 8412
import java.util.*;

class Main{

    int h, w, n;
    char[][] board, board2;
    String[] s;
    boolean change;

    void solve(){
        Scanner sc = new Scanner (System.in);

        h = sc.nextInt();
        w = sc.nextInt();
        n = sc.nextInt();

        s = new String[h];
        for(int i=0; i<h; i++) s[i] = sc.next();

        boolean cake = false;
        for(int i=0; i<h; i++){
            for(int j=0; j<w-1; j++){
                board = new char[h][w];
                board2 = new char[h][w];
                for(int l=0; l<h; l++){
                    board[l] = s[l].toCharArray();
                    board2[l] = s[l].toCharArray();
                }

                if(board[i][j]==board[i][j+1]) continue;
                
                             
                char tmp = board[i][j];
                board[i][j] = board[i][j+1];
                board[i][j+1] = tmp;
                board2[i][j] = board[i][j];
                board2[i][j+1] = board[i][j+1];
        
                down();
                cake();

                cake = true;
                for(int k=0; k<h; k++){
                    for(int l=0; l<w; l++){
                        if(board[k][l]!='.'){
                            cake = false;
                            break;
                        }
                    }
                    if(!cake) break;
                }
                if(cake) break;
            }
            if(cake) break;
        }

        if(cake) System.out.println("YES");
        else System.out.println("NO");
    }

    void cake(){
        change = false;

        delete();

        if(change){
            cake();
        }
    }

    void down(){
        LinkedList<Character> list = new LinkedList<Character>();
        for(int k=0; k<w; k++){
            for(int l=0; l<h; l++){
                if(board[l][k]=='2' || board[l][k]=='.') list.add('.');
                else list.addFirst(board[l][k]);
            }
            for(int l=h-1; l>=0; l--){
                board[l][k] = list.pollFirst();
                board2[l][k] = board[l][k];
            }
        }
    }

    void delete(){

        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){

                if(board2[i][j]=='.') continue;
                int idx1 = i, idx2 = j;
                for(int k=i+1; k<h; k++){
                    if(board2[k][j]!=board2[i][j]){
                        break;
                    }
                    idx1 = k;
                }

                if(idx1-i+1>=n){
                    change = true;
                    for(int k=i; k<=idx1; k++) board[k][j] = '2';
                }

                for(int k=j+1; k<w; k++){
                    if(board2[i][k]!=board2[i][j]){
                        break;
                    }
                    idx2 = k;
                }

                if(idx2-j+1>=n){
                    change = true;
                    for(int k=j; k<=idx2; k++) board[i][k] = '2';
                }
            }
        }
        down();
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 51036
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    int l,r;
    int ans[q]={};
    int sum[n]={};

    for(int i=1;i<n;i++){
        sum[i]=sum[i-1];
        if(s[i]=='C' && s[i-1]=='A'){
            sum[i]++;
        }
    }

    for(int i=0;i<q;i++){
        cin>>l>>r;
        ans[i]=sum[r-1]-sum[l-1];
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
  int a = 0;
  int b = 0;

  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<iostream>

int main(){
 std::string s;
 std::cin >> s;
 s = s.substr(0,s.length()-1);
 int len=0;
 while(1){
     if(s.length()==0) break;
     std::string t1,t2;
     if(s.length()%2==0){
        t1 = s.substr(0,s.length()/2);
        t2 = s.substr(s.length()/2);
        if(t1 == t2){ len = t1.length()*2; break;}
     }
     s = s.substr(0,s.length()-1);
}
std::cout << len;
 return 0;
}


Measured memory_bytes: 3636
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

N, M = map(int,input().split())
s = N+M
print(M*(M-1)//2 + N*(N-1)//2)

Measured memory_bytes: 7708
import java.util.Scanner;
import java.util.Arrays;

public class Main{

	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		
		// input
		final int NUM = scan.nextInt();
		int[] nums = new int[NUM];
		for(int i = 0; i < NUM; i++){
			nums[i] = scan.nextInt();
		}
		
		// copy&sort
		int[] numsCopy = nums.clone();
		Arrays.sort(numsCopy);
		int median1 = numsCopy[NUM / 2 - 1];
		int median2 = numsCopy[NUM / 2];
		
		// answer
		for(int i = 0; i < NUM; i++){
			if(nums[i] == median1){
				System.out.println(median2);
			} else if (nums[i] == median2){
				System.out.println(median1);
			} else if(nums[i] < median1) {
				System.out.println(median2);
			} else{
				System.out.println(median1);
			}
		}

	}
}

Measured memory_bytes: 91208
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>
using namespace std;

int main() {
	char S[4];
	cin>>S[0]>>S[1]>>S[2]>>S[3];
	if((S[0]==S[1]&&S[1]==S[2])||(S[1]==S[2]&&S[2]==S[3]))cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int main(){
  double n,t,a; cin>>n>>t>>a;

  double now=1000009;
  int index;
  rep(i,n){
    double h; cin>>h;
    double T=t-h*0.006;
    if(abs(a-T)<now){
      now=abs(a-T);
      index=i;
    }
  }
  cout<<index+1<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;
const int nmax=112345;

int n,v[112],v2;
ll w,dp[nmax],wi[112],w2;

int main()
{
    scanf("%d %lld",&n,&w);
    for(int i=0; i<n; ++i)
        scanf("%lld %d",&wi[i],&v[i]);
    int rmax=100012;
    for(int i=0; i<n; ++i)
    {
        for(int j=rmax; j>0; --j)
            if(dp[j]!=0)
            {
                w2=dp[j]+wi[i];
                v2=j+v[i];
                if(dp[v2]>w2 || dp[v2]==0)
                    dp[v2]=w2;
            }
        if(dp[v[i]]>wi[i] || dp[v[i]]==0)
            dp[v[i]]=wi[i];
    }
    ll res=0;
    for(int i=rmax; i>0; --i)
        if(dp[i]>0 && dp[i]<=w){
            res=i;
            break;
        }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    //abc137c
    int n; cin >> n;
    unordered_map<string, int> s;
    
    ll ans = 0;
    for(int i = 0; i < n; i++){
        string x;
        cin >> x;
        sort(x.begin(), x.end());
        s[x]++;
    }
    for(auto& p: s){
        int a = p.second;
        ans += (ll)a*(a-1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10660
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

a = 0
n,m = map(int,input().split())
if n>=2:
    a += combinations_count(n,2)
if m>=2:
    a += combinations_count(m,2)
print(a)

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long sum = a+b;
    long roop = n/sum;
    long ans = roop*a;
    if(n%sum != 0 && a != 0){
    	if((n-sum*roop)<a) {
    		ans +=n-sum*roop;
    	}
    	else {
    		ans += a;
    	}
    }
   System.out.println(ans);
  }
}

Measured memory_bytes: 23508
#include <iostream>
#include <vector>
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
static const int INF = 1<<21;
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int G[n][n];
    int d[n];
    int p[n];
    int color[n];
    for(int i=0;i<n;i++){
        for (int j=0; j<n; j++) {
            G[i][j] = -1;
        }
    }
    for(int i=0;i<n;i++){
        int u,k;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            int v,c;
            cin >> v >> c;
            G[u][v] = c;
        }
    }
    
    for (int i=0; i<n; i++) {
        color[i] = WHITE;
        p[i] = -1;
        d[i] = INF;
    }
    
    while(true){
        d[0] = 0;
        p[0] = 0;//?
        int u;
        int mincost = INF;
        //???????????????????±????
        for(int i=0;i<n;i++){
            if(d[i]<mincost && color[i]!=BLACK){
                mincost = d[i];
                u = i;
            }
        }
        color[u] = BLACK;
        if(mincost==INF) break;//?¶????????????????????????°??±?????£????????¨???
        
        for(int v=0;v<n;v++){
            if(G[u][v] != -1 && d[v]>d[u]+G[u][v]){
               d[v] = d[u] + G[u][v];
               color[v] = GRAY;//??????????????????
               p[v] = u;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout <<  i << " " << d[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3048
import java.util.Scanner;
public class Main 
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		
		int a = in.nextInt();
		int b = in.nextInt();
		
		int res = a * b;
		if(res % 2 == 0)
		{
			System.out.print("Even");
		}
		else
		{
			System.out.print("Odd");
		}
	}
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (int)(ceil(double(n)/double(m)))
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main(){
	int n , ans = 0 ;
	vi a(200005) ,pref(200005) , suf(200005);
	cin>>n ;
	f(n) cin>>a[i] ;
	for(int i=1 ;i<=n ; i++){
		pref[i] = __gcd( pref[i-1] , a[i]) ;
		//cout<<pref[i]<<" " ;
	}
	for(int i=n ;i>=1 ;i--){
		suf[i] = __gcd( suf[i+1]  , a[i]) ;
		//cout<<suf[i]<<" ";
	}
	f(n){
		ans = max( ans , __gcd( pref[i-1] , suf[i+1])) ;
	}
	cout<<ans ;
}

Measured memory_bytes: 4992
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
#include<stack>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;	
	vector<vector<int>>	tiles(H, vector<int>(W, 0));
	rep(i, H) {
		rep(j, W) {
			int c;	
			cin >> c;	
			tiles[i][j] = !c;	
		}
	}

	rep(i, W) {
		REP(j, 1, H) {
			tiles[j][i] += (!tiles[j][i]) ? 0 : tiles[j-1][i];
		}
	}

	long long res = 0;			
	for(const vector<int> &h : tiles) {
		vector<int> left(W, 0), right(W, 0);		
		stack<int> st;
		for(int i = 0; i < W; ++i) {
			while(!st.empty() && h[st.top()] >= h[i]) st.pop();	
			left[i] = (st.empty()) ? 0 : st.top() + 1; 
			st.push(i);
		}
		
		while(!st.empty()) st.pop();	
		
		for(int i = W - 1; i >= 0; --i) {
			while(!st.empty() && h[st.top()] >= h[i]) st.pop();	
			right[i] = (st.empty()) ? W : st.top(); 
			st.push(i);
		}

		for(int i = 0; i < W; ++i) {
			res = max(res, (long long)h[i] * (right[i] - left[i]));
		}
	}
	cout << res << endl;	
	return 0;
}

Measured memory_bytes: 8916
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	int s=0,a,b;
	int N;
	cin>>N;
	bool flag=0;
	while(N--)
	{
		cin>>a>>b;
//		s+=a==b;
		if(a==b)
		{
			s++;
			if(s>2)flag=1;
		}
		else s=0;
	}
//	puts(s>2?"Yes":"No");
	puts(flag?"Yes":"No");
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> a(N);
    rep(i,N)cin >> a[i];
    map<int,int> L;
    rep(i,N){
        L[a[i]] = 0;
        L[a[i]-1] = 0;
        L[a[i]+1] = 0;
    }
    rep(i,N){
        L[a[i]]++;
        L[a[i]-1]++;
        L[a[i]+1]++;
    }
    vector<int> X;
    for(auto itr = L.begin();itr != L.end();itr++){
        if(itr -> F == -1)continue;
        X.push_back(itr -> S);
    }
    sort(rall(X));
    cout << X[0] << endl;
}


Measured memory_bytes: 5756
#include <iostream>

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

  switch (N % 10) {
    case 2: case 4: case 5: case 7: case 9:
      std::cout << "hon\n";
      break;
    case 0: case 1: case 6: case 8:
      std::cout << "pon\n";
      break;
    case 3:
      std::cout << "bon\n";
      break;
  }
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <limits>
#include <cmath>

int main(){
  int n;
  std::cin >> n;
  std::vector<int> w;
  int temp;
  while(std::cin >> temp)
    w.push_back(temp);
  int sum = 0;
  for(auto i : w)
    sum += i;
  int ans = abs(2*w[0]-sum);
  temp = 0;
  for(auto i : w){
    temp += i;
    if(abs(2*temp-sum) < ans)
      ans = abs(2*temp-sum);
  }
  std::cout << ans << std::endl;
  return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
}c(200005);


//m^n
mint f(int m, int n) {
	if (0 == n) {
		return 1;
	}
	mint x = f(m, n / 2);
	x *= x;
	if (1 == n % 2) {
		x *= (mint)m;
	}
	return x;
}
// nCa
mint choose(int n, int a) {
	mint x = 1;
	mint y = 1;
	for (int m = 0; m < a; ++m) {
		x *= (mint)(n - m);
		y *= (mint)(a - m);
	}
	return x / y;
}
// nPk
mint nPk(int n, int a) {
	mint ret = choose(n,a);
	for (int n = 1;n<=a;++n) {
		ret *= n;
	}
	return ret;
}
vector<int>to[100005];
mint ans;
int K;
void dfs(int v, int p = -1) {
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		dfs(e, v);
	}
	if (-1 == p) {
		ans *= nPk(K-1,to[v].size());
	}
	else{
		ans *= nPk(K - 2, to[v].size()-1);
	}
}

int main() {
	int N;
	cin >> N >> K;
	for (int n = 0; n < N - 1; ++n) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans = K;
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15312
n=int(input())
a=[]
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.append(b)
a.append(c)
d=[]
cnd=a[0][0]
for i in range(n):
  for j in range(n):
    if i>j:
      cnd+=a[0][j]
    else:
      cnd+=a[1][j]
  d.append(cnd)
  cnd=a[0][min(n-1,i+1)]
print(max(d))

  


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

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> c(h);
  rep(i, h) cin >> c[i];
  rep(i, 2 * h) cout << c[i / 2] << endl;
  return 0;
}



Measured memory_bytes: 256
let rec f acc b = function
  | 0 -> acc
  | n -> f (n mod b + acc) b (n / b)
let f = f 0

let () = Scanf.scanf "%d %d" @@ fun n s ->
  let r = int_of_float @@ sqrt @@ float_of_int n in
  if n < s
  then print_endline "-1"
  else if n = s
  then Printf.printf "%d\n" (n + 1)
  else 
    try
      Array.init r (( + ) 2)
      |> Array.to_list
      |> List.find (fun b -> f b n = s)
      |> Printf.printf "%d\n"
    with Not_found ->
      try
        Array.init ((n - s) / (r - 1)) (( + ) 1)
        |> Array.to_list
        |> List.rev_map (fun p -> (n - s) / p + 1)
        |> List.filter (( <= ) 2)
        |> List.find (fun b -> f b n = s)
        |> Printf.printf "%d\n"
      with _ -> print_endline "-1"

Measured memory_bytes: 21280
n = int(input())
a = list(map(int, input().split()))
s = [0] * (10**5+10)
for x in a: s[x] += 1

ans = sum(a)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    ans -= b*s[b]
    ans += c*s[b]
    s[c] += s[b]
    s[b] = 0
    print(ans)


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<pair<pair<string, int>, int>> R(N);
  for (int i = 0; i < N; ++i) {
    cin >> R[i].first.first >> R[i].first.second;
    R[i].first.second *= -1;
    R[i].second = i + 1;
  }
  sort(R.begin(), R.end());
  for (int i = 0; i < N; ++i) cout << R[i].second << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
s=0
for i in range(1,n+2):
  s+=abs(a[i]-a[i-1])
# print(s)
for i in range(1,n+1):
  ans=s
  ans-=abs(a[i]-a[i-1])+abs(a[i+1]-a[i])
  ans+=abs(a[i+1]-a[i-1])
  print(ans)


Measured memory_bytes: 14048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main(){
int n,k;cin>>n>>k;
int ans=k;
for(int i=1;i<n;i++)ans*=k-1;
cout<<ans;
}

Measured memory_bytes: 504
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll C[Max];
ll n,A[Max],B[Max],ans,f=1;
void solve(){
	cin>>n;
	rep(i,0,n)cin>>A[i];
	rep(i,0,n)cin>>B[i];
	rep(i,0,n-1)cin>>C[i];
	ans = B[0];
	rep(i,1,n){
		ans+=B[i];
		if(A[i]-A[i-1] == 1){
			ans+=C[A[i-1]-1];
		}
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 4352
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    string S;
    int K;
    cin>>S>>K;
    set<string> se;
    for(int k=1;k<=K;k++){
        REP(i,SZ(S)-k+1){
            se.insert(S.substr(i,k));
        }
    }
    string ans;
    for(string s:se){
        if(K==1)
            ans=s;
        K--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1664
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <algorithm>


static int n;
static int d[5000];


static int u_lookup(int addr, int weight) {
	const int target = d[addr] + weight;
	int b = addr + 1, e = n;
	
	if (b >= n || d[b] > target || d[e - 1] < target) {
		return -1;
	}
	while (b < e) {
		const int m = (b + e) / 2;
		if (d[m] == target) {
			return m;
		}
		
		if (d[m] < target) {
			b = m + 1;
		}
		else {
			e = m;
		}
	}
	return -1;
}


int main(int argc, char* argv[]) {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &d[i]);
	}
	std::sort(d, d + n);

	int count_max = 2;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int count = 2;
			int k = j;
			for (;;) {
				k = u_lookup(k, d[j] - d[i]);
				if (k == -1) {
					break;
				}
				++count;
			}
			count_max = std::max(count_max, count);
		}
	}
	printf("%d\n", count_max);

	return EXIT_SUCCESS;
}



Measured memory_bytes: 2796
def main():
    ans = 0
    S = input()
    N = len(S)
    ans = 0
    now = 0
    skip = -1
    for i, s in enumerate(S):
        if i <= skip:
            continue
        if s == "A" and S[i+1:i+3] == "BC":
            now += 1
            ans += now
            skip = i+2
        elif s == "A":
            now += 1
        elif s == "B" and i < N-1 and S[i+1] == "C":
            ans += now
            skip = i+1
        else:
            now = 0
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42204
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int *l = (int *)calloc(n, sizeof(int));
  for(int i=0;i<n;i++){
    cin >> l[i];
  }

  sort(l, l+n);

  int len=0;
  for(int i=0;i<n-1;i++){
    len += l[i];
  }

  if(len>l[n-1]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int R, G, B, N; std::cin >> R >> G >> B >> N;
  int cnt = 0;
  for (int r = 0; r*R <= N; ++r) {
    for (int g = 0; r*R + g*G <= N; ++g) {
      int b = N - r*R - g*G;
      if (b%B == 0) ++cnt;
    }
  }
  std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;
long long int N,A,B;
long long int X[100001];
int main(){
  long long int ans=0;
  scanf("%lld %lld %lld",&N,&A,&B);
  for(int i=0;i<N;i++)scanf("%lld",&X[i]);
  for(int i=0;i<N-1;i++){
    int t=X[i+1]-X[i];
    if(t>B/A)ans+=B;
    else ans+=t*A;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1024
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for(int i = 0 ; i < 3 ; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(a);
        if(a[0] == a[1]){
            System.out.println(a[2]);
        }else{
            System.out.println(a[0]);
        }
    }
}

Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << 0 << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    cin >> N;
    cout << N*(N-1)/2 << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

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

  int n; cin >> n;
  ll cnt[5] = {};
  rep(i, n) {
    string s; cin >> s;
    if(s[0] == 'M') cnt[0]++;
    else if(s[0] == 'A') cnt[1]++;
    else if(s[0] == 'R') cnt[2]++;
    else if(s[0] == 'C') cnt[3]++;
    else if(s[0] == 'H') cnt[4]++;
  }

  ll ans = 0;
  rep(i, 5) {
    for(int j = i+1; j < 5; j++) {
      for(int k = j+1; k < 5; k++) {
        ans += cnt[i]*cnt[j]*cnt[k];
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;

string s;
map<char, int> mp;

int main() {
    cin >> s;
    int n = s.size();

    for (int i = 0; i < n; ++i) {
        mp[s[i]]++;
    }

    if (mp['N'] > 0 && mp['W'] > 0 && mp['E'] > 0 && mp['S'] > 0 || (mp['N'] > 0 && mp['S'] > 0 && mp['W'] == 0 && mp['E'] == 0) || ((mp['W'] > 0 && mp['E'] > 0 && mp['N'] == 0 && mp['S'] == 0))) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int W , H , x, y;
  cin >> W >> H >> x >> y;
  double S_ans = (double)W*(double)H/2.0;
  int div = 0;
  if(x==(double)W/2.0&&y==(double)H/2.0) div = 1;


  printf("%f %d\n",S_ans,div);
  return 0;
}


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

int main() {
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;

  int slen = tx-sx;
  int tlen = ty-sy;

  int rl = 2*slen+2*slen+4;
  int ud = 2*tlen+2*tlen+4;
  vector<string> ans(rl+ud);

  int index = 0;
  for (int i = 0;i < slen;i++){
      ans.at(index)="R";
      index+=1;
  }
  for (int j = 0;j < tlen;j++){
      ans.at(index)="U";
      index+=1;
  }

  for (int i = 0;i < slen;i++){
      ans.at(index)="L";
      index+=1;
  }
  for (int j = 0;j < tlen;j++){
      ans.at(index)="D";
      index+=1;
  }

  ans.at(index)="D";
  index+=1;
  for (int i = 0;i < slen+1;i++){
      ans.at(index)="R";
      index+=1;
  }
  for (int j = 0;j < tlen+1;j++){
      ans.at(index)="U";
      index+=1;
  }
  ans.at(index)="L";
  index+=1;

  ans.at(index)="U";
  index+=1;
  for (int i = 0;i < slen+1;i++){
      ans.at(index)="L";
      index+=1;
  }
  for (int j = 0;j < tlen+1;j++){
      ans.at(index)="D";
      index+=1;
  }
  ans.at(index)="R";

  for (int i = 0;i < rl+ud;i++){
    cout << ans.at(i);
  }







  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
using namespace std;
#define MAX 200005
#define MOD 1000000000
#define NINF -1000000000000000000
int pos[MAX];
int length[MAX];
int main()
{
    int n,i,inp,ans=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&inp);
        inp--;
        pos[inp]=i;
    }
    length[n-1]=1;
    for(i=n-2;i>=0;i--)
    {
        length[i]=1;
        if(pos[i+1]>pos[i])
        {
            length[i]=length[i]+length[i+1];
        }
        ans=max(ans,length[i]);
    }
    ans=n-ans;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys, math, fractions, itertools, bisect


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)

    counter = 0
    for j in range(N):
        b = B[j]
        ba = bisect.bisect_left(A, b)
        cb = N - bisect.bisect_right(C, b)
        counter += ba*cb
    
    print(counter)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 28000
#include<stdio.h>
int main()
{
	int a,b,c,t;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){t=a;a=b;b=t;}
	if(b>c){t=b;b=c;c=t;}
	if(a>b){t=a;a=b;b=t;}
	printf("%d\n",c-a);
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int kosu = sc.nextInt();
        int ond = sc.nextInt();
        int base = sc.nextInt();
        
      	int ans = -1;
      	double mm =Double.MAX_VALUE;
        for(int i=0;i < kosu;i++){
			double nam = Math.abs(base-(ond-0.006*sc.nextInt()));
			    if(nam <mm ) {
				    mm = nam;
				    ans = i + 1;
			}
      }

        System.out.println(ans);
    }
}


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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define mp make_pair
#define F first
#define S second


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j,ans=0;
	ll n;
	cin>>n;
	ll a[n],x[n][n],y[n][n];
	rep(i,0,n){
	    cin>>a[i];
	    rep(j,0,a[i]){
	        cin>>x[i][j]>>y[i][j];
	    }
	}
	ll p,l,k,c=0,m;
	rep(i,0,pow(2,n)){
	    c=0;
	    for(j=1;j<pow(2,n);j=j<<1){
	       
	        if(j&i){
	            c++;
	            p=log2(j);
	            rep(k,0,a[p]){
	                m=(1<<(x[p][k]-1));
	                if((y[p][k]&&!(m&i))||(!y[p][k]&&(m&i)))
	                    break;
	            }
	            if(k!=a[p])
	                break;
	        }
	    }if(j<pow(2,n))
	        continue;
	   ans=max(ans,c);
	}cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
 int main(){
 	int i=0,x=0,y=0,k,h;
 	int data[3000];
 	int data2[3000];
 	while(1){
 		scanf("%d %d",&data[x],&data2[y]);
 		if(data[x]>data2[y]){
 			h = data[x];
 			data[x] = data2[y];
 			data2[y] = h;
 		}
 		if(data[x]==0 && data2[y]==0)break;
 		x++;
 		y++;
 		i++;
 	}
 	for(k=0;k<i;k++){
 	printf("%d %d\n",data[k],data2[k]);
 	}
 }

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
int func(int x,int y){
	if(y==0)return 1;
	int ret = 1;
	for(int i=1;i<=y;i++){
		ret*=x;
	}
	return ret;
}
int main(void){
	int L;
	cin >> L;
	int N,r=1,X=2;
	while(X<=L){
		r++;
		X*=2;
	}
	r--;
	N = r + 1;
	vector<tuple<int,int,int>> v;
	for(int i = 1;i<N;i++){
		v.push_back(make_tuple(i,i+1,0));
		v.push_back(make_tuple(i,i+1,func(2,i-1)));
		//printf("%d %d %d\n",i,i+1,0);
		//printf("%d %d %d\n",i,i+1,func(2,i-1));
	}                            
	for(int i=N-1;i>=1;i--){
		if( (L-func(2,i-1) ) >=func(2,r) ){
			//printf("%d %d %d\n",i,N,L-func(2,i-1));
			v.push_back(make_tuple(i,N,L-func(2,i-1)));
			L-=func(2,i-1);
		}
	}
	cout << N <<" " << v.size() << endl;
	for(int i=0;i<v.size();i++){
		cout << get<0>(v[i]) <<" "<< get<1>(v[i]) <<" "<< get<2>(v[i]) <<endl;
	}
}

Measured memory_bytes: 256
/**
 * 	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;



int main(){
    int N;
    cin >> N;
    vector<int> W(N);
    // vector<int> S1(N);
    // vector<int> S2(N);
    for(int i = 0; i < N ;i++){
        cin >> W[i];
    }

    int ans = __INT_MAX__;
    for(int T = 1 ; T < N-1 ; T++){
        int S1 = 0;
        int S2 = 0;
        for(int i = 0; i <= T ;i++){
            S1 += W[i];
        }
        for(int i = T + 1; i < N ;i++){
            S2 += W[i];
        }
        ans = min(ans, abs(S1-S2));
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//1行目の整数を読み込む
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		//A+B,A-B,A×Bを計算する
		int AplusB = A+B ;
		int AminusB = A-B;
		int AmultiplyB = A*B;
		
		//3つの計算結果を比較し、最大のものを変数maxに入れる
		int max;
		max = AplusB;
		
		if(AplusB < AminusB) {
			max = AminusB;
			if (AminusB < AmultiplyB) {
				max = AmultiplyB;
			}
		}else if(AplusB < AmultiplyB){
			max = AmultiplyB;
		}
		
		System.out.println(max);
			
	}
}


Measured memory_bytes: 23764
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a1 = Integer.parseInt(sc.next());
        int a2 = Integer.parseInt(sc.next());
        int a3 = Integer.parseInt(sc.next());

        // 主処理
        int[] a = new int[] { a1, a2, a3 };
        Arrays.sort(a);

        int result = 0;
        result += a[1] - a[0];
        result += a[2] - a[1];

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


Measured memory_bytes: 22484
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n;
string s;
ll cnt[4][4005];
int32_t main(){
CODE_START;
cin>>n;
cin>>s;
for(ll i=0;i<s.size();i++)
{
    if(i!=0){
    cnt[0][i]=cnt[0][i-1];
    cnt[1][i]=cnt[1][i-1];
    cnt[2][i]=cnt[2][i-1];
    }
    if(s[i]=='R'){
       cnt[0][i]++;
    }else if(s[i]=='B'){
    cnt[1][i]++;
    }else {
        cnt[2][i]++;
    }
    if(s[i]=='R'){
        s[i]='0';
    }else if(s[i]=='B'){
    s[i]='1';
    }else s[i]='2';
}
ll ans=0;
for(ll i=0;i<s.size()-2;i++)
{
    for(ll j=i+1;j<s.size()-1;j++)
    {
        if(s[i]!=s[j]){
                ll val=-1;
                for(char c='0';c<='2';c++)
                {
                    if(s[i]!=c&&s[j]!=c){
                    val=c-'0';
                    break;
                }
                }
                ll s1=cnt[val][n-1]-cnt[val][j];
                if(j+j-i<s.size()&&s[j+j-i]==val+'0'){
                    s1--;
                }
                ans=ans+max(0LL,s1);
    }
    }
}
cout<<ans<<endl;
}


Measured memory_bytes: 3716
#include <iostream>

using namespace std;

int main(){
	int prime[10000],p = 3,n;
	bool isprime[50001];
	prime[1] = 2,prime[2] = 3;
	isprime[1] = isprime[4] = false;
	isprime[2] = isprime[3] = true;
	for(int i=5;i < 50001;i++){
		int f = 0;
		for(int j=1;prime[j]*prime[j] <= i;j++) if(i % prime[j] == 0) {f = 1;break;}
		if(!f) prime[p++] = i,isprime[i] = true;
		else isprime[i] = false;
	}
	
	while(1){
		int out = 0;
		cin >> n;
		if(!n) break;
		for(int i = 1;n >= 2 * prime[i];i++) if(isprime[n-prime[i]]) out++;
		cout << out << endl;
	}
		
	return 0;
}

Measured memory_bytes: 940
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<string>

using namespace std;

int main(){
    int i,j,k;
    int N,K;
    string S;
    cin >> N >> K ;
    cin >> S;
    if(S[K-1]=='A') S[K-1]='a';
    if(S[K-1]=='B') S[K-1]='b';
    if(S[K-1]=='C') S[K-1]='c';
    cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
using namespace std;
 
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  
  double a,b,x;
  double PI = 3.141592653589793;
  double y,deg,tan;
  
  cin >> a >> b >> x;
  if(pow(a, 2.0)*b<=2*x){
    tan = (2*pow(a, 2.0)*b-2*x)/pow(a, 3.0);
  }
  else{
    tan = (pow(b, 2.0)*a)/(2*x);
  }
  y = atan(tan);
  deg = y*180/PI;
  
  cout << std::setprecision(10) << deg << endl;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

const int max_n = 8100;
bool pos_x[max_n][max_n*2];
bool pos_y[max_n][max_n*2];
signed main()
{
    gearup;
    int n; cin >> n;
    vl a(n);
    rep(i,n)cin>>a[i];
    if(a[0] != 0){
        out(-1);
        return 0;
    }

    ll res = 0;
    rep(i,n-1){
        if(a[i+1] > i+1){
            out(-1);
            return 0;
        }
        if(a[i] + 1 == a[i+1])res++;
        else if(a[i] >= a[i+1])res += a[i+1];
        else {
            out(-1);
            return 0;
        }
    }
    out(res);
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b,c;
  cin >> a >> b >> c;
  if (a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            String S = in.next();
            char[] cs = S.toCharArray();

            ArrayList<Integer> l = new ArrayList<>();
            char prev = cs[0];
            int count = 1;
            for (int i = 1; i <= cs.length; i++) {
                if (i == cs.length || cs[i] != prev) {
                    l.add(prev == '.' ? count : -count);
                    count = 0;
                    if (i == cs.length) {
                        continue;
                    }
                }
                count++;
                prev = cs[i];
            }

            if (l.size() > 0 && l.get(0).intValue() > 0) {
                l.remove(0);
            }
            if (l.size() > 0 && l.get(l.size() - 1).intValue() < 0) {
                l.remove(l.size() - 1);
            }

            l.add(0, 0);
            l.add(0);

//            Utils.debug(l);

            int[] cumsumW = new int[l.size()];
            int[] cumsumB = new int[l.size()];
            for (int i = 0; i < l.size(); i++) {
                int n = l.get(i).intValue();
                cumsumW[i] = (n <= 0 ? -n : 0) + (i - 1 >= 0 ? cumsumW[i - 1] : 0);
            }
            for (int i = l.size() - 1; i >= 0; i--) {
                int n = l.get(i).intValue();
                cumsumB[i] = (n >= 0 ? n : 0) + (i + 1 < l.size() ? cumsumB[i + 1] : 0);
            }

            int res = (int) 1e9;
            for (int i = 0; i + 1 < l.size(); i++) {
                res = Math.min(res, cumsumW[i] + cumsumB[i + 1]);
//                Utils.debug(i, cumsumW[i], cumsumB[i + 1], cumsumW[i] + cumsumB[i + 1]);
            }

            System.out.println(res);
        }
    }
}


Measured memory_bytes: 32768
// Template
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep3(i, l, r) for (ll i = (ll)(l); i < (ll)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

struct S {
    ll zero, one, t, t_;
};

S op(S x, S y) {
    return S{x.zero + y.zero, x.one + y.one, x.t + y.t + x.one * y.zero, x.t_ + y.t_ + x.zero * y.one};
}

S e() {
    return S{0, 0, 0, 0};
}

using F = int;

S mapping(F f, S x) {
    if (f) return S{x.one, x.zero, x.t_, x.t};
    else return x;
}

F composition(F f, F g) {
    return f ^ g;
}

F ide() {
    return 0;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<S> a;
    rep(i, n) {
        int a_;
        cin >> a_;
        if (a_) a.push_back(S{0, 1, 0, 0});
        else a.push_back(S{1, 0, 0, 0});
    }
    
    lazy_segtree<S, op, e, F, mapping, composition, ide> st(a);
    
    rep(i, q) {
        int t, l, r;
        cin >> t >> l >> r;
        --l;
        if (t == 1) st.apply(l, r, 1);
        else cout << st.prod(l, r).t << "\n";
    }
}


Measured memory_bytes: 26912
X,Y = (int(x) for x in input().split())
Flag = False
for A in range(0,X+1):
    for B in range(0,X+1):
        if A+B==X and 2*A+4*B==Y:
            Flag = True
    if Flag:
        break
if Flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 63816
n = input()

v = input()
v = v.split(' ')
v = [int(a) for a in v]

c = input()
c = c.split(' ')
c = [int(a) for a in c]

r = 0
for value, cost in zip(v, c):
    profit = value - cost
    if profit > 0:
        r += profit

print(r)


Measured memory_bytes: 3060
N,K = map(int,input().split())
S = input()
switch = 0
ans = 0
for i in range(1,len(S)):
    if S[i] != S[i-1]:
        switch += 1
    else:
        ans += 1
for i in range(K):
    if switch == 0:
        break
    elif switch == 1:
        switch -= 1
        ans += 1
    else:
        switch -= 2
        ans += 2
print(ans)

Measured memory_bytes: 3316