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

#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define all(vec) vec.begin(), vec.end()
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
//#define int long long
#define endl "\n"
typedef long long ll;

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

  int N; cin >> N;
  vector<int> T;
  T.push_back(0); // 1-origin
  rep(i, N) {
    int t; cin >> t;
    T.push_back(t);
  }
  int M; cin >> M;

  rep(i, M) {
    int P, X; cin >> P >> X;

    int sum = 0;
    repr(j, 1, N+1) {
      if(j == P) sum+=X;
      else sum+=T[j];
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		long a = Long.parseLong(sa[1]);
		long b = Long.parseLong(sa[2]);
		long k = Long.parseLong(sa[3]);
		br.close();

		int mod = 998244353;
		long[] p = new long[n + 1];
		long[] pi = new long[n + 1];
		p[0] = 1;
		pi[0] = 1;
		for (int i = 1; i < p.length; i++) {
			p[i] = p[i - 1] * i % mod;
			pi[i] = modinv(p[i], mod);
		}

		long ans = 0;
		for (int i = 0; i <= n; i++) {
			long j = (k - a * i);
			if (j < 0 || j % b != 0) {
				continue;
			}
			j /= b;
			if (j > n) {
				continue;
			}
			long val1 = nCr(n, i, mod, p, pi);
			long val2 = nCr(n, (int) j, mod, p, pi);
			val1 *= val2;
			ans += val1;
			ans %= mod;
		}
		System.out.println(ans);
	}

	static long nCr(int n, int r, int m, long[] p, long[] pi) {
		return p[n] * pi[r] % m * pi[n - r] % m;
	}

	static long modinv(long a, long m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


Measured memory_bytes: 25812
# coding: utf-8

def printA(a, n):
    for i in range(n):
        print(a[i],end="")
        if i < n - 1:
            print(" ", end="")
        else:
            print()

def bubbleSort(a, n):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
    return count

n = int(input().rstrip())
a = list(map(int,input().rstrip().split()))
c = bubbleSort(a, n)
printA(a,n)
print(c)


Measured memory_bytes: 5624
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;


int main(){
	while(1){
		int n,p,cnt=0,ans=0;
		cin>>n>>p;
		int res[50]={};
		if(n==0)break;
		cnt=p;
		bool ok=false;
		int x=-1;
		while(1){
			x++;
			x=x%n;
			if(cnt!=0){
				cnt--;
				res[x]++;
			}else{
				cnt=res[x];
				res[x]=0;
				if(cnt==p){
					ans=x;
					break;
				}
			}
		}
		print(ans);
	}
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>

#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    fastio;
//	#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r" , stdin);
//    freopen("output.txt", "w" , stdout);
//    #endif
    ll n, m;
    cin >> n >> m;
    
    int x = 2 * ((m + 1) / 2), y = 1, z = x + 1, w = 2 * m + 1;
    
    while (y < x) {
    	cout << y << " " << x << "\n";
    	y++,x--;
	}
	
	
	
	while (z < w) {
		cout << z << " " << w << "\n";
		z++,w--;
	}
	
	//code
	return 0;
}


Measured memory_bytes: 3680
import java.util.*;
class Main{
    void solve(){
        Scanner sc = new Scanner(System.in);
        int i = 0, total = 0;
        while ( i < 10 ) {
            int s = sc.nextInt();
            total += s;
            i++;
        }
        System.out.println( total );
    }

    public static void main(String[] args){ new Main().solve(); }
}


Measured memory_bytes: 26244
from math import gcd 
 
n = int(input())
maxA = 10**6+1
A = list(map(int, input().split()))
c = [0]*maxA
for a in A:
    c[a] += 1

for i in range(2, maxA):
    cnt = 0
    for j in range(i, maxA, i):
        cnt += c[j]
    if cnt >= 2:
        break
else:
    print('pairwise coprime')
    exit()

g = A[0]
for a in A[1:]:
    g = gcd(g, a)
if g == 1:
    print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 202808
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
count = 0

for i in range(N):
    d1, d2 = LI()
    if d1 == d2:
        count += 1
    else:
        count = 0
    
    if count == 3:
        print('Yes')
        exit()

print('No')

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
const long double PI=(acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n;
  cin>>n;
  long double ans=0;
  rep(i,n){
    long double x;
    cin>>x;
    string u;
    cin>>u;
    if(u=="JPY"){
      ans+=x;
    }else{
      ans+=x*380000.0;
    }
  }
  cout<<ans<<endl;
    
}

Measured memory_bytes: 256
N = int(input())
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

f = False

index = N-1
while f == False:
    index += 1
    f = is_prime(index)

print(index)


Measured memory_bytes: 38384
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int d[4][2] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1} };
int A[100][100];

