akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stack>
using namespace std;
int tu[1000][1000];
int a[10000];
int an[10000];
int d[10000];
int f[10000];
int shijian,n;
int next(int q){
for(int i=an[q];i<n;i++){
    an[q]=i+1;
    if(tu[q][i])return i;
}
return -1;
}
void sou(int u){
     stack<int > s;
     s.push(u);
     a[u]=2;
     d[u]=++shijian;
     while(!s.empty()){
        int x=s.top();
        int v=next(x);
        if(v!=-1){
            if(a[v]==1){
                a[v]=2;
                d[v]=++shijian;
                s.push(v);
            }
        }
        else {
            s.pop();
            a[x]=3;
            f[x]=++shijian;
        }
     }
}
void shensou(){
     for(int u=0;u<n;u++){
        a[u]=1;
        an[u]=0;
     }
     shijian=0;
     for(int u=0;u<n;u++){
        if(a[u]==1)sou(u);
     }
     for(int u=0;u<n;u++){
         printf("%d %d %d\n",u+1,d[u],f[u]);
     }
}


int main(){
   int v;
   int m;
   int x;
   scanf("%d",&n);
   for(int i=0;i<n;i++){
        scanf("%d%d",&v,&m);
        v--;
        for(int j=0;j<m;j++){
            scanf("%d",&x);
            x--;
            tu[v][x]=1;
        }
   }
   shensou();
return 0;
}

Measured memory_bytes: 3028
/*
AizuOnline A0061
Title Rank Cheker
*/
#include <stdio.h>
// Select Below
#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int N;
struct nmpt {int name ;
  int point;} table[100];
int nm,pt;
//
int junni(int nm)
{
  int i,j,prev;

  prev=0;j=0;
  for(i=0;i<N;i++)
    {
      if(table[i].point != prev)
	j++;
      if(table[i].name ==nm)
	return(j);
      prev = table[i].point;
    }
  return(-1);
}
int comp(void * x,void * y)
{
  return(((struct nmpt *)y)->point - ((struct nmpt *)x)->point);
}
main()
{
  int i;

  i=0;

  while(scanf("%d,%d",&nm,&pt) && (nm || pt))
    {
      table[i].name=nm;
      table[i].point=pt;
      i++;
    }
  N=i;
  qsort(table,N,sizeof(table[0]),(__compar_fn_t)comp);
  while(EOF != scanf("%d",&nm))
    {
      printf("%d\n",junni(nm));
    }
 
return(0);
}

Measured memory_bytes: 600
#include<stdio.h>
#define N 101
int min(int a,int b){
  if(a<b)return a;
  else return b;
}
int main(){
  int n,p[N],m[N][N],i,j,l,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf(" %d %d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++)m[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l -1;
      m[i][j] = (1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j] = min(m[i][j],m[i][k] +m[k+1][j] + p[i-1] * p[k] * p[j]);
      }
    }
}

printf("%d\n",m[1][n]);

return 0;
}



Measured memory_bytes: 2048
#include<stdio.h>

int main(void){
  int n,r;
  scanf("%d%d",&n,&r);
  
  int x;
  
  if(n>=10){
    x=r;
  }else{
    x=100*(10-n)+r;
  }
  
  printf("%d",x);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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 main(){
    double n, d; cin >> n >> d;
    int ans = ceil(n/(2*d+1));
    cout << ans << endl;
}

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

using namespace std ;

#define N 5010
#define ll long long
const int mod = 1e9+7 ;

int n ;
char s[ N ] ;
int f[ N ][ N ] ;
//f[ i ][ j ] 表示按了i次键盘，出现了j个字母 

ll power( ll a , ll b ) {
	ll ans = 1 , base = a ;
	while( b ) {
		if( b&1 ) ans = ( ans * base ) % mod ;
		base = ( base * base ) % mod ;
		b >>= 1 ;
	}
	return ans % mod ;
}

int main() {
	scanf( "%d%s" , &n , s+1 ) ;
	int len = strlen( s + 1 ) ;
	f[ 0 ][ 0 ] = 1 ;
	for( int i = 0 ; i <= n ; i ++  ) {
		for( int j = 0 ; j <= i ; j ++ ) {
			f[ i + 1 ][ j + 1 ] += 2 * f[ i ][ j ] ;
			f[ i + 1 ][ j + 1 ] %= mod ;
			f[ i + 1 ][ max( j - 1 , 0 ) ] += f[ i ][ j ] ;
			f[ i + 1 ][ max( j - 1 , 0 ) ] %= mod ;
		}
	}
	ll ans =1ll*power( power( 2 , len ) , mod - 2 ) % mod * f[ n ][ len ] ;
	ans %= mod ;
	printf( "%lld" , ans ) ;
	return 0 ;
} 

Measured memory_bytes: 96512
#include<bits/stdc++.h>
#define ll          long long
#define dl          double
#define pb          push_back
#define eb          emplace_back
#define mp          make_pair
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(i=a;i<b;i++)
#define all(v)      v.begin(),v.end()
#define allr(v)     v.rbegin(),v.rend()
#define mod         1e9+7
#define CIN(V,s,n)  for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n) for(int i=s;i<n;i++){cout <<  V[i] << " ";}
#define SbS         sortbysec
#define fast        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);   for(ll i=0;i<V.size();i++) V[i] = 0;

// map<ll,vector<ll> > M;
// map<ll,vector<ll> >:: iterator it;
// it = M.begin();
// it.F will be ll
// it.S will be vector<ll>

using namespace std;

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}

