akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2150&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 あらかじめ素数を列挙しておき、探索する
 ================================================================
 */
const ll MAX_PRIME = 200000;
vector<int> primes;
vector<int> is_prime(MAX_PRIME + 1,true);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2;j<=MAX_PRIME;j+=i) is_prime[j] = false;
        }
    }
}

void solve(){
    init_primes();
    ll N,P;
    vector<ll> sum;
    while(cin >> N >> P){
        if(N == -1 && P == -1) break;
        sum.clear();
        auto idx = upper_bound(primes.begin(),primes.end(),N) - primes.begin();
        for(int i = 0; i <= P;i++){
            for(int j = i; j <= P;j++){
                ll S = primes[idx+i] + primes[idx+j];
                sum.push_back(S);
            }
        }
        sort(sum.begin(),sum.end());
        cout << sum[P-1] << endl;
    }
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 3752
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    string s , t;
    cin >> s >> t;
    cout << t << s << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys

def main():
    is_prime = sieve(10 ** 5 + 1)
    is_like2017 = [(is_prime[i] and is_prime[(i + 1) // 2]) for i in range(10 ** 5 + 1)]
    counter = [0]
    for i in range(1, 10 ** 5 + 1):
        counter.append(counter[-1] + (1 if is_like2017[i] else 0))

    q = int(input())
    for i in range(q):
        l, r = map(int, sys.stdin.readline().split())
        print(counter[r] - counter[l - 1])


# O(nloglogn) https://mathtrain.jp/eratosthenes
def sieve(n):  # exclusive
    s = [True] * n
    s[0] = s[1] = False
    for x in range(2, int(n**0.5) + 1):
        if s[x]:
            for i in range(2 * x, n, x):
                s[i] = False
    return s

if __name__ == "__main__":
    main()


Measured memory_bytes: 8412
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<cstring>
using namespace std;

int main(){
	int mat[10][10];
	memset(mat,0,sizeof(mat));
	int x,y,s;
	while(scanf("%d,%d,%d",&y,&x,&s)==3){
		mat[x][y]++;
		if(y-1>=0)mat[x][y-1]++;
		if(x-1>=0)mat[x-1][y]++;
		if(x+1<10)mat[x+1][y]++;
		if(y+1<10)mat[x][y+1]++;
		if(s>1){
			if(x-1>=0 && y-1>=0)mat[x-1][y-1]++;
			if(x+1<10 && y-1>=0)mat[x+1][y-1]++;
			if(x+1<10 && y+1<10)mat[x+1][y+1]++;
			if(x-1>=0 && y+1<10)mat[x-1][y+1]++;
			if(s==3){
				if(y-2>=0)mat[x][y-2]++;
				if(x-2>=0)mat[x-2][y]++;
				if(x+2<10)mat[x+2][y]++;
				if(y+2<10)mat[x][y+2]++;		
			}
		}
	}
	x = 0;
	s = 0;
	int maxi = 0;
	for(x=0;x<10;++x){
		for(y=0;y<10;++y){
			if(mat[x][y] == 0)s++;
			maxi = max(maxi,mat[x][y]);
		}
	}
	cout<<s<<endl<<maxi<<endl;
	return 0;
}

Measured memory_bytes: 1208
def solve():
  while True:
    h,w,n = map(int,input().split())
    if not h: break
    sss = [[1 if s == "1" else 0 for s in input().split()] for i in range(h)]
    dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
    dp[0][0] = n - 1
    for x in range(h):
      for y in range(w):
        a = dp[x][y]
        if sss[x][y]:
          if a % 2:
            dp[x + 1][y] += a // 2
            dp[x][y + 1] += a // 2 + 1
          else:
            dp[x + 1][y] += a // 2
            dp[x][y + 1] += a // 2
        else:
          if a % 2:
            dp[x + 1][y] += a // 2 + 1
            dp[x][y + 1] += a // 2
          else:
            dp[x + 1][y] += a // 2
            dp[x][y + 1] += a // 2
        sss[x][y] = (sss[x][y] + dp[x][y]) % 2
  
  #  print(sss)
  #  print(dp)
    x = y = 0
    while x < h and y < w:
      if sss[x][y]:
        y += 1
      else:
        x += 1
    print(x + 1,y + 1)
  #  print(sss)
solve()


Measured memory_bytes: 30336
#include<stdio.h>

int main() {
	int n, d;
	
	//入力
	scanf("%d%d", &n, &d);

	int ans = 0;
	while (n > 0) {
		ans++;
		n -= 2 * d + 1;
	}

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

Measured memory_bytes: 128
from sys import exit, stdin
from itertools import combinations
N = int(stdin.readline().rstrip())
S = [0]*5
for i in range(N):
    s = stdin.readline().rstrip()
    if s[0] == 'M': S[0] += 1
    if s[0] == 'A': S[1] += 1
    if s[0] == 'R': S[2] += 1
    if s[0] == 'C': S[3] += 1
    if s[0] == 'H': S[4] += 1
ans = 0
for c in list(combinations([0,1,2,3,4], 3)):
    ans += S[c[0]]*S[c[1]]*S[c[2]]
print(ans)

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

int calc(int k){
	int a=0;
	while(k>0){
		a+=k%10;
		k=k/10;
	}
	return a;
}

int main(){
  int N,i;
  cin>>N;
  int ans=10000000;
  for(i=1;i<N;i++){
	ans=min(ans,calc(i)+calc(N-i));
  }
  cout<<ans<<endl;
  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[]){
    string a,b;
    cin >> a >> b;

    a+=b;
    int n=stoi(a);

    bool ans=false;
    for(int i=1;i*i<=n;i++){
        if(i*i==n){
            ans=true;
            break;    
        }
    }

    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3616
from sys import stderr, setrecursionlimit, exit
from math import factorial
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

mod = 10**9 + 7

n, m = getInts()
if abs(n-m) >= 2:
    print(0)
    exit()
else:
    a = factorial(min(n, m))
    if n == m:
        print((((a**2) % mod) * 2 ) % mod)
    else:
        print((((a**2) % mod) * max(m, n)) % mod)

Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    ll K; cin >> K;
    ll m = 0;
    ll f = 7%K;
    ll c = 0;
    while(1){
        c++;
        m += f;
        if(m%K==0) break;
        f = f*10%K;
        m %= K;
        if(c>K){
          cout << -1 << endl;
          return 0;
        }
    }
    cout << c << endl;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector<int> v(m), diff(m-1);
    for (int i = 0; i < m; i++) cin >> v[i];
    sort(v.begin(), v.end());
    for (int i = 0; i < m-1; i++) {
        diff[i] = v[i+1] - v[i];
    }
    sort(diff.begin(), diff.end());
    int ans = 0;
    for (int i = 0; i < m-n; i++) {
        ans += diff[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  while(b<a)
  {
   if(k>0)
   {
	b*=2;
     k--;
   }
    else
      break;
  }
  if(b==a&&k>0)
  {
    b*=2;
    k--;
  }
  while(c<b)
  {
    if(k>0)
    {
      c*=2;
      k--;
    }
    else
      break;
  }
 if(c==b&&k>0)
 {
   c*=2;
   k--;
 }
  if((b>a&&b!=a)&&(c>b&&c!=b))
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}  

Measured memory_bytes: 3164
import java.util.ArrayList;
import java.util.Scanner;




class Main{


	static	ArrayList<Integer> one ;
	static	ArrayList<Integer> two ;
	static	ArrayList<Integer> three ;
	static	ArrayList<Integer> four ;
	static long pow = 1000000007;
	
	static int n;
	static int m;


	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力
		n =sc.nextInt();
		m =sc.nextInt();

		
		char[][] amap = new char[n][n];
		char[][] bmap = new char[m][m];
		
		for(int i = 0;i < n;i++){
			amap[i] = sc.next().toCharArray();
		}
		for(int i = 0;i < m;i++){
			bmap[i] = sc.next().toCharArray();
		}
		
		

		for(int i = 0;i <= n-m;i++){
			for(int j = 0;j <= n-m;j++){					//スタートいち
				
				char[][] test = new char[m][m];
				for(int x = 0;x < m;x++){					//mapの切り出し
					for(int y = 0;y < m;y++){
						test[y][x] = amap[y+i][x+j];
					}
				}
				if(check(test,bmap)){
					System.out.println("Yes");
					return;
				}
			}
			
		}
		System.out.println("No");


	}
	
	static boolean check(char[][] test,char[][] bmap){
		
		for(int i = 0;i < m;i++){
			for(int j = 0;j < m;j++){
				if(test[i][j] != bmap[i][j]){
					return false;
				}
			}
		}
		return true;
		
	}
}



class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 22740
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	class BIT {
		int n;
		long[] a;

		public BIT(int n_) {
			n = n_;
			a = new long[n + 1];
		}

		void add(int k) {
			++k;
			while (k <= n) {
				++a[k];
				k += k & -k;
			}
		}

		long sum(int k) {
			++k;
			long ret = 0;
			while (k > 0) {
				ret += a[k];
				k -= k & -k;
			}
			return ret;
		}

	}

	boolean check(double m, double[][] ps) {

		int n = ps.length;
		Arrays.sort(ps, new Comparator<double[]>() {
			@Override
			public int compare(double[] o1, double[] o2) {
				return Double.compare(o1[0] * m - o1[1], o2[0] * m - o2[1]);
			}
		});

		long tot = n * (n - 1) / 2;
		long t = (tot + 1) / 2;

		long sum = 0;
		BIT bit = new BIT(n);
		for (int i = 0; i < n; ++i) {
			sum += bit.sum((int) ps[i][2]);
			bit.add((int) ps[i][2]);
		}
		return sum >= t;

	}

	double solve(int n, double[] x, double[] y) {
		double[][] ps = new double[n][3];
		for (int i = 0; i < n; ++i) {
			ps[i][0] = x[i];
			ps[i][1] = y[i];
		}
		Arrays.sort(ps, new Comparator<double[]>() {
			@Override
			public int compare(double[] o1, double[] o2) {
				if (o1[0] != o2[0])
					return Double.compare(o1[0], o2[0]);
				else
					return Double.compare(o1[1], o2[1]);
			}
		});

		for (int i = 0; i < n; ++i) {
			ps[i][2] = i;
		}

		double ok = 1e9;
		double ng = -1e9;
		for (int t = 70; t >= 0; --t) {
			double middle = (ok + ng) / 2;
			if (check(middle, ps)) {
				ok = middle;
			} else {
				ng = middle;
			}
		}
		return ok;
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double[] a = new double[n];
		double[] b = new double[n];
		double[] c = new double[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextDouble();
			b[i] = sc.nextDouble();
			c[i] = sc.nextDouble();
		}
		double[] x = new double[n];
		double[] y = new double[n];
		for (int i = 0; i < n; ++i) {
			y[i] = c[i] / b[i];
			x[i] = a[i] / b[i];
		}
		System.out.print(String.format("%.20f", solve(n, x, y)) + " ");
		for (int i = 0; i < n; ++i) {
			y[i] = c[i] / a[i];
			x[i] = b[i] / a[i];
		}
		System.out.println(String.format("%.20f", solve(n, x, y)));
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 159708
n_1,n_2,n_3 = gets.strip.split('').map(&:to_i)

if n_1 < n_2
  n_1 += 1
elsif n_1 == n_2
  if n_2 < n_3
    n_1 += 1
  end
end
puts 100 * n_1 + 10 * n_1 + n_1

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int[] a = sc.nextIntArray(5);
    int k = sc.nextInt();
    for (int i = 0; i < 4; i++) {
      for (int j = i + 1; j < 5; j++) {
        if (a[j] - a[i] > k) {
          System.out.println(":(");
          return;
        }
      }
    }
    System.out.println("Yay!");
  }
}

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

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = in.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int t = Integer.parseInt(lines[1]);
      // int[] cost = new int[n];
      // int[] time = new int[n];
      int cost;
      int time;
      int ans = Integer.MAX_VALUE;

      for(int i=0; i<n; i++) {
        lines = in.readLine().split(" ");
        cost = Integer.parseInt(lines[0]);
        time = Integer.parseInt(lines[1]);
        if(time <= t)
          ans = Math.min(ans,cost);
      }

      System.out.println(ans < 100000 ? ans : "TLE");
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 21332
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

A, B, C = [int(x) for x in input().split()]
ans = max(0,C - (A - B))
print(ans)


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

void no(void) {
	puts("No");
	exit(0);
}

int main(void) {
	int N;
	int zero = 0, one = 0, two = 0;
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		int a;
		if (scanf("%d", &a) != 1) return 1;
		if (a % 4 == 0) two++;
		else if (a % 2 == 0) one++;
		else zero++;
	}
	if (zero > two + 1) no();
	if (zero == two + 1 && one > 0) no();
	puts("Yes");
	return 0;
}


Measured memory_bytes: 128
from itertools import permutations
n,m=map(int,input().split())
g=[]
for i in range(m):
    a,b=map(int,input().split())
    g.append([a,b])
    g.append([b,a])
ans=0
for i in permutations(range(2,n+1),n-1):
    f=0
    if not [1,i[0]] in g:
        continue
    for j in range(n-2):
        if not [i[j],i[j+1]] in g:
            f=1
            break
    if f==0:
        ans+=1
print(ans)


Measured memory_bytes: 41708
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)
#define N_MAX 100005

using namespace std;

typedef long long int Int;

Int dp[N_MAX];
Int h[N_MAX];

Int N,K;

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

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

    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);

    for(int i = 0;i < N;i++) {
        for(int k = 1;k <= K && i-k >= 0;k++) {
            dp[i] = min(dp[i-k]+abs(h[i]-h[i-k]),dp[i]);
        }
    }

    cout<<dp[N-1]<<endl;

    return 0;
}


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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n = 0;
	std::vector<int> a;
	double xa, ya, ra, xb, yb, rb;

#if INPUT_FROM_FILE
	//std::ifstream ifs("test.txt");
	FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	fscanf(fp, "%d", &n);
#else
	scanf("%d", &n);
#endif
	
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		fscanf(fp, "%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);
#else
		scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);
#endif

		double d = sqrt(pow(xa - xb, 2) + pow(ya - yb, 2));

		if(d > ra + rb){
			std::cout << 0 << std::endl;
		}
		else if(d + rb < ra){
			std::cout << 2 << std::endl;
		}
		else if(d + ra < rb){
			std::cout << -2 << std::endl;
		}
		else{
			std::cout << 1 << std::endl;
		}
	}
	return 0;
}


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

