akhauriyash/Code-Regression huggingface dataset:
/******************************************
* AUTHOR :kamesh_11 *
* INSTITUTION : GVPCOE *
******************************************/

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

#define ll long long
#define MOD 1000000007
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define endl '\n'
#define start_clock clock_t beginn=clock()
#define end_clock clock_t endd=clock()
#define cal_exec_time double time_spent=(double)(endd-beginn)/CLOCKS_PER_SEC
#define print_exec_time cout<<endl<<time_spent<<" secs"

int find(int arr[], int ind, int n, int dp[]){
	if(ind == n) return 0;
	if(dp[ind] != -1) return dp[ind];

	int l = INT_MAX, r = INT_MAX;
	if(ind+2 <= n)
		l = abs(arr[ind+2]-arr[ind]) + find(arr, ind+2, n, dp);
	if(ind+1 <= n)
		r = abs(arr[ind+1]-arr[ind]) + find(arr, ind+1, n, dp);

	return dp[ind] = min(l, r);
}

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin>>n;
	int arr[n+1];
	for(int i=1;i<=n;i++)
		cin>>arr[i];

	int dp[n+1];
	memset(dp, -1, sizeof(dp));
	cout<<find(arr, 1, n, dp);

	return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
int main(void){
	int A[100];
	int N,i,j,v;
	int cunt=0;
	int cunt2=0;
	
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",&A[i]);
	
	for(j=0;j<N;j++){
		for(i=N-1;i>=j+1;i--){
			if(A[i-1]>A[i]){
				v=A[i-1];
				A[i-1]=A[i];
				A[i]=v;
				cunt++;
			}
		}
	}
	for(i=0;i<N;i++){
		if(i>0)printf(" ");
		printf("%d",A[i]);
	}
	printf("\n%d\n",cunt);
	return 0;
}

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

int a[10][10];
int rem, n;
bool big(int x, int y, int r){
    bool res = true;
    if(x - 2 < 0 || x + 2 >= 10 || y - 2 < 0 || y + 2 >= 10)return false;
    for(int i = x - 2;i <= x + 2;i++)
	for(int j = y - 2;j <= y + 2;j++)
	    if(abs(x - i) + abs(y - j) <= 2){		
		a[i][j] += r;
		rem += r;
		if(a[i][j] < 0)res = false;
	    }
    if(!res)big(x, y, -r);
    return res;
}

bool small(int x, int y, int r){
    bool res = true;
    if(x - 1 < 0 || x + 1 >= 10 || y - 1 < 0 || y + 1 >= 10)return false;
    for(int i = x - 1;i <= x + 1;i++)
	for(int j = y - 1;j <= y + 1;j++)
	    if(abs(x - i) + abs(y - j) <= 1){
		a[i][j] += r;
		rem += r;
		if(a[i][j] < 0)res = false;
	    }
    if(!res)small(x, y, -r);
    return res;
}

bool middle(int x, int y, int r){
    bool res = true;
    if(x - 1 < 0 || x + 1 >= 10 || y - 1 < 0 || y + 1 >= 10)return false;
    for(int i = x - 1;i <= x + 1;i++)
	for(int j = y - 1;j <= y + 1;j++){
	    a[i][j] += r;
	    rem += r;
	    if(a[i][j] < 0)res = false;
	}
    if(!res)middle(x, y, -r);
    return res;
}

typedef pair<int, int> P;
typedef pair<P, int> T;

vector<T> ans;

bool solve(int n,int p = 0, int q = 0){
    if(rem > 13 * n)return false;
    for(int i = p;i < 10;i++){
	for(int j = 0;j < 10;j++){
	    if(i - 2 >= 0 && j - 2 >= 0 && a[i - 2][j - 2])return false;
	    if(a[i][j] == 0)continue;
	    if(big(i, j, -1)){
		ans.push_back(T(P(i, j), 3));
		if(solve(n - 1, i, j))return true;
		ans.pop_back();
		big(i, j, 1);
	    }
	    if(middle(i, j, -1)){
		ans.push_back(T(P(i, j), 2));
		if(solve(n - 1, i, j))return true;
		ans.pop_back();
		middle(i, j, 1);
	    }
	    if(small(i, j, -1)){
		ans.push_back(T(P(i, j), 1));
		if(solve(n - 1, i, j))return true;
		ans.pop_back();
		small(i, j, 1);
	    }
	}
    }
    return (n == 0);
}