int main()
{
ll t=1;
//cin >> t;
while(t--)
{
    ll n,m,i,j,k,h,l1,l2,w,q=1,u,v,d,temp=0,cn=0,cp=0,c0=0,max1=0;
    string s;
    cin >> s;
    ll flag=1;
    for(i=0;i<3;i++)
    {
        if(s[i]==s[i+1])
        {

            flag=0;
            break;
        }
    }
    if(flag)
    {
        cout << "Good";
    }
    else
        cout << "Bad";

}
    return 0;
}


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

signed main() {
  int N;
  cin >> N;
  
  map<int, int> kazu;
  int A;
  for( int i = 0; i < N; i++ ){
    cin >> A;
    if( kazu.count(A) ) kazu.at(A)++;
    else kazu[A] = 1;
  }
  
  int ans = 0;
  for( auto p : kazu ){
    auto k = p.first;
    auto v = p.second;
    if( k < v ) ans += (v - k);
    else if( k > v ) ans += v;
  }
    
  cout << ans << endl;
  
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> x(n);
	rep(i,n)cin>>x[i];
	int m;
	cin>>m;
	vector<int> a(m);
	rep(i,m)cin>>a[i];

	vector<int> s(2020,-1);
	rep(i,n) s[x[i]] = i;
	rep(i,m){
		int koma = x[a[i]-1];
		if(s[koma+1]== -1){
			s[koma]=-1;
			s[koma+1]=a[i]-1;
			x[a[i]-1]++;
		}
	}
	rep(i,n)cout<<x[i]<<endl;

	return 0;
}


Measured memory_bytes: 3116
N, *A = map(int, open(0).read().split())

tot = 0
xor = 0
right = 0
ans = 0
for left in range(N):
    while right < N and tot + A[right] == xor ^ A[right]:
        tot += A[right]
        xor ^= A[right]
        right += 1

    ans += right - left

    if left == right:
        right += 1
    else:
        tot -= A[left]
        xor ^= A[left]
print(ans)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)




int main() {
    FASTIO;
    int n;
    cin >> n;
    vector<int> p(n);

    vi cnt(n, 0);
    rep(i, n) {
        cin >> p[i];
        --p[i];
        if (i == p[i]) {
            cnt[i]++;
        }
    }


    int ans = 0;
    rep(i, n - 1) {
        if (!cnt[i]) continue;
        if (cnt[i + 1]) {
            ++ans;
            cnt[i + 1] = 0;
            cnt[i] = 0;
        }
    }

    rep(i, n) {
        if (cnt[i]) ++ans;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int ans =-1;
		int l = s.length();
		while(ans == -1) {
			l--;
			if(l%2==0&&s.substring(0, l/2-1).equals(s.substring(l/2, l-1))) {
				ans = l;
				break;
			}
		}
		System.out.println(ans);
	 }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << (double)w*h/2 << " ";
  cout << (2*x==w&&2*y==h) << endl;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

ll mod = 998244353 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,s ;
	cin >> n >> s ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	vvll dp(n+1,vll(3001,0)) ;
	for(int i=1;i<=n;i++){
		dp.at(i).at(0) = i ;
		dp.at(i).at(a.at(i-1)) = 1 ;
		for(int j=1;j<=s;j++){
			dp.at(i).at(j) += dp.at(i-1).at(j) ;
			if(a.at(i-1)<=j) dp.at(i).at(j) += dp.at(i-1).at(j-a.at(i-1)) ;
			dp.at(i).at(j) %= mod ;
		}
	}
	ll ans = 0 ;
	for(int i=1;i<=n;i++) ans = (ans+dp.at(i).at(s))%mod ;
	cout << ans << endl ;
}


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

