akhauriyash/Code-Regression huggingface dataset:
//   __                    .__              ________ .________ ________   ______  
//  |  | __  ____    ______|  |__   __ __  /  _____/ |   ____//   __   \ /  __  \ 
//  |  |/ /_/ __ \  /  ___/|  |  \ |  |  \/   __  \  |____  \ \____    / >      < 
//  |    < \  ___/  \___ \ |   Y  \|  |  /\  |__\  \ /       \   /    / /   --   \
//  |__|_ \ \___  >/____  >|___|  /|____/  \_____  //______  /  /____/  \______  /
//       \/     \/      \/      \/               \/        \/                  \/ 

#include<bits/stdc++.h>
#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int n;

int adj[210][210];

int vis[210];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   // freopen("test.txt","r",stdin);
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            char x;
            cin>>x;
            adj[i][j] = x - '0';
        }
    }

    bool check = true;
    queue<int> temp;
    temp.push(1);
    vis[1] = 1;
    while(!temp.empty()){
        int v = temp.front();
        temp.pop();
        for(int i=1;i<=n;i++){
            if(adj[v][i]==0)continue;
            if(vis[i]!=0&&fabs(vis[v]-vis[i])!=1){
                check = false;
            }
            else if(vis[i]==0){
                vis[i] = vis[v]+1;
                temp.push(i);
            }
        }
    }
    if(check==false){
        cout<<-1;
        return 0;
    }
    int output = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            vis[j] = 0;
        queue<int> Q;
        Q.push(i);
        vis[i] = 1;
        while(!Q.empty()){
            int v = Q.front();
            Q.pop();
            for(int u =1;u<=n;u++){
                if(adj[v][u]==1&&vis[u]==0){
                    vis[u] = vis[v]+1;
                    output = max(output,vis[u]);
                    Q.push(u);
                }
            }
        }
    }
    cout<<output;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	IOS;
	 
    char c; cin>>c;
    if(c>='A' && c<='Z') cout<<'A';
    else cout<<'a';
	
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    double te;
    double dp[2][3000];
    memset(dp[0], 0, sizeof(dp[0])); 
    memset(dp[1], 0, sizeof(dp[0])); 
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i){
        scanf("%lf", &te);
        dp[i&1][0] = dp[i-1&1][0]*(1-te);
        for (int j = 1; j <= i; ++j){
            dp[i&1][j] = dp[i-1&1][j-1]*te + dp[i-1&1][j]*(1-te);
        }
    }
    te = 0;
    for (int i = (n>>1)+1; i <= n; ++i)
        te += dp[n&1][i];
    printf("%0.10lf", te);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
char s[4],t[4];
int book[30];
int ans;
int main()
{
	cin>>s;
	cin>>t;

	for(int i=0;i<3;i++) if(s[i]==t[i]) ans++;
	printf("%d",ans);
}

Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [str(input().strip()) for _ in range(N)]
    M = int(input())
    T = [str(input().strip()) for _ in range(M)]

    ans = 0
    for s in S:
        cur = sum([s == a for a in S]) - sum([s == b for b in T])
        ans = max(ans, cur)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef map<char, int> mci;

