akhauriyash/Code-Regression huggingface dataset:
import math
from decimal import *

n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]

def newT(t, ratio):
    if t[0] <= ratio[0] and t[1] <= ratio[1]:
        return ratio
    else:
        #切り上げ (x+p-1)//p
        c = max((t[0]+ratio[0]-1)//ratio[0], (t[1]+ratio[1]-1)//ratio[1])
        return [i*c for i in ratio]

to = l[0]
for li in l[1:]:
    to = newT(to, li)

print(to[0]+to[1])


Measured memory_bytes: 5076
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	vector<int>coins;
	for (int i = 1; i < 18; ++i) {
		coins.push_back(i*i);
	}
	vector<vector<int>>dp(600,vector<int>(17));
	dp[0][0] = 1;
	for (int i = 0; i < 300; ++i) {
		for (int j = 0; j < 17; ++j) {
			for (int k = j; k < 17; ++k) {
				dp[i + coins[k]][k] += dp[i][j];
			}
		}
	}
	while (1) {
		int n; cin >> n;
		if (!n)break;
		int sum = 0;
		for (int i = 0; i < 17; ++i) {
			sum += dp[n][i];
		}
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int w;
	cin >> w;
	const int n = s.size();
	for(int i = 0; i < n; i += w){
		cout << s[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<stack>
#include<vector>

using namespace std;

typedef pair<int, int> P;

int A[200200];
int N;

void input(){
	scanf("%d", &N);
	for(int i = 0; i < N; ++i) scanf("%d", A + i);
}

stack<P> st;

int c[200200];

vector<long long> calcDP(vector<int> vec){
	vector<long long> dp(vec.size());
	for(int i = vec.size() - 1; i >= 1; --i){
		long long prv = vec[i - 1];
		long long cur = vec[i];
		c[i] = 0;
		if(prv > cur){
			while(prv > cur){
				c[i] += 2;
				cur *= 4;
			}
		}else{
			prv *= 4;
			while(prv <= cur){
				prv *= 4;
				c[i] -= 2;
			}
		}
	}
	int N = vec.size();
	dp[N - 1] = 0;
	while(st.size() > 0) st.pop();
	for(int i = N - 2; i >= 0; --i){
		if(c[i + 1] < 0){
			dp[i] = dp[i + 1];
			st.push(P(i + 1, -c[i + 1]));
		}else{
			dp[i] = dp[i + 1];
			int rem = c[i + 1];
			while(rem > 0){
				if(st.empty()) break;
				P p = st.top();
				st.pop();
				if(p.second <= rem){
					long long coe1 = p.first - i - 1;
					long long coe2 = p.second;
					dp[i] += coe1 * coe2;
					rem -= p.second;
				}else{
					long long coe1 = p.first - i - 1;
					long long coe2 = rem;
					dp[i] += coe1 * coe2;
					p.second -= rem;
					st.push(p);
					rem = 0;
				}
			}
			if(rem > 0){
				dp[i] += ((long long)(N - i - 1) * rem);
			}
		}
	}/*
	for(int i = 0; i < N; ++i){
		printf("%d ", vec[i]);
	}
	printf("\n");
	for(int i = 0; i < N; ++i){
		printf("%d ", c[i]);
	}
	printf("\n");
	for(int i = 0; i < N; ++i){
		printf("%lld ", dp[i]);
	}
	printf("\n");*/
	return dp;
}

vector<long long> dp1, dp2;
vector<int> a1, a2;

long long solve(){
	for(int i = 0; i < N; ++i) a1.push_back(A[i]);
	for(int i = N - 1; i >= 0; --i) a2.push_back(A[i]);
	dp1 = calcDP(a1);
	dp2 = calcDP(a2);
	long long ans = 1e12;
	for(int n = 1; n < N; ++n){
		long long cur = n;
		cur += dp1[n];
		cur += dp2[N - n];
		ans = min(ans, cur);
	}
	ans = min(ans, dp1[0]);
	ans = min(ans, N + dp2[0]);
	return ans;
}

int main(){
	input();
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 7268
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]

    sumA = [0 for i in range(N + 1)]
    sumAplus = [0 for i in range(N + 1)]
    for i in range(N):
        sumA[i + 1] = sumA[i] + A[i]
        sumAplus[i + 1] = sumAplus[i] + max(A[i], 0)

    max_score_b = 0
    max_score_w = 0
    for i in range(1, N - K + 2):
        score_b = (sumAplus[i - 1] - sumAplus[0]) + (sumA[i + K - 1] - sumA[i - 1]) + (sumAplus[N] - sumAplus[i + K - 1])
        max_score_b = max(max_score_b, score_b)
        score_w = (sumAplus[i - 1] - sumAplus[0]) + (sumAplus[N] - sumAplus[i + K - 1])
        max_score_w = max(max_score_w, score_w)
    print max(max_score_b, max_score_w)


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    int n, X;
    cin>>n>>X;
    int x[n];
    int res = 0;
    for(int i=0;i<n;++i)
    {
        cin>>x[i];
        res = __gcd(res, abs(X - x[i]));
    }
    cout<<res<<endl;
    return 0;
}


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

typedef long long ll;

int main() {
    int n;
    cin >> n;
    int a = 0, b = 0, c = 0;
    while (n--) {
        int num;
        scanf("%d", &num);
        if (num % 4 == 0)
            a++;
        else if (num % 2 == 0)
            b++;
        else
            c++;
    }
    if (c > a + 1 || (c == a + 1 && b != 0))
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}

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

struct KMP {
    vector<long long> pat;
    vector<int> fail;

    // construct
    KMP(const vector<long long> &p) { init(p); }
    void init(const vector<long long> &p) {
        pat = p;
        int m = (int)pat.size();
        fail.assign(m+1, -1);
        for (int i = 0, j = -1; i < m; ++i) {
            while (j >= 0 && pat[i] != pat[j]) j = fail[j];
            fail[i+1] = ++j;
        }
    }

    // the period of S[0:i]
    int period(int i) { return i - fail[i]; }
    
    // the index i such that S[i:] has the exact prefix p
    vector<int> match(const vector<long long> &S) {
        int n = (int)S.size(), m = (int)pat.size();
        vector<int> res;
        for (int i = 0, k = 0; i < n; ++i) {
            while (k >= 0 && S[i] != pat[k]) k = fail[k];
            ++k;
            if (k >= m) res.push_back(i - m + 1), k = fail[k];
        }
        return res;
    }
};

int N;
vector<long long> a, b;

void solve() {
    vector<long long> da(N*2), db(N);
    for (int i = 0; i < N*2; ++i) {
        int j = i % N;
        int k = (i + 1) % N;
        da[i] = a[j] ^ a[k];
        if (i < N) db[i] = b[j] ^ b[k];
    }
    KMP kmp(db);
    auto v = kmp.match(da);
    for (auto k : v) {
        if (k < N) cout << k << " " << (a[k] ^ b[0]) << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N) {
        a.resize(N); b.resize(N);
        for (int i = 0; i < N; ++i) cin >> a[i];
        for (int i = 0; i < N; ++i) cin >> b[i];
        solve();
    }
}

Measured memory_bytes: 14580
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
    bool ans = true;
    string w;
    cin >> w;
    map<char, int> m;
    for (int i = 0; i < w.size(); i++) {
        auto itr = m.find(w[i]);
        if (itr == m.end()) m[w[i]] = 1;
        else m[w[i]]++;
    }
    for (auto itr = m.begin(); itr != m.end(); itr++) if (itr->second % 2 != 0) ans = false;
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
template <typename T>
void ce(initializer_list<T> v){for(T i : v) cerr << i << ' '; cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 2019;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll l;
	cin >> l;
	bitset<20> L(l);

	ll sum = 0;
	ll n = 0;
	rep(i, 20) if(L[i]) n = i;
	sum = pow2(n);
	Vec1<pair<ll, P> > e;
	repn(i, n){
		e.push_back({i, {i + 1, 0}});
		e.push_back({i, {i + 1, pow2(i - 1)}});
	}
	n++;

	while(l - sum){
		ll a = 0;
		while(l - sum >= pow2(a + 1)) a++;
		e.push_back({a + 1, {n, sum}});
		sum += pow2(a);
	}
	cout << n << " " << e.size() << endl;
	for(auto i : e) cout << i.fs << " " << i.sc.fs << " " << i.sc.sc << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,count=0,count2=0,cnt[100005]={};
  int p[100005],p2[100005]={};
  string s[100005];
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>p[i]>>s[i];
  }
  for(int i=0;i<m;i++){
    if(s[i]=="WA"){
      if(p2[p[i]-1]==0)cnt[p[i]-1]++;
    }else{
      if(p2[p[i]-1]==0){
	count2++;
	count+=cnt[p[i]-1];
      }
      p2[p[i]-1]=1;
    }
  }
  cout<<count2<<" "<<count<<"\n";
  return 0;
}


Measured memory_bytes: 7680
n,k,q = gets.split.map!(&:to_i)

c = Array.new(n+1,0)
q.times do 
    a = gets.to_i
    c[a] += 1
end

1.upto(n) do |i|
    if k - q + c[i] > 0 then
        puts "Yes"
    else
        puts "No"
    end
end

Measured memory_bytes: 3196
package main

import (
	"fmt"
)

func main() {
	var r, D, x2000 int
	fmt.Scanln(&r, &D, &x2000)

	x := make([]int, 11)
	x[0] = x2000

	for i := 1; i <= 10; i++ {
		x[i] = r*x[i-1] - D
		fmt.Println(x[i])
	}
}


Measured memory_bytes: 512
let input = readLine()!.characters.map{String($0)}
let (A, B, C, D) = (Int(input[0])!, Int(input[1])!, Int(input[2])!, Int(input[3])!)
if A+B+C+D == 7 {
    print("\(A)+\(B)+\(C)+\(D)=7")
} else if A+B+C-D == 7 {
    print("\(A)+\(B)+\(C)-\(D)=7")
} else if A+B-C+D == 7 {
    print("\(A)+\(B)-\(C)+\(D)=7")
} else if A+B-C-D == 7 {
    print("\(A)+\(B)-\(C)-\(D)=7")
} else if A-B+C+D == 7 {
    print("\(A)-\(B)+\(C)+\(D)=7")
} else if A-B+C-D == 7 {
    print("\(A)-\(B)+\(C)-\(D)=7")
} else if A-B-C+D == 7 {
    print("\(A)-\(B)-\(C)+\(D)=7")
} else if A-B-C-D == 7 {
    print("\(A)-\(B)-\(C)-\(D)=7")
}

Measured memory_bytes: 4080
#!/usr/bin/python

import math
import sys

def is_prime(n):
    if n == 1:
        return False

    for i in xrange(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

def main(argv):
    primes = [False]
    for i in xrange(1, 100000 + 1):
        primes.append(is_prime(i))

    counter = 0
    results = [0]
    for i in xrange(1, 100000 + 1):
        if i % 2 == 0:
            results.append(counter)
            continue

        if primes[i] and primes[(i + 1) / 2]:
            counter += 1
        results.append(counter)

    line = sys.stdin.readline()
    while line:
        Q = int(line.rstrip("\n"))
        for i in xrange(Q):
            l, r = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))

            print results[r] - results[l - 1]

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 4744
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    int n,b,B=0,C=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        B=0;C=0;
        for(int j=0;j<10;j++){
            scanf("%d",&b);
            if(min(B,C)<b){
                if((B>C && B<b) || C>b)B=b;
                else C=b;
            }else{
                B=11;C=11;
            }
        }
        if(B==10 || C==10)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}

