akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

string toUpperString(string s){
	for (int i = 0; i < s.length(); i++){
		if ('a' <= s[i] && s[i] <= 'z'){
			s[i] = s[i] + 'A' - 'a';
		}
	}
	return s;
}


int main()
{
	string w, t;
	cin >> w;
	int counter = 0;
	while (cin >> t, t != "END_OF_TEXT"){
		if (toUpperString(w) == toUpperString(t)){
			counter++;
		}
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 1196
h,n = map(int, input().split())

inf = float('INF')
dp = [inf for i in range(h+1)]
dp[0] = 0
for i in range(n):
    a,b = map(int, input().split())
    for j in range(h+1):
        # print(j+a)
        if j + a <= h and dp[j+a] > dp[j] + b:
            dp[j+a] = dp[j] + b
        elif j + a > h and dp[h] > dp[j] + b:
            dp[h] = dp[j] + b

print(dp[h])
# print(dp)

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

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  string test = "CODEFESTIVAL2016";
  rep(i, s.size()) {
    if (s.at(i) != test.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
	string s;
	cin>>s;
	
	set<char> c;
	REP(i,s.size()) auto itr=c.insert(s[i]);
	
	string alphabet="abcdefghijklmnopqrstuvwxyz";
	REP(i,26){
		if(c.count(alphabet[i])==0){
			cout<<alphabet[i]<<endl;
			return 0;
		}
	}
	
	cout<<"None"<<endl;
	return 0;
}

Measured memory_bytes: 512
import math
import numpy as np

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n,m,x = NextInts()
data = np.array([NextIntList() for i in range(n)], np.int64)

c = data[:,:1].reshape(n)
a = data[:,1:]
ans = 10**10

for i in range(1<<n): 
    now = 1
    point = np.zeros(m, np.int64)
    tmp = 0
    for j in range(n):
        if now&i:
            for k in range(m):
                point[k] += a[j][k]
            tmp += c[j]
        now <<= 1
    ju = True
    for i in range(m):
        if point[i] < x:
            ju = False
            break
    if ju:
        ans = min(ans, tmp)
if ans == 10**10: print(-1)
else: print(ans)

Measured memory_bytes: 27192
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	const int MOD=1e9+7;
	
	for(int n,w;cin>>n>>w && n|w;){
		vi ws(n);
		rep(i,n) cin>>ws[i];
		sort(all(ws));
		
		vi sum(n+1);
		rep(i,n) sum[i+1]=sum[i]+ws[i];
		
		if(sum[n]<=w){
			cout<<1<<endl;
			continue;
		}
		
		int res=0;
		vi dp(w+1); dp[0]=1;
		per(i,n){
			peri(j,ws[i],w+1)
				(dp[j]+=dp[j-ws[i]])%=MOD;
			int l=w-sum[i]-ws[i],r=w-sum[i]-(i?ws[i-1]:0);
			repi(j,max(l+1,0),r+1)
				(res+=dp[j])%=MOD;
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1244
//In the name of God:)
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long int
#define fast  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int MAXN = 2e5 + 10;
ll a[MAXN] , num[MAXN];
int main(){
    ll n;
    ll ans = 0;
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i];
        num[a[i]]++;
    }
    for(int i = 1 ; i <= n ; i++){
        ans += num[i] * (num[i]-1) / 2;
    }
    for(int i = 0 ; i < n ; i++){
        cout << ans - num[a[i]] + 1 << endl;
    }

}


Measured memory_bytes: 4736
n=readline.strip.to_i
pp = readline.strip.split.map(&:to_i)

#p n
#p pp

ppp=pp.dup
result=0
r_result = 0
n.times do |i|
  reverse_i = n-1-i
  if ppp[reverse_i] == reverse_i+1
    r_result+=1
    ppp[reverse_i-1] = ppp[reverse_i] if reverse_i>0
  end

  if pp[i] == i+1
    result += 1
    pp[i+1] = pp[i] if i<n
  end
end

p [result, r_result].min


Measured memory_bytes: 9476
n = int(input())
h = list(map(int, input().split()))

mx = 0
cnt = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        cnt += 1
    else:
        mx = max(mx, cnt)
        cnt = 0

mx = max(mx, cnt)
print(mx)


Measured memory_bytes: 15020
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int val(int a, int b, int c){
    int ok = 0;
    if (a == b || b == c || a == c)
      return -1;
    if (abs(b-c) < a && a < b+c)
        ok += 1;
    if (abs(b-a) < c && c < b+a)
        ok += 1;
    if (abs(c-a) < b  && b< c+a)
        ok += 1;
        
    return ok;
}


int main(){
  int n;
  scanf("%d", &n);
  
  int cont = 0;
  
  int vec[n];
  for (int i = 0; i < n; ++i){
    scanf("%d", &vec[i]);
  }
  
  for (int i = 0; i < n; ++ i){
    for (int j = i+1; j < n; ++ j){
      for (int k = j+1; k < n; ++ k){
        if (val(vec[i], vec[j], vec[k]) == 3)
          cont += 1;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
#define re register
int f[5010],inv[5010];
const int mod=1e9+7;
int main()
{
	re int n,m,c=1;
	scanf("%d%d",&n,&m);
	inv[1]=1;
	for(re int i=2;i<=m;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(re int i=1;i<=m;i++)
	{
		f[i]=c;
		c=1ll*c*(m-i)%mod*inv[i]%mod;
	}
	for(re int i=1;i<=n;i++)
	{
		re int num=0;
		for(re int j=m;j>=1;j--)
		{
			re int xx=f[j];
			f[j]=(1ll*(j+1)*f[j]+2ll*j*num)%mod;
			num=(num+xx)%mod;
		}
	}
	printf("%d\n",f[1]);
}

Measured memory_bytes: 3868
#include <stdio.h>

int main()
{
	int flag = 1;
	long long int a,b,n;
	long long int num = 0;
	long long int ball = 0;
	
	scanf("%lld %lld %lld",&n,&a,&b);
	
	ball = n / (a + b);
	
	num = ball * a;
	
	n %= (a + b);
	
	if(n > a)
	num += a;
	else num += n;
	
	printf("%lld\n",num);
	
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N-1];

		for (int i=0; i<N; i++){
			A[i] = sc.nextInt();
		}
		for (int i=0; i<N; i++){
			B[i] = sc.nextInt();
		}
		for (int i=0; i<N-1; i++){
			C[i] = sc.nextInt();
		}
		int ans=0;
		for (int i=0; i<N; i++){
			ans += B[A[i]-1];
			if (i>0 && A[i-1]+1 == A[i]){
				ans += C[A[i]-2];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  int N, X;
  cin >> N >> X;

  int min_powder = INT_MAX;
  int sum = 0;
  int ans = N;
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    sum += p;
    min_powder = min(min_powder, p);
  }

  cout << ans + (X - sum) / min_powder << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int i,j,m,n,s,t,ans,v,k[11],p[11],b[11][11];
int f()
{
    int w=0;
    for(j=0;j<k[i];j++)w+=((1<<b[i][j]-1)&s)>0;
    return w%2==p[i];
}
int main()
{
    cin>>n>>m;
    for(;i<m;i++)
        for(cin>>k[i],j=0;j<k[i];j++)
            cin>>b[i][j];
    for(i=0;i<m;i++)cin>>p[i];
    for(t=1<<n;s<t;s++)
    {
        for(i=v=0;i<m;i++)v+=f();
        ans+=(v==m);
    }
    cout<<ans<<endl;
}

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

#define MAXV 100000
#define MAXE 100000
int V, E;
vector<int> G[MAXV];
set<int> ans;
bool visited[MAXV];
int prenum[MAXV];
int parent[MAXV];
int lowest[MAXV];
int nx;

void init() {
	for (int i = 0; i < V; i++) {
		visited[i] = false;
	}
	nx = 1;
}

void input() {
	for (int i = 0; i < E; i++) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
}

void dfs(int u, int p) {
	visited[u] = true;
	lowest[u] = prenum[u] = nx;
	nx++;
	for (int j = 0; j < G[u].size(); j++) {
		if (!visited[G[u][j]]) {
			parent[G[u][j]] = u;
			dfs(G[u][j], u);
			lowest[u] = min(lowest[u], lowest[G[u][j]]);
		} else if (G[u][j] != p) {
			lowest[u] = min(lowest[u], prenum[G[u][j]]);
		}
	}
}

void artpoints() {
	int np = 0;
	for (int u = 1; u < V; u++) {
		if (parent[u] == 0)
			np++;
		else if (prenum[parent[u]] <= lowest[u])
			ans.insert(parent[u]);
	}
	if (np > 1)
		ans.insert(0);
	for (set<int>::iterator it = ans.begin(); it != ans.end(); it++) {
		cout << (*it) << endl;
	}
}

int main() {
	cin >> V >> E;
	init();
	input();
	dfs(0, -1);
	artpoints();
	return 0;
}



Measured memory_bytes: 6756
using System;
using System.Linq;

namespace AOJ.Codes
{
    //問題の名称... ALDS1_11_A : Graph
    //問題文のURL... http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A&lang=jp
    //所要時間... AAA
    //学んだこと... AAA
    //教室内の大まかな着席位置... 中央 x 奥

    //未完，提出しない！

    class A_Graph
    {
        static void Main(string[] args)
        {

            //読み込み

            var n = int.Parse(Console.ReadLine());
            var M = new int[n, n];

            //読み込み＆計算
            //端が（１，１）なのに注意
            for (int i = 0; i < n; i++)
            {
                var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 2; j < line[1] + 2; j++)
                {
                    var num = line[j];
                    M[i, num - 1] = 1;
                }
            }

            //出力
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write(M[i, j]);
                    if (j != n - 1)
                        Console.Write(" ");
                }

                Console.WriteLine();
            }

            Console.ReadLine();
        }
    }
}



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

int main(){
  int n;
  cin >>n;
  int p[n];
  int sum = 0;
  rep(i,n) {
    cin >>p[i];
    sum += p[i];
  }
  sort(p,p+n,greater<int>());
  sum -= p[0]/2;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
def floor_sum(n, m, a, b):
    res = 0
    while True:
        if a >= m:
            res += (n - 1) * n * (a // m) // 2
            a %= m
        if b >= m:
            res += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        if y_max == 0: break
        x_max = b - y_max * m
        res += (n + x_max // a) * y_max
        n, m, a, b = y_max, a, m, x_max % a
    return res

import sys
input = sys.stdin.buffer.readline

T = int(input())
res = [None] * T

for i in range(T):
    n, m, a, b = map(int, input().split())
    res[i] = str(floor_sum(n, m, a, b))

print('\n'.join(res))

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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define endl "\n"

const int mod = 1e9 + 7;

int32_t main()
{
	IOS;
	int n, k;
	int sum = 0;
	cin >> n >> k;
	for (int i = k; i <= n + 1; i++)
	{
		int mn = i * (i - 1) / 2;
		int mx = n * (n + 1) / 2 - (n - i + 1) * (n - i) / 2;
		sum += mx - mn + 1;
		sum %= mod;
	}
	cout << sum % mod << endl;

	return 0;
}

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

int main(){
    string S;
    cin >> S;
    int cnt = 1, f = 1;
    int n = S.size();
    for(int i = 1; i < n; i++){
        if(f && S[i - 1] == S[i]){
            f = 0;
            if(i == n - 1)
                break;
            cnt++;
            i++;
        }
        else{
            f = 1;
            cnt++;
        }
    }
    cout << cnt<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    long long n, m = 10, ans = 0;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    while (n / m > 0) {
        ans += (n / m);
        m *= 5;
    }
    cout << ans << endl;

    return 0;
}

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

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
    let a = it.next().unwrap();
    let b = it.next().unwrap();
    
    println!("{} {}",a*b,2*(a+b));

    
}


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

int main()
{
  double N;
  cin >> N;
  const double PI = acos(-1);
  cout << 2 * PI * N << endl;
}

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

int main() {
  int N, A;
  cin >> N;
  
  int min = 0;
  for (int i = 0; i < N; i++) {
    cin >> A;
    if (A % 2) break;
    
    int cnt = 0;
    while (!(A % 2)) {
      A /= 2;
      cnt++;
    }
    
    if (i == 0) {
      min = cnt;
    } else if (cnt < min) {
      min = cnt;
    }
  }
  
  cout << min << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(A>B) A=B;
    if(C>D) C=D;
    cout << A+C;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) cin >> x;
	int r = 0;
	for (int i = 0; i < N; i += 2) {
		if (A[i] % 2) ++ r;
	}
	cout << r << endl;
}


Measured memory_bytes: 3620
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    char c; cin >> c;
    
    if(islower(c)) cout << "a";
    else cout << "A";
    
    return 0;
}


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

const int maxn = 2e5 + 5;

int n;
int c[maxn];
vector<int> G[maxn];

int sz[maxn];
int tot;
int cnt[maxn];
typedef long long ll;

ll ans[maxn];

void dfs(int u, int fa){
    sz[u] = 1;
    int in = cnt[c[u]]; 
    for(auto v : G[u]){
        if(v == fa)
            continue;
        int front = tot - cnt[c[u]];
        dfs(v, u);
        sz[u] += sz[v];
        int back = tot - cnt[c[u]];
        ans[c[u]] -= 1LL * (back - front) * (back - front + 1) / 2;
    } 
    tot++;
    cnt[c[u]] = in + sz[u];
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> c[i];
    }
    for(int i = 1;i < n;i++){
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1, 1);
    for(int i = 1;i <= n;i++){
        ans[i] -= 1LL * (n - cnt[i]) * (n - cnt[i] + 1) / 2;
        ans[i] += 1LL * n * (n + 1) / 2;
    }
    for(int i = 1;i <= n;i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 37176
#include<iostream>
using namespace std;
const int maxn = 10009;
int n,m,ans;
int a[maxn];
int main()
{
	cin>>n;
	cout<<"Christmas";
	if (n == 24) cout<<" Eve";
	if (n == 23) cout<<" Eve Eve";
	if (n == 22) cout<<" Eve Eve Eve";
	cout<<endl;
	return 0;
}


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

using namespace std;
int h[300005],w[300005];
int a[300005],b[300005];
map<pair<int,int>,int>mp;
int main(){
	int s,t;
	cin>>s>>t;
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>h[i]>>w[i];
		mp[make_pair(h[i],w[i])]=1;
		a[h[i]]++,b[w[i]]++;
	} 
	int p1=0,p2=0;
	for(int i=1;i<=s;i++)if(a[i]>p1){
		p1=a[i],p2=i;
	}
	vector<int>v1,v2;
	int k1=0,k2=0;
	for(int i=1;i<=t;i++)if(b[i]>k1){
		k1=b[i],k2=i;
	}
	for(int i=1;i<=s;i++)if(a[i]==p1)v1.push_back(i);
	for(int i=1;i<=t;i++)if(b[i]==k1)v2.push_back(i);
	for(int i=0;i<v1.size();i++){
		for(int j=0;j<v2.size();j++){
			if(mp[make_pair(v1[i],v2[j])]==0){
				cout<<a[v1[i]]+b[v2[j]]<<endl;
				return 0;
			}
		}
	}
	cout<<a[p2]+b[k2]-1<<endl;
//	if(mp[make_pair(p2,k2)]==1)cout<<a[p2]+b[k2]-1;
//	else cout<<a[p2]+b[k2];
	return 0;
}

Measured memory_bytes: 30868
#include <cstdio>
#include <algorithm>
using namespace std;

int N,K; char V[600200];

int main()
{
	scanf ("%d %d %s",&N,&K,V);
	if (K > 2 * N) K = 2 * N + (K - 2 * N) % 2;

	int idx = 0, neg = 0;
	while (K--){
		if (V[idx] == 'A' ^ neg) V[idx] = !(V[idx] - 'A') + 'A';
		else{
			neg = !neg;
			V[idx+N] = neg ? 'B' : 'A';
			idx++;
		}
	}

	if (neg){
		for (int i=idx;i<idx+N;i++) V[i] = !(V[i] - 'A') + 'A';
	}
	puts(V+idx);

	return 0;
}


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

void rot(D& d) {
	d.push_back(d[0]);
	d.pop_front();
}

D f(D d) {
	D ret = d;
	for(int i = 0; i < 3; i++) {
		rot(d);
		ret = min(ret, d);
	}
	return ret;
}

int overlap(D d) {
	int ret = 1;
	D t = d;
	for(int i = 0; i < 3; i++) {
		rot(d);
		if(t == d) ret++;
	}
	return ret;
}


ll P(int n, int k) {
	ll ret = 1;
	for(int i = n - k + 1; i <= n; i++) ret *= i;
	return ret;
}

D C[400];

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

	map<D, int> m;
	map<D, int> cnt;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < 4; j++) {
			int c;
			cin >> c;
			C[i].push_back(c);
		}
		C[i] = f(C[i]);
		m[C[i]]++;
	}

	for(auto p : m) {
		cnt[p.first] = overlap(p.first);
	}

	ll ans = 0;
	for(int i = 0; i < N; i++) {
		D d1 = C[i];
		m[d1]--;
		for(int j = i + 1; j < N; j++) {
			D d2 = C[j];
			m[d2]--;
			for(int r1 = 0; r1 < 4; r1++) {
				map<D, int> t;
				t[f(D({ d1[1], d1[0], d2[1], d2[0] }))]++;
				t[f(D({ d1[0], d1[3], d2[2], d2[1] }))]++;
				t[f(D({ d1[3], d1[2], d2[3], d2[2] }))]++;
				t[f(D({ d1[2], d1[1], d2[0], d2[3] }))]++;
				ll k = 1;
				for(auto p : t) {
					if(!m.count(p.first) || m[p.first] < p.second) {
						k = 0;
						break;
					}
					k *= P(m[p.first], p.second);
					for(int loop = 0; loop < p.second; loop++) {
						k *= cnt[p.first];
					}
				}
				ans += k;
				rot(d1);
			}
			m[d2]++;
		}
		m[d1]++;
	}

	cout << ans / 3 << endl;
}

Measured memory_bytes: 1152
from itertools import groupby
N = int(input())
A = list(map(int, input().split()))
A.sort()
a = []

for i, j in groupby(A):
    a.append(len(list(j)))


def f(x):
    while x >= 3:
        x = x // 3 + x % 3
    return x


a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)

if two % 2 == 0:
    print(one + two)
else:
    print(one + two - 1)

Measured memory_bytes: 14452
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll n,k,d;
    bool nums[10];
    for(int i=0;i<10;i++)   nums[i] = false;
    cin >> n >> k;
    for(ll i=0;i<k;i++){
         cin >> d;
         nums[d] = true;
    }
    for(int i=n;;i++){
        bool flag = true;
        string str=to_string(i);
        for(int j=0;j<str.size();j++){
            if(nums[str[j]-'0']==true){
                flag=false;
                break;
            }
        }
        if(flag==true){
              cout << i << endl;
              break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
N, M = map(int, input().split())

diff_dic = defaultdict(lambda: [])
for _ in range(M):
    L, R, M = map(int, input().split())
    diff_dic[L-1].append([R-1, M])
    diff_dic[R-1].append([L-1, -M])

INF = 10 ** 10

# print(diff_dic)

ans_array = [INF] * N

for i in range(N):
    if ans_array[i] != INF:
        continue
    people_deque = deque()
    people_deque.append(i)
    if ans_array[i] == INF:
        ans_array[i] = 0
    while(len(people_deque)):
        # print(ans_array)
        person = people_deque.popleft()

        for v in diff_dic[person]:
            p, m = v
            if ans_array[p] == INF:
                ans_array[p] = ans_array[person] + m
                people_deque.append(p)
            elif ans_array[p] != (ans_array[person] + m):
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 110936
import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  var query = false
  var s = ""
  var a = new ArrayBuffer[(Int,Int)]
  while( { s = readLine.trim;s } != "0,0" ) {
    val n = s.split(",").map(_.toInt)
    a += ((n(1),n(0)))
  }
  val g = a.groupBy(n=>n._1).mapValues(_.map(_._2)).toSeq.sortWith(_._1 > _._1)
  try {
    while(true) {
      val n = readInt
      println(g.indexWhere(i => i._2.exists( i => i==n ))+1)
    }
  } catch { case e:Exception => Nil }
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll MOD = 1e9+7;

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

	int n, m; cin >> n >> m;
	cout << n*(n-1)/2 + m*(m-1)/2 << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long LL;

int main(){
  LL n, k;
  cin >> n >> k;
  LL ans = 0;
  LL d = n / k;
  ans += d * d * d;
  if(k % 2 == 0){
    k /= 2;
    LL t = n / k - d;
    ans += t * t * t;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,i,j,a;
  int r[100]={0};
  while(1){
    scanf("%d %d",&n,&m);
    if(!(n||m))break;
    int d[100]={0};
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	r[j]=j;
	scanf("%d",&a);
	if(a)d[j]++;
      }
    }
    for(i=0;i<m;i++){
      for(j=1;i+j<m;j++){
	if(d[r[j-1]]<d[r[j]]){
	  a=r[j-1];
	  r[j-1]=r[j];
	  r[j]=a;
	}
      }
    }
    for(i=0;i<m;i++){
      if(i)printf(" ");
      printf("%d",r[i]+1);
    }
    printf("\n");
  }
  return 0;
}

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

int main(){
    int N, P, S;
    int sum = 0;
    cin >> N;
    S = N;

    while(S > 0){
        sum += S % 10;
        S /= 10;
    }

    P = N % sum;

    if(P == 0){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

ll count1(ll x, ll n, ll k, vll &a, vll &b, ll aa, ll bb) {
	ll ans = 0, j = 0;
	for (ll i = 0; i < aa; i++) {
		while (j < bb && a[i] * b[j] > x) j++;
		if (j == bb) break;
		ans += bb - j;
	}
	return ans;
}

//二分探索
//main関数で呼び出す前に，l, rの一方が条件を満たし他方が満たさないことを確認すること
//配列を引数にするときは原則として参照渡しすること
long long bs1(long long l, long long r, ll n, ll k, vll &a, vll &b, ll aa, ll bb) {
	if (l + 1 == r) {
		if (count1(l, n, k, a, b, aa, bb) >= k) return l;
		else return r;
	}

	long long mid = (l + r) / 2;
	if (count1(mid, n, k, a, b, aa, bb) >= k) return bs1(l, mid, n, k, a, b, aa, bb);
	else return bs1(mid, r, n, k, a, b, aa, bb);
}

ll count2(ll x, ll n, ll k, vll &a, vll &b, ll aa, ll bb) {
	ll ans = 0, j1 = aa - 1, j2 = bb - 1;
	for (ll i = 0; i < aa - 1; i++) {
		while (j1 > i && a[i] * a[j1] <= x) j1--;
		if (j1 >= i) ans += aa - 1 - j1;
		else ans += aa - 1 - i;
	}
	for (ll i = 0; i < bb - 1; i++) {
		while (j2 > i && b[i] * b[j2] > x) j2--;
		if (j2 == i) break;
		ans += j2 - i;
	}
	return ans;
}

long long bs2(long long l, long long r, ll n, ll k, vll &a, vll &b, ll aa, ll bb) {
	if (l + 1 == r) {
		if (count2(l, n, k, a, b, aa, bb) >= k) return l;
		else return r;
	}

	long long mid = (l + r) / 2;
	if (count2(mid, n, k, a, b, aa, bb) >= k) return bs2(l, mid, n, k, a, b, aa, bb);
	else return bs2(mid, r, n, k, a, b, aa, bb);
}

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

	ll n, k;
	cin >> n >> k;
	vll a(0), b(0);
	for (ll i = 0; i < n; i++) {
		ll x;
		cin >> x;
		if (x < 0) a.push_back(x);
		else if (x > 0) b.push_back(x);
	}
	sort(all(a));
	sort(all(b));

	ll aa = a.size(), bb = b.size();
	ll x, y, z;
	x = aa * bb;
	z = aa * (aa - 1) / 2 + bb * (bb - 1) / 2;
	y = n * (n - 1) / 2 - x - z;

	if (k <= x) {
		cout << bs1(-1e18 - 1, -1, n, k, a, b, aa, bb) << endl;
	}
	else if (k <= x + y) cout << 0 << endl;
	else {
		k -= x + y;
		cout << bs2(0, 1e18, n, k, a, b, aa, bb) << endl;
	}
}


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

int main(int argc, char *argv[]){
  int b[3];
  for (int i = 0; i < 3; i++) {
    cin >> b[i];
  }
  if(b[2] == 1 || (b[0] == 1 && b[1] == 1)){
    std::cout << "Open" << std::endl;
  }else{
    std::cout << "Close" << std::endl;
  }
  return 0;
}

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

bool ok(const string &S, const string& L){
    for(size_t b=0; b<L.size(); b++){
        for(size_t d=0; b+d*(S.size()-1)<L.size(); d++){
            for(size_t is=0, il=b; is<S.size() && il<L.size(); is++, il+=d){
                if(S[is]!=L[il]) break;
                if(S[is]==L[il] && is==S.size()-1){
                    return true;
                }
            }
        }
    }
    return false;
}

int n;
string S, L;

int main(){
    cin>>n>>S;
    int ans=0;
    while(n--){
        cin>>L;
        ans+=ok(S,L);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

signed main()
{

 	FLASH
 	int a, p;
 	cin>>a>>p;

 	p += 3*a;
 	cout<<p/2;
 	
}

Measured memory_bytes: 256
n=int(input())
c0,c1,c2,c3=0,0,0,0
for _ in range(n):
    s=input()
    if s=="AC":
        c0+=1
    elif s=="TLE":
        c2+=1
    elif s=="WA":
        c1+=1
    else:
        c3+=1
print("AC x",c0)
print("WA x",c1)
print("TLE x",c2)
print("RE x",c3)

Measured memory_bytes: 9204
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long a,b;
    scanf("%ld%ld", &a, &b);

    char str[8]={0};
    sprintf(str, "%ld%ld", a,b);

    long c;
    sscanf(str, "%ld", &c);

    double x = floor(sqrt((double)c)+0.1);
    if(fabs(x*x - c) <1e-8) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=220,M=10001000,oo=1000000000;
int i,j,k,n,nb0,nb1,nm,ans,En,S,T;
int a[N],fg[M],pr[M/10],z[M];
int b0[N],b1[N],c[N],d[N],h[N];
struct edge { int s,n,v;} E[N*N];
void pre(int n) {
	int i,j;
	fg[1]=3;
	for (i=2;i<=n;i++) {
		if (fg[i]!=3) pr[++nm]=i,fg[i]=1;
		for (j=1;j<=nm;j++) {
			if (i*pr[j]>n) break;
			fg[i*pr[j]]=3;
			if (i%pr[j]==0) break;
		}
	}
	for (i=2;i<=n;i+=2) fg[i]=2;
}
void E_add(int x,int y,int v) {
	E[++En].s=y;E[En].v=v;
	E[En].n=h[x];h[x]=En;
	E[++En].s=x;E[En].v=0;
	E[En].n=h[y];h[y]=En;
}
bool bfs() {
	int i,j,k;
	memset(c,0,sizeof c);
	i=0;j=1;d[1]=S;c[S]=1;
	while (i<j) {
		i++;
		for (k=h[d[i]];k;k=E[k].n) if (E[k].v && !c[E[k].s]) {
			c[E[k].s]=c[d[i]]+1;
			d[++j]=E[k].s;
		}
	}
	return c[T];
}
int dfs(int x,int y) {
	if (x==T || !y) return y;
	int k,t,Y=y;
	for (k=h[x];k;k=E[k].n) if (E[k].v && c[x]+1==c[E[k].s]) {
		t=dfs(E[k].s,min(E[k].v,y));
		y-=t;
		E[k].v-=t;
		E[k^1].v+=t;
		if (!y) return Y;
	}
	if (Y==y) c[x]=-1;
	return Y-y;
}
int main() {
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	pre(a[n]);
	for (i=1;i<=n;i++) z[a[i]]^=1,z[a[i]+1]^=1;
	for (i=1;i<=a[n]+1;i++) if (z[i]) {
		if (i&1) b1[++nb1]=i;
		else b0[++nb0]=i;
	}
	En=1;S=nb0+nb1+1;T=S+1;
	for (i=1;i<=nb0;i++) E_add(S,i,1);
	for (j=1;j<=nb1;j++) E_add(nb0+j,T,1);
	for (i=1;i<=nb0;i++)
		for (j=1;j<=nb1;j++) {
			k=b0[i]-b1[j];
			if (k<0) k=-k;
			if (fg[k]==1) E_add(i,nb0+j,1);
		}
	while (bfs()) ans+=dfs(S,oo);
	nb0-=ans;
	nb1-=ans;
	ans+=nb0/2*2+nb1/2*2;
	nb0&=1;nb1&=1;
	if (nb0) ans+=3;
	printf("%d\n",ans);
}

Measured memory_bytes: 80640
import itertools
import sys
input = sys.stdin.readline


def BlackCount(fig, cal_row, cal_col):
    N = 0
    for i in range(len(fig)):
        for j in range(len(fig[0])):
            if i not in cal_row and j not in cal_col:
                if fig[i][j] == '#':
                    N += 1
    return N


H, W, K = map(int, input().split())
fig = []
for i in range(H):
    row = list(input().rstrip('\n'))
    fig.append(row)

Nlist = list(itertools.product(range(H), range(W)))
# print(Nlist)
ans = 0
for N_row, N_col in Nlist:
    # print(N_row, N_col)
    cal_row_list = list(itertools.combinations(range(H), N_row))
    # print(cal_row_list)
    cal_col_list = list(itertools.combinations(range(W), N_col))
    # print(cal_col_list)
    for cal_row, cal_col in itertools.product(cal_row_list, cal_col_list):
        if BlackCount(fig, cal_row, cal_col) == K:
            ans += 1
print(ans)


Measured memory_bytes: 74264
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
ll digit(ll x) {
    int res = 0;
    while(x > 0) {
        x /= 10;
        res++;
    }
    return res;
}
ll f(ll a, ll b) {
    return max(digit(a), digit(b));
}
int main() {
    ll N; cin >> N;
    auto p = divisor(N);
    ll ans = 1e18;
    rep(i, p.size()) {
        ans = min(ans, f(p[i], N/p[i]));
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	int K,A,B,x,y;
	cin>>K>>A>>B;
	x=A/K;
	y=B/K;
	if((y-x)>0 || A%K==0 || B%K==0){
		cout<<"OK";
	}else{
		cout<<"NG";
	}
	
}

Measured memory_bytes: 3596
snukes = input().split(" ")
n = int(snukes[0])
k = int(snukes[1])

village = [0] * n
for i in range(k):
    numOwners = int(input())
    candyOwners = input().split(" ")
    for j in range(numOwners):
        village[int(candyOwners[j])-1] += i+1

print(village.count(0))


Measured memory_bytes: 9044
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<string>
#define mod 1000000007
#define ll long long
using namespace std;
char s[200000];
int main()
{
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
    cin>>s;
	for(int i=0;i<strlen(s);i=i+2)
	{
	   cout<<s[i];	
	} 
	cout<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define MAXN 21010
#define Scan(a) scanf("%I64d", &a)
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') cout << a+b;
    else cout << a-b;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  if(n==1){
    cout << "Hello World" << endl;
  }else if(n==2){
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
  }
  return 0;
}


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


int main(){
  string str;
  cin >> str;
  int n = str.length();
  for(int i = 0; i<n; i++){
  cout << "x";
  }
  return 0;
}


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

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("A.inp", "r")){
                freopen("test.inp", "r", stdin);
                freopen("test.out", "w", stdout);
        }
        ll x;
        cin >> x;
        cout << 1 - x;
}
/*
*/


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

int main(){

    int n;
    int count=0;

    
    cin >> n;
      vector<int> p(n);
    for(int i=0; i<n; i++) cin >> p[i];
    
    
    for(int i=1;i<=n-2;i++){
        
        
        if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] && p[i]>p[i+1])){
            count++;
        }
        
    }
    
    cout << count;
 
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<ll> A;
    rep(i, N) {
        ll a;
        cin >> a;
        A.push(a);
    }
    rep(i, M) {
        ll a = A.top();
        A.pop();
        A.push(a / 2);
    }
    ll ans = 0;
    rep(i, N) {
        ans += A.top();
        A.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
     
    string s; string temp;
    while(getline(cin,temp)){
        s += temp;
    }
     
    for(int i=97; i<=122; i++){
        int sum = 0;
        char a = (char)i;
        char b = (char)(i-32);
        for(int j=0; j<s.length(); j++){
            if(s[j]==a || s[j]==b) sum ++;
        }
        cout<<(char)i<<" : "<<sum<<endl;
    }
    
 
     
    return 0;
     
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
long int n,k,x,y,z;
int main()
{
    cin>>n>>k>>x>>y;
    for(int i=1;i<=n;i++)
    {    
    	if(i<=k)
		z+=x;
    	else 
		z+=y;
    }
    cout<<z<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  int n,k;
  cin>>n>>k;
  ////////// 1/nかける1／2の（kを超える回数）乗　　の和
  double ans;
  for(int i = 1 ; i <= (n) ; i ++ ){
    int count=0;
    
    int c=i;
    
    while(c<k){
      
      count++;
      
      c*=2;
    }
    
    ans+=pow(0.5,count)/n;
    
    
    
    //cout<<ans<<endl;
  }
  cout<<fixed<<setprecision(10);
 cout<<ans<<endl;
}






Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	long[] as;
	foreach(i; 0 .. n + 1) as ~= read.to!long;
	long[] bs;
	foreach(i; 0 .. n) bs ~= read.to!long;
	
	long ans;
	foreach(i; 0 .. n){
		long k;
		if(bs[i] <= as[i]) k = bs[i];
		else k = as[i];
		ans += k, bs[i] -= k, as[i] -= k;
		
		if(bs[i] <= as[i + 1]) k = bs[i];
		else k = as[i + 1];
		ans += k, bs[i] -= k, as[i + 1] -= k;
	}
	
	ans.writeln;
	
}


Measured memory_bytes: 9196
S = gets.chomp
size = S.size
a = Array.new(size,0)
odd = 0
even = 0
l = 0
r = 0
f = 0

for i in 0...size do
    if S[i] == 'R'
        if f == 0
            if i % 2 == 0
                even += 1
            else
                odd += 1
            end
        else
            f = 0
            if l%2 == 0
                a[l] = even
                a[r] = odd
            else
                a[r] = even
                a[l] = odd
            end
            even = 0
            odd = 0
            if i % 2 == 0
                even += 1
            else
                odd += 1
            end
        end
    else
        if i % 2 == 0
            even += 1
        else
            odd += 1
        end
        if f == 0
            f = 1
            l = i-1
            r = i
        end
    end
end
if l%2 == 0
    a[l] = even
    a[r] = odd
else
    a[r] = even
    a[l] = odd
end

for i in 0...size do
    print a[i]
    print " "
end
puts

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

typedef long long ll;

ll s[550];
bool ok[550];

int main() {
    ll H,W,h,w;
    ll cnt = 0;
    cin >> H >> W >> h >> w;
    if (H % h == 0 && W % w == 0) {
        cout << "No" << endl;
        return 0;
    }
    bool swp = 0;
    if (W % w == 0) {
        swp = 1;
        swap(W,H);
        swap(w,h);
    }
    int tmp = W;
    cnt = 1;
    while (tmp > 0) {
        s[tmp] = cnt++;
        ok[tmp] = 1;
        tmp -= w;
    }
    tmp = 0;
    cnt = 0;
    while (tmp <= W) {
        s[tmp] = cnt--;
        ok[tmp] = 1;
        tmp += w;
    }
    for (int i = 1; i < W; i++) {
        if (!ok[i]) {
            tmp = i;
            cnt = 0;
            while (tmp <= W) {
                s[tmp] = cnt--;
                ok[tmp] = 1;
                tmp += w;
            }
        }
    }
    cout << "Yes" << endl;
    if (!swp) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << s[j + 1] - s[j] << " \n"[j == W - 1];
            }
        }
    } else {
        for (int i = 0; i < W; i++) {
            for (int j = 0; j < H; j++) {
                cout << s[i + 1] - s[i] << " \n"[j == H - 1];
            }
        }
    }

    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //切り出しする文字列
        int N = sc.nextInt();
        String Nst = String.valueOf(N);
        String Anst = Nst.substring(Nst.length() - 1);
        int Ans = Integer.parseInt(Anst);
        if(Ans == 2 || Ans == 4 || Ans == 5 || Ans == 7|| Ans == 9){
            System.out.println("hon");
        }
        if(Ans == 0 || Ans == 1 || Ans == 6 || Ans == 8){
            System.out.println("pon");
        }
        if(Ans == 3){
            System.out.println("bon");
        }
    }
}

