akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using Weight=int;

struct Edge{
    int from,to,rev;
    Weight cap;
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;
Graph g;

void addEdge(int from,int to,Weight cap){
    g[from].push_back(Edge{from,to,int(g[to].size()),cap});
    g[to].push_back(Edge{to,from,int(g[from].size())-1,0});
}

const Weight INF=1e9;
Weight maxFlow(int s,int t){
    Weight res=0;
    Weight f;
    vector<int> used(g.size(),0);
    vector<int> course;
    function<Weight(int)> dfs=[&](int v){
        if(v==t){
            course.push_back(t);
            return INF;
        }
        if(used[v]) return 0;
        used[v]=true;        
        for(int i=0;i<g[v].size();i++){
            Weight cap=g[v][i].cap;
            if(!cap) continue;
            Weight f=dfs(g[v][i].to);
            if(f){
                course.push_back(v);
                return min(f,cap);
            }
        }
        return 0;
    };

    while(f=dfs(s)){
        res+=f;
        reverse(course.begin(),course.end());
        for(int i=0;i<int(course.size())-1;i++){
            int from=course[i];
            int to=course[i+1];
            for(int j=0;j<g[from].size();j++){
                if(g[from][j].to==to){
                    g[from][j].cap-=f;
                    assert(g[from][j].cap>=0);
                    g[to][g[from][j].rev].cap+=f;
                    break;
                }
            }
        }
        course.clear();
        used.assign(g.size(),false);
    }
    return res;
}

int main(){
    int v,e;
    cin>>v>>e;
    g.assign(v,Edges());    
    for(int i=0;i<e;i++){
        int u,v;
        Weight c;
        cin>>u>>v>>c;
        addEdge(u,v,c);
    }
    cout<<maxFlow(0,v-1)<<endl;
    return 0;
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int num[100005];
 
int32_t main()
{
    fast;
    int n, k; cin >> n >> k;
    For(i, 0, n) {
        int a, b; cin >> a >> b;
        num[a] += b;
    }
    Rep(i, 1, 100005) {
        if(k <= num[i]) {
            cout << i;
            break;
        }
        k -= num[i];
    }
    
    
    return 0;
}

Measured memory_bytes: 4444
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,b,c;
    cin >> n ;
    vector<int>a(n+10);
for (int i=1;i<=n;i++){
cin >> a.at(i);
}

vector<int>dp(n+1);

dp[1]=0;
 dp[2]=abs(a[1]-a[2]);
for(int i=3;i<n+1;i++){
    b=dp[i-2]+abs(a[i]-a[i-2]);
    c=dp[i-1]+abs(a[i]-a[i-1]);
dp[i]=min(b,c);

}
cout << dp[n] << endl;
  }


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

const long long INFLL = 1e18;

using namespace std;

typedef long long ll;

struct item{
    int w;
    long long cost;
    int max_amount;
};

bool comp(item A, item B)
{
    return A.cost * B.w < B.cost * A.w;
}

int main()
{
    int n, x, d;
    cin >> n >> x >> d;
    vector<int> m(n), p(n);
    cin >> m[0];
    p[0] = -1;
    for (int i = 1; i < n; i++)
        cin >> m[i] >> p[i], p[i]--;
    vector<item> items(n);
    for (int i = 0; i < n; i++)
    {
        items[i] = {1, m[i]};
    }
    for (int i = 0; i < n; i++)
    {
        int j = p[i];
        while (j != -1)
        {
            items[j].w++;
            items[j].cost += m[i];
            j = p[j];
        }
    }
    items[0].max_amount = x / items[0].cost + 12;
    for (int i = 1; i < n; i++)
    {
        items[i].max_amount = d;
    }
    vector<item> bag_dp(n);
    for (int i = 0; i < n; i++)
    {
        bag_dp[i] = items[i];
        int am = min(items[i].max_amount, 51);
        bag_dp[i].max_amount = am;
        items[i].max_amount -= am;
    }
    sort(items.begin(), items.end(), comp);
    vector<ll> dp(1);
    for (int i = 0; i < bag_dp.size(); i++)
    {
        for (int j = 0; j < bag_dp[i].max_amount; j++)
        {
            vector<ll> dp2(dp.size() + bag_dp[i].w, INFLL);
            for (int st = dp.size() - 1; st >= 0; st--)
            {
                dp2[st + bag_dp[i].w] = min(dp2[st + bag_dp[i].w], dp[st] + bag_dp[i].cost);
                dp2[st] = min(dp2[st], dp[st]);
            }
            dp = dp2;
        }
    }
    long long ans = 0;
    for (int i = 0; i < dp.size(); i++)
    {
        if (dp[i] > x) continue;
        long long res = i;
        long long coins = x - dp[i];
        for (int j = 0; j < items.size(); j++)
        {
            long long can = min(1ll * items[j].max_amount, coins / items[j].cost);
            res += items[j].w * can;
            coins -= can * items[j].cost;
        }
        //cout << i << " " << dp[i] << " " << coins << " " << res << endl;
        ans = max(ans, res);
    }
    cout << ans;
}


Measured memory_bytes: 5260
const main = (input: string) => {
  const [A, B] = input.trim().split(" ").map(str => parseInt(str))
  const taxRateA = 0.08
  const taxRateB = 0.1
  const maxCount = 1010
  let count = 1;
  let answer = -1;
  
  const taxRateCalc = (n: number) => {
    if(Math.floor(n * taxRateA) === A && Math.floor(n * taxRateB) === B) {
      return n
    } else {
      return -1
    }
  }

  while(answer === -1 && count < maxCount) {
    answer = taxRateCalc(count)
    count += 1
  }
  console.log(answer)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
n,m,d = map(int, input().split())
ans = []
for i in range(n):
    ans.append(list(str(input())))
ams = []
for i in range(m):
    ami = []
    for a in ans:
        ami.append(a[i])
    ams.append(ami)
#print(ans,ams)
num0 = [] 
for an in ans:
    cnt = 0
    for i in range(len(an)):
        if an[i] == ".":
            cnt += 1
            if (i == len(an)-1):
                num0.append(cnt)
        elif an[i] == "#":
            num0.append(cnt)
            cnt = 0
for am in ams:
    cnt = 0
    for i in range(len(am)):
        if am[i] == ".":
            cnt += 1
            if (i == len(am) -1):
                num0.append(cnt)
        elif am[i] == "#":
            num0.append(cnt)
            cnt = 0
#print(num0)
p = 0
for cnt in num0:
    if (cnt >= d):
        p += (cnt - d+1)
            
print(p)



Measured memory_bytes: 5772
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {

  public static void main( String[] args ) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String n = br.readLine();
    while (n != null) {
      String[] sp = n.split(" ");
      int result = 0;
      for (String str : sp) {
        try {
          result += Integer.parseInt(str);
        } catch (NumberFormatException ex) {
          result = 0;
        }
      }
      if (result == 0) {
        break;
      }
      System.out.println(String.valueOf(result).length());
      n = br.readLine();
    }
  }
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

#define int long long


signed main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int now = 0;
    while(now <= 3601) {
        for(int i=0; i<=a; ++i) {
            if(now > c) c += 60;
            if(now == c) {
                cout << now << endl;
                return 0;
            }
            now++;
        }
        for(int i=0; i<b-1; ++i) {
            now++;
            if(now > c) c += 60;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3096
while True:
    H,W=map(int,input().split())
    if H==0 or W==0:
        break
    else:
        for i in range(H):
            if (i+2)%2==0:
                for j in range(W):
                    if (j+2)%2==0:
                        print("#",end="")
                    else:
                        print(".",end="")
            else:
                for k in range(W):
                    if (k+2)%2==1:
                        print("#",end="")
                    else:
                        print(".",end="")
            print()
        print()
   



Measured memory_bytes: 7004
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
ma = max(A)
n = len(bin(ma))-2
D = [0]*n
ans = 0
for i in range(n):
    zero = 0
    one = 0
    for a in A:
        if a>>i&1:
            one+=1
        else:
            zero+=1
            
    ans+=((one*zero)*2**i)%mod
    ans%=mod
print(ans)

Measured memory_bytes: 124160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
const ll MOD=998244353;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

int main()
{
        io;
        //////////////////////////////////
        ll n,i,j,k,x,y;
        cin>>x>>y;
        if(y%2==0 && y>=2*x && y<=4*x)
        {
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
        //////////////////////////////////
        cer;
}

Measured memory_bytes: 3796
//
//  Circle.c
//  AOJ
//
//  Created by admin on 2014/07/12.
//
//

#include <stdio.h>
#define Pi 3.141592653589

main()
{
    double r;
    
    scanf("%lf",&r);
    
    printf("%f %f\n",Pi*r*r,2*Pi*r);
 
    return 0;
    
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int n;
  n=S.size()-1;
  if(S.at(n)=='s'){
    cout<<S<<'e'<<'s'<<endl;
  }else{
    cout<<S<<'s'<<endl;
  }
  
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"

using namespace std;

class UnionFind
{
    vector<int> par;

public:
    UnionFind(int n) : par(n, -1) {}

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) { return -par[root(x)]; }
};

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> lang[m];
    for (int i = 0; i < n; i++)
    {
        int k, l;
        cin >> k;
        while (k--)
        {
            cin >> l;
            lang[l - 1].push_back(i);
        }
    }
    UnionFind uf(n);
    for (int i = 0; i < m; i++)
    {
        int s = lang[i].size();
        for (int j = 0; j < s - 1; j++)
        {
            uf.merge(lang[i][j], lang[i][j + 1]);
        }
    }
    cout << (uf.size(0) == n ? "YES" : "NO") << endl;
}

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


Measured memory_bytes: 4608
/*
 * src.cpp
 *
 *  Created on: 2016/08/08
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if ((a && b) || c){
		cout<<"Open"<<endl;
	}else{
		cout<<"Close"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll x;
	cin>>x;

	ll t=100,ans=0;
	while(t<x){
		ans++;
		t+=t*0.01;
	}
	cout<<ans<<endl;

	return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) cin >> S[i];
    sort(ALL(S));
    
    ll ans = 1;
    REP(i, N - 1)
    {
        if (S[i] != S[i + 1]) ans++;
    }

    cout << ans << endl;
}


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

int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> v(N,K-Q);
  vector<int> v1(Q);
  for (int i=0;i<Q;i++){
    cin >> v1.at(i);
    v.at(v1.at(i)-1)++;
  }
  
  for (int i=0;i<N;i++){
    if(v.at(i)>0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
    
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
ll xsum, ysum;
ll MOD = 1e9+7LL;
int main(){
    ll n,m; cin >> n >> m;
    REP(i,n){
        ll x; cin >> x;
        xsum += x * (i - (n-1-i));
    }
    xsum %= MOD;
    REP(i,m){
        ll y; cin >> y;
        ysum += y * (i - (m-1-i));
    }
    ysum %= MOD ;
    cout << xsum * ysum  % MOD << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200010];
int main()
{
	int n,k;
	ll ans=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		ans+=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=n;i>n-k&&i>=0;i--){
		ans-=a[i];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;

using ll = long long;
using namespace std;

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

int main(){
    int n;
    cin >> n;
    int sum;
    sum = sum_of_digits(n);
    if (n%sum==0) out("Yes");
    else out("No");
}

Measured memory_bytes: 256
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
    
n = load()
li = []
for _ in range(5):
    li.append(load())

mn = min(li)
mni = li.index(mn)

ans = math.ceil(n / mn) + mni + (5-mni-1)
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <stack>

using namespace std;

int main() {
  char c;
  stack<char> S;
  int ans{};
  while(cin >> c) {
    if (S.empty() || S.top() == c) S.push(c);
    else {
      ans += 2;
      S.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
n = gets.chomp.to_i
s1 = gets.chomp
s2 = gets.chomp

M = 1_000_000_007

i = 0
ans = 1
loop do
  if s1[i] == s2[i]
    if i.zero?
      ans = 3
    elsif s1[i - 1] == s2[i - 1]
      ans = ans * 2 % M
    end
    i += 1
  else
    if i.zero?
      ans = 6
    elsif s1[i - 1] == s2[i - 1]
      ans = ans * 2 % M
    else
      ans = ans * 3 % M
    end
    i += 2
  end
  break if i >= n
end
puts ans


Measured memory_bytes: 3836
public class Main {
	
		
		public static void main(String[] args) {
			java.util.Scanner scan = new java.util.Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		if(-100 <= x && x <= 100 && -100 <= y && y <= 100 && 0 < r && r <= 100 && 0 < W && W <=100 && 0 < H && H <= 100){
		if( W >= (x + r) && H >= (y + r) && (y+r)>0 && (x+r)>0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		}
		}
		
		
		
		}

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

#define jaldi ios_base::sync_with_stdio(false)
#define fr(i,j,n) for(i=j;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define ppii pair<int,int> 
#define ppll pair<long long,long long>
#define ppcc pair<char,char>
#define ppss pair<string,string> 
#define vpll vector<pair<long long,long long>>
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 1000000007

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

int main()
{
    jaldi;
    precision(20);
    ll i,j;

    ll n,a,b;
    cin>>n>>a>>b;
    a--;
    ll x=a/n;
    ll y=b/n;
    ll e=y-x;

    if(e>=1)
        cout<<"OK";
    else
        cout<<"NG";


    return 0;
}

Measured memory_bytes: 3604
#coding:utf-8
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True

def main():
    MOD = 10**9 + 7
    # ?AGC, ?GAC, ?ACG, 
    # AG?C = (AGAC), (AGCC), AGGC, AGTC
    # A?GC = (AAGC)(ACGC)(AGGC), ATGC

    # AG?C,A?GC,?GAC,?ACG
    dp =[1] * 64
    A = 0
    C = 1
    G = 2
    T = 3
    #GAC
    dp[G * 4**2 + A * 4**1 + C * 4**0] = 0
    #ACG
    dp[A * 4**2 + C * 4**1 + G * 4**0] = 0
    #AGC
    dp[A * 4**2 + G * 4**1 + C * 4**0] = 0

    N = II()
    pre = dp
    for _ in range(N-3):
        #?AA →AAA,AAC,AAG,AAT
        pre = dp
        dp = [0] * 64
        for i in range(64):
            #GA
            # if i == (3 * 4**2 + 0 * 4**1 + 2 * 4**0)\
            # or i == (0 * 4**2 + 2 * 4**1 + 3 * 4**0):
            #     continue
            for j in range(4):
                #pre==?GA and j==C
                if i % 16 == G*4+A and j == C:
                    #print('GAC')
                    continue
                #pre == ?AC and j==G
                elif i % 16 == A*4+C and j == G:
                    #print('ACG')
                    continue
                #pre == ?AG and j == C
                elif i % 16 == A*4+G and j== C:
                    continue 
                #AG?C pre==AG? and j==C
                elif i // 4 == A*4+G and j == C:
                    continue
                #A?GC pre==A?G j==C
                elif i//16 == A and i%4 ==G and j == C:
                    continue

                dp[i%16*4+j] += pre[i]
        dp = list(map(lambda x:x%MOD, dp))

        
        

    print(sum(dp)%MOD)

    






    pass
if __name__ == '__main__':
    main()

Measured memory_bytes: 42480
n=int(input())
l=list(map(int,input().split()))
dp=l.copy()
for i in range(n-1):

	dp1=dp.copy()
	l=list(map(int,input().split()))
	for j in range(3):
		ans=float('-inf')
		for k in range(3):
			if(j!=k):
				ans=max(ans,l[j]+dp[k])
		dp1[j]=ans
	dp=dp1.copy()
print(max(dp))


Measured memory_bytes: 75648
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;

            var l = new int[N];
            var r = new int[N];

            for (int i = 0; i < N; i++)
            {
                l[i] = cin.ReadInt;
                r[i] = cin.ReadInt;
            }

            var ans = 0;

            for (int i = 0; i < N; i++)
            {
                ans += r[i] - l[i] + 1;
            }

            WriteLine(ans);

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

#define int long long



signed main() {
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a+b>c+d)
        puts("Left");
    else if(a+b<c+d)
        puts("Right");
    else
        puts("Balanced");
    
    return 0;
}


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

int main() {
  int N;
  int ans=1;
  cin >> N;
  vector <int> seq(N);
  for (int i=0 ; i<N ; i++){
    cin >> seq[i];
  }
  sort(seq.begin(), seq.end());
  for (int i=0; i<N-1; i++) {
    if(seq[i]<seq[i+1]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
max_a=-1
max_b=-1
N.times do
    a,b=get_i
    if max_a<a
        max_a=a
        max_b=b
    end
end
puts max_a+max_b

Measured memory_bytes: 3836
/*
author : shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,count=0,sum=0;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    for(i=n-1;i>=0;i--)
    {
        if(arr[i]==arr[i-1])
            count+=1;
        else
        {
            sum=sum+(count/2)+(count%2);
            count=0;
        }
    }
    if(count!=0 && sum==0)
        sum=sum+count/2+count%2;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k=0;
string s, t;


int main()
{
	int n, r;
	cin >> n >> r;
	if (n < 10)
		cout << r + 100 * (10 - n) << endl;
	else
		cout << r << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;


namespace ABC162
{
    class A
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            for (int i = 0; i < 3; i++)
            {
                if (N[i] == '7') { Console.WriteLine("Yes"); return; }
            }
            Console.WriteLine("No");
        }
    }
}



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

using namespace std;

int main()
{
  vector<int> W;
  vector<int> K;

  for(int i = 0;i < 20;++i){
    int a;
    cin>>a;
    
    if(i < 10){
      W.push_back(a);
    }
    else{
      K.push_back(a);
    }
  }

  sort(W.begin(),W.end());
  reverse(W.begin(),W.end());
  sort(K.begin(),K.end());
  reverse(K.begin(),K.end());

  int a = 0;
  int W_p = 0;
  int K_p = 0;
  for(int e : W){
    W_p += e;
    ++a;

    if(a == 3){
      a = 0;
      break;
    }
  }

  for(int e : K){
    K_p += e;
    ++a;

    if(a == 3){
      break;
    }
  }

  cout<<W_p<<" "<<K_p<<endl;
  return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int n;

	std::cin >> n;
	
	vector<long int> a(n+1);
	vector<long int> b(n);

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

	long int count = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] < b[i]) {
			count += a[i];
			b[i] -= a[i];
			if (a[i + 1] < b[i]) {
				count += a[i+1];
				a[i + 1] = 0;
			}
			else {
				count += b[i];
				a[i + 1] -= b[i];
			}
		}
		else {
			count += b[i];
		}
	}
		cout << count << endl;

	return 0;
}

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

using ll=long long;
#define int ll
#define upto(a,b,i) for(int i=(a),b_=(b);i<=b_;++i)
#define uptil(a,b,i) for(int i=(a),b_=(b);i<b_;++i)
#define downto(a,b,i) for(int i=(a),b_=(b);i>=b_;--i)
#define downtil(a,b,i) for(int i=(a),b_=(b);i>b_;--i)
#define times(n,i) uptil(0,n,i)
#define rtimes(n,i) downto((n)-1,0,i)
#define sp << " "
#define ln << endl

void solve() {
  string s; cin >> s;
  if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
  cout << "Bad" ln;
  else cout << "Good" ln;
}

signed main() {
  cout << fixed << setprecision(20);
  cerr << fixed << setprecision(10);
  solve();
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    int step = 0;
    int minstep = 999;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < a.size(); i++) {
        cin >> a.at(i);
    }

    sort(a.rbegin(), a.rend());

    for (int i = 0; i < n; i++) {
        if (minstep > a.at(i)) {
            minstep = a.at(i);
            step++;
        }
    }

    cout << step << endl;

}

Measured memory_bytes: 3632
#include <stdio.h>
int Circumference(int a, int b) {
	return 2*a + 2* b;
}
int area(int a, int b) {
	return a * b;
}
int main() {
	int a, b;
	
	scanf("%d %d",  &a, &b);
	
	printf("%d %d\n",area(a, b), Circumference(a, b));
	
	return 0;
}
	
	
	
	


Measured memory_bytes: 2080
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef vector<P> vec;

double eps=1e-7;
bool eq(double a,double b){return (b-a<eps&&a-b<eps);}
double dot(P a,P b){return real(b*conj(a));}
double cross(P a,P b){return imag(b*conj(a));}
P project(P a,P b,P c){b-=a;c-=a;return a+b*real(c/b);}
P reflect(P a,P b,P c){b-=a;c-=a;return a+conj(c/b)*b;}
int ccw(P a,P b,P c){
  b-=a,c-=a,a=c*conj(b);
  if(a.imag()>eps)return 1;//ccw
  if(a.imag()<-eps)return -1;//cw
  if(a.real()<-eps)return 2;//ob
  if(abs(b)+eps<abs(c))return -2;//of
  return 0;//os
}

//segment ab , point c
double dist(P a,P b,P c){
  if(dot(b-a,c-a)<0)return abs(c-a);
  if(dot(a-b,c-b)<0)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

bool isintersect(P a,P b,P c,P d){
  return ((ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0));
}

//segment ab , segment cd
P intersect(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

double dist(P a,P b,P c,P d){
  if(isintersect(a,b,c,d))return 0;
  double ab=min(dist(a,b,c),dist(a,b,d));
  double cd=min(dist(c,d,a),dist(c,d,b));
  return min(ab,cd);
}

double calcArea(vec &t){
  double res=0;
  int n=t.size();
  for(int i=0;i<n;i++)res+=cross(t[i],t[(i+1==n?0:i+1)]);
  return abs(res/2.0);
}

int main(){
  int n;
  cin>>n;
  vec t;
  double x,y;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    t.push_back(P(x,y));
  }
  int ans=1;
  for(int i=0;i<n;i++){
    int j=(i+1)%n;
    int k=(i+2)%n;
    if( ccw(t[i],t[j],t[k]) == -1 )ans=0;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;


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

    int D, T, S;
    cin >> D >> T >> S;

    if (D <= T * S)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int ans=0;
	string temp;
	cin >> temp;
	for (int i = 0; i < 4; i++) {
		if (temp[i] == '+') ans++;
		else ans--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define y1 y11
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define skip continue
#define all(x) x.begin(), x.end()
#define NAME "code"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;

const ll inf = 1e9;
const ll maxn = 2e5 + 11;

ll a, b, c, d, n, ans;

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

cin >> a >> b >> c >> d >> n;
b = min(a * 2, b); // 0.5
c = min(b * 2, c); // 1
d = min(c * 2, d); // 2

ans = (n / 2) * d + (n & 1) * c;

cout << ans;

return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]

a.sort()
for ans in m:
	dp = [[0 for i in range(ans+1)] for k in range(len(a)+1)]
	dp[0][0] = 1
	for i in range(len(a)):
		for k in range(ans+1):
			if a[i] <= k:
				dp[i+1][k] = dp[i][k-a[i]] or dp[i][k]
			else:
				dp[i+1][k] = dp[i][k]
	if dp[len(a)][ans]:
		print("yes")
	else:
		print("no")


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

using namespace std;

string str;
int pos;
int P, Q, R;

int formula() {
  pos ++;
  if(str[pos] == '(') {
    int f = formula();
    pos ++;
    if(str[pos] == '*') f = min(f, formula());
    if(str[pos] == '+') f = max(f, formula());
    pos ++;
    return f;
  }
  if(str[pos] == '-') return 2-formula();
  if(isdigit(str[pos])) return str[pos] - '0';
  if(str[pos] == 'P') return P;
  if(str[pos] == 'Q') return Q;
  if(str[pos] == 'R') return R;
}

int main() {
  
  while(cin >> str && str != ".") {
    int cnt = 0;
    for(P = 0; P<=2; P++)
      for(Q = 0; Q<=2; Q++)
	for(R = 0; R<=2; R++) {
	  pos = -1;
	  cnt += formula() == 2;
	}
    cout << cnt << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
#define NUM 1000000007
typedef long long int lli;

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

    int ans = 0;
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

int main(){
	vector<int> line(5000, true);
	vector<int> sosu;
	for(int i=2;i<5000;++i){
		if(line[i]){
			if((i-1)%5==0)sosu.push_back(i);
			for(int j=i*2;j<5000;j+=i)line[j]=false;
		}
	}
	int N;
	cin >> N;
	bool flag=false;
	REP(i, N){
		cout << (flag?" ":"") << sosu[i];
		flag=true;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%MOD;
        a=a*a%MOD;
        x>>=1;
    }
    return res;
}
string s;

int main(){
    int n;cin>>n;
    vector<int> x(n),y(n),num(n);
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        num[i]=i;
    }
    double sum=0;
    do{
        double len=0;
        for(int i=0;i<n-1;i++){
            len+=pow((x[num[i+1]]-x[num[i]])*(x[num[i+1]]-x[num[i]])+(y[num[i+1]]-y[num[i]])*(y[num[i+1]]-y[num[i]]),0.5);
        }
        sum+=len;
    }while(next_permutation(num.begin(),num.end()));
    int fac=1;
    for(int i=1;i<=n;i++) fac*=i;
    printf("%.14f\n",sum/(double)fac);
    return 0;
}

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

int main(){
    string str;
    getline(cin,str);

    for(int i=0;i<(int)str.size();i++){
        if('a'<=str[i]&&str[i]<='z'){
            str[i]=str[i]-'a'+'A';
        }else if('A'<=str[i]&&str[i]<='Z'){
            str[i]=str[i]-'A'+'a';
        }
    }
    cout<<str<<endl;
}


Measured memory_bytes: 3152
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N);
  vector<int> P(N);
  for(int i=0; i<M; i++) {
    int k;
    cin >> k;
    for(int j=0; j<k; j++) {
      int s;
      cin >> s; s--;
      S[i] += (1 << s);
    }
  }
  for(int i=0; i<M; i++)
    cin >> P[i];
  int ans = 0;
  for(int i=0; i<(1<<N); i++) {
    bool res = true;
    for(int j=0; j<M; j++) {
      bool on_off = P[j] == 0;
      int tmp = i & S[j];
      for(int l=0; l<N; l++) {
	if(tmp % 2 == 1)
	  on_off = !on_off;
	tmp >>= 1;
      }
      if(!on_off) {
	res = false;
	break;
      }
    }
    if(res)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        int N=gi();
        int[] A=new int[N];
        int[][] X =new int[N][N-1];
        int[][] Y =new int[N][N-1];

        for (int i=0; i<N;i++) {
        	A[i]=gi();
        	for (int j=0; j<A[i];j++) {
            	X[i][j]=gi();
            	Y[i][j]=gi();
            }
        }

        int max=0;
        for (int i=0; i<Math.pow(2, N);i++) {
        	boolean flg=true;
        	for (int j=0; j<N;j++) {
        		for (int k=0; k<A[j];k++) {
        			if(((i>>j) & 1) ==1) {
        			    int y = (i >> (X[j][k]-1)) & 1;
        		        if(y!=Y[j][k]) {
        		    	   flg=false;
        		    	    break;
        		        }
        			}
        		}
        		if(!flg)break;
        	}
        	if(flg) {
        		int c=0;
        		int d=i;
        		while(d>0) {
        			if(d%2==1) {
        				c++;
        				d= (d-1)/2;
        			}else {
        				d =d/2;
        			}
        		}
        		if (c>max) {
        			max=c;
        		}
        	}
        }

        //System.out.println("No");

        System.out.println(max);
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 36636
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main() {
    long long int N, M;
    cin >> N >> M;
    
    set<long long int> devisor;
    for(long long int i=1; i*i<=M; i++) {
        if(M%i==0) {
            devisor.insert(i);
            devisor.insert(M/i);
        }
    }
    
    auto itr=devisor.upper_bound(M/N);
    itr--;
    cout << *itr << endl;


    return 0;
    
}

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

int main() {

  int N;
  cin >> N;

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int a_;
    cin >> a_;
    mp[a_]++;
  }

  int count = 0;

  for (auto item:mp) {
    if (item.first != item.second) {
      if (item.first < item.second) {
        count += item.second - item.first;
      } else {
        count += item.second;
      }
    }
  }

  cout << count << endl;

}

Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)

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

	i64 n, x; cin >> n >> x;
	i64* a = new i64[n];
	rep(i, 0, n) cin >> a[i];

	vector<i64> cnt(40);
	rep(i, 0, 40) 
		rep(j, 0, n) cnt[i] += (a[j] >> i & 1);

	// あるところまでは同じ
	i64 ans = 0;
	rep(i, 0, 40) {
		if ((x >> i & 1) == 0) continue;
		i64 tmp = 0;
		rep(j, 0, 40) {
			i64 mul = 1LL << j;

			if (j < i) tmp += max(cnt[j], n - cnt[j]) * mul;
			else if (j == i) tmp += cnt[j] * mul;
			else
			{
				if (x >> j & 1) tmp += (n - cnt[j]) * mul;
				else tmp += cnt[j] * mul;
			}
		}
		ans = max(ans, tmp);
	}
	// 全部同じ
	i64 tmp = 0;
	rep(i, 0, n) tmp += a[i] ^ x;
	cout << max(tmp, ans);
	delete[] a;
	return 0;
}

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

const int N = 2e6+9;
int parent[N], set_size[N];

void make_set(int v){
    parent[v] = v;
    set_size[v] = 1;
}

int find_set(int v){
    return (parent[v] == v) ? v : parent[v] = find_set(parent[v]);
}

void union_set(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if(a == b) return;
    if(set_size[a] < set_size[b]) swap(a, b);
    parent[b] = a;
    set_size[a] += set_size[b];
}

int main() {
    int n, q;
    cin >> n >> q;
    for(int i = 1; i <= n; i++) {
        parent[i] = i;
    }
    for(int i = 0; i < q; i++) {
        int x, a, b;
        cin >> x >> a >> b;
        a++, b++;
        if(!x) union_set(a, b);
        else if(find_set(a) == find_set(b)) cout << 1 << '\n';
        else cout << 0 << '\n';
    }
    return 0;
}


/*
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0
*/



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

int main() {
	int n,d,x,arr[101],l,y,i,j,m;
	l = 0;
	m = 0;
	cin >> n >> d >> x;
	for (j = 0; j < n; j++)
		cin >> arr[j];
	for (i = 0; i < n; i++){
		for (y = 1; y <= d; y = y+arr[i]){
			l++;
		}
	}
	cout << l+x;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int Max_N=1e5,Max_Q=1e5;
int N,L,Q,X[Max_N+10]={},f[Max_N+10][22]={};
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%d",&X[i]);
	scanf("%d",&L);
	for(int i=1,r=1;i<=N;i++){
		for(;X[r+1]-X[i]<=L&&r+1<=N;++r);
		f[i][0]=r;
	}
	for(int i=1;i<=20;i++)
	 for(int j=1;j<=N;j++)
	  f[j][i]=f[f[j][i-1]][i-1];
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++){
		int a,b,Sum=0; scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		for(int j=20,x=a;j>=0;j--)
		 if(f[x][j]<b) x=f[x][j],Sum+=(1<<j);
		Sum+=1;
		printf("%d\n",Sum);
	}
	return 0;
}

Measured memory_bytes: 9856
#include<stdio.h>

#define ull unsigned long long

ull gcd(ull a,ull b){
    ull x;
    while(b!=0){
        x = b;
        b = a%b;
        a = x;
    }
    return a;
}

int main(){
    ull a,b;

    scanf("%llu %llu",&a,&b);
    printf("%llu\n",gcd(a,b));

    return 0;
}

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

int main(){
  int n,a,b,c,d,rcount=0,ecount=0,count=0,jag=0,A=0,B=0;
  string s;
  cin>>n>>a>>b>>c>>d>>s;
  if(c<d){
    for(int i=a;i<d;i++){
      if(s.at(i)=='#'){
        rcount++;
        if(rcount>=2){
          jag=1;
          break;
        }
      }
      else{
        rcount=0;
      }
    }
    rcount=0;
    if(b>c){
     for(int i=a;i<c;i++){    
      if(s.at(i)=='#'){      
        rcount++;        
        if(rcount>=2){        
          A=1;
            break;
        }
      }
      else{
        rcount=0;
      }
     }
     rcount=0;
     for(int i=b;i<d;i++){    
      if(s.at(i)=='#'){      
        rcount++;        
        if(rcount>=2){        
          B=1;
            break;
        }
      }
      else{
        rcount=0;
      }
     }
      if(A==0&&B==0){
      jag=0;
     }
    }
  }

        

  else {
    for(int i=b-2;i<1+d;i++){
      if(s.at(i)=='#'){
        rcount++;
        if(ecount>=3){
          count=1;
          ecount=0;
        }
        else{
          ecount=0;
        }
        if(rcount>=2){
          jag=1;
          break;
        }
      }
      else{
        ecount++;
        rcount=0;
        if(ecount>=3){
          count=1;
        }
      }
    }
    if(jag==0 && count==0){
      jag=1;
    }
    rcount=0;
    for(int i=a;i<b;i++){    
      if(s.at(i)=='#'){      
        rcount++;        
        if(rcount>=2){        
          jag=1;
            break;
        }
      }
      else{
        rcount=0;
      }
    }
    rcount=0;
    for(int i=d;i<c;i++){    
      if(s.at(i)=='#'){      
        rcount++;        
        if(rcount>=2){        
          jag=1;
            break;
        }
      }
      else{
        rcount=0;
      }
    }
      
  }

  if(jag==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
       
   

Measured memory_bytes: 640
import java.util.*;

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

class Solver {

    private boolean ok(int A, int B, int C) {
        return (A % 2 == 0) && (B % 2 == 0) && (C % 2 == 0);
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        Set<String> set = new HashSet<>();

        int cnt = 0;
        int a = A;
        int b = B;
        int c = C;
        while (ok(a, b, c)) {
            String s = String.format("%d,%d,%d", a, b, c);
            if (set.contains(s)) {
                cnt = -1;
                break;
            }
            set.add(s);

            int at = b / 2 + c / 2;
            int bt = c / 2 + a / 2;
            int ct = a / 2 + b / 2;

            a = at;
            b = bt;
            c = ct;
            cnt++;
        }

        System.out.println(cnt);
        return;
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const int N = 100005;
#define ll long long
int cmp(int a,int b){
	return a>b;
}	
int gcd(int x, int y)
{
    while(y^=x^=y^=x%=y);
    return x;
}
int main(){
	int n,k;
	int a[1005];
	cin >> n >>k;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	int s=0;
	for(int i=0;i<k;i++){
		s+=a[i];
	}
	cout << s <<endl;
	return 0;
}




Measured memory_bytes: 3628
s = input()
length = len(s)

wb = ''
bw = ''
for i in range(0,length):
  if i % 2 == 0:
    wb += '0'
    bw += '1'
  else:
    wb += '1'
    bw += '0'

pat1 = 0
pat2 = 0
for i in range(0, length):
  if s[i] != wb[i]:
    pat1 += 1
  elif s[i] != bw[i]:
    pat2 += 1

if pat1 > pat2:
  print(pat2)
else:
  print(pat1)

Measured memory_bytes: 3316