int main(){
    cin >> n;
    for(int i = 0;i < 10;i++)
	for(int j = 0;j < 10;j++){
	    cin >> a[i][j];
	    rem += a[i][j];
	}
    
    solve(n);
    for(int i = 0;i < ans.size();i++){
	cout << ans[i].first.second << " "<< ans[i].first.first << " "<<ans[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
#include<string.h>
struct sai {
	int A;
};

int main(void){
    int i,len;
    char x[100];
    struct sai r[6];
    struct sai s;
    for(i=0;i<6;i++){
    	scanf("%d",&r[i].A);
    }
    
    
    
    
    scanf("%s",&x);
    len = strlen(x);
    for(i=0;i<len;i++){
    	if(x[i]=='S'){
    		s=r[0];
    		r[0]=r[4];
    		r[4]=r[5];
    		r[5]=r[1];
    		r[1]=s;
    	}else if(x[i]=='N'){
    		s=r[0];
    		r[0]=r[1];
    		r[1]=r[5];
    		r[5]=r[4];
    		r[4]=s;
    	}else if(x[i]=='W'){
    		s=r[0];
    		r[0]=r[2];
    		r[2]=r[5];
    		r[5]=r[3];
    		r[3]=s;
    	}else{
    		s=r[0];
    		r[0]=r[3];
    		r[3]=r[5];
    		r[5]=r[2];
    		r[2]=s;
    	}
    }
    printf("%d\n",r[0].A);
    
    return 0;
    }

Measured memory_bytes: 596
import sys

sys.setrecursionlimit(10**6)
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n_ = 2 * 10**5 + 20
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
    fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
    rev[i] = rev[i + 1] * (i + 1) % mod

def modinv(x, mod):
    x %= mod
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b; a, b = b, a
        u -= t * v; u, v = v, u
    return u % mod

def nCr(n, r):
    if r > n:
        return 0
    return fun[n] * rev[r] % mod * rev[n - r] % mod

n = ni()
g = [list() for _ in range(n)]
for _ in range(n-1):
    a,b = nm()
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)

sl = [1]*n
pm = [1]*n
def dfs(v, p):
    for x in g[v]:
        if x == p:
            continue
        dfs(x, v)
        sl[v] += sl[x]
        pm[v] = pm[v] * pm[x] % mod
    sv = sl[v] - 1
    for x in g[v]:
        if x == p:
            continue
        pm[v] = pm[v] * nCr(sv, sl[x]) % mod
        sv -= sl[x]
    return

def dfs2(v, p):
    pp = pm[p] *  modinv(nCr(n-1, sl[v]) * pm[v], mod) % mod
    sp = n - sl[v]
    pm[v] = pm[v] * pp % mod * nCr(n-1, sp) % mod
    for x in g[v]:
        if x == p:
            continue
        dfs2(x, v)

dfs(0, -1)
for x in g[0]:
    dfs2(x, 0)

print(*pm, sep = '\n')


Measured memory_bytes: 78968
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int> v;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a=0,b,c,d=0,e=0,f=0,g=0,i;
  string s;
  cin >>a>>b;
  c=b/2;
  if(a>c){
    d=c,b-=c*2;
  }
  else{
    d=a,b-=a*2;
    d+=b/4;
  }
  cout <<d<<'\n';
  return (0);
}


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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    vector<ll> s(n,0);
    s[0] = a[0];
    rep(i, 1, n) s[i] = a[i] + s[i-1];
    ll ans = 1e18;
    rep(i, 0, n-1){
        ans = min(ans, abs(s[i] - (s[n-1]-s[i])));
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<ll, ll>> v(n);
    rep(i, n)
    {
        cin >> v[i].second >> v[i].first;
    }
    sort(ALL(v));
    ll cur = 0;
    int ans = 0;
    rep(i, n)
    {
        if (cur + v[i].second <= v[i].first)
        {
            cur += v[i].second;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define MOD 1000000007
long int SUM(long int a,long int b){return (a%MOD+b%MOD+MOD)%MOD;}//a+b
long int PROD(long int a,long int b){return a%MOD*(b%MOD)%MOD;}//a*b
long int p[1001];
int main(){
  long int n,i,j,k;
  scanf("%ld",&n);
  for(int i=0;i<n;i++)p[i]=0;
  for(i=2;i<=n;i++){k=i;for(j=2;j*j<=k;j++)while(k%j==0){p[j]++;k/=j;}p[k]++;}
  j=1;for(i=2;i<=n;i++){j=PROD(j,p[i]+1);}
  printf("%ld",j);
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n = 3;
    VVI a(n, VI(n)), f(n, VI(n));
    REP(i,n) REP(j,n) a[i][j] = in();
    set<int> st;
    int x = in();
    REP(i,x) st.insert(in());
    REP(i,n) REP(j,n){
        if (st.count(a[i][j])) f[i][j] = 1;
    }
    REP(i,n){
        int c = 0;
        REP(j,n) c += f[i][j];
        if (c == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    REP(j,n){
        int c = 0;
        REP(i,n) c += f[i][j];
        if (c == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (f[0][0] + f[1][1] + f[2][2] == 3) cout << "Yes" << endl;
    else if (f[0][2] + f[1][1] + f[2][0] == 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

void solve(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll res = 0;
    k -= a;
    if(k <= 0){
        res += (k + a);
        cout << res << endl;
        exit(0);
    }
    else{
        res += a;
    }
    //cout << res <<endl;
    k -= b;
    if(k <= 0){
        cout << res << endl;
        exit(0); 
    }
    else{
        res += 0;
    }
    //cout << res << endl;
    k -= c;
    //cout << k << endl;
    if(k <= 0){
        res -= (k + c);
        cout << res << endl;
        exit(0); 
    }
    else{
        res += -c;
        cout << res << endl;
        exit(0);
    }
    
    
}

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

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

#define int long long

#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
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int acc[222222];

signed main(){
    int N;cin>>N;
    rep(i,N){
        int l,r;
        cin>>l>>r;
        acc[l]++;
        acc[r+1]--;
    }

    rep(i,222222-1)acc[i+1]+=acc[i];
    int ans=0;
    rep(i,222222)if(acc[i])ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1920
a,b = map(int,input().split())
if a == 1 and b == 1:
  print("Draw")
elif a == 1 and b != 1:
  print("Alice")
elif a != 1 and b == 1:
  print("Bob")
else:
  if a > b:
    print("Alice")
  elif a < b:
    print("Bob")
  else:
    print("Draw")

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	printf("%d\n",(a+b+c+d)/60);
	printf("%d\n",(a+b+c+d)%60);
	return 0;
}


Measured memory_bytes: 2148
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<iterator>
#include<string>
#include<sstream>
#include <unordered_map>
#include<cmath>
using namespace std;
#define ll long long


int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int t; t=1;
    while(t--){
       for(int i=1;i<=5;++i){
           int x; cin>>x;
           if(x==0) cout<<i<<"\n";
       }
    }    
}

Measured memory_bytes: 3648
using System;

namespace _0226
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] x = Console.ReadLine().Split();
                if (x[0] == "0" && x[1] == "0")
                {
                    break;
                }
                int h = 0;
                int b = 0;
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (x[0][i] == x[1][j])
                        {
                            if (i == j)
                            {
                                h++;
                            }
                            else
                            {
                                b++;
                            }
                        }
                    }
                }
                Console.WriteLine(h + " " + b);
            }
        }
    }
}

Measured memory_bytes: 9212
import java.util.*;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		long[] H = new long[N];
		for (int i = 0; i < N; ++i) {
			H[i] = Long.parseLong(tokens[i]);
		}

		Deque<Long> deque = new ArrayDeque<>();
		int max = 1;
		deque.addFirst(H[0]);
		for (int i = 1; i < N; ++i) {
			if (deque.getLast() >= H[i]) {
				deque.addLast(H[i]);
			} else {
				deque.clear();
				deque.addLast(H[i]);
			}
			max = Math.max(max, deque.size());
		}
		System.out.println(max - 1);
	}

}