Measured memory_bytes: 35736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PI acos(-1.0)
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	char a;
  cin >> a;

  if(a >= 'A' && a <='Z'){
    cout << "A" << endl;
  }else{
    cout << "a" << endl;
  }


  return 0;
}


Measured memory_bytes: 3596
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

immutable int Dirs = 4;
immutable int [Dirs] DCol = [+1,  0, -1,  0];
immutable int [Dirs] DRow = [ 0, +1,  0, -1];

void main ()
{
	int h, w;
	while (readf (" %s %s", &h, &w) > 0)
	{
		readln;
		char [] [] a;
		foreach (row; 0..h)
		{
			a ~= readln.strip.dup;
		}

		auto build (int row, int col, int [2] s)
		{
			auto res = new char [] [] (h, w);
			foreach (ref x; res)
			{
				x[] = '.';
			}
			int b = 0;
			int dir = 0;
			if (col >= 0)
			{
				res[row][col] = '#';
			}
			while (s[b] > 0)
			{
				foreach (step; 0..s[b])
				{
					row += DRow[dir];
					col += DCol[dir];
					if (col >= 0)
					{
						res[row][col] = '#';
					}
				}
				dir = (dir + 1) & (Dirs - 1);
				s[b] -= 2;
				if (s[b] < 0)
				{
					break;
				}
				b ^= 1;
			}
			return res;
		}

		char [] [] b = build (0, -2, [w + 1, h - 1]);
		char [] [] c = build (1, -1, [w - 1, h - 3]);

		foreach (row; 0..h)
		{
			foreach (col; 0..w)
			{
				if (a[row][col] == '#')
				{
					b[row][col] = '#';
					c[row][col] = '#';
				}
				else
				{
					assert (b[row][col] != '#' ||
					    c[row][col] != '#');
				}
			}
		}

		writefln ("%-(%s\n%)", b);
		writeln;
		writefln ("%-(%s\n%)", c);
	}
}


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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r.begin()); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }

