akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){
 
   double n;
   cin>>n;

    cout<<(n-2)*180.0<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> a = new TreeSet<Integer>();
        for (int i = 0 ; i < n ; i++) {
            int m = sc.nextInt();
            if (a.contains(m)) {
                a.remove(m);
            } else {
                a.add(m);
            }
        }
        System.out.println(a.size());
    }

}

Measured memory_bytes: 62552
#include <iostream>
#include <string>

using namespace std;

int main(){

  string s;
  int appear_cnt[26][3]={0};
  int temp_half;
  int over_half;

  int char_num = 0;
  const int char_base = 'a';

  int a = 0, b = 0;

  cin >> s;

  int s_len=s.size();
  over_half = s_len / 2 + 1;

  for (int i = 0; i < s_len; i++)
  {
    char_num = (char)s[i] - char_base;
    
    if (appear_cnt[char_num][0]==0)
    {
      appear_cnt[char_num][1] = i;
      appear_cnt[char_num][2] = -3;
    }
    appear_cnt[char_num][0]++;
    temp_half = (i - appear_cnt[char_num][1]) / 2 + 1;

    if (appear_cnt[char_num][0]>temp_half && temp_half!=1)
    {
      a = appear_cnt[char_num][1] + 1;
      b = i + 1;
      appear_cnt[char_num][2] = i;      
      break;
    } else if (i-appear_cnt[char_num][2]<=2) {
      a = i - 1;
      b = i + 1;
      appear_cnt[char_num][2] = i;      
      break;
    }
    else
    {
      appear_cnt[char_num][2] = i;
    }
  }

  if (a==0 && b!=0)
  {
    a = 1;
    b = s_len;
  }

  if (a==0 || b==0)
  {
    cout << -1 << " " << " " << -1 << endl;
  } else 
  {
    //cout << s.substr(a, b-a+1) << endl;
    cout << a << " " << " " << b << endl;
  }

  return 0;
}

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

using namespace std;

#define DB( x ) cout << #x << " = " << x << endl;
#define LEFT(n) (2 * (n))
#define RIGHT(n) (2 * (n) + 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> node;
//typedef vector <vector <ll>> matrix;

const ll INF = 1e18;
const double EPS = 1e-9;
const ll MOD = (ll)(1e9 + 7);
const ll MAXV = (ll)(3e5 + 10);
const ll MAXE = (ll)(1e6 + 10);

ll A[MAXV], B[MAXV];
ll n, k;

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

	cin >> n >> k;

	for(ll i = 0;i < n;i ++)
		cin >> A[i];
	ll ans = 0LL;

	for(ll i = 0;i < n;i ++){
		for(ll j = 0;j < n;j ++){
			if(A[i] > A[j])
				B[i] ++;
			if(j > i && A[i] > A[j])
				ans = (ans + 1) % MOD;
		}

	}

	ans = ans % MOD;
	ans = (ans * k) % MOD;

	ll K = ((k * (k - 1LL)) / 2LL) % MOD;

	if(k > 1)
		for(ll i = 0;i < n;i ++){
			ans = (ans + (B[i] * K) % MOD) % MOD;
		}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 2304
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by zhangrunfeng on 2/18/20
 */
public class Main {
    private int N;

    private int[] arr;
    private int[] T;
    private boolean[] v;

    private int minVal;

    public Main(Scanner sc) {
        N = sc.nextInt();
        arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
        int[] sortedArr = arr.clone();
        Arrays.sort(sortedArr);

        int VMAX = 10000 + 5;
        T = new int[VMAX];
        for (int i = 0; i < N; i++) {
            T[sortedArr[i]] = i;
        }
        minVal = sortedArr[0];

        v = new boolean[N]; // 不用初始化
        Arrays.fill(v, false);
    }