Measured memory_bytes: 46292
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int n;
    cin >> n;
    if(n==3 || n==5 || n==7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>

using namespace std;

int N;
int A, B, C;
int min_mp;

int calc(vector<int> s, int l[]) {
  // 0 -> Aの材料
  // 1 -> Bの材料
  // 2 -> Cの材料
  // 3 -> 使わない

  int mp = 0;
  int la = 0;
  int lb = 0;
  int lc = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 0) {
      if (la != 0) {
        mp += 10;
      }
      la += l[i];
    }
    else if (s[i] == 1) {
      if (lb != 0) {
        mp += 10;
      }
      lb += l[i];
    }
    else if (s[i] == 2) {
      if (lc != 0) {
        mp += 10;
      }
      lc += l[i];
    }
  }

  if (la == 0 || lb == 0 || lc == 0) {
    return INT_MAX;
  }

  // A
  mp += abs(la - A);
  // B
  mp += abs(lb - B);
  // C
  mp += abs(lc - C);

  return mp;
}

void print_vector(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}

void dfs(int depth, vector<int> s, int l[]) {
  if (depth == N) {
    // int tmp = calc(s, l);
    // if (tmp < min_mp) {
    //   min_mp = tmp;
    //   cout << min_mp << " : ";
    //   print_vector(s);
    // }
    min_mp = min(min_mp, calc(s, l));
    return;
  }

  for (int i = 0; i < 4; i++) {
    s[depth] = i;
    dfs(depth + 1, s, l);
  }
}

