akhauriyash/Code-Regression huggingface dataset:
def main():
    H = map(int, open(0).read().split()[:1:-1])
    pre = None
    for h in H:
        if pre is None:
            pre = h
        if pre + 1 < h:
            print("No")
            return
        if pre + 1 == h:
            pre = h - 1
        else:
            pre = h

    print("Yes")
    return


main()


Measured memory_bytes: 11200
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: usize = read();
  let mut t: Vec<u64> = Vec::new();
  for _ in 0..n {
    let v: u64 = read();
    t.push(v);
  }


  let mut lcm = 1;
  for i in 0..n {
    let g = gcd(lcm, t[i]);
    lcm = lcm * (t[i] / g);
  }

  println!("{}", lcm);
}


fn gcd(a: u64, b: u64) -> u64 {
  if b > a {
    gcd(b, a);
  }

  if a % b == 0 {
    return b;
  }

  let r: u64 = a % b;

  return gcd(b, r);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))

const int inf = 999999999;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n, a, b; cin >> n >> a >> b;
	cout << min(n * a, b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int n;
  cin >> n;
  set<string> st;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;

  return 0;
}


Measured memory_bytes: 19172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] leftABCD = new int[4];
		int[] rightABCD = new int[4];
		while(stdIn.hasNext()){
			float temp = stdIn.nextFloat();
			if(1.1 <= temp){
				leftABCD[0]++;
			}else if(0.6 <= temp & temp < 1.1){
				leftABCD[1]++;
			}else if(0.2 <= temp & temp < 0.6){
				leftABCD[2]++;
			}else if(temp < 0.2){
				leftABCD[3]++;
			}
			temp = stdIn.nextFloat();
			if(1.1 <= temp){
				rightABCD[0]++;
			}else if(0.6 <= temp & temp < 1.1){
				rightABCD[1]++;
			}else if(0.2 <= temp & temp < 0.6){
				rightABCD[2]++;
			}else if(temp < 0.2){
				rightABCD[3]++;
			}
		}
		for(int i = 0; i < 4;i++){
			System.out.println(leftABCD[i] + " " + rightABCD[i]);
		}
	}
}

Measured memory_bytes: 12000
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())

n, d = MI()
result = 0
d2 = d*d

for i in range(n):
    x,y = MI()
    dis = x**2+y**2
    if dis <= d2:
        result+=1


print(result)


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