int main(int argc, char *argv[])
{
  int H, W;
  string S[2000];
  queue<pair<int, int> > que;
  cin >> H >> W;
  int b = 0;

  for (int i = 0; i < H; i++) {
    cin >> S[i];

    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') b++;
      A[i][j] = -1;
    }
  }

  que.push(make_pair(0, 0));
  A[0][0] = 1;

  while (!que.empty()) {
    auto p = que.front();
    que.pop();

    for (int i = 0; i < 4; i++) {
      int dy = p.first + d[i][0];
      int dx = p.second + d[i][1];
      if (0 <= dx && 0 <= dy && dx < W && dy < H && -1 == A[dy][dx] && S[dy][dx] != '#') {
        A[dy][dx] = A[p.first][p.second] + 1;
        que.push(make_pair(dy, dx));
      }
    }
  }

  if (A[H-1][W-1] == -1) {
    cout << -1 << endl;
  } else {
    cout << (H*W) - b - A[H-1][W-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int a,b,c;
  cin >> a >> b >> c;
  if(a < b) {
    if(b < c) {
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3124
t = list(input())
S = [int(x) for x in t]
cnt1 = 0
cnt2 = 0

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == 0:
            cnt2 += 1
        else:
            cnt1 += 1
    else:
        if S[i] == 0:
            cnt1 += 1
        else:
            cnt2 += 1
print(min(cnt1, cnt2))


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

main :: IO ()
main = do
  n <- inp toInt
  xs <- inpn n solve
  mapM_ print xs

solve :: String -> Int
solve s = mx - mn
  where
    ss = sort s
    rs = reverse ss
    mn = read ss
    mx = read rs

toInt :: String -> Int
toInt s = read s

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

inpn :: Int -> (String -> a) -> IO [a]
inpn n f = map f <$> replicateM n getLine

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

  int N;
  cin >> N;
  vector<int> A(N);
  multiset<int> st;
  repr(i, N, 0) {
    cin >> A[i];
    int a = -A[i];
    auto it = st.upper_bound(a);
    if (it == st.end()) {
      st.insert(a);
    } else {
      st.erase(it);
      st.insert(a);
    }
  }

  cout << st.size() << endl;
}


Measured memory_bytes: 8172
N = int(input())
S = list(input())
ans = 0
#print(S)

for i in range(10):
    first = 0
    while S[first] != str(i) and first < N-1:
        first += 1
    if first > N-3:
        continue
    for j in range(10):
        second = first+1
        while S[second] != str(j) and second < N-1:
            second += 1
        if second > N-2:
            continue
        #print(i,first,j,second)
        ans += len(set(S[second+1:]))
print(ans)


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


int main(void){
  std::string s;
  int a,b;
  stack<int> S;

  while(std::cin >> s){
    if(s=="+"){
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a + b);
    } else if (s=="-") {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a - b);
    } else if (s=="*") {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a * b);
    } else {
      int val = std::stoi(s);
      S.push( val );
    }
//    stack.show();
  }


  std::cout << S.top() << '\n';

  return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <vector>

using namespace std;

int main(){
 
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> data(h, vector<char>(w));
  
  for(int i = 0; i < h; i++){
    bool f_white = true;
    for(int j = 0; j < w; j++){
      cin >> data[i][j];
      if(data[i][j] == '#'){
        f_white = false;
      }
    }
    if(f_white){
      for(int j = 0; j < w; j++){
        data[i][j] = 'x';
      }
    }
  }
  
  for(int j = 0; j < w; j++){
    bool f_white = true;
    for(int i = 0; i < h; i++){
      if(data[i][j] == '#'){
        f_white = false;
      }
    }
    if(f_white){
      for(int i = 0; i < h; i++){
        data[i][j] = 'x';
      }
    }
  }
  
  for(int i = 0; i < h; i++){
    bool f_nout = true;
    for(int j = 0; j < w; j++){
      if(data[i][j] != 'x'){
        cout << data[i][j];
        f_nout = false;
      }
    }
    if(!f_nout){
      cout << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

struct BINNODE {
	int parent;
	int left;
	int right;

	BINNODE () { // default constructor
		parent=-1;
		left=-1;
		right=-1;
	}
};

void make_node(vector<int>& pre, vector<int>& in, pair<int,int> pre_indx, pair<int,int> in_indx, int parent, vector<BINNODE>& node) {
	int pre_found=pre_indx.first, in_found=in_indx.first;

	node[pre[pre_indx.first]].parent=parent;

	while(pre[pre_indx.first]!=in[in_found]) {
		++in_found;
		++pre_found;
	}

	if(in_found==in_indx.first) {
		node[pre[pre_indx.first]].left=-1;
	} else {
		node[pre[pre_indx.first]].left=pre[pre_indx.first+1];
		make_node(pre,in,{pre_indx.first+1,pre_found},{in_indx.first,in_found-1},pre[0],node);
	}
	if(in_found==in_indx.second) {
		node[pre[pre_indx.first]].right=-1;
	} else {
		node[pre[pre_indx.first]].right=pre[pre_found+1];
		make_node(pre,in,{pre_found+1,pre_indx.second},{in_found+1,in_indx.second},pre[0],node);
	}
	return;
}


void postorderwalk(vector<BINNODE>&node, int root) {
	if(root==-1) return;
	postorderwalk(node,node[root].left);
	postorderwalk(node,node[root].right);
	if(node[root].parent==-1) {
		printf("%d\n",root);
	} else {
		printf("%d ",root);
	}
	return;
}

int main() {
	int n;
	int i;
	int root;
	vector<int> pre,in;
	vector<BINNODE> node;
	scanf("%d",&n);
	node.resize(n+1);
	pre.resize(n);
	in.resize(n);
	for(i=0; i<n; ++i) {
		scanf("%d",&pre[i]);
	}
	for(i=0; i<n; ++i) {
		scanf("%d",&in[i]);
	}
	root=pre[0];
	make_node(pre,in,{0,n-1},{0,n-1},-1,node);
	postorderwalk(node,root);
	return 0;
}

Measured memory_bytes: 2748
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,n,k;
  cin>>n>>k;
  vector<long int> h(n);
  for(i=0;i<n;i++){
    cin>>h.at(i);
  }
  sort(h.begin(),h.end());
  long int sa;
  long int min = h.at(n-1);
  i=0;
  j=k-1;
  while(j<n){
    sa=h.at(j)-h.at(i);
    if(min>sa){
      min=sa;
      if(min==0){break;}
    }
    i++;j++;
  }
  cout<<min<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){

  int i;
  int weight[10] = {1,2,4,8,16,32,64,128,256,512};
  int use[10];
  int obj;
  int max;

  while(scanf("%d",&obj)!=EOF){

    max = 0;

    for(i=9;i>=0;i--){
      if(obj >= weight[i]){
	obj -= weight[i];
	use[i] = 1;
	if(max < i)max = i;
      }else{
	use[i] = 0;
      }
    }

    for(i=0;i<10;i++){
      if(use[i]){
	printf("%d",weight[i]);
	if(i == max)break;
	putchar(' ');
      }
    }
    putchar('\n');
  }

  return 0;
}

Measured memory_bytes: 0
import sys
import fractions
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab_sorted = sorted(ab, key=lambda x: x[1])

    sum_a = 0
    for a, b in ab_sorted:
        sum_a += a
        if b < sum_a:
            print('No')
            quit()
    print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 35540
from collections import deque

def bfs():
    dist = [[f_inf] * w for _ in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((0, 0))
    dist[0][0] = 0

    while que:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if h > nx >= 0 and w > ny >= 0 and \
               C[nx][ny] != '#' and \
               dist[nx][ny] == f_inf:
                que.append((nx, ny))
                dist[nx][ny] = dist[p[0]][p[1]]+1
    return dist[h-1][w-1]

h, w = map(int, input().split())
C =[input() for _ in range(h)]
f_inf = float('inf')

cnt = 0
for c in C:
    cnt += c.count('.')

if bfs() == f_inf:
    print(-1)
else:
    print(cnt - 1 - bfs())

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

int main()
{
	int n,m;
	cin>>n>>m;
	
	int ac[n+1],wa[n+1];
	memset(ac,0,sizeof(ac));
	memset(wa,0,sizeof(wa));
	
	int cut_ac=0,cut_wa=0;
	for(int i=1; i<=m; i++)
	{
		int idx;
		string s;
		cin>>idx>>s;
		
		if(ac[idx]==0 && s=="WA")
		{
			wa[idx]++;
		}
		else if(ac[idx]==0 && s=="AC")
		{
			ac[idx]++;
			cut_wa+=wa[idx];
			cut_ac++;
		}
	}
	
	cout<<cut_ac<<' '<<cut_wa<< endl;
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < s.size(); i++)
	{
		cin >> s.at(i);
	}

	int acNum = count(s.begin(), s.end(), "AC");
	int waNum = count(s.begin(), s.end(), "WA");
	int tlNum = count(s.begin(), s.end(), "TLE");
	int reNum = count(s.begin(), s.end(), "RE");

	cout << "AC x " << acNum << endl
		 << "WA x " << waNum << endl
		 << "TLE x " << tlNum << endl
		 << "RE x " << reNum << endl;

	return 0;
}

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

int b[200][200];
int n;
int ask(int i, int j) {
	string s = string(n, '0');
	s[i] = '1'; s[j] = '1';
	cout << "? " << s << endl;
	int res; cin >> res;
	return res;
}
int main() {
	cin >> n;
	int cnt = 0;
	memset(b, -1, sizeof(b));
	rep(i, n)for (int j = i + 1; j < n; j += 2) {
		if (cnt == n - 1)break;
		if (b[i][j] != -1) {
			j--; continue;
		}
		string s(n, '0'); s[i] = '1'; s[j] = '1';
		if (j + 1 < n)s[j + 1] = '1';
		cout << "? " << s << endl;
		int res; cin >> res;
		if (res == 0) {
			b[i][j] = 0; 
			if (j + 1 < n) {
				b[i][j + 1] = 0;
				b[j][j + 1] = 0;
			}
			continue;
		}
		if (j + 1 == n) {
			b[i][j] = 1; cnt++; continue;
		}
		int a = 0;
		if (ask(i, j)) {
			a++; b[i][j] = 1; cnt++;
		}
		else b[i][j] = 0;
		if (ask(i, j + 1)) {
			a++; b[i][j + 1] = 1; cnt++;
		}
		else b[i][j + 1] = 0;
		if (a == 2) {
			b[j][j + 1] = 0;
		}
		if (res == 2 && a != 2)b[j][j + 1] = 1;
	}
	cout << "!";
	rep(i, n)for (int j = i + 1; j < n; j++) {
		if (b[i][j]) {
			if (b[i][j] == -1)abort();
			cout << " ";
			cout << "(" << i << "," << j << ")";
		}
	}
	cout << endl;
}

Measured memory_bytes: 976
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}*/
/*ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

ll test[12345678];
signed main() {
	string s, t;
	ll n, m, a, b, cnt = 0, ans = 0;
	ll x, k, d; cin >> x >> k >> d;
	x = abs(x); ld aa = x / k;
	if (aa >= d) { cout << x - (k * d) << endl; return 0; }
	k -= (x / d); x %= d;
	cnt = abs(x - d); ans = x;
	if (k % 2 == 0) { cout << ans << endl; }
	else { cout << cnt << endl; }
	return 0;
}

Measured memory_bytes: 3620
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7
k = k % mod
# 配列内で自身より小さい数の個数　前後別に求める
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            elif i < j:
                b[i][1] += 1
    b[i][0] = b[i][0] % mod
    b[i][1] = b[i][1] % mod
ans = 0

if k%2 == 0:
    sigmakp = (int(k/2) * (k+1)) % mod
    sigmakn = (int(k/2) * (k-1)) % mod
else:
    sigmakp = (int((k+1)/2) * k) % mod
    sigmakn = (int((k-1)/2) * k) % mod

for i in range(n):
    mae = (sigmakp * b[i][1]) % mod
    ushiro = (sigmakn * b[i][0]) % mod
    ans = ((mae + ushiro) % mod + ans) % mod 
print(ans)

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

int main() {
  int number_of_elements;
  int i, j = 0, k;
  int key;
  int *A;
  
  scanf("%d", &number_of_elements);

  A = (int *)malloc(number_of_elements * sizeof(int));

  for(i = 0; i < number_of_elements; i++)
    scanf("%d", &A[i]);

  for(i = 1; i < number_of_elements; i++) {
    key = A[i];
    j = i - 1;
    for(k = 0; k < number_of_elements; k++){
      printf("%d", A[k]);
      if(k != number_of_elements - 1) printf(" ");
    }
    printf("\n");
    while( j >= 0 && A[j] > key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
  }

  for(i = 0; i < number_of_elements; i++){
    printf("%d", A[i]);
    if(i != number_of_elements - 1) printf(" ");
  }
  printf("\n");

  free(A);
  
  return 0;
  
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define INF 1e15
#define MOD 1e9+7
int n, q;
string s;
int cnt[111111];
signed main() {
	cin >> n >> q;
	cin >> s;
	rep(i, s.size()) {
		if (i) {
			if (s[i] =='C'&& s[i - 1]=='A')cnt[i] = 1;
			cnt[i] += cnt[i - 1];
		}
	}
	rep(i, q) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		if (l == 0)cout << cnt[r] << endl;
		else {
			int ans = cnt[r] - cnt[l - 1];
			if (s[l] == 'C'&&s[l-1]=='A')ans--;
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	char a[3][4];
	char b[3][4];
	char t;
	for(int i=1;i<=2;i++){
		scanf(" %c %c %c",&a[i][1],&a[i][2],&a[i][3]);
	}
	b[1][1]=a[2][3];
	b[1][2]=a[2][2];
	b[1][3]=a[2][1];
	b[2][1]=a[1][3];
	b[2][2]=a[1][2];
	b[2][3]=a[1][1];
	if(b[1][1]==a[1][1]&&b[1][2]==a[1][2]&&b[1][3]==a[1][3]&&b[2][1]==a[2][1]&&b[2][2]==a[2][2]&&b[2][3]==a[2][3]){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}

Measured memory_bytes: 256
N = gets.to_i
H = gets.split.map &:to_i

cnt = 0
max = 0
(1..N-1).each do |i|
  if H[i] - H[i-1] <= 0
    cnt += 1
  else
    max = cnt if cnt > max
    cnt = 0
  end
end
max = cnt if cnt > max
puts max

Measured memory_bytes: 20716
#include <iostream>
using namespace std;
int main()
{
    int a;
    cin>>a;
    int k=a;
    int sum=0;
    while(k>0)
    {
        sum=sum+k%10;
        k=k/10;
    }
    if(a%sum==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,l;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<ll> ans;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>l;
    rep(i,n)cin>>a[i];
    ll flags=0;
    rep(i,n-1){
        if(a[i]+a[i+1]>=l){
            flags=i+1;
            break;
        }
    }
    if(flags==0)Cout("Impossible");
    else{
        rrep(i,1,n+1){
            if(i==flags)break;
            ans.push_back(i);
        }
        rrrep(i,n-1,1){
            if(i==flags)break;
            ans.push_back(i);
        }
        ans.push_back(flags);
        Cout("Possible");
        rep(i,Size(ans))Cout(ans[i]);
    }
    return 0;
}


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

int main() {
    for (;;) {
        int n, x;
        cin >> n >> x;

        if (n == 0 && x == 0) break;

        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                for (int k = j + 1; k <= n; ++k) {
                    if (i + j + k == x) ++ans;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uset unordered_set
#define umap unordered_map
#define db(x) cout << #x << " == " << x << ";\n"
#define a(x) x.begin(),x.end()
#define input(v,n) for(int i=0;i<n;i++)cin>>v[i]
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf = 1e5+7;
// ===================== MANASH =================== //

void test() {

	int n;
	cin >> n;
	int cnt = 0;
	
	umap<int,int> m;
	for( int i = 0; i < n; i++) {
		int t;
		cin >> t;
		cnt += m[i+1-t]; // INCREASING ORDER. SO ONLY BEFORE REQ.
		m[i+1+t]++;
	}

	cout << cnt;

}

int32_t main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);

	#ifdef LOCAL
	freopen("input.txt","r",stdin);
	#endif

	int T = 1;
	while(T--) {
		test();
		cout << "\n";
	}
	return 0;

}

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

int main()
{
    int a, b, c;
    int k;
    int m = 0;
    cin >> a >> b >> c >> k;
    long long sum = a + b + c;
    m = max({a, b, c});
    sum -= m;
    for (int i = 0; i < k; ++i)
    {
        m *= 2;
    }
    sum += m;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    H, W, d = map(int, input().split())

    N = 1500
    grid = [[""] * N for _ in range(N)]
    if d & 1:
        ans = [[""] * W for _ in range(H)]
        for h in range(H):
            for w in range(W):
                if (h+w) & 1:
                    ans[h][w] = "R"
                else:
                    ans[h][w] = "B"
        for h in range(H):
            print("".join(ans[h]))
        exit()

    grid = [[""] * N for _ in range(N)]
    e = (d-2) // 2
    for h in range(N):
        if h * d >= N:
            break
        for w in range(N):
            if w * d >= N:
                break
            if (h+w) & 1:
                c = "R"
            else:
                c = "B"
            for hh in range(h*d - e, h*d + e + 1):
                for ww in range(w*d - e, w*d + e + 1):
                    if 0 <= hh < N and 0 <= ww < N and abs(h*d-hh) + abs(w*d-ww) <= e:
                        grid[hh][ww] = c
    for h in range(N):
        if h * d + d//2 >= N:
            break
        for w in range(N):
            if w * d + d//2 >= N:
                break
            if (h+w) & 1:
                c = "Y"
            else:
                c = "G"
            for hh in range(h*d + d//2 - e, h*d + d//2 + e + 1):
                for ww in range(w*d + d//2 - e, w*d + d//2 + e + 1):
                    if 0 <= hh < N and 0 <= ww < N and abs(h*d + d//2 - hh) + abs(w*d + d//2 - ww) <= e:
                        grid[hh][ww] = c

    for h in range(1, N):
        for w in range(N):
            if grid[h][w] == "":
                grid[h][w] = grid[h-1][w]

    for h in range(501, 500+H+1):
        print("".join(grid[h][501:500+W+1]))


if __name__ == '__main__':
    main()


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
    int n;
    cin>>n;
    vector<int> l(2*n);
    rep(i,0,2*n)cin>>l[i];

    sort(l.begin(),l.end());

    int ans=0;
    for(int i=0;i<2*n;i+=2) ans+=l[i];

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

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    char x;
  cin >> x;
    if(x == 'A') cout << 'T';
    else if(x == 'T') cout << 'A';
    else if(x == 'G') cout << 'C';
    else cout << 'G';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pvar(x) clog<<"["<<#x<<":"<<x<<"]\n"
using namespace std;
using ll = long long int;
const int N = 101;
const int W = 100001;
ll dp[N][W];
ll knapsack(vector<int> &we , vector<int> &val , int n , int w){
	if(n==0 || w==0)return 0;
	
	if(dp[n][w] != -1)return dp[n][w];//if sub-problem not solved	
	
	if(we[n-1] > w)//if current object wt is greater than knapsac wt;
	  dp[n][w] = knapsack(we,val,n-1,w);
	else
		dp[n][w] = max((ll)val[n-1]+knapsack(we,val,n-1,w-we[n-1]),
													knapsack(we,val,n-1,w));
	return dp[n][w];
}
int main(){
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
	memset(dp , -1 , sizeof(dp));
	int n,w;
	cin>>n>>w;
	vector<int> we(n) , val(n);
	for(int i=0;i<n;i++){
		cin>>we[i]>>val[i];
	}
	cout<<knapsack(we,val,n,w);
}
 


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

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

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

    sort(A, A + N);

    string ans = "YES";
    for (int i = 0; i < N - 1; i++) {
        if (A[i] == A[i+1]) {
            ans = "NO";
        }
    }

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


Measured memory_bytes: 1024
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <ios>
#include <iomanip>

using namespace std;

int main(){
    int N,Q;
    string s;
    int l,r;
    cin >> N >> Q;
    cin >> s;

    vector<int> v;

    REP(i, s.length()){
        if(s[i]=='A'){
            if(i<s.length()-1){
                if(s[i+1]=='C'){
                    v.push_back(i+1);
                }
            }
        }
    }


    REP(i, Q){
        int ans=0;
        cin>>l>>r;
        for(int x : v){
        	if(x>=l && x+1<=r){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    vector<char> v ={'2','4','5','7','9','0','1','6','8','3',};
    string T; cin >> T;
    for (int i = 0; i < 10; i++)
    {   
        
        if( i < 5 && T[T.size()-1] == v[i]){
            cout << "hon" << endl; break;
        }
        if( 4 < i && i < 9 && T[T.size()-1] == v[i]){
            cout << "pon" << endl; break;
        }if(i == 9){cout << "bon" << endl; break;}
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define endl              "\n"
#define pb              push_back
#define fir               first
#define sec               second
#define all(v)            ((v).begin()), ((v).end())
#define sz(v)            ((int)((v).size()))
#define ll              long long
#define ld              long double
#define lp(i, n)        for(int i = 0 ; (int)i<n ; i++)
#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)
#define isPowerOfTwo(s) (!(s & (s-1)))
typedef vector<int> vi;
typedef deque<int> de;
void origi() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
set<int>s;
void tiranga() {
    int n;
    int res = 0;
    cin >> n;
    int x;
    cin >> x;
    s.insert(x);
    res++;
    loop(i, 1, n - 1) {
        cin >> x;
        if (x < * s.begin()) res++;
        s.insert(x);
    }
    cout << res;
}
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#else
#endif 
    origi();
    tiranga();
    //cout << sumOfDig(123654);
   // genLarge(10, 10);
   // genSmall(10);
   
}


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

#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void input(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

int di[] = {-1,1,0,0}, dj[] = {0,0,-1,1};

void dfs(int i, int j, vector<string>& grid, vector<vector<bool>>& visited){
	if(grid[i][j]!='#')
		visited[i][j]=true;
	else
		return;
	for(int d=0;d<4;d++){
		int ni=i+di[d],nj=j+dj[d];
		if(ni>=0&&nj>=0&&ni<grid.size()&&nj<grid[0].size()&&grid[ni][nj]!='#'&&!visited[ni][nj]){
			visited[ni][nj]=true;
			dfs(ni,nj,grid,visited);
		}
	}
}



void solveTest(){
}

int main(){
	fastio();
	//input();

	/*int t;
	cin>>t;
	while(t--){
		solveTest();
	}*/

	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(int(i*1.08)==n){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<":("<<endl;
	return 0;
}
     

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        long[] a = Pattern.compile(" ").splitAsStream(stdin.nextLine()).mapToLong(Long::parseLong).toArray();
        long[] b = Pattern.compile(" ").splitAsStream(stdin.nextLine()).mapToLong(Long::parseLong).toArray();
        long[] c = a.clone();

        for (int i = 0; i < n; i++) {
            if (a[i] < b[i]) {
                b[i] -= a[i];
                a[i] = 0;
                a[i + 1] = Math.max(0, a[i + 1] - b[i]);
            } else {
                a[i] -= b[i];
            }
        }

        long ans = IntStream.range(0, n + 1).mapToLong(i -> c[i] - a[i]).sum();
        System.out.println(ans);
    }

}


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