using namespace std;

const long long INF = LONG_LONG_MAX;
const int maxsum = (int) (1e5 + 1);
const long long mod = (long long) (1e9 + 7);

double dp[305][305][305];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    int n, x;
    cin >> n;
    vector<int> cnt(4);
    for (int i = 0; i < n; ++i) {
        cin >> x;
        cnt[x]++;
    }
    for (int k = 0; k <= n; ++k) {
        for (int j = 0; j <= n; ++j) {
            for (int i = 0; i <= n; ++i) {
                dp[i][j][k] = 0;
                if (0 < i + j + k && i + j + k <= n) {
                    if (i != 0) dp[i][j][k] += dp[i - 1][j][k] * i;
                    if (j != 0) dp[i][j][k] += dp[i + 1][j - 1][k] * j;
                    if (k != 0) dp[i][j][k] += dp[i][j + 1][k - 1] * k;
                    dp[i][j][k] += n;
                    dp[i][j][k] /= (i + j + k);
                }
            }
        }
    }
    cout << dp[cnt[1]][cnt[2]][cnt[3]] << "\n";
    return 0;
}

Measured memory_bytes: 219520
#include <bits/stdc++.h>
int main() {
	long long n; std::cin >> n;
	std::string name = "";
	while (n-- > 0) {
		name += 'a' + n % 26;
		n /= 26;
	}
	std::reverse(name.begin(), name.end());
	std::cout << name << std::endl;
}

