akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
using Int = long long;
using namespace std;
const int MOD = 1000000007;
int MUL(int x, int y) { return ((Int)x * y) % MOD; }
int FACT(int x) {
    int ans = 1;
    for (int i = 2; i <= x; i++) {
        ans = MUL(ans, i);
    }
    return ans;
}
int main()
{
    int N, M; cin >> N >> M;
    if (abs(N - M) >= 2) {
        cout << 0 << endl;
    } else if (abs(N - M) == 1) {
        cout << MUL(FACT(N), FACT(M)) << endl;
    } else {
        cout << MUL(2, MUL(FACT(N), FACT(M))) << endl;
    }
    return 0;
}

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

import math
n = int(input())
A,B = 1,1
for i in range(n):
    t,a = map(int,input().split())
    if A % t == 0:
        na = A//t
    else:
        na = A//t+1
    if B % a == 0:
        nb = B//a
    else:
        nb = B//a+1
    n = max(na,nb)
    A,B = n*t,n*a
print(A+B)


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>

using namespace std;

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

  long int min_v, max_v, sum;
  int x;
  int i;
  sum = 0;
  i = 0;
  while(cin >> x) {
    if(i == 0) {
      min_v = x;
      max_v = x;
    }
    if(x < min_v) min_v = x;
    if(max_v < x) max_v = x;
    sum += x;
    i++;
  }
  printf("%d %d %ld\n", min_v, max_v, sum);
  return 0;
}

Measured memory_bytes: 3212
import java.util.*;
public class Main {

		static void solve() {
			Scanner sc = new Scanner(System.in);
			int k = sc.nextInt();
			String []s = sc.next().split("");
			if(s.length>k) {
				for(int i = 0;i<k;i++) {
					System.out.print(s[i]);
					if(i == k-1) 
						System.out.print("...");
				}
			}
				else if(s.length<=k) {
					for(int i = 0;i<k-(k-s.length);i++)
					System.out.print(s[i]);
				}
			
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

}


Measured memory_bytes: 35600
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 220
// 44

using namespace std;


int dp[101][101];
int arr[101];

map <int, int> mp;

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, j;
    ios::sync_with_stdio(false);
    cin >> n;
    int cnt = 0;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
        if(mp[arr[i]] == 0)
            mp[arr[i]] = ++cnt;
    }
    cnt = n;
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= cnt; j++) {
            dp[i][j] = 1e9;
            for(int last = 1; last <= cnt; last++) {
                if(last != j) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][last] + (mp[arr[i]] != j));
                }
            }
        }
    }
    int ans = 1e9;
    for(i = 1; i <= cnt; i++) {
        ans = min(ans, dp[n][i]);
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{	
	char A,B,C,D;
	cin>>A>>B>>C>>D;
		
		int a=A-'0',b=B-'0', c=C-'0', d=D-'0';
		if(a+b+c+d==7) cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
		else if(a+b+c-d==7) cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
		else if(a+b-c+d==7) cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
		else if(a+b-c-d==7) cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
		else if(a-b+c+d==7) cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
		else if(a-b+c-d==7) cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
		else if(a-b-c+d==7) cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
		else if(a-b-c-d==7) cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
		
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
Ar =list(map(str,input().split()))

S = list(Ar[0])
T = list(Ar[1])

Ans_Ar = []

for i in range(N):
  Ans_Ar.append(S[i])
  Ans_Ar.append(T[i])

result = ''.join(Ans_Ar)
print(result)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
    int k, s;
    scanf("%d%d", &k, &s);
    int x, y, z, count = 0;
    for(x = 0; x <= k; x++){
        for(y = 0; y <= k; y++){
            z = s-x-y;
            if(k >= z && z >= 0){
                count++;
            }
        }
    }
    printf("%d\n", count);
}    





Measured memory_bytes: 1700
#include <iostream>
using namespace std;
int main(void){
 int E,Y;
 cin >> E >> Y;
 int A = Y - 1867;
 int B = Y - 1911;
 int C = Y - 1925;
 int D = Y - 1988;
 int a = Y + 1867;
 int b = Y + 1911;
 int c = Y + 1925;
 int d = Y + 1988;
 
  if(1868 <= Y && Y <= 1911){
   cout << "M" << A << endl;
  }
  else if(1912 <= Y &&Y <= 1925){
   cout << "T" << B << endl;
  }
  else if(1926 <= Y &&Y <= 1988){
   cout << "S" << C << endl;
  }
  else if(1989 <= Y &&Y <= 2016){
   cout << "H" << D << endl;
  }
  
  else if(E == 1){
   cout << a << endl;
  }
  else if(E == 2){
   cout << b << endl;
  }
  else if(E == 3){
   cout << c << endl;
  }
  else if(E == 4){
   cout << d << endl;
  }
} 


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, m; std::cin >> n >> m;
    std::vector<std::vector<int>>
        a(n, std::vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            std::cin >> a[i][j];
            a[i][j]--;
        }
    }
    bool used[303] = {};
    auto func = [&](auto &self, int pos = 0) -> int {
        if (pos >= m) return 1e9;
        std::vector<int> cnt(m);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (used[a[i][j]]) continue;
                cnt[a[i][j]]++;
                break;
            }
        }
        int ma = 0, p = 0;
        for (int i = 0; i < m; i++) {
            if (ma < cnt[i]) {
                ma = cnt[i];
                p = i;
            }
        }
        used[p] = true;
        return std::min(ma, self(self, pos + 1));
    };
    std::cout << func(func) << std::endl;
    return 0;
}


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