int main() {FIN
    
    int n, i, j, c;
    char s;
    mci st; st['S'] = 0, st['H'] = 1, st['C'] = 2, st['D'] = 3;
    vc ist = { 'S', 'H', 'C', 'D' };
    vvi cd(4, vi(14));
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> s >> c;
        cd[st[s]][c] = 1;
    }
    for (i = 0; i < cd.size(); i++) {
        for (j = 1; j < cd[i].size(); j++) {
            if (cd[i][j] == 0) cout << ist[i] << " " << j << "\n";
        }
    }
    
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    string x;
    cin>>x;
    int temp[30];
    for(int i=0;i<30;i++){
        temp[i]=0;
    }
    for(int i=0;i<x.length();i++){
        temp[x[i]-'a']++;
    }
    for(int i=0;i<26;i++){
        if (temp[i]%2!=0){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0279
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                int[] items = RArInt();

                if (items.Max() < 2)
                {
                    Console.WriteLine("NA");
                }
                else
                {
                    Console.WriteLine(items.Count(x => x > 0) + 1);
                }
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 42232
n,m = map(int,input().split())
d = {}

for _ in [0]*n:
  a,b = map(int,input().split())
  if a in d.keys():
    d[a] = d[a] + b
  else:
    d[a] = b

l = list(d.keys())

l.sort()
s = 0

for t in l:
  if d[t] < m:
    m -= d[t]
    s += t*d[t]
  else:
    s += t*m
    break
print(s)

Measured memory_bytes: 18652
import java.util.*;
public class Main {

		
	    public static void main(String[] args) throws java.io.IOException{
	        Scanner scan = new Scanner(System.in);
	        int n=9;
	        while(n!=0){
	        	String cl = scan.next();
	        	int am=scan.nextInt();
	        	int pm = scan.nextInt();
	        	System.out.println(cl+" "+(am+pm)+" "+(am*200+pm*300));
	        	n--;
	        	}
	        }
	     
}
	    

Measured memory_bytes: 12000
train_tujo = int(input())
train_noriho = int(input())
bus_tujo = int(input())
bus_noriho = int(input())
train_yasui = 0
bus_yasui = 0

if(train_noriho > train_tujo):
    train_yasui = train_tujo
else:
    train_yasui = train_noriho

if(bus_noriho > bus_tujo):
    bus_yasui = bus_tujo
else:
    bus_yasui = bus_noriho

print(bus_yasui + train_yasui)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    int now = 0;
    REP(i, N) {
        if (S[i] == 'A') {
            now = 1;
        } else if (now == 1 && S[i] == 'B') {
            now++;
        } else if (now == 2 && S[i] == 'C') {
            now = 0;
            ans++;
        } else {
            now = 0;
        }
    }

    cout << ans << "\n";

    return 0;
}


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

static class Program
{
    static void Main(string[] args)
    {
        //入力
        var input = Console.ReadLine().Split(' ');
        var K = int.Parse(input[0]);
        var S = int.Parse(input[1]);

        //処理
        var result = 0;
        for(var i = 0; i <= K; i++){
            for(var j = 0; j <= K; j++){
                var x = S - i - j;
                if(0 <= x && x <= K){
                    result++;
                }
            }
        }

        //出力
        Console.WriteLine(result);
    }
}


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

int main(){
    using namespace std;
    constexpr unsigned long MOD{1000000007};
    // my fast in
    constexpr unsigned long buf_size = 5UL;
    char buffer[buf_size];
    fread(buffer, 1, buf_size, stdin);
    unsigned long tmp_buf = 0;
    const auto &read = [&tmp_buf, &buffer] {
        unsigned long ret;
        from_chars(begin(buffer) + tmp_buf, end(buffer), ret);
        return ret;
    };
    // fast in kokomade
    const unsigned long S{read()};
    vector<unsigned long> k(S + 1);
    k[0] = 1;
    for(unsigned long i{3}; i <= S; ++i)k[i] = (k[i - 3] + k[i - 1]) % MOD;
    cout << k.back() << endl;
    return 0;
}

Measured memory_bytes: 3628
N = int(input())
a = [[0]]*(N)
for i in range(N):
  a[i] = list(map(int, input().split()))
DP = [[0] * 3 for _ in range(N+3)]
for i in range(N):
  for j in range(3):
    for k in range(3):
      if j != k:
        DP[i+1][k] = max(DP[i+1][k],DP[i][j]+a[i][k])
print(max(DP[N]))

Measured memory_bytes: 47356
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    int a, b;
    cin >> a >> b;
    int ans = a + b;
    if (ans >= 10)
        cout << "error" << endl;
    else
        cout << ans << endl;
}

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

Measured memory_bytes: 3556
#include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,M[MAX][MAX];
void func(){
  int minv;
  int d[MAX],color[MAX];
  for(int i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INFTY;
    int u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=GRAY;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INFTY ? -1: d[i])<<endl;
  }
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }
  int k,c,u,v;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      M[u][v]=c;
    }
  }
  func();
  return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