Measured memory_bytes: 3624
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

ll a, b, h;

int main() {
    fast_io; cout_precision;
    cin >> a >> b >> h;
    cout << (((a + b) * h) >> 1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[10009], dp[5009][2];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) scanf("%d", &a[i]);
	for (int i = 0; i <= n >> 1; i++) dp[i][0] = dp[i][1] = 999999999;
	dp[0][0] = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = min(i + 1, n >> 1); j >= 1; j--) {
			dp[j][0] = min(dp[j][0], dp[j][1] + a[i]);
			dp[j][1] = min(dp[j - 1][1], dp[j - 1][0] + a[i]);
		}
	}
	printf("%d\n", min(dp[n >> 1][0], dp[n >> 1][1]));
	return 0;
}

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

using namespace std;

int main(){
    int n;
    int min = 1000000;
    int max = -1000000;
    long sum = 0;

    cin >> n;
    for (int input, i = 0; i < n; i++) {
        cin >> input;
        if (input < min) {
            min = input;
        }
        if (max < input) {
            max = input;
        }
        sum += input;
    }

    cout << min << " " << max << " " << sum << endl;

    return 0;
}


Measured memory_bytes: 3120
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin >> N;
  char c;
  for (int i = 0; i < N; i++) {
    cin >> c;
    if (c == 'Y') {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vector<LP> as(n);
    rep(i, n) as[i].se = i;
    rep(i, n) cin>>as[i].fi;

    sort(rng(as));
    reverse(rng(as));
    ll cur = as[0].se;
    ll acc = 0;
    vl ans(n);
    rep(i, n) {
        if (as[i].se < cur) {
            ans[cur] = acc - as[i].fi * i;
            acc = as[i].fi * i;
            cur = as[i].se;
        }
        acc += as[i].fi;
    }
    ans[0] = acc;
    rep(i, n) cout<<ans[i]<<endl;
}

Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {
	static public void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] tArray = new int[n];
		int[] xArray = new int[n];
		int[] yArray = new int[n];
		for (int i = 0; i < n; i++) {
			tArray[i] = scan.nextInt();
			xArray[i] = scan.nextInt();
			yArray[i] = scan.nextInt();
		}
		scan.close();

		int currentT = 0;
		int currentY = 0;
		int currentX = 0;
		for (int i = 0; i < n; i++) {
			int nextT = tArray[i];
			int nextX = xArray[i];
			int nextY = yArray[i];
			int diffT = nextT - currentT;
			int diffX = nextX - currentX;
			int diffY = nextY - currentY;
			int remainT = diffT - diffX - diffY;
			if (remainT < 0 || (remainT) % 2 == 1) {
				System.out.println("No");
				return;
			}
			currentT = nextT;
			currentX = nextX;
			currentY = nextY;
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 90260
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],n;
int main()
{
	scanf("%d",&n);
	long long ans=0;
	for (int i=1;i<=n;i++)scanf("%d",&a[i]),a[i]-=i;
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	 ans+=abs(a[i]-a[(n+1)/2]);
	printf("%lld",ans); 
} 

Measured memory_bytes: 1024
n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))