int main() {
  int x,y,X,Y;
  cin >> x >> y ;
  X=(x+y)/2;
  Y=(x+y)%2;
  if (Y==0){
    cout << X << endl;
  }
  else {
    cout << X+1 <<endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		while(true){
			int n=int.Parse(Console.ReadLine());
			if(n==0)break;
			Sol mySol =new Sol(n);
			mySol.Solve();
		}
	}
}

class Sol{
	public void Solve(){
		Dictionary<String,Page> D=new Dictionary<String,Page>();
		
		List<String> buf=new List<String>();
		String EOB="nullnullnullnullnullnull";
		
		for(int i=0;i<N;i++){
			var s=rsa();
			var P=new Page();
			P.Name=s[0];
			P.LCount=int.Parse(s[1]);
			P.LinkName=new String[P.LCount];
			P.LinkArea=new Area[P.LCount];
			for(int j=0;j<P.LCount;j++){
				s=rsa();
				Area A=new Area(int.Parse(s[0]),int.Parse(s[1]),int.Parse(s[2]),int.Parse(s[3]));
				P.LinkArea[j]=A;
				P.LinkName[j]=s[4];
			}
			D.Add(P.Name,P);
			if(i==0){
				buf.Add(P.Name);
				buf.Add(EOB);
			}
		}
		
		int q=ri();
		String order="";
		int cur=0;
		
		for(int i=0;i<q;i++){
			order=rs();
			switch(order[0]){
				case 'c':
					var ss=order.Split(' ');
					int px=int.Parse(ss[1]);
					int py=int.Parse(ss[2]);
					String trgt="";
					for(int j=0;j<D[buf[cur]].LCount;j++){
						if(D[buf[cur]].LinkArea[j].xmin<=px &&
						   D[buf[cur]].LinkArea[j].xmax>=px &&
						   D[buf[cur]].LinkArea[j].ymin<=py &&
						   D[buf[cur]].LinkArea[j].ymax>=py ){
							trgt=D[buf[cur]].LinkName[j];
							break;
						}
					}
//Console.WriteLine("trgt:{0}",trgt);
					if(trgt!=""){
						cur++;
						buf[cur]=trgt;
						if(cur==buf.Count-1){
							buf.Add(EOB);
						}else{
							buf[cur+1]=EOB;
						}
					}
				break;
				case 'f':
					if(cur+1<buf.Count&&buf[cur+1]!=EOB)cur++;
				break;
				case 'b':
					if(cur-1>=0)cur--;
				break;
				case 's':
					Console.WriteLine(buf[cur]);
				break;
			}
		}
		
	}
	

	int N;
	//int W;
	//int H;
	public Sol(int n_){
		N=n_;
		rs();
		//var d=ria();
		//W=d[0];H=d[1];
	}

	class Page{
		public String Name;
		public String[] LinkName;
		public Area[] LinkArea;
		public int LCount;
		public Page(){
		}
	}
	class Area{
		public int xmin;
		public int xmax;
		public int ymin;
		public int ymax;
		public Area(int in0,int in1,int in2,int in3){
			xmin=in0;
			ymin=in1;
			xmax=in2;
			ymax=in3;
		}
	}


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

Measured memory_bytes: 5720
import random


def main():
    nvertices, nedges = map(int, input().split())
    INF = float('inf')
    W = [[0 if i == j else INF for i in range(nvertices)] for j in range(nvertices)]
    for i in range(nedges):
        u, v, w = map(int, input().split())
        W[u][v] = w