const int MN = 3e5+5, LOG = 60, MOD = 1e9+7;
using pii = pair<int,int>;
using ll = long long;
int cnt1[LOG];
int main () {
	int n;
	scanf ("%d",&n);
	ll a;
	for (int j = 0; j < n; j++) {
		scanf ("%lld",&a);
		for (int i = 0; i < LOG; i++) cnt1[i] += a>>i&1;
	}
	ll ans = 0;
	for (int i = 0; i < LOG; i++) ans = (ans+(1LL<<i)%MOD*(cnt1[i])%MOD*(n-cnt1[i])%MOD)%MOD;
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 100000000
using namespace std;

long H, W;
long s, r;

int main(void) {
  cin >> H >> W;

  long ans = INF;

  REP(i, 1, H) {
    long p1 = i * W;
    long p2 = (H - i) * (W / 2);
    long p3 = H * W - p1 - p2;
    long d = max(p1, max(p2, p3)) - min(p1, min(p2, p3));
    ans = min(ans, d);

    long q1 = i * W;
    long q2 = ((H - i) / 2) * W;
    long q3 = H * W - q1 - q2;
    long e = max(q1, max(q2, q3)) - min(q1, min(q2, q3));
    ans = min(ans, e);
  }

  REP(i, 1, W) {
    long p1 = i * H;
    long p2 = (W - i) * (H / 2);
    long p3 = H * W - p1 - p2;
    long d = max(p1, max(p2, p3)) - min(p1, min(p2, p3));
    ans = min(ans, d);

    long q1 = i * H;
    long q2 = ((W - i) / 2) * H;
    long q3 = H * W - q1 - q2;
    long e = max(q1, max(q2, q3)) - min(q1, min(q2, q3));
    ans = min(ans, e);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int a,b,c;
	cin >> a >> b >> c;
	map<int,int> m;
	m[a]++;
	m[b]++;
	m[c]++;
	for(auto it = m.begin();it != m.end();it++){
		if(it->second == 1){
			cout << it->first << endl;
		}
	}
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int n;
	cin >> n;
	bool flag = false;
	int d[n][2];
	for(int i=0;i<n;i++)
	cin >> d[i][0] >> d[i][1];
	for(int i=0;i<n-2;i++){
		if((d[i][0]==d[i][1])&&(d[i+1][0]==d[i+1][1])&&(d[i+2][0]==d[i+2][1]))
		flag=true;
	}
	cout<<(flag ? "Yes":"No");
	return 0;
}




Measured memory_bytes: 3632
// NK
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define ll long long
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
	int n,m,s=0; cin>>n>>m;
	int a[n];
	for (int i=0; i<n; i++) cin>>a[i], s+=a[i];
	int ch=ceil((double)s/(4*m));
	int cnt=0;
	for (int i=0; i<n; i++){
		if (a[i]>=ch) cnt++;
	}
	cout<<(cnt>=m? "Yes" : "No")<<endl;
	
	return 0;
}


Measured memory_bytes: 256
def solve():
    H, W = map(int, input().split())
    c = []
    for _ in range(H):
        c.append(list(map(int, input().split())))
        
    dp = [[0] * W for i in range(H)] 
    
    for i in range(H):
        if c[i][0] == 0: #?????£??????????????????????????£?????¢??????
            dp[i][0] = 1
    for j in range(W):
        if c[0][j] == 0:
            dp[0][j] = 1
    
    for i in range(H-1):
        for j in range(W-1):
            if c[i+1][j+1] == 0:
                dp[i+1][j+1] = min(dp[i][j], dp[i][j+1], dp[i+1][j]) + 1
                
    #print(dp)
    print(max([max(p) for p in dp]) **2 )
    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 57248
#include <bits/stdc++.h>
#define X first
#define Y second
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;

int n, q;
string s;
char t[200010];
char d[200010];

int main () {

	cin >> n >> q;
	cin >> s;
	
	for (int i = 0; i < q; i ++) {
		cin >> t[i] >> d[i];
	}
	
	int lo = 0, hi = n;
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		int pos = mid, da = 0;
		for (int i = 0; i < q; i ++) {
			if (s[pos] == t[i]) {
				if (d[i] == 'L') pos --;
				else pos ++;
			}
			
			if (pos >= n) {
				da = 1;
				break;
			}
		}
		
		if (da) hi = mid;
		else lo = mid+1;
	}
	int sol = lo;
	//cout << sol << endl;
	
	lo = 0, hi = n;
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		int pos = mid, da = 0;
		for (int i = 0; i < q; i ++) {
			if (s[pos] == t[i]) {
				if (d[i] == 'L') pos --;
				else pos ++;
			}
			
			if (pos < 0) {
				da = 1;
				break;
			}
		}
		
		if (da) lo = mid+1;
		else hi = mid;
	}
	
	sol -= lo;
	cout << sol;

	return 0;
}

Measured memory_bytes: 900
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
for i in range(N):
    s = bin(A[i])
    for j in range(1, len(s) - 1):
        if s[-j] == '0':
            ans[i] += 1
        else:
            break
print(min(ans))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;



ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}
int main(){
    cin>>N;
    vec a(N), b(N);
    rep(i,N) cin>>a[i];
    b = a;
    map<ll, ll> ps;
    rep(i,N){
        for(int j = 2; j * j <= b[i]; ++j){
            ll temp = 0;
            while(b[i] % j == 0){
                ++temp;
                b[i] /= j;
            }
            if(temp != 0) ps[j] = max(ps[j], temp);
        }
        if(b[i] != 1) ps[b[i]] = max(ps[b[i]], 1LL);
    }
    ll ans = 0, lcm = 1;
    for(P p : ps) {
        if(p.se != 0) (lcm *= fastpow(p.fi, p.se))%=MOD;
        //cout<<p.fi<<' '<<p.se<<endl;
    }
    rep(i,N) (ans += (lcm * fastpow(a[i], MOD - 2))%MOD)%=MOD;
    //cout<<lcm<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct Pr{
	ll x,y;
}l_r[210000],r_l[210000];
 
struct Te{
	int ls,rs,lv,rv;
}t[210000];
 
int n;
ll mid;
vector<Pr>V[210000];
 
