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

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using int128 = __int128;
using cint = cpp_int;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define input(a) scanf("%lld", &(a))
#define output(a) printf("%lld\n", (a))
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }

signed main() {
    ll N, K, S = 0;
    cin >> N >> K;
    inc(i, 1, N)
        S += N / i * max(i - K, 0LL) + max(N % i - K + bool(K), 0LL);
    cout << S << endl;
}

// for compilation: g++ -O3 -o _ _.cpp -std=c++17

Measured memory_bytes: 256
x,y = map(int,input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
if a.count(x)*a.count(y) == 1 or b.count(x)*b.count(y) == 1 \
or c.count(x)*c.count(y):
  print("Yes")
else:
  print("No")
 

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int n;
typedef long long ll;
const int maxn = 2e5+5;
ll a[maxn],b[maxn];
int get_num(){
	int num = 0;
	char c;
	bool flag = false;
	while((c = getchar()) == ' ' || c == '\r' || c == '\n');
	if(c == '-')
		flag = true;
	else num = c - '0';
	while(isdigit(c = getchar()))
		num = (num<<3) + (num<<1) + c - '0';
	return (flag ? -1 : 1) * num;
}
ll ret = 0;
ll mxa,mna,mxb,mnb;
ll dmx,dmi;
ll id[maxn];
bool cmp(int x,int y){
	return a[x] < a[y];
}
int main(){
	n = get_num();
	mna = mnb = 1e9;
	for(int i = 1;i <= n;++i){
		id[i] = i;
		a[i] = get_num();
		b[i] = get_num();
		if(a[i] > b[i])swap(a[i],b[i]);
		mxa = max(mxa,a[i]);
		mna = min(mna,a[i]);
		mxb = max(mxb,b[i]);
		mnb = min(mnb,b[i]);
	}
	ret = (mxb - mnb) * (mxa - mna);
	dmx = 0;
	dmi = 1e9;
	sort(id+1,id+n+1,cmp);
	for(int i = 1;i < n;++i){
		dmx = max(dmx,b[id[i]]);
		dmi = min(dmi,b[id[i]]);
		ret = min(ret,(ll)(max(dmx,a[id[n]])-min(dmi,a[id[i+1]])) * (mxb - mna));
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4992
import operator
import functools


def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = list(reversed(sorted(v)))
    # use slice to sum first A elements
    v_sum = sum(v[:A])
    # use '{:f}'.format to format float
    print('{:.6f}'.format((v_sum / A)))

    pool = sum(list(map(lambda x: 1 if x == v[A] else 0, v)))
    head = sum(list(map(lambda x: 1 if x > v[A] else 0, v[:A])))
    # 5 4 3 3 3 2 1, A = 3, B = 5, pool = 3, pick = 1
    # 5 4 3 3 3 2 1, A = 4, B = 5, pool = 3, pick = 2
    # 3 3 3 3 3 2 1, A = 3, B = 6, pool = 5, pick = 3, 4, 5
    # 3 3 3 3 3 2 1, A = 3, B = 4, pool = 5, pick = 3, 4
    ans = 0
    if head == 0:
        for pick in range(A, min(B, pool) + 1):
            ans += _nCr(pool, pick)
    else:
        pick = A - head
        ans = _nCr(pool, pick)
    print(ans)


def _nCr(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    # reduce and xrange are for python2
    numer = functools.reduce(operator.mul, range(n, n-r, -1))
    denom = functools.reduce(operator.mul, range(1, r+1))
    return numer//denom


if __name__ == '__main__':
    main()


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

int main(void)
{
    unsigned int inputN, total = 1;
    char *inputS;

    scanf("%u", &inputN);
    inputS = (char *)malloc(sizeof(char) * inputN);
    scanf("%s", inputS);
    for(int index = 0; index < inputN - 1; index++)
    {
        if (inputS[index] != inputS[index + 1])
        {
            total++;
        }
    }

    printf("%u", total);

    free(inputS);

    return 0;
}

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

int main() {
	int a[5];
	for (int i = 0; i< sizeof(a)/sizeof(*a); i++) {
		cin >> a[i];
	}
	int k;
	cin >> k;
	sort(a, a+5);
	int dis = a[4] - a[0];
	string ans = ":(";
	if (dis <= k) {
		ans = "Yay!";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long n,m,pair_num(0);
void using_s(){
	n--;
	m -= 2;
	pair_num++;
}
void using_c(){
	m -= 4;
	pair_num++;
}
int main(void){
	cin>>n>>m;
	while(n>=1 && m>=2)using_s();
	while(m>=4)using_c();
	cout<<pair_num<<endl;
	return 0;
}

Measured memory_bytes: 888
#D
S=int(input())
p=10**9+7

fac=[1]
for i in range(1,S+1):
    fac.append( (fac[-1]*i)%p)
    
def cal(n,r):
    A= fac[n]
    B= fac[r]
    C= fac[n-r]
    ans = A*pow(B,p-2,p)*pow(C,p-2,p)
    ans %= p
    return ans
    
ans=0

if S<3:
    pass
else:
    m= S//3
    for i in range(1,m+1):
        t = S-3*i
        #u = pow(t+1,i-1,p)
        u = cal(t+i-1,i-1)
        #print(i,t,u)
        ans = (ans+u)%p
print(ans)
            

Measured memory_bytes: 9204
#include <iostream>
#include <string>

using namespace std;

int main(){
 
  string s;
  int ans = 0;
  
  cin >> s;
  
  for(int i = 0; i < 3; i++){
    if(s[i] == '1'){
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
//This code was made by Chinese_zjc_
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,q,head[200001],p[200001],x,y;
struct WAY{
	int next,to;
}way[200001];
void dfs(int now)
{
	for(int i=head[now];i;i=way[i].next)
	{
		p[way[i].to]+=p[now];
		dfs(way[i].to);
	}
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>n>>q;
	for(int i=1;i<n;++i)
	{
		cin>>x>>way[i].to;
		way[i].next=head[x];
		head[x]=i;
	}
	while(q>0)
	{
		--q;
		cin>>x>>y;
		p[x]+=y;
	}
	dfs(1);
	for(int i=1;i<=n;++i)
	{
		printf("%lld ",p[i]);
	}
	return 0;
}


Measured memory_bytes: 14848
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,k,r,s,p;
    in>>n>>k>>r>>s>>p;
    string t;
    map<char,int> mp;
    mp['r']=0;
    mp['s']=1;
    mp['p']=2;
    int x[3][3]={{0,r,0},{0,0,s},{p,0,0}};
    in>>t;
    vector<vector<ll>> dp(n,vector<ll>(3));
    fr(i,n){
        fr(j,3){
            if(i<k) dp[i][j]=x[j][mp[t[i]]];
            else{
                fr(l,3)if(l!=j){
                    dp[i][j]=max(dp[i][j],dp[i-k][l]+x[j][mp[t[i]]]);
                }
            }
        }
    }
    ll ans{};
    fr(i,k) ans+=max({dp[n-1-i][0],dp[n-1-i][1],dp[n-1-i][2]});
    /*fr(i,n){
        fr(j,3) cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    cout<<ans<<endl;
}

Measured memory_bytes: 5840
#include<cstdio>
#include<algorithm>
using namespace std;
#define MOD 1000000007
#define MAXN 200005
#define LL long long
LL inv[MAXN],s[MAXN];
int N;
int H,W,A,B;
LL Pow(LL a,int b) 
{
    LL ans=1;
    while(b) 
	{
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return ans;
}
void Pre() 
{
    s[0]=1;
    for(int i=1; i<=N; i++)
        s[i]=s[i-1]*i%MOD;
    inv[0]=1;
    inv[N]=Pow(s[N],MOD-2);
    for(int i=N-1; i>0; i--)
        inv[i]=inv[i+1]*(i+1)%MOD;
}
LL C(int a,int b) 
{
    if(a<0||b<0) return 1;
    return s[a]*inv[b]%MOD*inv[a-b]%MOD;
}
int main() 
{
    scanf("%d %d %d %d",&H,&W,&A,&B);
	N=H+W-2;
	Pre();
	LL ans=C(H+W-2,H-1);
	for(int i=1;i<=B;i++)
	{
		ans-=C(H-A+i-2,H-A-1)*C(A-1+W-i,A-1)%MOD;
		ans=(ans%MOD+MOD)%MOD;
	}
    printf("%lld\n",ans);
}


Measured memory_bytes: 3328
#![allow(non_snake_case, dead_code)]

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

struct UnionFind {
    size: usize,
    pos: Vec<isize>,
}
impl UnionFind {
    fn new(n: usize) -> Self {
        let size = n;
        let pos = vec![-1; n + 1];
        UnionFind { size, pos }
    }
    fn find(&mut self, x: usize) -> usize {
        if self.pos[x] < 0 {
            x
        } else {
            let v = self.pos[x] as usize;
            self.pos[x] = self.find(v) as isize;
            self.pos[x] as usize
        }
    }
    fn unite(&mut self, x: usize, y: usize) -> Result<(), ()> {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x == y {
            return Err(());
        };
        if self.pos[x] > self.pos[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.pos[x] += self.pos[y];
        self.pos[y] = x as isize;
        Ok(())
    }
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
    fn size(&mut self, x: usize) -> usize {
        let x = self.find(x);
        -self.pos[x] as usize
    }
}


fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    loop {
        let W: usize = sc.read();
        let H: usize = sc.read();
        if W == 0 { break; };
        let mut g = Vec::new();
        for _ in 0..H {
            let v: String = sc.read();
            let v = v.chars().collect::<Vec<char>>();
            g.push(v);
        }
        let mut uf = UnionFind::new(H*W);
        let mut x: usize = 0;
        for i in 0..H {
            for j in 0..W {
                if g[i][j] == '@' {
                    x = i * W + j;
                }
                if g[i][j] == '#' { continue; };
                if j < W - 1 && g[i][j+1] != '#' {
                    uf.unite(i*W + j, i*W + j + 1).ok();
                }
                if i + 1 < H && g[i+1][j] != '#' {
                    uf.unite(i*W + j, i*W + j + W).ok();
                }
            }
        }
        println!("{}", uf.size(x));
    }
}



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

using namespace std;

#define long long long


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

    vector<int> color(n - 1);
    vector<vector<pair<int, int>>> g(n);
    vector<bool> visited(n, false);

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }

    queue<int> q;
    q.push(0);
    vector<int> skip(n, 0);

    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        visited[cur] = true;

        int cl = 1;
        for (pair<int, int> i : g[cur]) {
            if (!visited[i.first]) {
                q.push(i.first);
                if (cl == skip[cur]) cl++;
                color[i.second] = cl;
                skip[i.first] = cl;
                cl++;
            }
        }
    }

    int ans = 0;

    for (int i : color) ans = max(ans, i);

    cout << ans << "\n";

    for (int i : color) cout << i << "\n";

    return 0;
}


Measured memory_bytes: 7424
def check(ans, n, s)
	# 2番からn-1番の回答に合致させる
	1.upto(n-2) do |i|
		temp = (ans[i-1] == "S") ^ (ans[i] == "S") ^ (s[i] == "o") 
		ans[i+1] = temp ? "S" : "W"
	end
 
	temp = (ans[n-2] == "S") ^ (ans[n-1] == "S") ^ (s[n-1] == "o")
	ans_zero = temp ? "S" : "W"
 
	temp = (ans[n-1] == "S") ^ (ans[0] == "S") ^ (s[0] == "o")
	ans_one = temp ? "S" : "W"
 
	if ans_zero == ans[0] && ans_one == ans[1] then
		return true
	else
		return false
	end
end
 
 
n = gets.to_i
s = gets.chomp

["S", "W"].repeated_permutation(2) { |ans|
	if check(ans, n, s)
		puts ans.join
		exit
	end
}
puts -1


Measured memory_bytes: 10476
n=int(input())
a=sorted(list(map(int,input().split())))
num=[]
cnt=0
bef=a[0]
for i in range(n):
    if bef==a[i]:
        cnt+=1
    else:
        num.append(cnt-1)
        bef=a[i]
        cnt=1
    if i==n-1:
        num.append(cnt-1)
s=sum(num)
if s%2==0:
    print(n-s)
else:
    print(n-s-1)


Measured memory_bytes: 14396
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
	int n, t, x, y,i,l,T,X,Y,t0,x0,y0;
	l = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> t; cin >> x; cin >> y;
		while (i == 0) {
			T = t; X = x; Y = y;
			if (t - x - y < 0 || (t - x - y) % 2 == 1) {
				l = 1;
			}
			break;
		}
		t0 = max(t - T,T-t);
		x0 = max(x - X,X-x);
		y0 = max(y - Y, Y - y);
		if (t0 - x0 - y0 < 0 || (t0 - x0 - y0) % 2 == 1) {
			l = 1;
		}
		T = t; X = x; Y = y;
	}
	if (l == 1) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int N,T;
string sA,sB;
int n[50000];
vector<string> vstr[50000];
vector<int> vst[50000],vt[50000];
vector<string> ash;
map<P,P> d;
int main(){
	cin>>N>>T>>sA>>sB;
	rep(i,N){
		cin>>n[i];
		rep(j,n[i]){
			string st;
			cin>>st;
			ash.pb(st);
			vstr[i].pb(st);
		}
		rep(j,n[i]-1){
			int hoge;
			cin>>hoge;
			vt[i].pb(hoge);
		}
	}

	sort(all(ash));
	ash.erase(unique(all(ash)),ash.end());
	rep(i,N) rep(j,n[i]) vst[i].pb(lower_bound(all(ash),vstr[i][j])-ash.begin());
	int A=lower_bound(all(ash),sA)-ash.begin();
	int B=lower_bound(all(ash),sB)-ash.begin();

	vector<P> stats[100000];
	rep(i,N) rep(j,n[i]) stats[vst[i][j]].pb(P(i,j));

	priority_queue<PP,vector<PP>,greater<PP> > que;
	que.push(PP(P(-T,-1),P(-1,A)));
	d[P(-1,A)]=P(-T,-1);
	while(!que.empty()){
		PP pp=que.top();
		que.pop();
		P v=pp.sc;
		P dis=pp.fs;
		if(d[v]!=dis) continue;
		if(v.fs<0){	//name
			int x=v.sc;
			for(P nv:stats[x]){
				P ndis=dis;
				ndis.fs+=T,ndis.sc++;
				if(!d.count(nv) || ndis<d[nv]){
					d[nv]=ndis;
					que.push(PP(ndis,nv));
				}
			}
		}else{	//place
			int x=v.fs,y=v.sc;
			{
				int id=vst[x][y];
				P nv=P(-1,id);
				P ndis=dis;
				if(!d.count(nv) || ndis<d[nv]){
					d[nv]=ndis;
					que.push(PP(ndis,nv));
				}
			}
			if(y-1>=0){
				P nv=P(x,y-1);
				P ndis=dis;
				ndis.fs+=vt[x][y-1];
				if(!d.count(nv) || ndis<d[nv]){
					d[nv]=ndis;
					que.push(PP(ndis,nv));
				}
			}
			if(y+1<n[x]){
				P nv=P(x,y+1);
				P ndis=dis;
				ndis.fs+=vt[x][y];
				if(!d.count(nv) || ndis<d[nv]){
					d[nv]=ndis;
					que.push(PP(ndis,nv));
				}
			}
		}
	}
	P dest=P(-1,B);
	if(!d.count(dest)) puts("-1");
	else cout<<d[dest].fs<<" "<<d[dest].sc<<endl;
}

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

int main() {
	string s;
	cin >> s;
	if (s[2] != s[3]) {
		cout << "No" << endl;
		return 0;
	}
	if (s[4] != s[5]) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
  return 0;
}

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

const int N=2e5+5;
int n,a[N],b[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i) cin>>a[i];
	for(int i=0;i<n;++i) cin>>b[i];
	int res=0;
	for(int i=1;i<=29;++i){
		int mod=1<<i,k=1<<(i-1),cnt=0;
		vector<int> A,B;
		for(int j=0;j<n;++j) A.push_back(a[j]%mod);
		for(int j=0;j<n;++j) B.push_back(b[j]%mod);
		sort(A.begin(),A.end());
		sort(B.begin(),B.end());
		for(int j=0;j<n;++j)
			if(A[j]<k){
				cnt+=upper_bound(B.begin(),B.end(),(1<<i)-1-A[j])-lower_bound(B.begin(),B.end(),k-A[j]);
			}
			else{
				cnt+=upper_bound(B.begin(),B.end(),(1<<i)-1-A[j])-B.begin();
				cnt+=upper_bound(B.begin(),B.end(),(1<<i)+k*2-1-A[j])-lower_bound(B.begin(),B.end(),(1<<i)+k-A[j]);
			}
		//cerr<<i<<' '<<cnt<<'\n';
		if(cnt&1) res|=1<<(i-1);
	}
	cout<<res<<'\n';
}




Measured memory_bytes: 7400
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>

using namespace std;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
	uint32_t N,A,B;
	cin >> N >> A >> B;

    if(N*A > B){
        cout << B << endl;
    }else{
        cout << N*A << endl;
    }

	return 0;
}



Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException
    {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        int[] m = makeIntArray(br);
        int N = m[0];
        int[] data = makeIntArray(br);
        rev(data);
        show(data);

    }
    public static void show(int[] a){
        int n = a.length;
        for(int i = 0; i < n - 1; i++){ System.out.print(a[i] + " "); }
        System.out.println(a[n - 1]);
    }
    public static int[] makeIntArray(BufferedReader br) throws IOException
    {
        String[] str = br.readLine().split(" ");
        int n = str.length;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); }
        return a;
    }
    public static void rev(int[] a){
        int n = a.length;
        int x;
        for(int i = 0; i < (n / 2); i++){
            x = a[i];
            a[i] = a[n - 1 - i];
            a[n - 1 - i] = x;
        }
    }
}


Measured memory_bytes: 24376
n = int(input())
result = 1000
for i in range(1,n//2 + 1):
    b = n - i
    a2 = str(i)
    b2 = str(b)
    a_sum = 0
    b_sum = 0
    for x in range(len(a2)):
        a_sum += int(a2[x])
    for y in range(len(b2)):
        b_sum += int(b2[y])
    result = min(result,a_sum + b_sum)
print(result)

Measured memory_bytes: 41580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF 1LL<<60

using namespace std;

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

const int MAX_N = (int)1e5 + 5;
ll x[MAX_N];

int main()
{
	memset(x, 0LL, sizeof(x));
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int N, K; cin >> N >> K;
	rep (i, N){
		cin >> x[i];
	} // end rep

	ll res = INF;
	rep (i, N - K + 1){
		ll xl = x[i];
		ll xr = x[i + K - 1];
		res = min(res, abs(xl) + abs(xr - xl));
		res = min(res, abs(xr) + abs(xr - xl));
	} // end rep

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1024
"""
標準入力
"""
def simpleInput(): return input()
def intInput(): return int(input())
def floatInput(): return float(input())
def splitInput(): return input().split()
def multiCIntInput(): return map(int, input().split())
def multiCIntInputList(): return list(map(int, input.split()))
def multiRIntInputList(num): return [int(input()) for i in range(num)]
#-----------------------------------

S = simpleInput()
T = simpleInput()
if len(S)+1 == len(T) and S == T[:-1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8992
#include <iostream>
#include <string>
using namespace std;
 
class Dice{
private:
    int d[6];
public:
    Dice(int n0, int n1, int n2, int n3, int n4, int n5){ //Constructor
        d[0]=n0; d[1]=n1; d[2]=n2; d[3]=n3; d[4]=n4; d[5]=n5;
    }
    int get_top(){
        return d[0];
    }
    int get_front(){
        return d[1];
    }
    int get_right(){
        return d[2];
    }
    int get_left(){
        return d[3];
    }
    int get_back(){
        return d[4];
    }
    int get_bottom(){
        return d[5];
    }
    void Roll(string op){
        for(unsigned int i=0;i<op.length();i++){
            switch(op[i]){
                case 'N': RollN(); break;
                case 'E': RollE(); break;
                case 'W': RollW(); break;
                case 'S': RollS(); break;
            }
        }
    }
    void RollN(){
        int tmp=d[0];
        d[0]=d[1];
        d[1]=d[5];
        d[5]=d[4];
        d[4]=tmp;
    }
    void RollE(){
        int tmp=d[0];
        d[0]=d[3];
        d[3]=d[5];
        d[5]=d[2];
        d[2]=tmp;
    }
    void RollW(){
        int tmp=d[0];
        d[0]=d[2];
        d[2]=d[5];
        d[5]=d[3];
        d[3]=tmp;
    }
    void RollS(){
        int tmp=d[0];
        d[0]=d[4];
        d[4]=d[5];
        d[5]=d[1];
        d[1]=tmp;
    }
};
 
int main(){
    int a, b, c, d, e, f, q;
    cin >> a >> b >> c >> d >> e >> f >> q;
    Dice di(a, b, c, d, e, f);
    int top, front;
    for(int i=0;i<q;i++){
    	cin >> top >> front;
    	for(int j=0;j<4;j++){
    		bool flg = false;
    		di.RollE();
    		for(int k=0;k<4;k++){
    			di.RollN();
    			for(int l=0;l<4;l++){
    				di.RollE();
    				if(di.get_top()==top && di.get_front()==front){
    					flg=true; break;
    				}
    			}
    			if(flg) break;
    		}
    		if(flg) break;
    	}
        cout << di.get_right() << endl;
    }

    return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>
 
int main(){
int n,m;
scanf("%d %d",&n,&m);
int a[m],sum=0;
for(int i=0;i<m;i++){
scanf("%d",&a[i]);
sum=sum+a[i];
}
if(n-sum>=0)
printf("%d",n-sum);
else
puts("-1");
return 0;
}    

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

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

int main()
{
	int n;
	cin >> n;
	
	int a, b, c, d;
	a = n / 1000;
	b = (n - a*1000) / 100;
	c = (n - a*1000 - b*100) / 10;
	d = n % 10;
	
	//cout << "a" << a << " b" << b << " c" << c << " d" << d << endl;

	if ((a == b&&b == c) || (b == c&&c == d))cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        int n = in.Int();
        int m = in.Int();

        int total = ((n - 1) * n) / 2  + ((m - 1) * m) / 2;
        out.println(total);

        out.close();
    }


    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long Long() throws IOException {
            return Long.parseLong(next());
        }

        int Int() throws IOException {
            return Integer.parseInt(next());
        }

        double Double() throws IOException {
            return Double.parseDouble(next());
        }

        char Char() throws IOException {
            return next().charAt(0);
        }

        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 23124
// B - Battle
#include <bits/stdc++.h>
using namespace std;
int A,B,C,D;

bool solve(){
	int m[2][2]={{A,B},{C,D}};
	int at = 0;
	while(true){
		int df = (at+1)%2;
		m[df][0] -= m[at][1];
		if(m[df][0] <= 0){
			if(df%2) return true;
			return false;
		}
		at = df;
	}
	return false;
}

int main(){
	cin>>A>>B>>C>>D;
	cout<< (solve()? "Yes":"No") <<endl;
}


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

int main() {
	//素数列取得
	vector<int>p = { 2,3 };
	for (int i = 3; i <= 100000; i++) {
		bool a = true;
		for (int j = 0; j < p.size(); j++) {
			if (i % p.at(j) == 0) {
				a = false;
				break;
			}
		}
		if (a)p.push_back(i);
	}
	set<int>ps;
	for (int i = 0; i < p.size(); i++)ps.insert(p.at(i));
	vector<int>ans;
	for (int i = 1; i < p.size(); i++) {
		if (ps.count((p.at(i) + 1) / 2))ans.push_back(p.at(i));
	}
	sort(ans.begin(), ans.end());
	//for (int i = 0; i < ans.size(); i++)cout << ans.at(i) << " ";
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		int s = lower_bound(ans.begin(), ans.end(), l) - ans.begin();
		int t = upper_bound(ans.begin(), ans.end(), r) - ans.begin();
		cout << t-s << endl;
	}

}

Measured memory_bytes: 1152
$line = <STDIN>;
chomp $line;
$N=scalar($line);
$line = <STDIN>;
chomp $line;
$S=$line;

$wc=0;
for($i=0;$i<$N;$i++){
	$wc+=1 if(substr($S,$i,1) eq "W");
	$wc[$i]=$wc;
}

$ec = $N-$wc[$N-1];
$mc = $ec-(1-$wc[0]);

for($i=1;$i<$N;$i++){
	$c = $ec-1-$i+$wc[$i-1]+$wc[$i];
	$mc=$c if ($mc>$c);
}

print "$mc\n";


Measured memory_bytes: 10572
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		Map<String, Integer> map = new HashMap<String, Integer>();
		try {
			sc = new Scanner(System.in);
			String maxFrequencyWord = "";
			String maxLengthWord = "";

			String[] sentence = sc.nextLine().split(" ");

			if (!sentence[0].isEmpty()) {
				for (String s : sentence) {
					map.put(s, map.containsKey(s) ? map.get(s) + 1 : 1);
				}

				int maxFrequency = Collections.max(map.values());
				int maxLength = 0;

				for (Map.Entry<String, Integer> entry : map.entrySet()) {
					if (maxFrequency == entry.getValue()) {
						maxFrequencyWord = entry.getKey();
					}
					if (maxLength < entry.getKey().length()) {
						maxLength = entry.getKey().length();
						maxLengthWord = entry.getKey();
					}
				}
			}
			System.out.println(maxFrequencyWord + " " + maxLengthWord);

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26036
//
// Created by Huang,Zhiqiang on 2018/7/17.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef  long long ll;
int n;
string s;
map<pair<string,string>, ll> m;

int main() {
    cin >> n;
    cin >> s;
    for (int i = 0; i < (1 << n); i++) {
        string s1,s2;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) s1 += s[j];
            else s2 += s[j];
        }
        m[make_pair(s1, s2)]++;
    }
    ll ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        string s1,s2;
        for (int j = n - 1; j >= 0; j--) {
            if (i & (1 << j)) s1 += s[n + j];
            else s2 += s[n + j];
        }
        ans += m[make_pair(s2, s1)];
    }
    cout << ans << endl;
}

Measured memory_bytes: 91904
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

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

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	string S;
	cin >> S;
	
	vi cand;
	for (int i = 0; i < S.length() - 1; i++)
		if (S[i] != S[i + 1])
			cand.push_back(i + 1);

	int ans = S.length();
	for (int i = 0; i < cand.size(); i++)
		ans = min(ans, max(cand[i], (int)S.length() - cand[i]));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 768
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define pb(n) push_back(n)
#define endl '\n'
#define debug(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define OUT2(n1,n2) cout << n1 << " " << n2 << endl
#define OUT3(n1,n2,n3) cout << n1 << " " << n2 << " " << n3 << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
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); }
ll n, m, k, ans, sum, cnt = 0; string s; char c; bool flg;

bool possible(string s, int size, int start, string target) {
  return (start + target.size() <= size && s.substr(start, target.size()) == target);
}
int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  IN(s);
  int size = s.size();
  int i = 0;
  while (i<size) {
    if (possible(s, size, i, "dreameraser")) {
      i += 11;
    } else if (possible(s, size, i, "dreamerase")) {
      i += 10;
    } else if (possible(s, size, i, "dreamer")) {
      i += 7;
    } else if (possible(s, size, i, "dream")) {
      i += 5;
    } else if (possible(s, size, i, "eraser")) {
      i += 6;
    } else if (possible(s, size, i, "erase")) {
      i += 5;
    } else {
      OUT("NO");
      return 0;
    }
    // debug(i);
  }

  OUT("YES");
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >> N;
  
  	int ans = 0;
  	int log = 0;
  	for(int i=0;i<N-1;i++){
      int B;
      cin >> B;
      if(i==0){
      	ans += B;
      }else{
      	ans += min(log,B);
      }
      log = B;
    }
  	ans += log;
    cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	S=S%3600;
	m=S/60;
	S=S%60;
	s=S;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 2692
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    ll arr[] = {A, B, C, D, E};
    sort(all(arr));
    cout << (ll)ceil((double)N / arr[0]) + 4 << endl;
}


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

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

using namespace std;

typedef pair<string,string> s2;

int main() {
  map<s2,int> counter;
  int n,f;
  cin >> n >> f;
  rep(i,n) {
    int m;
    cin >> m;
    vector<string> vec(m);
    rep(j,m) cin >> vec[j];
    sort(vec.begin(),vec.end());
    rep(j,m) REP(k,j+1,m) ++counter[s2(vec[j],vec[k])];
  }
  vector<s2> ans;
  for(auto v : counter) {
    if( v.second >= f ) {
      ans.push_back(v.first);
    }
  }
  cout << ans.size() << endl;
  rep(i,(int)ans.size()) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#include<iostream>
        #include <algorithm>
        using namespace std;
        int main(){
                   int n,k;
                   cin>>n>>k;
                   int a[n],s=0;
                   for(int i=0;i<n;i++){
                   cin>>a[i];
                    s+=a[i];
                     }
                   int v=s/(4*k),yy=4*k;
                   sort(a,a+n);
                   for(int i=n-1;i>=0;i--){
                     if(s%(yy)==0&&a[i]>=v)k--;
                     else if(a[i]>v)k--;
                       }
                    if(k>0)cout<<"No";
                    else cout<<"Yes";
        return 0;
                        }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    int N, K;
    int x = 0;
    
    cin >> N >> K;
    
    for (int i = 0; i < N; i++)
    {
        int h;
        cin >> h;
        if (K <= h) {
            x++;
        }
    }
    cout << x;
}


Measured memory_bytes: 3632
import java.util.*;
import java.io.*;

public class Main {
	static int[] memo = new int[100000];
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int[] v = new int[n];
		int[] c = new int[n];
		for(int i = 0; i < n; i++)
			v[i] = sc.nextInt();
		for(int i = 0; i < n; i++)
			c[i] = sc.nextInt();	
		
		int sum = 0;
		for(int i = 0; i < n; i++) {
			if (v[i] > c[i]) sum += v[i] - c[i];
		}
		out.println(sum);
		
		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



Measured memory_bytes: 21204
#include <cstdio>
#include <cstring>
#include <iostream>

int main()
{
    char buf[11];
    while (scanf("%s", buf) == 1) {
        long long result = 0;
        int n = strlen(buf);
        for (int i = 0; i < n; ++ i) {
            long long s = 0;
            for (int j = i; j < n; ++ j) {
                s = s * 10 + buf[j] - '0';
                result += s * (1LL << std::max(i - 1, 0) + std::max(n - j - 2, 0));
            }
        }
        printf("%lld\n", result);
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int d[2]={2,8},ans=-1;
vector<ll> s;

void func(int x,ll k){
  if(x!=0) s.push_back(k);
  if(x==18) return ;
  for(int i=0;i<2;i++) func(x+1,k*10+d[i]);
}

void func2(int x,ll k,int sum){
  if(k==1&&sum) ans=max(ans,sum);
  if(s[x]>k) return ;
  if(k%s[x]==0) func2(x,k/s[x],sum+1);
  if(x+1!=s.size()) func2(x+1,k,sum);
}

int main(){
  ll n;
  cin>>n;
  func(0,0);
  sort(s.begin(),s.end());
  func2(0,n,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7256
#include <stdio.h>

int main()
{
    int n, m, nresult = 1, mresult = 1, nkaijo, mkaijo, i;

    scanf( "%d %d", &n, &m ); //n:偶数m:奇数

    //偶数＋偶数、奇数＋奇数が偶数になる
    if( n == 1 )
    {
        nresult = 0;
        for(i = 1; i <= 2; i++) 
        {
            mresult = mresult * (m - i + 1) / i;
        }
    }
        
    else if( m == 1 )
    {
        mresult = 0; 
        for(i = 1; i <= 2; i++) 
        {
            nresult = nresult * (n - i + 1) / i;
        }
        
    }
    else
    {
        for(i = 1; i <= 2; i++) 
        {
            nresult = nresult * (n - i + 1) / i;
        }
        for(i = 1; i <= 2; i++) 
        {
            mresult = mresult * (m - i + 1) / i;
        }
    }

    printf( "%d\n", nresult + mresult );
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    int n;
    while(cin>>n&&n){
        char c[111];
        for(int i=0;i<100;i++)cin>>c[i];
        int fld=0,hand[n]={};
        for(int i=0;i<100;i++){
            if(c[i]=='M')hand[i%n]++;
            if(c[i]=='S'){
                fld+=hand[i%n]+1;
                hand[i%n]=0;
            }
            if(c[i]=='L'){
                hand[i%n]+=fld+1;
                fld=0;
            }
        }
        sort(hand,hand+n);
        for(int i=0;i<n;i++){
            cout<<hand[i]<<' ';
        }
        cout<<fld<<endl;
    }
}


Measured memory_bytes: 3180
import sys
import collections

S = int(next(sys.stdin))
_A = (s.strip() for s in sys.stdin)
A = collections.Counter(_A)

# print(A)
# print(max(A.values()))

m = max(A.values())
keys = [k for k, v in A.items() if v == m]
keys.sort()
for s in keys:
  print(s)

Measured memory_bytes: 35544
#include <cstdio>
#include <vector>
#define MOD 1000000007
typedef long long ll;
struct Matrix
{
	std::vector<std::vector<int> > arr;
	Matrix()
	{
		arr.resize(3, std::vector<int>(3, 0));
	}
	inline std::vector<int> &operator [](const int &x)
	{
		return arr[x];
	}
	inline const std::vector<int> &operator [](const int &x) const
	{
		return arr[x];
	}
	inline Matrix operator *(const Matrix &a) const
	{
		Matrix res;
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				for (int k = 0; k < 3; k++)
					res[i][k] = (res[i][k] + (ll)arr[i][j] * a[j][k]) % MOD;
			}
		}
		return res;
	}
} ans, trans, sing;
int arr[100005];
int main()
{
	// freopen("AGC013-E.in", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
		scanf("%d", arr + i);
	arr[++m] = n;
	ans[0][0] = 1;
	trans.arr = {{1, 2, 1}, {0, 1, 1}, {1, 2, 2}};
	sing.arr = {{1, 2, 1}, {0, 1, 1}, {0, 0, 1}};
	int cur = 0;
	for (int i = 0; i <= m; i++)
	{
		int x = arr[i] - cur;
		auto tmp = trans;
		while (x)
		{
			if (x & 1)
				ans = ans * tmp;
			tmp = tmp * tmp;
			x >>= 1;
		}
		if (i == m)
			break;
		ans = ans * sing;
		cur = arr[i] + 1;
	}
	printf("%d\n", ans[0][2]);
	return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en 


constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    int n;
    cin >> n;
    VI pv(n);
    REP(i, n) cin >> pv[i];
    VI qv(n);
    REP(i, n) cin >> qv[i];
    int a, b;
    VI v(n);
    REP(i, n) v[i] = i + 1;
    int count = 0;
    do {
        count++;
        int f = 0;
        REP(i, n) if (v[i] != pv[i]) f = 1;
        if (f == 0) a = count;
    } while (next_permutation(ALL(v)));
    REP(i, n) v[i] = i + 1;
    count = 0;
    do {
        count++;
        int f = 0;
        REP(i, n) if (v[i] != qv[i]) f = 1;
        if (f == 0) b = count;
    } while (next_permutation(ALL(v)));
    cout << abs(a-b) << endl;

}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3648
n,p = [int(i) for i in input().split()]
s = input()
ans = 0
import collections

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
    exit()

else:
  chk = []
  m = 0
  chk = collections.deque(chk)
  for i in range(n)[::-1]:
    m = (int(s[i])*pow(10,n-1-i,p)+m)%p
    chk.append(m)
  chk.append(0)
  chk = list(chk)
  c = collections.Counter(chk)
  for i in range(p):
    ans += c[i]*(c[i]-1)/2
  print(int(ans))

Measured memory_bytes: 49228
import Data.List

main = interact $ sol . last . lines

sol s = s0 ++ s ++ s1 where
  (b,m) = foldl' f (0,0) s
  s0 = replicate (-m) '('
  s1 = replicate (max 0 (b-m)) ')'

f (b,m) '(' = (b+1,m)
f (b,m) ')' = (b-1,min m (b-1))

Measured memory_bytes: 508
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int M = 1e9+7;
const int INF = 1<<30;

int _;
int a[105];

ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b) {ll s=1;while(b){if(b&1)s=(s*a)%M;b>>=1;a=(a*a)%M;}return s;}



int main()
{
    ll n,k;
    cin>>n>>k;
    ll t = n%k;
    ll u = k-t;
    cout<<min(t,u)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void clear( std::queue<int> &q ) {
   std::queue<int> empty;
   std::swap( q, empty );
}

void solve() {
	int n, m;
	cin >> n >> m;
	
	vvi adj(n);
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		
		adj[a].pub(b);
	}
	
	vi ans;
	for(int start = 0; start < n; start++) {
		queue<int> q;
		vi prev(n, -1);
		q.push(start);
		
		while(!q.empty()) {
			int node = q.front(); q.pop();
			
			for(int i : adj[node]) {
				if(i == start) {
					vi res;
					
					int x = node;
					res.pub(x);
					while(prev[x] != -1) {
						x = prev[x];
						res.pub(x);
					}
					
					if(ans.size() == 0 || res.size() < ans.size()) ans = res;
					
					clear(q);
					break;			
				}
				
				if(prev[i] != -1) continue;
				
				prev[i] = node;
				q.push(i);
			}
		}
	}
	
	cout << ((int) ans.size() ? (int)ans.size() : -1) << endl;
	for(int i : ans) cout << i + 1 << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 3724