using ll = long long;

int main() {
    ll N, M, A, B;
    cin >> N >> M;
    vector<vector<ll>> C(100000, vector<ll>(0));
    rep(i, N) {
        cin >> A >> B;
        C[A - 1].push_back(B);
    }
    //rep(i, M) rep(j, C[i].size()) cout << i << j << C[i][j] << endl;
    priority_queue<ll> p;
    ll ans = 0;
    rep(i, M) {
        rep(j, C[i].size()) {
            p.push(C[i][j]);
        }
        if (p.empty()) continue;

        ans += p.top();
        //cout << i << " " << ans << endl;
        p.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

signed main(void)
{
  int t;
  cin >> t;
  REP(i, t) {
    int n, d;
    cin >> n >> d;
    int now = d, ret = 0;
    REP(j, n-1) {
      ret += 127;
      now ^= 127;
    }
    ret += now;
    cout << ret << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
struct edge{
	int to,cost;
};

int main() {
	int n;
	ll a,b,c,d;

	cin>>n>>a>>b>>c>>d;
	ll ab=abs(a-b);
	bool flg=false;
	n--;
	for(int i=0;i<=n/2;++i){
		if(ab<=((n-i)*d-i*c)&&ab>=((n-i)*c-i*d))flg=true;
	}
	if(flg){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, t;
    int times;
    int count = 0;
    cin >> a >> b >> t;
    times = (t + 0.5) / a;
    count = times * b;

    cout << count << '\n';

    return 0;
}


Measured memory_bytes: 892
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

diff = [A[i] - B[i] for i in range(N)]
if sum(diff) < 0:
    print(-1)
    exit(0)

minus = [diff[i] for i in range(N) if diff[i] < 0]
plus = [diff[i] for i in range(N) if diff[i] > 0]
plus.sort(reverse=True)
ans = len(minus)
minus_s = sum(minus)*(-1)
id = 0
while(minus_s > 0):
    minus_s -= plus[id]
    id += 1
print(ans+id)


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

const int MOD = int(1e9)+7;

const int MAXN = 400;
const int MAXM = 400;
int N, M;
vector<int> constraints[MAXN][4];
int dp[MAXN][MAXN][MAXN]; // decreasing

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int l, r, x; cin >> l >> r >> x;
		constraints[r][x].push_back(l);
	}
	for (int r = 1; r <= N; r++) {
		for (int x = 1; x <= 3; x++) {
			sort(constraints[r][x].begin(), constraints[r][x].end());
		}
	}
	dp[0][0][0] = 1;
	int ans = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= j; k++) {
				if (!constraints[i][1].empty() && j >= constraints[i][1].front()) {
					continue;
				}
				if (!constraints[i][2].empty() && j < constraints[i][2].back()) {
					continue;
				}
				if (!constraints[i][2].empty() && k >= constraints[i][2].front()) {
					continue;
				}
				if (!constraints[i][3].empty() && k < constraints[i][3].back()) {
					continue;
				}

				if (i == N) {
					ans += dp[i][j][k];
					if (ans >= MOD) ans -= MOD;
				} else {
					dp[i+1][j][k] += dp[i][j][k];
					if (dp[i+1][j][k] >= MOD) dp[i+1][j][k] -= MOD;
					dp[i+1][i][k] += dp[i][j][k];
					if (dp[i+1][i][k] >= MOD) dp[i+1][i][k] -= MOD;
					dp[i+1][i][j] += dp[i][j][k];
					if (dp[i+1][i][j] >= MOD) dp[i+1][i][j] -= MOD;
				}
			}
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 186880
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,k=map(int, readline().rstrip().split())
    arr=list(map(int, readline().rstrip().split()))
    
    score=1
    for i in range(n):
        #score*=arr[i]
        if (i+1) > k:
            #score = score//arr[i-k]
            if arr[i] > arr[i-k]:
                print("Yes")
            else:
                print("No")
        #bef=score

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 39356
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  rep(i,h)cin>>s[i];
  rep(i,w+2)cout<<"#";
  cout<<endl;
  rep(i,h){
    cout<<"#";
    cout<<s[i];
    cout<<"#"<<endl;
  }
  rep(i,w+2)cout<<"#";
  cout<<endl;



}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative

data Op = S | E | N | W deriving (Show, Eq, Enum)

fromChar c | c == 'S' = S
           | c == 'E' = E
           | c == 'N' = N
           | c == 'W' = W
           | otherwise = error $ "Invalid char " ++ [c]

fromString [] = []
fromString (x:xs) = (fromChar x):(fromString xs)

data Dice = Dice { top :: Int, front :: Int, right :: Int, left :: Int, back :: Int, bottom :: Int }
  deriving (Show, Eq)

makeDice [t, f, r, l, ba, bo] = Dice t f r l ba bo

roll (Dice t f r l ba bo) S = Dice ba t r l bo f
roll (Dice t f r l ba bo) N = Dice f bo r l t ba
roll (Dice t f r l ba bo) E = Dice l f t bo ba r
roll (Dice t f r l ba bo) W = Dice r f bo t ba l
rolls = foldl roll

guessRight :: Int -> Int -> Dice -> Int
guessRight t f dice = right . head . filter (\x -> front x == f) $ scanl rolls d [[N, E, S], [N, E, S], [N, E, S]]
  where d = head . filter (\x -> top x == t) $ scanl roll dice [N, E, N, E, N]

solve :: [Int] -> [Int] -> Int
solve lbls [t,f] = guessRight t f $ makeDice lbls

main = do
  labels <- map read . words <$> getLine :: IO [Int]
  n <- readLn :: IO Int
  xs <- map (map read . words) <$> replicateM n getLine :: IO [[Int]]
  mapM_ (print . solve labels) xs




Measured memory_bytes: 4072
#include<iostream>
#include<cmath>

using namespace std;
void s(int x)
{
	
}
int main()
{
int n;
int a[100001],f[100001],w[100001];
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
f[0]=0;
a[0]=0;
a[n+1]=0;
for(int i=1;i<=n+1;i++)
{
	f[i]=f[i-1]+abs(a[i]-a[i-1]);
	if(i<=n) w[i]=abs(a[i+1]-a[i-1]);
}

for(int i=1;i<=n;i++)
{
	int ans=f[i-1]+w[i]+f[n+1]-f[i+1];
	cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 2432
#include<cstdio>
#include<cstring>
const int MAXN = 100000;
const int MAXK = 1000;
int x[MAXN + 5], y[MAXN + 5], c[MAXN + 5];
int y1[10 * MAXK + 5];
int main() 
{
	int N,K,Max=0,cnt = 0;
	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;i++) 
	{
		char ch;
		scanf("%d%d %c",&x[i],&y[i],&ch);
		x[i]= x[i] % (2*K);
		y[i]= y[i] % (2*K);
		if(ch=='W' ) c[i] = 1;
		else c[i]=0;
	}
	for(int i=0;i<=K;i++) {
		cnt = 0;
		memset(y1,0,sizeof(y1));
		for(int j=1;j<=N;j++) {
			bool p = ( i <= x[j] && x[j] < i+K );
			bool q = ( 0 <= y[j] && y[j] < K );
			if( p ^ q == c[j] )
			{
				cnt++;
				y1[y[j]] ++;
			}
			else 
			{
				y1[y[j]] --;
			}
		}
		for(int j=0;j<=K;j++) 
		{
			if(cnt>Max) 
				Max = cnt;
			if(N-cnt>Max ) 
				Max=N-cnt;
			if( j != K )
				cnt = cnt - y1[j] - y1[K+j];
		}
	}
	printf("%d\n",Max);
}


Measured memory_bytes: 1408
n = gets.to_i
p = gets.split.map {|x| x.to_i}

i = 1
sum = 0
while i < n - 1
  if (p[i-1] < p[i] and p[i] < p[i+1]) or
    (p[i+1] < p[i] and p[i] < p[i-1])
    sum += 1
  end
  i+=1
end
puts sum




Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		for(int i=0;i<N;i++) A[i]--;
		int tot = B.Sum();
		for(int i=0;i<N-1;i++){
			if(A[i] + 1 == A[i+1]){
				tot += C[A[i]];
			}
		}
		Console.WriteLine(tot);
		
		
	}
	int N;
	int[] A,B,C;
	public Sol(){
		N = ri();
		A = ria();
		B = ria();
		C = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> v(n+1);
	for(int i=1;i<=n;i++)
		cin>>v[i];
	vector<int> cnt(n+1,0);
	for(int i=n;i>0;i--){
		int sol=0;
		for(int j=2;i*j<=n;j++)
			sol+=cnt[i*j];
		if(sol%2 != v[i])
			cnt[i]++;
	}
	vector<int> res;
	for(int i=1;i<=n;i++)
		if(cnt[i]==1)
			res.push_back(i);
	cout<<res.size()<<endl;
	for(auto x:res) cout<<x<<" ";
}

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

int main()
{
    string s;
    cin >> s;

    string answer;

    rep(i, s.size())
    {
        if (s.at(i) == 'B')
        {
            if (answer.size() > 0)
                answer.pop_back();
        }
        else
        {
            answer += s.at(i);
        }
    }

    cout << answer << endl;
}

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

#define ll long long
#define mx 100005

int main()
{



    int k,x,m;
    scanf("%d %d",&k,&x);

    m=x-k+1;

    for(int i=k-1;i>0;i--)
    {
       printf("%d ",m++);
    }
    printf("%d",x);
    m=x;
    for(int i=k-1;i>0;i--)
    {
       printf(" %d",++m);
    }

    printf("\n");

    return 0;
}



Measured memory_bytes: 256
x1, y1, x2, y2 = map(int,input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)

print(x3, y3, x4, y4)


Measured memory_bytes: 2940
def draw_frame(h, w):
	print("#" * w)
	print(("#" + "." * (w - 2) + "#\n") * (h - 2), end="")
	print("#" * w + "\n")

while True:
	H, W = map(int, input().split())
	if H == W == 0: break
	draw_frame(H, W)

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int flag=0;
  for(int i=0;i<N;i++){
    if(flag==0){
      if(S.at(i)=='C'){
        flag=1;
      }
    }else if(flag==1){
      if(S.at(i)=='F'){
        flag=2;
      }
    }
  }
  if(flag==2){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n, m, l[MAXN], r[MAXN], d[MAXN], p[MAXN];

vector<pii> g[MAXN];
bool vis[MAXN];

void dfs(int x, int pos){
	if(vis[x]) return;
	vis[x] = true;
	p[x] = pos;
	for(auto i : g[x]){
		dfs(i.first, i.second + pos);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
    	cin >> l[i] >> r[i] >> d[i];
    	l[i]--;
    	r[i]--;
    	g[l[i]].pb({r[i], d[i]});
    	g[r[i]].pb({l[i], -d[i]});
    }
    for(int i = 0; i < n; i++)
    	dfs(i, 0);
    for(int i = 0; i < m; i++){
    	if(p[r[i]] - p[l[i]] != d[i]){
    		cout << "No";
    		return 0;
    	}
    }
    cout << "Yes";
}

Measured memory_bytes: 16256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];
void maxHeapify(int i){
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  if (l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if (r <= H && A[r] > A[largest]) largest = r;

  if (i != largest){
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if (H < 1) return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  if (key < A[i]) return;
  A[i] = key;
  while (i > 1 && A[i] > A[i/2]){
    swap(A[i], A[i/2]);
    i = i / 2;
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

int main(){
  int i, key;
  char com[10];

  while(1){
    scanf("%s", com);
    if (com[0] == 'e' && com[1] == 'n') break;
    if (com[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    } else {
      printf("%d\n", extract());
    }
  }

  return 0;
}



Measured memory_bytes: 6624
#include <stdio.h>
int main()
{
  int n,i,j=0,k=0;
  scanf("%d",&n);
  int ar[n];
  for(i=0;i<n;i++)
  {
    scanf("%d",&ar[i]);
  }
  for(i=0;i<n;i++)
  {
   if((ar[i])==(i+1))
   {
     j++;
   } 
   else if((ar[i])!=(i+1))
   {
     k++;
   }
  }
  if(j==n)
  {
    printf("YES\n");
   }
  else if(k<=2)
  {
    printf("YES\n");
  }
  else
  {
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 1628
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  int N = input();
  string S = input<string>();
  string T = input<string>();

  string ret = "";
  for(int i=0;i<N;i++){
    char s1 = S[i];
    ret += s1;
    char t1 = T[i];
    ret += t1;
  }

  output(ret);

  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
/*
caba
abc
  
 */

public class Main {

	public static Set<Integer>[] g;
	public static boolean[] vis;
	public static int max;
	public static int lo;
	
    @SuppressWarnings("unchecked")
	public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        
        int n = sc.nextInt(), m = sc.nextInt();
        n++;
        g = new HashSet[n];
        vis = new boolean[n];
        for(int i=0;i<n;i++) {
        	g[i] = new HashSet<>();
        }
        max=0;
        while(m-->0) {
        	int a = sc.nextInt();
        	int b = sc.nextInt();
        	g[a].add(b);
        	g[b].add(a);
        }
        for(int i=1;i<n;i++) {
        	lo=0;
        	if(!vis[i]) {
        		dfs(i);
        	}
        	if(max<lo)
        		max=lo;
        }
        pw.print(max);
        
        
        pw.close();
    }
    
    public static void dfs(int s) {
    	lo++;
    	vis[s] = true;
    	for(Integer e:g[s]) {
    		if(!vis[e]) {
    			dfs(e);
    		}
    	}
    }
    
    
    
    
   
   static <T> void deb(T x){
       System.out.println(x);
   }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
}

Measured memory_bytes: 117612
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    L, R, d = readnums()
    ans = (R - L) // d
    if not L % d:
        ans += 1
    elif not R % d:
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9048
#include <stdio.h>

int main()
{
    int n, i;
    long long int power;
    scanf("%d", &n);
    power = 1;
    for (i=1; i<=n; i++)
    {
        power = power * i % (1000000007);
    }
    printf("%lld\n", power);
    return 0;
}


Measured memory_bytes: 128
//
// Created by Takaaki Hirano on 2018/09/01.
//
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
typedef long long ll;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)


int N, K;

void solve() {
    unordered_map<ll, ll> mp;
    rep(i, N) mp[(i + 1) % K]++;
    ll ans = 0;
    each(a, mp) {
        ll b = (K - a.first) % K;
        ll c = (K - a.first) % K;
        if ((b + c) % K == 0) ans += a.second * mp[b] * mp[c];
    }

    printf("%lli\n", ans);
}

int main() {
    cin >> N >> K;
    solve();
    return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int N, L;
    cin >> N >> L;
    string s[N];
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }
  
    sort(s, s+N);

	for(int i = 0; i < N; i++){
        cout << s[i];
    }
}

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

using namespace std;

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n%2)
        cout << "No\n";
    else{
        int flag=0;
        for(int i=0;i<n/2;i++){
            if(s[i]!=s[i+n/2])
                flag=1;
        }
        if(flag)
            cout << "No\n";
        else
            cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    string s;cin>>s;
    set<char>c;
    rep(i,s.size()){
        c.insert(s.at(i));
    }
    if(c.count('a') && c.count('b') && c.count('c')){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

int main()
{
  long long n;
  cin >> n;
  for(int i = (int)sqrt(n); i >= 1; --i)
  {
    if(!(n % i)) {
      cout << (i+n/i-2) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#include <iomanip>
#define rep(i,N) for(ll i=0;i<N;i++)
#define disp(a) cout << a << endl;
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(20) << ** << endl;
typedef long long ll;
using namespace std;

double deg2rad(double degree)
{
    return degree * PI / 180.0000000000;
}
int main()
{
	ll M,D,m,d;
	cin>>M>>D>>m>>d;
	if(M!=m){
		cout<<"1"<<endl;
	}
	else{
		cout<<"0"<<endl;
	}
}

Measured memory_bytes: 256
import math


def seachPrimeNum(N):
    max = int(math.sqrt(N))
    seachList = [i for i in range(2, N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum


def isPrime(n, prime_numbers):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    m = math.floor(math.sqrt(n))
    for p in prime_numbers:
        if n % p == 0:
            return False
        if p > m:
            # 素数がnの平方根を超えたら終了
            break
    return True


def main():
    A = int(input())
    primeNum = seachPrimeNum(A)
    while True:
        if isPrime(A, primeNum) is True:
            print(A)
            break
        A += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 47792
a,b=gets.chomp.split(" ").map(&:to_i)
count=0
(a..b).each do |number|
  numberArray = number.to_s.split("")
  leftNumbers = numberArray.slice(0,2)
  rightNumbers = numberArray.slice(3,2)
  rightNumbers = [rightNumbers[1],rightNumbers[0]]
  count +=1 if leftNumbers.join.to_s == rightNumbers.join.to_s
end
puts count

Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
priority_queue < int > q;
const int maxn = 1e5 + 10;
int a[maxn];
int main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d", &x);
		q.push(x);
	}
	while(m--){
		int x = q.top();
		q.pop();
		q.push(x / 2);
	}
	long long ans = 0;
	while(q.size()){
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define int long long
//BEGIN CUT HERE
struct LowestCommonAncestor{
  const int MAX_LOG_V = 50;
  
  vector<vector<int> > G,parent;
  int root=0,V;
  vector<int> depth;
  LowestCommonAncestor(){}
  LowestCommonAncestor(int V):V(V){init();}

  void init(){
    for(int i=0;i<(int)G.size();i++) G[i].clear();
    G.clear();
    for(int i=0;i<(int)parent.size();i++) parent[i].clear();
    parent.clear();
    depth.clear();
    G.resize(V);
    parent.resize(MAX_LOG_V,vector<int>(V));
    depth.resize(V);
  }

  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }
  
  void dfs(int v,int p,int d){
    parent[0][v]=p;
    depth[v]=d;
    for(int i=0;i<(int)G[v].size();i++){
      if(G[v][i]!=p) dfs(G[v][i],v,d+1);
    }
  }
  
  void construct(){
    dfs(root,-1,0);
    for(int k=0;k+1<MAX_LOG_V;k++){
      for(int v=0;v<V;v++){
	if(parent[k][v]<0) parent[k+1][v]=-1;
	else parent[k+1][v]=parent[k][parent[k][v]];
      }
    }
  }
  
  int lca(int u,int v){
    if(depth[u]>depth[v]) swap(u,v);
    for(int k=0;k<MAX_LOG_V;k++){
      if((depth[v]-depth[u])>>k&1){
	v=parent[k][v];
      }
    }
    if(u==v) return u;
    for(int k=MAX_LOG_V-1;k>=0;k--){
      if(parent[k][u]!=parent[k][v]){
	u=parent[k][u];
	v=parent[k][v];
      }
    }
    return parent[0][u];
  }
};
//END CUT HERE

signed main(){
  int n;
  cin>>n;
  LowestCommonAncestor lca(n);
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      lca.add_edge(i,c);
    }
  }
  lca.construct();
  int q;
  cin>>q;
  while(q--){
    int u,v;
    cin>>u>>v;
    cout<<lca.lca(u,v)<<endl;
  }
  return 0;
}
/*
verified on 2017/06/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A&lang=jp
*/

Measured memory_bytes: 51848
#include <stdio.h>

int main(void)
{

  int a, b, c;

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

  if (c < a + b)
  {
    printf("%d\n", b + c);
  }
  else if (c == a + b)
  {
    printf("%d\n", b + c);
  }
  else
  {
    printf("%d\n", b + a + b + 1);
  }

  return 0;
}

Measured memory_bytes: 128
#![allow(non_snake_case, unused_imports)]

// Input
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)*} };}
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, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: u64,
    }
    println!("{}", if N<1000{"ABC"}else{"ABD"});
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n;
    int a,b,c,d;
    scanf("%d",&n);
    a=n/1000;
    b=(n/100)%10;
    c=(n/10)%10;
    d=n%10;
    if(a==b||b==c||c==d)
    {
        printf("Bad\n");     
    }
    else
    {
        printf("Good\n");
    }
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 10005
#define LL long long
using namespace std;
const int mo=1e9+7;
int n,a,b,c; LL fc[N],xf[N],ans;
LL fpm(LL x,LL y){ LL s=1; while(y){ if(y&1) s=(s*x)%mo; y>>=1,x=(x*x)%mo;} return s;}
LL C(int n,int m){ return fc[n]*xf[m]%mo*xf[n-m]%mo;}
LL f(int n,int m)
{
	if(!n) return (m==0);
	else return xf[n]*C(m+n-1,n-1)%mo;
}
int main()
{
	int i,j,p,q,r,s,v;
	cin>>n>>a>>b>>c;
	if(b&1){ printf("0"); return 0;}
	fc[0]=xf[0]=1;
	for(i=1;i<N;i++){
		fc[i]=(fc[i-1]*i)%mo;
		xf[i]=fpm(fc[i],mo-2);
	  }
	for(i=0;i<=a&&i<=c;i++)
		for(j=0;i+3*j<=c;j++){
			p=a-i,q=i,r=j,s=b/2,v=c-i-3*j;
			ans=(ans+fc[p+q+r+s]*xf[p]%mo*xf[q]%mo*xf[r]%mo*f(s,v))%mo;
		  }
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
# include<bits/stdc++.h>
using namespace std;
#define tmprep(i,n) for(int i=2;i<=(int)n;i++)
#define rep(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
unordered_map<ll,ll> mp;

int main(){
  ll N;
  cin >> N;
  ll A[N+10];
  ll orig_sum=0;
  rep(i,N){
    cin >> A[i];
    orig_sum += A[i];
    mp[A[i]]++;
  }
  
  
  int Q;
  cin >> Q;
  ll B,C;
  ll diff;
  rep(i,Q){
    cin >> B >> C;
    diff=C-B;
    orig_sum += diff*mp[B];
    cout << orig_sum << '\n';
    mp[C]+=mp[B];
    mp[B]=0;
  }
  return 0;
}

Measured memory_bytes: 7832
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>

using namespace std;

int main(){
    long n;
    cin >> n;
    long p[n+10],m[n+10];
    for (long i=0;i<n;i++){
        cin >>p[i];
        m[i]=p[i];
    }
    long ans=1;
    for(long i=1;i<n;i++){
        m[i]=min(m[i-1],m[i]);
        if(m[i]==p[i]) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static double debt = 100000;

	public static void main(String[] args) throws IOException {

		int n;
		double hell = debt;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			hell *= 1.05;
			hell = Math.ceil(hell / 1000) * 1000;
		}

		System.out.println((int) hell);
	}
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int h, a; cin >> h >> a;
  cout << (h - 1) / a + 1 << endl;

}


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

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

  if(S[K-1] == 'A'){
    S[K-1] = 'a';
  } else if (S[K-1] == 'B'){
    S[K-1] = 'b';
  } else {
    S[K-1] = 'c';
  }

  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> X(n, 0);
    rep(i, k) {
        int d;
        cin >> d;
        rep(_, d) {
            int a;
            cin >> a;
            X[a - 1]++;
        }
    }
    int ans =0 ;
    rep(i, n) ans += X[i] == 0;
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define ld                 long double
#define ff                 first
#define ss                 second
#define P                 pair<int,int>
#define pb                 push_back
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
const int N = 3005;//change it when needed
int n;
double dp[N];
void solve() {
    cin >> n;
    memset(dp, 0.0, sizeof(dp));
    dp[0] = 1;
    // dp[i][j]   getting I heads for j coins......2 cases to deal ..
    // if it is a head or it   dp[i][j]=p[head]*dp[i-1][j-1]...we can get I-1 heads from j-1
    // it is a tail      dp[i][j]=p_tail*dp[i][j-1];
    for (int i = 1; i <= n; i++) {
        double head;
        cin >> head;
        for (int j = i; j > 0; j--) {
            dp[j] = head * dp[j - 1] + (1 - head) * dp[j];
        }
    }
    double ans = 0.0;
    int heads = n, tails = 0;
    for (int i = n; i >= 0; i--) {
        if (heads < tails)break;
        ans = dp[i];
        --heads, ++tails;
    }
    cout << fixed << setprecision(12) << ans << endl;
}

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t; cin >> t; while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<pair<double,double>> root(n);
    for(auto &x:root){
        cin >> x.first >> x.second;
    }

    vector<vector<double>> dist(n,vector<double>(n,-1));
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(dist[i][j]!=-1)continue;
            dist[i][j]=sqrt((root[i].first-root[j].first)*(root[i].first-root[j].first)+(root[i].second-root[j].second)*(root[i].second-root[j].second));
        }
    }

    vector<int> perm(n);
    for(int i=0;i<n;i++){
        perm[i]=i;
    }

    double sumdist=0;
    int count=0;
    do{
        for(int i=0;i<n-1;i++){
            int nowbeg=perm[i],nowend=perm[i+1];
            double nowdist=max(dist[nowbeg][nowend],dist[nowend][nowbeg]);
            sumdist+=nowdist;
        }
        count++;
    }while(next_permutation(perm.begin(),perm.end()));

    printf("%.7lf",sumdist/count);

    return 0;
}


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

using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
  int parent;
  int left; // 子の一番左
  int right; // 右の兄弟
};

Node T[MAX];
int n, D[MAX];

void print(int id) {
  int i, c;
  cout << "node " << id << ": ";
  cout << "parent = " << T[id].parent << ", ";
  cout << "depth = " << D[id] << ", ";

  if (T[id].parent == NIL) cout << "root, ";
  else if (T[id].left == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";
  for (i = 0, c = T[id].left; c != NIL; i++, c = T[c].right) {
    if (i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void setDepth(int id, int depth) {
  D[id] = depth;
  if (T[id].right != NIL) setDepth(T[id].right, depth);
  if (T[id].left != NIL) setDepth(T[id].left, depth + 1);
}

int main() {
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    T[i].parent = T[i].left = T[i].right = NIL;
  }
  for (int i = 0; i < n; i++) {
    int id, k; cin >> id >> k;
    int before;
    for (int j = 0; j < k; j++) {
      int child; cin >> child;
      if (j == 0) T[id].left = child;
      else T[before].right = child;
      before = child;
      T[child].parent = id;
    }
  }
  int root;
  for (int i = 0; i < n; i++) {
    if (T[i].parent == NIL) root = i;
  }
  setDepth(root, 0);
  for (int i = 0; i < n; i++) print(i);
  return 0;
}



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


void solve(long long N, std::vector<long long> A, long long Q, std::vector<long long> B, std::vector<long long> C){
    long long ans = accumulate(A.begin(), A.end(), 0LL);
    map<long long, long long> mp;
    for(auto a: A) mp[a] += 1;
    for(int i = 0; i < Q; ++i){
        ans = ans - B[i] * mp[B[i]] + C[i] * mp[B[i]];
        mp[C[i]] += mp[B[i]];
        mp[B[i]] = 0;
        cout << ans << endl;
    }
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> B(Q);
    std::vector<long long> C(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), Q, std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 11420