int main() {
  cin >> N >> A >> B >> C;

  int l[N];
  for (int i = 0; i < N; i++) {
    cin >> l[i];
  }

  vector<int> state(N);
  min_mp = INT_MAX;

  dfs(0, state, l);

  cout << min_mp << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N, cost;

  cin >> N;

  cost = (int)(N/1.08);
  if ((int)(cost*1.08) == N) cout << cost << endl;
  else if ((int)((cost+1)*1.08) == N) cout << cost+1 << endl;
  else cout << ":(" << endl;

  return 0;
}


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

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forn(i, n) for (int i = 0; i < n; i++)
#define fin(ds) for (auto &v : ds) cin >> v;
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define nl '\n'

typedef long long ll;

signed main() { _
    int n; cin >> n;
    
    int div = 0;
    while (n >= 3) {
        n -= 3;
        div++;
    }
    
    cout << div << nl;
}


Measured memory_bytes: 256
x,y=map(int,input().split())

if x==0:
    if 0<y:
        ans=y
    else:
        ans=1+abs(y)
elif y==0:
    if 0<x:
        ans=1+x
    else:
        ans=abs(x)
else:
    if abs(x)==abs(y):
        ans=1
    elif abs(x)>abs(y):
        if x<0 and y<0:
            ans=abs(x)-abs(y)
        elif x*y<0:
            ans=1+abs(x)-abs(y)
        elif 0<x and 0<y:
            ans=2+abs(x)-abs(y)
    elif abs(x)<abs(y):
        if x<0 and y<0:
            ans=2+abs(y)-abs(x)
        elif x*y<0:
            ans=1+abs(y)-abs(x)
        elif 0<x and 0<y:
            ans=abs(y)-abs(x)

print(ans)

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

vector<pair<long long int, long long int> > factrizeRes;

void primeFactorize(long long int N) {
    
	vector<pair<long long int, long long int> > res;
    
	for (long long int a = 2; a * a <= N; a++) {
        if (N % a != 0) continue;
        long long int ex = 0;

        while (N % a == 0) {
            ex++;
            N = N/a;
        }

        factrizeRes.push_back({a, ex});
    }

    if (N != 1) factrizeRes.push_back({N, 1});
}

long long int calc(long long int a){

	int j=0;
	while(true){
		if((j+1)*j/2 <= a && a < (j+2)*(j+1)/2){
			break;
		}

		j++;
	}

	return j;

}

int main(){
    long long int N;

    cin >> N;

	primeFactorize(N);

	long long int res = 0;

	rep(i, factrizeRes.size()){
		res += calc(factrizeRes[i].second);
	}

    cout << res;

	return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  if(s.length()<4){
    cout<<"No"<<endl;
  }else if(s.substr(0,4)=="YAKI"){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 384
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.List.Split (splitOn)

main :: IO ()
main = do
  xs <- readResult []
  ys <- getc toInt
  mapM_ print $ solve xs ys

solve :: [(Int,Int)] -> [Int] -> [Int]
solve tbl qs = map (toRank db) qs
  where
    stbl = sortBy (\i j -> compare (snd j) (snd i)) tbl
    db = setRank 1 [] stbl
    
readResult :: [(Int,Int)] -> IO [(Int,Int)]
readResult acc = do
  [x,y] <- getl $ map toInt . splitOn ","
  if (x == 0 && y == 0)
    then return acc
    else readResult ((x,y) : acc)

setRank :: Int -> [(Int,Int)] -> [(Int,Int)] -> [(Int,Int)]
setRank r acc [(n1, p1)] = (n1, r) : acc
setRank r acc ((n1, p1) : (n2, p2) : xs)
  | p1 == p2 = setRank r ((n1, r) : acc) ((n2,p2) : xs)
  | otherwise = setRank (r + 1) ((n1, r) : acc) ((n2,p2) : xs)

toRank :: [(Int,Int)] -> Int -> Int
toRank db i = let Just r = lookup i db in r
    
toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  ll n, k;
  cin >> n >> k;
  ll x = n/k;
  ll ans = 0;
  ans += x * x * x;

  if (k % 2 == 0) {
    ll y = x;
    if (n % k >= k/2) y++;
    ans += y * y * y;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int A[100005];

int main()
{
    int N;

    cin >> N;

    long long sum = 0;

    A[0] = 0;
    A[N + 1] = 0;

    for (int i = 1; i <= N;i++)
    {
        cin >> A[i];
        sum += abs(A[i] - A[i - 1]);
    }
    sum += abs(A[N + 1] - A[N]);

    //cout << sum << endl;

    for (int i = 1; i <= N; i++)
    {
        cout << sum + abs(A[i + 1] - A[i - 1]) - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
N = int(input())
S = list(input())
b = S.count("#")
w = S.count(".")
ans = min(b,w)
if b>=1 and w>=1:
  cost = N-w
  for i in range(N-1, -1, -1):
    if S[i]=='.':
      cost+=1
    else: 
      cost-=1
      ans = min(ans,cost)
print(ans)

Measured memory_bytes: 4840
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

istringstream lcin;
void rl()
{
    string s;
    getline(cin, s);
    lcin = istringstream(s);
}
// build: ctrl + f9

// run: shift + f10
// debug: shift + f9
// sanitize: shift + f11

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

    ll N;
    
    cin >> N;
    map<int, vector<int>> sub;

    R1(N-1) {
        int ai;
        cin >> ai;
        sub[ai].PB(i+1);
    }

    R1(N) {
        cout << (sub.count(i+1) > 0 ? sub[i+1].size() : 0 )<< endl;
    }

}

Measured memory_bytes: 25364
#include <cstdio>
#include <algorithm>

using namespace std;

#define INF (1<<29)
#define MAX 100

int main(){
  int n,v;
  int G[MAX][MAX];

  for(int i = 0 ; i < MAX ; i++){
    for(int j = 0 ; j < MAX ; j++){
      G[i][j] = INF;
    }
  }

  scanf("%d" ,&n);

  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      G[i][j] = INF;
    }
  }
  
  int r,k,t;
  for(int i = 0 ; i < n ; i++){
    scanf("%d %d" ,&r ,&k); r--;
    while(k--){
      scanf("%d" ,&t); t--;
      G[r][t] = 1;
    }
  }

  for(int k = 0 ; k < n ; k++){
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
	G[i][j] = min(G[i][j],G[i][k]+G[k][j]);
      }
    }
  }

  int a,b,c;
  scanf("%d" ,&v);
  while(v--){
    scanf("%d %d %d" ,&a ,&b ,&c);
    a--,b--;
    if(G[a][b] == INF || G[a][b] + 1 > c){
      puts("NA");
    }else{
      printf("%d\n" ,G[a][b] + 1);
    }
  }

  return 0;
}