void insert(int x,Pr y){
	//x sorted
	//compare y is ok
	int i=V[x].size()-1;
	if(V[x].empty()){V[x].push_back(y);return;}
	if(V[x][i].y<=y.y)return;
	while(!V[x].empty()&&V[x][i].x>=y.x)V[x].pop_back();
	V[x].push_back(y);
}
 
int dfs(int u){
	V[u].clear();
	int i,j,ltor=0,rtol=0,dt=t[u].lv+t[u].rv;
	int ls=t[u].ls,rs=t[u].rs,lv=t[u].lv,rv=t[u].rv;
	if(t[u].ls==0){
		insert(u,(Pr){0,0});
		return 1;
	}int jud=dfs(t[u].ls)&&dfs(t[u].rs);
	if(jud==0)return 0;
	//stay x/ y\
	//using combine
	for(i=V[ls].size()-1,j=V[rs].size()-1;i>=0;i--)
	{
		while(j>=0&&V[ls][i].y+V[rs][j].x+dt>mid) j--;
		if(j>=0) l_r[++ltor]=(Pr){V[ls][i].x+lv,V[rs][j].y+rv};
	}
	for(i=V[ls].size()-1,j=V[rs].size()-1;j>=0;j--)
	{
		while(i>=0&&V[ls][i].x+V[rs][j].y+dt>mid) i--;
		if(i>=0) r_l[++rtol]=(Pr){V[rs][j].x+rv,V[ls][i].y+lv};
	}
	reverse(l_r+1,l_r+ltor+1);
	reverse(r_l+1,r_l+rtol+1);
	i=1;j=1;
	while(i<=ltor&&j<=rtol){
		if(l_r[i].x<r_l[j].x){insert(u,l_r[i]);i++;}
		else {insert(u,r_l[j]);j++;}
	}while(i<=ltor){insert(u,l_r[i]);i++;}
	while(j<=rtol){insert(u,r_l[j]);j++;}
	return !V[u].empty();
}
 
int main(){
	int x,y;
	scanf("%d",&n);
	ll L=-1,R=17179869184ll;
	for(int i=2;i<=n;i++){
		scanf("%d %d",&x,&y);
		if(t[x].ls==0)t[x].ls=i,t[x].lv=y;
		else t[x].rs=i,t[x].rv=y;
	}while(L+1<R){
		mid=(L+R)>>1;
		if(dfs(1)){
			R=mid;
		}else L=mid;
	}printf("%lld\n",R);
	return 0;
}

Measured memory_bytes: 35368
/*
 * Author: luyanan
 * Created Time:  2011/8/22 12:49:25
 * File Name: k.cpp
 */
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define SZ(v) ((int)(v).size())
#define lson (t<<1)
#define rson (t<<1|1)
#define maxn 1000000

int main() 
{  
    int r,c;
    while(true)
    {
        cin>>r>>c;
        if( r == 0 && c == 0)
            break;
        if (r*c % 2 == 0)
        {
            cout<<"yes"<<endl;
        }
        else
        {
            cout<<"no"<<endl;
        }
    }    
    return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<map>
#include<iostream>
using namespace std;
int main(){
//int n,a[100001]={0};
//cin>>n;
//cout<< <<endl;
string s;
cin>>s;
int len=s.length();
for(int i=0;i<len;i++){
	if(s[i]!=s[len-i-1]){
		cout<<"No";
		return 0;
	}
}
cout<<"Yes";
return 0;
}


Measured memory_bytes: 256
import * as fs from "fs";

let [line1, line2] = fs.readFileSync("/dev/stdin", "utf8").trim().split('\n');

let [N, K] = line1.split(" ").map(Number);
let A = line2.split(" ").map(Number);

function makeOneStep(A: number[]): [boolean, number[]] {
    let B: number[] = new Array(N).fill(0);
    for(let i=0; i<N; i++) {
        let left = Math.max(0, i-A[i]), right = i+A[i];
        B[Math.max(0, left)] += 1;
        if (right+1 < N)
            B[right+1] -= 1;
    }
    let converged = true;
    for(let i=1; i<N; i++) {
        B[i] += B[i-1]
        converged = converged && B[i] == N;
    }
    return [converged, B];
}

let converged: boolean;

for(let i=0; i<K; i++) {
    [converged, A] = makeOneStep(A);
    if (converged)
        break;
}

console.log(A.map((a) => {return a.toString();}).join(" "));


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

#define ll long long int

ll dp[405][405], S[405];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    S[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        int a;
        cin >> a;
        S[i] = S[i - 1] + a;
        dp[i][i] = 0;
    }
    for (int k = 1; k < N; k++) for (int i = 1; i + k <= N; i++)
    {
        dp[i][i + k] = dp[i][i] + dp[i + 1][i + k];
        for (int j = i + 1; j < i + k; j++)
        {
            ll tmp = dp[i][j] + dp[j + 1][i + k];
            if (tmp < dp[i][i + k]) dp[i][i + k] = tmp;
        }
        dp[i][i + k] += S[i + k] - S[i - 1];
    }
    cout << dp[1][N] << '\n';
    return(0);
}