    public int minCost() {
        int sum = 0;
        for (int i = 0; i < N; i++) {
            if (v[i]) continue;

            int an = 0;
            int currSum = 0;
            int currMin = Integer.MAX_VALUE;
            int currIx = i;
            while (!v[currIx]) {
                v[currIx] = true;
                currSum += arr[currIx];
                if (arr[currIx] < currMin) {
                    currMin = arr[currIx];
                }
                an++;
                currIx = T[arr[currIx]];
            }
            if (an >= 2) {
                sum += (currSum + Math.min((an - 2) * currMin, (an + 1) * minVal + currMin));
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        int res = m.minCost();
        System.out.println(res);
    }
}


Measured memory_bytes: 30892
H,W=map(int,input().split())
l=[]
l2=[]

for i in range(H):
    a=list(input())
    if a.count("#")!=0:
        l.append(a)

l1=list(zip(*l))
i=0
while i < len(l1):
    if l1[i].count("#")!=0:
        l2.append(l1[i])
    i+=1
l3=list(zip(*l2))
for i in range(len(l3)):
    print("".join(l3[i]))        


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int main() {
  int k,n;
  cin >> k >> n;
  vector<int>a(n); 
  rep(i,n) cin >> a[i];
  a.push_back(a[0]+k);
  int l=0;
  rep(i,n) {
    l=max(l,a[i+1]-a[i]);
  }
  int ans=k-l;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict
dic1=defaultdict(int)
dic2=defaultdict(int)
n=int(input())
l=list(map(int,input().split()))
for i in range(0,n-1,2):
  dic1[l[i]]+=1
for i in range(1,n,2):
  dic2[l[i]]+=1
max11=0
i1=0
max12=0
i2=0
max21=0
i3=0
max22=0
i4=0
for i in dic1:
  if dic1[i]>=max11:
    max12=max11
    max11=dic1[i]
    i2=i1
    i1=i
  elif dic1[i]>max12:
    max12=dic1[i]
    i2=i
for i in dic2:
  if dic2[i]>=max21:
    max22=max21
    max21=dic2[i]
    i4=i3
    i3=i
  elif dic2[i]>max22:
    max22=dic2[i]
    i4=i
if i1!=i3:
  print(n-max11-max21)
elif i1==i3:
  print(min(n-max11-max22,n-max21-max12))

Measured memory_bytes: 18400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
 
/**
 * 0007:Debt Hell????§£???
 * 
 * @author MS14A
 * @version 2015/04/15
 */
public class Main {
 
    /** ??????????????????10?????? */
    private static final BigDecimal INITIAL_DEBT = BigDecimal.valueOf(100000L);
 
    /** ?????????5% */
    private static final BigDecimal INTEREST_RATE = new BigDecimal("0.05");
 
    /** \1000???????????°??????????¨??????¨ */
    private static final BigDecimal DIVISOR_FOR_ROUND_UP = BigDecimal.valueOf(1000L);
 
    /**
     * n ??±??????????????????????????????????????????<br>
     * ???n ??? 100 ??\?????¨?????????
     * 
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // ?¨??????\???????????????
        int weeks = getWeeks();
 
        // n??±???????????????????¨????????????¨??????
        System.out.println(calcDebt(weeks));
    }
 
    /**
     * ?¨??????\?????????????????????"n"??????????????????
     * 
     * @return n?????\??????
     * @throws IOException
     *             ?¨??????\??????????????±??????
     */
    private static int getWeeks() throws IOException {
 
        InputStreamReader streamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(streamReader);
 
        int weeks = Integer.parseInt(bufferedReader.readLine());
         
        bufferedReader.close();
        streamReader.close();
         
        return weeks;
    }
 
    /**
     * n??±??????????????????????¨?????????????
     * 
     * @param weeks
     * @return n??±??????????????????
     */
    private static BigDecimal calcDebt(int weeks) {
        BigDecimal finalDebt = INITIAL_DEBT;
 
        for (int i = 0; i < weeks; i++) {
            // ??????????¨???????1000??§?????£????°???°??¨?????°???????????????
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                    .divide(DIVISOR_FOR_ROUND_UP, 0, BigDecimal.ROUND_UP);
 
            // ????????? = ?????±???????????? + ?????????
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR_FOR_ROUND_UP));
        }
 
        return finalDebt;
    }
 
}

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

int main() {
  int N, K,i = 0,a = 1;
  cin >> N >> K;
  while (a < K) {
    a *= 2;
    i++;
    if (i == N) {break;}
  }
  a += K * (N - i);
  cout << a << endl;
}

Measured memory_bytes: 384
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<vector>
#include<cmath>
#include<set>
using namespace std;
int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d, 0));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < d; ++j) {
			cin >> x[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < n - 1; ++i) {
		for(int j = i + 1; j < n; ++j) {
			long long int sum = 0;
			for(int k = 0; k < d; ++k) {
				sum += pow(x[i][k] - x[j][k], 2);
			}
			for(int k = 0; k <= 3300000; ++k) {
				if(k * k == sum)
					++ans;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
    int sum,m,r,f;
    
    while(1){
        cin >> m >> r >> f;
        if(m == -1 && r == -1 && f == -1)break;
        sum = 0;
        sum = m+r;
        if(sum>=80)cout << "A" << endl;
        else if(65 <= sum && sum < 80)cout << "B" << endl;
        else if(50 <= sum && sum < 65)cout << "C" << endl;
        else if(30 <= sum && sum < 50 && f >= 50)cout << "C" << endl;
        else if(m == -1 || r == -1)cout << "F" << endl;
        else if(30 <= sum && sum < 50)cout << "D" << endl;
        else if(sum < 30)cout << "F" << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#!/usr/bin/env python3
import itertools

# input
n, m, x = map(int, input().split())
c = [-1 for _ in range(n)]
a = [[-1 for _ in range(m)] for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    c[i] = tmp[0]
    a[i] = tmp[1:]

# calc
# k冊買うとして全探索
ans = []
for k in range(n+1):
    seq = list(itertools.combinations(list(range(n)), k)) 
    for l in seq:
        rikaido = [0 for _ in range(m)]
        cost = 0 
        for i in l:
            cost += c[i]
        for p in range(m):
            for q in l:
                rikaido[p] += a[q][p]
        #print('rikaido = ', rikaido)
        ok = True
        for p in range(m):
            if rikaido[p] < x:
                ok = False
                break
        if ok: 
            ans.append(cost)

if len(ans) > 0:
    print(min(ans))
else:
    print(-1)


Measured memory_bytes: 9296
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= putStrLn . which "Yes" "No" . ( "AC" `isInfixOf` )


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define ss cout << " ";
#define nn cout << "\n";
#define ct(x) cout << x;
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
const int maxn = 200200;
 
void solve(){

    return;
}
 
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s, t;
    cin >> s >> t;
    int sol = t.size();
    for(int i = 0; i <= s.size() - t.size(); i++) {
        int nr = 0;
        for(int j = 0; j < t.size(); j++) {
            if(t[j] != s[i + j]) {
                nr++;
            }
        }
        sol = min(sol, nr);
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n, m;
    std::cin>>n>>m;
    std::vector<int> a(m), b(m);
    for(int i = 0;i < m;i++){
        std::cin>>a[i]>>b[i];
    }

    std::vector<int> ans(n);
    for(int i = 0;i < n;i++){
        ans[i] = std::count(a.begin(), a.end(), i + 1) +
            std::count(b.begin(), b.end(), i + 1);
    }
    for(auto x : ans){
        std::cout<<x<<std::endl;
    }
    return 0;
}

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

int main() {
  int x, y;
  
  cin >> x >> y;
  
  bool flag = false;
  for(int i = 0; i <= x; ++i) {
    int number_of_leg = 2 * i + 4 * (x - i);
    if(y == number_of_leg) {
      flag = true;
      break;
    }
  }
  
  if(flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <algorithm>

#define lli long long int

using namespace std;

int main() {
	lli n, a[100010], b, sisa, defeat, ans = 0;
	scanf("%lld", &n);
	for (lli i = 0; i <= n; i++)
		scanf("%lld", &a[i]);
	sisa = a[0];
	for (lli i = 1; i <= n; i++) {
		scanf("%lld", &b);
		defeat = min(sisa, b);
		ans += defeat;
		b -= defeat;
		sisa = a[i];
		defeat = min(sisa, b);
		ans += defeat;
		sisa -= defeat;
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

int main() {

	long n;
	cin >> n;

	string s;
	cin >> s;

	long counter = 0;
	for (long i = 0; i <= s.size()-3; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			counter++;
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.util.Scanner;

public class Main{
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;
		//PrintStream out = new PrintStream("src/output.txt");

		//System.setOut(out);

		sc = new Scanner(in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(b - a == c - b){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

		//out.close();
	}
}

Measured memory_bytes: 23124
fun main(args: Array<String>) {
        val sc = if (args.size > 1) java.util.Scanner(java.io.File(args[1])) else java.util.Scanner(System.`in`)
        solve(sc)
    }

    fun solve(sc: java.util.Scanner) {
        val A = sc.nextInt()
        val B = sc.nextInt()
        val result = (A..B).count {
            it == it.toString().reversed().toInt()
        }
        println(result)
    }


Measured memory_bytes: 41848
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define timepass 1073741824
#define MAXN 200000 + 5
#define LOGN 20
#define over ((1ll << 32))
using namespace std;
#define N 2005
 
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int ll 
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define rrep(i , n , a) for (int i = n - 1 ; i >= a ; i--)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define sp(a , x) cout << fixed << setprecision(a) << x << endl; 
#define siz(temp) (ll)temp.size()
#define len(temp) (ll)temp.length()
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define pi acos(-1)
#define con continue
#define endl "\n"
#define w(q) while(q--)
 
//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl
 
typedef pair<int , int> pii;
typedef pair<int , pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<piii> vpiii;


signed main()
{
    int n;
    cin >> n;
    vector<pair<int , int > > arr(n);
    rep(i , 0 , n)
    {
        cin >> arr[i].ff;
        arr[i].ss = i + 1;
    }
    s(arr);
    for (int i = 0 ; i < n ; i++)
        cout << arr[i].ss << " \n"[i == n - 1];
    return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    string s;
    cin >> s;

    vector<int> former(26);
    vector<int> latter(26);

    int ans=0, anstmp = 0;
    for(int i=1;i<n;i++) {
        for(int j=0;j<n;j++) {
            if(j<i) former.at(s.at(j)-'a')++;
            else latter.at(s.at(j)-'a')++;
            //if(s.at(i)=='a') cout << s.at(i)-'a' <<endl;     
        }
        for(int k=0;k<26;k++) {
            if(former.at(k)&&latter.at(k)) anstmp++;
        }

        ans = max(ans, anstmp);

        for(int l=0;l<26;l++) {
            former.at(l) = 0;
            latter.at(l) = 0;
        }
        anstmp = 0;
    }

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


Measured memory_bytes: 256
from collections import deque

N,M=map(int,input().split())
a=[[[] for j in range(N)] for i in range(3)] # 0-indexのグラフが3つある
for i in range(M):
    u,v=map(lambda x:int(x)-1,input().split())
    a[0][u].append((1,v))
    a[1][u].append((2,v))
    a[2][u].append((0,v))
S,T=map(lambda x:int(x)-1,input().split())
# print(a)

r=[[-3 for j in range(N)] for i in range(3)]
q=deque()
q.append((0,S));r[0][S]=0
while q:
    ui,uj=q.popleft()
    for vi,vj in a[ui][uj]:
        if r[vi][vj]==-3:
            r[vi][vj]=r[ui][uj]+1
            q.append((vi,vj))
# print(r)
print(r[0][T]//3)

Measured memory_bytes: 105912
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x, y;
  cin >> n >> x >> y;
  VI ans(n, 0);
  REP2(int, i, 1, n) REP2(int, j, i+1, n+1) ++ans[min(abs(j-i), abs(x-i)+1+abs(y-j))];
  REP2(int, k, 1, n) cout << ans[k] << endl;

  return 0;
}


Measured memory_bytes: 3680
n = int(input())
C, S, F = [], [], []
for i in range(n - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(n):
    t = 0
    for j in range(i, n - 1):
        if t <= S[j]:
            t = S[j]
        elif (t - S[j]) % F[j] == 0:
             pass
        else:
            t += F[j] - (t - S[j]) % F[j]
        t += C[j]
    print(t)

Measured memory_bytes: 3064
k = int(input())

dp = [[0]*10 for _ in range(10)]
d = [-1,0,1]
for i in range(10):
    for j in range(10):
        if i == 0:
            dp[i][j] = 1
        else:
            for dj in d:
                pj = j + dj
                if 0<=pj<10:
                    dp[i][j] += dp[i-1][pj]
cnt = 0
for n in range(10):
    s = sum(dp[n][1:])
    if cnt + s < k:
        cnt += s
    else:
        break
ans = ''
for j in range(1,10):
    if cnt + dp[n][j] < k:
        cnt += dp[n][j]
    else:
        ans += str(j)
        break

for i in range(n)[::-1]:
    for dj in d:
        nj = j + dj
        if 0<=nj<10:
            if cnt + dp[i][nj] < k:
                cnt += dp[i][nj]
            else:
                j = nj
                ans += str(nj)
                break
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue> 
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 200001;
int n, m, h[N]; 
vector<int> g[N];
priority_queue<int> q[N];

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i<=n; ++i)scanf("%d", h+i);
    for(int i = 0; i<m; ++i){
      int u, v;
      scanf("%d%d", &u, &v);
      q[u].push(h[v]);
      q[v].push(h[u]);
    }
    int an = 0;
    for(int i = 1; i<=n; ++i){
       if(q[i].size() >= 1 && q[i].top() < h[i])++an;
       if(!q[i].size())++an;
    }
    printf("%d\n", an);
}

Measured memory_bytes: 17360
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper

n = inp()
print(n//3)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


class QF{
public:
  int V;
  vector<int> par;
  vector<vector<int> > grp;
  QF(){}
  QF(int V):V(V),par(V),grp(V){
    iota(par.begin(), par.end(), 0);
    for(int i=0;i<V;i++) grp[i].push_back(i);
  }
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }

  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(grp[x].size() < grp[y].size()) swap(x, y);
    par[y] = x;
    for(int a:grp[y]) grp[x].push_back(a);
    grp[y].clear();
  }
  bool same(int x,int y){return find(x)==find(y);}
  int size(int x){return grp[find(x)].size();}
};


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, q;
  cin>>n>>q;

  QF A(n);
  while(q--){
    int com, x, y;
    cin>>com>>x>>y;
    if(com == 0) A.unite(x, y);
    else cout<<A.same(x, y)<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3760
n, k = map(int, raw_input().strip().split())

if k == 0:
    sz = 1 << n
    sz -= 1
    out = [' '.join([str(i), str(i)]) for i in xrange(sz + 1)]
    print ' '.join(out)
    exit()

m = 1 << n
if k >= m:
    print -1
    exit()

if n < 2:
    print -1
    exit()

l = []
for i in xrange(m):
    if i == k: continue
    l.append(i)

l.append(k)
for i in xrange(m - 1, -1, -1):
    if i == k: continue
    l.append(i)
l.append(k)

print ' '.join(map(str, l))

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

int main() {
int H,N;
cin >> H >> N;
vector<int> A(N);
for (int i = 0; i<N ; i++){
    cin >> A.at(i);
}

int damage = 0;
for (int i = 0; i<N ; i++){
    damage += A.at(i);
}

if (damage < H)
    cout << "No" << endl;
else
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  ll N;

  cin >> N;

  double inv = 0;
  for (int i = 0; i < N; i++) {
    double tmp;
    cin >> tmp;
    inv += 1 / tmp;
  }

  printf("%.10e", 1/inv);

  return 0;
}


Measured memory_bytes: 256
n = input()
tmp_n = n.split(" ")

W = tmp_n[0]
a = tmp_n[1]
b = tmp_n[2]

aW = int(W)+int(a)
bW = int(W)+int(b)

if a<b:
    if int(b)-aW<0:
        print("0")
    else:
        print(int(b)-aW)  
else:
    if int(a)-bW<0:
        print("0")
    else:
        print(int(a)-bW)


Measured memory_bytes: 3060
fun main(args: Array<String>){
    val aspects : List<Int>? = readLine()?.split(" ")?.map { Integer.parseInt(it)}
    if ( aspects != null && aspects.isNotEmpty() ) {
        println("${calcArea(aspects[0], aspects[1])} ${calcPerimeter(aspects[0], aspects[1])}")
    }
}

fun calcArea(height: Int, width: Int) : Int = height * width

fun calcPerimeter(height: Int, width: Int) : Int = height * 2 + width * 2


Measured memory_bytes: 31772
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <map>
#include <stdio.h>
#include <vector>
#define INFTY = 2000000000;
using namespace std;
typedef long long int ll;
 vector<ll> L(250002), R(250002);
 ll cut;
void merge(ll A[], ll left, ll mid, ll right) {
	ll n1 = mid - left, n2 = right - mid;
	for (int i = 0; i < n1; i++) {
		L.at(i) = A[left + i];
	}
	for (int i = 0; i < n2; i++) {
		R.at(i) = A[mid + i];
	}
	L[n1] = R[n2] = 2000000000;
	ll i = 0, j = 0;
	for (ll k = left; k < right; k++) {
		cut++;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
	}
}
void MergeSort(ll A[], ll N, ll left, ll right) {
	if (left + 1 < right) {
		ll mid = (left + right) / 2;
		MergeSort(A, N, left, mid);
		MergeSort(A, N, mid, right);
		merge(A, left, mid, right);
	}
}

int main() {
	ll N; cin >> N;
	cut = 0;
	ll A[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	MergeSort(A, N, 0, N);
	for (int i = 0; i < N; i++) {
		cout << A[i];
		if (i != N - 1) cout << ' ';
	}
	cout << endl << cut << endl;

}


Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
int ans=0;
void kaage(int N,string S){
  bool A=false,B=false,C=false;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='3')A=true;
    if(S.at(i)=='5')B=true;
    if(S.at(i)=='7')C=true;
  }
  long long a=atoll(S.c_str());
  if(A&&B&&C&&N>=a)ans++;
  if(S.size()==10)return;
  kaage(N,S+"3");
  kaage(N,S+"5");
  kaage(N,S+"7");
}
int main(){
  int N;cin>>N;string S="";
  kaage(N,S);
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#coding=UTF-8

def search(jun):
    global ans
    global R
    global r
    global rCost
    tmpans=0
    if len(jun)==R:
        mae=jun[0]
        for idx in range(1,R,1):
            ba=jun[idx]
            tmpans += rCost[mae][r[ba]]
            mae=ba

        if ans==None or tmpans<ans:
            ans=tmpans
    else:
        for me in range(0,R,1):
            if not (me in jun):
                search(jun+[me])


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
M=int(hyo[1])
R=int(hyo[2])

mozir=input()
hyo=mozir.split(' ')
r=[(int(mono) -1 ) for mono in hyo]

michi=[]
for idx in range(0,N,1):
    michi.append([])

for idx in range(0,M,1):
    mozir=input()
    hyo=mozir.split(' ')
    A=int(hyo[0])-1
    B=int(hyo[1])-1
    C=int(hyo[2])
    michi[A].append((B,C))
    michi[B].append((A,C))


rCost=[]
for idr in range(0,R,1):
    Cost=[None]*N
    Cost[r[idr]]=0
    miru=[r[idr]]
    while miru:
        nextmiru=[]
        for toshi in miru:
            preCost=Cost[toshi]
            for (saki,sakiCost) in michi[toshi]:
                tmpCost=preCost+sakiCost
                if Cost[saki]==None or tmpCost < Cost[saki]:
                    Cost[saki]=tmpCost
                    nextmiru.append(saki)

        miru=list(set(nextmiru))
    rCost.append(Cost)

#for ko in rCost:
#    print(ko)

ans=None
search([])
print(ans)


Measured memory_bytes: 6644
#include<iostream>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
if(m*10000<n||m*1000>n||n%1000!=0){
cout<<"-1 -1 -1";
return 0;}
for(int i=0;i<=m;i++)
for(int j=0;j<=m;j++)
for(int k=0;k<=m,i+j+k<=m;k++)
if(i+j+k==m&&i*1000+j*5000+k*10000==n){
cout<<k<<" "<<j<<" "<<i;
return 0;}
cout<<"-1 -1 -1";}

Measured memory_bytes: 256
def main():
    S = input()
    minnum = float('inf')
    minus = float('inf')
    for i in range(len(S) - 3 + 1):
        if minus > abs(753 - int(S[i:i + 3])):
            minnum = int(S[i:i + 3])
            minus = abs(753 - int(S[i:i + 3]))
    print(minus)
main()

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
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;}



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

  ll N , C, K; cin >> N >> C >> K;
  vector<ll> T;
  rep(i,N){
    ll inp; cin >> inp;
    T.pb(inp);
  }
  sort(all(T));
  
  ll till = 0;
  ll cnt = 0;
  ll ans = 0;

  rep(i,N){
    if(T[i] > till || cnt >= C) {
      ans ++;
      till = T[i] + K;
      cnt = 0;
    }
    cnt ++;
  }
  
  cout << ans << endl;

  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

int main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  vector<int> s;
  vector<int> ord(N + 1, -1);

  int c = 1, l = 0;
  int v = 1;
  while (ord.at(v) == -1) {
    ord.at(v) = s.size();
    s.push_back(v);
    v = A.at(v - 1);
  }

  c = s.size() - ord.at(v);
  l = ord.at(v);

  if (K < l) cout << s.at(K) << endl;
  else {
    K -= l;
    K %= c;
    cout << s.at(l + K) << endl;
  }

  return 0;
}


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

int main(){
    ll n,ans,a,b;
    cin >> n >>  a >> b;
    if(b-a>=0&&n>1)cout << (n-2)*(b-a)+1 << endl;
    else if(n==1&&a==b) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

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

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  int n=in();
  vector<float> g(n); // vは使っているのでg(具材)
  cin>>g;
  sort(g.begin(),g.end());
  rep(i,n-1) g[i+1]=(g[i]+g[i+1])/2;
  cout << g[n-1] << endl;
  return 0;
}


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

#define MAX 100010

using namespace std;

struct node{
  int index;
  int way = 0;
  stack <int> room;
};

void printans(vector <node>& cavemap, int& cnt, int& N)
{
  if (cnt < N - 1)
    cout << "No" << '\n';
  else{
    cout << "Yes" << '\n';
    for (int i = 2; i <= N; i++)
      cout << cavemap[i].way << '\n';
  }
}

void findans(vector <node>& cavemap, int& N, int& cnt)
{
  queue <int> temp;
  temp.push(1);
  while (cnt <= N - 1 && !temp.empty()){
    int index = temp.front();
    while(!cavemap[index].room.empty()){
      if (cavemap[cavemap[index].room.top()].way == 0){
	cavemap[cavemap[index].room.top()].way = index;
	temp.push(cavemap[index].room.top());
	cnt++;
      }
      cavemap[index].room.pop();
    }
    temp.pop();
  }
}

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, a, b, cnt = 0;
  cin >> N >> M;
  vector <node> cavemap(MAX);
  for (int i = 0; i < M; i++){
    cin >> a >> b;
    cavemap[a].index = a;
    cavemap[b].index = b;
    cavemap[a].room.push(b);
    cavemap[b].room.push(a);
  }
  findans(cavemap, N, cnt);
  printans(cavemap, cnt, N);
  return 0;
}


Measured memory_bytes: 72568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    int s, w; cin >> s >> w;
    if(w >= s) cout << "unsafe";
    else cout << "safe";
}


Measured memory_bytes: 3624
<?php

fscanf(STDIN, "%d", $n);

for($i=0;$i<$n;$i++){
    fscanf(STDIN, "%d", $array[]);
}

$max = max($array);
$flag = 0;
for($i=0;$i<$n;$i++){

    if($array[$i] == $max && $flag == 0){
        $copy = $array;
        unset($copy[$i]);
        echo max($copy).PHP_EOL;
        $flag = 1;

    }else{
        echo $max.PHP_EOL;
    }


}


Measured memory_bytes: 26484
s = input()

result = []

def spstr(made, left):
    for x in range(1, len(left)+1):
        new_made = made.copy()
        new_made.append(int(left[0:x]))
        new_left = left[x:]
        if new_left == "":
            result.append(new_made)
        else:
            spstr(new_made, new_left)
spstr([], s)

count = 0
for r in result:
    for n in r:
        count += n
print(count)

Measured memory_bytes: 3064
//Bismillahir Rahmanir Raheem
//In the name of Allah , Most Gracious , Most Merciful

/*

  * * * * * * *   * * * * * * *   *           *   * * *   * * * * * *
              *   *           *   *           *     *     *           *
              *   *           *   *           *     *     *             *
              *   *           *   *           *     *     *             *
              *   * * * * * * *   * * * * * * *     *     *             *
  *           *   *           *   *           *     *     *             *
  *           *   *           *   *           *     *     *             *
  *           *   *           *   *           *     *     *           *
  * * * * * * *   *           *   *           *   * * *   * * * * * *

*/



#include<bits/stdc++.h>
using namespace std;


#define BOOST ios_base::sync_with_stdio(false) , cin.tie(NULL)


int main()
{
    BOOST;

    int k,f=0;
    cin>>k;
    int m,n;
    cin>>m>>n;
    for(int i=m;i<=n;i++){
        if(i%k==0){f=1;break;}
    }
    if(f==1)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    return 0;
}












Measured memory_bytes: 3648
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)

ans = 0

for i in range(0, N + 1):
    d = a[i] + a[i + 1] - x
    if d > 0:
        ans += d
        if a[i + 1] > d:
            a[i + 1] -= d
        else:
            a[i] -= d - a[i + 1]
            a[i + 1] = 0

print(ans)


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

int n,d,m[100],id[100],p[100],num;
vector<int> c[100];

int main(){
  cin.tie(0);
  std::ios::sync_with_stdio(0);
  while(cin >> n >> d, n){
    num = 0;
    rep(i,n){
      cin >> m[i];

      c[i].resize(m[i]); p[i] = 0;
      rep(j,m[i]){
	cin >> c[i][j];
	p[i] += c[i][j];
      }

      num += m[i];
      id[i] = m[i]-1;
    }

    bool f = true;
    rep(i,num){
      int maxv = -1, secv = -1;
      rep(j,n){
	secv = max(secv,p[j]);
	if(secv > maxv)swap(secv,maxv);
      }

      f = false;
      rep(j,n){
	if(id[j]>=0){
	  if(p[j] == maxv){
	    if(secv<0 || secv-d<=p[j]-c[j][id[j]]){
	      p[j] -= c[j][id[j]];
	      id[j]--;
	      f = true;
	      break;
	    }
	  }else if(maxv-d<=p[j]-c[j][id[j]]){
	    p[j] -= c[j][id[j]];
	    id[j]--;
	    f = true;
	    break;
	  }
	}
      }

      if(!f)break;
    }
    cout << (f?"Yes":"No") << endl;
  }
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template <typename T1, typename T2>
void chmax(T1 &a, const T2 &b) {
  if(a < b) a = b;
}

template <typename T1, typename T2>
void chmin(T1 &a, const T2 &b) {
  if(a > b) a = b;
}

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<int> a(n);
  for(int i=1;i<n;++i) {
    int p = 0; cin >> p;
    p--;
    a[p]++;
  }
  for(int i=0;i<n;++i) {
    cout << a[i] << endl;
  }
  
}


Measured memory_bytes: 3988
import java.util.*;
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args) {
		int a,b;
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		if(a <= 5)	out.println(0);
		else if(a >= 13)	out.println(b);
		else	out.println(b / 2);
	}
}


Measured memory_bytes: 23764
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int a, b;
  cin>>a>>b;
  int ans = max(max(a+b, a-b), a*b);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef tuple<int, int, int> t3;

int n, t, a[200020];
ll ans;

void solve(){
	scanf("%d%d", &n, &t);
	rep(i, n)scanf("%d", a+i);
	for(int i=0;i<n;i++){
		if(i > 0 && a[i] - a[i-1] < t)ans += a[i] - a[i-1];
		else ans += t;
	}
	printf("%lld\n", ans);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 1024