Measured memory_bytes: 1080
using System;
using System.Collections.Generic;
using System.Linq;

public static partial class Program
{
    public static void Main()
    {
        var abx = CRL().ArrayLongs();
        var a = abx[0];
        var b = abx[1];
        var x = abx[2];
        var count = b / x - a / x;
        if (a % x == 0)
        {
            count++;
        }

        CWL(count);
    }
}

public static partial class Program
{
    //テンプレここから
    public static int ToInt(this double d) => (int) d;
    public static long ToLong(this double d) => (long) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] {0, -1, 0, 1};
    public static long[] dy = new long[] {-1, 0, 1, 0};
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
    public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);

    public static long LCM(long a, long b) => a * b / GCD(a, b);

    //テンプレここまで
}

Measured memory_bytes: 13396
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,a[40010],b[40010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>N && N){
		rep(i,N)cin>>a[i];
		rep(i,N)cin>>b[i];
		sort(a,a+N,greater<int>());
		sort(b,b+N,greater<int>());
		int ans=-1;
		for(int i=0;i*2<N-1;i++){
			if(a[i*2] > b[i]){
				ans=i*2+1;
				break;
			}
		}
		if(ans==-1)cout<<"NA"<<endl;
		else cout<<ans<<endl;
	}
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
struct RangedFenwickTree {
  int N;
  vll bit1, bit2;
  RangedFenwickTree(int n) : N(n), bit1(n+2, 0), bit2(n+2, 0) {}
  void add(vll& bit, int i, int a) {
    assert(i > 0);
    while(i <= N) {
      bit[i] += a;
      i += (i & -i);
    }
  }
  void range_add(int l, int r, int a) {
    add(bit1, l, a);
    add(bit2, l, -a*(l-1));
    add(bit1, r+1, -a);
    add(bit2, r+1, a*r);
  }
  ll query(vll& bit, int i) {
    ll res = 0;
    while(i > 0) {
      res += bit[i];
      i -= (i & -i);
    }
    return res;
  }
  ll sum(int i) {
    return query(bit1, i) * i + query(bit2, i);
  }
};

