akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n;
	vector<ll>list;
	ll sum = 0, sum2 = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		ll num;
		cin >> num;
		list.push_back(num);
	}

	bool flag; // falseでマイナス、trueでプラス
	ll ima = list[0];
	if (ima == 0) {
		ima = 1;
		sum += 1;
	}

	int index = 0;



	for (int i = index + 1; i < n; i++) {
		//ima = list[i];

		if (ima <= 0) {
			flag = false;
		}
		else {
			flag = true;
		}

		ima += list[i];

		if (flag == false) {
			if (ima <= 0) {
				sum += abs(ima) + 1;
				//ima += abs(ima) + 1;
				ima = 1;
			}
		}
		else if (flag == true) {
			if (ima > 0) {
				sum += abs(ima) + 1;
				//ima -= abs(ima) - 1;
				ima = -1;
						
			}
		}
	}

   ima = list[0];
 

	//for (int i = 0; i < n; i++) {
	//	if (list[i] == 0)continue;
	//	index = i;
	//	ima = list[i];
	//	break;
	//}

   if (ima == 0) {
	   ima =  -1;
	   sum2 += 1;
   }
   else if (ima < 0) {
   //if (ima < 0) {
	   sum2 += abs(ima) + 1;
	   ima = 1;
   }
   else if (ima > 0) {
   //else if (ima >= 0) {
	   sum2 += abs(ima) + 1;
	   ima = -1;
   }


	for (int i = index + 1; i < n; i++) {

		if (ima <= 0) {
			flag = false;
		}
		else {
			flag = true;
		}

		ima += list[i];

		if (flag == false) {
			if (ima <= 0) {
				sum2 += abs(ima) + 1;
				//ima += abs(ima) + 1;
				ima = 1;
			}
		}
		else if (flag == true) {
			if (ima > 0) {
				sum2 += abs(ima) + 1;
				//ima -= abs(ima) - 1;
				ima = -1;
			}
		}
	}

	cout << min(sum, sum2) << endl;



	return 0;
}

Measured memory_bytes: 1400
H, W, M = map(int, input().split())
boms = set()
Hs = [0] * H
Ws = [0] * W
for i in range(M):
  h, w = map(lambda x: int(x) - 1, input().split())
  boms.add((h, w))
  Hs[h] += 1
  Ws[w] += 1
  
Hmax = max(Hs)
HMaxIndexs = set()
for i, h in enumerate(Hs):
  if h == Hmax:
    HMaxIndexs.add(i)

Wmax = max(Ws)
WMaxIndexs = set()
for i, w in enumerate(Ws):
  if w == Wmax:
    WMaxIndexs.add(i)

count = 0
for bom in boms:
  if (bom[0] in HMaxIndexs) and (bom[1] in WMaxIndexs):
    count += 1
print(Hmax + Wmax - 1) if count == len(HMaxIndexs) * len(WMaxIndexs) else print(Hmax + Wmax)



Measured memory_bytes: 216080
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
using namespace std;


int main(){
    int n;
    cin >> n;
    int a[n + 1], b[n];
    for (int i = 0; i < n + 1; i++){
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        cin >> b[i];
    }
    long long sum = 0, monster_tmp;
    for (int i = 0; i < n; i++){
        monster_tmp = min(b[i], a[i]);
        b[i] -= monster_tmp;
        sum += monster_tmp + min(b[i], a[i + 1]);
        a[i + 1] -= min(b[i], a[i + 1]);
    }
    cout << sum << endl;
    return 0;
}

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

#define mx 100005
#define md 1000000007

using namespace std;

map<string, int> mp;
string s;
long long n, ans;