Measured memory_bytes: 1536
// Given an array of integers of size ‘n’.
// Our aim is to calculate the maximum sum of ‘k’
// consecutive elements in the array.

/*{{{*/
#include<bits/stdc++.h>
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, A, B) for (int I = (A); I <= (B); ++I)
#define repr(I, A, B) for (int I = (A); I >= (B); --I)
#define fors(I, S) for (int I = 0; S[I]; ++I)
#define get_pos(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define mp make_pair
#define pb emplace_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define in insert
#define cn count
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef set<int> si;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T, class U> void _W(const pair<T, U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
/*}}}*/

const int SIZE = 1e6 + 10;

bool isEqual(vi a, vi b) {
	rep(i, 0, sz(a) - 1) {
		if (a[i] != b[i])
			return false;
	}
	return true;
}

void solve() {
	ll a, b, k;
	R(a, b, k);
	if (k <= a) {
		W(a - k, b);
	} else if (k <= a + b) {
		W(0, b - (k - a));
	} else {
		W(0, 0);
	}
}

int main() {

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

#define MULTITEST 0
#if MULTITEST
	CASET {
		solve();
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
DPっぽいけど違うかな
しゃくとりか
和がマイナスになった時点で仕切りなおし、かな
-4 10 -11 300 -5 1  -20 500
0  10 -1　300    296                
いったん、プラスとマイナスは合算してよくて
プラスがきた場合、そのままか、これまでのプラスを引き継ぐか、で判断？
マイナスになったらリセットで。
ああ、連続するKます
ってことはシマシマとりも可能なわけか
どこかKマス続きが1箇所で、それ以外は任意の取得可能、か。
プラスの総和をだす。
そのあと、K並びを、とる場合ととらない場合とで、もっとも効率のいいものを選択
＋の配列と-の配列、それぞれで累積和用意。
とる場合、マイナスが少ないもの
とらない場合、プラスが少ないもの
が回答か
bwbbbとかbwwwbとか
*/
int main(){
  ll N,K; cin>>N>>K;
  vector<ll> P(N+1,0), M(N+1,0);
  for(int i=1; i<=N; i++){
    ll a; cin>>a;
    if(a>0)
      P[i]=a;
    else
      M[i]=a;
  }
  //累積和
  for(int i=1; i<=N; i++){
    P[i]=P[i-1]+P[i];
    M[i]=M[i-1]+M[i];
  }
  ll lose=1e14;
  for(int i=K; i<=N; i++){
    ll ptmp=P[i]-P[i-K];
    ll mtmp=M[i-K]-M[i];
    lose=min(lose, min(ptmp, mtmp));
  }
  ll ans=P[N]-lose;
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int one = 1900 * m + 100 * (n - m);
       System.out.println(one * (int)(Math.pow(2, m)));
	}
}


Measured memory_bytes: 21588
#include <iostream>
using namespace std;
int ans[10];

int main() {
	int a,b;
	while(cin >> a >> b){
		if(cin.eof())break;
	int sum = a+b;
	int j=1;
	int i=1;

	while(i){
		if(sum/=10){
			j++;
		}else{
			cout << j << "\n";
			break;
		}
	}
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if((a<=c)&&(b>=c))System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21972
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int[] a = new int[30];
		while(scan.hasNext()){
			a[scan.nextInt()-1]++;
		}
		for(int i = 0;i < 30;i++){
			if(a[i] == 0){
				System.out.println(i+1);
			}
		}
	}
}

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

#define INC(i, a, b) for(int i = a; i < b; ++i)
#define DEC(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) INC(i, 0, n)

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        std::cout << T << std::endl;
    }else{
        std::cout << F << std::endl;
    }
}

int main(){
    int n; std::cin >> n;
    ull a;
    int odd;
    
    REP(i, n){
        std::cin >> a;
        if(a % 2 == 1){
            odd++;
        }
    }
    TFprint(odd % 2 == 0, "YES", "NO");
    return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline lint ty()
	{
		lint a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;

int n,m,who[_],nex[_],ed[_]={0},stk[_],top;
lint loc[_],chaf[_]={0},anschaf[_]={0},tim;

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)loc[i]=ty();
	m=ty(),tim=ty();
	for(int i=1;i<=m;i++)who[i]=ty();

	for(int i=1;i<=n;i++)nex[i]=i,chaf[i]=loc[i]-loc[i-1];
	for(int i=1;i<=m;i++)swap(nex[who[i]],nex[who[i]+1]);
	for(int i=1;i<=n;i++)
	{
		if(ed[i])continue;
		top=0;
		for(int x=i;!ed[x];x=nex[x])stk[top++]=x,ed[x]=1;
		for(int j=0;j<top;j++)anschaf[stk[j]]=chaf[stk[(j+tim)%top]];
	}

	for(int i=2;i<=n;i++)anschaf[i]+=anschaf[i-1];
	for(int i=1;i<=n;i++)printf("%lld.0\n",anschaf[i]);

	return 0;
}