    lst = [i for i in range(nvertices)]
    random.shuffle(lst)
    for k in lst:
        for i in range(nvertices):
            for j in range(nvertices):
                W[i][j] = min(W[i][j], W[i][k] + W[k][j])

    for i in range(nvertices):
        if W[i][i] < 0:
            print("NEGATIVE CYCLE")
            return

    for lst in W:
        print(" ".join(map(lambda e: str(e) if e < INF else "INF", lst)))


main()

Measured memory_bytes: 12016
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int h,w;
string s[60];
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool dfs(int sx, int sy){
    bool ok =  0;
    rep(i,4){
        int nx = sx + dx[i], ny = sy + dy[i];
        if(nx<h && nx>=0 && ny<w && ny>=0){
            if(s[nx][ny]=='#') ok = 1;
        }
    }
    return ok;
}
int main(){
    cin >> h >> w;
    rep(i,h) cin >> s[i];
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'){
                if(dfs(i,j)==0){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
    a[i] = min(a[i], K);
  }
  vector<vector<int>> dp(N + 1, vector<int>(K + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++){
    for (int j = 0; j <= K; j++){
      int next = min(j + a[i], K);
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;
      dp[i + 1][next] += dp[i][j];
      dp[i + 1][next] %= MOD;
    }
  }
  vector<vector<int>> dp2(N + 1, vector<int>(K + 1, 0));
  dp2[N][0] = 1;
  for (int i = N - 1; i >= 0; i--){
    for (int j = 0; j <= K; j++){
      int next = min(j + a[i], K);
      dp2[i][j] += dp2[i + 1][j];
      dp2[i][j] %= MOD;
      dp2[i][next] += dp2[i + 1][j];
      dp2[i][next] %= MOD;
    }
  }
  for (int i = 0; i <= N; i++){
    for (int j = K - 1; j >= 0; j--){
      dp2[i][j] += dp2[i][j + 1];
      dp2[i][j] %= MOD;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++){
    long long cnt = 0;
    for (int j = 0; j <= K; j++){
      cnt += (long long) dp[i][j] * dp2[i + 1][K - j] % MOD;
    }
    cnt %= MOD;
    if (cnt * 2 % MOD == dp[N][K]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 199080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	string s;
	cin >>s;
	int n = s.size();
	int K;cin>>K;
	vector<string> S;
	for(int l = 1;l<=5;l++)
	{
		for(int i = 0;i<n-l+1;i++)
		{
			string ireru;
			for(int j=i;j<i+l;j++)
			{
				ireru.push_back(s[j]);
			}
			S.push_back(ireru);
		}
	}
	sort(S.begin(),S.end());
	int now = 1;
	if(K==1)
	{
		cout<<S[0]<<endl;
		return 0;
	}
	//for(auto a=S.begin();a!=S.end();a++)cout<<*a<<endl;
	for(int i = 0;i<S.size()-1;i++)
	{
		
		if(S[i]!=S[i+1])
		{
			now++;
			if(now==K)
			{
				cout<<S[i+1]<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1660
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  goto yarudake;
yarudake:
  int n;
  while (cin >> n, n) {
    vi a(n);
    rep(i, n) cin >> a[i];
    int totalSwapTime = 0;
    for (;;) {
      int partialSwapTime = 0;
      loop(i, 1, n) {
        if (a[i - 1] <= a[i]) continue;
        swap(a[i - 1], a[i]);
        partialSwapTime++;
      }
      totalSwapTime += partialSwapTime;
      if (!partialSwapTime) break;
    }
    cout << totalSwapTime << endl;
  }
}

Measured memory_bytes: 3072
import numpy as np
N=int(input())
A=np.array(list(int(i) for i in input().split())  )
B=np.array(list(int(i) for i in input().split())  )

num=np.sum(A)

for i in range(len(B)):
    if A[i]<=B[i]:
        B[i]=B[i]-A[i]
        A[i]=0
    else:
        A[i]=A[i]-B[i]
        B[i]=0
    if A[i+1]>=B[i]:
        A[i+1]=A[i+1]-B[i]
    else:
        A[i+1]=0
        B[i]=B[i]-A[i+1]
print(num-np.sum(A))     

Measured memory_bytes: 24832
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, Q = map(int, input().split())
s = input()[:-1]
acc = [0]*(N+1)
prev = ""
for i, c in enumerate(s):
    if c == "C" and prev == "A":
        prev = c
        acc[i+1] = 1
    else:
        prev = c
for i in range(len(acc)-1):
    acc[i+1] += acc[i]
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(acc[r]-acc[l])
for a in ans:
    print(a)


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

using namespace std;

ll n, W, w[MAXN], v[MAXN], dp[102][MAXN];
ll inf = 1e16;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> W;
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < MAXN; j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    dp[0][v[0]] = w[0];
    for(int i = 1; i < n; i++){
        for(int j = 0; j < MAXN; j++){
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            dp[i][j + v[i]] = min(dp[i][j + v[i]], dp[i - 1][j] + w[i]);
        }
    }
    for(int i = MAXN - 1; i >= 0; i--){
        if(dp[n - 1][i] <= W){
            cout << i;
            break;
        }
    }
}

Measured memory_bytes: 162048
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int N, X;
  cin >> N >> X;
  vector<int> L(N);
  for(int i = 0; i < N; i++){
    cin >> L.at(i);
  }
  vector<int> x(0);
  x.push_back(0);
  for(int i = 1; i < N+1; i++){
    int a = x.at(x.size()-1) + L.at(i-1);
    if(a <= X) x.push_back(a);
    else break;
  }
  cout << x.size() << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> ans(100002);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    ans.at(a)++;
    ans.at(a+1)++;
    ans.at(a+2)++;
  }
  sort(ans.begin(),ans.end());
  
  cout << ans.at(100001) << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec(m);
  rep(i,m) cin >> vec.at(i).first >> vec.at(i).second;
  bool b = true;
  if(n == 3){
    for(int i = 100; i < 1000; i++) {
      string s = to_string(i);
      bool a = true;
      rep(j,m) {
        string c = to_string(vec.at(j).second);
        if(s.at(vec.at(j).first-1) != c.at(0)) a = false;
      }
      if(a) {
        cout << i << endl;
        b = false;
        break;
      }
    }
  }
  if(n == 2){
    for(int i = 10; i < 100; i++) {
      string s = to_string(i);
      bool a = true;
      rep(j,m) {
        string c = to_string(vec.at(j).second);
        if(s.at(vec.at(j).first-1) != c.at(0)) a = false;
      }
      if(a) {
        cout << i << endl;
        b = false;
        break;
      }
    }
  }
  if(n == 1){
    for(int i = 0; i < 10; i++) {
      string s = to_string(i);
      bool a = true;
      rep(j,m) {
        string c = to_string(vec.at(j).second);
        if(s.at(vec.at(j).first-1) != c.at(0)) a = false;
      }
      if(a) {
        cout << i << endl;
        b = false;
        break;
      }
    }
  }
  if(b) cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x, y =  map(int, readline().split())

if x < y:
    x, y = y, x

b = (2 * x - y) // 3 
if (2 * x - y) % 3  != 0:
    print(0)
    exit()

a = x - 2 * b
if a < 0:
    print(0)
    exit()

MOD = 10 ** 9 + 7
a %= MOD
b %= MOD

MAX = 10 ** 6 * 2 + 2
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod
    
comInit(MOD)
print(com(a + b, b, MOD))

Measured memory_bytes: 133420
n = gets.chomp.to_i
ans = 0
sqrt = Math.sqrt(n).to_i
1.upto(sqrt) do |a|
    maxb = n / a
    1.upto(maxb) do |b|
        if a * b < n then
            if a == b then
                ans += 1
            elsif a < b then
                ans += 2
            end
        end
    end
end
puts ans

Measured memory_bytes: 14316
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 305;

double dp[MX][MX][MX];

int main() {
  int n;
  scanf("%d",&n);
  vi a(3);
  rep(i,n) {
    int x;
    scanf("%d",&x);
    a[x-1]++;
  }
  double p = 1.0/n;
  rep(k,n+1)rep(j,n+1)rep(i,n+1) {
    int z = n-i-j-k;
    if (z < 0) break;
    if (z == n) continue;
    double x = 1-z*p;
    if (i) dp[i][j][k] += dp[i-1][j][k]*i*p;
    if (j) dp[i][j][k] += dp[i+1][j-1][k]*j*p;
    if (k) dp[i][j][k] += dp[i][j+1][k-1]*k*p;
    dp[i][j][k] += 1;
    dp[i][j][k] /= x;
  }
  printf("%.10f\n",dp[a[0]][a[1]][a[2]]);
  return 0;
}






















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

int N,M;
string board[60];
string pattern[60];

bool match(int x, int y) {
  int i,j;
  for(i=0; i<M; i++) {
    for(j=0; j<M; j++) {
      if(board[x+i][y+j] != pattern[i][j])
        return false;
    }
  }
  return true;
}


int main() {
  cin >> N >> M;
  int i, j;
  for(i=0; i<N; i++) cin >> board[i];
  for(i=0; i<M; i++) cin >> pattern[i];

  bool found = false;
  for(i=0; i<=N-M; i++) {
      for(j=0; j<=N-M; j++) {
          if(match(i,j)) found = true;
      }
  }
  cout << (found ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int x;
  cin >> x;
  cout << (x+1)%2 << endl;
}

Measured memory_bytes: 3648
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
	cin>> a >> b;
	cout << max({a+b,a-b,a*b});
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


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

#define N 200123
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define fastio ios::sync_with_stdio(false); cin.tie(0)

int main(){
    fastio;
 	int n;
 	ll a[N], b, sum = 0;
 	cin >> n;
 	for(int i = 0 ; i <= n ; i++)
 		cin >> a[i];
 	for(int i = 0 ; i < n ; i++){
 		cin >> b;
 		for(int j = 0 ; j < 2 ; j++){
 			if(a[i+j] > b){
 				sum += b;
 				a[i+j] -= b;
 				b = 0;
 			} else {
 				sum += a[i+j];
 				b -= a[i+j];
 				a[i+j] = 0;
 			}
 		}
 	}
 	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
int main(){
	int p; std::cin >> p;
	std::vector<int> number(p); for (auto& a : number) std::cin >> a;
	std::vector<int> coefficient(p, 0);
	std::vector<int> factorial(p, 1), inverse(p, 1), inverse_factorial(p, 1);
	for (auto i = 2; i < p; ++i) {
		factorial[i] = i * factorial[i - 1] % p;
		inverse[i] = (p - p / i) * inverse[p % i] % p;
		inverse_factorial[i] = inverse[i] * inverse_factorial[i - 1] % p;
	}
	for (auto i = 0; i < p; ++i) {
		auto base = -1;
		if (number[i] == 1) {
			for (auto d = 1; d <= coefficient.size(); ++d) {
				coefficient[p - d] += base * factorial[p - 1] % p * inverse_factorial[p - d] % p * inverse_factorial[d - 1] % p;
				base *= -i;
				base %= p;
				coefficient[p - d] %= p;
			}
			coefficient[0]++;
		}
	}
	for (auto i = 0; i < coefficient.size(); ++i) {
		if (i != 0) std::cout << ' ';
		std::cout << (coefficient[i] % p + p) % p;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N,M;cin>>N>>M;
  vector<vector<int>> G(N);
  int a,b;
  REP(i,0,M){
    cin>>a>>b;
    a--;b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  vector<int> ans(N,-1);
  ans[0]=0;
  queue<int> que;
  que.push(0);
  while(que.size()){
    int q=que.front();que.pop();
    // debug(G[q]);
    each(e,G[q]){
      // print(e,q,ans[e]);
      if(ans[e]!=-1)continue;
      ans[e]=q;
      que.push(e);
    }
  }
  REP(i,1,N){
    a=ans[i];
    if(a==-1){
      print("No");
      re 0;
    }
    ans[i]=a+1;
  }
  print("Yes");
  REP(i,1,N){
    print(ans[i]);
  }

}


Measured memory_bytes: 12988
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class BTimeLimitExceeded {
public:
	void solve(istream& in, ostream& out) {
	    int n, T; in >> n >> T;
	    vector<int> c(n),t(n);
	    rep(i,n) in >> c[i] >> t[i];
	    int ans = 1e6;
	    rep(i,n) {
	        if(T >= t[i]) {
	            ans = min(ans,c[i]);
	        }
	    }
	    if(ans != 1e6) out << ans << endl;
	    else out << "TLE" << endl;
	}
};

int main() {
	BTimeLimitExceeded solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll dp[55][3333][55];



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


  cin >> n >> m;
  dp[0][0][0]++;

  rep(i, n) {
    rep(k, n*n + 1) rep(j, i + 1) {
      (dp[i + 1][k + 2*(j + 1)][j + 1] += dp[i][k][j]) %= mod;
      (dp[i + 1][k + 2 * j][j] += dp[i][k][j]) %= mod;
      (dp[i + 1][k + 2 * j][j] += dp[i][k][j] * 2 * j) %= mod;
      if (j) (dp[i + 1][k + 2 * (j - 1)][j - 1] += dp[i][k][j] * j*j) %= mod;
    }
  }

  cout << dp[n][m][0] << endl;


  return 0;
}


Measured memory_bytes: 72576
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

H, W = mi()
cells = [input() for _ in range(H)]

ispossible = 1
for y, row in enumerate(cells):
  for x, cell in enumerate(row):
    if cell == '.': continue
    else: #cellが'#'だった場合
      ispossible = 0
      #移動する座標を(0, -1)などの形にしてsetにする
      dirset = {(0,1), (0,-1), (1,0), (-1,0)}
      if y == 0: #一番上だった場合
        dirset.remove((0,-1)) #上にはいかない
      elif y == H-1: #一番下だった場合
        dirset.remove((0,1)) #下にはいかない
      if x == 0: #いちばん左だった場合
        dirset.remove((-1,0)) #左にはいかない
      elif x == W-1: #いちばん右だった場合
        dirset.remove((1,0)) #右にはいかない
      for mx, my in dirset: #mx, myはx,yの移動量
        if cells[y+my][x+mx] == '#':
          ispossible = 1
          break
      if ispossible == 0:
        print('No')
        exit()

print('Yes')



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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

ll N[100001] = {0};

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

    
    REP(i,n){
        int a,b;
        cin >> a >> b;
          
        N[a] += b;
    }

    ll ans = 0;
    REP(i,100001){
        ans += N[i];
        if(ans >= k){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    int A[3][3];
    int N;
    int B[12];

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

    cin >> N;

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

    for (int i = 0; i < N; ++i) {

        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (A[j][k] == B[i]) A[j][k] = 0;
            }
        }
    }

    string ans = "No";
    if (A[0][0] == 0 && A[0][1] == 0 && A[0][2] == 0) ans = "Yes";
    if (A[1][0] == 0 && A[1][1] == 0 && A[1][2] == 0) ans = "Yes";
    if (A[2][0] == 0 && A[2][1] == 0 && A[2][2] == 0) ans = "Yes";

    if (A[0][0] == 0 && A[1][0] == 0 && A[2][0] == 0) ans = "Yes";
    if (A[0][1] == 0 && A[1][1] == 0 && A[2][1] == 0) ans = "Yes";
    if (A[0][2] == 0 && A[1][2] == 0 && A[2][2] == 0) ans = "Yes";

    if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) ans = "Yes";
    if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0) ans = "Yes";

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


Measured memory_bytes: 256
n = int(input())
T, A = map(int,input().split())
h = [int(i) for i in input().split()]
min_T = abs(T - h[0]*0.006 - A)
i_min = 0

for i,v in enumerate(h):
    if (min_T > abs(T - h[i]*0.006 - A)):
        min_T = abs(T - h[i]*0.006 - A);
        i_min = i
print(i_min+1)

Measured memory_bytes: 3064
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
x1 = x
x2 = x

while x1 < n+1:
    x1 += 1
    if x1 in a:
        cnt1 += 1

while x2 > 0:
    x2 -= 1
    if x2 in a:
        cnt2 += 1



if cnt1 < cnt2:
    ans = cnt1
else:
    ans = cnt2

print(ans)


Measured memory_bytes: 8972
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int,int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int mp[1000006];
int m[1000006];
int vis[1000006];
int main()
{
    ios;
    int n;
    cin>>n;
    int ar[n];

    f(i,0,n)cin>>ar[i],m[ar[i]]++;
    if(n==1){
     cout<<1;
     return 0;
    }
    int p=0;
    f(i,1,n)
    {
        if(ar[i]!=ar[i-1])p=1;
    }
    if(p==0)
    {
        cout<<0;
        return 0;

    }
    sort(ar,ar+n);

    f(i,0,n)
    {
        if(vis[ar[i]]==0)
        for(ll j=2*ar[i]; j<=ar[n-1]; j+=ar[i])
        {
            if(m[j]>0)
            {
                mp[j]++;
            }
            vis[j]++;
        }
    }
    int c=0;
    f(i,0,n)
    {
        //cout<<mp[ar[i]]<<" ";
        if(m[ar[i]]==1&&mp[ar[i]]==0)c++;
    }
    cout<<c;
}


Measured memory_bytes: 16084
import java.util.*;

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

        int[] bells = new int[3];

        bells[0] = sc.nextInt();
        bells[1] = sc.nextInt();
        bells[2] = sc.nextInt();

        Arrays.sort(bells);

        System.out.print(bells[0]+bells[1]);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int dp[maxn][4];
int main()
{
    int n;
    cin>>n;
    int ans =0;
    for(int i=1;i<=n;i++)
    {
        cin>>dp[i][1]>>dp[i][2]>>dp[i][3];
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3]);
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3]);
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2]);
        ans = max(dp[i][1],max(dp[i][2],dp[i][3]));
    }
//    for(int i=1;i<=3;i++)
//        ans=max(ans,dp[n][i]);
    cout<<ans<<endl;
}


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

int main(){
    int x,y;
    scanf("%d %d", &x, &y);
    if(1 <= x && x <= 9 && 1 <= y && y <= 9)
        printf("%d", x * y );
    else
        printf("-1");
}

Measured memory_bytes: 128
/*
	written by Pankaj Kumar.
	country:-INDIA
*/
#include<algorithm>
#include<string.h>
#include<iostream>
#include<vector>
#include<deque>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll ;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef set<string> ss;
typedef set<int> si;
typedef set<ll> sl;
typedef set<pair<int,int>> spi;
typedef set<pair<ll,ll>> spl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007;
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define second ss
#define mp make_pair
#define line cout<<endl;
#define pb push_back
#define INT_SIZE sizeof(int)
#define INT_BITS INT_SIZE*8-1
// function
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res*=x;
		y/=2; x*=x;
	}
	return res;
}
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  -----------------------------------------------------------------------------------*/