int main(){
  cin >> n >> s;
  for(int i = 0; i < 2; i++){
    for(int j = 0; j < (1<<n); j++){
      int l = 0, r = n;
      char t[20]; t[n+1] = '\0';
      for(int k = 0; k < n; k++){
        if((j>>k)&1) t[l++] = s[i ? 2*n-1-k : k];
        else t[r--] = s[i ? 2*n-1-k : k];
      }
      t[l] = 'A';
      if(i) ans += mp[(string)t];
      else mp[(string)t]++;
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 65920
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        Map<Long, Integer> map = new HashMap<>();
        for (long p = 1; p <= Math.sqrt(nn) + 1; p++) {
            if (isPrime(p)) {
                map.put(p, 0);
                while (n > 0) {
                    if (n % p != 0) {
                        break;
                    }
                    map.compute(p, (k, old) -> old + 1);
                    n /= p;
                }
            }

            if (nn % p != 0) continue;

            long q = nn / p;
            if (isPrime(q)) {
                map.put(q, 0);
                while (n > 0) {
                    if (n % q != 0) {
                        break;
                    }
                    map.compute(q, (k, old) -> old + 1);
                    n /= q;
                }
            }
        }

        int total = 0;
        for (long key : map.keySet()) {
            int m = map.get(key);
            for (int i = 1; m - i >= 0; i++) {
                total++;
                m = m - i;
            }
        }

        System.out.println(total);

    }

    static boolean isPrime(long n) {
        if (n == 1) return false;
        if (n == 2) return true;
        for (long i = 2; i < Math.sqrt(n) + 1; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 45248
const val MOD = 1000000007
fun main(args: Array<String>) {
    val sc = MyScanner()
    val a = sc.nextInt()
    val b = sc.nextInt()

    println(a * b)
}

class MyScanner {
    operator fun next(): String {
        return sc.next()
    }

    fun nextLine(): String {
        return sc.nextLine()
    }

    fun nextInt(): Int {
        return sc.next().toInt()
    }

    fun nextDouble(): Double {
        return next().toDouble()
    }

    fun nextLong(): Long {
        return next().toLong()
    }

    fun nextIntArray(n: Int): IntArray {
        val array = IntArray(n)
        for (i in 0 until n) {
            array[i] = nextInt()
        }
        return array
    }

    fun nextDoubleArray(n: Int): DoubleArray {
        val array = DoubleArray(n)
        for (i in 0 until n) {
            array[i] = nextDouble()
        }
        return array
    }

    fun nextLongArray(n: Int): LongArray {
        val array = LongArray(n)
        for (i in 0 until n) {
            array[i] = nextLong()
        }
        return array
    }

    fun nextLineArray(n: Int): Array<String?> {
        val array = arrayOfNulls<String>(n)
        for (i in 0 until n) {
            array[i] = nextLine()
        }
        return array
    }

    fun nextIntMatrix(n: Int, m: Int): Array<IntArray> {
        val matrix = Array(n) { IntArray(m) }
        for (i in 0 until n) {
            for (j in 0 until m) {
                matrix[i][j] = nextInt()
            }
        }
        return matrix
    }

    fun nextDoubleMatrix(n: Int, m: Int): Array<DoubleArray> {
        val matrix = Array(n) { DoubleArray(m) }
        for (i in 0 until n) {
            for (j in 0 until m) {
                matrix[i][j] = nextDouble()
            }
        }
        return matrix
    }

    fun nextLongMatrix(n: Int, m: Int): Array<LongArray> {
        val matrix = Array(n) { LongArray(m) }
        for (i in 0 until n) {
            for (j in 0 until m) {
                matrix[i][j] = nextLong()
            }
        }
        return matrix
    }

    companion object {
        var sc: java.util.Scanner = java.util.Scanner(java.lang.System.`in`)
    }
}


Measured memory_bytes: 36288
N = int(input())
M = [[int(x) for x in input().split()] for _ in range(N)]

p = []

for m in M:
    p.append(m[0])

p.append(M[-1][1])

dp = [[0] * N for j in range(N)]

for l in range(2, N + 1):
    for i in range(N + 1 - l):
        j = i + l - 1
        dp[i][j] = float("inf")
        for k in range(i, j):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i] * p[k + 1] * p[j + 1])

print(dp[0][N - 1])



Measured memory_bytes: 5716
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll int dp[100001][13];
#define MOD 1000000007
int main(){
  REP(i, 100001) REP(j, 13) dp[i][j] = 0;
  string s;
  cin >> s;
  if(s[s.size() - 1] == '?'){
    REP(i, 10) dp[0][i] = 1;
  }else{
    int a = s[s.size() - 1] - '0';
    dp[0][a] = 1;
  }
  int t = 10;
  FOR(i, 1, s.size()){
    REP(j, 13){
      char c = s[s.size() - 1 - i];
      if(c == '?'){
        REP(k, 10){
          int p = (j + ((k * t) % 13)) % 13;
          dp[i][p] = (dp[i-1][j] + dp[i][p]) % MOD;
        }
      }else{
        int k = c - '0';
        int p = (j + ((k * t) % 13)) % 13;
        dp[i][p] = (dp[i-1][j] + dp[i][p]) % MOD;
      }
    }
    t = (t * 10) % 13;
  }
  // REP(k, 3){
  //   REP(i, 13) cout << dp[k][i] << " ";
  //   cout << endl;
  // }
  cout << dp[s.size() - 1][5] << endl;
}	


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

int main(){
    int x, y, z; cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << ' ' << y << ' ' << z << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
#include<stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  if(x==NIL){root=z;
  }else{
    do{
      if(x->key>=k){
	y=x->left;
      }else {
	y=x->right;
      }
      if(y!=NIL) {
	y->parent=x;
      }else{
	if(x->key>=k) x->left=z;
	else x->right=z;
      }
      x=y;
    }while(x!=NIL);
  }
}
void inorder(Node s){
  if(s==NIL)return;
  inorder(s->left);
  printf(" %d",s->key);
  inorder(s->right);
}
void preorder(Node s){
  if(s==NIL)return;
  printf(" %d",s->key);
  preorder(s->left);
  preorder(s->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}





Measured memory_bytes: 25180
n = int(input())
a = list(int(x) for x in input().split())
x = 0
 
a.sort()
for i in range(n-1):
    if a[-1] - a[-2] == 0:
        print("NO")
        x = 1
        break
    a.pop()
 
if x == 0:
    print("YES")

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


int main() {
    int N;
    cin>>N;
    double x[N];
    string u[N];
    double ans=0;
    rep(i,N){
        cin>>x[i]>>u[i];
        if(u[i]=="JPY")ans+=x[i];
        else ans+=x[i]*380000;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(list[int(input())-1])

Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int,P>PP;
vector<int>G[2005];
int A[2005],B[2005];
int dis[2005][2005];

void dfs(int now,int par,int top,int K,int &ans){
	for(int e:G[now]){
		if(e==par)continue;
		dis[top][e]=dis[top][now]+1;
		if(dis[top][e]<=K)ans++;
		dfs(e,now,top,K,ans);
		}
	}

signed main(){
	int n,k;cin>>n>>k;
	rep(i,n-1){
		int a,b;cin>>a>>b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
		A[i]=a;B[i]=b;
		}
		
	int ans=inf;
	if(k&1){
		rep(i,n-1){
			int res=2;
			int d=0;
			dfs(A[i],B[i],A[i],k/2,d);
			res+=d;d=0;
			dfs(B[i],A[i],B[i],k/2,d);
			res+=d;
			ans=min(ans,n-res);
			}
		}
	else{
		rep(i,n){
			int res=0;
			int d=1;
			dfs(i,-1,i,k/2,d);
			res+=d;
			ans=min(ans,n-res);
			}
		}	
	cout<<ans<<endl;	
}


Measured memory_bytes: 31872
a, b, c = map(int, input().split())
if c==1:
    print('No')
elif c==2:
    print('No')
elif c-a-b<=1:
    print('No')
else:
    if (c - b - a) * (c - b - a) > 4 * a * b:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 2940
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int[] x = new int[N];
        for(int i = 0;i < N;i++){
            x[i] = sc.nextInt();
        }
        long[][][] dp = new long[N + 1][N + 1][N * 50 + 1];
        for(int j = 0; j <= N; j++) {
            dp[j][0][0] = 1;
        }
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                for(int s = 0; s <= N * 50; s++){
                    long cnt = 0;
                    cnt += dp[j - 1][k][s];
                    if(s - x[j - 1] >= 0) {
                        cnt += dp[j - 1][k - 1][s - x[j - 1]];
                    }
                    dp[j][k][s] = cnt;
                }
            }
        }
        long ans = 0;
        for(int k = 1; k <= N; k++){
            for(int s = 0; s <= N * 50; s++){
                if(s == k * A) {
                    ans += dp[N][k][s];
                }
            }
        }
        System.out.println(ans);
    }
}


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

