akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {

	int H = 0;			//??????????????°??????????????°
	int i = 0;
	int W = 0;			//?¨????????????°??????????????°
	int j = 0;

	do{
		scanf("%d",&H);
		scanf("%d",&W);
		for(i = 1 ; i <= H ; i++){
			for(j = 1 ; j <= W ; j++){
				printf("#");
			}
			printf("\n");
		}

		if(W || H){
			printf("\n");
		}

	}while(W || H);

	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const long long MOD=1e09+7;

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






int main(){
  

  int n;
  cin>>n;
  
  vi height(n);
  rep(i,n){
    int tmp;
    cin>>tmp;
    height.at(i)=tmp;
  }
  
  vi maxes(n);
  int tmp=height.at(0);
  maxes.at(0)=tmp;
  for (int i=1;i<n;i++){
    tmp=max(tmp,height.at(i));
    maxes.at(i)=tmp;
  }
  
  int answer=0;
  rep(i,n){
    if (height.at(i)==maxes.at(i)){
      answer++;
    }
  }
  
  cout<<answer<<endl;

    
      
 

  
}

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 ll;

ll ceil(ll i, ll j) {
	return i / j + (i%j > 0);
}
int main() {
	ll n; scanf("%lld", &n);
	ll A = 1, B = 1;
	rep(i, n) {
		ll t, a; scanf("%lld%lld", &t, &a);
		ll n = max(ceil(A, t), ceil(B, a));
		A = t*n; B = a*n;
	}
	printf("%lld\n", A + B);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  int N;
  cin>>N;
  vector<int> C(N);
  for(int i=0;i<N;i++){
    cin>>C.at(i);
  }
  vector<vector<int>> index(200001);
  for(int i=0;i<N;i++){
    index.at(C.at(i)).push_back(i);
  }

  vector<ll> dp(N+1,0);
  dp.at(0)=1;
  for(int i=0;i<N;i++){
    dp.at(i+1)+=dp.at(i);
    dp.at(i+1)%=MOD;
    if(i<N-1){
      if(C.at(i)==C.at(i+1)){
        continue;
      }
    }
    int c=C.at(i);
    int k=upper_bound(index.at(c).begin(),index.at(c).end(),i+1)-index.at(c).begin();
    if(k==index.at(c).size()){
      continue;
    }
    dp.at(index.at(c).at(k))+=dp.at(i);
    dp.at(index.at(c).at(k))%=MOD;
  }
  cout<<dp.at(N-1)<<endl;
}


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

using namespace std;

int main(){
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	if(a1 + a2 + a3 >= 22){
		cout << "bust";
	} 
	else {
		cout << "win";
	}
	return 0;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())
rad = math.radians((abs(((h / 12.0)+(m/60.0/12.0)) - (m / 60.0)) * 360))
print(math.sqrt((math.cos(rad)*a-b)**2 + (math.sin(rad)*a)**2))

Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
int ko[10][2];
int main()
{
	//freopen("a.gir","r",stdin);
	//freopen("a.cik","w",stdout);
	int n;
	cin >> n;
	vector<int>path;
	for(int i=1;i<=n;i++)
		path.push_back(i);
	for(int i=1;i<=n;i++)
	{
		cin >> ko[i][0] >> ko[i][1];
	}
	long double sum=0;
	do
	{
		for(int i=0;i<n-1;i++)
		{
			long double temp=ko[path[i]][0]-ko[path[i+1]][0];
			temp*=temp;
			long long temp2=ko[path[i]][1]-ko[path[i+1]][1];
			temp2*=temp2;
			temp+=temp2;
			temp=sqrt(temp);
			sum+=temp;
		}
	}

	while(next_permutation(path.begin(),path.end()));
	long long fak=1;
	cout.precision(8);
	while(n>1)
	{
		fak*=n;
		n--;
	}
	cout << sum/fak;
}

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

using namespace std;

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

    if(N%2 != 0){
        cout << "No" << endl;
        return 0;
    }else{
        for(int i=0; i<N/2; i++){
            if(S[i] != S[i+N/2]){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
e = [[] for _ in range(N + 1)]
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

t = 0
res = 0
for x in range(1, N + 1):
  res += x * (N - x + 1)
  for y in e[x]:
    if y < x: t += y * (N - x + 1)
    else: t += x * (N - y + 1)
print(res - t // 2)

Measured memory_bytes: 106032
n,k=map(int,input().split())
l=[i for i in range(1,k+1)][::-1]
mod=10**9+7
m=[0]*(k+1)
for i in l:
  a=k//i
  m[i]=pow(a,n,mod)
  for j in range(i*2,k+1,i):
    m[i]-=m[j]
ans=0
for i in range(k+1):
  ans+=m[i]*i
  ans%=mod
print(ans%mod)

Measured memory_bytes: 15312
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>
#include <cstring>
#include <cctype>
#include <random>

using namespace std;
typedef long long  ll;
const ll INF = 1000000007;
const ll mod = 998244353;

int main()
{
	ll n;
	cin >> n;
	for (ll N = 1; N <= n; N++)
	{
		ll ans = 0;
		for (ll x = 1; x * x <= N; x++)
		{
			for (ll y = 1; y * y + x * x + x * y <= N; y++)
			{
				for (ll z = 1; x * x + y * y + z * z + x * y + y * z + z * x <= N; z++)
				{
					if (x * x + y * y + z * z + x * y + y * z + z * x == N)
					{
						ans++;
					}
				}
			}
		}
		cout << ans << "\n";
	}
	cout << endl;
	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;



Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){

  while(u!=NIL&&k!=u->key){

    if(k<u->key){

      u=u->left;
    }
    else if(k>=u->key){

      u=u->right;
    }

  }

    return u;
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){

    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key<y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20480
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	int ans = 0;
	rep(i,n){
		int a;
		cin >> a;
		while(a % 2 == 0 and a != 0){
			ans++;
			a/=2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 200005
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(c) (c).begin(), (c).end()
#define KONJ 42-42
using namespace std;

int n, h, x, sol;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> h;
	for (int i = 0; i < n; i++) {
		cin >> x;
		if (x >= h) sol++;
	}
	cout << sol;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a >= b){
            if(a >= c){
                System.out.println(10 * a + b + c);
            }else {
                System.out.println(10 * c + a + b);
            }
        }else{
            if(b > c) {
                System.out.println(10 * b + a + c);
            }else{
                System.out.println(10 * c + a + b);
            }
        }
    }
}


Measured memory_bytes: 24916
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);

int n;
int[] a;
int[] b;
int[] c;

long[][] dp = new long[][](100010, 4);
long rec(int i, int p) {
    if (dp[i][p] >= 0)
        return dp[i][p];
    if (i == n)
        return dp[i][p] = 0;
    long ret;
    int[] lucky = [a[i], b[i], c[i]];
    foreach (c; 0..3) if (c != p) {
        ret = max(ret,
                rec(i+1, c) + lucky[c]);
    }
    return dp[i][p] = ret;
}

void main() {
    n = read();
    a.length = b.length = c.length = n;
    foreach (i; 0..n) {
        readf("%d %d %d\n", &a[i],&b[i],&c[i]);
    }
    foreach (r; dp) fill(r, -1);
    writeln(rec(0, 3));
}


Measured memory_bytes: 20476
#include <iostream>
#include <algorithm>

#define int long long
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

using namespace std;

int A, B;
int G[101][101]; // Black:0, White:1

signed main()
{
    cin >> A >> B;

    int h = 100;
    int w = 100;

    int bnum = 1;
    int wnum = 1;
    REPS(i, h) REPS(j, w)
    {
        if (j <= 50)
        {
            if (i%2 == 0 && j%2 != 0 && bnum < B)
            {
                ++bnum;
                G[i][j] = 0;
            }
            else
            {
                G[i][j] = 1;
            }
        }
        else
        {
            if (i%2 == 0 && j%2 == 0 && wnum < A)
            {
                ++wnum;
                G[i][j] = 1;
            }
            else
            {
                G[i][j] = 0;
            }
        }
    }

    printf("%lld %lld\n", h, w);
    REPS(i, h)
    {
        REPS(j, w)
        {
            char c = G[i][j] == 0 ? '#' : '.';
            printf("%c", c);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 384
/*input
30
4
*/

#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)
#define int long long int
#define itr ::iterator it;
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>                      
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
const int MOD = 1000000007;

string K; int D; int n;
int dp[10009][2][200];
int solve(int pos,bool prev,int sum){
	if(pos==n){
		if(sum%D==0) return 1;
		else return 0;
	}
	if(dp[pos][prev][sum]!=-1) return dp[pos][prev][sum]; 
	
	int till = prev?(K[pos]-'0'):9;
	int ans = 0;
	for(int i=0;i<=till;i++){
		ans = (ans%MOD + solve(pos+1,prev and i==till,(sum%D+i%D)%D)%MOD)%MOD;
	}
	return dp[pos][prev][sum]=ans;
}
signed main(){
	memset(dp,-1,sizeof dp);
	cin>>K>>D;
	n = K.size();
	int ans = solve(0,1,0); cout<<(ans-1+MOD)%MOD;
}



Measured memory_bytes: 32640
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    for0(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    Sort(s) sort(s.begin(),s.end())
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long int
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
    
	int m,n,p[1000],mx=0,mi=100,x;
	cin>>m>>n;
	int a[n];
	for0(i,n){
		cin>>a[i];
		p[a[i]]=1;
		mx=max(mx,a[i]);
		mi=min(mi,a[i]);
	}
	int q=100,t=0;
	for(int i=0;i<105;i++){
		if(p[i]!=1){
			x=abs(i-m);
			q=min(q,x);
		}
	}
	for(int i=0;i<105;i++){
		if(p[i]!=1){
			if(abs(i-m)==q){
				cout<<i;break;
			}
		}
	}
	
End;
}


Measured memory_bytes: 3692
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int a[3];
    int ans=0;
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    sort(a,3+a);
    ans = a[2]-a[1];
    ans = ans+a[1]-a[0];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
def gcd(m, n):
	if m % n == 0:
		return n
	return gcd(n, m % n)

def resolve():
	ans = 0
	k = int(input())
	for i in range(1, k+1):
		for j in range(1, k+1):
			for k in range(1, k+1):
				ans += gcd(i, gcd(j, k))
	print(ans)
resolve()

Measured memory_bytes: 77044
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  
  if(A==B){
    cout << "Draw" << endl;
  }
  else if(A>B){
    if(B==1){
      cout << "Bob" << endl;
    }
    else{
    cout << "Alice" << endl;
    }
  }
  else if(B>A){
    if(A==1){
      cout << "Alice" << endl;
    }
    else{
    cout << "Bob" << endl;
  } 
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {
	if (a * b == 0)
		return a + b;
	return gcd(b, a % b);
}

void solve() {
	int n;
	cin >> n;
	__int128 ans = 1;
	for (int i = 0; i < n; i++) {
		ll t;
		cin >> t;
		ll x = ans;
		ans = (t * ans) / gcd(t, x);
	}
	ll x = ans;
	cout << x;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1; 
    //cin >> T;
    while(T--) solve();
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b,c,d,e,k;
  int cnt=0;

  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);
  scanf("%d",&k);

  if(e-a<=k) printf("Yay! \n");
  else printf(":( \n");
  
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b[] = new int[100];
		int i = 0;
		int sum = 0;
		int c = a;

		while (c != 0) {
			b[i++] = c % 10;
			c /= 10;
		}

		for (int j = 0; j < i; j++) {
			sum += b[j];
		}

		if (a % sum == 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 23764
n=int(input())
a = sorted( list(map(int,input().split())) )
b=[0]*n
b[0]=a[0]
for i in range(n-1):b[i+1]=b[i]+a[i+1]
chk2 = [1 if b[i]*2>=a[i+1] else 0 for i in range(n-1)]
ans=0
while ans<n-1:
    if chk2[n-2-ans]==0:break
    ans+=1
print(ans+1)


Measured memory_bytes: 20528
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define mp make_pair
#define for(i,a,b) for(int i=(a);i<=(b);i++)
#define forr(x,arr) for(auto& x:arr)
#define vi vector<int>
#define pii pair<int, int>
#define fi first 
#define se second
#define all(x) (x).begin(), (x).end()
const int inf=1<<30; const ll linf=1ll<<60 ; const ll mod=1e9+7 ;
template<class t>bool chmax(t &a, const t &b) { if (a<b) { a = b; return 1; } return 0; }
template<class t>bool chmin(t &a, const t &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------


int main(){
	int n; cin >> n;
	int r=0, b=0;
	for(i,1,n){
		char s; cin >> s;
		if(s == 'R')  r += 1;
		else b += 1;
	}

	if( r > b) cout << "Yes"<< endl;
	else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using lb = long double;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SI(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
#define debugV(x) for(int i=0;i<((ll)(x).size());i++)cerr << #x <<"at:"<<i<< ": " << x[i] << "\n"//手動デバッグ 
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define O(p) cout<<p<<"\n",0
#define OS(p) cout<<p<<" ",0
#define ON(p) cout<<p,0
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};//^>v<

template<class T=int> T in(){
    T x;
    cin>>x;
    return (x);
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
//------------------------------------------------------------





//------------------------------------------------------------
int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
//------------------------------------------------------------
    int n;cin>>n;
    vector<ll> A(n);
    ll com=-1;
    vector<ll> M(n);
    rep(i,n){
        cin>>A[i];
        com=max(com,A[i]);
        M[i]=com;
    }
    
    ll sum=0;
    rep(i,n){
        sum+=(M[i]-A[i]);
    }
    O(sum);
    
    
    
    
    
    
//------------------------------------------------------------
	return 0;
}


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;



int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1 != m2)cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
s=list(input())
n=len(s)
ans=[0]*n
r=0
l=0
for i in range(n):
    if s[i]=="R":
        r+=1
    else:
        ans[i-1]+=(r+1)//2
        ans[i]+=r//2
        r=0
for i in range(n-1,-1,-1):
    if s[i]=="L":
        l+=1
    else:
        ans[i+1]+=(l+1)//2
        ans[i]+=l//2
        l=0
print(*ans)


Measured memory_bytes: 7096
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

if N == 0:
	if A[0] == 1:
		print(1)
	else:
		print(-1)
	exit()

num = 1
M = [0] * (N+1)
for i in range(N+1):
	M[i] = num
	if A[i] > num:
		print(-1)
		exit()
	num = (num - A[i]) * 2
ans = sum(A)

inodes = 0
for i in range(N-1, -1, -1):
	inodes = min(M[i]-A[i], A[i+1]+inodes)
	ans += inodes
print(ans)


Measured memory_bytes: 701040
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
constexpr long INF = 1 << 30;
constexpr int MOD = 1e9 + 7;

long n, m, a, b, c, dp[1<<12];

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n >> m;
  REP(i,1<<12) dp[i] = INF;

  dp[0] = 0;
  REP(i,m){
    cin >> a >> b;
    long upd = 0;
    REP(j, b) {
      cin >> c; --c;
      upd |= (1<<c);
    }
    REP(bit, 1<<n) {
      dp[bit | upd] = min(dp[bit | upd], dp[bit] + a);
    }
  }
  if(dp[(1<<n)-1] == INF) cout << -1;
  else cout << dp[(1<<n)-1];
  cout << endl;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if (12 < a) {
    ans = b;
  } else if (5 < a) {
    ans = b/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll> mp;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll H,W;cin>>H>>W;
    ll h,w;cin>>h>>w;
    cout<<(H-h)*(W-w);
}


Measured memory_bytes: 256
if __name__ == '__main__':
    A, B = map(int, input().split())
    count = 0
    if A > B:
        count += A
        A -= 1
    else:
        count += B
        B -= 1
    
    if A > B:
        count += A
        A -= 1
    else:
        count += B
        B -= 1
    
    print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 4005;
#define rend fuck

int x, y, z;
string s;

int dp[51][51][51][51];
int link[51][3]; // -1 if failure, otherwise follow it's next
int fail[51];

bool rend[MAXN];

bool f(int x, int y, int z, int m){
	if(m == s.size()) m = fail[m];
	if(x + y + z == 0) return rend[m];
	if(~dp[x][y][z][m]) return dp[x][y][z][m];
	int ret = 0;
	if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
	if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
	if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
	return dp[x][y][z][m] = ret;
}

bool trial(){
	int p = 0;
	for(int i=1; i<s.size(); i++){
		while(p && s[i] != s[p]) p = fail[p];
		if(s[i] == s[p]) p++;
		fail[i+1] = p;
	}
	for(int i=0; i<s.size(); i++){
		for(int j=0; j<3; j++){
			int pos = i;
			if(s[i] > j + 'a'){
				link[i][j] = -1;
				continue;
			}
			while(pos && s[pos] != j + 'a') pos = fail[pos];
			if(s[pos] == j + 'a') pos++;
			link[i][j] = pos;
		}
	}
	for(int i=0; i<s.size(); i++){
		int pos = i;
		rend[i] = 1;
		for(int j=0; j<s.size(); j++){
			pos = link[pos][s[j] - 'a'];
			if(pos == -1){
				rend[i] = 0;
				break;
			}
		}
	}
	memset(dp, -1, sizeof(dp));
	return f(x, y, z, 0);
}

int main(){
	cin >> x >> y >> z;
	while(s.size() < x + y + z){
		s.push_back('c');
		if(trial()) continue;
		s.back() = 'b';
		if(trial()) continue;
		s.back() = 'a';
	}
	cout << s << endl;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll a[100000];
ll cou[5];
ll b[5];
int main(void){
    ll n; cin >> n; for(int i = 0;i < n;i++)cin >> a[i];
    sort(a, a+n);
    int c = 0; ll mem = -1; int j = -1;
    fill(cou, cou+5, 1);
    for(int i = 0;i < n;i++){
        if(mem != a[i]){c++; j++; mem = b[j] = a[i];}
        else cou[j]++;
        if(c > 3){printf("No\n"); return 0;}
    }
    if(c == 1){
        if(a[0] == 0)printf("Yes\n");
        else printf("No\n");
    }else if(c == 2){
        if(n%3 == 0 && cou[0] *2 == cou[1])printf("Yes\n");
        else printf("No\n");
    }else{
        if(n%3 == 0 && cou[0] == cou[1] && cou[1] == cou[2]){
            if((b[0] ^ b[1]) == b[2])printf("Yes\n");
            else printf("No\n");
        }
        else printf("No\n");
    }
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  
  int count = 0;
  int n, sqrt_n;
  FOR(i, 1, N) {
    n = N - i;
    sqrt_n = ceil(sqrt(n));
    FOR(j, 1, sqrt_n) {
      if (n % j == 0) count+=2;
    }
    if (n == pow(sqrt_n, 2)) count++;
  }
  cout << count << endl;
}


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

using namespace std;

int main(){
	string s; cin >> s;
	string t; cin >> t;
	int ops = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] != t[i]){
			ops++;
		}
	}
	cout << ops << endl;
}

Measured memory_bytes: 3808
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author caoash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AHarmony solver = new AHarmony();
        solver.solve(1, in, out);
        out.close();
    }

    static class AHarmony {
        public void solve(int testNumber, FastScanner br, PrintWriter pw) {
            long A = br.nextInt();
            long B = br.nextInt();
            if (A == B) {
                pw.println(1);
            } else {
                long val = -A - B;
                pw.println((val % 2 == 0) ? Math.abs(val / 2) : "IMPOSSIBLE");
            }
            pw.close();
        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastScanner.SpaceCharFilter filter;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21972
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int W, H;
	cin >> W >> H;

	vector<lint> p(W), q(H);
	for (int i = 0; i < W; i++) cin >> p[i];
	for (int i = 0; i < H; i++) cin >> q[i];
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());

	lint sum = 0;
	for (int i = 0; i < W; i++) sum += (q.end() - upper_bound(q.begin(), q.end(), p[i]) + 1) * p[i];
	for (int i = 0; i < H; i++) sum += (p.end() - lower_bound(p.begin(), p.end(), q[i]) + 1) * q[i];

	cout << sum << "\n";

	return 0;
}


Measured memory_bytes: 4728
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    cout << (N-K <= 0 ? 1 : 0) << ln;
}


Measured memory_bytes: 3212
X, K, D = map(int, input().split())  # 座標X, ちょうどK回, 距離Dの移動
X = abs(X)
# 最適な回数
most_nearest_do = X//D

# K回移動しても最適な分近づけない場合はK回移動するだけ
if most_nearest_do >= K:
    X -= K*D
    print(abs(X))
    exit()
else:
    # 余る場合（Kの方が大きい場合）
    X -= most_nearest_do*D
    K -= most_nearest_do  # 余った回数が偶数なら反復横跳び
    if K % 2 == 0:
        print(abs(X))
    else:
        print(abs(X-D))


Measured memory_bytes: 61844
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;

typedef long long lli;

const int MAXN = 51;
const int NUM = MAXN*2;
int N, K;
lli x1[MAXN], y1[MAXN], z1[MAXN], x2[MAXN], y2[MAXN], z2[MAXN];
set<lli> sx, sy, sz;
map<lli, lli> mx, my, mz;
lli X[NUM], Y[NUM], Z[NUM];
lli S[NUM][NUM][NUM];

int main() {
  while(cin >> N >> K) {
    sx.clear();
    sy.clear();
    sz.clear();
    mx.clear();
    my.clear();
    mz.clear();
    for(int i = 0; i < N; ++i) {
      cin >> x1[i] >> y1[i] >> z1[i] >> x2[i] >> y2[i] >> z2[i];
      sx.insert(x1[i]);
      sx.insert(x2[i]);
      sy.insert(y1[i]);
      sy.insert(y2[i]);
      sz.insert(z1[i]);
      sz.insert(z2[i]);
    }

    {
      int cnt;
      cnt = 0;
      for(set<lli>::iterator it = sx.begin(); it != sx.end(); ++it) {
        mx[*it] = cnt;
        X[cnt++] = *it;
      }
      cnt = 0;
      for(set<lli>::iterator it = sy.begin(); it != sy.end(); ++it) {
        my[*it] = cnt;
        Y[cnt++] = *it;
      }
      cnt = 0;
      for(set<lli>::iterator it = sz.begin(); it != sz.end(); ++it) {
        mz[*it] = cnt;
        Z[cnt++] = *it;
      }
    }

    for(int i = 0; i < N; ++i) {
      x1[i] = mx[x1[i]];
      x2[i] = mx[x2[i]];
      y1[i] = my[y1[i]];
      y2[i] = my[y2[i]];
      z1[i] = mz[z1[i]];
      z2[i] = mz[z2[i]];
      /*
      cout << x1[i] << ", " << y1[i] << ", " << z1[i] << ", "
           << x2[i] << ", " << y2[i] << ", " << z2[i] << endl;
      */
    }

    fill(S[0][0], S[NUM][0], 0);
    for(int m = 0; m < N; ++m) {
      for(int k = z1[m]; k < z2[m]; ++k) {
        for(int i = y1[m]; i < y2[m]; ++i) {
          for(int j = x1[m]; j < x2[m]; ++j) {
            S[k][i][j] += 1;
          }
        }
      }
    }
    lli res = 0;
    for(int k = 0; k < sz.size(); ++k) {
      for(int i = 0; i < sy.size(); ++i) {
        for(int j = 0; j < sx.size(); ++j) {
          if(S[k][i][j] >= K) {
            res += ( X[j+1] - X[j] ) * ( Y[i+1] - Y[i] ) * ( Z[k+1] - Z[k] );
          }
        }
      }
    }
    cout << res << endl;

  }
}

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

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


int main(){

    string s;
    int q;
    cin >> s >> q;
    int re = 1;
    string l , r ;
    rep(i,q){
        int n;
        cin >> n;
        if(n==1){
            re *= -1;
        }else{
            int m;
            char c;
            cin >> m >> c;
            if(m==1){
                if(re>0){
                    l = l + c;
                }else{
                    r = r + c;
                }
            }else{
                if(re>0){
                    r = r + c;
                }else{
                    l = l + c;
                }
            }
        }
    }
    reverse(l.begin(),l.end());
    s = l + s + r;

    if(re<0){
        reverse(s.begin(), s.end());
    }
    cout << s << endl;


    return 0;
}  

Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  string t;
  std::cin >> t;
  int m=t.size();
  bool n,s,e,w;
  n=w=s=e=false;
  rep(i,m){
    if(t[i]=='N') n=true;
    else if(t[i]=='W') w=true;
    else if(t[i]=='S') s=true;
    else e=true;
  }
  if(n==s && w==e)std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';



  return 0;
}


Measured memory_bytes: 256
from fractions import gcd
a,b,c,d = map(int, input().split())
c_n = b//c - (a-1)//c
d_n = b//d - (a-1)//d
l = (c*d)//gcd(c,d)
l_n = b//l - (a-1)//l
print(b - a - c_n - d_n + l_n + 1)


Measured memory_bytes: 5048
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 1e5 + 7;

int gr[N];
int used[N];
vector<int> g[N];

int mexx(vector<int> cur) {
    if (cur.empty()) return 0;
    sort(cur.begin(), cur.end());
    if (cur.front() != 0) {
        return 0;
    }
    for (int i = 0; i + 1 < (int)cur.size(); i++) {
        if (cur[i] + 1 < cur[i + 1]) {
            return cur[i] + 1;
        }
    }
    return cur.back() + 1;
}

void dfs(int cur) {
    used[cur] = 1;
    vector<int> sons;
    for (auto t : g[cur]) {
        if (!used[t]) {
            dfs(t);
            sons.push_back(t);
        }
    }
    if (sons.empty()) {
        gr[cur] = 0;
    } else {
        for (auto t : sons) {
            gr[cur] ^= (gr[t] + 1);
        }
    }
}

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

    int n;
    cin >> n;
    for (int i = 0; i + 1 < n; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0);
    // for (int i = 0; i < n; i++) {
    //     cerr << i + 1 << ' ' << gr[i] << endl;
    // }
    if (!gr[0]) {
        cout << "Bob\n"; 
    } else {
        cout << "Alice\n";
    }
}       


Measured memory_bytes: 14336
#include<iostream>
using namespace std;
using ll = long long;

int main() {
    // get K <= 100, S
    int k; string s;
    cin >> k >> s;

    if (s.size() <= k) cout << s << endl;
    else cout << s.substr(0, k) << "..." << endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;
int main(){
	int ans,n,g=0,k=0,x;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x;
		if(x%2==0)	g++;
	}
	ans = pow(3,n)-pow(2,g);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A < B:
    if (A+V*T >= B+ W*T):
        print("YES")
    else:
        print("NO")
else:
    if (A-V*T <= B - W*T):
        print("YES")
    else:
        print("NO")

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

// bad knowhow
#define REP(i,n) for(long long i=0;i<(long long)n;++i)

struct Score {
	Score() : ac(0), pn(0) {}
	bool operator<(const Score & other) const {
		if (ac == other.ac){
			if (pn == other.pn) return id < other.id;
			return pn < other.pn;
		}
		return ac > other.ac;
	}
	int ac;
	long long pn;
	int id;
};

int g_wrong[50][10];
bool g_accept[50][10];
Score g_score[50];


int main() {
	while (true) {
		fill(g_score, g_score + 50, Score());
		fill(*g_accept, *g_accept + 500, false);
		fill(*g_wrong, *g_wrong + 500, 0);

		int t, p, r;
		cin >> t >> p >> r;
		if (t == 0) break;

		REP(i, t) g_score[i].id = i;

		REP(i, r) {
			int tid, pid, time;
			string message;
			cin >> tid >> pid >> time >> message;
			tid--; pid--;
			if (g_accept[tid][pid]) continue;
			if (message == "CORRECT") {
				g_score[tid].ac++;
				g_accept[tid][pid] = true;
				g_score[tid].pn += g_wrong[tid][pid] * 1200 + time;
			} else {
				g_wrong[tid][pid]++;
			}
		}

		sort(g_score, g_score+t);
		REP(i, t) {
			cout << g_score[i].id + 1 << " " << g_score[i].ac << " " << g_score[i].pn << endl;
		}
	}
}

Measured memory_bytes: 1220
N = int(input())
a = list(map(int,input().split()))
ans=1
check=0
for i in range(N):
    ans=ans*a[i]
    if a[i]==0:
        ans=0
        check=2
        break
    if ans>1000000000000000000:
        ans=1
        check=1
if check==1:
    ans=-1
print(ans)

Measured memory_bytes: 84492
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] d = new int[N];
        for(int i = 0; i < N; i++) d[i] = sc.nextInt();

        //餅を昇順に並び替える
        Arrays.sort(d);
      
        //同じサイズの餅があれば、一方を0（削除）とする。
        for(int i = 0; i < N - 1; i++){
            if(d[i] == d[i+1]) d[i] = 0;
        }
        //０でない餅をカウント
        int count = 0;
        for(int i = 0; i < N; i++){
            if(d[i] != 0) count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  vector<string> s;
  rep(i,n){
    string t; cin>>t;
    s.PB(t);
  }

  int ans = 0;
  rep(a,n){
    bool flg = true;
    rep(j,n){
      rep(k,n){
        if(s[(j+a)%n][k]!=s[(k+a)%n][j]) flg = false;
      }
      if(j==n-1&&flg) ans++;
    }

  }

  cout << ans*n << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
typedef int fuko[yuzu|10];
fuko a,fa;
int n=read(),m=read();
 
void init(int n){for (int i=1;i<=n;++i) fa[i]=i;}
int find(int x){return fa[x]^x?fa[x]=find(fa[x]):x;}
void mg(int u,int v){fa[find(u)]=find(v);}
 
int main(){
int i;
init(n);
for (i=1;i<=n;++i) a[i]=read();
for (i=1;i<=m;++i){
  int u=read(),v=read();
  mg(u,v);
  }
int ans=0;
for (i=1;i<=n;++i) ans+=find(a[i])==find(i);
write(ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

int n;

int main() {
    cin >> n;
    for (int id = 0; id < n; ++id) {
        vint mine(9), part(9);
        for (int i = 0; i < 9; ++i) cin >> mine[i];
        for (int i = 0; i < 9; ++i) cin >> part[i];
        sort(ALL(mine));
        int cm = 0, cp = 0, tot = 0;
        do {
            int pm = 0, pp = 0;
            for (int i = 0; i < 9; ++i) {
                if (mine[i] > part[i]) pm += mine[i] + part[i];
                else pp += mine[i] + part[i];
            }
            ++tot;
            if (pm > pp) ++cm;
            if (pm < pp) ++cp;
        } while (next_permutation(ALL(mine)));
        
        cout << fixed << setprecision(9) << (double)(cm)/tot << " " << (double)(cp)/tot << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int len,i,j;
	char s;
	while(scanf("%c",&s)!=EOF) {
		if('a'<=s && 'z'>=s){
			s=s-('a'-'A');
			printf("%c",s);
		}
		else if(s==' ' || s=='.')	printf("%c",s);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 936
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=[list(map(int,input().split())) for i in range(n)]
    l.insert(0,[0,0,0])
    ans='Yes'
    for i in range(n):
        t=l[i+1][0]-l[i][0]
        x=abs(l[i+1][1]-l[i][1])
        y=abs(l[i+1][2]-l[i][2])
        if t<x+y or t%2!=(x+y)%2:
            ans='No'
            break
    print(ans)
resolve()

Measured memory_bytes: 56412
/*
ID: yzshang1
LANG: C++11
TASK: Small Multiple
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define pf push_front
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 100010;
int vis[N];

int main() {
	int k; cin >> k;
	deque < pair < LL, int> > q;
	q.pb(mp(1, 1));
	while (!q.empty()) {
		auto u = q.front(); q.pop_front();
		if (u.first == 0) {
			cout << u.second << endl;
			return 0;
		}
		
		if (vis[u.first]) continue; vis[u.first] = true;
		q.pf(mp(u.first * 10 % k, u.second));
		q.pb(mp((u.first + 1) % k, u.second + 1));
	}
	return 0;
}


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

int main(){
  int i;
  int l=0;
  int minx=100;
  int maxx=-100;
  int miny=100;
  int maxy=-100;
  int n,m,X,Y;

  scanf("%d %d %d %d",&n,&m,&X,&Y);

  int x[n];
  int y[m];

  for(i=0; i<=n-1; i++){
    scanf("%d ",&x[i]);
  }
  for(i=0; i<=m-1; i++){
    scanf("%d ",&y[i]);
  }

  for(i=0; i<=n-1; i++){
    if(x[i]>maxx){
      maxx = x[i];
    }
  }
  for(i=0; i<=m-1; i++){
    if(y[i]<miny){
      miny = y[i];
    }
  }

  if(maxx<miny && maxx>X && miny<=Y){
    printf("No War\n");
  }else{
    printf("War\n");
  }

  return 0;
}


Measured memory_bytes: 128