akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 1; i <  N+1; i++)
  {
    cin >> a[i];
  }
  int cur = 1;
  rep(i, N) {
    cur = a[cur];
    if (cur==2) {
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

q,h,s,d = map(int,input().split())
n = int(input())
h = min(q*2,h)
s = min(h*2,s)
if n == 1:
    print(s)
    sys.exit()

if 2*s > d:
    print(d*(n//2) + (n%2)*s)
else:
    print(n*s)

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

int main() {
	int a,b;
	int i=0;
	int dt[5];
	while(cin >> a >> b) {
		if (i==0&&a==0&&b==0) break;
		dt[i] = a+b;
		i++;
		if (i==5) {
			int pos = 0;
			int max = dt[0];
			for (int j=0; j<5; j++) {
				if (max < dt[j]) {
					max = dt[j];
					pos = j;
				}
			}
			cout << (char)((int)'A'+pos) << ' ' << max << endl;
			i = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 0
//by achhhy
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
inline LL in()
{
	char ch=getchar();
	LL f=1,x=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}
//need changing
const int inf=(1<<30);
const int mod=1e9+7;
const int N=200010;

int n,a[N],f[N],ans;

int main()
{
	n=in();
	rep(i,1,n) a[i]=in();
	rep(i,1,n) f[a[i]]=f[a[i]-1]+1;
	rep(i,1,n) ans=max(ans,f[i]);
	printf("%d\n",n-ans);
	return 0;
}




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

#define ll long long int
#define ff first
#define ss second
#define pb push_back

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    int a[n], b[n], c[n - 1];
    long ans = 0;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    for(int i = 0; i < n; ++i)
    {
        cin >> b[i];ans += b[i];
    }
        for(int i = 0; i < n - 1; ++i)
        cin >> c[i];
    for(int i = 1; i < n; ++i)
        if(a[i] == a[i - 1] + 1)
        {
            ans += c[a[i - 1] - 1];
        }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

def dist(a, b):
  return pow(pow(b[0]-a[0], 2) + pow(b[1]-a[1], 2), 1/2)

que = deque([[i] for i in range(N)])
perm = []
while que:
  seq = que.popleft()
  if len(seq) == N:
    perm.append(seq)
  for j in range(N):
    if j not in seq:
      que.append(seq + [j])

d = 0
s = len(perm)
for p in perm:
  for k in range(N-1):
    d += dist(xy[p[k]], xy[p[k+1]])
print(d / s)

Measured memory_bytes: 15264
#include <stdio.h>

int main(void){
	int N;
	scanf("%d",&N);
	int i,ans=N;
	
	
	for(i=0;i<=N;i++){
		int tmp = 0;
		int t = i;
		while(t > 0){
			tmp += t%6;
			t /= 6;
		}
		t = N-i;
		while(t > 0){
			tmp += t%9;
			t /= 9;
		}
		if(ans > tmp) ans = tmp;
	}
	
	
	printf("%d\n",ans);
	return 0;}

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

int main(){
	string s;
	cin >> s;
	int i, j, a[2] = {0, 0};
	for(i = 0; i < s.size(); i++){
		for(j = 0; j < 2; j++){
			a[j] += ((i + j) % 2) ^ (s[i] - '0');
		}
	}
	printf("%d\n", min(a[0], a[1]));
	return 0;
}

Measured memory_bytes: 512
loop ::	Int -> Int -> [String]
loop x y = if x	> 0 then replicate y '#' : loop	(x - 1) y else [""]

solve :: [Int] -> [String]
solve (x : y : xs)
  | x == 0 && y == 0 = []
  | otherwise = loop x y ++ solve xs

main = getContents >>= mapM_ putStrLn . solve . map read . words

Measured memory_bytes: 4524
s = input()
a = 0
ans = 0
n = len(s)
i = 0
while(i<n):
  if s[i] == "A":
    a += 1
  elif s[i] == "B" and i+1<n and s[i+1] == "C":
    ans += a
    i += 1
  else:
    a = 0
  i += 1
print(ans)

Measured memory_bytes: 9224
from itertools import combinations_with_replacement

N, M, Q = [int(x) for x in input().split()]
ABCD = [[int(x) for x in input().split()] for i in range(Q)]

best = 0
for combo in combinations_with_replacement(range(1, M + 1), r=N):
    score = 0
    for a, b, c, d in ABCD:
        assert 1 <= a < b <= N
        assert 0 <= c <= M - 1
        if combo[b - 1] - combo[a - 1] == c:
            score += d
    best = max(best, score)
print(best)


Measured memory_bytes: 73556
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  string s;
  cin >> s;
  i64 n = s.size();
  vector<bool> dp(n + 1);
  dp[0] = true;
  for (i64 i = 0; i < n; ++i) {
    if (dp[i]) {
      if (i + 5 <= n) {
        string ss5 = s.substr(i, 5);
        if (ss5 == "dream" || ss5 == "erase") dp[i + 5] = true;
      }
      if (i + 6 <= n) {
        string ss6 = s.substr(i, 6);
        if (ss6 == "eraser") dp[i + 6] = true;
      }
      if (i + 7 <= n) {
        string ss7 = s.substr(i, 7);
        if (ss7 == "dreamer") dp[i + 7] = true;
      }
    }
  }
  cout << (dp[n] ? "YES" : "NO") << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
int main() {
    int N,M;
    cin >> N >> M;
    priority_queue<long long> A;
    for(int i = 0; i < N; i++){
        long long tmp;
        cin >> tmp;
        A.push(tmp);
    }

    long long sum = 0;
    for(int i = 0; i < M; i++){
        long long tmp = A.top();
        A.pop();
        tmp = floor(tmp / 2);
        A.push(tmp);
    }
    for(int i = 0; i < N; i++){
        long long tmp = A.top();
        sum += tmp;
        A.pop();
    }
    cout << sum << endl;

}

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

int main(){
	long long x;
	cin>>x;
	for(long long i=-120;i<=120;i++){
		for(long long j=-120;j<=120;j++){
			if(pow(i,5)-pow(j,5)==x){
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4060
#from functools import lru_cache
import sys
from itertools import product,combinations
from functools import reduce,lru_cache
import heapq
from math import ceil
def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def list_t(l): return vfunc(lambda *args:args)(*l)

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

n,x,t=vfunc(int)(reader()[0])
print((ceil(n/x))*t)

Measured memory_bytes: 67240
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
//#include "C:\code\all.h"
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;

int main(){
  int i,j,k;
  int n,x;
  cin >> n >> x;
  vector<int> a(n+3,0);
  for(i = 1;i<n+1;i++) cin>>a[i];
  long long ans = 0;
  //vector<int> b(n+2,0);
  // for(i = 1;i<n+2;i++){
  //   label:
  //   if(a[i-1] + a[i] > x){
  //     if(a[i]>0) {a[i]--; ans++; b[i]++; goto label;}
  //     else {a[i-1]--; ans++; b[i-1]++; goto label;}
  //   }
  // }
  for(i = 1;i<=n+1;i++){
    label:
    if(a[i-1] + a[i] > x){
      if(a[i] > 0){
        int temp = fmin(a[i], (a[i-1] + a[i]) - x);
        a[i] -= temp; ans+=temp;
        goto label;
      }
      else{
        int temp = fmin(a[i-1], (a[i-1] + a[i]) - x);
        a[i-1] -= temp; ans+=temp;
        goto label;
      }
    }
  }
  cout << ans << endl;
  // for(i = 1;i<n+1;i++) cout << b[i] << " "; cout << endl;
  // for(i = 0; i< n+1;i++) cout << a[i]<< " "; cout << endl;
  

}


Measured memory_bytes: 640
import sys
input = sys.stdin.buffer.readline

N = int(input())
A = list(map(int, input().split()))

left = [0] * N
tmp = []
for i, a in enumerate(A):
    cnt = 1
    while tmp:
        aa, c = tmp.pop()
        if aa < a:
            tmp.append((aa, c))
            break
        else:
            cnt += c
    tmp.append((a, cnt))
    left[i] = cnt
A =A [::-1]
right = [0] * N
tmp = []
for i, a in enumerate(A):
    cnt = 1
    while tmp:
        aa, c = tmp.pop()
        if aa < a:
            tmp.append((aa, c))
            break
        else:
            cnt += c
    tmp.append((a, cnt))
    right[i] = cnt
right = right[::-1]

A = A[::-1]
answer = 0
for i in range(N):
    answer += left[i] * right[i] * A[i]
    
print(answer)

Measured memory_bytes: 69668
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            B();
        }

        static void B()
        {
            var N = ReadInt();
            long ans = 1;
            for (long i = 1; i <= N; i++)
                ans = i*ans % 1000000007;
            Println(ans);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static IList<string> ReadSplit() => Read().Split().ToList();
        static IList<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();

        static void Print(object value = null) => Console.Write(value.ToString());
        static void Println(object value = null) => Console.WriteLine(value.ToString());
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int slen=s.size();
    int tlen=t.size();
    int dp[slen+1][tlen+1];
    for(int i=0;i<=slen;i++)
    {
        for(int j=0;j<=tlen;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]);
            }
        }
    }
    // cout<<dp[slen][tlen]<<endl;
    string res="";
    int i=slen;
    int j=tlen;
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            res=s[i-1]+res;
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    cout<<res;  
    return 0;
}

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

#define ll long long


int main(){
	ll N; cin >> N;
	ll mn = 2e18, mx = -2e18;
	vector < pair < ll, ll > > V(N);
	for (int i = 0; i < N; i ++){	
		ll X, Y; cin >> X >> Y; V[i].first = X; V[i].second = Y;
	}
    ll result = 0, smallest, cur;
    for (int p : {1, -1}) {
        for (int q : {1, -1}) {
            ll mn = 2e9, mx = -2e9;
            for (int i = 0; i < N; i ++){
                mn = min(mn, p*V[i].first + q*V[i].second);
                mx = max(mx, p*V[i].first + q*V[i].second);
            }
            result = max(mx - mn, result);
        }
    }
    cout << result << "\n";
}


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

int main(){
    int n, h, w, a, b;
    cin >> n >> h >> w;
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        if(a >= h && b >= w) sum++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  for (int i=1;i <= n;i++){
    cin >> a[i];
  }
  for (int k=n;k >= 1;k--){
    if(k != 1){
      cout << a[k] << " ";
    }else if(k = 1){
      cout << a[1];
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3092
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int sum=0;
		int[] a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		int count=0;
		if(sum%(4*m)==0){
			sum=sum/(4*m)-1;
		}else{
			sum=sum/(4*m);
		}
		for(int i=0; i<n; i++){
			if(sum<a[i]){
				count++;
			}
		}
		if(count<m){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 22608
import sys
input = sys.stdin.readline
from collections import deque

K = int(input())
q = deque([])

for i in range(1, 10):
    q.append(i)

cnt = 0
    
while q:
    v = q.popleft()
    cnt += 1
    
    if cnt==K:
        print(v)
        exit()
    
    for i in range(max(0, v%10-1), min(9, v%10+1)+1):
        q.append(10*v+i)


Measured memory_bytes: 70248
import java.util.Scanner;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        if (a == b) {
            System.out.println(c);
        } else if (a == c) {
            System.out.println(b);
        } else {
            System.out.println(a);
        }
    }
}

Measured memory_bytes: 23636
#include<iostream>
#include<queue>
using namespace std;
int main() {
    string s; cin >> s;
    string d[3] = {"dream", "eraser", "erase"};
    for (int i = 0; i < s.size(); ) {
        for (int j = 0; j < 3; ++j) {
            if (s.substr(i, d[j].size()) == d[j]) {
                i += d[j].size();
                if (j == 0) { //dreamerが危険
                    if (i == s.size()) {
                        break;
                    }
                    //継続条件
                    //ere : dreamererase, dreamserase
                    //erd : dreamerdream, dreamerdreamer
                    //(s.size() - i == 2 && ... : dreamer and finish
                    if (s.substr(i, 3) == "ere" || s.substr(i, 3) == "erd"
                        || (s.size() - i == 2 && s.substr(i, 2) == "er")) {
                        i += 2;
                    }
                }
                break;
            }
            if (j == 2) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int mod = 998244353;
int n;
string s;

void Minus(vector<int> &x) {
	int i;
	
	x[0]--;
	if (x[0] < 0) {
		i = 1;
		while (true) {
			x[i - 1] += 2;
			x[i]--;
			if (x[i] >= 0) break;
			i++;
		}
	}
}

bool check(vector<int> &x, int d) {
	vector<int> y(n, 0);
	int i, j;
	
	//cout << "d = " << d << ", x = ";
	//for (i = x.size() - 1; i >= 0; i--) cout << x[i];
	//cout << endl;
	
	int shift = 0;
	for (i = 0; i < n / d; i++) {
		if (i % 2 == 0) {
			for (j = 0; j < d; j++) {
				y[shift] += x[j];
				shift++;
			}
		}
		else {
			for (j = 0; j < d; j++) {
				y[shift] += (!x[j]);
				shift++;
			}
		}
	}
	
	//cout << "y = ";
	//for (i = n - 1; i >= 0; i--) cout << y[i];
	//cout << endl;
	
	for (i = n - 1; i >= 0; i--) {
		int p = s[n - 1 - i] - '0';
		int q = y[i];
		if (q != p) {
			if (q > p) return false;
			return true;
		}
	}
	return true;
}

int calc(int d) {
	
	//まずは、2^(n - d) * x <= int(s)なる最大のxを探す
	int i;
	vector<int> x;	//…x2x1x0 (2進数)
	x.resize(d);
	//cout<< "x.size() = " << x.size() << endl;
	
	int xval = 0;
	for (i = 0; i < d; i++) {
		int val = s[d - 1 - i] - '0';
		x[i] = val;
		xval *= 2;
		xval += x[i];
		if (xval >= 4) xval = 4;
	}
	
	//x, x-1, x-2, x-3…あたりを試すと条件を満たす最大のxが分かる
	while (true) {
		if (check(x, d)) break;
		xval--;
		if (xval <= -1) break;
		Minus(x);
	}
	if (xval <= -1) return 0;
	
	int ret = 0;
	int mul = 1;
	for (i = 0; i < x.size(); i++) {
		ret += x[i] * mul;
		ret %= mod;
		mul *= 2;
		mul %= mod;
	}
	ret++;
	ret %= mod;
	return ret;
}

signed main() {
	int i, j, k;
	
	cin >> n >> s;
	
	static int memo[200001];
	for (i = 1; i <= n; i++) {
		if (n % i != 0) continue;
		if ((n / i) % 2 == 0) continue;
		memo[i] = calc(i);
		//cout << "memo[" << i << "] = " << memo[i] << endl;
	}
	
	//約数包除？冷静に考えると包除さえいらない.
	//f(x) = 最小周期xの文字列の個数
	//g(x) = 周期xの文字列の個数
	//とおくとg(x) = sum(d, f(d), where x % d == 0)
	//g(x)からf(x)を求めたい。とりあえず、
	//f(x) = g(x) - sum(d, f(d), where x % d == 0 and d < x)
	//となるが、d < xよりf(0)から順番に求めていけば、これは普通に計算できる。
	//fをgだけで表そうとするとヤバいが、漸化式を使えば簡単という.. (個人的にここが一番山場です）
	static int cnt[200001];	//cnt[x] = f(x). n / xが奇数でないxについてはドントケア(0とは限らない).
	for (i = 1; i <= n; i++) { cnt[i] = memo[i]; }
	for (i = 1; i <= n; i++) {
		for (j = i * 2; j <= n; j += i) {
			cnt[j] -= cnt[i];
			if (cnt[j] < 0) cnt[j] += mod;
		}
	}
	
	int ans = 0;
	for (i = 1; i <= n; i++) {
		if (n % i != 0 || (n / i) % 2 == 0) continue;
		ans += 2 * i * cnt[i] % mod;
		ans %= mod;
		//cout << "cnt[" << i << "] = " << cnt[i] << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
import sys
sys.setrecursionlimit(10**9)
N,M = map(int,input().split())
G = [[] for n in range(N)]

for m in range(M):
  a,b,d = map(int,input().split())
  G[a-1].append((b-1,d))
  G[b-1].append((a-1,-d))

X = [None]*N

def dfs(i, x=0):
  for j, d in G[i]:
    if X[j] is None:
      X[j] = x+d
      dfs(j, x+d)
    elif X[j] != x+d:
      print("No")
      exit()

for n in range(N):
  if X[n] is not None:
    continue
  X[n] = 0
  dfs(n)

print("Yes")

Measured memory_bytes: 161152
#!/usr/bin/env python3
from collections import Counter

def check():
    h, w = map(int, input().split()) 
    c = Counter()
    for i in range(h):
        c.update(input())
    cc = {}
    cc[4] = (h >> 1) * (w >> 1)
    cc[2] = (h & 1) * (w >> 1) + (w & 1) * (h >> 1)
    cc[1] = (h & 1) * (w & 1)
    tt = list(c.values())
    for v in [4, 2, 1]:
        for i in range(len(tt)):
            k = min(cc[v], tt[i] // v)
            tt[i] -= k * v
            cc[v] -= k
    return sum(tt) == 0


print(["No", "Yes"][check()])


Measured memory_bytes: 3444
using System;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static Queue<int> F(int a)
    {
        Queue<int> q = new Queue<int>();
        while (a % 2 == 0)
        {
            q.Enqueue(2);
            a /= 2;
        }
        for(int i=3; i <= a; i += 2)
        {
            while (a % i == 0)
            {
                q.Enqueue(i);
                a /= i;
            }
        }
        return q;
    }

    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var S = Console.ReadLine().Split(' ');

        long s = 0;
        long m = long.MaxValue;
        int negV = 0;

        for (int i = 0; i < N; i++)
        {
            long A = long.Parse(S[i]);
            if (A < 0)
                negV++;
            m = Math.Min(m, Math.Abs(A));
            s += Math.Abs(A);
        }

        if (negV % 2 == 0)
            Console.WriteLine(s);
        else
            Console.WriteLine(s-2*m);
    }
}


Measured memory_bytes: 26208
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N, Q; cin >> N >> Q;
  string S; cin >> S;
  int c[N];
  c[0] = 0;
  rep(i,N-1) {
    if (S.substr(i,2)=="AC") c[i+1] = 1;
    else c[i+1] = 0;
  }
  rep(i,N){
    if (i==0) continue;
    else c[i] += c[i-1];
  }
  
  rep(q,Q){
    int l, r;
    cin >> l >> r;
    cout << c[r-1] - c[l-1] << endl;
  }
  


  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 4140
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    int k,t;
    cin>>k>>t;
    int ma=0;
    rep(i,0,t){
        int a;
        cin>>a;
        ma=max(a,ma);
    }
    cout<<max(ma-1-(k-ma),0)<<endl;
}

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

int main(void){
    string A, B;
    cin >> A >> B;

    int a = A.size();
    int b = B.size();

    if(a>b){
        cout << "GREATER" << endl;
        return 0;
    }else if(a<b){
        cout << "LESS" << endl;
        return 0;
    }
    for(int i=0; i<a; i++){
        if((int)A[i]>(int)B[i]){
            cout << "GREATER" << endl;
            return 0;
        }else if((int)A[i]<(int)B[i]){
            cout << "LESS" << endl;
            return 0;
        }
    }
    cout << "EQUAL" << endl;
    return 0;
}


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

int main() {
    int N, L, T;

    cin >> N >> L >> T;
    int X[N], W[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> W[i];
    }

    int count = 0;

    for (int i = 1; i < N; i++) {
        if (W[i] - W[0] > 0) {
            int dist = 2 * T - X[i] + X[0];
            if (dist >= 0) {
                count += dist / L + 1;
            }
        } else if (W[i] - W[0] < 0) {
            int dist = 2 * T + X[i] - X[0] - L;
            if (dist >= 0) {
                count -= dist / L + 1;
            }
        }
    }

    for (int i = 0; i < N; i++) {
        if (W[i] == 1)
            X[i] = (X[i] + T) % L;
        else
            X[i] = (X[i] - T % L + L) % L;
    }

    int X0 = X[0];

    sort(X, X + N);

    int offset;

    for (int i = 0; i < N; i++) {
        if (X[i] == X0) {
            offset = i - count % N + N;
            if (W[0] == 2) break;
        }
    }

    for (int i = 0; i < N; i++) {
        cout << X[(i + offset) % N] << endl;
    }

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define endl "\n"
string x;
ll ans=0,mas[200000],n=0;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>x;
for(int i=0;i<x.length();i++)
{
    if(x[i]=='A'){mas[n++]=1;continue;}
    if(i<x.length()-1)if(x[i]=='B' && x[i+1]=='C'){mas[n++]=0,i++;continue;}
    mas[n++]=-1;
}ll s=0;
for(int i=0;i<n;i++)
{
    if(mas[i]==1)s++;
    else if(!mas[i])ans+=s;
    else s=0;
}
cout<<ans<<endl;
return 0;

}


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

using namespace std;

int n,r;
vector<int> ans;
int main(){
	while(1){
		vector<int> m;
		cin >> n >> r;
		if(n + r == 0) break;
		for(int i = 1;i <= n;i++){
			m.push_back(i);
		}
		for(int i = 0; i < r;i++){
			int c,p;
			cin >> p >> c;
			vector<int> nm;
			
			for(int j = 0;j < n;j++){
				if(j<n-p-c+1 || n-p+1<=j){
					nm.push_back(m[j]);
				}
			}
			for(int j = n-p-c+1;j < n-p+1;j++){
				nm.push_back(m[j]);
			}
			
			m = nm;
		}
		ans.push_back(m[n-1]);
	}
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3096
N,K = [int(x) for x in input().split()]
S = list(input())
point = N - 1
count = 0
for i in range(N-1):
    if S[i] != S[i+1]:
        point -= 1
        count += 1
if K >= count/2:
    print(N-1)
elif K >= int(count/2):
    print(N-2)
else:
    print(point+2*K)

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

string s;
string s2;
ll ans;

void calc()
{
  ll t1 = 0, t2 = 0;
  for (char c : s2)
    if (c != '+')
    {
      t1 *= 10;
      t1 += c - '0';
    }
    else
    {
      t2 += t1;
      t1 = 0;
    }
  ans += t1 + t2;
}

void func(int c)
{
  s2 += s[c];
  if (c == s.size() - 1)
  {
    calc();
    s2.pop_back();
    return;
  }
  func(c + 1);
  s2 += '+';
  func(c + 1);
  s2.pop_back();
  s2.pop_back();
  return;
}

int main()
{
  cin >> s;
  ans = 0;
  s2 = "";
  func(0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);

$xSortList = [];

// データを入れていく
for($i = 0; $i < $N; $i++) {
	fscanf(STDIN, "%d %d", $X, $D);
	$xSortList[] = [
		"x" => $X,
		"d" => $D,
	];
}

// ソート
usort($xSortList, function($a, $b) {
	return($a["x"] <=> $b["x"]);
});

// 検索用
function getIdx(&$list, $sIdx, $eIdx, $maxX) {
	$idx = 0;
	while($sIdx <= $eIdx) {
		// 真ん中
		$idx = intval(($eIdx + $sIdx) / 2);
		
		if($list[$idx]["x"] == $maxX) {
			return($idx);
		}
		if($list[$idx]["x"] > $maxX) {
			$eIdx = $idx - 1;
		}
		else {
			$sIdx = $idx + 1;
		}
	}
	return($sIdx);
}

// ループ(範囲を求める)
for($i = $N - 1; $i >= 0; $i--) {
	//==================================================================
	// 影響範囲計算
	//==================================================================
	$xSortList[$i]["r"] = $i;

	$maxX = $xSortList[$i]["x"] + $xSortList[$i]["d"];
	
	$idx = max(0, min($N - 1, getIdx($xSortList, 0, $N - 1, $maxX)));
	
	if($xSortList[$idx]["x"] >= $maxX) {
		$idx = max(0, $idx - 1);
	}
	for($n = $i + 1; $n <= $idx; $n++) {
		$xSortList[$i]["r"] = max($xSortList[$i]["r"], $xSortList[$n]["r"]);
		$n = $xSortList[$i]["r"];
	}

	//==================================================================
	// パターン計算
	//==================================================================
	$onNextIdx = $xSortList[$i]["r"] + 1;
	$offNextIdx = $i + 1;
	
	// ONのときよう
	$on = 1;
	if($onNextIdx < $N) {
		$on =  $xSortList[$onNextIdx]["a"];
	}
	
	// OFFのとき
	$off = 1;
	if($offNextIdx < $N) {
		$off =  $xSortList[$offNextIdx]["a"];
	}
	
	$xSortList[$i]["a"] = ($on + $off) % 998244353;
}

echo "{$xSortList[0]["a"]}\n";


Measured memory_bytes: 95088
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
char charin() {char c; cin>>c; return c;}
string strin() {string s; cin>>s; return s;}
int main(){
    ll n=lin();
    ll ans=n*(n-1)/2;
    cout<<ans<<endl;
}


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

int main(){
	int i, j;
	int n, tmp;
	int count = 0;
	    scanf("%d", &n);
	    for(i = 0; i < n; i++){
        scanf("%d", &tmp);
        for(j = 2; j <= sqrt(tmp); j++){
            if (tmp % j == 0) break;
        }
        if (j > sqrt(tmp) || sqrt(tmp) < 2){
count++;
}
}
    printf("%d\n", count);
return 0; 
}

Measured memory_bytes: 596
n=int(input())
arr=list(map(int,input().split()))
dic={}
for val in arr:
  if val not in dic:
    dic[val]=1
  else:
    dic[val]+=1
l=len(dic)
if l==1:
  if 0 in dic:
    print('Yes')
  else:
    print('No')
elif l==2:
  if n%3==0:
    if 0 in dic:
      if dic[0]==n//3:
        print('Yes')
      else:
        print('No')
    else:
      print('No')
  else:
      print('No')
elif l==3:
  if n%3==0:
    arr2=list(dic.keys())
    arr3=list(dic.values())
    if (arr2[0]^arr2[1]^arr2[2])==0:
      if dic[arr2[0]]==n//3 and dic[arr2[1]]==n//3 and dic[arr2[2]]==n//3:
        print('Yes')
      else:
        print('No')
    else:
      print('No')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 14212
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)

using namespace std;

int main(void){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int ans=0;
  for(int i=1;i<=100;i++) if(i>A && i<=B && i>C && i<=D) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
//#define REP(i,n) for(int i = 0;i < (n);i++)
//#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;
 
int main(){
  long long a,b,c,d,e,f;
  cin >> a >> b>> c >> d >> e >> f;
  
  long long sum = 0;
  vector <long long> A;
  for(int i = 0;i < f/a+1;i++){
    
    for(int j = 0;j < f/b+1;j++){
      
      sum = a*100*i+ b*100*j;
      if(sum <= f){
	A.push_back(sum);
      }
      else
	break;
    }
 
  }
  vector <long long> B;
  for(int i = 0;i < f/c+1;i++){
    
    for(int j = 0;j < f/d+1;j++){
    
      sum = c*i+ d*j;
      if(sum <= f){
	B.push_back(sum);
      }
      else
	break;
    }
 
  }
  
  double res,E,bres = 0;
  long long sum1=0,sum2=0;
  for(int i = 0;i < A.size();i++){

    for(int j = 0;j < B.size();j++){
      
      if(A[i] != 0){
	res = (double)B[j]/(A[i]+B[j])*100;
	E = (double)e/(100+e)*100;
	
	if(A[i]+B[j] <= f && res <= E){
	  if(res >= bres){
	    sum1 = A[i]+B[j];
	    sum2 = B[j];
	    bres = res;
	  }
	}
      }
    }
  }
 
  cout << sum1 << " " << sum2 << endl;
  return 0;
}


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

int main() {
	vector<int> a(3);
	cin >> a.at(0) >> a.at(1) >> a.at(2);
	int cnt = 0;
	sort(a.begin(), a.end());
	if (a.at(0) % 2 == a.at(1) % 2 && a.at(1) % 2 == a.at(2) % 2) {
		cnt += (a.at(1) - a.at(0)) / 2;
		cnt += (a.at(2) - a.at(1));
	} else {
		if (a.at(0) % 2 == a.at(1) % 2) {
			cnt += (a.at(1) - a.at(0)) / 2;
			cnt += (a.at(2) - a.at(1));
		} else {
			if (a.at(0) % 2 == a.at(2) % 2) {
				cnt++;
				a.at(0)++, a.at(2)++;
				cnt += (a.at(1) - a.at(0)) / 2;
				cnt += (a.at(2) - a.at(1));
			} else if (a.at(1) % 2 == a.at(2) % 2) {
				cnt++;
				a.at(1)++, a.at(2)++;
				cnt += (a.at(1) - a.at(0)) / 2;
				cnt += (a.at(2) - a.at(1));
			}
		}
	}
	cout << cnt << endl;
}

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

  int n;
  cin>>n;

  set <string> id;

  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    id.insert(s);
  }

  int m,open=0;
  cin>>m;

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

    string s;
    cin>>s;

    if(id.count(s)){ // if(id.find(s) != id.end()

      open++;

      if(open%2) cout<<"Opened by "+s<<endl;
      else cout<<"Closed by "+s<<endl;

    }

    else cout<<"Unknown "+s<<endl;

  }

  return 0;

}



Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int X, Y;
int main() {
  ios::sync_with_stdio(false);
  cin >> X >> Y;
  bool good = 0;
  for (int i = 0; i <= X; i++) {
    if (i * 2 + (X - i) * 4 == Y) {
      good = 1;
      break;
    }
  }
  cout << (good ? "Yes\n" : "No\n");
}

Measured memory_bytes: 3652
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] h = new int[N];
		int[] m = new int[N];
		for(int i = 0 ; i<N ; i++){
			h[i] = scan.nextInt();
			m[i] = scan.nextInt();
		}
		int M = scan.nextInt();
		int[] k = new int[M];
		int[] g = new int[M];
		int[] Z = new int[N+M];
		for(int i = 0 ; i<N ; i++){
			Z[i] =  h[i]*60+m[i];
		}
		for(int i = 0; i<M ; i++){
			k[i] = scan.nextInt();
			g[i] = scan.nextInt();
			Z[N+i] = k[i]*60+g[i];
		}
		int r;
		for(int i = 0; i < N+M ; i++){
			for(int j = i+1; j <M+N; j++){
				if(Z[i] > Z[j]){
					r = Z[i];
					Z[i] = Z[j];
					Z[j] = r;
				}
			}
		}
		for(int i = 0; i<N+M; i++){
			if(i == N+M-1){
				String s = String.valueOf(Z[i]%60);
				if(s.length() ==1){
					System.out.println(Z[i]/60+":0"+Z[i]%60);
				}else{
					System.out.println(Z[i]/60+":"+Z[i]%60);
				}
			}else{
				if(Z[i+1] != Z[i]){
					String s = String.valueOf(Z[i]%60);
					if(s.length() ==1){
						System.out.print(Z[i]/60+":0"+Z[i]%60+" ");
					}else{
						System.out.print(Z[i]/60+":"+Z[i]%60+" ");
					}
				}
			}
		}
	}
}

Measured memory_bytes: 20732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100005],t[45];
int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
    {
        int pos=0;
        while(a[i])
        {
            if(a[i]&1)t[pos]++;
            pos++;
            a[i]>>=1;
        }
    }
    ll ans=0;
    for(int i=41;i>=0;i--)
    {
        ll s=1ll<<i;
        if(t[i]>=n-t[i])ans+=s*t[i];
        else
        {
            if(k>=s)ans+=(n-t[i])*s,k-=s;
            else ans+=t[i]*s;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> c(n);
    int a[n][m];
    rep(i,0,n-1){
        cin >> c[i];
        rep(j,0,m-1){
            cin >> a[i][j];
        }
    }
    int ans = INF;
    for(int i = 0;i<(1<<n);i++){
        vector<int> v(m);
        int ne = 0;
        rep(j,0,n-1){
            if (i & (1<<j)){
                rep(k,0,m-1){
                    v[k] += a[j][k];
                }
                ne += c[j];

            }
        }
        bool flg = true;
        rep(k,0,m-1)if(v[k] < x)flg = false;
        if(flg)ans = min(ans, ne);
    }
    if(ans == INF)ans = -1;

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3628
s = input()
n = len(s)
zen = s[:n // 2]

kou= s[n // 2 + 1:]

s_rev = s[::-1]

zen_rev = zen[::-1]
kou_rev = kou[::-1]

if s == s_rev and zen == zen_rev and kou == kou_rev:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define test int t; cin>>t;
#define MOD 1000000007LL
#define all(x) (x).begin(),(x).end()

using namespace std;

ll nxt() { ll x; cin>>x; return x; }

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS

    ll n = nxt();
    ll mn = LLONG_MAX, mx = LLONG_MIN, mn2 = LLONG_MAX, mx2 = LLONG_MIN;
    for(int i = 0; i<n; i++){
        ll x, y;
        cin>>x>>y;
        mn = min(mn,x+y);
        mx = max(mx,x+y);
        mn2 = min(mn2,x-y);
        mx2 = max(mx2,x-y);
    }

    cout<<max(mx-mn,mx2-mn2)<<endl;

    return 0;
}


Measured memory_bytes: 3580
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import re

BIGNUM = 10 ** 9 + 7

def main():
    #N, K = map(int, input().split())
    N = int(input())
    S = list(input())

    nums = defaultdict(int)
    for s in S:
        nums[s] += 1

    result = 1
    for n in nums.values():
        result *= (n + 1)
        result = result % BIGNUM
    result = (result - 1) % BIGNUM
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49392
#include <stdio.h>

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

    int array[100];
    for (int i=0;i<len;i++) {
        scanf("%d", &array[i]);
    }

    int tmp, flag = 1, count = 0;
    while (flag) {
        flag = 0;
        for (int j=len-1;j>0;j--) {
            if (array[j] < array[j-1]) {
                tmp = array[j];
                array[j] = array[j-1];
                array[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
    }

    for (int i=0;i<len;i++) {
        if (i != len-1) {
            printf("%d ", array[i]);
        } else {
            printf("%d\n", array[i]);
        }
    }
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 2752
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;

vi a;
vi ans;

void input() {
  a.clear();
  ans.clear();

  cin >> n;

  a.resize(n - 1);
  ans.resize(n);

  for (auto&& i : a)
    cin >> i;
}

void solve() {
  for (auto&& i : a)
    ans[i - 1]++;

  for (auto&& i : ans)
    cout << i << '\n';

  cout << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 3;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


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

int main() {
  
int N,sum;
  cin >> N;
  sum = 0;
  for(int i = 0;i<N;i++){
    string s;
    cin >> s;
    if (s=="Y"){
      cout << "Four" << endl;
      break;
    }
    else if (i==N-1){
      cout << "Three" << endl;
    }
  }
  }
  
  

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

int tot;
int cnt[505];
int grid[505][505];
int cnt2[505];
int main() {
	// your code goes here
	int n;
	cin >> n;
	for (int i = 0; i < n ; i ++){
		string s;
		cin >> s;
		for (int j = 0; j < n; j++) {
			grid[i][j] = (s[j] == '#');
			cnt[i] += grid[i][j];
			cnt2[j] += grid[i][j];
			tot += grid[i][j];
		}
	}
	if (tot == 0) {
		cout << -1 << endl;
		return 0;
	}
	int ans = n;
	int best = n;
	for (int i = 0; i < n; i++) {
		if (cnt2[i] == n) ans--;
		best = min(best, n - cnt[i] + (cnt2[i] == 0));
	}
	ans += best;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- sortOn Down <$> getIntList
    print . succ . length . takeWhile id $ zipWith (\a s -> a <= 2 * s) as (tail (scanr (+) 0 as)) 

Measured memory_bytes: 36476
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, na = 0, nb = 0, a;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    if(i & 1) na ^= a;
    else nb ^= a;
  }
  if(n & 1) na ^= nb, nb = 0;
  if(!na && !nb) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
// clang-format off
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

// clang-format on
int main() {

    llint n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    REP(i, n) {
        cin >> a[i];
    }

    REP(i, m) {
        cin >> b[i];
    }

    REP(i, n - m + 1) {

        REP(j, n - m + 1) {
            REP(k, m) {
                REP(l, m) {
                    if(a[i+k][j+l]!=b[k][l]){
                        goto END;
                    }
                }
            }
            cout << "Yes" << endl;
            return 0;
        END:;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

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

  bool yes = true;
  int acnt = 0;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;

    if (s[0] == 'A') {
      acnt++;
    } else if (s[0] == 'U') {
      if (acnt == 0) {
	yes = false;
      }
      acnt--;
    }
  }

  cout << (acnt == 0 && yes ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 3140
import math
N = int(input())
ans = 0
for m in range(1,math.ceil(N**(1/2))):
  if (N-m)%m == 0 and m < (N-m)//m:
    ans += int((N-m)/m)

if N == 1:
  ans = 0
if N == 2:
  ans = 0
if N == 3:
  ans = 2
if N == 6:
  ans = 5
print(ans)    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  cout<<b*(c/a)<<endl;
  
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		
		int N=sc.nextInt();
		int T=sc.nextInt();
		int[] c=new int[N];
		int[] t=new int[N];
		int sum=0;
		int min=1000;
		for(int i=0;i<N;i++) {
			c[i]=sc.nextInt();
			t[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(t[i]<=T) {
				sum=1;
			}
			
		}
		for(int i=0;i<N;i++) {
			if(t[i]<=T)
				if(min>=c[i]){
					min=c[i];
					
				}
			
		}
		
		
		
		
		
		
		
		
		if(sum==0) {
			System.out.println("TLE");
		}else {
			System.out.println(min);
			
		}
		
		
		
	}

}

Measured memory_bytes: 23508
while gets do
  sum = $_.to_i
  count = 0
  0.upto(9).each do |a|
    break if a > sum
    0.upto(9).each do |b|
      break if (a + b) > sum
      0.upto(9).each do |c|
        break if (a + b + c) > sum
        0.upto(9).each do |d|
          if (a + b + c + d) == sum
            count += 1
          elsif (a + b + c + d) > sum
            break
          end
        end
      end
    end
  end
  puts count
end

Measured memory_bytes: 6136
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	private long cnt = 0;
	private int[] g;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Main main = new Main();
		main.shellSort(a, n);
		System.out.println(main.g.length);
		// 整数Gの表示
		for (int i = main.g.length - 1; i >= 0; i--) {
			if (i > 0) {
				System.out.print(main.g[i] + " ");
			} else { //最後の1回
				System.out.println(main.g[i]);
			}
		}
		System.out.println(main.cnt);
		// 整列したaの表示
		for (int i : a) {
			System.out.println(i);
		}

	}

	private void insertionSort(int[] a, int n, int g) {
		for (int i = g; i < n; i++) {
			int v = a[i];
			int j = i - g;

			while (j >= 0 && a[j] > v) {
				a[j + g] = a[j];
				j -= g;
				cnt++;
			}
			a[j + g] = v;

		}

	}

	private void shellSort(int[] a, int n) {
		// 数列 g = {1 , 4 , 13 , 40 , … }; を生成
		List<Integer> list = new ArrayList<>();
		for (int h = 1;;) {
			if (h > n) {
				break;
			}
			list.add(h);
			h = 3 * h + 1;
		}

		g = new int[list.size()];
		for (int i = 0; i < g.length; i++) {
			g[i] = list.get(i);
		}

		// 配列の要素を逆順に取り出して引数gを指定
		for (int i = g.length - 1; i >= 0; i--) {
			insertionSort(a, n, g[i]);
		}

	}

}


Measured memory_bytes: 299660
def is_prime(x):
    # Perform prime number discrimination for odd numbers of 3 or more.
    return pow(2, x - 1, x) == 1

def solve():
    n = int(input())
    ans = n
    if n % 2 == 0:
        ans -= ans // 2
        while n % 2 == 0:
            n //= 2
    d = 3
    while d <= n ** 0.5:
        if is_prime(d) and n % d == 0:
            ans -= ans // d
            while n % d == 0:
                n //= d
        d += 2
    if is_prime(n):
        ans -= ans // n
    print(ans)

solve()

Measured memory_bytes: 7852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007LL;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

vll F;
ll dp[110][100100];

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, k;
    cin >> n >> k;
    ll c = 1;
    ll nu = 0;
    while(1){
        if(n/c > n/(c+1)){
            F.emplace_back(n/c-n/(c+1));
            c++;
        }else{
            nu = n/c;
            break;
        }
    }
    rep(j, nu){
        F.emplace_back(1);
    }
    reverse(ALL(F));
    //PRINT(F);
    //cout << accumulate(ALL(F), 0LL) << endl;
    ll FS = SZ(F);
    rep(i, FS){
        dp[1][i+1] = F[i];
    }
    //PRINT(dp[1]);
    repr(i, 2, k+1){
        dp[i][FS] = dp[i-1][1] % MOD;
        for(int j = FS-1; j >= 1; j--){
            dp[i][j] = (dp[i][j+1]+dp[i-1][FS-j+1]) % MOD;
        }
        repr(j, 1, FS+1){
            dp[i][j] *= F[j-1];
            dp[i][j] %= MOD;
        }
    }
    ll ans = 0;
    repr(i, 1, FS+1){
        ans += dp[k][i];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 79736