T = [[0]*2001 for i in range(n)]

T[0][0] = 1
T[0][A[0]] = 1
for i in range(1,n):
    for j in range(2001):
        T[i][j] = T[i-1][j]
        if (j - A[i] >=0) and (T[i-1][j-A[i]] == 1):
            T[i][j] = 1
    
for i in range(m):
    if T[n-1][B[i]] == 1:
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5932
def main():
    N = int(input())
    p = list(map(float,input().split()))
    dp = [[0]*(N+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(i+1):
            dp[i+1][j] += dp[i][j] * (1-p[i])
            dp[i+1][j+1] += dp[i][j] * p[i]
    print(sum(dp[N][N//2+1:]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 263048
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int dx[]={1,1,0,0,-1,-1};
int dy[]={1,0,1,-1,0,-1};
int ban[200][200];
int bfs[200][200];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<200;i++)for(int j=0;j<200;j++)ban[i][j]=bfs[i][j]=0;
		for(int i=0;i<b;i++){
			int c,d;
			scanf("%d%d",&c,&d);
			c+=100;
			d+=100;
			ban[c][d]=1;
		}
		int p,q;
		scanf("%d%d",&p,&q);
		p+=100;
		q+=100;
		queue<pair<int,int> > Q;
		Q.push(make_pair(p,q));
		bfs[p][q]=a+1;
		while(Q.size()){
			int row=Q.front().first;
			int col=Q.front().second;
			Q.pop();
			if(bfs[row][col]==1)break;
			for(int i=0;i<6;i++){
				if(!bfs[row+dx[i]][col+dy[i]]&&!ban[row+dx[i]][col+dy[i]]){
					bfs[row+dx[i]][col+dy[i]]=bfs[row][col]-1;
					Q.push(make_pair(row+dx[i],col+dy[i]));
				}
			}
		}
		int ret=0;
		for(int i=0;i<200;i++)for(int j=0;j<200;j++)if(bfs[i][j])ret++;printf("%d\n",ret);
	}
}

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

int n,m,q;
vector<int>a,b,c,d;
int score(vector<int>&A){
    int sum = 0;
    rep(i,q){
        if(A[b[i]-1]-A[a[i]-1]==c[i])sum += d[i];
    }
    return sum;
}
int dfs(vector<int>&A){
    
    if(A.size()==n){
        return score(A);
    }
    int lastNum;
    if(A.size()==0)lastNum = 1;
    else lastNum = A.back();
    int ans = 0;
    for(int v = lastNum;v<=m;v++){
        A.push_back(v);
        ans = max(ans,dfs(A));
        A.pop_back();
    }
    return ans;
}
int main(){
    cin >> n >> m >> q;
    a.resize(q),b.resize(q),c.resize(q),d.resize(q);
    rep(i,q)cin >> a[i] >> b[i]>> c[i]>>d[i];
    vector<int>A;
    cout << dfs(A) << endl;
    return 0;
}

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

using namespace std;

bool in_3(int x) {
    while (x) {
        if (x % 10 == 3) return true;
        x /= 10;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0 || in_3(i)) cout << ' ' << i;
    }
    cout << endl;
    return 0;
}


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

using ll=long long;

using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;

int main() {
  int N; cin >>N;
  vi A(N);
  rep(i,0,N) {cin >>A[i];}
  ll ans=0;
  int right=0;
  int sum=0;
  rep(left,0,N) {
    while (right<N && (sum^A[right])==(sum+A[right])) {
      sum+=A[right];
      right++;
    }
    ans+=right-left;
    if (left==right) {
      right++;
    } else {
      sum-=A[left];
    }
  }
  cout <<ans << endl;
  return 0;
}


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

class Main {

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

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

		System.out.println( (int)Math.pow(n, 3) );
	}

}

