akhauriyash/Code-Regression huggingface dataset:
/*
* @Author: kabbo
* @Date:   2020-05-02 18:14:53
* @Last Modified by:   kabbo
* @Last Modified time: 2020-05-02 18:17:51
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define endl '\n'
#define ull unsigned long long
#define ll long long
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
void solve() {
	int k;
	cin >> k;
	int a, b;
	cin >> a >> b;
	int m_n = (a / k) * k;
	int m_x = (b / k) * k;
	bool flag = false;
	if (m_n >= a && m_n <= b)
		flag = true;
	else if (m_x >= a && m_x <= b)
		flag = true;
	if (flag)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;

}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	//cin >> t;
	//for (int i(1); i <= t; ++i) {
	//printf("Case %d: ", i);
	solve();
	//}
#ifndef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
	return 0;
}

Measured memory_bytes: 3800
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [ [0 for _ in range(W+1)] for _ in range(N+1) ]

for i in range(1, N+1):
    for j in range(1, W+1):
        if j < w[i-1]:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1])

print(dp[N][W])

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

int main(){

	int n, p, pt;
	
	while(cin >> n){
		if(n == 0) break;

		pt = 0;
		for(int i=0; i<n/4; i++){
			cin >> p;
			pt += p;
		}
		
		cout << pt << endl;
	}

	return 0;

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
int main() {
	int a[6];
	for (int i = 1; i <= 5; i++) {
		cin >> a[i];
		if (a[i] != i) {
			cout << i; break;
	}

	}


	return 0;
}

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

S = []
for i in range(N):
    string = input()
    string = list(string)
    string.sort()
    string = ''.join(string)
    S.append(string)

S.sort()

ans = 0
cnt = 1
for i in range(1, N):
    if S[i] == S[i-1]:
        cnt += 1
    else:
        ans += cnt*(cnt-1) // 2
        cnt = 1

ans += cnt*(cnt-1) // 2
print(ans)

Measured memory_bytes: 10616
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;

const int BIG_NUM = 1e9;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end());
    int count = 0;
    for(int i = n - 1; i >= 0; i--) {
        if(a[i] * 4 * m >= sum) {
            count++;
        } else {
            break;
        }
    }
    if(count >= m) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3612
L,R=map(int,input().split())

m=2018

for i in range(L,min(R+1,L+2019)):
    for j in range(i+1,min(R+1,L+2019)):
        if i*j%2019<m:
            m=i*j%2019
        if m==0:
            break

print(m)
            


Measured memory_bytes: 2940
#include<iostream>
#define MAXN 500000+5
using namespace std;
int a[MAXN];
int t[MAXN];
int count=0;
void merge(int* A,int x,int y,int* T)
{
	if(y-x>1)
	{
		int mid=x+(y-x)/2;
		int p=x,q=mid,i=x;
		merge(A,x,mid,T);
		merge(A,mid,y,T);
		while(q<y||p<mid)
		{
			if(q>=y||(p<mid&&A[p]<=A[q]))T[i++]=A[p++];
			else T[i++]=A[q++];
			count++;
		}
		for(i=x;i<y;i++)
		    A[i]=T[i];
	}
}
int main()
{
	int n;
	int i,j;
	cin>>n;
	for(i=0;i<n;i++)
	    cin>>a[i];
	merge(a,0,n,t);
	for(i=0;i<n-1;i++)
	    cout<<t[i]<<' ';
	cout<<t[n-1]<<endl;
	cout<<count<<endl;    
	return 0;
}

Measured memory_bytes: 6888
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
// #define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#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 ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }
  void solve()
  {
  	string s;
  	cin>>s;
  	if(s.back()!='s')
  	{
  		s+='s';
  	}
  	else s+="es";


  	cout<<s;



  }
  
  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
    #endif
int t=1;
while(t--)
{
  solve();
}

    return 0;
  }


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		boolean possible = false;

		for (int i = 0; i < 26; i++) {
			sum = 0;
			for (int j = 0; j < 16; j++) {
				if (4 * i + 7 * j == N) possible = true;
			}
		}

		if (possible) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int t[100003], x[100003], y[100003];

int main() {
	int n; cin >> n;
	t[0] = x[0] = y[0] = 0;
	for (int i = 1; i <= n; ++i) cin >> t[i] >> x[i] >> y[i];
	bool ans = true;
	for (int i = 0; i < n; ++i) {
		int tt = t[i + 1] - t[i];
		ans &= abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]) <= tt;
		tt -= abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		ans &= tt % 2 == 0;
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s="";
	char c;
	rep(i,3){
		rep(j,3){
			cin>>c;
			if(i==j)s+=c;
		}
	}
	cout<<s<<endl;
	return 0;
}

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

int N, M, R;
int r[8];
const int MAX_N = 202;
int mp[MAX_N][MAX_N];
const int INF = (1<<29);

void warshall_floyd() {
    for(int k = 0; k < N; ++k)
        for(int i = 0; i < N; ++i) 
            for(int j = 0; j < N; ++j)
                mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
}


int main()
{
    cin >> N >> M >> R;
    for(int i = 0; i < N; ++i) 
        for(int j = 0; j < N; ++j) 
            if(i != j) mp[i][j] = 1e8;

    for(int i = 0; i < R; ++i) { cin >> r[i]; --r[i]; }
    for(int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        mp[a][b] = mp[b][a] = c;
    }

    warshall_floyd();

    int res = INF;
    vector<int> P(R);
    for(int i = 0; i < R; ++i) P[i] = i;
    do {
        int tmp = 0;
        for(int i = 1; i < R; ++i) {
            int j = r[P[i-1]], k = r[P[i]];
            tmp += mp[j][k];
        }
        res = min(res, tmp);
    } while(next_permutation(P.begin(), P.end()));
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
use std::io;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {

    let n = read_one::<usize>();

    let mut x = read::<usize>();
    let y = x.clone();

    x.sort();

    let large = x[n/2];
    let small = x[(n-2)/2]; 

    for i in 0..n {
        if y[i] <= small {
            println!("{}", x[n/2]);
        } else if y[i] >= large {
            println!("{}", x[n/2 - 1]);
        }
    }
}

Measured memory_bytes: 10492
#include <iostream>

int main(void) {
	int r, D, startX = 0;
	std::cin >> r;
	std::cin >> D;
	std::cin >> startX;

	int X[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	
	X[0] = startX;

	for (int ii = 0; ii < 10; ii++) {
		X[ii + 1] = r * X[ii] - D;
		std::cout << X[ii + 1] << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    bool flag=true;
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n/2+i])flag=false;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
// AOJ ALDS1_5_B Merge Sort
// 2018.4.30 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int w;
	if (!n) { pc('0'); return; }
	w = 0; while (n) buf[w++] = n%10 + '0', n/=10;
	while (w--) pc(buf[w]);
}

#define MAX_N 500002
int *a;
int w[MAX_N/2+2];
int cnt;

void merge(int low, int high) 
{ 
   int i, j, k, p, mid; 

   if (low < high) {
	   mid = (low + high) >> 1;
	   merge(low, mid);
	   merge(mid+1, high);

	   p = mid-low+1; cnt += high-low+1;
	   memcpy(w, a+low, p << 2);
	   i = mid+1, j = 0, k = low;
	   while (i <= high && j < p) {
		   if (w[j] <= a[i]) a[k++] = w[j++];
		   else              a[k++] = a[i++];
	   }
	   while (j < p) a[k++] = w[j++];
   }
}

void merge_sort(int n, int *aa)
{
	a = aa;
	merge(0, n-1);
}

int aa[MAX_N];

int main()
{
	int n, i;
	
	n = in();
	for (i = 0; i < n; i++) aa[i] = in();
	cnt = 0;
	merge_sort(n, aa);
	mypr(a[0]); for (i = 1; i < n; i++) pc(' '), mypr(a[i]);
	pc('\n');
	mypr(cnt);
	pc('\n');
	return 0;
}


Measured memory_bytes: 4532
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int MAX = 100010;

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

    vector<vector<int>> dp(n+1, vector<int>(2));  // dp[i][j] : 

    dp[0][0] = 1;
    rep(i, n) {
        // a+b = 0
        if(s[i] == '0') {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
        }
        else {
            dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
        } 
        // a+b = 1
        if(s[i] == '0') {
            (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
        }
        else {
            (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
            (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
        }
    }

    cout << (dp[n][0] + dp[n][1])%mod << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    bool yes_or_no = true;
    if (a >= b || a >= c || b >= c) yes_or_no = false;
    if (yes_or_no) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int f(int a,int b,vector<int> v){
    if(a<b)return 0;
    int n=v.size();
    sort(v.begin(),v.end(),greater<int>());
    int dp[n+1][51];
    rep(i,0,n+1)fill(dp[i],dp[i]+51,0);
    dp[0][a]=1;
    rep(i,0,n){
        rep(j,0,51){
            if(dp[i][j]==0)continue;
            dp[i+1][j]=1;
            dp[i+1][j%v[i]]=1;
        }
    }
    if(dp[n][b])return 1;
    else return 0;
}
int main(){
    int n;cin>>n;
    int a[n];rep(i,0,n)cin>>a[i];
    int b[n];rep(i,0,n)cin>>b[i];
  vector<int> vv;

    int d[51][51][51];
    rep(i,0,51)rep(j,0,51)rep(k,0,51)d[i][j][k]=0;
    d[0][0][0]=1;
    d[1][0][1]=1;
    d[1][0][0]=1;
    d[1][1][0]=1;
    rep(i,2,51){
        rep(j,0,i+1){
            if(i==j){
                d[i][j][0]=1;
                continue;
            }
            rep(k,1,i+1){
                int u=i%k;
                if(d[u][j][0]==1){
                    d[i][j][k]=1;
                    d[i][j][0]=1;
                }
                
            }
        }
    }
    int mi[51][51];
    rep(i,0,51)fill(mi[i],mi[i]+51,100);
    rep(i,0,51){
        rep(j,0,51){
            rep(k,1,51){
                if(d[i][j][k]==1){
                    mi[i][j]=k;
                    break;
                }
            }
        }
    }
    rep(i,0,n){
        if(d[a[i]][b[i]][0]==0){
            cout<<-1<<endl;
            return 0;
        }
    }
  rep(i,1,51)vv.push_back(i);
  rrep(i,50,1){
    rep(j,0,vv.size()){
      if(vv[j]==i){
        vv.erase(vv.begin()+j);
        break;
      }
    }
    int g=1;
    rep(j,0,n){
      int d=f(a[j],b[j],vv);
      if(d==0){
        g=0;
        break;
      }
    }
    if(g==0){
      vv.push_back(i);
    }
  }
  ll anss=0;
  rep(i,0,vv.size()){
    ll o=pow(2,vv[i]);
    anss+=o;
  }
  cout<<anss<<endl;
  return 0;
}

Measured memory_bytes: 768
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
    n, u, v = map(int,input().split())
    if u == v:
        print(0)
        sys.exit()

    graph = [[] for _ in range(n)]
    depth_u = [-1] * (n) #頂点iのuから見た深さ
    depth_v = [-1] * (n) #頂点iのvから見た深さ
    u -= 1 #高橋
    v -= 1 #青木
    for i in range(n-1):
        a, b = map(int,input().split())
        graph[a - 1].append(b - 1)
        graph[b - 1].append(a - 1)
    
    # bfsで高橋から見た各頂点の深さをメモる。
    queue = deque([u])
    visited = [False]*n
    visited[u] = True
    depth_u[u] = 0
    while queue:
        node = queue.popleft()
        for xnode in graph[node]:
            if not visited[xnode]:
                visited[xnode] = True
                depth_u[xnode] = depth_u[node] + 1
                queue.append(xnode)
    # bfsで青木から見た各頂点の深さをメモる。
    queue = deque([v])
    visited = [False]*n
    visited[v] = True
    depth_v[v] = 0
    while queue:
        node = queue.popleft()
        for xnode in graph[node]:
            if not visited[xnode]:
                visited[xnode] = True
                depth_v[xnode] = depth_v[node] + 1
                queue.append(xnode)
    ans = 0
    max_d_v = 0
    for i in range(n):
        if depth_u[i] < depth_v[i]:
            max_d_v = max(max_d_v, depth_v[i])
    print(max_d_v - 1)



if __name__=='__main__':
    main()

Measured memory_bytes: 89688
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

int main(){
   int n;
   cin>>n;
   string s,t;
   cin>>s>>t;
   REP(i,2*n){
       if(i%2==0){
           printf("%c",s[i/2]);
       }else{
          printf("%c",t[i/2]);
       }
   }
   printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Pos{
  int x,y;
  Pos(int a,int b){
    x=a;
    y=b;
  }
};

class Field{
  int cell_[10][5]={};
  int height_;

  void FallBlock(void){
    for(int col=0;col<5;col++){
      bool found_empty=false;
      int empty_row=11;
      for(int row=height_-1;row>=0;row--){
        if(!found_empty){
          if(cell_[row][col]==0){
            found_empty=true;
            empty_row=row;
          }
        }else{
          if(cell_[row][col]!=0){
            cell_[empty_row][col]=cell_[row][col];
            cell_[row][col]=0;
            empty_row--;
          }
        }
      }
    }
  }

  int EraseBlock(void){
    int result=0;
    std::vector<Pos> erased_pos;
    for(int row=0;row<height_;row++){
      for(int col_left=0;col_left<=2;col_left++){
        if(cell_[row][col_left]==cell_[row][col_left+1]&& cell_[row][col_left]==cell_[row][col_left+2]){
          erased_pos.push_back(Pos(row,col_left));
          erased_pos.push_back(Pos(row,col_left+1));
          erased_pos.push_back(Pos(row,col_left+2));
          int color=cell_[row][col_left];
          for(int add_col=col_left+3;add_col<5;add_col++){
            if(color==cell_[row][add_col]){
              erased_pos.push_back(Pos(row,add_col));
            }else break;
          }
          break;
        }
      }
    }
    for(auto tgt:erased_pos){
      result+=cell_[tgt.x][tgt.y];
      cell_[tgt.x][tgt.y]=0;

    }
    return result;
  }

public:
  Field(int h){
    height_=h;
  }
  void Set(int row,int col,int num){
    cell_[row][col]=num;
  }
  int Calc(void){
    int result=0;
    int in_turn=0;
    do{
      in_turn=EraseBlock();
      FallBlock();
      result+=in_turn;
    }while(in_turn>0);

    return result;

  }

};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  while(1){
    int h;
    cin>>h;
    if(h==0) break;
    Field field(h);
    for(int i=0;i<h;i++){
      for(int j=0;j<5;j++){
        int num;
        cin>>num;
        field.Set(i,j,num);
      }
    }
    cout<<field.Calc()<<endl;
  }

  return 0;
}



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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl;
#define CNO cout<<"No"<<endl;

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  int a=0,b=0;
  int x=0;
  string s;
  int ans=0;
  rep(i,n){
    cin >> s;
    if(s[s.size()-1]=='A') a++;
    if(s[0]=='B') b++;
    if(s[s.size()-1]=='A'&&s[0]=='B') x++;
    rep(j,s.size()-1){
      if(s[j]=='A'&&s[j+1]=='B') ans++;
    }
  }
  if(a-x>0||b-x>0) ans+=min(a,b);
  else ans+=max(0,min(a,b)-1);
  cout << ans << endl;
  return 0;
}


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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

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

  vector<char> v;
  for (int i = 0; i < s.length(); ++i) {
    if (i % n == 0) {
      v.push_back(s[i]);
    }
  }

  p(string(v.begin(), v.end()));
}

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

int main(void){

    int N,nmax = 0,last = 0;
    cin >> N;
    int data[N];
    for(int i=0;i<N;i++) cin >> data[i];
    
    for(int i=1;i<N;i++){
        if(data[i-1] >= data[i]){
            nmax++;
        }
        else{
            if(nmax >= last){
                last = nmax;
                nmax = 0;
            }
            else{
                nmax = 0;
            }
        }
    }
    cout << max(nmax,last) << endl;
}


Measured memory_bytes: 3960
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
 
int main () {
	int a,b,c;
	cin >> a  >> b >>c;
	if (a == b  && b== c) cout << 1 << endl;
	else if (a == b || b == c || a ==c) cout << 2 << endl;
	else cout << 3 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<int,int> P;

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e>> k;
    string ans="Yay!";
    if(e-a>k){
        ans=":(";
    }
    cout << ans << endl;
    return 0;
}



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

// Function to find the minimum number
// character change required

void change(string s)
{

    // Finding the length of the string
    int n = s.length();

    // To store the number of replacement operations
    int cc = 0;

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

        // If the characters at location
        // i and n-i-1 are same then
        // no change is required
        if(s[i]== s[n-i-1])
            continue;

        // Counting one change operation
        cc+= 1;

        // Changing the character with higher
        // ascii value with lower ascii value
        if(s[i]<s[n-i-1])
            s[n-i-1]= s[i] ;
        else
            s[i]= s[n-i-1] ;
    }
    printf("%d\n", (cc)) ;
   // cout<<s<<endl;
}
// Driver code
int main()
{
    string s ;
    cin>>s;

    change((s));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<ll> vint;
int main() {
  ll n;
  cin >> n;
  vint a(n),b(n);
  for (ll i=0;i<n;i++) {
    cin >> a.at(i);
    b.at(i)=a.at(i);
  }
  
  ll ans1=0,ans2=0,sum=0;
  for (ll i=0;i<n;i++) {
    if (i%2==0 && sum+a.at(i) <= 0) {
      ans1 += -sum-a.at(i)+1;
      a.at(i) = -sum+1;
    }
    if (i%2==1 && sum+a.at(i) >= 0) {
      ans1 += sum+a.at(i)+1;
      a.at(i) = -sum-1;
    }
    sum += a.at(i);
  }
  
  sum=0;
  for (ll i=0;i<n;i++) {
    if (i%2==1 && sum+b.at(i) <= 0) {
      ans2 += -sum-b.at(i)+1;
      b.at(i) = -sum+1;
    }
    if (i%2==0 && sum+b.at(i) >= 0) {
      ans2 += sum+b.at(i)+1;
      b.at(i) = -sum-1;
    }
    sum += b.at(i);
  }
  
  cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 1792
import bisect
n = int(input())
a = list(map(int, input().split())); a.sort()
b = list(map(int, input().split())); b.sort()
c = list(map(int, input().split())); c.sort()
ab = [0 for i in range(n)]
ans = 0

for i in range(n):
  ab[i] = ab[i-1] + bisect.bisect_left(a, b[i])
for i in range(n):
  tmp = bisect.bisect_left(b, c[i])
  if tmp != 0:
  	ans += ab[tmp-1] 

print(ans)


Measured memory_bytes: 29488
n = int(input())
a=[0]*4
k=['AC','WA','TLE','RE']
for x in range(n):
    s=input()
    if s=='AC':
        a[0]+=1
    if s=='WA':
        a[1]+=1
    if s=='TLE':
        a[2]+=1
    if s=='RE':
        a[3]+=1
z=' x '
for i in range(4):
    print(k[i]+z+str(a[i]))
    


Measured memory_bytes: 74704
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;


int main(){
	fastio();
	deque<char> s;
	string read; cin >> read;
	for(char x: read) s.push_back(x);
	int q; cin >> q;
	bool flip = false;
	while(q--){
		int t; cin >> t;
		if (t == 1) flip = !flip;
		if (t == 2){
			int f; char c;
			cin >> f >> c; f--;
			if (flip) f ^= 1;
			if (f == 0) s.push_front(c);
			else if (f == 1) s.push_back(c);
		}
	}
	string ans = ""; for(char x: s) ans.push_back(x);
	if (flip) reverse(ans.begin(), ans.end());
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1368
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #整数1つinput
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii())
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #文字列1つinput
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

n,w = mii()
wei=[]
val=[]
for i in range(n):
    ww,vv=map(int,input().split())
    wei.append(ww)
    val.append(vv)
#dp[i][j]:i番目まで選んで、価値がj以上となる最小の重さ
dp=[[10**10]*(sum(val)+1) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
    for j in range(sum(val)+1):
        if j>=val[i]:
            dp[i+1][j]=min(dp[i][j-val[i]]+wei[i],dp[i][j])
        else:
            dp[i+1][j]=dp[i][j]
ans=[]
for i in range(sum(val)+1):
    if dp[n][i]<=w:
        ans.append(i)
print(max(ans))

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

const int MAX = 2e5+10;

int N;

int main() {
    cin >> N;
    ll ans = 0;
    map<ll, int> m;
    REP (i, N) {
        int a; cin >> a;
        ans += m[i-a];
        m[i+a]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 26340
N = gets.to_i
n3 = N / 3
n5 = N / 5
n15 = N / 15

sn = N * (N + 1) / 2
s3n = 3 * n3 * (n3 + 1) / 2
s5n = 5 * n5 * (n5 + 1) / 2
s15n = 15 * n15 * (n15 + 1) / 2

puts sn - s3n - s5n + s15n


Measured memory_bytes: 14296
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[110000],cnt[110000];
vector<int> vs,v1;
int n,m;

bool check(int p){
	int i,j;
	int a,b,c;
	set<int> s1;
	if(p==m){
		for(i=(int)vs.size()-m;i<(int)vs.size();i++){
			if(s1.find(vs[i])!=s1.end())return false;
			s1.insert(vs[i]);
			if(i && t[vs[i-1]]==vs[i])return false;
		}
		return true;
	}
	for(i=0;i<v1.size();i++){
		vs.push_back(v1[i]);
		if(check(p+1))return true;
		vs.pop_back();
	}
	return false;
}

int main(){
	int i,j,k;
	int a,b,c;
	const int M=5;
	set<int> s1;
	cin>>n;
	for(i=0;i<n;i++){
		s1.insert(i);
	}
	for(i=0;i<n;i++){
		cin>>t[i];
		t[i]--;
		cnt[t[i]]++;
	}
	t[n]=-1;
	if(n>M){
		for(i=0;i<n-M;i++){
			if(!vs.empty())a=vs.back();
			else a=n;
			auto itr=s1.begin();
			b=*itr,c=t[b];
			if(cnt[b]<cnt[c])swap(b,c);
			if(cnt[b]==n-i-1){
				vs.push_back(b);
				s1.erase(b);
				cnt[t[b]]--;
				continue;
			}
			if(*itr==t[a])itr++;
			b=*itr;
			vs.push_back(*itr);
			s1.erase(itr);
			cnt[t[b]]--;
		}
	}
	for(auto node:s1)v1.push_back(node);
	sort(v1.begin(),v1.end());
	m=v1.size();
	if(check(0)){
		for(i=0;i<n;i++)vs[i]++;
		array_show(vs);
	}else cout<<-1<<endl;
}

Measured memory_bytes: 9100
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
	if(a>b)
		swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
	char str[100];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
	sprintf(str,"%s.out",s);
	freopen(str,"w",stdout);
#endif
}
int rd()
{
	int s=0,c;
	while((c=getchar())<'0'||c>'9');
	do
	{
		s=s*10+c-'0';
	}
	while((c=getchar())>='0'&&c<='9');
	return s;
}
int upmin(int &a,int b)
{
	if(b<a)
	{
		a=b;
		return 1;
	}
	return 0;
}
int upmax(int &a,int b)
{
	if(b>a)
	{
		a=b;
		return 1;
	}
	return 0;
}
pii a[200010];
int d[200010];
const long double pi=acos((long double)-1);
int main()
{
	int x1,y1,x2,y2,n,i;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	int b1=0,b2=0;
	if(x1>x2)
	{
		b1=1;
		x1=-x1;
		x2=-x2;
	}
	if(y1>y2)
	{
		b2=1;
		y1=-y1;
		y2=-y2;
	}
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].first,&a[i].second);
		if(b1)
			a[i].first*=-1;
		if(b2)
			a[i].second*=-1;
	}
	sort(a+1,a+n+1);
	int s=0;
	memset(d,0x7f,sizeof d);
	for(i=1;i<=n;i++)
		if(a[i].first>=x1&&a[i].first<=x2&&a[i].second>=y1&&a[i].second<=y2)
		{
			int k=lower_bound(d+1,d+n+1,a[i].second)-d;
			d[k]=a[i].second;
			upmax(s,k);
		}
	long double ans=(x2+y2-x1-y1)*100.;
	if(s==min(y2-y1,x2-x1)+1)
	{
		s--;
		ans+=10*pi-20;
	}
	ans-=s*(20-5*pi);
	printf("%.20Lf\n",ans);
	return 0;
}

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

int main(){
	long long a,b;
	cin>>a>>b;
	if(a<=0&&b>=0)cout<<"Zero"<<endl;
	else{
		if(a>0)cout<<"Positive"<<endl;
		else{
			if(((long long)abs(b-a)+1)%2)cout<<"Negative"<<endl;
			else cout<<"Positive"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N,W;
    cin >> N >> W;
    ll w[110],v[110];
    REP(i,N){
        cin >> w[i] >> v[i];
    }
    ll dp[110][100100] = {};

    REP(i,N){
        REP(j,W+1){
            if(j >= w[i]){
                chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            }
            
            chmax(dp[i+1][j],dp[i][j]);
            
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 86272
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	char input[101];
	string str;

	scanf("%s", input);
	str = input;

	int cnt = 0;

	for (int i = 0; i < str.size() / 2; i++)
	{
		cnt += (str[i] != str[str.size() - 1 - i]);
	}

	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int N, ans = 100000000, a = 0, b = 0;
	cin >> N;
	vector<int>W(N);
	for (int i = 0; i < N; i++)cin >> W[i];
	for (int i = 1; i < N; i++)
	{
		a = 0;
		b = 0;
		for (int j = 0; j < N; j++)
		{
			if (j <= i)a += W[j];
			else b += W[j];
		}
		ans = min(abs(a - b), ans);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int field[13][13];
int ans=0;

void dfs(int y,int x){
  field[y][x]=0;
  int dx[4]={-1,0,1,0};
  int dy[4]={0,-1,0,1};

  for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(0<=nx && nx<12 && 0<=ny && ny<12 && field[ny][nx] == 1)dfs(ny,nx);
    
  }
  
}

int iscan(){

  for(int i=0;i<=12;i++){
    for(int j=0;j<=12;j++){
      if(field[j][i] == 1){dfs(j,i);
	ans++;
      }
      
  }
    
  }
  return ans;
}

int main(){
  string s;

  while(1){
    ans=0; 
  for(int i=0;i<12;i++){
    for(int j=0;j<12;j++)field[j][i]=0;
  }


  for(int i=0;i<12;i++){
      cin >> s;
      for(int j=0;j<12;j++){

	  field[j][i]=s[j]-'0';
	

      }

  }
  if(cin.eof())break; 

  cout <<   iscan() << endl;
}
  

}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	int mini = 1e9;
	for(int i = 0; i < s.size() - 2; i++)
		mini = min(abs(((s[i] -'0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0')) - 753), mini);
	cout << mini;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

vector<ll> enum_divisors(ll n){
    vector<ll> res;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0){
            res.push_back(i);
            if (n/i != i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){
    ll n;
    cin >> n;

    ll res = 1;
    map<ll, ll> mp1 = prime_factor(n-1);
    for(auto x : mp1){
        res *= x.second + 1;
    }
    res--;

    auto v = enum_divisors(n);
    for (int i = 1; i < v.size(); ++i) {
        ll x = n;
        while (x % v[i] == 0){
            x /= v[i];
        }
        if (x % v[i] == 1) res++;
    }

    cout << res << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
	int a,b,c,d,i;
	char class[9+1];
	/*scanf("%s %d %d",&class, &a, &b);*/
	for(i=1;i<=9;i++) {
		scanf("%s %d %d",&class,&a,&b);
		c=a+b;
		c<=400;
		d=a*200+b*300;
		printf("%s %d %d\n",class,c,d);
	}
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
const int p = 3;
ll calc(vector<ll>a,vector<ll>b,ll m){
    vector<ll> dp(m+1);
    for(int i=0;i<=m;i++){
        if(i!=0){
            dp[i] = max(dp[i],dp[i-1]+1);
        }
        rep(k,3){
            if(i>=a[k]){
                dp[i] = max(dp[i],dp[i-a[k]]+b[k]);
            }
        }
    }
    return dp[m];
}
int main(){
    ll n;
    cin >> n;
    vector<ll>a(3);
    vector<ll>b(3);
    rep(i,p){
        cin >> a[i];
    }
    rep(i,p){
        cin >> b[i];
    }
    ll m = calc(a,b,n);
    ll ans = calc(b,a,m);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 195584
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    ll n;
    cin >> n;
    ll S=0;
    ll X=0;
    ll a1;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin >> x;
        if(i==0)
        a1=x;
        if(i<2)
        S+=x;
        if(i>1)
        X^=x;
    }
    ll D=(S-X)/2;
    if((S-X<0) || (S-X)%2 || (D&X)!=0)
    {
        cout <<-1 << endl;
        return;
    }
    //cout << D << " " << (D&X) << endl;
    ll ans=D;
    if(D>a1)
    {
        cout <<-1 << endl;
        return;
    }
    for(ll i=42;i>=0;i--)
    {
        if((ll)pow(2,i)&X)
        if(ans+(ll)pow(2,i)<=a1)
        ans+=(ll)pow(2,i);
    }
    if(ans==0)
    cout << -1 << endl;
    else
    cout << a1-ans << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 4116