void answer() {
  int n, k; cin >> n >> k;
  vector<int> a(n, 0), p(n, 0);
  rep(i, n) cin >> a[i];
  rep(j,k) {
    swap(p, a);
    RangedFenwickTree ft2(n);
    rep(i,n) {
      ft2.range_add(max(1, i+1-p[i]), min(n, i+1+p[i]), 1);
    }
    rep(i,n) {
      a[i] = ft2.sum(i+1) - ft2.sum(i);
    }
    bool diff = false;
    rep(i,n) {
      if(a[i] != p[i]) diff = true;
    }
    if(!diff) break;
  }
  rep(i,n) {
    if(i) cout << " ";
    cout << a[i];
  }
  cout << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 7880
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
vector <int> e[MAXN];
int N,Q,ans[MAXN],cont[MAXN] = {0};
void dfs(int node,int father_node,int sum){
	ans[node] = sum;
	for(int next_node:e[node]){
		if(next_node == father_node)
			continue;
		dfs(next_node,node,sum+cont[next_node]);
	}
	return ;
}
int main() {
	cin >> N >> Q;
	int a,b,p,x;
	for(int i = 0; i < N-1; i++){
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	for(int i = 0; i < Q; i++){
		cin >> p >> x;
		cont[p]+=x;
	}
	dfs(1,0,cont[1]);
	for(int i = 1; i <= N; i++){
		cout << ans[i];
		if(i != N)
			cout << " ";
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 24064
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    ll dp[100+1][4][4][4]; //[length][後ろから3文字前][2文字前][1文字前]
    rep0(i,3){rep0(j,3){rep0(k,3){
        if((i ==0 && j == 1 && k ==2) || (i ==1 && j == 0 && k ==2) || (i ==0 && j == 2 && k ==1)){
            dp[3][i][j][k] = 0;
        }else{
            dp[3][i][j][k] = 1;
        }
    }}}

    ll mod = 1e9 + 7;
    for(int s = 4; s <= 100;s++){
        rep0(i,3){rep0(j,3){rep0(k,3){
            dp[s][i][j][k] = 0;
            if(k == 0 || k == 3){
                rep0(l,3) dp[s][i][j][k] += dp[s-1][l][i][j]; 
            }else if(k == 1){
                if(i == 0 && j == 2);
                else rep0(l,3) dp[s][i][j][k] += dp[s-1][l][i][j];
            }else if(k == 2){
                if((i == 0 && j == 1) || (i == 1 && j == 0));
                else if(i == 1 || j == 1){
                    rep1(l,3) dp[s][i][j][k] += dp[s-1][l][i][j];
                }else{
                    rep0(l,3) dp[s][i][j][k] += dp[s-1][l][i][j];
                }
            }
            dp[s][i][j][k] %= mod;
        }}}
    }

    ll ans = 0;
    rep0(i,3){rep0(j,3){rep0(k,3){
        ans += dp[n][i][j][k] % mod;
    }}}
    ans %= mod;

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

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

using namespace std;
int n, m;
int x[55], y[55];
int xx[55], yy[55];
int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++){
		scanf("%d%d", &x[i], &y[i]);
	}
	for(int i = 1; i <= m; i ++){
		scanf("%d%d", &xx[i], &yy[i]);
	}
	for(int i = 1; i <= n; i ++){
		long long mn = 1e14;
		int id = 0;
		for(int j = 1; j <= m; j ++){
			if(id == 0 || abs(xx[j] - x[i]) + abs(yy[j] - y[i]) < mn){
				mn = abs(xx[j] - x[i]) + abs(yy[j] - y[i]);
				id = j;
			}
		} 
		printf("%d\n", id);
	}
	return 0;
}

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

struct P{
    int a, b, dist, atk;
    P(){}
    ~P(){}
    P(const P& r) : a(r.a), b(r.b), dist(r.dist), atk(r.atk) {}
    P(int a, int b, int c, int d) : a(a), b(b), dist(c), atk(d) {}
};

const int INF = 1<<29;

vector<P> G;
int dp[100][101];

void append_edge(int& a, int& b, int& c, int& d){
    G.push_back(P(a, b, c, d));
}

int N, M, L;

int main(){
    while(scanf("%d%d%d", &N, &M, &L) && (N||M||L)){
        int a, b, c, d;
        G.clear();
        for(int x = 0; x < N; x++){
            fill(dp[x], dp[x]+L+1, INF);
        }
        for(int x = 0; x < M; x++){
            scanf("%d%d%d%d", &a, &b, &c, &d);
            append_edge(--a, --b, c, d); }
        dp[0][0] = 0;
        for(int x = 0; x < N; x++){
            bool updated = false;
            for(int v = 0; v < G.size(); v++){
                int a = G[v].a, b = G[v].b,
                    dist = G[v].dist, atk = G[v].atk;
                for(int w = 0; w <= L; w++){
                    if(dp[b][w] + atk < dp[a][w]){
                        updated = true;
                        dp[a][w] = dp[b][w] + atk;
                    }
                    if(dp[a][w] + atk < dp[b][w]){
                        updated = true;
                        dp[b][w] = dp[a][w] + atk;
                    }
                    if(w >= dist){
                        if(dp[b][w-dist] < dp[a][w]){
                            updated = true;
                            dp[a][w] = dp[b][w-dist];
                        }
                        if(dp[a][w-dist] < dp[b][w]){
                            updated = true;
                            dp[b][w] = dp[a][w-dist];
                        }
                    }
                }
            }
            if(!updated) break;
        }
        int min_atk = INF;
        for(int x = 0; x <= L; x++){
            min_atk = min(min_atk, dp[N-1][x]);
        }
        printf("%d\n", min_atk);
    }
    return 0;
}

Measured memory_bytes: 1356
#include<stdio.h>

int main(void)
{
  int N,M,r,q;
  int i,j,t,flag,usePC;
  int riyou[1000][4]; /*time, PC, student, sign*/
  int ques[3];    /*start, end, student*/
  int ans;
  
  while(1){
    scanf(" %d %d",&N, &M) ;
    if(N==0 && M==0){
      break;
    }
    scanf(" %d",&r);
    for(i=0;i<r;i++){
      scanf(" %d %d %d %d"
	    , &riyou[i][0], &riyou[i][1], &riyou[i][2], &riyou[i][3]);
    }
    
    scanf(" %d",&q);

    for(i=0;i<q;i++){
      scanf(" %d %d %d"
	    , &ques[0], &ques[1], &ques[2]);
      flag = 0; usePC =0;
      j=0; 
      ans = 0;
      for(t=540;t< ques[1];t++){
	//
	if(t == ques[0])
	  flag =1;



	while(riyou[j][0] == t) {  
	  // pJn or pI¹
	  // ....
	  if(riyou[j][2] == ques[2]){
	    if(riyou[j][3] == 1){
	      usePC ++;
	    }
	    else if(riyou[j][3] ==0){
	      usePC --;
	    }
	    
	  }
	  // Ì j
	  j ++;
	}
	// ¦Ôð1ªÇÁ
	if(usePC>0 && flag ==1){
	  ans ++;
	}

      }
      printf("%d\n",ans); 
    }
    
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
	int n,i,j,k,cnt=0;
	int a[2010]={};
	int sjx(int a,int b,int c);
	while(~scanf("%d",&n)){
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}for(i=0;i<n-2;i++){
			for(j=i+1;j<n-1;j++){
				for(k=j+1;k<n;k++){
					if(sjx(a[i],a[j],a[k])){
						cnt++;
					}
				}
			}
		}printf("%d\n",cnt);
		cnt=0;
	}
}
int sjx(int a,int b,int c){
	int leapa=0,leapb=0,leapc=0;
	if(a<b+c){
		leapa=1;
	}if(leapa==1&&b<a+c){
		leapb=1;
	}if(leapb==1&&c<a+b){
		leapc=1;
	}
	if(leapa==1&&leapb==1&&leapc==1){
		return 1;
	}else{
		return 0;
	}leapa=0;leapb=0;leapc=0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail)
{
  cout << head;
  if (sizeof...(tail) != 0)
    cout << " ";
  print(forward<Tail>(tail)...);
}

int main()
{
  int n;
  cin >> n;
  print(n == 1 ? 0 : 1);
  return 0;
}

Measured memory_bytes: 3556
a,b=map(int,input().split())
s=input()
frag='Yes'

if len(s)!=a+b+1:
  frag='No'
else:
  if s[a]!='-':
    frag='No'
  elif s[:a].isdecimal()==False:
    frag='No'
  elif s[a+1:].isdecimal()==False:
    frag='No'
    
print(frag)
  


Measured memory_bytes: 38256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize,
        s: chars
    }
    let mut ans = 0;
    for i in 0..n - 1 {
        if s[i] == s[i + 1] {
            ans += 1;
        }
    }
    println!("{}", min(ans + 2 * k, n - 1));
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main()
{

    int n, ans;
    cin>>n;
    if(n%1000 != 0)
    {
        ans=((n/1000)+1)*1000-n; cout<<ans<<"\n";
    }
    else
    cout<<"0"<<"\n";



    return 0;

}


Measured memory_bytes: 3624
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String n = sc.next();

		int t = 0;

		for ( int i=0; i<n.length(); i++ ) {
			t += n.charAt(i) - '0';
		}

		if ( t%9==0 ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 40236
#include <iostream>
#include <queue>

int d[110];

int main() {
  int n;
  std::cin >> n;
  int G[110][110];
  for(int i=0; i<n; ++i) {
    for(int j=0; j<n; ++j) G[i][j] = 0;
  }

  for(int i=0; i<n; ++i) {
    d[i] = -1;
  }

  for(int i=0; i<n; ++i) {
    int u, k;
    std::cin >> u >> k;
    u--;
    for(int j=0; j<k; ++j) {
      int v;
      std::cin >> v;
      v--;
      G[u][v] = 1;
    }
  }

  std::queue<int> que;
  que.push(0);
  int dist = 0;
  d[0] = 0;

  while(!que.empty()) {
    // キューから一番最初を取り出す
    int u = que.front();
    que.pop();

    for(int v=0; v<n; ++v) {
      if(G[u][v] == 1 && d[v] == -1) {
        que.push(v);
        d[v] = d[u]+1;
      }
    }
  }

  for(int i=0; i<n; ++i) {
    std::cout << i+1 << " " << d[i] << std::endl;
  }
}


Measured memory_bytes: 3124
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] iArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long[] val = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            //種類
            long N = iArray[0];
            //個数
            long M = iArray[1];
            List<long> list = new List<long>();
            for (long i = 0; i < N; i++)
            {
                //票数
                list.Add(val[i]);
            }
            long sum = val.Sum();
            List<long> vs = new List<long>();

            for (int p = 0; p < N; p++)
            {
                //合計/(4*M)以上のものをリストに加える
                if ((decimal)list[p] >= sum / (decimal)(4 * M))
                {
                    vs.Add(list[p]);
                }
            }
            if (vs.Count() >= M)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");

            }
        }
    }
}

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