int main(){
  int i, N, y=0;
  scanf("%d", &N);
  char s[N];
  
  for(i=0;i<N;i++){
    scanf(" %c", &s[i]);
    if(s[i]=='Y'){
      y=1;break;
    }
  }
  
  if(y)
    printf("Four\n");
  else
    printf("Three\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define NewNode (ListNode *)malloc(sizeof(ListNode))
#define Mem(a,b) memset(a,b,sizeof(a))
const int N = 4e5 + 5;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const unsigned long long mod = 998244353;
const double II = 3.1415926535;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    ull a,b,n;
    cin >> a >> b >> n;
    ull num1 = a*min((b-1),n)/b - a*(min((b-1),n)/b);
    cout << num1 << endl;
}


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

a = x2 - x1
b = y2 - y1
x3 = x2 - b
y3 = y2 + a

print(x3, end=' ')
print(y3, end=' ')
print(x3 - a, end=' ')
print(y3 - b)



Measured memory_bytes: 2940
def StringTransformation(s , t):

    taious = {}
    taiout = {}
    ans = "Yes"

    for i in range(len(s)):
        if t[i] in taiout.keys() and taiout[t[i]] != s[i]:
            ans = "No"
            break
        elif s[i] in taious.keys() and taious[s[i]] != t[i]:
            ans = "No"
            break
        else:
            taiout[t[i]] = s[i]
            taious[s[i]] = t[i]

    return ans

def main():
    s = str(input())
    t = str(input())
    print(StringTransformation(s , t))

if __name__ == '__main__':
    main()

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

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

	int ara[3];
	for (int i = 0; i < 3; ++i)
	{
		cin >> ara[i];
	}
	cout << ara[2] << " " << ara[0] << " " << ara[1] << endl;
	return 0;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        char[][] s = new char[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = sc.next().toCharArray();
        }

        // 主処理
        int[] x = new int[] { 0, 0, -1, 1 };
        int[] y = new int[] { -1, 1, 0, 0 };

        boolean judge = true;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (s[i][j] == '.') {
                    continue;
                }
                boolean canPaint = false;
                for (int k = 0; k < 4; k++) {
                    int targetX = j + x[k];
                    int targetY = i + y[k];
                    boolean isOutside = targetX < 0 || w <= targetX || targetY < 0 || h <= targetY;
                    if (!isOutside) {
                        canPaint = canPaint || s[targetY][targetX] == '#';
                    }
                }
                if (!canPaint) {
                    judge = false;
                }
            }
        }

        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21972
light=input().split(' ')
line=[]
for i in range(int(light[1])):
  line.append(input().split(' ')[1:])
  
switch=input().split(' ')

length=2**int(light[0])
count=0
for i in range(length):
  li=[]
  for j in range(int(light[0]),0,-1):
    if i%2 == 1:
      li.append(1)
    else:
      li.append(0)
      
    i//=2

  flg=True
  for j in range(int(light[1])):
    light_count=0
    for k in line[j]:
      if li[int(k)-1]==1:
        light_count+=1
        
    if light_count%2!=int(switch[j]):
      flg=False
      break

  if flg:
    count+=1
    