import sys
input = sys.stdin.readline

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
check = a[0]
for i in range(1, 10**5):
    if check == 2:
        print(i)
        sys.exit()
    else:
        check = a[check-1]
print(-1)

Measured memory_bytes: 6900
let k=[0;1;2;3];;
let h()=Scanf.scanf"%d %d %d %d "(fun a b c d->[a;b;c;d]);;
let rec f()=
  let a,b=h(),h()in
  let g(m,n)s i=
    List.fold_left2(fun(p,q)x j->if x=s&&i=j then(p+1,q)else if x<>s then(p,q)else(p,q+1))(m,n)a k
  in
  let m,n=List.fold_left2 g(0,0)b k in
  f(Printf.printf "%d %d\n"m n);;
try f()with _->()

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

using namespace std;

int main(){
  int A[9];
  bool B[9];
  
  for(int i = 0; i < 9; i++){
  	cin >> A[i];
    B[i] = false;
  }
  
  int N;
  
  cin >> N;
  
  for(int i = 0; i < N ; i++){
    int tmp;
    cin >> tmp;
  	for(int j = 0; j < 9; j++){
      if(A[j] == tmp) 
        B[j] = true;
    }
  }
  for(int i = 0; i < 3; i++){
    if(B[0+i*3] && B[1+i*3] && B[2+i*3]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  for(int i = 0; i < 3; i++){
    if(B[i] && B[3+i] && B[6+i]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if(B[0] && B[4] && B[8]){
      cout << "Yes" << endl;
      return 0;
  }
  if(B[2] && B[4] && B[6]){
      cout << "Yes" << endl;
      return 0;
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

var c = 0

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	a := map[int]int{}
	b := map[int]int{}
	for i := 0; i < n; i++ {
		v, _ := strconv.Atoi(stringLineScan())
		if i%2 == 0 {
			a[v]++
		} else {
			b[v]++
		}
	}
	x := make([]int, 4)
	y := make([]int, 4)
	for v, k := range a {
		if x[1] < k {
			x[0], x[1], x[2], x[3] = v, k, x[0], x[1]
		} else if x[3] < k {
			x[2], x[3] = v, k
		}
	}
	for v, k := range b {
		if y[1] < k {
			y[0], y[1], y[2], y[3] = v, k, y[0], y[1]
		} else if y[3] < k {
			y[2], y[3] = v, k
		}
	}
	if x[0] != y[0] {
		fmt.Println(n - x[1] - y[1])
	} else {
		if n-x[1]-y[3] < n-y[1]-x[3] {
			fmt.Println(n - x[1] - y[3])
		} else {
			fmt.Println(n - y[1] - x[3])
		}
	}

}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

int n;
deque<ll> dq;

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

	cin>>n;
	REP(i,n) {
		ll a; cin>>a;
		if(i&1) dq.pf(a);
		else dq.pb(a);
	}
	if(n&1) {
		for(int i=dq.size()-1;i>=0;i--) cout<<dq[i]<<' ';
	}
	else REP(i,dq.size()) cout<<dq[i]<<' ';
	cout<<endl;

	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  map<string, int>m;
  rep(i, n){
    string s;cin>>s;
    m[s]++;
  }

  cout<<m.size()<<endl;

  return 0;
}

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

int main() {
    int n, k; 
    cin >> n >> k;
    vector<ll> h(n, 0);
    for(auto& i: h)
        cin >> i;
    vector<ll> dp(n, numeric_limits<ll>::max());
    dp[0] = 0;
    for(int i = 1; i < n; ++i) {
        int kk = k;
        for(int j = i - 1; j >= 0 && k > 0; --j, --k) {
            dp[i] = min({
                dp[i],
                dp[j] + abs(h[i] - h[j])
                });
        }
        k = kk;
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <vector>
#include <iostream>
#include <limits>
#include <iostream>
#include <vector>
#include <cassert>
#include <complex>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long Long;

Long nex[100010][20];

int main(){
	
	int N;
	cin >> N;
	vector<int> X(N);
	for(int &v : X)
		cin >> v;
	N++;
	X.push_back(X.back());
	int L;
	cin >> L;
	// nex 0
	for(int i = 0; i < N; ++i){
		int nX = X[i]+L;
		int p = upper_bound(X.begin(),X.end(),nX) - X.begin();
		p--;
		nex[i][0] = p;
	}
	for(int i = 1; i < 20; ++i){
		for(int j = 0; j < N; ++j){
			nex[j][i] = nex[ nex[j][i-1] ][i-1];
		}
	}
	int Q;
	cin >> Q;
	for(int i = 0; i < Q; ++i){
		int a,b;
		cin >> a >> b;
		a--;b--;
		if(a > b)swap(a,b);
		int c = 0;
		for(int i = 19; i >= 0; --i){
			if(nex[a][i] < b){
				c += (1<<i);
				a = nex[a][i];
			}
		}
		c++;
		cout << c << endl;
	}
	
}


/*


 */



Measured memory_bytes: 16888
n, k = list(map(int, input().split()))

scores = [0] * (n + 1)
cnts = [0] * (n + 1)

for i in range(1, (n + 1), 1):
    scores[i] = i

    while True:
        if (k <= scores[i]):
            break

        scores[i] *= 2
        cnts[i] += 1

list = list(map(lambda x: (1 / 2) ** x, cnts))
print(sum(list[1:(n + 1)]) / n)


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int smallest = INT_MAX, res = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        smallest = min(smallest, x);
        if (x == smallest) ++res;
    }
    cout << res << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> v;
  int a;
  cin >>  a;
  v.push_back(a);
  int ans = -a;
  for(int i=1;i<n;i++){
    cin >> a;
    ans += a;
    v.push_back(a);
  }
  int sa=ans;
  ans = abs(ans);
  int p;
  for(int i=1;i<n;i++){
    sa -= 2*v[i];
    p = abs(sa);
    if(p<ans){
      ans = p;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N,K;
  int sum =0;
  cin >> N >> K;
  
  for(int i =0; i<N; i++){
    int x;
    cin >> x;
    if( x<(K-x))
      sum+=2*x;
    else sum += 2*(K-x);
  }
  cout << sum << endl;
}


Measured memory_bytes: 256