int main() {
  string s;
  cin >> s;
  int l = s.size();
  bool hi = true;
  int i = 0;
  while (i < l) {
    if (i + 1 == l) { hi = false; break; }
    if (s[i] != 'h' || s[i + 1] != 'i') { hi = false; break; }
    i += 2;
  }
  if (hi) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


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

void stradd(char *str1, char *str2)
{
	char temp[128];
	int max;
	int i;
	
	if (strlen(str1) > strlen(str2)){
		max = strlen(str1);
	}
	else {
		max = strlen(str2);
	}
	
	memset(temp, '\0', sizeof(temp));
	strcpy(&temp[max - strlen(str1) + 1], str1);
	i = 0;
	while (temp[i] == '\0'){
		 temp[i] = '0';
		 i++;
	}
	strcpy(str1, temp);
	
	memset(temp, '\0', 128);
	strcpy(&temp[max - strlen(str2) + 1], str2);
	i = 0;
	while (temp[i] == '\0'){
		 temp[i] = '0';
		 i++;
	}
	strcpy(str2, temp);
	
	for (i = max; i >= 0; i--){
		str1[i] += str2[i] - '0';
		if (str1[i] > '9'){
			str1[i] -= 10;
			str1[i - 1] += 1;
		}
	}
	if (str1[0] == '0'){
		memset(temp, '\0', sizeof(temp));
		strcpy(temp, &str1[1]);
		memset(str1, '\0', sizeof(str1));
		strcpy(str1, temp);
	}
}

int main(void)
{
    char l[3][128], lt[128], s[128];
    int flag;
    int i, j, k;
    
    while (~scanf("%s", lt)){
        getchar();
        
        memset(l, '\0', sizeof(l));
        i = 0;
        
        while (lt[i] != '+'){
            l[0][i] = lt[i];
            i++;
        }
        
        j = ++i;
        
        while (lt[i] != '='){
            l[1][i - j] = lt[i];
            i++;
        }
        
        j = ++i;
        
        while (lt[i] != '\0'){
            l[2][i - j] = lt[i];
            i++;
        }
        flag = 0;
        
        for (i = 0; i < 10; i++){
            memset(s, '\0', sizeof(s));
            s[0] = '0';
            for (j = 0; j < 3; j++){
                k = 0;
                memset(lt, '\0', sizeof(lt));
                while (l[j][k] != '\0'){
                    lt[k] = l[j][k];
                    if (l[j][k] == 'X'){
                        lt[k] = i + '0';
                    }
                    k++;
                }
                if (j == 0 || j == 1){
                    stradd(s, lt);
                }
                else if (strcmp(s, lt) == 0){
                        printf("%d\n", i);
                        flag = 1;
                }
            }
        }
        if (flag == 0){
            printf("NA\n");
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
n = int(input())
direction = []
click = [0]*n
click[0] = 1

for i in range(n):
  direction.append(int(input()))
  
index = 0
cnt = 0
while cnt<=100000:
  cnt += 1
  index = direction[index] - 1
  click[index] += 1
  
  if index == 1:
    break
  if click[index] ==2:
    cnt = -1
    break
   
print(cnt)
  


Measured memory_bytes: 7852
n,m = list(map(int,input().split()))
LR= [tuple(input().split()) for i in range(m)]

min = 0
max = 1000000000
for L, R in LR:
  if(int(L) > min):
    min = int(L)
  if(int(R) < max):
    max = int(R)
if(max - min >= 0):
  print(max - min + 1)
else:
  print(0)

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

int main() {
    long long N, a, ans;
    cin >> N;
    map<long long, long long> mp;
    ans = 0;
    for (long long i = 1; i <= N; i++) {
        cin >> a;
        ans += mp[i - a];
        mp[i + a] ++;
    }
    cout << ans << endl;
 
    
}



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

using namespace std;
int main() {
  int n;
  cin >> n;
  int moti[n];
  for (int i = 0; i < n; i++) {
    cin >> moti[i];
  }

  sort(moti, moti + n);
  int cnt = 0;
  int temp = -1;
  for (int i = 0; i < n; i++) {
    if (temp < moti[i]) cnt++;
    temp = moti[i];
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * 不安なら ll を使う.
 * 小数は double を忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
 * 比較するときは型まで注意
 * 区間の計算は累積和
*/

/* ===== コーナーケースに気をつけろ ===== */

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

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


int main(void) {
    int j, i, num, n, flag, count = 0;
    scanf("%d",&n);
    for(j = 0; j < n; j++ ) {
        scanf("%d",&num);
        flag = 0;
        for(i = 2; (double)i <= sqrt((double)num); i += 2 ) {
            if(!(num % i)) {
                flag = 1;
                break;
            }
            if(i == 2) {
                i--;
            }
        }
        if(!flag) {
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#define abs(X) ((X) < 0 ? -1 * (X) : (X))

using namespace std;

typedef long long ll;

int main()
{
    int n, m, x, y;
    int xx, yy;
    int mx, my;

    cin >> n >> m >> x >> y;

    mx = x;
    my = y;
    for (int i = 0; i < n; i++) {
        cin >> xx;

        mx = max(mx, xx);
    }

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

        my = min(my, yy);
    }

    if (mx < my) {
        cout << "No ";
    }
    cout << "War" << endl;
    
    return 0;
}


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

using namespace std;

const char alpha[27] = { 'z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

void d_26(long long N) {
	if (N > 26) {
		long long n = N / 26;
		d_26(n);
	}
	
	long long flag = N % 26;
	printf("%c", alpha[flag]);
	
}

int main() {
	long long N;
	int a[10000];
	cin >> N;

	//d_26(N);
	int i = 0;
	while (N) {
		a[i] = N % 26;
		if ((N % 26) == 0) {
			N /= 26;
			N--;
		}
		else N /= 26;

		i++;
	}

	for (int j = i-1;j >= 0;j--) {
		int flag = a[j];
		printf("%c", alpha[flag]);
	}

	return 0;
}

Measured memory_bytes: 3640
W, H, x, y = map(int, input().split())
is_mid_x = W % 2 == 0 and W // 2 == x
is_mid_y = H % 2 == 0 and H // 2 == y
print(H * W / 2, 1 if is_mid_y and is_mid_x else 0)


Measured memory_bytes: 2940
N,P=list(map(int,input().split()))
pf={}
m=P
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
out = 1
for k,v in pf.items():
    out *= k**(v//N)
print(out)


Measured memory_bytes: 63432
#include <cstdio>
#include <algorithm>

const int MAXN = 100005;

struct City {
    int p, y, order;
    long long id;
} C[MAXN];

int main() {
    int m;
    scanf("%*d %d", &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &C[i].p, &C[i].y);
        C[i].order = i;
    }

    std::sort(C, C + m, [](const City &a, const City &b) {
                return a.p == b.p ? a.y < b.y : a.p < b.p;
            });

    int rk, last = 0;
    for (int i = 0; i < m; i++) {
        if (C[i].p != last) rk = 0;
        C[i].id = C[i].p * 1000000ll + (++rk);
        last = C[i].p;
    }

    std::sort(C, C + m, [](const City &a, const City &b) {
                return a.order < b.order;
            });

    for (int i = 0; i < m; i++) printf("%012lld\n", C[i].id);
    
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

#define N 26
#define MAX_T 1.9

const int INF = 1 << 30;
const double mean = 0.0;
const double stddev = 1.0;

int c[N];
int s[365][N];
int last[N];
std::chrono::time_point<std::chrono::steady_clock> start, endt;
random_device rd;
mt19937 generator(rd());
uniform_real_distribution<> dist_real(0.0, 1.0);
uniform_int_distribution<> dist_int(0, RAND_MAX);

struct ContestInfo {
	int D;
	long score;
	long best_score;
	vector<int> t;
	vector<int> best_t;
	set<int> held[N];
	ContestInfo(int dd) : D(dd), score(0) {
		t.resize(D, -1);
		for (int i = 0; i < N; i++) {
			held[i].insert(-1);
			held[i].insert(D);
			score -= c[i] * D * (D + 1) / 2;
		}
	}

	void add(int dd, int qq) {
		if (t[dd] != -1) {
			cout << "Add faild!" << endl;
			exit(1);
		}

		t[dd] = qq;
		score += s[dd][qq];
		held[qq].insert(dd);
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score -= c[qq] * range(*litr, *ritr);
		score += c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
	}

	void erase(int dd) {
		if (t[dd] == -1) {
			cout << "Erase faild!" << endl;
			exit(1);
		}
		int qq = t[dd];
		t[dd] = -1;
		score -= s[dd][qq];
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score += c[qq] * range(*litr, *ritr);
		score -= c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
		held[qq].erase(itr);
	}

	void change(int dd, int qq) {
		erase(dd);
		add(dd, qq);
	}

	void save() {
		best_t = t;
		best_score = score;
	}

	void output(bool show = false) {
		for (int i = 0; i < D; i++)
			cout << best_t[i] + 1 << endl;
		if (show) cout << best_score << endl;
	}
};

double dice() {
	return dist_real(generator);
}

double prob(double rem) {
	return 1.0 / pow(3, rem);
}

void tic() {
	start = std::chrono::steady_clock::now();
}

double toc() {
	endt = std::chrono::steady_clock::now();
	std::chrono::duration<double> elapsed_seconds = endt - start;
	return elapsed_seconds.count();
}

int main() {
	int d;
	cin >> d;
	for (int i = 0; i < N; i++)
		cin >> c[i];
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < N; j++) {
			cin >> s[i][j];
		}
	}

	tic();
	int t;
	ContestInfo ci(d);
	for (int i = 0; i < d; i++) {
		// t = max_element(s[i], s[i] + N) - s[i];
		t = dist_int(generator) % N;
		ci.add(i, t);
	}

	int current_score = ci.score;
	int best_score = current_score;
	ci.save();

	int dd, qq;
	while (toc() < MAX_T) {
		dd = dist_int(generator) % d;
		qq = dist_int(generator) % N;
		int old_q = ci.t[dd];
		ci.change(dd, qq);
		long new_score = ci.score;
		// if (new_score < current_score || prob(MAX_T - toc()) < dice()) {
		if (new_score < current_score) {
			ci.change(dd, old_q);
		} else {
			current_score = new_score;
		}
		if (best_score < current_score) {
			best_score = current_score;
			ci.save();
		}
	}
	ci.output();
}

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

#define fir first
#define sec second

vector < pair <int, int> > vi;
int dp[100001];

int main(void)
{
	int n, L, tmp;
	cin >> n >> L;
	
	for (int i = 0; i < n; i++){
		cin >> tmp;
		vi.push_back(make_pair(tmp, i));
	}
	sort(vi.begin(), vi.end());
	
	for (int i = 0; i < vi.size(); i++){
		dp[vi[i].sec + 1] = max(dp[vi[i].second], dp[vi[i].second + 2]) + (L - vi[i].fir);
	}
	
	int res = 0;
	for (int i = 0; i <= n; i++){
		res = max(res, dp[i]);
	}
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 1896
//# define FLAG
///delet....................................
//# include <bits/stdc++.h>
# include <iostream>
# include <cstring>
# include <cstdlib>
# include <cstdio>
# include <string>
# include <cmath>
# include <ctime>
# include <set>
# include <map>
# include <queue>
# include <stack>
# include <bitset>
# include <vector>
# include <fstream>
# include <algorithm>
using namespace std;
# define eps 1e-8
# define VI vector<int>
# define pb push_back
# define mp make_pair
# define pi acos(-1.0)
# define bug puts("H")
# define mem(a,b) memset(a,b,sizeof(a))
# define IOS ios::sync_with_stdio(false)
# define FO(i,n,a) for(int i=n; i>=a; --i)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define MAX 0x7fffffffffffff
# define INF 0x3f3f3f3f
# define MOD 1e9+7
# define Template int   ///          <-------------变量类型
# define hr putchar('\n')
# define pc putchar
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef unsigned long long ULL;
typedef long long LL;

struct co{
    LL lit,cost;
}bo[5],bo2[5];

int t[5];

bool cmp(co a,co b){
    if(a.cost!=b.cost)
        return a.cost<b.cost;
    else
        return a.lit<b.lit;
}
//
//bool cmp1(co a,co b){
//    return a.lit<b.lit;
//}

int main() {
    IOS;
    LL n,sum=0;
    mem(bo,0);
    mem(bo2,0);
    for(int i=1;i<=4;i++) cin>>t[i];
    cin>>n;
    for(int i=1;i<=4;i++){
        bo[i].lit=bo2[i].lit=i;
        bo2[i].cost=t[i]*pow(2,4-i);
        bo[i].cost=t[i]*pow(2,3-i);
    }
    sort(bo+1,bo+4,cmp);
    sort(bo2+1,bo2+5,cmp);
    if(n>=2){
        if(n%2==0){
            sum=n/2*bo2[1].cost;
        }
        else
        {
            sum=(n-1)/2*bo2[1].cost;
            sum+=1*bo[1].cost;
        }
    }
    else{
        sum=1*bo[1].cost;
    }
    cout<<sum<<endl;
    return 0;
}
/*
1000000000 500000000 250000000 125000000

*/





Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

int main(){
	const int N=1000*(1+5+10+50+100+500),coin[]={1,5,10,50,100,500};
	static int chg[N+1];
	for(int i=1;i<=N;i++){
		chg[i]=INF;
		rep(j,6) if(i-coin[j]>=0) chg[i]=min(chg[i],chg[i-coin[j]]+1);
	}

	for(int p;scanf("%d",&p),p;){
		int n[6],tot=0;
		rep(i,6)	scanf("%d",n+i),tot+=n[i]*coin[i];

		static int pay[N+1],dp[N+1][2];
		rep(i,tot+1){
			pay[i]=(i?INF:0);
			dp[i][0]=-1;
		}
		for(int j=5;j>=0;j--)if(n[j]>0){	// desc. order is important (consider the case 10 6 1 0 0 0 0)
			for(int i=coin[j];i<=tot;i++){
				int prc=i-coin[j];
				if(prc==0 || pay[prc]!=0){	// can make i yen
					if(dp[prc][0]!=j || dp[prc][1]<n[j]){	// whether j-th coin used up
						if(pay[prc]+1<pay[i]){
							dp[i][0]=j;
							if(dp[prc][0]!=j)	dp[i][1]=1;
							else				dp[i][1]=dp[prc][1]+1;
							pay[i]=pay[prc]+1;
						}
					}
				}
			}
		}

		int ans=INF;
		for(int i=p;i<=tot;i++)	ans=min(ans,pay[i]+chg[i-p]);
		printf("%d\n",ans);
	}

	return 0;
}

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

typedef long long int ll;

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

    ll a[n];

    for (ll i=0 ; i<n ; i++) {
        cin >> a[i];
    }

    ll sum1=0, sum2=0, min=INT_MAX;

    for (ll i=0 ; i<n-1 ; i++) {

        sum1=0;
        sum2=0;


        for (ll j=0 ; j<=i ; j++) {
            sum1 += a[j];
        }

        for (ll j=(i+1) ; j<n ; j++) {
            sum2 += a[j];
        }

        if (abs(sum1-sum2) < min) {
            min = abs(sum1- sum2);
        }
    }

    cout << min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this


const ll MAXN = 101;
ll val[MAXN],weight[MAXN];
ll n,W;
ll dp[MAXN][100001];

ll rec(ll idx,ll v){

    if(idx > n){
        if(v == 0) return 0;
        return 1e15;
    }
    ll &ans = dp[idx][v];

    if(ans != -1) return ans;

    ans = 1e15;
    ans = min(ans,rec(idx+1,v));
    if(v - val[idx] >= 0) ans = min(ans,rec(idx+1,v - val[idx]) + weight[idx]);

    return ans;
}

void solve(){
    cin>>n>>W;

    memset(dp,-1,sizeof(dp));
    FOR(i,1,n){
        cin>>weight[i]>>val[i];
    }

    ll ans = 0;
    for(ll j=1;j<=100000;j++){
        if(rec(1,j) <= W) ans = j;
    }

    cout<<ans<<endl;
}

signed main(){


    FastRead;    

    ll t;
    t = 1; 
    // cin>>t;
    while(t--) solve();
    
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
const int N=100*1000;
int a[100*1000+3];
int main(){
    int n;cin>>n;
    while(n--){
        int l,r;cin>>l>>r;
        a[l]+=1;
        a[r+1]-=1;
    }
    for(int i=1;i<=N;++i)a[i]+=a[i-1];
    int ans=0;
    for(int i=1;i<=N;++i)if(a[i])ans++;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 640
// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define INF 1e9+5
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
int n;
cin>>n;
vector<int>dp(3,0);
for(int day=0;day<n;day++){
    vector<int>new_dp(3,-1);
    vector<int>c(3);
    loop(i,0,3) cin>>c[i];
    loop(i,0,3){
        loop(j,0,3){
            if(i!=j){
                new_dp[j]=max(new_dp[j],dp[i]+c[j]);
            }
        }
    }
    dp=new_dp;
}
cout<<max({dp[0],dp[1],dp[2]});
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    var arr = input[1].split(" ").map(Number);
    var sum = 0;
    var min = Number.MAX_SAFE_INTEGER;
    for(var i=0;i<arr.length;i++){
        sum += arr[i];
    }
    var n = 0;
    var mp = 0
    for(i=0;i<arr.length;i++){
        n += arr[i];
        var m = sum-n;
        if(min>Math.abs(n-m)){
            min = Math.abs(n-m);
        }
    }
    console.log(min);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7372
import math

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

A, B = 1, 1

for t in TA:
    a = A // t[0]
    b = B // t[1]
    if A % t[0] != 0:
        a += 1
    if B % t[1] != 0:
        b += 1
    n = max(a, b)
    # n = max(math.ceil(A / t[0]), math.ceil(B / t[1]))
    A, B = t[0] * n, t[1] * n

print(A + B)


Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int primeNumber(const int n) {
	//上から確認する
	for (int N = n; N >= 1; N--) {

		bool isPrime = true;
		//素数判定 i < sqrt(N)+1
		for (int i = 2; i * i <= N; i++) {
			if (N % i == 0) {
				isPrime = false;
				break;
			}
		}
		//もし素数なら
		if (isPrime) {
			return N;
		}
	}
}

int main() {
	int i, j, k;
	int N,K;
	cin >> N>>K;

	vector<int> A(N);
	rep(i, 0, N)
		cin >> A[i];

	sort(A.begin(), A.end());
	int sum = 0;
	rep(i, 0, K) {
		sum += A[i];
	}
	cout << sum;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> s(N);
  int sum=0;
  for(int i=0;i<N;++i){
    cin>>s.at(i);
    sum += s.at(i);
  }

  sort(s.begin(),s.end());
  if(sum%10==0){
  int count=0;
  while(count<N &&s.at(count)%10==0){
    ++count;
  }
  if(count==N){
    sum=0;
  }
  else{
    sum -= s.at(count);
  }
}

  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n;
    cin >> n;
    int ans;
    for (int i = 1; i * i <= n; i++)
    {
        ans = i * i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

int n;
vector<vector<ll>> a;
// 男性 i まで見て、既に組まれてる女性の集合が j で表された上で、残りのすべての男性を調べたとき条件を満たすペアの数
vector<vector<ll>> dp(25, vector<ll>((1<<21), -1));

ll memo_rec(int male, int female){
    if(dp[male][female] != -1)  return dp[male][female];
    if(female == (1 << n) - 1)  return dp[male][female] = 1;
    if(male >= n)   return 0;

    ll res = 0;
    for(int i = 0; i < n; ++i){
        if(!a[male][i]) continue;
        if(female & (1 << i))   continue;
        res = (res + memo_rec(male+1, female | (1 << i))) % mod;
    }

    return dp[male][female] = res;
}

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

    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; ++i){
        a[i].resize(n);
        for(int j = 0; j < n; ++j){
            cin >> a[i][j];
        }
    }
    
    cout << memo_rec(0, 0) << endl;
}

Measured memory_bytes: 426368
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int gcd(int a, int b)
{
	if(a == 0)
		return b;

	return gcd(b % a, a);
}

int main(int argc, char const *argv[])
{
	//ifstream cin("input.txt");
	int k;
	cin>>k;
	ll sum =0;
	rep(i, 1,k)
		rep(j,1,k)
			rep(l, 1,k)
				sum += gcd(gcd(i,j), l);

	cout<<sum;
}

Measured memory_bytes: 3608
import Control.Monad
import Control.Applicative

main = do
  [a, b] <- map (\x -> read x :: Int) . words <$> getLine
  when (not(a == 0 && b == 0)) $ do 
    putStrLn $ if a < b 
      then unwords $ map show [a, b]
      else unwords $ map show [b, a]
    main

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

using namespace std;

bool isAllEven(vector<int> v){
    for(auto x: v){
        if(x%2 == 1){
            return false;
        }
    }
    return true;
}

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

    vector<int> n_array;
    for(int i = 0; i < N; ++i){
        int input_num;
        cin >> input_num;
        n_array.push_back(input_num);
    }

    int count = 0;
    while(true){
        if(isAllEven(n_array) == false){
            break;
        }
        count++;

        for(int i = 0; i < n_array.size(); ++i){
            n_array[i] /= 2;
        }
    }

    cout << count << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;  
#define PI 3.1415
int main(void)  
{  
   	int a,b,sum=0;
   	cin>>a>>b;
   	for(int i=1;i<=b;i++)
   	{
   		int g;
   		cin>>g;
   		sum+=g;
	   }
	   cout<<(a-sum<0?-1:a-sum);
    return 0;     
}  

Measured memory_bytes: 3596
s = list(input())
a, b, c, d = map(int, s)
op = ['+', '+', '+']

sums = a + b + c + d

for i in range(2):
    for j in range(2):
        for k in range(2):
            if sums - (2 *b * i + 2* c * j + 2* d * k) == 7:
                if i == 1:
                    op[0] = '-'
                if j == 1:
                    op[1] = '-'
                if k == 1:
                    op[2] = '-'
                print('{}{}{}{}{}{}{}=7'.format(a, op[0], b, op[1], c, op[2], d))
                exit()



Measured memory_bytes: 3064
def number(m,l):
  count=0
  mini=l[0]
  for i in range(m):
    if l[i]<=mini:
      mini=l[i]
      #miniはi-1番目のうち最も小さい値であるから、これより小さかったら、i-1番目のどれよりも小さい
      count+=1
  return count

n=int(input())
p=list(map(int,input().split()))
result=number(n,p)
print(result)

Measured memory_bytes: 76752
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int rec(int a, int b, int n)
{
	if(n == 0) return 0;
	else return a / b + rec((a - b * int(a / b)) * 10, b, n - 1);
}



int main()
{
	double a, b, n;
	while(cin >> a >> b >> n)
	{
		cout << rec((a - b * int(a / b)) * 10, b, n) << endl;
	}
}

Measured memory_bytes: 0
//
// Created by Hideaki Imamura on 2020-04-04.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

vector<ll > divisor(ll n) {
    vector<ll> ret;
    for(int64_t i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

ll N;

int main() {
    cin >> N;

    vector<ll> div_n = divisor(N);
    vector<ll> div_n_1 = divisor(N - 1);

    ll ans = div_n_1.size() - 1;
    for (auto x : div_n) {
        if (x == 1) continue;
        ll tmp = N;
        while (tmp % x == 0 && tmp > 0) tmp /= x;
        if (tmp % x == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int i;
	double sum = 0;
	double a[10];
	while(scanf("%lf",&a[0]) != EOF){
		sum += a[0];
		for(i = 1;i < 10;i++){
			if(i % 2 == 1){
				a[i] = a[i-1] * 2;
				sum += a[i];
			}
			else{
				a[i] = a[i-1] / 3;
				sum += a[i];
			}
		}
		printf("%.8f\n",sum);
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, ans = 0, x = 0; cin >> N;
    string S; cin >> S;
    for (auto c : S) {
        if ('I' == c) x += 1;
        if ('D' == c) x -= 1;
        ans = max(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

if a<=0 and 0 <=b:
    print(max(a*d, a*c, b*c, b*d, 0))
elif c<=0 and 0 <=d:
    print(max(a*d, a*c, b*c, b*d, 0))
else:
    print(max(a*d, a*c, b*c, b*d))

Measured memory_bytes: 61648
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int64_t> as(n);
    for (auto& a : as)
    {
        cin >> a;
    }

    map<int64_t, int64_t> freq;

    int64_t ans = 0;

    for (int64_t i = 0; i < n; i++)
    {
        const auto key = i - as[i];
        ans += freq[key];
        freq[i + as[i]] += 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 27156
#include <bits/stdc++.h>
#define rep(i,n1) for(int i=0;i<n1;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
#define PI 3.141592653589793
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const ll inf=1000000007;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vector<Pii> v[100001];
int dp[100000][3]={};
ll dp2[300000][60]={};
int main() {
	int n,m;
	cin>>n>>m;
	int k[n]={};
	int k2[n]={};
	rep(i,m){
		int p;
		string s;
		cin>>p>>s;
		if(s=="AC"){
			k[p-1]++;
		}else{
			if(k[p-1]==0)k2[p-1]++;
		}
	}
	int r1=0;
	int r2=0;
	rep(i,n){
		if(k[i]>0){
			r1++;
			r2+=k2[i];
		}
	}
	cout<<r1<<" "<<r2<<endl;
	return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
main(){
  l q;cin>>q;
  for(l i=0;i<q;i++){
    l x,y;
    cin>>x>>y;
    if(x>y)swap(x,y);
    long double k=sqrt(x*y-0.75)-x+0.5;
    cout<<(l)(x-1+k+(x*y-1)/(x+k))-(x!=y)<<endl;
  }
}


Measured memory_bytes: 3572
from fractions import gcd
def lcm(a,b):
    return(a*b//gcd(a,b))

N,M=map(int,input().split())
S,T=input(),input()

_lcm=lcm(N,M)
n=_lcm//N
m=_lcm//M
for i in range(0,_lcm,n*m):
    if S[i//n]!=T[i//m]:
        print(-1)
        exit()    
print(_lcm)


Measured memory_bytes: 65388
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define MOD 998244353
#define MAX 100005
#define loop(i,a,b) for(long long int i=a;i<b;i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
typedef long long int ll;

using namespace std;
//using namespace boost::multiprecision;

ll prime[MAX];
void sieve()
{
	prime[1] = 1;
	for(ll i=2;i<MAX;i++)
	if(prime[i]==0)
	for(ll j=i;j<MAX;j+=i)
	prime[j]=i;
}
vector<ll> v;
void dfs(ll n, ll m, ll stepNum) 
{ 
    // If Stepping Number is in the 
    // range [n,m] then display 
    if (stepNum <= m && stepNum >= n) 
        v.pb(stepNum); 
  
    // If Stepping Number is 0 or greater 
    // than m, then return 
    if (stepNum == 0 || stepNum > m) 
        return ; 
  
    // Get the last digit of the currently 
    // visited Stepping Number 
    ll lastDigit = stepNum % 10; 
  
    // There can be 2 cases either digit 
    // to be appended is lastDigit + 1 or 
    // lastDigit - 1 
    ll stepNumA = stepNum*10 + (lastDigit-1); 
    ll stepNumB = stepNum*10 + (lastDigit+1); 
    ll stepNumC = stepNum*10 + (lastDigit);
  
    // If lastDigit is 0 then only possible 
    // digit after 0 can be 1 for a Stepping 
    // Number 
    if (lastDigit == 0) 
        {
		dfs(n, m, stepNumB); 
		dfs(n,m,stepNumC);}
  
    // If lastDigit is 9 then only possible 
    // digit after 9 can be 8 for a Stepping 
    // Number 
    else if(lastDigit == 9) 
        {
		dfs(n, m, stepNumA); 
		dfs(n,m,stepNumC);
	}
    else
    { 
        dfs(n, m, stepNumA); 
        dfs(n, m, stepNumB); 
        dfs(n,m,stepNumC);
    } 
} 
  
// Method displays all the stepping 
// numbers in range [n, m] 
void displaySteppingNumbers(ll n, ll m) 
{ 
    // For every single digit Number 'i' 
    // find all the Stepping Numbers 
    // starting with i 
    for (ll i = 0 ; i <= 9 ; i++) 
        dfs(n, m, i); 
}

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

//sieve();


ll t=1;
//cin>>t;

loop(k,0,t)
{
	ll n;
	cin>>n;
	displaySteppingNumbers(0,3234566667);
	sort(v.begin(),v.end());
	cout<<v[n]<<"\n";
}



return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
//#include <unordered_set>
#define mkp make_pair
#define err cout<<"here"<<endl
using namespace std;
const double EPS=1e-12;
typedef long long lon;
typedef unsigned long long ull;
typedef set<int>::iterator IT;
const lon SZ=100010,SSZ=30,APB=52,mod=97,one=1;
const lon INF=0x7FFFFFFF;
int n,m,arr[SZ];
struct nd{
	int to,wt;
	nd(int a=0,int b=0):to(a),wt(b){}
};
vector<nd> mp[SZ];

void dfs(int x,int p,int c)
{
	arr[x]=c&1;
	for(int i=0;i<mp[x].size();++i)
	{
		int t=mp[x][i].to;
		int w=mp[x][i].wt;
		if(t!=p)
		{
			dfs(t,x,c+w);
		}
	}
}

void init()
{
	cin>>n;
	for(int i=1;i<=n-1;++i)
	{
		int a,b,c;
		cin>>a>>b>>c;
		mp[a].push_back(nd(b,c));
		mp[b].push_back(nd(a,c));
	}
	dfs(1,-1,0);
	for(int i=1;i<=n;++i)
	{
		cout<<arr[i]<<endl;
	}
}


void work()
{
	
}

void release()
{
	
}

int main()
{
	std::ios::sync_with_stdio(0);
	//freopen("d:\\1.txt","r",stdin);
	int casenum;
	//cin>>casenum;
	//cout<<casenum<<endl;
	//for(int time=1;time<=casenum;++time)
	//for(int time=1;cin>>n>>m;++time)
	{
		//cout<<"Case #"<<time<<": ";
		init();
		work();
		release();
	}
	return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//↑templete
signed main(){

    int A, B, C, D;
    cin>>A>>B>>C>>D;
    while(1){
        C-=B;
        if(C<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        A-=D;
        if(A<=0){
            cout<<"No"<<endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <algorithm>
using namespace std;

long long a[3];
int b[3];
long long s;
int ans;

int main(){
	scanf("%lld %lld %lld", &a[0], &a[1], &a[2]);
	s = a[0] + a[1] + a[2];
	for(int i=0; i<3; ++i){
		int c = 0;
		for(int j=0; j<30; ++j){
			if(a[i] % 2 == 1) break;
			a[i] = (s - a[i]) / 2;
			++c;
		}
		b[i] = c;
	}
	ans = min(b[0], min(b[1], b[2]));
	if(ans == 30) printf("%d\n", -1);
	else printf("%d\n", ans);
}

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

int orde(const void* a, const void* b){

    //const char *x = a, *y = b;
    return strcmp(a,b);

    /*if (x[0] < y[0])
        return -1;
    if (x[0] > y[0])
        return 1;

    return 0;
*/
}

int main(){

int n, l;
scanf("%d %d", &n, &l );
char s[n][l+1];
for (int i = 0; i < n; i++)
    scanf(" %s", s[i]);

qsort(s,n,sizeof(s[0]), orde);

for (int i = 0; i < n; i++)
    printf("%s", s[i]);

printf("\n");

return 0;
}


Measured memory_bytes: 128
import java.util.HashSet;
import java.util.Scanner;

public class Main {

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

	public static void main(String[] args) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		for (int i = 0; i < K; ++i) {
			set.add(sc.nextInt());
		}
		for (int i = N;; ++i) {
			boolean ok = true;
			int p = i;
			while (p > 0) {
				if (set.contains(p % 10)) {
					ok = false;
					break;
				}
				p /= 10;
			}
			if (ok) {
				System.out.println(i);
				return;
			}
		}
	}

}


Measured memory_bytes: 9936
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
const ll INF = 1LL << 60;

int main(void){
    int n;
    cin >> n;
    vector<int> h(n);
    REP(i,n) cin >> h[i];
    vector<ll> dp(n);
    REP(i,n) dp[i]=INF;
    dp[0]=0;
    FOR(i,1,n){
        chmin(dp[i],dp[i-1]+abs(h[i-1]-h[i]));
        if(i>1)
            chmin(dp[i],dp[i-2]+abs(h[i-2]-h[i]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4556
import sys

h, w = (int(i) for i in input().split())  

ans = min(h,w)

if h%3==0 or w%3==0:
	print(0)
	sys.exit()

for i in range(1,h+1):
	ans = min(ans, max(w*i, (h-i)*(w//2), (h-i)*(w-w//2)) - min(w*i, (h-i)*(w//2), (h-i)*(w-w//2)))
for i in range(1, w+1):
	ans = min(ans, max(h*i, (w-i)*(h//2), (w-i)*(h-h//2)) - min(h*i, (w-i)*(h//2), (w-i)*(h-h//2)))

print(ans)

Measured memory_bytes: 3064
#include<set>   
#include<map>   
#include<stack>   
#include<cmath>   
#include<cstdio>   
#include<queue>   
#include<vector>   
#include<climits>   
#include<cstring> 
#include<iostream> 
#include<algorithm> 
#define LL long long 
using namespace std;      
int read(){      
    int f=1,x=0;char c=getchar();         
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}        
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();      
    return x*f;     
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int a[MAXN+5];
int main(){
	int n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	int d=a[1];
	for(int i=2;i<=n;i++)
		d=gcd(d,a[i]);
	printf("%d\n",d);
    return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys

H, W = map(int, raw_input().split())

S = []
for i in range(0, H):
	S.append(raw_input())

ans = [["" for i in range(W)] for j in range(H)]

for i in range(0, H):
	for j in range(0, W):
		if S[i][j] == "#":
			ans[i][j] = "#"
		else:
			count = 0

			# i-1
			if i-1 >= 0:
				if j-1 >= 0:
					if S[i-1][j-1] == "#":
						count+=1
				if S[i-1][j] == "#":
					count+=1
				if j+1 < W:
					if S[i-1][j+1] == "#":
						count+=1
			# i
			if j-1 >= 0:
				if S[i][j-1] == "#":
					count+=1
			if j+1 < W:
				if S[i][j+1] == "#":
					count+=1
			# i+1
			if i+1 < H:
				if j-1 >= 0:
					if S[i+1][j-1] == "#":
						count+=1
				if S[i+1][j] == "#":
					count+=1
				if j+1 < W:
					if S[i+1][j+1] == "#":
						count+=1

			ans[i][j] = str(count)

for i in range(0, H):
	for j in range(0, W):
		sys.stdout.write(ans[i][j])
	print


Measured memory_bytes: 2696
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    auto a = readln.split.to!(int[]);
    auto ans = a.reduce!max - a.reduce!min;
    writeln(ans);
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
def isPrime(x):
	for i in range(2,min(x,236)):
		if x%i == 0:
			return False
	return True
n,a,t = int(input())-1,[],6
a.append(str(2))
while n > 0:
	if isPrime(t):
		a.append(str(t))
		n -= 1
	t += 5
print(" ".join(a))


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

using namespace std;

int main(){
	int a, b, c;
	int d = 0;
	int ans = 0;
	cin >> a >> b >> c;
	for (int i = 1;;i++){
		d += a;
		if (i % 7 == 0){
			d += b;
		}
		if (d >= c){
			ans += i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    int n, m, result = 1;
    cin >> n >> m;
    bool color[n + 1] = {};
    int count[n + 1];
    fill(count, count + n + 1, 1);
    color[1] = 1;
    for (int x, y; cin >> x >> y; ) {
        count[y]++;
        count[x]--;
        if (color[x] == 1) {
            if (color[y] == 0) {
                result++;
                color[y] = 1;
            }
            if (count[x] == 0) {
                result--;
                color[x] = 0;
            }
        }
    }
    cout << result;
    return 0;
}

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

using namespace std;

#define ll long long
#define ar array

int32_t R,C,K;
ll DP[3001][3001][3];
int32_t Arr[3001][3001];



void solve(){
    cin >> R >> C >> K;

    for (int i = 0; i < 3001; i++)
    {
        for (int j = 0; j < 3001; j++)
        {
         Arr[i][j] = 0;
         for (int h = 0; h < 3; h++)
         {
             DP[i][j][h] = 0;
         }
         
        }
    }
    
    int32_t r, c, v;
    for (int i = 0; i < K; i++)
    {
        cin >> r  >> c >> v ;

        Arr[r][c] = v;
    }
    
    
    for (int i = 1; i < R+1; i++)
    {
        for (int j = 1; j < C+1; j++)
        {
            DP[i][j][0] = max(DP[i-1][j][0], max( DP[i-1][j][1] , DP[i-1][j][2])) + Arr[i][j];

            DP[i][j][0] = max(DP[i][j][0], DP[i][j-1][0]);
            DP[i][j][1] = max(DP[i][j-1][1], DP[i][j-1][0] + Arr[i][j]);
            DP[i][j][2] = max(DP[i][j-1][2], DP[i][j-1][1] + Arr[i][j]);
        }
        
    }
    
    ll out = max(DP[R][C][0] , max(DP[R][C][1], DP[R][C][2]));
    cout << out << endl;
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 249884
#include <iostream>
#include <string>
#include<algorithm>
#include<vector>
using namespace std;
 
int main() {
	int n, a;
	cin >> n >> a;
 
	if(n>=13){
		cout << a << endl;
	}
	else if (n>=6) {
		a = a / 2;
		cout << a << endl;
	}
	else cout << 0 << endl;
}

Measured memory_bytes: 256