Measured memory_bytes: 24436
#include<stdio.h>

int main(void){
  char S[11];
  char check;
  int check_c=-1;
  int i;
  int len=0;
  scanf("%s", S);
  check = S[len];
  while(check != '\0'){
    len++;
    check = S[len];
  }

  check = S[0];
  S[0] = 'a';
  if(check != 'A'){
    printf("WA\n");
    return 0;
  }
  for(i=2;i<=len-2;i++){
    if(S[i] == 'C'){
      check_c = i;
      S[i] = 'a';
      break;
    }
  }

  if(check_c == -1){
    printf("WA\n");
    return 0;
  }
  for(i=0;i<=len-1;i++){
    if(S[i] < 97 || S[i] > 122){
      printf("WA\n");
      return 0;
    }
  }
  printf("AC\n");
  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

typedef vector<ll> arr;
typedef vector<arr> mat;

mat eye(ll n){
	mat I(n, arr(n, 0));
	REP(i, n) I[i][i] = 1;
	return I;
}

mat mul(const mat &A, const mat &B){
	mat C(A.size(), arr(B[0].size(), 0));
	REP(i, C.size()){
		REP(j, C[0].size()){
			REP(k, A[0].size()){
				C[i][j] += A[i][k]*B[k][j];
				C[i][j] %= mod;
			}
		}
	}
	return C;
}

mat matpow(const mat &A, ll k){
	mat res = eye(A.size());
	mat tmp = A;
	REP(i, 64){ 
		if(k>>i&1==1){
			res = mul(res, tmp);
		}
		tmp = mul(tmp, tmp);
	}
	return res;
}

int main(){
	ll N, K;
	cin >> N >> K;
	mat a(N, arr(N, 0));
	REP(i, N)REP(j, N) cin >> a[i][j];
	mat r = matpow(a, K);
	ll res = 0;
	REP(i, N)REP(j, N){
		res += r[i][j];
		res %= mod;
	}
	cout << res << endl;
    return 0;
}

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

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

    int k, n;
    cin>>k>>n;

    vector<int> v(n);
    for (int i=0; i<n; i++) cin>>v[i];
    v.push_back(v[0]+k);

    int mx = 0;
    for (int i=0; i<n; i++) mx = max(v[i+1]-v[i], mx);
    cout<<k-mx<<endl;
}


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