Measured memory_bytes: 5376
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
if (a * b % 2 == 0 ){
          System.out.print("Even");
}else{
          System.out.print("Odd");
}
}
}

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

int main(void){
    stack<int> s;
    deque<pair<int, int>> d;
    int sum = 0;
    char c;
    for(int i = 0; cin >> c; ++i){
        if(c == '\\') s.push(i);
        else if(c == '/' && !s.empty()){
            int j = s.top(); s.pop();
            sum += i - j;
            int a = i - j;
            while(!d.empty() && d.front().first > j){
                a += d.front().second; d.pop_front();
            }
            d.push_front(make_pair(j, a));
        }
    }
    
    cout << sum << endl;
    int len = d.size();
    cout << len;
    for(int i = len - 1; i >= 0; --i)
        cout << " " << d[i].second;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3220
import java.util.Scanner;
 
public class Main{
    public  static void main(String[] args) {
        Scanner src = new Scanner(System.in);
        int a = src.nextInt();
        int b = src.nextInt();
         if(a<b) {
             System.out.println("a < b");
         }else if(a>b){
             System.out.println("a > b");
         }else if(a==b){
             System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
using namespace std;

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

	vector<int> L(M);
	vector<int> R(M);
	for (int i = 0; i < M; ++i) {
		cin >> L[i] >> R[i];
	}
	sort(L.rbegin(), L.rend());
	sort(R.begin(), R.end());

	cout << max(1 + R[0] - L[0], 0) << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Info{

	int TIME,value;
};

struct Query{

	int L,R;
};

int table[8][3*SIZE]; //震度別累積和
double POW[8][3*SIZE]; //震度別累乗テーブル
map<int,int> MAP;
Info info[SIZE];
Query query[SIZE];


int main(){

	int N;
	scanf("%d",&N);

	vector<int> V;

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

		scanf("%d %d",&info[i].TIME,&info[i].value);
		V.push_back(info[i].TIME);
	}

	int num_query;
	scanf("%d",&num_query);

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

		scanf("%d %d",&query[i].L,&query[i].R);
		V.push_back(query[i].L);
		V.push_back(query[i].R);
	}

	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());

	for(int i = 0; i < V.size(); i++){

		MAP[V[i]] = i+1;
	}

	for(int i = 0; i <= 7; i++){
		table[i][0] = 0;
	}

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

		table[info[i].value][MAP[info[i].TIME]] = 1;
	}

	for(int i = 1; i <= V.size(); i++){
		for(int k = 0; k <= 7; k++){

			table[k][i] += table[k][i-1];
		}
	}

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

		POW[i][0] = 1;
		for(int k = 1; k <= V.size(); k++){

			POW[i][k] = POW[i][k-1]*((double)((10-i)*10)/(double)100);
		}
	}

	ll NUM = 1000000000;
	int L,R;

	double mult;

	for(int loop = 0; loop < num_query; loop++){

		L = MAP[query[loop].L];
		R = MAP[query[loop].R];

		mult = 1;
		for(int i = 0; i <= 7; i++){
			mult *= POW[i][table[i][R]-table[i][L]]; //作業の開始・終了時には地震が起こらない
		}

		printf("%.10lf\n",NUM*mult);
	}

	return 0;
}



