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

int main (){
	long long int a,b,c,n;
	cin >> a >> b >> c;
	if(c-1<=a+b){
		n=b+c;
	} else {
		n=b+a+b+1;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
//Copyright(c)2017 Mstdream
#include<bits/stdc++.h>
using namespace std;

inline void splay(int &v){
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
const int N=200010;
int nxt[N],fir[N],to[N],sz,dis[N],n,is[N],col[N],vis[N];
void add(int x,int y){
	nxt[++sz]=fir[x],fir[x]=sz,to[sz]=y;
}
void dfs(int x,int fa){
	dis[x]=dis[fa]+1;
	if(x==n){
		is[x]=1;
		return;
	}
	for(int u=fir[x];u;u=nxt[u]){
		if(to[u]!=fa){
			dfs(to[u],x);
			if(is[to[u]]){
				is[x]=1;return;
			}
		}
	}
}
void dfs2(int x,int fa){
	col[x]=col[fa];vis[x]=1;
	for(int u=fir[x];u;u=nxt[u]){
		if(to[u]!=fa){
			if(!col[to[u]]){
				dfs2(to[u],x);
			}
		}
	}
}
int main(){
	splay(n);
	for(int i=1;i<n;i++){
		int x,y;
		splay(x),splay(y);
		add(x,y),add(y,x);
	}
	dfs(1,0);int p=dis[n];
	for(int i=1;i<=n;i++){
		if(is[i]){
			if(dis[i]-1<=dis[n]-dis[i]){
				col[i]=1;
			}
			else col[i]=2;
		}
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs2(i,i);
		}
	}
	int A=0,B=0;
	for(int i=1;i<=n;i++){
		if(col[i]==1)A++;
		else B++;
	}
	if(A>B)puts("Fennec");
	else puts("Snuke");
}

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        int[] inputs = input();
//        int[] inputs = mockup();
        int swapCount = 0;

        for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i : inputs) {
            output.append(i + " ");
        }
        String outputString = output.toString();
        System.out.println(outputString.substring(0,outputString.length() - 1));
        System.out.println(swapCount);
    }

    private static int[] mockup() {
        int a[] = {1,2,3,4,5};
        return a;
    }

    private static void swap(int[] inputs, int j, int i) {
        int a = inputs[j];
        int b = inputs[i];
        inputs[i] = a;
        inputs[j] = b;
    }


    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] inputs = new int[count];
        for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        }
        in.close();
        return inputs;
    }

}

Measured memory_bytes: 18340
#include <bits/stdc++.h>
using namespace std;
 
const int DIM = 2e5 + 5;
 
int arr[DIM];
 