int main()
{
	int s,w;
	cin>>s>>w;
	if(s<=w)
		cout<<"unsafe"<<endl;
	else
		cout<<"safe"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

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

int prime[1000000];
bool isprime[1000001];

int sieve(int n){
	int p=0;
	for(int i=0;i<=n;i++)isprime[i]=true;
	isprime[0]=isprime[1]=false;
	for(int i=0;i<=n;i++){
		if(isprime[i]){
			prime[p++]=i;
			for(int j=i*2;j<=n;j+=i)isprime[j]=false;
		}
	}
	return p;
}

int n;

int main(){
	sieve(1<<15);
	while(cin>>n&&n){
		int ans=0;
		rep(i,n/2+1)if(isprime[i]&&isprime[n-i])ans++;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	string s;
	cin >> s;
	char ans[2];
	ans[0] = s[0];
	int ans1 = 1;
	int ans2 = 0;

	for(int i = 1; i < 4;i++)
	{
		if (s[i] == ans[0])
		{
			ans1++;
		}
		else if(ans2==0)
		{
			ans[1] = s[i];
			ans2++;
		}
		else if (ans[1] == s[i])
		{
			ans2++;
		}
	}

	if (ans1 == 2 && ans2 == 2)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
  char str1[100001];
  int i,len,score;
  scanf("%s",str1);
  len = strlen(str1);
  for(i=0;i<len;i+=2){
    if(str1[i]=='p'){
      score--;
    }
  }
  for(i=1;i<len;i+=2){
    if(str1[i]=='g'){
      score++;
    }
  }
  printf("%d\n",score);
  return 0;
}


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


int main()
{
    int i,j,k,n,m,x,p[200],l;
    cin>>n>>m;
    vector<int> v[20];
    for(i=0;i<m;i++){
        cin>>k;
        for(j=0;j<k;j++){
            cin>>x;
            v[i].push_back(x);
        }
    }
    for(i=0;i<m;i++){
        sort(v[i].begin(),v[i].end());
    }
    for(i=0;i<m;i++)
        cin>>p[i];
    int ans=0;
    for(i=0;i<(1<<n);i++){
        int cnt=0,flag[m]={0};
        vector<int> vv;
        for(j=0;j<10;j++){
            if((1<<j)&i){
                vv.push_back(j+1);
            }
        }
        for(j=0;j<m;j++){
            for(k=0;k<v[j].size();k++){
                for(l=0;l<vv.size();l++){
                    if(v[j][k]==vv[l])
                        flag[j]++;
                }
            }
        }
        for(j=0;j<m;j++){
            if(flag[j]%2==p[j])
                cnt++;
        }
        if(cnt==m)
            ans++;
        
    }
    cout<<ans;
    
}


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

#define MAX 100

void initialize(void);
int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);

int top;
int S[MAX];

int main(){
  int a,b;
  char arr[MAX];
  
  initialize();

  while(scanf("%s",arr)!=EOF){
    if(arr[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if(arr[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }else if(arr[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }else{
      push(atoi(arr));
    }
  }

  printf("%d\n",S[top]);
 

  return 0;
}

void initialize(){
  top=0;
}

int isEmpty(){
  if(top==0){
    return 0; //empty
  }else{
    return 1;
  }
}
int isFull(){
  if(top>=MAX){
    return 1; //full
  }else{
    return 0;
  }
}

void push(int x){
  int full;

  full=isFull();

  if(full==1){
    fprintf(stderr,"overflow\n");
  }
  
  top++;

  S[top]=x;
}

int pop(){
  int emp;

  emp=isEmpty();

 if(emp==0){
    fprintf(stderr,"underflow\n");
  }
  
  top--;

  return S[top+1];
}

Measured memory_bytes: 548
n, m = [int(x) for x in input().split()]
A = [input() for i in range(n)]
B = [input() for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    if [a[j:j+m] for a in A[i:i+m]] == B:
      print('Yes')
      break
  else:
    continue
  break
else:
  print('No')


Measured memory_bytes: 3060
fun main (args: Array<String>) {
	var num1 : String?
	var num2 : Int
	
	var list : MutableList<Int> = mutableListOf()
	var count : Int = 0
	
	for (i in 0..4) {
		num1 = readLine()
		num2 = num1!!.toInt()
		list.add(num2)
	}
	
	val num3 = readLine()
	val k = num3!!.toInt()
	
	var p : Int
	var q : Int
	
	for (i in 0..list.size - 1) {
		p = list[i]
		for (j in 0..list.size - 1) {
			q = list[j]
			if ( (p-q)>k || (p-q)<-k ) {
				count++
			}
		}
	}
	
	if (count >= 1) {
		println(":(")
	} else {
		println("Yay!")
	}
	
}

Measured memory_bytes: 33604
n,m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
a = Hash.new(0)
x.each do |i|
    a[i] += 1
end
b = Array.new(m,0)
ans = 0
a.keys.each do |i|
    if a[i]%2 == 1
        b[i%m] += 1
        a[i] -= 1
    end
end
for i in 0..m-1
    if i != (m-i)%m
        c = (b[i] < b[(m-i)%m] ? b[i] : b[(m-i)%m])
        ans += c
        b[i] -= c
        b[(m-i)%m] -= c
    else
        ans += b[i]/2
        b[i] %= 2
    end
end
a.keys.each do |i|
    if b[(m-i%m)%m] > 1 && a[i] > 1
        c = (b[(m-i%m)%m]/2 < a[i]/2 ? b[(m-i%m)%m]/2 : a[i]/2)
        ans += c*2
        b[(m-i%m)%m] -= c*2
        a[i] -= c*2
        ans += a[i]/2
    else
        ans += a[i]/2
    end
end
puts ans

Measured memory_bytes: 16916
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop") 
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
string an;
ll fl[3001][3001];
ll dp[3001][3001];
ll maxval(char s[],char t[],ll i,ll j){
	if(i==-1||j==-1){
		return 0;
	}

	if(dp[i][j]!=-1){
		return dp[i][j];
	}

	if(s[i]==t[j]){
		fl[i][j]=0;
		return dp[i][j]=(1+maxval(s,t,i-1,j-1));
	}

	ll a,b;
	a=maxval(s,t,i-1,j);
	b=maxval(s,t,i,j-1);
	if(a>b){
		fl[i][j]=1;
		return dp[i][j]=a;
	}
	else {
		fl[i][j]=2;
		return dp[i][j]=b;
	}
}
void ans(char s[],char t[],ll i,ll j){
	if(i==-1||j==-1){
		return ;
	}

	if(fl[i][j]==0){
		an=an+s[i];
		ans(s,t,i-1,j-1);
	}
	else if(fl[i][j]==1){
		ans(s,t,i-1,j);
	}
	else {
		ans(s,t,i,j-1);
	}
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	memset(dp,-1,sizeof(dp));

	char s[3001],t[3001];
	cin>>s>>t;

	ll k=maxval(s,t,strlen(s)-1,strlen(t)-1);
	//cout<<k<<endl;
	ans(s,t,strlen(s)-1,strlen(t)-1);
	an[k]='\0';
	reverse(all(an));
	cout<<an<<endl;
	return 0;
}
//ctrl H replace

Measured memory_bytes: 141312
#include<stdio.h>
int main(void){
  double a,b,c,d,e,f;
  double x,y;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
    x = (e*c-b*f)/(a*e-b*d);
    y = (a*f-c*d)/(a*e-b*d);
    if(x==-0.0)x = 0;
    if(y==-0.0)y = 0;
    printf("%.3f %.3f\n",x,y);
  }
  return(0);
}

Measured memory_bytes: 1712