int n,x,y;

int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&x);
        y = y^x;
    }
    if(y!=0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
#define dd double
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	if (n >= 13) {
		cout << m << endl;
	}
	else if (n >= 6 && n <= 12) {
		cout << m / 2 << endl;
	}
	else {
		cout << "0" << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  static long MOD = (long)Math.pow(10, 9) + 7;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] kaijou = new long[n + 2];
    kaijou[0] = 1;
    for(int i = 1; i < n + 2; i++) {
      kaijou[i] = (kaijou[i - 1] * (long)i) % MOD;
    }
    int[] suuretu = new int[n + 1];
    long[] aho = new long[n + 1];
    for(int i = 0; i < n + 1; i++) {
      long a = sc.nextLong();
      aho[i] = a;
      suuretu[(int)a]++;
    }
    long u = 0;
    for(int i = 0; i < n + 1; i++) {
      if(suuretu[i] == 2) u = i;
    }
    int index = 0;
    int index2 = 0;
    boolean flg = true;
    for(int i = 0; i < n + 1; i++) {
      if(aho[i] == u) {
        if(flg) {
          flg = false;
          index = i;
        } else {
          index2 = i;
        }
      }
    }
    long unko = (long)(index + n - index2);
    long[] dp = new long[(int)(unko + 1)];
    long[] dp2 = new long[n + 2];
    for(int k = 0; k < unko + 1; k++) {
      long inv = func(kaijou[k], MOD - 2);
      long inv2 = func(kaijou[(int)unko - k], MOD - 2);
      long ret = (kaijou[(int)unko] * inv) % MOD;
      ret = (ret * inv2) % MOD;
      dp[k] = ret;
    }
    for(int k = 0; k < n + 2; k++) {
      long inv = func(kaijou[k], MOD - 2);
      long inv2 = func(kaijou[n + 1 - k], MOD - 2);
      long ret = (kaijou[n + 1] * inv) % MOD;
      ret = (ret * inv2) % MOD;
      dp2[k] = ret;
    }
    for(int k = 1; k <= n + 1; k++) {
      long ans = dp2[k];
      if(k >= 1) {
        if(k - 1 < (int)(unko + 1)) {
          if(ans >= dp[k - 1]) {
            ans -= dp[k - 1];
          } else {
            ans = (ans + MOD - dp[k - 1]) % MOD;
          }
        }
      }
      System.out.println(ans);
    }
  }

  public static long func(long a, long x) {
    if(x == 0) return 1;
    long t = func(a, x / 2);
    long ret = (t * t) % MOD;
    if(x % 2 == 1) ret = (ret * a) % MOD;
    return ret;
  }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(void) {
	long long n, q;
	string s;
	cin >> n >> s >> q;
	vector<long long> v(q), m(n), c(n), mc(n);
	REP(i, q) cin >> v[i];
	m[0] = s[0] == 'M' ? 1 : 0;
	c[0] = s[0] == 'C' ? 1 : 0;
	mc[0] = 0;
	FOR(i, 1, n) {
		m[i] = s[i] == 'M' ? m[i - 1] + 1 : m[i - 1];
		c[i] = s[i] == 'C' ? c[i - 1] + 1 : c[i - 1];
		mc[i] = s[i] == 'C' ? mc[i - 1] + m[i - 1] : mc[i - 1];
	}
	for(long long k: v){
		long long res = 0;
		REP(i, n) {
			if (s[i] == 'D') {
				int j = min(i + k - 1, n - 1);
				res += mc[j] - mc[i];
				res -= m[i] * (c[j] - c[i]);
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 200005
#define MOD 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi 3.14159265358979323846
#define Q ll _; cin >> _; while(_--)
#define endl "\n"
#define flush fflush(stdout);

int main(){

    fast;

    ll i,n;
    cin >> n;
    ll maxa = 0;
    ll ans = 0;
    for(i=0;i<n;i++){
        ll a1;
        cin >> a1;
        if(a1>=maxa){
            maxa = a1;
        }
        else{
            ans+=(maxa-a1);
        }
    }
    cout << ans << endl;

}

//    cout << fixed << setprecision(12);


Measured memory_bytes: 3612