akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <unordered_set>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
template<class T> using vv=vector< vector<T> >;
typedef deque<int> di;
typedef deque< deque<int> > ddi;


int main() {
    int n;
    unordered_set<string>  ss;
    cin >> n;
    rep(i,n){
        string inst,tmp;
        cin >> inst >> tmp;
        if(inst == "insert") {
            ss.insert(tmp);
        } else {
            if(ss.count(tmp)) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
	return 0;
}

Measured memory_bytes: 31944
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
template<class T>inline bool chmax(T& a, T b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T& a, T b){if(a > b){a = b; return 1;}return 0;}
const ll INF = 1LL<<60;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll binary_search(ll key) {
    int ng = -1; 
    int ok = 1000000; 

    //ok と ng のどちらが大きいかわからないことを考慮
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if(mid*(mid+1) >= 2*key) ok = mid;
        else ng = mid;
    }
    return ok;
}

void solve(){
    ll x; cin >> x;
    ll res = binary_search(x);
    cout << res << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
int main(){
    int N,C,K; SCD3(N,C,K);
    vector<int> T;
    REP(i,N){
        int x; SCD(x); T.PB(x);
    }

    sort(T.begin(),T.end());

    int count = 0;
    int ans = 0;
    while(count < N){
        int takes = 0;
        int dtime = T[count] + K;
        ans++; takes++;
        FORq(i,1,C-1){
            if (count+i >= N) break;
            if (T[count+i] <= dtime){
                takes++;
            }else{
                break;
            }
        }

        count += takes;
    }

    PRINTD(ans);

}

Measured memory_bytes: 892
# pythonの場合、ライブラリ関数でgcdがある？ただし、配列まとめてというわけではない模様
from math import gcd

def main():
	N = int(input())
	A = list(map(int,input().split()))

	pc = True
	maxA = max(A)

	cnts = [ 0 for _ in range(maxA+1) ]
	for a in A:
		cnts[a] += 1
	for i in range(2,maxA):
		if pc:
			# 素因数ごとに、A内での登場回数を数える
			# 2つあったらその2つのcommon dividerとして、1以外にそれがあることが確定する
			cnt = 0
			for j in range(i,maxA+1,i):
				cnt += cnts[j]
				if 1 < cnt:
					# Aの素因数で重複があれば、pcでない
					pc = False
					break

	sc = False

	if pc == False:
		gcdResult = 0
		for a in A:
			# 配列全要素に対してgcdを呼んでるが、結果的に、それが1になればsc、ならなければnot sc
			gcdResult=gcd(gcdResult,a)
		if gcdResult == 1:
			sc = True

	if pc:
		print("pairwise coprime")
	elif sc:
		print("setwise coprime")
	else:
		print("not coprime")






if __name__ == "__main__":
	main()



Measured memory_bytes: 220616
using System;
using System.IO;

namespace AtCoder {
	class Program {
		public static void Main(string[] args) {
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

			string str = Console.ReadLine();
			if (str[2] == str[3] && str[4] == str[5]) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}

			Console.Out.Flush();
		}
	}
}

Measured memory_bytes: 11092
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>

#define N 3
#define N2 9
#define LIMIT 100

using namespace std;

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle {
  int f[N2], space, MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz){
  int sum = 0;
  for(int i=0; i<N2; i++){
    if(pz.f[i] == N2) continue;
    sum += MDT[i][pz.f[i]-1];
  }
  return sum;
}

bool isSolved(){
  for(int i=0; i<N2; i++)
    if(state.f[i] != i+1) return false;
  return true;
}

bool dfs(int depth, int prev){
  if(state.MD == 0) return true;

  if(depth+state.MD > limit) return false;

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;

  for(int r=0; r<4; r++){
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    
    if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
       if(max(prev, r)-min(prev, r) == 2) continue;
       tmp = state;

       state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
       state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
       swap(state.f[tx*N+ty], state.f[sx*N+sy]);
       state.space = tx*N+ty;
       if(dfs(depth+1,r) ) {path[depth] = r; return true; }
       state = tmp;
  }       
       
    return false;
  
}    


string iterative_deepening(Puzzle in){
  in.MD = getAllMD(in);

  for(limit = in.MD; limit <= LIMIT; limit++){
    state = in;
    if(dfs(0, -100) ){
      string ans = "";
      for(int i = 0; i<limit; i++) ans += dir[path[i]];
      return ans;
    }
  }

  return "unsolvable";
}

int main(){
  for(int i=0; i<N2; i++)
    for(int j=0; j<N2; j++)
      MDT[i][j] = abs(i/N - j/N) + abs(i%N - j%N);

  Puzzle in;

  for(int i=0; i<N2; i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;

  return 0;

}



Measured memory_bytes: 3200
fh=STDIN
while fh.gets do
  reg = Regexp.new("[+=]")
  s=$_.chomp.split(reg)
  t =("0".."9").to_a.select { |x|
    s0=s[0].gsub(/X/,x)
    s1=s[1].gsub(/X/,x)
    s2=s[2].gsub(/X/,x)
    s0==s0.to_i.to_s and s1==s1.to_i.to_s and s2==s2.to_i.to_s \
      and s0.to_i + s1.to_i == s2.to_i}
  puts (t.length==0) ? "NA" : t[0]
end

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

#define ll long long int
#define vi vector<int>

int main() {

    ll N, A, B;
    cin >> N >> A >> B;

    ll ans = 0;
    ans += (N/(A+B)) * A;
    ans += min(N%(A+B), A);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
NM = list(map(int, input().split()))
A = list(map(int, input().split()))

count = 0
sumA = sum(A)
board = sumA / (4*NM[1])


# print(sumA)
# print(board)

for i in range(len(A)):
    if float(A[i]) >= board:
        count += 1
    else:
        continue


if count >= NM[1]:
    print("Yes")
else:
    print("No")


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

int main() {
    int c11, c12, c13;
    int c21, c22, c23;
    int c31, c32, c33;
    
    cin >> c11 >> c12 >> c13;
    cin >> c21 >> c22 >> c23;
    cin >> c31 >> c32 >> c33;

    int d1 = c11 - c12;
    int d2 = c12 - c13;

    string out;

    if (c21 - c22 == d1 && c22 - c23 == d2 && c31 - c32 == d1 && c32 - c33 == d2) {
        out = "Yes";
    } else {
        out = "No";
    }

    cout << out << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

H, W = mi()
S = [li() for _ in range(H)]
f = 0
ans = []

for j in range(W):
    if not j%2:
        for i in range(H):
            if f:
                ans.append([pi, pj, i+1, j+1])
            if S[i][j] % 2:
                f = 1 - f
            pi, pj = i+1, j+1
    if j%2:
        for i in reversed(range(H)):
            if f:
                ans.append([pi, pj, i+1, j+1])
            if S[i][j] % 2:
                f = 1 - f
            pi, pj = i+1, j+1


N = len(ans)
print(N)
for i in range(N):
    print(ans[i][0], ans[i][1], ans[i][2], ans[i][3])

Measured memory_bytes: 73052
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll C, ll mod){
  ll ans = 1; C = min(C, N - C);
  for (ll i = 1; i <= C; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}

int main(){
  string S, T; cin >> S >> T;
  int A, B; cin >> A >> B;
  string U; cin >> U;
  if (S == U) A--;
  else B--;
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int A[3];
	rep(i, 3) cin >> A[i];
	sort(A, A + 3);
	cout << A[2] * 10 + A[1] + A[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
	int l, r; cin>>l>>r;
	if(r - l > 1e4){
		cout<<0<<endl;
		return 0;
	}
	int ans = 2019;
	for(int i = l; i < r; i++){
		for(int j = i + 1; j <= r; j++){
			ans = min(ans, i * j % 2019);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "math.h"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;

int main() {
	int ans = 0;
	int a, b, plug = 1;
	cin >> a >> b;
	while (plug < b) {
		plug += (a - 1);
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
 #include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int oe[2][100005];

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n) {
		int v;
		scanf("%d", &v);
		oe[i & 1][v]++;
	}
	vector<PII> v[2];
	REP(i, 100005) {
		if (oe[0][i])v[0].PB(MP(oe[0][i], i));
		if (oe[1][i])v[1].PB(MP(oe[1][i], i));
	}
	v[0].PB(MP(0, 0));
	v[1].PB(MP(0, 0));
	sort(ALL(v[0]), greater<PII>());
	sort(ALL(v[1]), greater<PII>());
	if (v[0][0].second != v[1][0].second) {
		cout << (n + 1) / 2 + n / 2 - v[0][0].first - v[1][0].first << endl;
		return 0;
	}
	cout << (n + 1) / 2 + n / 2 - max(v[0][1].first + v[1][0].first, v[0][0].first + v[1][1].first) << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'C')ans = 1;
        if(s[i] == 'F'){
            if(ans == 1){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	map<int, int> mp;
	for(int i = 0; i < n; i++){
		int x;
		cin>>x;
		mp[x]++;
	}
	vector<pair<int, int> > v(m);
	for(auto &x : v){
		cin>>x.second>>x.first;
	}
	sort(v.rbegin(), v.rend());
	for(auto pp : v){
		int b = pp.second;
		int c = pp.first;
		if((*mp.begin()).first >= c)break;
		while(b--){
			int val = (*mp.begin()).first;
			if(c <= val)break;
			mp[val]--;
			if(!mp[val])mp.erase(val);
			mp[c]++;
		}
	}
	ll ans = 0;
	for(auto x : mp){
		ans += x.first*1LL*x.second;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<stdlib.h>



int main(){
  int i,n,q,j,count=0;
  int *S;
  scanf("%d",&n);
  S=malloc((n+1)*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&S[n]);
    j=0;
    while(1){
      if(S[j]==S[n]){
        if(j!=n) count++;
        break;
      }
      j++;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 636
from itertools import accumulate

N, K = map(int, input().split())
a = [i for i in range(N+1)]
# print(a)
b = list(accumulate(a))
# print(b)
# print(a)
mod = 10**9 + 7
ans = 0

for i in range(K, N+2):
    if i == N+1:
        end = b[N]
        start = b[i-1] - b[0]
    else:
        end = b[N] - b[N-i]
        start = b[i-1] - b[0]
    # print(end)
    # print(start)
    ans += end - start + 1
print(ans % mod)


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

int main(){
    ll k , a , b ;
     cin >> k >> a >> b ;
     ll i ; 
     for ( i = a ; i <= b ; i++ ){
         if ( i % k == 0 ){
             cout << "OK" ; return 0;
         }
     }
     cout << "NG" ;
} 

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

using namespace std;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	if(a*b>c*d){
		cout<<a*b<<endl;
		}
	else{
		cout<<c*d<<endl;
		}	
	}

Measured memory_bytes: 256
s = input()
t = input()
list1 = list()
y = list()
for i in range(len(s)):
    if i < (len(s)-len(t)+1):
        list1.append(s[i:(i+len(t))])
for j in range(len(list1)):
    count = 0
    for k in range(len(t)):
        if list1[j][k] != t[k]:
            count = count + 1
    y.append(count)
print(min(y))


Measured memory_bytes: 9184
n,x = map(int,input().split())
a_list = list(map(int,input().split()))
count = 0
for i in range(1,n):
  if a_list[i-1] + a_list[i] > x:
    count += a_list[i-1] + a_list[i] - x
    if a_list[i-1] + a_list[i] - x > a_list[i]:
      a_list[i] = 0
    else:
      a_list[i] = x - a_list[i - 1]
print(count)

Measured memory_bytes: 14472
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(void){
  int n;
  double m,vote=0;
  cin>>n>>m;
  vi a(n);
  rep(i,0,n){
    cin>>a[i];
    vote+=a[i];
  }
  sort(all(a));
  
  if(a[n-m]<(double)vote/4/m){
    cout << "No";
  }else{
    cout << "Yes";
  }
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
x = 1
if 0 in a:
    x = 0
else:
    for i in range(n):
        if x != -1:
            x = x * a[i]
        if x > 10 ** 18:
            x = -1
print(x)

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

int main() {
    int r, g, b, n = 3, total = 0, m = 100, i = 0;
    cin >> r >> g >> b;
    vector <int> a = {r,g,b};
    while(n--){
        total += m * a[i++];
        m/=10;
    }
    total%4 == 0? cout << "YES" << endl : cout << "NO" << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;

    SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) {
        init(n);
    }
    void init(int n) {
        SIZE_R = 1;
        while(SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }

    // set, a is 0-indexed
    void set(int a, const Monoid &v) {
        dat[a + SIZE_R] = v;
    }
    void build() {
        for(int k = SIZE_R - 1; k > 0; k--) {
            dat[k] = F(dat[k*2], dat[k*2+1]);
        }
    }

    // update a is 0-indexed
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while(k >>= 1) {
            dat[k] = F(dat[k*2], dat[k*2+1]);
        }
    }

    // get {min-value, min-index}, a and b are 0-indexed
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if(left & 1) vleft = F(vleft, dat[left++]);
            if(right & 1) vright = F(dat[--right], vright);
        }
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }

    // debug
    void print() {
        for (int i = 0; i < SIZE_R; i++) {
            cout << (*this)[i];
            if(i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};


// 最大公約数(ユークリッドの互除法)
// O(log max(a, b))
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main(){
    int n, q, com, x, y;
    cin >> n;
    auto fx = [](int x1, int x2) -> int {return gcd(x1, x2);};
    int ex = 0;
    SegTree<int> seg(n, fx, ex);
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        seg.set(i, a[i]);
    }
    seg.build();

    int ans = 0;
    rep(i, n) {
        int l = seg.get(0, i);
        int r = seg.get(i+1, n);
        chmax(ans, gcd(l, r));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4536
#include<stdio.h>
#include<algorithm>
#include<string.h>

char a[1001] = { 0 };
char b[1001] = { 0 };
int main() {

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%s", &a);
	
	int len, A = 0, C = 0,S = 0;;
	
	len = strlen(a);
	
	for (int i = 0; i < len; i++) {
		if (a[i] == 'A') {
			A++;
			if (i != 0) {
				printf("WA");
				S = 1;
				break;
			}
		}
		else if (a[i] == 'C') {
			C++;
			if (i < 2 || i >= len - 1) {//범위 over
				printf("WA");
				S = 1;
				break;
			}
		}
		else if (a[i] < 'a') {
			printf("WA");
			S = 1;
			break;
		}
	}
	if (S != 1) {
		if (A != 1 || C != 1) {
			printf("WA");
			S = 1;
		}
		else {
			printf("AC");
		}
	}
}

Measured memory_bytes: 128
tmp = "abcdefghijklmnopqrstuvwxyz"
alph = list(tmp)
alphcount = [0]*26

while True:
    try:
        letter = input()
        letterarray = list(letter.lower())
        # print(letterarray)

    except:
        break

    for x in letterarray:
        for i in range(26) :
            if (x == alph[i]):
                alphcount[i] += 1

            else :
                continue

for i in range(26):
    print(str(alph[i])+" : "+str(alphcount[i]))



Measured memory_bytes: 5560
N, K = map(int, input().split())

d = []
l = []
i = 0

while i < 2*K:
  i += 1
  if i % 2 == 0:
    l.extend([int(x) for x in input().split()])
  else:
    d.append(int(input()))

L = list(set(l))
print(N - len(L))

Measured memory_bytes: 67600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int a,b,c;cin>>a>>b>>c;
    if(a>b)swap(a,b);
    if(b>c)swap(b,c);
    if(a>b)swap(a,b);
    int atmp=(c-a)/2;
    int btmp=(c-b)/2;
    int ans;
    if((c-a)%2!=(c-b)%2)ans=2;
    else {
        if((c-a)%2==0 && (c-b)%2==0)ans=0;
        else ans=1;
    }
    cout<<ans+atmp+btmp<<endl;
}


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

//配列の要素を順番に出力
void trace(int A[], int N){
    rep(i,N){
        if (i!=0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertion(int A[],int N){
    for (int i=1; i<N; i++){
        int v=A[i];
        int j=i-1;
        while(j>=0 && A[j]>v){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(){
    int N;
    int A[100];
    scanf("%d",&N);
    rep(i,N) scanf("%d",&A[i]);
    trace(A,N);
    insertion(A,N);
    return 0;
}


Measured memory_bytes: 3224
n = gets.to_i

road = Array.new(n+1).map{[]}
(n-1).times do
    a,b = gets.split.map(&:to_i)
    road[a] << b
    road[b] << a
end

j = Array.new(n+1,10**6)
queue = [1]
j[1] = 0
while x = queue.shift do
    road[x].each do |e|
        if j[e] > j[x] + 1
            j[e] = j[x] + 1 
            queue << e
        end
    end
end

queue = [n]
j[n] = 0
count = 1
while x = queue.shift do
    road[x].each do |e|
        if j[e] > j[x] + 1
            j[e] = j[x] + 1 
            queue << e
            count += 1
        end
    end
end

puts count >= (n+1)/2 ? "Snuke" : "Fennec"

Measured memory_bytes: 13308
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> L(N * 2);
		for(int i = 0; i < N * 2; ++ i)
			scanf("%d", &L[i]);
		sort(L.begin(), L.end());
		int ans = 0;
		rep(i, N)
			ans += L[i * 2];
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int P = sc.nextInt();
    int ans = (A * 3 + P) / 2;
    System.out.println(ans);
  }

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

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
  	ll sum = 0;
    for(int i=1; i<=n; ++i){
        if((i%3 != 0) && (i%5 != 0)){
            sum += i;
        }
    }
  	cout << sum;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t; cin>>s>>t;
    int h = s.size(), w = t.size();
    vector <vector<int>> dp(s.size()+5,vector <int>(t.size()+5));
    
    rep(i,h){
        rep(j,w){
            if(j-1>=0) chmax(dp[i][j], dp[i][j-1]);
            if(i-1>=0) chmax(dp[i][j], dp[i-1][j]);
            if(s[i] == t[j]){
                chmax(dp[i][j], 1 + ((i-1>=0 && j-1>=0)? dp[i-1][j-1] : 0 ));
            }
        }
    }
    vector <vector<int>> g(h,vector <int>(w));
    queue <pair <int,int>> q;
    q.push({h-1, w-1});
    string ans = "";
    int x = dp[h-1][w-1];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            //cout<<dp[i][j];
            
        }
        //cout<<endl;
    }
    int i = h-1, j = w-1;
    while(i >= 0 && j >= 0){
        if( ((i==0) ? 0LL :dp[i-1][j]) == dp[i][j]){
            i--;
        }else if(((j == 0) ? 0LL : dp[i][j-1]) == dp[i][j]){
            j--;
        }else{
            ans += s[i];
            i--;
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}


Measured memory_bytes: 141312
N, M = map(int, input().split())
L = [[] for i in range(N)]
ans = []
for i in range(M) :
    info, num = map(int, input().split())
    
    if info == 1 :
        x = 0
        for j in range(1, N) :
            if len(L[j]) < len(L[x]) :
                x = j
        L[x].append(num)
    else :
        ans.append(L[num-1][0])
        del L[num-1][0]
print(*ans, sep='\n')
    


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001

int main() {
    int k, s, z;
    int ans=0;
    cin >> k >> s;
    for(int i=0; i<=k; i++) {
        for(int j=0; j<=k; j++) {
            z = s-i-j;
            if (z >= 0 && z <= k) ans ++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}


fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
      a
    } else {
      gcd(b, a % b)
    }
}  

fn divisors(n: u64) -> Vec<u64> {
    let mut divisors: Vec<u64> = Vec::new();
    for i in 1..(n+1) {
        if i * i > n {
            break;
        }
        if n % i == 0 {
            divisors.push(i);
            if i * i != n {
                divisors.push(n / i);
            }
        }
    }
    divisors
}

fn main() {
    let (a, b, k) = input_tuple();
    let mut divisors = divisors(gcd(a, b));
    divisors.sort_by(|x, y| y.cmp(&x));
    println!("{:?}", divisors[(k-1) as usize]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=1005;
const ll inf=(ll)1e15;
ll a[N];
bool mark[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  int mx=INT_MIN,mxind=-1;
  rep(i,1,n+1)
    {
      cin>>a[i];
      if(a[i]>mx) mx=a[i],mxind=i;
    }
  if(mx<0)
    {
      cout<<mx<<endl;
      cout<<n-1<<endl;
      repv(i,mxind+1,n+1) cout<<i<<endl;
      rep(i,1,mxind) cout<<1<<endl;
      return 0;
    }
  ll ans=-inf;
  int ind=-1;
  rep(j,0,2)
    {
      ll sum=0;
      int cnt=0;
      for(int i=1+j;i<=n;i+=2)
	if(a[i]>=0) sum+=a[i],cnt++;
      if(sum>ans) ans=sum,ind=j;
    }
  cout<<ans<<endl;
  vi inds;
  for(int i=1+ind;i<=n;i+=2)
    if(a[i]>=0) inds.pb(i),mark[i]=true;
  vi rem;
  int sz=n;
  rep(i,1,inds[0]) rem.pb(1),sz--;
  repv(i,inds.back()+1,n+1) rem.pb(sz),sz--;
  vi newarr;
  rep(i,inds[0],inds.back()+1) newarr.pb(i);
  while(sz(newarr)>1)
    {
      vi tmp;
      rep(i,0,sz(newarr))
	{
	  if(mark[newarr[i]]) continue;
	  if(mark[newarr[i-1]] && mark[newarr[i+1]])
	    {
	      rem.pb(i+1);
	      break;
	    }
	  if(!mark[newarr[i-1]] && !mark[newarr[i+1]])
	    {
	      rem.pb(i+1);
	      break;
	    }
	}
      rep(i,0,rem.back()-1)
	tmp.pb(newarr[i]);
      rep(i,rem.back()+1,sz(newarr))
	tmp.pb(newarr[i]);
      swap(tmp,newarr);
    }
  cout<<sz(rem)<<endl;
  for(int x:rem) cout<<x<<endl;
  return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

ll cx(ll n) {
    ll c = (n >> 1) & 1LL;
    if (n % 2 == 1) return c ^ 1;
    else return n | c;
}

int main() {
    ll a, b;
    cin >> a >> b;

    cout << (cx(b) ^ cx(a) ^ a) << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n,mod = map(int,input().split())
s = input()
if mod == 2:
    ans = 0
    for i in range(n-1,-1,-1):
        if int(s[i]) % 2 == 0:
            ans += i+1
    print(ans)
    quit()
elif mod == 5:
    ans = 0
    for i in range(n-1,-1,-1):
        if int(s[i]) % 5 == 0:
            ans += i+1
    print(ans)
    quit()

l = [0]*(n+1)
for i in range(n-1,-1,-1):
    l[i] = (l[i+1]+int(s[i])*pow(10,n-1-i,mod))%mod
#print(l)
c = Counter(l)
#print(c)
def nC2(i):
    return i*(i-1)//2
ans = c[0]-1+nC2(c[0]-1)
for i in range(1,mod):
    ans += nC2(c[i])
print(ans)

Measured memory_bytes: 11988
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll k;
  cin >> k;
  
  ll ans = 0;
  for(ll a=1;a<k+1;a++){
    for(ll b=1;b<k+1;b++){
      for(ll c=1;c<k+1;c++){
        ans+=gcd(a,gcd(b,c));
      }
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int N,K;
    cin >> N >> K;
    map<int,int> mp;
    for (int i=0; i<K; i++) {
        int d;
        cin >> d;
        for (int i=0; i<d; i++) {
            int a;
            cin >> a;
            mp[a]++;
        }
    }
    int ans=0;
    for (int i=1; i<=N; i++) {
        if (mp[i] == 0) ans++;
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
int main() {
	std::string s, t;
	std::cin >> s >> t;
	for (auto i = 0; i < s.size(); ++i) {
		bool is_equal = true;
		for (auto j = 0; j < t.size() && is_equal; ++j) {
			is_equal &= s[(i + j) % s.size()] == t[j];
		}
		if (is_equal) {
			std::cout << "Yes" << std::endl;
			return 0;
		}
	}
	std::cout << "No" << std::endl;
}

Measured memory_bytes: 888
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    var string = ""
    val command = readLine()!!

    (0 until command.length).forEach {
        when (command[it].toString()) {
            "0" -> string += "0"
            "1" -> string += "1"
            /* .dropLast(n) : 後ろからn文字消去できる。再代入しなくてはならないことに注意。 */
            "B" -> string = string.dropLast(1)
        }
    }

    print(string)
}

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

#define int long long
int MOD = 1000000007;
int mypow10[19];
int dg;
int count(int D, int depth) {
	int x = (mypow10[dg - depth] - mypow10[depth]) / 9;
	if (dg <= depth * 2) {
		if (D == 0) {
			if (dg == depth * 2) {
				return 10;
			}
			else {
				return 1;
			}
		}
		return 0;
	}

	int res = 0;
	if (D >= 0) {
		int a = (D % (mypow10[depth + 1])) / mypow10[depth];
		if (depth == 0) {
			res += (9 - a) * count(D - a*x, depth + 1);
		}
		else {
			res += (10 - a) * count(D - a*x, depth + 1);
		}
		if (a != 0 && depth > 0) {
			res += a * count(D - (a - 10)*x, depth + 1);
		}
	}
	else {
		int a = ((-D) % (mypow10[depth + 1])) / mypow10[depth];
		if (depth == 0) {
			res += (9 - a) * count(D + a*x, depth + 1);
		}
		else {
			res += (10 - a) * count(D + a*x, depth + 1);
		}
		if (a != 0 && depth > 0) {
			res += a * count(D + (a - 10)*x, depth + 1);
		}
	}
	return res;
}
signed main() {
	int D;
	cin >> D;
	int res = 0;
	
	if (D % 9 == 0) {
		D /= 9;
		mypow10[0] = 1;
		for (int i = 1; i < 19; i++) {
			mypow10[i] = mypow10[i - 1] * 10;
		}
		
		for (int i = 1; i < 19; i++) {
			dg = i;
			res += count(D, 0);
		}
	}
	cout << res << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main()
{
    int n;
    cin >> n;
    //city,score,num
    vector<tuple<string, int, int>> a;
    for (int i = 0; i < n;i++){
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.push_back(tie(s, p, i));
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n;i++){
        cout << get<2>(a[i])+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
let id x = x

let mk_ls n =
  let rec aux i ls =
    if i = 0 then List.fast_sort (fun i j -> j - i) ls
    else aux (i - 1) ((Scanf.scanf "%d " id) :: ls)
  in
  aux n []

let solve ls =
  let rec aux i a b = function
    | [] -> a - b
    | h :: t ->
      let i' = i + 1 in
      if i mod 2 = 1 then aux i' (a + h) b t else aux i' a (b + h) t
  in
  aux 1 0 0 ls

let () =
  mk_ls (Scanf.scanf "%d\n" id) |> solve |> Printf.printf "%d\n"

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


bool visited1[100][100];
bool visited2[100][100];
int dx[100][100];
int dy[100][100];


bool f(int y,int x){
	if(visited1[y][x]){
		return visited2[y][x];
	}
	visited1[y][x]=true;
	visited2[y][x]=true;
	bool res=f(dy[y][x],dx[y][x]);
	visited2[y][x]=false;
	return res;
}

int main(){
	int n;
	while(cin>>n&&n){
		memset(visited1,false,sizeof(visited1));
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				cin>>dx[y][x]>>dy[y][x];
			}
		}
		int ans=0;
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				if(!visited1[y][x])ans+=f(y,x);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1264
class in{struct my_iterator{int it;const bool rev;explicit constexpr my_iterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(my_iterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const my_iterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const my_iterator& begin(){return i;}const my_iterator& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    const string code = "CODEFESTIVAL2016";
    string s; cin >> s;
    int ans = 0;
    for(int i : in(16)) {
        if(s[i] != code[i])
          ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10,mod=1e9+7;
inline void add(int &x,int y){
	x+=y;
	if(x>=mod) x-=mod;
}
char s[maxn];
int Next[maxn][3],sum[maxn],dp[maxn];
int main(){
	bool flag=1;
	scanf("%s",s+1);
	int n=strlen(s+1),ans=0;
	REP(i,2,n) flag&=(s[i]!=s[i-1]);
	if(flag){
		printf("1\n");
		return 0;
	}
	REP(i,1,n) sum[i]=(sum[i-1]+s[i]-'a'+1)%3;
	DREP(i,n,0){
		REP(j,0,2) Next[i][j]=Next[i+1][j];
		Next[i][sum[i]]=i;
	}
	dp[0]=1;
	REP(i,0,n){
		REP(j,1,2){
			int u=Next[i][(sum[i]+j)%3];
			if(u) add(dp[u],dp[i]);
		}
		if(i && sum[i]==sum[n]) add(ans,dp[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

s=input()
q=int(input())
from collections import deque
ar=[]
for i in s:
    ar.append(i)
ar=deque(ar)
r=0
for i in range(q):
    t=[i for i in input().strip().split(" ")]
    if t[0]=="1":
        r=1-r
    else:
        if r==0:
            if t[1]=="1":
                ar.appendleft(t[2])
            else:
                ar.append(t[2])
        else:
            if t[1]=="1":
                ar.append(t[2])
            else:
                ar.appendleft(t[2])
if r==0:
    print("".join(ar))
else:
    print("".join(ar)[::-1])


Measured memory_bytes: 103988
#include <stdio.h>
 
class Dice{
public:
    Dice(){
        number = new int[6];
        work = new int[6];
    };
    ~Dice(){
        delete[] number;
        delete[] work;
    };
 
    void setLabel(int index,int num){
        number[index] = num;
    };
 
    void roll(char dst){
        for(int i = 0; i < 6; i++) work[i] = number[i];
        switch(dst){
        case 'E':
            setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
            break;
        case 'N':
            setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
            break;
        case 'S':
            setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
            break;
        case 'W':
            setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
            break;
        }
    };
 
    int returnPeek(){
        return number[0];
    }
 
private:
    void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
 
private:
    int* number;
    int* work;
};
 
int main(){
    Dice dice;
    int label;
    char ch;
    for(int i = 0; i < 6; i++){
        scanf("%d",&label);
        dice.setLabel(i,label);
    }
    getchar(); 
    while((ch = getchar()) != '\n'){
        dice.roll(ch);
    }
    printf("%d\n",dice.returnPeek());
}

Measured memory_bytes: 2708
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

ll x, a, b;
ll ans;

int main(void) {
    
    scanf("%lld %lld %lld", &a, &b, &x);
    
    ll t = a > 0 ? (a-1)/x : -1;
    ans = b / x - t;
    
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner sc =new Scanner(System.in);
        long N = sc.nextInt();
        long M = sc.nextInt();
        if(Math.min(N,M)>=3){
            System.out.println((N-2)*(M-2));
        }else if(N==2 || M==2){
            System.out.println(0);
        }else if(N==1 && M!=1){
            System.out.println(M-2);
        }else if(N==1 && M==1){
            System.out.println(1);
        }else{
            System.out.println(N*M-2);
        }
    }
}


Measured memory_bytes: 23380
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

vector<vector<int>> G;
vector<LL> cnt;
map<int, LL> m;

void dfs(int n, int p, LL x) {
  cnt[n] = m[n] + x;
  for (int c : G[n]) {
    if (c == p) continue;
    dfs(c, n, cnt[n]);
  }
}

int main() {
  int N, Q; cin >> N >> Q;
  G.resize(N);
  for (int i = 0; i < N-1; ++i) {
    int a, b; cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 0; i < Q; ++i) {
    LL p, x; cin >> p >> x;
    --p;
    m[p] += x;
  }

  cnt.resize(N, 0LL);
  dfs(0, -1, 0LL);

  cout << cnt << endl;
}


Measured memory_bytes: 43008
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    P=LIN(N)
    print(sum(P)-max(P)//2)
if __name__ == '__main__':
    main()

Measured memory_bytes: 64108
a, b, c = map(int, input().split())

max_num = []

max_num.append(a*10+b+c)
max_num.append(b*10+a+c)
max_num.append(a*10+c+b)
max_num.append(c*10+a+b)
max_num.append(b*10+c+a)
max_num.append(c*10+b+a)

print(max(max_num))

Measured memory_bytes: 3060
n = int(input())
l = list(map(int, input().split()))

l = sorted(l)

count = 0
for i in range(2, n):
    for j in range(1, i):
        for k in range(j):
            if l[j] + l[k] > l[i] and l[i] != l[j] != l[k]:
                count += 1

print(count)


Measured memory_bytes: 9188