print(count)
  

Measured memory_bytes: 3064
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])

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

using namespace std;

const int N = 1e5+10;

int a[N];
bool q[N];

int main() {
	int n, m; cin >> n >> m;
	q[1] = 1;
	for(int i = 1; i <= n; i++) a[i] = 1;

	for(int i = 0; i < m; i++) {
		int x, y; cin >> x >> y;
		if(a[x]==0) continue;
		else {
			if(a[x] == 1) {
				if(q[x]) q[y] = 1;
				q[x] = 0;		
			} else {
				if(q[x]) q[y] = 1;
			}
			a[x]--, a[y]++;
		}
	}

	/*for(int i = 1; i <= n; i++) {
		cout << a[i] << " " << q[i] << endl;
	}
	*/
	int cnt = 0;
	for(int i = 1; i <= n; i++) if(a[i] && q[i]) cnt++;
	cout << cnt;
}

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

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime> 

#define ll long long
using namespace std;
const int N=1e5 + 100;
const double eps=1e-10;
int a[N];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	ll ans=0;
	for(int i=1;i<=m;i++) ans+=a[i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
   	
int main() {

	long long int n;

	cin >> n;

	long long int a[n];

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] == 0)
		{
			cout << 0;
			exit(0);
		}
	}

	long long int lim = 1e18;
	long long int prod = 1;

	for (int i = 0; i < n; i++)
	{
		if (a[i] <= lim / prod)
		{
			prod = prod * a[i];
		}
		else
		{
			cout << -1;
			exit(0);
		}
	}

	cout << prod;

    return 0;
}

Measured memory_bytes: 4368
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main(){
    int sScore = 0; int tScore = 0;
    string[] sInput = readln().split();
    string[] tInput = readln().split();
    foreach(string s; sInput){
        sScore += s.to!int();
    }
    foreach(string s; tInput){
        tScore += s.to!int();
    }
    if(sScore > tScore){
        writeln(sScore);
    }else{
        writeln(tScore);
    }
}

Measured memory_bytes: 968
#include <stdio.h>