ll factorial(ll x){
  if(x == 1 || x == 0){
    return 1;
  }else{
    return x * factorial(x-1);
  }    
}

ll combination(ll n, ll r){
  ll tmp = 1;
  REP(i, r){
    tmp *= n--;
    tmp /= i + 1;
  }
  return tmp;
}

int main(){
  ll n, m;
  cin >> n >> m;

  int odd = 0, even =0;  
  
  if(n <= 1) even = 0;
  else even = combination(n, 2);

  if(m <= 1) odd = 0;
  else odd = combination(m, 2);
  
  int ans = even + odd;

  cout << ans << endl;
}

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

int main()
{
  int array[25];
  int n;
  int now;
  int cnt;
  int turn; //1:ichiro 0:jiro

  while( cin >> n, n ) {
    now = 32;
    turn = 1;
    cnt = 0;
    for(int i=0; i<n; i++) {
      cin >> array[i];
    }

    while( now > 0 ) {
      if( cnt >= n ) cnt = 0;
      if( turn ) {
	now -= (now - 1) % 5;
	turn = 0;
      } else {
	now -= array[cnt];
	cnt++;
	turn = 1;
      }
      cout << max(0, now) << endl;
    }

  }

}

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

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

	int counter = 0;
	while (true) {
		bool has_odd = false;
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 1) has_odd = true;
		}
		if (has_odd == true) break;
		counter++;
		for (int i = 0; i < N; i++) A[i] /= 2;
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

void solve()
{
    ll x,k,d;
    cin>>x>>k>>d;

    x=abs(x);
    ll val=x/d;
    val=min(val,k);
    if((k-val)%2==1){
        val++;
    }

        x-=d*val;
    // if(x>0){
    // }
    // else{
    //     x+=d*val;
    // }

    cout<<abs(x)<<endl;
}