Measured memory_bytes: 1168
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main(){
		new A().doIt();
	}
	
	class A{
		int n,m;
		int[] result;
		int zero,one;
		boolean calc(int target){
			int index = 0,num = 1;
			int c = ((target>>0)%2);
			for(int i=1;i<n;i++){
				if(c == (target>>i)%2)num++;
				else{
					if(result[m-index-1]!=num)return false;
					index++;
					num = 1;
					c = (target>>i)%2;
				}
			}
			if(result[m-index-1]!=num)return false;
			int z = 0;
			int o = 0;
			for(int i=0;i<n;i++){
				if((target>>i)%2==0)z++;
				else o++;
			}
			if(zero==z&&one==o)return true;
			return false;
		}
		
		int solve(ArrayList<Integer> kouho,char[] to){
			int result = Integer.MAX_VALUE/2;
			ArrayList<String> list = new ArrayList<String>();
			for(int i=0;i<kouho.size();i++){
				String a = "";
				for(int s=n-1;s>=0;s--)a+=((kouho.get(i)>>s)%2);
				list.add(a);
			}
//			System.out.println(list);
			
			for(int i=0;i<list.size();i++){
				int cnt = 0;
				boolean[] sw = new boolean[n];
				String target = list.get(i);
//				System.out.println(target);
				for(int s=0;s<n;s++)if(target.charAt(s)=='1'){
					for(int j=0;j<n;j++){
//						System.out.println(s+" "+j+" "+target.charAt(s)+" "+to[j]);
						if(to[j]==target.charAt(s)&&!sw[j]){
							sw[j] = true;
							cnt += Math.abs(j-s);
							break;
						}
//						System.out.println(Arrays.toString(sw));
					}
				}
				result = Math.min(cnt, result);
			}
			
			return result;
		}
		
		void doIt(){
			n = in.nextInt();
			m = in.nextInt();
			zero = 0;one = 0;
			char[] input = new char[n];
			for(int i=0;i<n;i++)input[i] = in.next().charAt(0);
			String input2 = "";
			for(int i=0;i<n;i++)input2+=input[i];
			result = new int[m];
			for(int i=0;i<m;i++)result[i] = in.nextInt();
			for(int i=0;i<n;i++){
				if(input[i]=='0')zero++;
				else one++;
			}
			ArrayList<Integer> kouho = new ArrayList<Integer>();
			for(int i=0;i<(1<<n);i++){
				if(calc(i))kouho.add(i);
			}
//			System.out.println(kouho);
//			for(int i=0;i<kouho.size();i++)System.out.println(Integer.toBinaryString(kouho.get(i)));
			System.out.println(solve(kouho,input));
		}
	}
	
}

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