using namespace std;

int main()
{
  int n;
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    int pep[7] = {0};
    for(int i = 0; i < n; i++){
      int old;
      scanf("%d", &old);
      pep[(old >= 60 ? 6 : old / 10)]++;
    }
    for(int i = 0; i < 7; i++){
      printf("%d\n", pep[i]);
    }
  }
}

Measured memory_bytes: 1188
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		int K = sc.nextInt();
		
		// 計算
		long result = 0;
		int len = s.length();
		int[][][] dp = new int[len+1][4][2];
		dp[0][0][0] = 1;
		for(int i = 1; i < len+1; i++){
		    int n = s.charAt(i-1) - '0';
		    for(int j = 0; j < 4; j++){
		        dp[i][j][1] += dp[i-1][j][1];
		        if(n == 0){
		            dp[i][j][0] += dp[i-1][j][0];
		        }else{
		            dp[i][j][1] += dp[i-1][j][0];
		        }
		        if(j < K){
		            dp[i][j+1][1] += dp[i-1][j][1]*9;
		            if(n > 0){
		                dp[i][j+1][1] += dp[i-1][j][0]*(n-1);
		                dp[i][j+1][0] += dp[i-1][j][0];
		            }
		        }
		    }
		}
		result = dp[len][K][0] + dp[len][K][1];
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	string num = "012092012";
	while(1){
		string s; cin >> s;
		if(s == "#") break;
		int n = s.size();
		function<int(int)> calc = [&](int turn){
			int left = 0, right = 2;
			int res = 0;
			rep(i,n){
				int nxt = num[s[i]-'0'-1] - '0';
				if(!turn){
					if(right >= nxt){
						left = nxt;
						turn = 1 - turn;
					}else{
						res++;
						right = nxt;
					}
				}else{
					if(left <= nxt){
						right = nxt;
						turn = 1 - turn;
					}else{
						res++;
						left = nxt;
					}
				}
			}
			return res;
		};
		cout << min(calc(0), calc(1)) << "\n";
	}
}