int main()
{
  int a=0, b=0, c=0;
  scanf("%d %d %d", &a, &b, &c);
  if(a == b && b == c){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

  

Measured memory_bytes: 128
import java.io.InputStream
import java.util.*

fun main(args: Array<String>) {
    val inputStream = System.`in`
    problem(inputStream)
}

fun problem(inputStream: InputStream?) {
    val sc = Scanner(inputStream)

    val a = sc.nextInt()
    val b = sc.nextInt()
    val multi = a * b
    val c = sc.nextInt()
    println(
        if (multi < c) {
            multi
        } else {
            c
        }
    )
}

Measured memory_bytes: 29352
package main

import "fmt"

func reverse(str string) string {
	rev := ""
	for i := range str {
		rev += string(str[len(str)-i-1])
	}
	return rev
}

func main() {
	var s string
	fmt.Scan(&s)

	rev := reverse(s)
	for {
		if rev == "" {
			fmt.Println("YES")
			break
		} else if len(rev) >= 7 && rev[:7] == "remaerd" {
			rev = rev[7:]
		} else if len(rev) >= 6 && rev[:6] == "resare" {
			rev = rev[6:]
		} else if len(rev) >= 5 && rev[:5] == "maerd" || rev[:5] == "esare" {
			rev = rev[5:]
		} else {
			fmt.Println("NO")
			break
		}
	}
}


Measured memory_bytes: 11904
def main():
    import itertools
    n,m,r=map(int,input().split())
    rx=[int(i) for i in input().split()]
    inf=100000000
    wf=[[inf]*n for i in range(n)]
    for i in range(n):
        wf[i][i]=0

    for i in range(m):
        a,b,c=map(int,input().split())
        wf[a-1][b-1]=c
        wf[b-1][a-1]=c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                if wf[i][j]>wf[i][k]+wf[k][j]:
                    wf[i][j]=wf[i][k]+wf[k][j]
    cnt=0
    l=list(itertools.permutations([i for i in range(r)]))
    cnt=inf
    for i in l:
        cnt_sub=0
        for j in range(r-1):
            cnt_sub+=wf[rx[i[j]]-1][rx[i[j+1]]-1]
        cnt=min(cnt,cnt_sub)
    print(cnt)
main()


Measured memory_bytes: 9564
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
#include <queue>
#include <set>
using namespace std;

typedef long long ll;

#define INF 100000000;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define eps 1.0e-14;
#define mod 1e9 + 7;

int main(){
	int n; cin >> n;
	int a[200005];
	map<int,int> mp;
	int one = 0;
	rep(i,n){
		cin >> a[i];
		mp[a[i]]++;
		if (a[i] == 1){
			one++;
		}
	}
	if(one){
		if(one == 1){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
	}else{
		vector<bool> isOK(n,true);
		rep(i,n){
			for(int j = 2; j * j <= a[i]; j++){
				if (a[i] % j == 0){
					if (mp[j]){
						isOK[i] = false;
						break;
					}
					if (mp[a[i]/j]){
						// cout << a[i] << endl;
						// cout << j << endl;
						isOK[i] = false;
						break;
					}
				}
			}
			if(mp[a[i]] >= 2) isOK[i] = false;
		}
		int ans = 0;
		rep(i,n){
			if (isOK[i]) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 33332
n = int(input())
hn = [int(num) for num in input().split()]

answer = 0
count = 0
for index in range(1,len(hn)):
  if hn[index-1] >= hn[index]:
    count += 1
  else :
    if answer < count:
      answer = count
    count = 0

if answer < count:
  answer = count
    
print(answer)

Measured memory_bytes: 20104
n = int(input())
ans = n
for i in range(n+1):
    num1 = i
    ansi = 0
    while(num1 > 0):
        ansi += num1 % 6
        num1 //= 6
    num2 = n - i
    while(num2 > 0):
        ansi += num2 % 9
        num2 //= 9
    ans = min(ans, ansi)
print(ans)




Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
  string from,to;
  cin>>from>>to;
  int f[from.size()+1][to.size()+1];
  for(int i=0;i<from.size()+1;i++){
    for(int j=0;j<to.size()+1;j++){
      f[i][j]=0;
    }
  }
  for(int i=1;i<from.size()+1;i++){
    f[i][0]=i;//f[i-1][0]+1;
  }
  for(int i=1;i<to.size()+1;i++){
    f[0][i]=i;//f[0][i-1]+1;
  }
  for(int i=1;i<from.size()+1;i++){
    for(int j=1;j<to.size()+1;j++){
      if(from[i-1]==to[j-1]){
	//int min1=min(f[i-1][j]+1,f[i][j-1]+1);
	f[i][j]=f[i-1][j-1];
      }else{
	int min1=min(f[i-1][j-1],f[i][j-1]);
	f[i][j]=min(min1,f[i-1][j])+1;
      }
    }
  }

  cout<<f[from.size()][to.size()]<<endl;
  return 0;
}


Measured memory_bytes: 7088
#include<bits/stdc++.h>
#define ll long long int
#define PB emplace_back
#define MP make_pair
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main() {
    IOS;
//      freopen("input.txt","r",stdin);
//  		freopen("output.txt","w",stdout);
//ll t;
//cin>>t;
//while(t--){
    ll n,k,x,y=1,i,z,t,ch,m,ans;
    cin>>n>>x>>t;
    ans=(n+x-1)/x;
    cout<<ans*t<<endl;
//}
	return 0;
}

Measured memory_bytes: 3572
from itertools import combinations

N = int(input())
name_count = {'M': 0,
              'A': 0,
              'R': 0,
              'C': 0,
              'H': 0, }
for i in range(N):
    name = input()

    if name[0] in name_count:
        name_count[name[0]] += 1


def comb(n, r):
    up = 1
    down = 1
    for i in range(r):
        up *= n - i
        down *= i + 1
    return up // down


all_sum = sum(name_count.values())
total = comb(all_sum, 3)

for i in name_count.values():
    if i >= 2:
        total -= comb(i, 2) * (all_sum - i)

    if i >= 3:
        total -= comb(i, 3)

print(total)


Measured memory_bytes: 9232
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    map<pair<int, int>, int> v;
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        v[make_pair<int>(s.front(), s.back())]++;
    }
    ll ans = 0;
    for (auto &&i : v) {
        int l, r;
        tie(l, r) = i.first;
        if(v.count(make_pair(r, l))){
            ans += i.second*v[make_pair(r, l)];
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,mm;
    cin>>n>>mm;
    int a[n+1]={0};
    int x[n+1]={0},y[n+1]={0};
    long long ans=0;
    map<int,int> m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    while(mm--)
    {
        int h1,h2;
        cin>>h1>>h2;
        x[h1]++;
        x[h2]++;
        if(a[h2]>a[h1])
            y[h2]++;
        else if(a[h1]>a[h2])
            y[h1]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(y[i]==x[i] || x[i]==0)
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 4828
#BFSにdpを乗っける
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=list(map(float,input().rstrip().split(" ")))
dp=[[0]*(n+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    for j in range(n):
        dp[i+1][0]=dp[i][0]*(1-lis[i])
        dp[i+1][j+1]=dp[i][j]*lis[i]+dp[i][j+1]*(1-lis[i])
#print(dp)
ans=0
for i in range((n+1)//2,n+1):
    ans+=dp[-1][i]
print(ans)

            
    

        

Measured memory_bytes: 199676
import java.util.*;
import java.lang.Math;

public class Main {
	static String a;
	static int ok=-1;
	public static void printans(int x,int y,char[] s) {
		if (x==y) {
			if (ok==2)
				System.out.println();
			ok=2;
			System.out.print(new String(s));
		}
		else {
			char max='a';
			for (int i=1;i<=x;i++) {
				if (max<s[i]) max=s[i];
			}
			for (int i='a';i<max+2;i++) {
				s[x+1]=(char)i;
				printans(x+1,y,s);
			}
		}
	}
		  public static void main(String[] args){
		    Scanner sc = new Scanner(System.in);
		    int n = sc.nextInt();
		    char a[]=new char [n];
		    a[0]='a';
		    printans(0,n-1,a);
		  }
		}



Measured memory_bytes: 40912
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,a=0,b=0,c=0,d=0;
    string s;
    cin>>n;
    for(i=0;i<n;i++)
    {
      cin>>s;
      if(s=="AC") a++;
      else if(s=="TLE") b++;
      else if(s=="WA") c++;
      else d++;
    }
   cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<c<<endl;
     cout<<"TLE"<<" "<<"x"<<" "<<b<<endl;
      cout<<"RE"<<" "<<"x"<<" "<<d<<endl;
      return 0;
}


Measured memory_bytes: 3632
import math

N,D = map(int,input().split())
X = []
for i in range(N):
    X += [[int(x) for x in input().split()]]

ans = 0
for i in range(N):
    for j in range(i+1,N):
        temp = 0
        for k in range(D):
            temp += (X[i][k] - X[j][k])**2
        d = math.sqrt(temp)
        if d == int(d): ans += 1

print(ans)

Measured memory_bytes: 3064
#include <cstdio>

using namespace std;

int n;

bool prime(int x){
    if(x < 2) return 0;
    if(x == 2) return 1;
    for(int j = 2;j*j<=x;j++){
        if(x % j == 0) return 0;
    }
    return 1;
}

int main(){
    scanf("%d", &n);
    int lst = 3;
    for(int i = 0;i<n;i++){
        while(!prime(lst) || lst % 5 != 1){
            lst++;
        }
        printf("%d ", lst++);
    }
    printf("\n");
}


Measured memory_bytes: 128
#include <stdio.h>

int main( void )
{
    unsigned char tmp;
    int total = 'a' + 'b' + 'c';

    for( int i = 0; i < 3; i++ )
        total -= getchar();
    
    printf("%s\n", (total == 0)? "Yes":"No");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int n,m,l,i,j,k;
  int a[100][100]={0},b[100][100]={0};
  long long c[100][100]={0};

  scanf("%d %d %d",&n,&m,&l);

  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&a[i][j]);
    }
  }

  for(j=0;j<m;j++){
    for(k=0;k<l;k++){
      scanf("%d",&b[j][k]);
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<l;j++){
      for(k=0;k<m;k++){
	c[i][j]+=a[i][k]*b[k][j];
      }
    }
  }

  for(i=0;i<n;i++){
    for(k=0;k<l;k++){
      if(k!=l-1){
        printf("%lld ",c[i][k]);
      }
      else{
	printf("%lld\n",c[i][k]);
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1192
<?php
list($n, $m) = ints();
$redpos[0] = true;
$cnt = array_fill(0, $n, 1);
for ($i = 0; $i < $m; ++$i) {
    list($x, $y) = ints();
    --$x;
    --$y;
    --$cnt[$x];
    ++$cnt[$y];
    if (isset($redpos[$x])) {
        $redpos[$y] = true;
        if ($cnt[$x] === 0) unset($redpos[$x]);
    }
}
echo count($redpos);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 26328
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int N;
int ac, wa, tle, re;

int main() {
  //
  cin >> N;
  rep(i, 0, N) {
    string s;
    cin >> s;
    if (s == "AC") {
      ac++;
    } else if (s == "WA") {
      wa++;
    } else if (s == "TLE") {
      tle++;
    } else {
      re++;
    }
  }

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> A(N);
    for (int i=0;i<N;++i){
        cin >> A[i];
        if (!A[i]){
            cout << 0 << '\n';
            return 0;
        }
    }
    ll ans=1;
    for (int i=0;i<N;++i){
        if (ans>INF/A[i]){
            cout << -1 << '\n';
            return 0;
        }
        ans*=A[i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3976
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep (i, n) {
    cin >> v[i];
    v[i] -= 1;
  }
  int count = 0;
  int pos = 0;
  while (pos != 1) {
    count++;
    pos = v[pos];
    if (count > 100000) {
      P(-1);
      return 0;
    }
  }
  P(count);
  return 0;
}

Measured memory_bytes: 640
class Dice 
    def initialize(nums)
        @nums = [nil] + nums
    end
    def top
        @nums[1]
    end
    def rollx
        @nums[1], @nums[2], @nums[6], @nums[5] = @nums[5], @nums[1], @nums[2], @nums[6]
        self
    end
    def rolly
        @nums[1], @nums[3], @nums[6], @nums[4] = @nums[4], @nums[1], @nums[3], @nums[6]
        self
    end
    def rollz
        @nums[2], @nums[3], @nums[5], @nums[4] = @nums[4], @nums[2], @nums[3], @nums[5]
        self
    end
    def moveN
        rollx.rollx.rollx
    end
    def moveS
        rollx
    end
    def moveE
        rolly
    end
    def moveW
        rolly.rolly.rolly
    end
    def move(m)
        case m
        when 'N' then moveN
        when 'S' then moveS
        when 'E' then moveE
        when 'W' then moveW
        end
    end
end

nums = STDIN.gets.split.map(&:to_i)
moves = STDIN.gets.split('')

dice = Dice.new(nums)

moves.each do |m|
    dice.move(m)
end

puts dice.top

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

int main() {
  int N;
  cin >> N;
  int n=N;
  int S=0;
  while (N>0) {
    S+=N%10;
    N/=10;
  }
  if (n%S==0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  //cout << S << endl;
}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String s = stdin.readLine();
        String t = ok(s) ? "Yes" : "No";
        System.out.println(t);
    }
    
    public static boolean ok(String s) {
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (i % 2 == 0) {
                if (ch == 'L') return false;
            } else {
                if (ch == 'R') return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 22484
<?php
  	fscanf(STDIN, '%d', $max500);
  	fscanf(STDIN, '%d', $max100);
  	fscanf(STDIN, '%d', $max50);
	fscanf(STDIN, '%d', $total);

	$cnt = 0;
	for($i = 0; $i <= $max500; $i++){
      	$money = $i * 500;
      	if($money == $total){
          	++$cnt;
          	echo $cnt;
          	exit;
        }
      	if($money > $total){
          	echo $cnt;
          	exit;
        }
      	for($j = 0; $j <= $max100; $j++){
          	$money = $i * 500 + $j * 100;
          	if($money == $total){
              	++$cnt;
              	break;
            }
          	if($money > $total){
              	break;
            }
          	for($k = 0; $k <= $max50; $k++){
	          	$money = $i * 500 + $j * 100 + $k * 50;
              	if($money == $total){
              		++$cnt;
                  	break;
                }
            }
        }
    }
	echo $cnt;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
const int N = 3003;
int dp[N][N];
int lcs(string s,string t,int n,int m){
	if(n==0 || m==0)
		return 0;
	if(dp[n][m]!=-1)
		return dp[n][m];
	if(s[n-1]==t[m-1])
		return dp[n][m] = 1+lcs(s,t,n-1,m-1);
	return dp[n][m] = max(lcs(s,t,n-1,m),lcs(s,t,n,m-1));
}


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

    memset(dp,-1,sizeof(dp));

    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    for(int i=0;i<=n;i++){
    	for(int j=0;j<=m;j++){
    		if(i==0||j==0)
    			dp[i][j]=0;
    		else{
    			if(s[i-1]==t[j-1]){
    				dp[i][j]=1+dp[i-1][j-1];
    			}
    			else{
    				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    			}
    		}
    	}
    }

    // for(int i=0;i<=n;i++){
    // 	for(int j=0;j<=m;j++){
    // 		cout<<dp[i][j]<<' ';
    // 	}
    // 	cout<<endl;
    // }

    int taille = dp[n][m];
    string ans="";

    while(n>0 && m>0){
    	if(s[n-1]==t[m-1]){
    		ans = s[n-1] + ans;
    		n--;m--;
    	}
    	else{
    		if(dp[n-1][m]>dp[n][m-1])
    			n--;
    		else
    			m--;
    	}

    }
    cout<<ans;

	return 0;
}

Measured memory_bytes: 35456
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	S := next()

	var start int
	var sum int
	var result int
	length := len([]rune(S))

	for bit := 0; bit < (1 << (length - 1)); bit++ {
		for i := 0; i < length-1; i++ {
			if (bit>>i)&1 == 1 {
				num, err := strconv.Atoi(S[start : i+1])
				if err != nil {
					fmt.Println(err)
				}
				sum += num
				start = i + 1
			}
		}
		num, _ := strconv.Atoi(S[start:length])
		result += sum + num
		start, sum = 0, 0
	}
	fmt.Println(result)
}

Measured memory_bytes: 1772
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int r,D,x;

int main(){
    cin>>r>>D>>x;

    rep(i,10){
        x=r*x-D;
        cout<<x<<endl;
    }
}

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

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

	int n = s.length();

	int* counts = new int[n];
	for (int i = 0; i < n; i++)
	{
		counts[i] = 0;
	}

	//左からループしてLの計算
	int start = 0;
	int c = 0;

	//左からループしてLの計算
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'L')
		{
			c++;

			if(start == 0) start = i;
			
			if (c % 2 == 0)
			{
				//偶数歩の場合は、L開始時点が終了地点
				counts[start]++;
			}
			else
			{
				//奇数歩の場合は、L開始時点直前のRが終了地点
				counts[start-1]++;
			}
		}
		else
		{
			//Rの場合は一時変数クリア
			start = 0;
			c = -1;
		}
	}

	//右からループしてRの計算
	for (int i = 0; i < n; i++)
	{
		int present = n - 1 - i;

		if (s[present] == 'R')
		{
			c++;

			if (start == 0) start = present;

			if (c % 2 == 0)
			{
				//偶数歩の場合は、R開始時点が終了地点
				counts[start]++;
			}
			else
			{
				//奇数歩の場合は、R開始時点直前のLが終了地点
				counts[start + 1]++;
			}
		}
		else
		{
			//Lの場合は一時変数クリア
			start = 0;
			c = -1;
		}
	}

	//結果を表示
	for (int i = 0; i < n; i++)
	{
		cout << counts[i] << " ";
	}

	delete[] counts;

	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  var (_a, _b, k) = (sc.nextInt(), sc.nextInt(), sc.nextInt())
  val a = math.max(_a, _b)
  val b = math.min(_a, _b)

  (1 to b).reverse.foreach { i =>
    if (a % i == 0 && b % i == 0) {
      k -= 1
      if (k == 0) {
        println(i)
        sys.exit()
      }
    }
  }
}

Measured memory_bytes: 25548
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	long long a, b;
	int k;
	cin >> a >> b >> k;
	if ((b - a) % 2 == 0 && (b - a) / 2 + 1 <= k) {
		for (int i = a; i <= b; i++) {
			cout << i << endl;
		}
	}
	else {
		for (int i = 0; i < k; i++) {
			if (i <= floor((b - a) / 2)) {
				cout << a + i << endl;
			}
		}
		for (int i = k - 1; i >= 0; i--) {
			if (i <= floor((b - a) / 2)) {
				cout << b - i << endl;
			}
		}
	}
	
	return 0;
}

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

int main(){
  int A,B,M;
  cin >> A >> B >> M;
  vector<long> a(A);
  vector<long> b(B);
  vector<long> x(M);
  vector<long> y(M);
  vector<long> c(M);
  for(int i=0;i<A;++i) cin >> a[i];
  for(int i=0;i<B;++i) cin >> b[i];
  for(int i=0;i<M;++i){
    cin >> x[i] >> y[i] >> c[i];
  }
  long ans = 1e7;
  for(int i=0;i<M;++i){
    ans = min(ans,a[x[i]-1]+b[y[i]-1]-c[i]);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ans = min(ans,a[0]+b[0]);
  cout << ans << endl;
}

Measured memory_bytes: 4224
#include<stdio.h>
#define N 20

struct object{
int value;
int cost;
};
struct object a[N];

int totv,maxv=0;
int sel[N]={};

void try(int i);

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

for (i=0;i < n;i++){ 
    scanf("%d",&a[i].value);}
    
   
for (i=0;i < n;i++){ 
    scanf("%d",&a[i].cost);}
 
    try(n-1);
    
printf("%d\n",maxv);
}

void try(int i)
{ int j;
    sel[i]=0;
 if(i!=0){try(i-1);}
 else{totv=0;
        for(j=0;j<N;j++){if(sel[j]==1)totv+=(a[j].value-a[j].cost);}
        if(totv>maxv)maxv=totv;}
     
 sel[i]=1;
 if(i!=0){try(i-1);}
 else{totv=0;
        for(j=0;j<N;j++){if(sel[j]==1)totv+=(a[j].value-a[j].cost);}
        if(totv>maxv)maxv=totv;}
}
    


Measured memory_bytes: 128
#include<bits/stdc++.h>
//luogu
const int maxn = 2010;
using ll = long long;
ll mod = 1e9+7;
ll n, k,  ans, s1, s2,t,v=16;
ll powmod(ll a, ll x) {
    ll ret = 1ll, nww = a;
    while (x) {
        if (x & 1) ret = ret * nww % mod;
        nww = nww * nww % mod;
        x >>= 1;
    }
    return ret;
}
ll inv(ll x) { return powmod(x, mod - 2); }
using namespace std;
//ll x[17]={0, 0 ,0 ,11 ,341 ,4598 ,39138,245443 ,1232837 ,5222552, 19316488, 63933498, 192839398 ,537499132, 1399637812 ,3434820114 ,8000780414};
//ll y[17]={0,0,0,1,71,1346,14038,101193,563447,2585672,10198232,35588718,112225058,324900532,874246012,2207858102,5274485994};
ll y[33]={0,0,0,0,0,1,11,71,341,1346,4598,14038,39138,101193,245443,563447,1232837,2585672,5222552,10198232,19316488,35588718,63933498,112225058,192839398,324900532,537499132,874246012,1399637812,2207858102,3434820114,5274485994,8000780414};
ll x[33];
int main() {
    cin>>t;
    for(int i=1;i<=32;++i)x[i]=i;
    while(t--){
        cin>>k;
        ans=0;
        int r=(k&1==1)?1:2;
        for (int i = r; i <= 32; i+=2) {
            s1 = y[i] % mod;
            s2 = 1ll;
            for (int j = r; j <= 32; j+=2)
                if (i != j)
                    s1 = s1 * (k - x[j]) % mod, s2 = s2 * ((x[i] - x[j] % mod) % mod) % mod;
            ans += s1 * inv(s2) % mod;
            ans = (ans + mod) % mod;
        }
        printf("%lld\n", ans);
    }


    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pii make_pair
#define pb push_back
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }

main()
{
    fastio;
    int n;
    cin>>n;
    int a[n];
    map<int, int>mp;
    for(int i=0; i<n; i++) {
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a, a+n);
    int res=0;
    for(int i=0; i<n; i++) {
        for(int j=i+1 ; j<n; j++) {
            for(int k=j+1; k<n; k++) {
                if(a[i]!=a[j] && a[k]<a[i]+a[j] && a[k]!=a[i] && a[k]!=a[j]) res++;
            }
        }
    }
    cout<<res;
}


Measured memory_bytes: 3572
from collections import defaultdict

x,n = map(int,input().split())
if n==0:
    print(x)
else:
    dd = defaultdict(int)
    arr = list(map(int,input().split()))
    for i in range(len(arr)):
        dd[x-arr[i]]+=1

    for i in range(101):
        if dd[i]==0:
            print(x-i)
            break
        elif dd[-i]==0:
            print(x+i)
            break




Measured memory_bytes: 9340