Measured memory_bytes: 47808
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int a[100010];
int dp[100010];
int main(){
//  cout<<fixed<<setprecision(1)<<1<<endl;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		dp[i]=1e9;
		cin>>a[i];
	}
	dp[0]=0;
	for(int i=0;i<n-1;i++){
		dp[i+1]=min(dp[i+1],abs(a[i+1]-a[i])+dp[i]);
		if(i<n-2){
			dp[i+2]=min(dp[i+2],abs(a[i+2]-a[i])+dp[i]);
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 4416
package main

import "fmt"

func main() {
	var n, x, m int
	fmt.Scan(&n, &x, &m)

	ans := 0
	ss := make(map[int]int)
	done := make(map[int]int)
	a := x
	ss[1] = a
	done[a] = 1
	ans += a
	for i := 2; i <= n; i++ {
		a = a * a % m
		ss[i] = ss[i-1] + a
		if done[a] > 0 {
			l, r := done[a], i
			s := ss[r-1] - ss[l-1]
			rem := n - r + 1
			sl := r - l
			ans += s * (rem / sl)

			x := rem % sl
			ans += ss[l+x-1] - ss[l-1]
			break
		}
		done[a] = i
		ans += a
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7660
mod = 10**9+7
n,a,b = map(int,input().split())
ans = pow(2,n,mod)-1
comb1 = 1
for i in range(n-a+1,n+1):
    comb1 *= i
    comb1 %= mod
for i in range(1,a+1):
    comb1 *= pow(i,mod-2,mod)
    comb1 %= mod

comb2  = 1
for i in range(n-b+1, n+1):
    comb2 *= i
    comb2 %= mod
for i in range(1,b+1):
    comb2 *= pow(i,mod-2,mod)
    comb2 %= mod

ans -= (comb1+comb2)
ans %= mod
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
  int N, W, H, x, y, S, T, cnt_tree, max_tree;
  while(1){
    cin>>N;
    if(!N) return 0;
    cin>>W>>H;
    int tree[100][100] = {};
    for(int i=0;i<N;i++){
      cin>>x>>y;
      tree[x][y] = 1;
    }
    max_tree = 0;
    cin>>S>>T;
    for(int i=1;i<=W-S+1;i++){
      for(int j=1;j<=H-T+1;j++){
	cnt_tree = 0;
	for(int k=i;k<i+S;k++){
          for(int l=j;l<j+T;l++){
	    cnt_tree += tree[k][l];
	  }
	}
	if(max_tree < cnt_tree) max_tree = cnt_tree;
      }
    }
    cout<<max_tree<<endl;
  }
}



Measured memory_bytes: 3096
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx, dy = ty - sy;
	string res = "";
	rep(i, dx) res += "R";
	rep(i, dy) res += "U";
	rep(i, dx) res += "L";
	rep(i, dy) res += "D";

	res += "D";
	rep(i, dx + 1) res += "R";
	rep(i, dy + 1) res += "U";
	res += "L";
	res += "U";
	rep(i, dx + 1) res += "L";
	rep(i, dy + 1) res += "D";
	res += "R";

	cout << res << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a,ll b);

int main(){
  int A,B,C,X,Y;
  int ans = 0;
  cin >> A >> B >> C >> X >> Y;
  if(A + B > 2*C){
    int Ccount = min(X,Y);
    ans += min(X,Y)*2*C;
    X -= Ccount;
    Y -= Ccount;
  }
  if(A<2*C){
    ans += A*X;
  }
  else{
    ans += 2*C*X;
  }
  if(B<2*C){
    ans += B*Y;
  }
  else{
    ans += 2*C*Y;
  }
  cout << ans << endl;
}







Measured memory_bytes: 256
// 一回一回探索してもまあよさそう
// なぜか大量にWAをくらう あってるのはサンプルくらい 地獄
// lcm使ってたのが駄目っぽい（それはそう

package main

import "fmt"

type Data struct {
	C, S, F int
}

func main() {
	var N int
	fmt.Scan(&N)
	datas := make([]Data, N-1)
	for i := 0; i < N-1; i++ {
		var c, s, f int
		fmt.Scan(&c, &s, &f)
		datas[i] = Data{C: c, S: s, F: f}
	}
	for i := 0; i < N-1; i++ {
		time := datas[i].S + datas[i].C
		for j := i + 1; j < N-1; j++ {
			// ここについたときに経過してる時間 vs 次の出発
			// 出発前 -> 始発の時間にする
			// 出発済 -> 次のやつ
			if datas[j].S >= time {
				time = datas[j].S + datas[j].C
			} else {
				// いまの時間を超える最小のF これは題意的にlcmでいけそう -> いけなさそう？
				// じゃ愚直にかんがえてみる
				x := (time / datas[j].F)
				if time%datas[j].F != 0 {
					x += 1
				}
				x *= datas[j].F
				// fmt.Printf("今の時間 %d よりあとで最近の出発時間 %d\n", time, x)
				time = x + datas[j].C
			}
		}
		fmt.Println(time)
	}
	fmt.Println(0)
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string o, e;
    cin >> o >> e;

    int size;
    if(o.size() < e.size()) size = e.size();
    else size = o.size();

    for(int i = 0; i < size; i++){
        if(i < o.size()) cout << o[i];
        if(i < e.size()) cout << e[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace lean
{
    class Program
    {
        static void Main()
        {
            string[] a = Console.ReadLine().Split();
            Console.WriteLine(a[2] +" "+ a[0] + " "+ a[1]);
        }
    }
}

Measured memory_bytes: 13140
N, M = map(int, input().split())
ac = [0] * (N+1)  
wa = [0] * (N+1)
ans= [0, 0]

for i in range(M):
    p, s = input().split()
    p = int(p)-1
    if ac[p] == 1:
        continue
    elif s == "WA":
        wa[p] += 1
    else:
        ans[0] += 1
        ans[1] += wa[p]
        ac[p] = 1
print(*ans)


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

int main() {
  int N;
  int p=0;
  int w=0;
  int g=0;
  int y=0;
  cin >>N;
  for(int i=0; i<N-1; i++){
    string col;
    cin>>col;
    if(col=="P"){
      p++;
    }
    else if(col=="W"){
      w++;
    }
    else if(col=="Y"){
      y++;
    }
    else if(col=="G"){
      g++;
    }
    else{
      cout<<"error"<<endl;
      break;
    }
  }
 if(p==0||w==0||y==0||g==0){
   cout<<"Three"<<endl;
 }
 else{
   cout<<"Four"<<endl;
 }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
template<class T> inline bool chmax(T& a, T b){if(a<b) {a=b; return 1;} return 0; }
template<class T> inline bool chmin(T& a, T b){if(a>b) {a=b; return 1;} return 0; }
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

ll N;
ll W,w[110],v[110];

ll dp[110][100100];
int main(){
	//乱数srand((unsigned)time(NULL));
	ll N;cin>>N;
	vll X(N); rep(i,N) cin>>X[i];
	ll ans=INF;
	rep(i,100){
		ll sum=0;
		rep(j,N){
			sum+=(X[j]-(i+1))*(X[j]-(i+1));
		}
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
n, k, q = [int(i) for i in input().split()]
a = [None for i in range(q)]
for i in range(q):
  a[i] = int(input())

pt = [0 for i in range(n)]

for i in range(q):
  pt[a[i] - 1] += 1

th = q - k

result = list(map(lambda x: 'Yes' if x > th else 'No', pt))
print('\n'.join(result))


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll ans=0;
    ll cnt=0;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=1; i<n; i++) {
        for(ll j=cnt+i-1; j<n; j++) {
            if(a[j]!=i){
                cnt++;
            }else if (a[j]==i){
                break;
            }
        }
    }
    ans = cnt==n?-1:cnt;

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


Measured memory_bytes: 1792
import Control.Monad
import Data.Bool
import Data.List

readInt = readLn :: IO Int
readInts = map read . words <$> getLine :: IO [Int]
readNInts = flip replicateM readInts

main :: IO ()
main = do
    [a, b, k] <- readInts
    print $ (!!(k - 1)) $ reverse $ nub $ intersect (factors a) (factors b)

factors :: Int -> [Int]
factors n = filter (\x -> n `mod` x == 0) [1..n]


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

int main(){

  long long int a,b,c,r,s;

  while(cin >> a >> b){

    s=a*b;

    while(b!=0){

      c=a/b;
      r=a%b;
      a=b;
      b=r;

    }

    cout << a << ' ' << s/a <<  endl;
  }

  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

vector<vector<char>> MAP(22,vector<char>(22,'#'));
vector<vector<int>> dist(22, vector<int>(22, -1));

void bfs(int row, int col){

    queue<int> qR;
    queue<int> qC;
    qR.push(row); qC.push(col);

    int axisR[4]={1,0,-1,0};
    int axisC[4]={0,1,0,-1};
    int cnt=0;
    dist[row][col]=0;

    while(!qR.empty()){
        int R=qR.front(); qR.pop();
        int C=qC.front(); qC.pop();

        for (int i = 0; i < 4; ++i) {
            int tmpd = dist[R+axisR[i]][C+axisC[i]];
            if(MAP[R+axisR[i]][C+axisC[i]]!='#' && dist[R+axisR[i]][C+axisC[i]]==-1){
                dist[R+axisR[i]][C+axisC[i]] = dist[R][C]+1;
                qR.push(R+axisR[i]); qC.push(C+axisC[i]);
            }
        }
    }
}

int search(){
    int ret=0;
    for (int i = 1; i <=20; ++i) {
        for (int j = 1; j <= 20; ++j) {
            ret = max(ret, dist[i][j]);
        }
    }
    return ret;
}

int main(){

    int H,W; cin>>H>>W;

    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            cin>>MAP[i][j];
        }
    }

    int ans = 0;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            vector<vector<int>> init(22, vector<int>(22, -1));
            dist = init;
            if(MAP[i][j]=='.'){
                bfs(i,j);
                ans = max(ans,search());
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func nextInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func main() {
	n := nextInt()
	dic := map[int]struct{}{}

	for range make([]struct{}, n) {
		a := nextInt()
		if _, in := dic[a]; !in {
			dic[a] = struct{}{}
		} else {
			delete(dic, a)
		}
	}

	fmt.Println(len(dic))
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    string s, p;
    while(cin >> s >> p){
        bool c;
        s += s;
        rep(i,s.size()){
            c = true;
            rep(j,p.size()){
                if(s[i + j] != p[j]){
                    c = false;
                    break;
                }
            }
            if(c) break;
        }
        if(c) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1184