Measured memory_bytes: 3176
#include <stdio.h>
int main(void){
    int a1,b2,c3,five=0,seven=0;
    scanf("%d%d%d",&a1,&b2,&c3);
    if(a1==5){
        five++;
    }else if(a1==7){
        seven++;
    }
    if(b2==5){
        five++;
    }else if(b2==7){
        seven++;
    }
    if(c3==5){
        five++;
    }else if(c3==7){
        seven++;
    }
    if(five==2||seven==1){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
	}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

int main()
{
    int N, K;
    std::cin >> N >> K;
    std::vector<int> A(N);
    for(int i=0; i<N; i++)
    {
        std::cin >> A[i];
    }

    for(int i=K; i<N; i++)
    {
        int rm = A[i-K];
        int add = A[i];

        if(add > rm)
        {
            std::cout << "Yes" << std::endl;
        }
        else
        {
            std::cout << "No" << std::endl;
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 4048
mod=1000000007
def mi(a,m)
  b,u,v=m,1,0
  while b>0
    t=a/b
    a-=t*b
    u-=t*v
    a,b,u,v=b,a,v,u
  end
  u%=m
  u+=m if u<0
  return u
end
s=gets.to_i
f=[1]
s.times do |i|
  f << f[-1]*(i+1)%mod
end
a=0
1.upto(s/3) do |i|
  a=(a+f[s-3*i+i-1]*mi(f[s-3*i],mod)*mi(f[i-1],mod))%mod
end
puts a


Measured memory_bytes: 14376
'use strict';
function Main(input) {
  let array = input.split("\n");
  array.shift();
  let sort = array.sort();
  let out = '';
  for (let i = 0; i < sort.length; i++) {
    out += sort[i];
  }
  console.log(`${out}`);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 6904
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            try :
                if isCLKWISE(phU) : break
                else : del phU[-2]
            except IndexError : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            try :
                if isCLKWISE(phL) : break
                else : del phL[-2]
            except IndexError : break
    ph = phU + phL[1:-1]
    return ph
  
P = [[int(x) for x in input().split()] for _ in range(int(input()))]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
for p in P[idx:] + P[:idx] : print(p[0],p[1])

Measured memory_bytes: 33176
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(V),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	set<int> st;
	st.insert(a);
	st.insert(b);
	st.insert(c);
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String str="";
		StringBuffer sb;
		int counter=0;
		while(sc.hasNext()) {
			str=sc.next();
			sb=new StringBuffer(str);
			if(str.equals(sb.reverse().toString())) {
				counter++;
			}
		}
		System.out.println(counter);
		sc.close();
	}
}


Measured memory_bytes: 25888
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#define REL
#endif
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

//#pragma GCC optimize("Ofast")
//#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);
//mt19937_64 gen(41);


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rps2.in", "r", stdin);
	//freopen("rps2.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------//
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.rbegin(), a.rend());
	for (int i = 0; i < m; i++) {
		if (a[i] * 4 * m < sum) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";	
	//----------------------------------------------//

	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x,y,d;
	scanf("%d %d",&x,&y);

 	while (x != y) {
		if (x > y) {
           		d = x - y;
           		x = y;
           		y = d;
		} else {
            		d = y - x;
           		y = x;
            		x = d;
        	}
	}

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



Measured memory_bytes: 2112
main :: IO ()
main = print . solve 0 0 . map read . tail . words =<< getContents

solve :: Int -> Int -> [Int] -> Int
solve n m (x:y:xs) | x >= y = solve n (m + 1) (y:xs)
                   | otherwise = solve (max n m) 0 (y:xs)
solve n m _ = max n m


Measured memory_bytes: 2428
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn = 300000+10;
int a[maxn];
int main()
{
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    for(int i=0;i<3*N;i++)  cin >> a[i];
    sort(a, a+3*N);
    LL ans = 0;
    int j=3*N - 2;
    for(int i=1;i<=N;i++)
    {
        ans += a[j];
        j-=2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, C;
ll pows[410][410];
ll dp[410][410];
int A[410], B[410];

void solve() {
	cin >> N >> C;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) cin >> B[i];

	rep(i, 1, 400 + 1) {
		pows[0][i + 1] = 1;
		rep(j, 1, C + 1) {
			pows[j][i + 1] = pows[j - 1][i + 1] * i  % mod;
		}
	}
	rep(i, 0, C + 1) {
		rep(j, 0, 400 + 1) {
			ADD(pows[i][j + 1], pows[i][j]);
		}
	}

	// rep(i, 0, C + 1) {
	// 	debug(vl(pows[i], pows[i] + 400 + 2));
	// }

	dp[0][0] = 1;
	rep(i, 0, N) {
		rep(j, 0, C + 1) {
			if(dp[i][j] == 0) continue;
			rep(k, 0, C + 1) {
				if(j + k <= C) {
					ADD(dp[i + 1][j + k], dp[i][j] * (pows[k][B[i] + 1] - pows[k][A[i]] + mod) % mod);
				}
			}
		}
	}
	cout << dp[N][C] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (a + b > c + d)cout << "Left\n";
	else if (a + b == c + d)cout << "Balanced\n";
	else cout << "Right\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
#define int long long
int32_t main(){
	int n; cin>>n;
	vector<int> a(n);
	rep(i,n) {
		cin>>a[i];
	}
	int ans = 0;
	while(true){
	rep(i, n){
		if(a[i] % 2 != 0){
			cout<<ans<<endl;
			return 0;
		}
		a[i] /= 2;
		if(i == n - 1) ans++;
		}
	}
	
}


Measured memory_bytes: 256