int main( void ) {
    
    int n, t;
    cin >> n >> t;
    
    int ans = 0;
    for( int i = 1; i <= n; i ++ ) {
        cin >> arr[i];
        
        if( i == 1 )
            ans += t;
        else
            ans += t - max( arr[i - 1] + t - arr[i], 0 );
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
o = str(input())
e = str(input())
l = []
if len(o) == len(e):
    for i in range(len(o)):
        l.append(o[i]+e[i])
    print("".join(l))
else:
    for i in range(len(e)):
        l.append(o[i]+e[i])
    print("".join(l)+o[-1])

Measured memory_bytes: 3064
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]

A.sort(reverse=True)
F.sort()

ng = -1
ok = 10**12
while ok - ng > 1 :
    mid = (ok + ng) // 2
    k = 0
    for i in range(N) :
        k += max(0, A[i] - mid // F[i])
    if k <= K :
        ok = mid
    else :
        ng = mid
print(ok)

Measured memory_bytes: 119500
N,A,B,C=map(int,input().split())

llist = []
for i in range(N):
  llist.append(int(input()))
  
blist = [0]*N
min_mp = 10000
for i in range(4**N):
  index = i
  for j in range(N):
    blist[j] = index%4
    index = index//4
  
  if 1 not in blist or 2 not in blist or 3 not in blist:
    continue
  
  #print(blist)
  mp = 0
  len_A = 0
  len_B = 0
  len_C = 0
  for j in range(N):
    if blist[j] == 1:
      if len_A != 0:
        mp += 10
      len_A += llist[j]
    if blist[j] == 2:
      if len_B != 0:
        mp += 10
      len_B += llist[j]
    if blist[j] == 3:
      if len_C != 0:
        mp += 10
      len_C += llist[j]
      
  mp += abs(A-len_A)
  mp += abs(B-len_B)
  mp += abs(C-len_C)
  
  if mp < min_mp:
    min_mp = mp
    
print(min_mp)

Measured memory_bytes: 3064
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = []
for i in range(n):
    A, B = MAP()
    a.append([A+B, A, B])

a.sort(reverse=True)
tmp_a = 0
tmp_b = 0

for i in range(n):
    if i % 2 == 0:
        tmp_a += a[i][1]
    else:
        tmp_b += a[i][2]

ans = tmp_a - tmp_b
print(ans)

Measured memory_bytes: 30328
#include <iostream>
#define int long long
#define INF 1e+18
using namespace std;

signed main(){
	int n,a[200000],sum = 0;
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
		sum += a[i];
	}
	int now = 0,mi = INF;
	for(int i = 0;i < n;i++){
		now += a[i];
		if(i < n - 1) mi = min(mi,abs(now - (sum - now)));
	}
	cout << mi << endl;
	return 0;
}

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

int main() {

  	int n,y;
  	int man = 10000;
  	int gosen = 5000;
  	int sen = 1000;
  	cin >> n >> y;
  	for(int i = n;0 <= i;i--){
      for(int j = n-i;0 <= j;j--){
        for(int k = n-i-j;0 <= k;k--){
          if(i + j + k > n)break;
          if(y == (i *man + j * gosen + k * sen) && n == (i + j + k)){
            cout << i << " "<<  j  << " "<< k << " ";
            return 0;
          }
        }
      }
    }
  cout << "-1" << " "<< "-1" << " "<< "-1" << " ";
      
}


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;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MOD = 1e9+7;
template<class Type>
Type solve(Type res = Type()){
    ll N,M; cin >> N >> M;
    if(abs(N-M)>=2) return 0;
    if(N > M) swap(N,M);
    vector<ll> fact(M+1,1);
    for(int i = 1; i <= M;i++){ fact[i] = fact[i-1]*i%MOD;}
    
    if(N == M) res = fact[M]*fact[N]%MOD*2%MOD;
    else res = fact[M]*fact[N]%MOD;
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 1024
n=int(input())
l = list(map(int,input().split()))
s = set(l)
sl = sorted(list(s))
if len(s)==1 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==2 and l.count(sl[1])==2*n//3 and l.count(sl[0])==n//3 and sl[0]==0:
  print("Yes")
elif n%3==0 and len(s)==3 and l.count(sl[0])==l.count(sl[1])==l.count(sl[2]):
  if sl[0]^sl[1]^sl[2]==0:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 14116
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MOD=1000000007;
ll const INF=1001001001;
typedef pair<int,int> P;

int H,W;
int c[10][10];
int A[200][200];
int cost[10][10];

int main(){
    cin>>H>>W;
    rep(i,10) rep(j,10) cin>>c[i][j];
    rep(i,H) rep(j,W) cin>>A[i][j];
    rep(i,10) fill(cost[i],cost[i]+10,INF);

    rep(s,10){
        cost[s][s]=0;
        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(s,0));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            if(cost[s][p.first]<p.second) continue;
            rep(i,10){
                if(cost[s][p.first]+c[p.first][i]<cost[s][i]){
                    cost[s][i]=cost[s][p.first]+c[p.first][i];
                    que.push(P(i,cost[s][i]));
                }
            }
        }
    }

    int ans=0;
    rep(i,H){
        rep(j,W){
            if(A[i][j]==-1) continue;
            ans+=cost[A[i][j]][1];
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
 
long long s[400][30]; 
const int Shurui=26;//今回は26種類
int Date;//今回は1年間なので365日
long long Seigenjikan=1800000;//実行時間
 
int main() {
  clock_t start = clock();
  cin >>Date;
  vector<int>c(Shurui);
  vector<int>last(Date,0);//前回の日にち
  vector<int>t(Date,0);//開催する順番
  for(int i=0;i<Date;i++)t[i]=i%Shurui;//とりあえずの値
  long long wa=0;
  for(int i=0;i<Shurui;i++){
    cin>>c[i];
    wa+=c[i];
  }
  for(int i=0;i<Date;i++){
    for(int j=0;j<Shurui;j++){
      cin>>s[i][j];
    }
  }
  long long kotae=0;
  long long hikukazu=0;
  long long atai=0;
  for(int i=0;i<Date;i++){
    atai=0;
    atai=s[i][t[i]];
    hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
    last[t[i]]=i+1;
    kotae+=atai-hikukazu;
  }  
  clock_t end = clock();
  long long time = end - start;
  while(time<Seigenjikan){
    int d=rand()%Date;
    int q=rand()%Shurui;
    int old=t[d];
    t[d]=q;
    long long new_kotae=0;
    hikukazu=0;
    for(int i=0;i<Date;i++){
      atai=0;
      atai=s[i][t[i]];
      hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
      last[t[i]]=i+1;
      new_kotae+=atai-hikukazu;
    }
    if(new_kotae<kotae){
      t[d]=old;
    }else{
      kotae=new_kotae;
    }
    end = clock();
    time = end - start;
  }
  for(int i=0;i<Date;i++){
    cout<<t[i]+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3740
/*氏名：保坂優介, 学籍番号：200441141
  概要：整数を計算する*/

#include<stdio.h>

int main(void)
{
    int a, b, d, r;     //変数の宣言
    double f;

    scanf("%d %d", &a, &b);     //入力

    d = a / b;      //計算
    r = a % b;
    f = (double)a / (double)b;

    printf("%d %d %f", d, r, f);        //表示

    return 0;
}


Measured memory_bytes: 2100
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int MOD = 1000000007;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    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); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll N,M;
    cin>>N>>M;
    UnionFind uf(N);
    vector<ll> p(N);
    for(ll i=0;i<N;i++){
        cin>>p[i];
        p[i]--;
    }
    for(ll i=0;i<M;i++){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        uf.merge(a,b);
    }
    ll res=0;
    for(ll i=0;i<N;i++){
        if(uf.root(p[i])==uf.root(i))res++;
    }
    cout<<res<<endl;



}

Measured memory_bytes: 1408
import math
def main():

    while True:
        n = int(input())
        if n == 0:
            break
        else:
            data = list(map(float, input().split()))
            avg = sum(data) / n
            square = 0
            for i in range(n):
                square += data[i]**2
            print(math.sqrt((square / n - avg**2)))
            
if __name__ == '__main__':
    main()



Measured memory_bytes: 5776
from math import ceil
n=int(input())
lst=list(map(int, input().split()))
cut=ceil(n/2)
lst=sorted(lst,reverse=True)
arr=lst[:cut]
f=arr[0]
if n%2==0:
    for i in range(1,len(arr)):
        f+=2*arr[i]
else:
    for i in range(1,len(arr)):
        if i==len(arr)-1:
            f+=arr[i]
        else:
            f+=2*arr[i]
print(f)

Measured memory_bytes: 33036
#include<stdio.h>
int main(void)
{
	char m[8][8];
	int i,j;

	while (scanf("%s",m[0]) != EOF) {
		for (i = 1; i < 8; i++) {
			scanf("%s", m[i]);
		}
	
		for (i = 0; i < 8; i++) {
			for (j = 0; j < 8; j++) {
				if (m[i][j]  == '1') {
					if (m[i][j + 1] == '1' && m[i + 1][j] == '1' && m[i + 1][j + 1] == '1') {
						printf("A\n");
						break;
					}
					else if (m[i + 1][j] == '1' && m[i + 2][j] == '1' && m[i + 3][j] == '1') {
						printf("B\n");
						break;
					}
					else if (m[i][j + 1] == '1' && m[i][j + 2] == '1' && m[i][j + 3] == '1') {
						printf("C\n");
						break;
					}
					else if (m[i + 1][j] == '1' && m[i + 1][j - 1] == '1' && m[i + 2][j - 1] == '1') {
						printf("D\n");
						break;
					}
					else if (m[i][j + 1] == '1' && m[i + 1][j + 1] == '1' && m[i + 1][j + 2] == '1') {
						printf("E\n");
						break;
					}
					else if (m[i + 1][j] == '1' && m[i + 1][j + 1] == '1' && m[i + 2][j + 1] == '1') {
						printf("F\n");
						break;
					}
					else if(m[i][j+1] == '1' && m[i + 1][j - 1] == '1' && m[i + 1][j] == '1'){
						printf("G\n");
						break;
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 524
N=gets.chomp.to_i
X=gets.chomp.split.map(&:to_i)

min=X.min
max=X.max
p=(min+max)/2
a=1000000000000
(0..100).each do |p|
  b=0
  X.each do |i|
    b+=(i-p)*(i-p)
  end
  if b<a then
    a=b
  end
end
puts a

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    long money = 1000;
    for(int i=0;i<n-1;i++){
        if(a[i] < a[i+1]){
            long kabu = money/a[i];
            money -= kabu * a[i];
            money += kabu * a[i+1];
        }
    }
    cout << money << endl;
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

string s;
int main(){
    cin >> s;
    int ok = 1;
    if(s.size()%2 == 1) ok = 0;
    _for(i,0,s.size()){
        if(i%2 && s[i] !='i') ok = 0;
        if(!(i%2) && s[i] != 'h') ok = 0;
    }
    if(ok) cout << "Yes" <<endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
const int MAX = 2000000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


int main(){
    ll x,y,ans=0;
    cin>>x>>y;
    COMinit();
    ll a=x/2;
    rep(i,0,a+1){
      ll b=x-i*2;
      ll d=y-i;
      if(b*2!=d)continue;
      else ans+=COM(b+i, b);
    }
    cout<<ans;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main (){
  int N;
  cin>>N;
  int ans=0;
  vector<int>kumi(1000010,0);
  for(long long i=1;i<1000010;i++){
    int j=1;
    while(i*j<1000010){
      kumi[i*j]++;
      j++;
    }
  }
  for(int i=1;i<N;i++){
    ans+=kumi[i];
  }
  cout<<ans;
}

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

int main() {
    int n, k, sum = 0;
    cin >> n >> k;
    vector<int> l(n);
    rep(i,n) {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    for (int i = n-1; i >= (n-1)-(k-1); i--)
    {
        sum += l[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long int N, M, i, sum, ans;
    cin >> N >> M;
    int A[M];
    for(i = 0; i < M; i++){
        cin >> A[i];
    }
    sum = 0;
    for(i = 0; i < M; i++){
        sum = sum + A[i];
    }
    ans = N - sum;
    if (ans >= 0)    cout << ans;
    else             cout << "-1";  
    
}

Measured memory_bytes: 3664
#include <cstdio>
#include <algorithm>
#include <bitset>

typedef unsigned int ui;
const int MN = 2000;
const int Mod = 998244353;

int N, M, Cnt;
int A[MN][MN];

int Sz; ui *B[MN], *tmp;
#define set(b, i, x) ((x) ? (b[(i) >> 5] |= 1 << ((i) & 31)) : (b[(i) >> 5] &= ~(1 << ((i) & 31))))
#define val(b, i) (b[(i) >> 5] >> ((i) & 31) & 1)

int main() {
	scanf("%d%d", &N, &M);
	if (N > M) {
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j)
				scanf("%d", &A[i][j]);
	}
	else {
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < M; ++j)
				scanf("%d", &A[j][i]);
		std::swap(N, M);
	}
	Sz = (M + 31) >> 5;
	for (int j = 0; j < M; ++j) B[j] = new ui[Sz];
	tmp = new ui[Sz];
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) set(tmp, j, A[i][j]);
		for (int j = M - 1; ~j; --j) if (val(tmp, j)) {
			if (val(B[j], j)) for (int k = 0; k < Sz; ++k) tmp[k] ^= B[j][k];
			else {
				for (int k = 0; k < Sz; ++k) B[j][k] = tmp[k];
				++Cnt;
				break;
			}
		}
	}
	long long Ans = 0;
	for (int i = 0, s = 1; i < N + M; ++i, s = (s << 1) % Mod) {
		if (i == N + M - Cnt - 1) Ans -= s;
		if (i == N + M - 1) Ans += s;
	}
	printf("%lld\n", (Ans % Mod + Mod) % Mod);
	for (int j = 0; j < M; ++j) delete [] B[j];
	delete [] tmp;
	return 0;
}

Measured memory_bytes: 3712
h,w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    ans = int(1e9+5)
    for i in range(h//2+1):
        a1 = i*w
        a2 = w//2*(h-i)
        a3 = (w+1)//2*(h-i)
        ans = min(ans, max(a1,a2,a3)-min(a1,a2,a3))
    for i in range(w//2+1):
        a1 = i*h
        a2 = h//2*(w-i)
        a3 = (h+1)//2*(w-i)
        ans = min(ans, max(a1,a2,a3)-min(a1,a2,a3))
    ans = min(ans, h*((w+2)//3)-h*(w//3))
    ans = min(ans, w*((h+2)//3)-w*(h//3))
    print(ans)




Measured memory_bytes: 70868
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    map<pair<int,int>,int> mpi;
    for(int i=1;i<=n;i++){
        int first = i%10;
        int last = i%10;
        int copy = i;
        while(copy>0){
            last = copy%10;
            copy/=10;
        }
        mpi[{first,last}]++;
    }
    int ans = 0;
    rep(i,10){
        rep(j,10){
            if(i==0 || j==0) continue;
            ans += mpi[{i,j}]*mpi[{j,i}];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include <algorithm>

using namespace std;

int main() {
    int N, D;

    vector<int> squareNums;

    // 平方数計算
    for(int i = 0; i * i < 20000; i++){
        squareNums.push_back(i * i);
    }

    cin >> N >> D;

    int X[N][D];

    // 入力
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int counter = 0;

    for(int i = 0; i < N - 1; i++) {
        for(int j = i + 1; j < N; j++) {
            int judge = 0;
            for(int k = 0; k < D; k++) {
                judge += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            if(find(squareNums.begin(), squareNums.end(), judge) != squareNums.end()){
                counter++;
            }
        }
    }

    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(a: int, s: str):
    if a >= 3200:
        print(s)
    else:
        print("red")
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(a, s)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=P.copy()

for i in range(n):
    P[i]=abs(P[i]-x)
P.sort()
count = -1
for i in range(n):
    if (i+1)//2 == P[i]:
        continue
    else:
        count=(i+1)//2
        break

if n%2==0 and count==-1:
    count=n//2
elif n%2==1 and count==-1:
    count=(n+1)//2

if n==0:
    print(x)
elif x-count in Q:
    print(x+count)
else:
    print(x-count)

Measured memory_bytes: 9244
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    m[i + a[i]]++;
    ans += m[i - a[i]];
  }

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


Measured memory_bytes: 21036
#include<stdio.h>

int main(){
int n,d,x,i,a,ans=0;
scanf("%d%d%d",&n,&d,&x);
for(i=0;i<n;i++){
scanf("%d",&a);
int j=0;
while(a*j+1<=d){
j++;
ans++;
}
}
printf("%d\n",ans+x);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

ll n, m, dp[222][22222];
int tmp;
vi w;

ll solve(int i, int wei)
{
	if (i >= n) return (wei < tmp ? 1 : 0);
	if (dp[i][wei] >= 0) return dp[i][wei];
	ll res = 0;
	if (wei < w[i]) res = solve(i + 1, wei);
	else res = solve(i + 1, wei) + solve(i + 1, wei - w[i]);
	return dp[i][wei] = res%MOD;
}

int main()
{
	cin >> n >> m;
	w.resize(n);
	REP(i, n) cin >> w[i];
	sort(ALL(w));
	int sum = 0;
	ll ans = 0;
	REP(i, n)
	{
		MS(dp, -1);
		tmp = w[i];
		if (m - sum < 0) break;
		ans += solve(i + 1, m-sum);
		ans %= MOD;
		sum += tmp;
	}
	if (sum <= m) ans++;
	cout << ans << endl;
	return 0;
}

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

#define int long long

using namespace std;



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

    int N, K;
    cin >> N >> K;

    vector<int> vect;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;

    	vect.push_back(n);
    }

    int a = 1, b = 1e9, res = -1;

    while(a <= b)
    {
    	int mid = (a+b)/2;

    	bool flag = true;

    	int cont = 0;

    	for(int i = 0 ; i < N ; i++)
    	{
    		if(mid > vect[i])continue;

    		cont += vect[i]/mid - 1;

    		if(vect[i]%mid)cont++;
    	}

    	if(cont > K)flag = false;

    	if(flag)
    	{
    		b = mid-1;
    		res = mid;
    	}
    	else
    	{
    		a = mid+1;
    	}
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 5324
#include <iostream>
using namespace std;
int main() {
  int n, x, ans = 1, at;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    at += l;
    if (at <= x) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// check if it is judged online
long long n;
int main() {
#ifdef LOCAL
	freopen("textname.in", "r", stdin);
	freopen("textname.out", "w", stdout);
#endif
	cin >> n;
	for (int i = sqrt(n); i >= 1; --i) 
		if (n % i == 0) {
			cout << i + (n / i) - 2;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void) {
  long long l[90];
  l[0]=2;
  l[1]=1;
  for(int i=2; i<90; i++) {
    l[i]=l[i-1]+l[i-2];
  }
  int n;
  cin>>n;
  cout<<l[n]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

const int kMod = 1000000007;

// Usage:
//  int N = 100000;
//  int MOD = 1000000007;
//  Comb comb(N, MOD);  // O(N)
//  comb.Calc(N, k);  // O(1)
class Comb {
public:
  Comb(int a_max, int a_mod)
    : max(a_max), mod(a_mod), fac(a_max + 1), finv(a_max + 1), inv(a_max + 1) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i <= max; ++i) {
      fac[i] = fac[i - 1] * i % mod;
      inv[i] = mod - inv[mod % i] * (mod / i ) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }

  long long Calc(int n, int k) {
    assert(n <= max);
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
  
private:
  int max;
  int mod;
  vector<long long> fac;
  vector<long long> finv;
  vector<long long> inv;
};

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  Comb comb(N, kMod);
  
  sort(A.begin(), A.end());

  ll sum_max = 0;
  for (int i = K - 1; i < N; ++i) {
    ll cnt = comb.Calc(i, K - 1);
    sum_max += cnt * A[i] % kMod;
    sum_max %= kMod;
  }

  ll sum_min = 0;
  for (int i = 0; i < N - K + 1; ++i) {
    ll cnt = comb.Calc(N - i - 1, K - 1);
    sum_min += cnt * A[i] % kMod;
    sum_min %= kMod;
  }

  ll ans = (sum_max - sum_min + kMod) % kMod;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#define LL long long
LL n,cnt;
int judge(LL k,LL m){
	while(m>=k){
		if(m%k==0)m/=k;
		else m%=k;
	}
	if(m==1)return 1;
	else return 0;
}
int main(){
	LL i;
	scanf("%lld",&n);
	if(n==2){printf("1\n");return 0;}//注意n=2需特判
	for(i=2;i*i<=n-1;i++)//找n-1的约数
		if((n-1)%i==0){
			cnt++;
			if(i!=(n-1)/i)cnt++;
		}
	cnt++;//加上n-1本身
	for(i=2;i*i<=n;i++)
		if(n%i==0){
			if(judge(i,n))cnt++;
			if(i!=n/i&&judge(n/i,n))cnt++;
		}
	cnt++;//加上n本身
	printf("%lld\n",cnt);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int A,B,C;

int main(){
    cin>>A>>B>>C;
    cout<<((B*10+C)%4==0?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 256
'use strict';

const Main = (input) => {
    const N = input;

    const answer = timestable(N);

	console.log(answer);
}

const timestable = number => {
    if(number > 81) {
        return "No"
    }

    const buffer = [];
    for(let i = 1; i <= 9; i++) {
        if(number % i == 0) {
            buffer.push(i);
        }
    }
  
    for(let i = 0; i <= buffer.length; i++) {
        for(let n = 0; n <= buffer.length; n++) {
            if(buffer[i] * buffer[n] == number) {
                return "Yes";
            }
        }
    }

    return "No"
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],cnt[100];
vector <long long int> v;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	long long n,i,j,k,x,y,z,f;
	cnt[1]=9;
	cnt[2]=26;
	for (i=1;i<=9;i++)
	{
		v.push_back(i);
	}
	x=9;
	y=0;
	while (v.size()<=100007)
	{
		for (i=y;i<x;i++)
		{
			if (v[i]%10==9)
			{
				v.push_back(v[i]*10+v[i]%10-1);
				v.push_back(v[i]*10+v[i]%10);				
			}
			else if (v[i]%10==0)
			{
				v.push_back(v[i]*10+v[i]%10);
				v.push_back(v[i]*10+v[i]%10+1);				
			}
			else
			{
				v.push_back(v[i]*10+v[i]%10-1);
				v.push_back(v[i]*10+v[i]%10);
				v.push_back(v[i]*10+v[i]%10+1);
			}
		}
		y=x;
		x=v.size();
	}
	sort(v.begin(),v.end());
    cin>>n;
    cout<<v[n-1]<<endl;
}

Measured memory_bytes: 2420
//#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

ll mod_pow(ll m, ll n) {
    if(n==1) return m;
    ll v;
    v = mod_pow(m, n/2)%MOD;
    if(n%2==0) return (v*v)%MOD;
    else return ((v*v)%MOD*m)%MOD;
}


int main()
{
    ll n, m, ans=1;
    cin >> m >> n;
    cout << mod_pow(m,n) << endl;
    return 0;
}

Measured memory_bytes: 3104
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int ,int>> c(M);
    for (int m = 0; m < M; m++) {
        int p, y;
        cin >> p >> y;
        c[m] = make_tuple(m, p, y);
    }
    sort(c.begin(), c.end(), [](const auto& a, const auto& b) { return get<2>(a) < get<2>(b); });

    vector<int> counter(N);
    vector<string> res(M);
    for (auto a: c) {
        int p = get<1>(a);
        counter[p - 1] += 1;
        ostringstream s;
        s << setfill('0') << setw(6) << p;
        s << setfill('0') << setw(6) << counter[p - 1];
        res[get<0>(a)] = s.str();
    }

    for (auto s: res) cout << s << endl;

    return 0;
}


Measured memory_bytes: 8576
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
# print(N)
# print(A)
nex = 1
ans = 0

for i in range(N):
    if A[i] == nex:
        nex += 1
    else:
        ans += 1

print(-1) if N == ans else print(ans)


Measured memory_bytes: 27016
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,x;
  cin >> n >> x;
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  long long cnt=0;
  if(a[0]>x){
    cnt+=a[0]-x;
    a[0]=x;
  }
  for(int i=0;i<n-1;i++){
    if(a[i]+a[i+1]>x){
      cnt+=a[i]+a[i+1]-x;
      a[i+1]=x-a[i];
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
class Main {
   public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		boolean t;
		int count = 0;
		
		for(int i = 0; i < input; i++){
			num[i] = scan.nextInt();
			
			if(isPrime(num[i])) {
				count++;
			}
		}
		
		System.out.println(count);
	}
	
	static boolean isPrime(int x){
		if(x == 2) 
			return true;
		
		if(x < 2 || (x % 2) == 0) 
			return false;
		
		for(int i = 3; i <= Math.sqrt(x); i += 2){
			if(x % i == 0){
				return false;
			}
		}
		return true;
	}
}

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

int main()
{
    string s;
    cin >> s;
    int min = 753;
    int n = s.length();
    for(int i = 0; i < n - 2; ++i) {
        int abs753 = abs(atoi(s.substr(i, 3).c_str()) - 753);
        min = min > abs753 ? abs753 : min;
    }
    cout << min;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{

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

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


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

if(a==b)
{
   printf("a == b\n");
}
return 0;

}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,m,x,y,z;
vector<int> v[8],ans;

main() {
    cin >> n >> m;
    rep(i,n) {
        cin >> x >> y >> z;
        v[0].pb(x+y+z)
        v[1].pb(x*-1+y+z)
        v[2].pb(x+y*-1+z)
        v[3].pb(x+y+z*-1)
        v[4].pb(x*-1+y*-1+z)
        v[5].pb(x*-1+y+z*-1)
        v[6].pb(x+y*-1+z*-1)
        v[7].pb(x*-1+y*-1+z*-1)
    }
    rep(i,8) {
        int tmp = 0;
        sort(rall(v[i]));
        rep(j,m) tmp += v[i][j];
        ans.pb(tmp);
    }
    sort(rall(ans));
    cout << ans[0] << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll a[n], b[n];
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for(int i = n - 1; i >= 0; i--){
        if((ans + a[i]) % b[i] != 0) ans += b[i] - (ans + a[i]) % b[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = 0;
		for(int i = 0 ; i < 5 ; i++) {
			n++;
			if(sc.nextInt() == 0) {
				System.out.println(n);
			}
		}
	}


}



Measured memory_bytes: 35660
N,X,M = map(int,input().split())
R = [X]
dr = {}
for i in range(M):
    dr[i] = 0
m = min(N,M)
for i in range(m):
    r = R[-1]
    r = r**2%M
    if dr[r] == 1:
        break
    R.append(r)
    dr[r] = 1
for i in range(len(R)):
    if r == R[i]:
        break
a = 0
b = sum(R)
for j in range(i):
    a += R[j]
    b -= R[j]
n = len(R) - i
t = N - i
p = t // n
q = t % n
c = 0
for j in range(q):
    c += R[i+j]
ans = a + b*p + c
print(ans)

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

int fst[433333], nxt[433333], tot = 0;

struct qer
{
    int f, t;
} es[433333];

void build(int f, int t)
{
    es[++tot] = (qer){f, t};
    nxt[tot] = fst[f];
    fst[f] = tot;
}

int ans = 0, st = 0;

void dfs(int u, int fa, int len)
{
    if (len > ans)
        st = u, ans = len;
    for (int i = fst[u]; i; i = nxt[i])
        if (es[i].t != fa)
            dfs(es[i].t, u, len + 1);
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int f, t;
        scanf("%d%d", &f, &t);
        build(f, t);
        build(t, f);
    }
    dfs(1, 0, 0);
    ans = 0;
    dfs(st, 0, 0);
    if (ans % 3 == 1)
        puts("Second");
    else
        puts("First");
    return 0;
}

Measured memory_bytes: 15744
package main

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

func main() {
	var n, x int
	fmt.Scan(&n)
	fmt.Scan(&x)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	d := 0
	ret := 1
	for i := 0; i < n; i++ {
		scanner.Scan()
		l, _ := strconv.Atoi(scanner.Text())
		d += l
		if d <= x {
			ret++
		}
	}

	fmt.Println(ret)
}


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

int main() {
  // Not so Diverse
  int n, k; cin >> n >> k;
  int ans = 0;
  map<int,int> m;
  rep(i,n) {
    int ai; cin >> ai;
    m[ai]++;
  }
  int ms = m.size();
  if (ms > k) {
    priority_queue<P, vector<P>, greater<P>> pq;
    for (auto mi : m) {
      pq.push(make_pair(mi.second, mi.first));
    }
    while (pq.size() > k) {
      int c = pq.top().first; pq.pop();
      ans += c;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14468
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    divisors.sort()
    return divisors
N=int(input())
mem=make_divisors(N)
if len(mem)%2==0: ans=(mem[(len(mem)//2)-1]+mem[(len(mem)//2)])-2
else: ans=(mem[(len(mem)//2)]*2)-2
print(ans)

Measured memory_bytes: 3268
import sys

def input(): return sys.stdin.readline().rstrip("\r\n")
def List(): return list(map(int, input().split()))
def Num(): return int(input())


s = input()
if "RRR" in s:
    print(3)
elif 'RR' in s:
    print(2)
elif "R" in s:
    print(1)
else:
    print(0)


Measured memory_bytes: 9044
#include<bits/stdc++.h>
#define int long long 

using namespace std ;

int n,k=0; 
vector<int>graph[100001];
map<pair<int,int>,int>edge_color;
pair<int,int>edge[100001];
int color[100001];

void dfs(int v, int parent ){
        int cnt = 1; 
        for(int i : graph[v]){
                if(i == parent) continue ;
                if(cnt == color[v]) cnt++;
                color[i] = cnt ;
                edge_color[make_pair(v,i)] = cnt;
                edge_color[make_pair(i,v)] = cnt;
                k = max(k,cnt);
                cnt++;
                dfs(i,v);
        }
}

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

        cin >> n ;
        for(int i=0;i<n-1;i++){
                int a , b ; cin >> a >> b ;
                a--;b--; graph[a].emplace_back(b);
                graph[b].emplace_back(a);
                edge[i] = {a,b};
        }
        
        memset(color,0,sizeof(color));

        dfs(0,-1);

        cout << (*max_element(color,color+n)) << endl; 

        for(int i = 0 ; i < n-1 ; i++ )
                cout << edge_color[edge[i]] << endl ;


        return 0;
}

Measured memory_bytes: 22016
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) std::cout << (x) << std::endl
typedef long long ll;

int main() {
    ll h;
    cin >> h;
    ll ans = 0;
    for (ll i = 1; h > 0; i *= 2) {
        ans += i;
        h /= 2;
    }
    OUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n;
  cin >> n;
  vector<int> a(n), b(n);
  int mmin = INF;
  int minI = 0;
  int mmax = 0;
  int maxI = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    if(mmin > b[i]) {
      mmin = b[i];
      minI = a[i];
    }

    if(mmax < b[i]) {
      mmax = b[i];
      maxI = a[i];
    }
  }

  int ans = minI + mmin;

  cout << ans << ln;

  return 0;
}

/*
1 2 3 4 5 6 7 8 9
x 9 x 7 x 2 1 0
*/

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
	int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    int ans = 0;
    rep(i,N-1){
        if(a[i] == a[i+1]){
            a[i+1] = -1;
            ans++;
        }
    }
    cout << ans << endl;
}
   


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



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

int main(){

    int A;
    int B;
    int C;
    int ans;
    int V1,V2,V3;

    cin >> A;
    cin >> B;
    cin >> C;

    V1 = A;
    if ( V1 < B){
        V2 = V1;
        V1 = B;
    }
    else V2 = B ;

    if (V1 < C ){
        V3 = V2;
        V2 = V1;
        V1 = C;
    }else if ( V2 < C ){
        V3 = V2;
        V2 = C;
    }else{
        V3 = C;
    }

    ans = V1 * 10 + V2 + V3;
    cout << ans;



    return 0;
}

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N, Q, ans;
   string S;

   cin >> N >> Q >> S;

   vector<int> pos(N + 1);
   rep(i, N - 1) {
     if (S.at(i) == 'A' && S.at(i + 1) == 'C') pos.at(i + 2) = pos.at(i + 1) + 1;
     else pos.at(i + 2) = pos.at(i + 1);
   }

   vector<int> l(Q), r(Q);
   rep(i, Q) cin >> l.at(i) >> r.at(i);

   rep(i, Q) cout << pos.at(r.at(i)) - pos.at(l.at(i)) << endl;
 }


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  string S1,S2; cin>>S1>>S2;
  int ans=3;
  int k=1;
  bool flag=1;
  if(S1[0]==S1[1]){
    ans*=2;
    k++;
    flag=0;
  }
  rep(i,k,N){
    if(S1[i]==S1[i+1]){
      i++;
      if(flag)
        ans*=2;
      else
        ans*=3;
      ans%=MOD;
      flag=0;
    }
    else{
      if(flag){
        ans*=2;
        ans%=MOD;
      }
      flag=1;
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
(defun judge (s &optional (c 0))
  (cond
    ((null (cdr s)) c)
    ((equal (first s) (car (last s))) (judge (cdr (butlast s)) c))
    (t                               (judge (cdr (butlast s)) (+ c 1))))
  )

     

(let ((S (concatenate 'list (read-line))))
      (princ (judge S)))          

Measured memory_bytes: 3808