int main() {
  int H,W;
  cin >> H >> W;
  string S[H];
  int count[H][W];

  for(int i = 0; i < H; i++) {
    cin >> S[i];
    for(int j = 0; j < W; j++) {
        count[i][j] = 0;
    }
  }

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++){
      if(S[i].at(j) == '#') {
          for(int x = i - 1; x <= i + 1; x++) {
            for(int y = j  - 1; y <= j + 1; y++) {
                if(x == i && y ==j){
                  count[x][y] = -1;
                  continue;
                }
                else if(x >= 0 && x < H && y >= 0 && y < W && count[x][y] != -1){
                  count[x][y]++;
                }
            }
          }
      }
    }
  }

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(count[i][j] == -1) {
       continue;
      }
      char c = '0' + count[i][j];
      S[i].at(j) = c;
    }
  }

  for(int i = 0; i < H; i++) {
    cout << S[i] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
short n, x, a = 10086, b = -1;
int main() {
	scanf("%hd", &n);
	while (n--) {
	    scanf("%hd", &x);
	    a = min(a, x);
	    b = max(b, x);
	}
	printf("%hd\n", b - a);
	return 0;
} 

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

int main()
{
    int H, W, N, result = 0, count = 0;
    cin >> H;
    cin >> W;
    cin >> N;

    int B = (H < W) ? W : H;
    int S = (W < H) ? W : H;

    for (int i = 1; i <= S; i++)
    {
        count += B;
        result++;
        if (N <= count)
        {
            cout << result << endl;
            return 0;
        }
    }

    return 0;
}


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

using namespace std;

int main() {

	double a, b, c, d, e, f,x,y;

	while (cin >> a >> b >> c >> d >> e >> f) {
		
		x = (c*e - b*f) / (a*e-b*d)+0.0;
		y = (c*d - a*f) / (b*d - a*e)+0.0;

		printf("%.3lf %.3lf\n",x,y);

	}

	return 0;

}

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

bool dp[10010];
int main() {
    int n;
    scanf("%d", &n);
    dp[0] = true;
    int sum = 0, num;
    for(int i = 1; i <= n; i++) {
        scanf("%d", &num);
        sum += num;
        for(int j = sum; j >= num; j--) if(j >= num){
            dp[j] |= dp[j - num];
        }
    }
    int ret = 0;
    for(int i = 0; i <= sum; i++) if(dp[i] && i % 10){
        ret = i;
    }
    printf("%d\n", ret);
    return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int sx,tx,sy,ty;
  cin >> sx >> sy >> tx >> ty;
  REP(i,tx-sx){
    cout << "R";
  }
  REP(i,ty-sy){
    cout << "U";
  }
  REP(i,tx-sx){
    cout << "L";
  }
  REP(i,ty-sy){
    cout << "D";
  }
  //
  cout << "DR";
  REP(i,tx-sx){
    cout << "R";
  }
  REP(i,ty-sy){
    cout << "U";
  }
  cout << "ULUL";
  REP(i,tx-sx){
    cout << "L";
  }
  REP(i,ty-sy){
    cout << "D";
  }
  cout << "DR" << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
N = int(input())
p = [None]+[int(c) for c in input().split()]
p_to_i = [None]*(N+1)
for i, x in enumerate(p[1:],1):
  p_to_i[x] = i

tree = [0]*(N+1)

def BIT_add(i):
  while i<=N:
    tree[i] += 1
    i += i&(-i)
    
def BIT_sum(i):
  s = 0
  while 0<i:
    s += tree[i]
    i -= i&(-i)
  return s

def BIT_search(c):
  s = 0
  step = 1<<(N.bit_length()-1)
  i = 0
  while step:
    if i+step<=N and s+tree[i+step]<c:
      i += step
      s += tree[i]
    step >>= 1
  return i+1

ans = 0
for i in range(1,N+1):
  c = p_to_i[i]
  L = BIT_sum(c)
  R = i-1-L
  BIT_add(c)
  a = BIT_search(L) if L>0 else 0
  b = BIT_search(L+2) if R>0 else N+1
  m = (c-a)*(b-c)
  ans += m*i
#  print(i, ans, a, b, c, L, R)
print(ans)
  

Measured memory_bytes: 87632
import java.util.*;

public class Main {
	public static void main(String args[]) throws NumberFormatException{
		Scanner scan = new Scanner(System.in);
		long sum;//??´??°?????°
		int n;
		n = scan.nextInt();
		sum = 0;//????¨??????¨????????????
		
		List<Integer> list = new ArrayList<Integer>();
		
		//n?????????????????????????????\??????
		for(int count = 0; count < n ; count++){
			list.add(scan.nextInt());
			
		}
		
		
		//??????????????????????????????????????¨??????????????????????????????n-1
		Collections.sort(list);
		
		//??¨????????????????¨?????????¨???
		for(int i =0;i < list.size();i++){
			sum = sum + list.get(i);
		}
		
		System.out.println(String.valueOf(list.get(0)) + " " + String.valueOf(list.get(n-1)) + " " + String.valueOf(sum));
		
		
	}
}

Measured memory_bytes: 42500
K = int(input())
seven = 7
count = 0

if(K % 2 == 0 or K % 5 == 0):
    print(-1)
if(K == 7 or K == 1):
    print(1)
else:
    for i in range(1,10**6):
        seven = (seven * 10 + 7) % K
        if(seven % K == 0):
            print(i+1)
            break

        # これだと10^5以降の計算が遅くなる。countのせい？？
        # count += 1
        # seven = seven + 7 * (10 ** count)

Measured memory_bytes: 9192
import sys
import fractions

n, m = map(int, input().split())
a = set(map(int, input().split()))

g = 0
mx_2 = 0
for i in a:
    tmp = 0
    while i % (2 ** tmp) == 0: tmp += 1
    mx_2 = max(mx_2, tmp - 1)
    g = fractions.gcd(g, i)

if g % (2 ** mx_2) != 0 or g % (2 ** (mx_2 + 1)) == 0:
    print(0)
else:
    prod = 1
    lcm = 1
    g = 0
    for i in a:
        lcm = lcm * i // 2 // fractions.gcd(lcm, i // 2)

    print((m // lcm + 1) // 2)



Measured memory_bytes: 13328
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std ;
ll a[100100];
int main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    string sol="";
    if(s.length()==3)
    {
        if(s[0]==s[2])
        {
            sol="Second";
        }
        else
        {
            sol="First";
        }
    }
    else
    {
        if(s[0]!=s[s.length()-1])
        {
            if(s.length()%2==0)
            {
                sol="Second";
            }
            else
            {
                sol="First";
            }
        }
        else
        {
                if(s.length()%2==0)
                {
                    sol="First";
                }
                else
                {
                    sol="Second";
                }

        }
    }
    cout<<sol<<endl;
}


Measured memory_bytes: 512
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    lint d, g;
    cin >> d >> g;
    vector<lint> p(d), c(d);
    rep(i, d){
        cin >> p[i] >> c[i];
    }
    vector<lint> ma(d);
    rep(i, d){
        ma[i] = (i+1) * 100 * p[i] + c[i];
    }
    lint l = pow(2, d), ans = LLINF;
    rep(i, l){
        lint res = i, cnt = 0;
        vector<bool> b(d);
        while(res > 0){
            b[cnt] = res % 2;
            res /= 2;
            cnt++;
        }
        lint point = 0;
        cnt = 0;
        rep(j, d){
            if(b[j]){
                point += ma[j];
                cnt += p[j];
            }
        }
        if(point < g){
            bool flag = false;
            repr(j, d){
                if(!b[j]){
                    rep(k, p[j] - 1){
                        point += (j+1)*100;
                        cnt++;
                        if(point >= g){
                            flag = true;
                            break;
                        }
                    }
                }
                if(flag){
                    break;
                }
            }
        }
        if(point >= g){
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
const int MAXN=200000;
const int logn=18;
const int INF=MAXN+1;
int n,perm[MAXN+5],msb[MAXN+5],ans[MAXN+5],idx=1;
priority_queue <pair<int,pii> >pq;
//first itu terkecil, second itu pilihan
pii st[2][logn+2][MAXN+5];
int jenis(int indeks){			//membedakan ganjil genap
	return (indeks&1)?1:0;
}
void buatst(int id,int depth){
	for(int i=1;i<=n;i++)
	{
		if((i+(1<<(depth-1)))>n)
			st[id][depth][i]=st[id][depth-1][i];
		else
		{
			st[id][depth][i]=min(st[id][depth-1][i],st[id][depth-1][i+(1<<(depth-1))]);
		}
	}
}
void basecasest(int id){
	for(int i=1;i<=n;i++)
	{
		if(jenis(i)==id)
			st[id][0][i]=mp(perm[i],i);
		else
			st[id][0][i]=mp(INF,i);
	}
}
void buatst(int id){
	basecasest(id);
	for(int i=1;i<logn;i++)
		buatst(id,i);
}
void buatst(){
	for(int id=0;id<2;id++)
		buatst(id);
}
void isimsb(){
	msb[0]=-1;			//harusnya ini dak mungkin
	msb[1]=0;
	for(int i=2;i<=n;i++)
	{
		msb[i]=msb[i-1];
		while((1<<(msb[i]+1))<=i)				//loopnya harusnya at most 1 kali
			msb[i]++;
	}
}
pii query(int id,int l,int r){
	int panjang=r-l+1;
	return min(st[id][msb[panjang]][l],st[id][msb[panjang]][r-(1<<msb[panjang])+1]);
}
void updateans(int angka){
	ans[idx++]=angka;
}
void masukkan(int l,int r){
	if(l>r)
		return;
	pq.push(mp(-query(jenis(l),l,r).fi,mp(l,r)));
}
pii rangetarget(int l,int r){
	pii ret,temp;
	temp=query(jenis(l),l,r);
	ret.fi=temp.se;
	temp=query(jenis(l)^1,ret.fi,r);
	ret.se=temp.se;
	return ret;
}
void pecah(int l,int r,int ll,int rr){
	masukkan(l,ll-1);
	masukkan(ll+1,rr-1);
	masukkan(rr+1,r);
}
void carians(){
	masukkan(1,n);
	while(!pq.empty())
	{
		pii range=pq.top().se;
		pq.pop();
		pii pilihan=rangetarget(range.fi,range.se);
		updateans(perm[pilihan.fi]);
		updateans(perm[pilihan.se]);
		pecah(range.fi,range.se,pilihan.fi,pilihan.se);
	}
}
int main()
{
	scan(n);
	for(int i=1;i<=n;i++)
		scan(perm[i]);
	buatst();
	isimsb();
	carians();
	for(int i=1;i<=n;i++)
	{
		printf("%d",ans[i]);
		if(i==n)
			printf("\n");
		else
			printf(" ");
	}
}

Measured memory_bytes: 62840
/*
********************
Author : Sahil Kundu
********************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define pb(i) push_back(i)
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define all(vc) vc.begin(),vc.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ms(i,j) memset(i,j,sizeof i)
#define w(t) while(t--)
#define len(s) s.length()
const ll MAX=1e5+5;
const ll INF=2e18+10;
const int inf=1e9+10;
void solve()
{
    int n,m;
    cin>>n>>m;
    int a[m],b[m],w[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i]>>b[i]>>w[i];
        a[i]--;b[i]--;
    }
    int dist[n+1][n+1];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i==j)
                dist[i][j]=0;
            else dist[i][j]=inf;
        }
    }
    for(int i=0;i<m;i++)
    {
        dist[b[i]][a[i]]=min(dist[b[i]][a[i]],w[i]);
        dist[a[i]][b[i]]=min(dist[a[i]][b[i]],w[i]);
    }
    
    // shortest distance using floyd
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            for(int k=0;k<n;k++)
            {
                dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
            }
    // find ans
    int ans=m;
    for(int i=0;i<m;i++)
    {
        bool shortest=false;
        for(int j=0;j<n;j++)
        {
            if(dist[j][a[i]]+w[i]==dist[j][b[i]])
                shortest=true;
        }
        if(shortest)ans--;
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    w(t) solve();
    return 0;
}

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

	typedef long long ll;

	typedef pair<int, int> pii;
	typedef pair<ll,ll> pll;

	typedef vector<int> vi;
	typedef vector<ll> vll;
	typedef vector<pii> vpii;
	typedef vector<pll> vpll;

	#define FOR(i, a, b) for (int i=a; i<(b); i++)
	#define F0R(i, a) for (int i=0; i<(a); i++)
	#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
	#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

	#define ALL(s) (s).begin(),(s).end()
	#define ALLn(s,n) s,s+n
	#define F first
	#define S second
	#define pb push_back
	#define tc(t) int t; cin >> t; while(t--)
	#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
	#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
	#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

	const ll MOD = 1e9 + 7;
	const ll MAXN = 1e6 + 7;
	const ll INF = LONG_LONG_MAX;

	void solve() {
		int n;
			cin >> n;
			int a[n];
			map<int,int> mp;
			ll sum = 0;

			F0R(i,n) {
				cin >> a[i];
				sum += a[i];
				mp[a[i]]++;
			}

			int q;
			cin >> q;

			F0R(i,q) {
				// for(auto x: mp) cout << x.F << ' ' <<x.S<<'\n';
				int b,c;
				cin >> b>> c;
				int diff = c - b;
				if(mp.count(c)==0) mp[c] = 0;
				mp[c] += mp[b];
				sum += (mp[b]*diff);
				mp[b]=0;
				cout << sum << '\n';
			}

	}

	int32_t main() {_
		
	#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
	#endif

		// tc(t)
			solve();
		cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
	}



Measured memory_bytes: 8592
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
nb = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    l = len(s)
    dp = [[0 for _ in range(13)] for __ in range(l + 1)]
    dp[0][0] = 1

    for i, si in enumerate(s):
        base = pow(10, l - i - 1, 13)

        if si == "?":
            for k in range(10):
                tmp = base * k % 13
                for j in range(13):
                    dp[i + 1][(j + tmp) % 13] += dp[i][j]
                    dp[i + 1][(j + tmp) % 13] %= MOD
        else:
            si = int(si)
            tmp = base * si % 13
            for j in range(13):
                dp[i + 1][(j + tmp) % 13] += dp[i][j]
                dp[i + 1][(j + tmp) % 13] %= MOD

    print(dp[l][5])


if __name__ == '__main__':
    main()


Measured memory_bytes: 105912
(N,M,P),*E=[list(map(int,s.split()))for s in open(0)]
D=[0]*2+[-9e9]*N
def f():
	for _ in D:
		for a,b,c in E:D[b]=max(D[b],D[a]+c-P)
f()
s=D[N]
f()
print([max(s,0),-1][s<D[N]])

Measured memory_bytes: 52252
#include<bits/stdc++.h>
#define rep(X,Y) for(int X=0;X<(Y); ++X)
#define pb push_back
#define eb emplace_back

using namespace std;

typedef long long ll;
const ll MOD=1e9+7;

int d[111][111];

struct UF{
  vector<int> data;
  UF(int size):data(size,-1){}
  bool unite(int x,int y){
    x=root(x); y=root(y);
    if(x!=y){
      if(data[y]<data[x]) swap(x,y);
      data[x]+=data[y]; data[y]=x;
    }
    return x!=y;
  }
  bool findSet(int x,int y){return root(x)==root(y);}
  int root(int x){return data[x]<0?x:data[x]=root(data[x]);}
  int size(int x){return -data[root(x)];}
};

int main(){
  cout<<fixed<<setprecision(10);
  int n;
  while(cin>>n,n){
    fill(d[0],d[111],MOD);
    vector<double> p(n);
    rep(i,n){
      int t;
      cin>>p[i]>>t;
      rep(_,t){
	int x;
	cin>>x; --x;
	d[i][x]=1;
      }
    }
    rep(i,n) d[i][i]=0;
    rep(k,n)rep(i,n)rep(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    //rep(i,n){rep(j,n) cout<<d[i][j]<<",";cout<<endl;}
    UF uf(n);
    rep(i,n)rep(j,n)if(d[i][j]<MOD && d[j][i]<MOD) uf.unite(i,j);
    vector<double> over(n,1);
    vector<int> ind(n);
    rep(i,n){
      over[uf.root(i)]*=p[i];
      if(uf.root(i)==i)
	rep(j,n)if(i!=j && d[i][j]<MOD) ++ind[j];
    }
    double re=1;
    rep(i,n)if(uf.root(i)==i && ind[i]==0) re*=1-over[i];
    cout<<re<<endl;
  }
  return 0;
}

Measured memory_bytes: 3276
#include<bits/stdc++.h>
//往回回溯的时候容易runtime error
//往前加的时候一定不会越界 
//就是一直往前减到了0 
using namespace std;
const int maxn=3005;
char s[maxn];
char t[maxn];
int len1,len2;
//动态规划要搞清楚这个二维数组的两个量表示的含义 
 //const int maxnn=1e5+5;
 int dp[maxn][maxn];
 
 //标记任意一个都是可以的 
 bool vis[maxn] ;
 
 void FindMax()
{
	for(int i=0;i<len1;i++)
	{
		for(int j=0;j<len2;j++)
		{
			if(s[i]==t[j])
			dp[i+1][j+1]=dp[i][j]+1; 
			else
			dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
		}	
	} 
}

void FindWhat(int i,int j)
{
	if(i>=0)
	{
		//cout<<"sadjkhkajshdf";
		if((i-1>=0)&&(j-1>=0)&&s[i-1]==t[j-1])	
		{
		//	cout<<"isdfs";
			vis[i-1]=1;
			FindWhat(i-1,j-1);
		}
		else if((i-1>=0)&&dp[i][j]==dp[i-1][j])
		{
			FindWhat(i-1,j);
		}
		else 
		if((j-1)>=0&&dp[i][j]==dp[i][j-1])
		{
			FindWhat(i,j-1);
		}
		
	}
	return; 
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>s>>t;
	len1=strlen(s);
	len2=strlen(t);
	
	FindMax();
	
//	cout<<dp[len1][len2];
	
	FindWhat(len1,len2);
	
	int flag=0;
	
	for(int i=0;i<len1;i++)
	{
		if(vis[i]) 
		{
			flag=1;
			cout<<s[i];
		}
	}
	
	if(flag==0)
	cout<<"";
	
	return 0;
 } 

Measured memory_bytes: 35456
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
#include<string>
typedef long long ll;
#define PB	push_back
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define pii(p)			pair<int,int> p
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define print(mes)		cout << mes << endl
const double PI	 = 3.141592;
const int	 MOD = 1e9 + 7;
using namespace std;

void solve() {
	string s;
	cin >> s;
	for(int i = 0; i < s.length()-1; ++i){
		if(s[i] != s[i+1]) {
			print("Yes");
			return;
		}
	}
	print("No");
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3556
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1000000000
#define MOD 1000000007
#define MAX 1000000
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
string s;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>s;
    if(s[s.size()-1]=='s'){
    	s+="es";
	}
	else{
		s+="s";
	}
	cout<<s;
}

Measured memory_bytes: 3632
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let ans = 1110 - n;
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#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 pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int main() {
	int n;
	cin >> n;
	if (n == 3 || n == 5 || n == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

root = [-1]*n#各数字の親を-1で初期化
def r(x):
    if root[x] < 0: #親がなければ自分自身の値を返す
        return x
    else:
        root[x] = r(root[x])#親を辿る
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:#親が同じ場合
        return
    root[x] += root[y]
    root[y] = x #xをyの親とする

for i in range(m):
    a, b = map(int, input().split())
    a -= 1#0_indexにする
    b -= 1
    unite(a, b)

ans = 0
for i in range(n):
    ans = max(ans, -root[i])#要素数が最大の親が答え

print(ans)

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

int main()
{
    string S;
    int Q;
    cin >> S >> Q;
    int length = S.size();
   
    vector<char> list(length + Q * 2);

    for (int i = 0; i < length; i++)
        list[Q + i] = S[i];

    bool x = true; //元の向き
    char Ti, Fi, Ci;
    int L = 1;
    int R = 1;
    int Qcount = 0;

    for (int i = 0; i < Q; i++)
    {
        cin >> Ti;
        if (Ti == '1')
            x = !x;

        if (Ti == '2')
        {
            cin >> Fi >> Ci;
            //左側に追加
            if ((x == true && Fi == '1') || (x == false && Fi == '2'))
            {
                list[Q - L] = Ci;
                L++;
                Qcount++;
            }
            //右側に追加
            if ((x == true && Fi == '2') || (x == false && Fi == '1'))
            {
                list[(Q + length - 1) + R] = Ci;
                R++;
                Qcount++;
            }
        }
    }

    if(x)
    {
        for (int i = 0; i < length + Qcount; i++)
            cout << list[Q - L + 1 + i];
    }
    else
    {
        for (int i = 0; i < length + Qcount; i++)
            cout << list[(Q + length) - 2 + R - i];
    }
}

Measured memory_bytes: 1280
N,K =  list(map(int, input().split()))
a = []
sunuke = [0]*N
for i in range(K):
    d = int(input())
    A =  list(map(int, input().split()))
    for l in range(len(A)):
        sunuke[A[l]-1] += 1

print(sunuke.count(0))


Measured memory_bytes: 67492
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
    int n,cnt=0;
    cin>>n;
    VI p(n);
    rep(i,n) cin>>p[i];
    for(int i=1;i<n-1;i++){
      if(p[i-1]<p[i] && p[i]<p[i+1]){
        cnt++;
      }else if(p[i+1]<p[i] && p[i]<p[i-1]){
        cnt++;
      }
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 256
#include<atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int k;
    cin >> k;
    rep(i, k)cout << "ACL";
    cout << endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <array>

using namespace std;

int main() {
    cout << fixed << setprecision(10);
    
    int n;
    cin >> n;
    
    vector<int> arr(n);
    for (int idx = 0; idx < n; idx++) {
        int tmp;
        cin >> tmp;
        arr[tmp - 1] = idx + 1;
    }
    
    for (int idx = 0; idx < n; idx++) {
        cout << arr[idx] << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.LinkedList;
import java.util.Scanner;


public class Main {
	
	public static final int ALLOW_NORTH = 1;
	public static final int ALLOW_WEST = 2;
	public static final int ALLOW_SOUTH = 4;
	public static final int ALLOW_EAST = 8;
	
	public static class Walk{
		int x, y, cost;

		public Walk(int x, int y, int cost) {
			super();
			this.x = x;
			this.y = y;
			this.cost = cost;
		}
		
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int w = sc.nextInt();
			final int h = sc.nextInt();
			
			if(w == 0 && h == 0){
				break;
			}
			
			boolean[][] is_visited = new boolean[h][w];
			int[][] allow_move = new int[h][w];
			
			for(int i = 0; i < 2*h - 1; i++){
				if(i % 2 == 0){
					final int y = i / 2;
					
					for(int x = 0; x < w - 1; x++){
						final int b = sc.nextInt();
						if(b == 0){
							allow_move[y][x]   |= ALLOW_EAST;
							allow_move[y][x+1] |= ALLOW_WEST;
						}
					}
					
				}else{
					final int y = i / 2;
					
					for(int x = 0; x < w; x++){
						final int b = sc.nextInt();
						if(b == 0){
							allow_move[ y ][x] |= ALLOW_SOUTH;
							allow_move[y+1][x] |= ALLOW_NORTH;
						}
					}
					
				}
			}
			
			LinkedList<Walk> queue = new LinkedList<Walk>();
			queue.add(new Walk(0,0,1));
			
			boolean found = false;
			while(!queue.isEmpty()){
				Walk walk = queue.poll();
				
				//System.out.println(walk.x + " " + walk.y + " " + walk.cost + " " + allow_move[walk.y][walk.x]);
				
				if(walk.x == w - 1 && walk.y == h - 1){
					found = true;
					System.out.println(walk.cost);
					break;
				}
				
				if(is_visited[walk.y][walk.x]){
					continue;
				}
				is_visited[walk.y][walk.x] = true;
				
				if(walk.y > 0 && !is_visited[walk.y - 1][walk.x] && ((allow_move[walk.y][walk.x] & ALLOW_NORTH) > 0)){
					queue.add(new Walk(walk.x, walk.y - 1, walk.cost + 1));
				}
				if(walk.y < h - 1 && !is_visited[walk.y + 1][walk.x] && ((allow_move[walk.y][walk.x] & ALLOW_SOUTH) > 0)){
					queue.add(new Walk(walk.x, walk.y + 1, walk.cost + 1));
				}
				if(walk.x > 0 && !is_visited[walk.y][walk.x - 1] && ((allow_move[walk.y][walk.x] & ALLOW_WEST) > 0)){
					queue.add(new Walk(walk.x - 1, walk.y, walk.cost + 1));
				}
				if(walk.x < w - 1 && !is_visited[walk.y][walk.x + 1] && ((allow_move[walk.y][walk.x] & ALLOW_EAST) > 0)){
					queue.add(new Walk(walk.x + 1, walk.y, walk.cost + 1));
				}
			}
			
			if(!found){
				System.out.println(0);
			}
		}
		
	}

}

Measured memory_bytes: 12000
main(n,m,p,i){for(;scanf("%d%d",&n,&m),n|m;printf("%d\n",p)){int f[12]={0};for(i=n;i--;f[p]+=n)scanf("%d%d",&n,&p);p=0;for(i=10;i>=0;p+=f[i]*i,i--)for(;f[i]&&m;)m--,f[i]--;}}

Measured memory_bytes: 412
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>

int N, A[3][3], b[10];
bool appear[3][3];

using namespace std;

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

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

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			appear[i][j] = false;
			for (int k = 0; k < N; k++) {
				if (A[i][j] == b[k]) {
					appear[i][j] = true;
				}
			}
		}
	}
	string ans = "No";
	for (int i = 0; i < 3; i++) {
		if (appear[i][0] && appear[i][1] && appear[i][2]) {
			ans = "Yes";
		}
	}
	for (int i = 0; i < 3; i++) {
		if (appear[0][i] && appear[1][i] && appear[2][i]) {
			ans = "Yes";
		}
	}
	if (appear[0][0] && appear[1][1] && appear[2][2]) {
		ans = "Yes";
	}
	if (appear[0][2] && appear[1][1] && appear[2][0]) {
		ans = "Yes";
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()
#define PB push_back
#define MP make_pair
using namespace std;
int a[10010];
int min(int n){
    if(n==1){
        return a[0];
    }else{
        return min(a[n-1],min(n-1));
    }
}
int max(int n){
    if(n==1){
        return a[0];
    }else{
        return max(a[n-1],max(n-1));
    }
}
long long sum(int n){
    if(n==1){
        return a[0];
    }else{
        return a[n-1]+sum(n-1);
    }
}
int main(){
    int n;
    cin>>n;
    REP(i,n)cin>>a[i];
    cout<<min(n)<<" "<<max(n)<<" "<<sum(n)<<endl;
}

Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  auto a=make_v<Int>(h,w);
  for(Int i=0;i<h;i++)
    for(Int j=0;j<w;j++)
      cin>>a[i][j];

  Int ans=0;
  for(Int i=0;i<h;i++)
    for(Int j=0;j<w;j++)
      ans+=a[i][j]*(i+1)*(j+1)*(h-i)*(w-j);
  
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 4704
function main(input) {
    const args = input.split('\n');
    var one = args[0].split(' ');
    var two = args[1].split(' ');

    var H = parseInt(one[0], 10);
    var W = parseInt(one[1], 10);

    var h = parseInt(two[0], 10);
    var w = parseInt(two[1], 10);

    console.log((W - w) * (H - h));


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064