int main()
{
  int n, m;
  while (n = in(), m = in(), n || m){
    vector<int> ns = inpt<int>(n);
    vector<int> ms = inpt<int>(m);
    int nt = acum(ns);
    int mt = acum(ms);
    sort(ns);
    sort(ms);

    const int INF = 1e9;
    int mini = INF;
    pair<int, int> p;
    for (int i = 0; i < n; i++){
      for (int j = 0; j < m; j++){
        if (mt + ns[i] - ms[j] != nt - ns[i] + ms[j]) continue;
        int t = ms[j] + ns[i];
        if (mini < t) continue;
        mini = t;
        p = make_pair(ns[i], ms[j]);
      }
    }
    if (mini == INF){
      puts("-1");
    }
    else {
      cout << p.first << " " << p.second << endl;
    }
  }

  return (0);
}

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

int LCM(int n, int m)
{
  if (n == 0){
    return (m);
  }
  m = m % n;
  return (LCM(m, n));
}

int main()
{
  int a, b, lcm, gcd;

  while (cin >> a >> b){

    if (a > b){
      int c = a;
      a = b;
      b = c;
    }

    lcm = LCM(a, b);
    gcd = a / lcm * b;

    cout << lcm << " " << gcd << endl;
  }
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

ll N,M;
deque<int> D;
ll dp [100] [2] [2];
const ll MOD = 1e9 + 7;

int main()
{
	scanf("%lld",&N);
	ll c = N;
	do{
		D.push_front(c & 1);
	}while(c >>= 1);
	M = D.size();

	dp [0] [0] [0] = 1;
	FOR(i,0,M) FOR(j,0,2) FOR(k,0,2) if(dp [i] [j] [k]){
		if(j == 0 && k == 0){
			if(D [i] == 0){
				(dp [i + 1] [0] [0] += dp [i] [j] [k]) %= MOD;
			}
			else{
				(dp [i + 1] [0] [1] += dp [i] [j] [k]) %= MOD;
				(dp [i + 1] [0] [0] += dp [i] [j] [k]) %= MOD;
				(dp [i + 1] [1] [0] += dp [i] [j] [k]) %= MOD;
			}
		}
		else if(j == 0 && k == 1){
			(dp [i + 1] [0] [1] += dp [i] [j] [k]) %= MOD;
			(dp [i + 1] [0] [1] += dp [i] [j] [k]) %= MOD;
			(dp [i + 1] [1] [1] += dp [i] [j] [k]) %= MOD;
		}
		else if(j == 1 && k == 0){
			if(D [i] == 0){
				(dp [i + 1] [0] [0] += dp [i] [j] [k]) %= MOD;
				(dp [i + 1] [1] [0] += dp [i] [j] [k]) %= MOD;
			}
			else{
				(dp [i + 1] [0] [1] += dp [i] [j] [k]) %= MOD;
				(dp [i + 1] [1] [1] += dp [i] [j] [k]) %= MOD;
				(dp [i + 1] [1] [0] += dp [i] [j] [k]) %= MOD;
			}
		}
		else{
			(dp [i + 1] [0] [1] += dp [i] [j] [k]) %= MOD;
			(dp [i + 1] [1] [1] += dp [i] [j] [k]) %= MOD;
			(dp [i + 1] [1] [1] += dp [i] [j] [k]) %= MOD;
		}
	}

	ll ans = (dp [M] [0] [0] + dp [M] [0] [1]) % MOD;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256