int main()
{
    IOS;
    ll t=1; //cin>>t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(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(){
    char c; cin>>c;
    string a="abcdefghijklmnopqrstuvwxyz";
    rep(i,26){
        if(a[i]==c) cout<<a[i+1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
D=[]
A=[]
for i in range(K):
    d=int(input())
    D.append(d)
    Ai=[int(x) for x in input().split()]
    A.append(Ai)
NUMBERS=[int(x) for x in range(1,N+1)]
for i in range(K):
    for j in range(D[i]):
        if A[i][j] in NUMBERS:
            NUMBERS.remove(A[i][j])
        else:
            pass
print(len(NUMBERS))


Measured memory_bytes: 9176
#include<stdio.h>

int main(){
  int N,sum=0,sum_sq=0,p=0;
  int ans_a=0,ans_b=0;
  scanf("%d",&N);
  int x[N];
  for (int i = 0; i < N; i++)
  {
    scanf("%d",&x[i]);
    sum += x[i];
    sum_sq += x[i]*x[i];
  }
  p = sum / N;
  ans_a = N*p*p-2*sum*p+sum_sq;
  p++;  
  ans_b = N*p*p-2*sum*p+sum_sq;
  printf("%d\n",(ans_a > ans_b ? ans_b:ans_a));

  return 0;
}

Measured memory_bytes: 128
def calc(n, to_metal, to_acorn):
    mas = tuple(zip(to_metal, to_acorn))
    dp = list(range(n + 1))
    for i in range(n + 1):
        for m, a in mas:
            if i >= m:
                dp[i] = max(dp[i], dp[i - m] + a)
    return dp[n]


def main():
    N = int(input())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    N = calc(N, a, b)  # 1 周目 : dp[巣から持ってきたドングリ数] = 取引所 B で持てる最大ドングリ数
    N = calc(N, b, a)  # 2 周目 : dp[取引所 B から持ってきたドングリ数] = 巣に持ち帰れる最大ドングリ数
    print(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 230552
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
    vector<long long> cnt(4, 0);
    for(long long i = 0; i < 3; i++){
        long long a, b;
        cin >> a >> b;
        cnt[a-1]++;
        cnt[b-1]++;
    }

    long long cnt_1 = 0;
    long long cnt_2 = 0;

    for(long long i = 0; i < 4; i++){
        if(cnt[i] == 1) cnt_1++;
        else if(cnt[i] == 2) cnt_2++;
    }

    if(cnt_1 == 2 and cnt_2 == 2) printf("YES\n");
    else printf("NO\n");

    return 0; 
}

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

int main () {
  int N, A;
  cin >> N >> A;
  cout << (N % 500 <= A ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

#define PB push_back  
#define MP(A, B) make_pair(A, B)  
#define fi first  
#define se second  

#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define ll long long  
#define MAX 1000005  
#define MOD 1000000007  
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 


long long A[15][15] = {0}, C[15] = {0}, skill[15] = {0};
long long ans = LONG_MAX;
int n, m, x; 

void dfs(int dep, long long cost) {
    if (dep == n) {
        int flag = 1;
        for (int i = 0; i < m; ++i) 
            if (skill[i] < x) {flag = 0; break;}
        if (flag) ans = min(cost, ans);
        return;
    }
    dfs(dep+1, cost);
    for (int i = 0; i < m; ++i) 
        skill[i] += A[dep][i];
    dfs(dep+1, cost+C[dep]);
    for (int i = 0; i < m; ++i) 
        skill[i] -= A[dep][i];
}

int main()
{
    cin >> n >> m >> x;
    for (int i = 0; i < n; ++i) {
        cin >> C[i];
        for (int j = 0; j < m; ++j) cin >> A[i][j];
    }

    dfs(0, 0);
    if (ans == LONG_MAX)
    cout << -1 << endl;
    else 
    cout << ans << endl;
    return 0;
}

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



void printAll(vector<int> a){
  rep(i,a.size()-1) cout << a[i] << " ";
  cout << a[a.size()-1] << endl;
}

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

  int cnt = 0;

  bool flag = true;
  while(flag){
    flag = false;
    for(int i=N-1;i>0;i--){
      if(a[i]<a[i-1]){
        a[i] = a[i]+a[i-1];
        a[i-1] = a[i]-a[i-1];
        a[i] = a[i]-a[i-1];
        cnt++;
        flag = true;
      }
    }
  }
  
  printAll(a);
  cout << cnt << endl;
}


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

int main(){
    int L,R;
    cin >> L >> R;

    if(L+2019 <= R){
        cout << 0 << endl;
        return 0;
    }

    int mL = L%2019, mR = R%2019;
    if(mL > mR) swap(mL,mR);
    int ans = 2020;
    for(int i = mL;i < mR;i++){
        for(int j = i+1;j <= mR;j++){
            ans = min(ans,i*j % 2019);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
x1,y1,x2,y2 = list(map(int,input().split()))
x3 = x2 -(y2 - y1)
y3 = y2 -(x1 - x2)
x4 = x3 -(y3 - y2)
y4 = y3 -(x2 - x3)

print(x3,y3,x4,y4)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
ios::sync_with_stdio(false);

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

 return 0;
}


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

using namespace std;

const int md = (int) 1e9 + 7;
const int N = 1111111;

inline void add(int& a, int b) {
  a += b;
  if (a >= md) {
    a -= md;
  }
}

inline void sub(int& a, int b) {
  a -= b;
  if (a < 0) {
    a += md;
  }
}

inline int mul(int a, int b) {
  return a * 1LL * b % md;
}

inline int power(int a, long long b) {
  int ret = 1;
  while (b > 0) {
    if (b & 1) {
      ret = mul(ret, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return ret;
}

inline int inv(int a) {
  return power(a, md - 2);
}

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> fact(N);
  fact[0] = 1;
  for (int i = 1; i < N; ++i) {
    fact[i] = mul(fact[i - 1], i);
  }
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  int ans = 0;
  for (int i = b + 1; i <= w; ++i) {
    int cnt = 1;
    cnt = mul(cnt, mul(fact[h - a - 1 + i - 1], mul(inv(fact[h - a - 1]), inv(fact[i - 1]))));
    cnt = mul(cnt, mul(fact[a - 1 + w - i], mul(inv(fact[a - 1]), inv(fact[w - i]))));
    add(ans, cnt);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4608
while True:
    h,w = map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for j in range(w):
            if (i+j)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print() #データセットの区切り


Measured memory_bytes: 7004
#include <stdio.h>
int main(void){
    int n,i,S[13],H[13],C[13],D[13],l;
    char m;
    scanf("%d\n",&n);
    
    for(i=0;i<13;i++){
        S[i]=0;
        H[i]=0;
        C[i]=0;
        D[i]=0;
    }
    
    for(i=0;i<n;i++){
        scanf("%c %d\n",&m,&l);
        if(m=='S'){
            S[l-1]=1;
        }if(m=='H'){
            H[l-1]=1;
        }if(m=='C'){
            C[l-1]=1;
        }if(m=='D'){
            D[l-1]=1;
        }
    }
    for(i=0;i<13;i++){
        if(S[i]==0){
            printf("S %d\n",i+1);
        }
    }for(i=0;i<13;i++){
        if(H[i]==0){
            printf("H %d\n",i+1);
        }
    }for(i=0;i<13;i++){
        if(C[i]==0){
            printf("C %d\n",i+1);
        }
    }for(i=0;i<13;i++){
        if(D[i]==0){
            printf("D %d\n",i+1);
        }
    }
    return 0;
}

Measured memory_bytes: 600
-- Insertion Sort
main = getContents >>= solve

solve :: String -> IO ()
solve = insert [] . map read . tail . words

type Sorted = [Int]
type Disorderd = [Int]
insert :: Sorted -> Disorderd -> IO ()
insert xs [] = printList xs
insert [] (y:ys) = insert [y] ys
insert xs s@(y:ys) = do
  printList (xs ++ s)
  insert (asc y xs) ys

-- sort in ascending order
asc :: Int -> [Int] -> [Int]
asc x [] = [x]
asc x s@(y:ys)
  | x > y = [y] ++ asc x ys
  | otherwise = [x] ++ s

printList :: [Int] -> IO ()
printList = putStrLn . unwords . map show

Measured memory_bytes: 3904
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm> 
#include <functional>	
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((fabs(a - b) <= d&&fabs(c - b)<=d) || fabs(c - a) <= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}







	return 0;
}

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

int main(){
  ll n;
  cin >> n;
  int c=1;//桁数
  ll k=1;//10^c
  
  ll x=n;
  
  while(x>9){
    x/=10;
    k*=10;
    c++;
  }
  
  x=n/k;//nの1番左の数
  
  if(n+1==(x+1)*k) cout << x+9*(c-1) << endl;
  else cout << x+9*c-10 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
std::string S;
std::vector<int> F[2];
bool went[8010][16010];
int x, y;
int main() {
	std::cin >> S;
	std::cin >> x >> y;
	int ac = 0;
	int r = 0;
	for (auto u : S) {
		if (u == 'T') {
			F[ac].push_back(r);
			r = 0;
			ac = (ac + 1) % 2;
		}
		else {
			r++;
		}
	}
	F[ac].push_back(r);
	went[0][8000] = true;
	for (int i = 0; i<F[0].size(); i++) {
		for (int j = 0; j <= 16000; j++) {
			if (i == 0 && S[0] == 'F') {
				went[i + 1][8000 + F[0][i]] = true;
				break;
			}
			if (went[i][j])went[i + 1][j - F[0][i]] = went[i + 1][j + F[0][i]] = true;
		}
	}
	if (!went[F[0].size()][x + 8000]) {
		std::cout << "No" << std::endl;
		return 0;
	}
	for (int i = 0; i <= 8000; i++) {
		for (int j = 0; j<16010; j++) {
			went[i][j] = false;
		}
	}
	went[0][8000] = true;
	for (int i = 0; i<F[1].size(); i++) {
		for (int j = 0; j <= 16000; j++) {
			if (went[i][j])went[i + 1][j - F[1][i]] = went[i + 1][j + F[1][i]] = true;
		}
	}
	std::cout << (went[F[1].size()][8000+y] ? "Yes" : "No") << std::endl;
	return 0;
}

Measured memory_bytes: 125440
#include<iostream>
using namespace std;
static const int MAX_A=100;
int A[MAX_A];
int lcm(int a,int b){return a%b==0?(b):lcm(b,a%b);}
int lcmemo(int n,int *A){
	int j=0;
	for(int i=1;i<=n;i++){
		if(!(n%i))
			A[j++]=i;
	}
	return j;
}
int main(void){
	int a,b,k;
		cin >> a >> b >> k;
	int res=lcm(max(a,b),min(a,b));
	int size=lcmemo(res,A);
	cout << A[size-k] << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();
		String strArr[] = str.split(" ");
		
		int w, h, x, y, r;
		
		w = Integer.parseInt(strArr[0]);
		h = Integer.parseInt(strArr[1]);
		x = Integer.parseInt(strArr[2]);
		y = Integer.parseInt(strArr[3]);
		r = Integer.parseInt(strArr[4]);
		
		if(x+r<=w && x-r>=0 && y+r<=h && y-r>=0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 24452
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define apo ios::sync_with_stdio(false);cin.tie(0)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}

ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
int main(){
	apo;
	ll h1,m1,h2,m2,k,h1_min,h2_min,diff;
	cin>>h1>>m1>>h2>>m2>>k;
	h1_min=h1*60;h2_min=h2*60;
	diff=(h2_min+m2)-(h1_min+m1);
	if(diff<=k){
		cout<<0<<endl;
	}
	else{
		cout<<diff-k<<endl;
	}
}

Measured memory_bytes: 3608
N = int(input())
T = [int(t) for t in input().split()]
M = int(input())
D = []
for i in range(M):
    D.append([int(p) for p in input().split()])
S = sum(T)
for i in range(M):
    print(S + D[i][1] - T[D[i][0]-1])


Measured memory_bytes: 3060