akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_VN 100000

using namespace std;
typedef pair<int, int> ipair;

ipair odd_nums[MAX_VN], even_nums[MAX_VN];

int main(int argc, char **argv) {
    int N;
    cin >> N;

    for(int i = 0; i < MAX_VN; ++i)
        odd_nums[i].second = even_nums[i].second = i;

    for(int i = 0; i < N; ++i) {
        int v;
        cin >> v;
        if(i % 2 == 1)
            odd_nums[v].first--;
        else
            even_nums[v].first--;
    }
    sort(odd_nums, odd_nums + MAX_VN);
    sort(even_nums, even_nums + MAX_VN);
    
    int res;
    if(even_nums[0].second != odd_nums[0].second)
        res = N - (-odd_nums[0].first) - (-even_nums[0].first);
    else {
        int res1 = N - (-odd_nums[0].first) - (-even_nums[1].first);
        int res2 = N - (-odd_nums[1].first) - (-even_nums[0].first);
        res = min(res1, res2);
    }

    cout << res << endl;
}

Measured memory_bytes: 1792
/**
*    created: 21.06.2020 00:34:02
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

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

    int n;
    cin >> n;
    set<int> d;
    int tmp;
    rep(i,n) {
        cin >> tmp;
        d.insert(tmp);
    }
    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int a, b;cin >> a >> b;
  if(a < b){
      cout << "a < b" << endl;
  }else if(a > b){
      cout << "a > b" << endl;
  }else{
      cout << "a == b" << endl;
  }
}


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

void main() {
    auto S = readln.chomp;
    auto N = S.length.to!int;

    auto next = new int[][](26, N);
    foreach (i; 0..26) fill(next[i], -1);

    foreach (c; 0..26) {
        for (int i = N - 1; i >= 0; i--) {
            if (S[i] - 'a' == c) {
                next[c][i] = i + 1;
            } else if (i < N - 1) {
                next[c][i] = next[c][i+1];
            }
        }
    }

    auto mem = new Tuple!(int, int)[](N);
    fill(mem, tuple(1 << 29, 1 << 29));

    Tuple!(int, int) dfs(int n) {
        if (n == -1) return tuple(0, -1);
        if (n >= N) return tuple(1, -1);
        if (mem[n][0] != 1 << 29) return mem[n];
        auto ret = tuple(1 << 29, 1 << 29);
        foreach (i; 0..26) {
            auto t = dfs(next[i][n]);
            if (t[0] < ret[0]) ret = tuple(t[0], i);
        }
        mem[n] = tuple(ret[0] + 1, ret[1]);
        return mem[n];
    }

    dfs(0);
    string ans = "";

    for (int i = 0; i != -1;) {
        if (mem[i][1] == -1) break;
        char c = (mem[i][1].to!char + 'a').to!char;
        ans ~= c;
        i = next[c - 'a'][i];
    }

    ans.writeln;
}


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

vector<vector<int>> adjlist;
ll memo[100005][2];
int n;
const int MOD = 1e9+7;
ll solve(int v,int p, int f){
	if(memo[v][f]!=-1)
	    return memo[v][f];
	ll ans = 1;
	for(int u : adjlist[v]){
		if(u == p)
		    continue;
		if(f == 0)
		    ans = (ans*(solve(u,v,0) + solve(u,v,1)))%MOD;
		else{ 
		    ans =  (ans*solve(u,v,0))%MOD;
		}
	}

	return memo[v][f] = ans;

}

int main(){
    cin >> n;
	memset(memo,-1,sizeof(memo));
	adjlist.resize(n+1);
	for(int i = 0; i < n-1; i++){
		int u,v;
		cin >> u >>v;
		adjlist[u].push_back(v);
		adjlist[v].push_back(u);
	}

	ll ans = (solve(1, -1, 0)+solve(1, -1, 1))%MOD;
	cout << ans;

	return 0;

}

Measured memory_bytes: 15616
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    ll res = mod_pow(x * x % mod, n / 2);
    if (n & 1) res = res * x % mod;
    return res;
}

ll com(ll a, ll b) {
    if (a < b) return 0;
    ll res = 1;
    for (ll i = 0; i < b; i++) {
        res *= (a - i);
        res %= mod;
        res *= mod_pow(b - i, mod - 2);
        res %= mod;
    }
    return res;
}

int main() {
    int n,a,b; cin >> n >> a >> b;
    ll ans = mod_pow(2, n) - 1;
    ans %= mod;
    ans -= com(n,a);
    ans -= com(n,b);
    ans += 2 * mod;
    ans %= mod;
    cout << ans << "\n";
}

Measured memory_bytes: 384
package main

import (
	"fmt"
)

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

	if d == 0 {
		if n != 100 {
			fmt.Println(n)
		} else {
			fmt.Println(n + 1)
		}
	} else if d == 1 {
		if n != 100 {
			fmt.Println(n * 100)
		} else {
			fmt.Println(n*100 + 100)
		}
	} else if d == 2 {
		if n != 100 {
			fmt.Println(n * 10000)
		} else {
			fmt.Println(n*10000 + 10000)
		}
	}
}


Measured memory_bytes: 512
import math
def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
def koch(n,x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    sx = (2*x1+x2)/3
    sy = (2*y1+y2)/3
    tx = (x1+2*x2)/3
    ty = (y1+2*y2)/3
    ux = (tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy = (tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    koch(n-1,x1,y1,sx,sy)
    koch(n-1,sx,sy,ux,uy)
    koch(n-1,ux,uy,tx,ty)
    koch(n-1,tx,ty,x2,y2)
    
n=int(input())
koch(n,0,0,100,0)
plot(100,0)


    


Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



long long maxSubArray(long long a[], int sze)
{
   long long max_so_far = 0, max_ending = 0;
   for (int i = 0; i < sze; i++)
   {
       max_ending = max_ending + a[i];
       if (max_ending < 0)
           max_ending = 0;
       else if (max_so_far < max_ending)
           max_so_far = max_ending;
   }
   return max_so_far;
}




int32_t main()
{ 
   
      int n;
      cin>>n;
      
      if(n%10 !=1 && n%10 !=3 && n%10!=7 && n%10!=9)
      cout<<-1<<"\n";
      
      
      else
      {
          int ans=-1;
          map <int,int> m;
          int rem=0;
          int i=1;
          while(1)
          {
              rem=(rem*10+7%n)%n;
              if(rem==0)
              {
                  ans=i;
                  break;
              }
              else
               m[rem]++;
               
              if(m[rem]>1)
              {
                  ans=-1;
                  break;
              }
              i++;
          }
          
          cout<<ans<<"\n";
          
      
      
       
    }
    return 0;
	}

Measured memory_bytes: 66064
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        s: Chars,
    }

    let mut childrens = vec![0; s.len()];

    // right
    for i in 0..s.len()-1 {
        let str = s[i..=i+1].iter().collect::<String>();
        
        if &str == "RL" {
            childrens[i] += 1;
            childrens[i+1] += 1;

            let mut right_index = 1;
            loop {
                right_index += 1;
                if i + right_index >= s.len() { break; }
                if s[i+right_index] == 'R' { break; }

                if right_index % 2 == 0 {
                    childrens[i] += 1;
                } else {
                    childrens[i+1] += 1;
                }
            }

            let mut left_index = 0;
            loop {
                left_index += 1;
                if left_index > i { break; }
                if s[i-left_index] == 'L' { break; }

                if left_index % 2 == 0 {
                    childrens[i] += 1;
                } else {
                    childrens[i+1] += 1;
                }
            }
        }
    }

    println!("{}", childrens.iter().join(" "));
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 3268
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>

using namespace std;

double sq(double x){return x*x;}


int main(){
	int a[4],b[4];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
		int hit = 0,brow = 0;
		for (int i = 0; i < 4; i++)
		{
			if(a[i] == b[i])
				hit++;
			else if(find(a,a+4,b[i]) != a+4)
				brow++;
		}

		printf("%d %d\n",hit,brow);
	}

	return 0;
}

Measured memory_bytes: 0
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var maxv = 0; var maxid = 21;
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var v = int.Parse(line[1]);
            if (v > maxv) { maxv = v; maxid = a; }
            else if (v == maxv && a < maxid) maxid = a;
        }
        Console.WriteLine("{0} {1}", maxid, maxv);
    }
}

Measured memory_bytes: 9196
N=int(input())
S=input()
from collections import Counter
C=Counter(S)
ans=C['R']*C['G']*C['B']
for i in range(N):
    for j in range(i+1,N):
        if j+(j-i) >= N: break
        if S[i] != S[j] and S[j] != S[j+(j-i)] and S[i] != S[j+(j-i)]:
            ans-=1
print(ans)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int K,X;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>X;
	if(K*500>=X) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it!= v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >> (istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

random_device seed_gen; mt19937_64 mtrand(seed_gen());
#define MOD 1000000007
//////////////////////////////////////////

int main(){
  ins(s);
  if(s.size() < 4) die("No");
  s.resize(4);
  string t = "YAKI";
  die( s == t ? "Yes" : "No" );
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N; cin >> N; // 配列サイズ
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i]; // a の入力

  // 累積和
  vector<int> s(N+1, 0); // s[0] = 0 になる
  unordered_map<int,int> mp;
  mp[0]++;
  for (int i = 0; i < N; ++i){
    s[i+1] = s[i] + a[i];
    mp[s[i+1]]++;
  }
  int ans=0;
  for(auto i:mp){
    ans+=i.second*(i.second-1)/2;
  }
  answer
  return 0;
}


Measured memory_bytes: 11592
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        int a = Integer.parseInt(input[1]);
        int b = Integer.parseInt(input[2]);
        
        out.println(Math.min(a * n, b));
        out.close();
        
    }
}

Measured memory_bytes: 32736
// ???????????????????????????????????????????£???????
// ?????\???????????¨????????§O(n^2)
#include <bits/stdc++.h>
using namespace std;
int N, A[100], res;

void Out() {
	cout << A[0];
	for (int i = 1; i < N; i++)
		cout << ' ' << A[i];
	cout << endl;
}

void BubbleSort() {
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = N - 1; i >= 0; i--) {
			if (A[i] < A[i - 1]) {
				int tmp = A[i];
				A[i] = A[i - 1];
				A[i - 1] = tmp;
				flag = true;
				res++;
			}
		}
	}
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];
	BubbleSort();
	Out();
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3080
n = int( raw_input( ) )

mi = int( raw_input( ) )
profit = 0 - 1000000000
n -= 1
i = 0
while i < n:
	num = int( raw_input( ) )
	
	diff = num - mi
	if profit < diff:
		profit = diff

	if num < mi:
		mi = num
	i += 1

print( profit )

Measured memory_bytes: 4208
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
	if (a < 0) {
		cout << c*-a + d + b*e << endl;
	}
	else cout << (b- a)*e << endl;
}

Measured memory_bytes: 3108
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		int N1 = A.length();
		int N2 = B.length();
		if(N1 > N2) {
			System.out.println("GREATER");
		} else if(N1 < N2) {
			System.out.println("LESS");
		} else {
			for(int i = 0 ; i < N1 ; i++) {
				if(A.charAt(i) > B.charAt(i)) {
					System.out.println("GREATER");
					break;
				} else if(A.charAt(i) < B.charAt(i)) {
					System.out.println("LESS");
					break;
				} else {
					System.out.println("EQUAL");
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 23764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
n=len(s)
ones=""
zers=""
counto,countz=0,0
for i in range(n):
    if i%2==0:
        ones+="1"
        zers+="0"
    else:
        ones+="0"
        zers+="1"
for i in range(n):
    if ones[i]!=s[i]:
        counto+=1
    if zers[i]!=s[i]:
        countz+=1
print(min(countz,counto))

Measured memory_bytes: 3700
#include<stdio.h>

#define MAX 100005
#define NIL -1

struct Node_struct{

  int p, l, r;   /* p:親　l:一番左の子　r:右の兄弟 */
};
typedef struct Node_struct Node;

Node T[MAX];
int D[MAX], H[MAX], S[MAX], DEG[MAX];

void print(int u){

  int i;
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", u, T[u].p, S[u], DEG[u], D[u], H[u]);

  if(T[u].p == NIL)
    printf("root");

  else if(T[u].l == NIL && T[u].r == NIL)
    printf("leaf");

  else printf("internal node");

  printf("\n");
}

void calcDepth(int u, int p){

  D[u] = p;
  if(T[u].l != NIL)
    calcDepth(T[u].l, p + 1);

  if(T[u].r != NIL)
    calcDepth(T[u].r, p + 1);
}

int height(int u){

  int hl = 0, hr = 0;

  if(u == NIL) return 0;

  hl = height(T[u].l) + 1;
 hr = height(T[u].r) + 1;

  if(hl > hr) {
    H[u] = hl - 1;
    return hl;
  }
  else {
    H[u] = hr - 1;
    return hr;
  }
}

int main(){

  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
    T[i].p = T[i].l = T[i].r = S[i] = NIL;

  for(i = 0; i < n; i++){
scanf("%d", &id);

    for(j = 0, sib = NIL; j < 2; j++){
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0)
        T[id].l = child;
      else
        T[id].r = child;
    }
  }

  for(i = 0; i < n; i++){

    S[T[i].l] = T[i].r;
    S[T[i].r] = T[i].l;
  }

  for(i = 0; i < n; i++){

    if(T[i].l != NIL && T[i].r != NIL)
      DEG[i] = 2;
    else if(T[i].l != NIL || T[i].r != NIL)
      DEG[i] = 1;
   else
      DEG[i] = 0;
  }

  for(i = 0; i < n; i++){

    if(T[i].p == -1)
      root = i;
  }

  calcDepth(root, 0);
  height(root);

  for(i = 0; i < n; i++)
    print(i);

  return 0;
}



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

int main() {
  long int A,B;
  A=0;
  long int N;
  cin >> N;

  vector<string>t(N);
  for(long int i=0;i<N;i++){
    string u;
    cin >> u;
    sort(u.begin(),u.end());
    t.at(i)=u;
  }
  sort(t.begin(),t.end());
    long int i;
  i=1;
      long long a;
  while(i<N){

    a=1;
    while(t.at(i)==t.at(i-1)){
      i++;
      a++;
      if(i>=N){
       break; 
      }
    }
    A=A+(a*(a-1)*0.5);
    i++;
  }
  
cout << A << endl;

}




Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  vector<long long> xxx(n);
  vector<long long> yyy(n);
  vector<long long> hhh(n);
  
  int a,b,c;
  for(int i = 0 ; i < n ; i++){
    cin >> xxx.at(i) >> yyy.at(i) >> hhh.at(i);
    if(hhh.at(i) >= 1){
      a = xxx.at(i);
      b = yyy.at(i);
      c = hhh.at(i);
    }
  }

  bool jad = false;
  for(int x = 0 ; x <= 100 ; x++){
    for(int y = 0 ; y <= 100 ; y++){
      
      long long h = abs(x-a)+abs(y-b)+c;
      for(int i = 0 ; i < n ; i++){
        
        if( max( h-abs(x-xxx.at(i))-abs(y-yyy.at(i)) , 0ll) != hhh.at(i)){
          break;
        }
        if(i == n-1){
          cout << x << " " << y << " " << h << endl;
          jad = true;
          break;
        }
      }
      if(jad){
        break;
      }
    }
    if(jad){
      break;
    }
  }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
typedef struct {
    int d0;
    int d1;
    int d2;
    int d3;
    int d4;
    int d5;
}DICE;
 
int DiceRoll(DICE[], int);
void Dice(char p, DICE[], int);
int Count(DICE[], int);
 
int main() {
    DICE d[100];
    int i = 0, flg = 0, n;
    char str[2][4] = { "Yes" ,"No" };
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d%d%d%d%d%d", &d[i].d0, &d[i].d1, &d[i].d2, &d[i].d3, &d[i].d4, &d[i].d5);
    for (i = 1; flg == 0&&i < n; i++) flg = DiceRoll(d, i);
    if (flg) { printf("No\n"); return 0; }
    printf("Yes\n");
    return 0;
}
 
int DiceRoll(DICE d[], int i)
{
    int j, l, iSum, jSum;
     
        for (j = 0; j < i; j++) {
            iSum = d[i].d0 + d[i].d1 + d[i].d2 + d[i].d3 + d[i].d4 + d[i].d5;
            jSum = d[j].d0 + d[j].d1 + d[j].d2 + d[j].d3 + d[j].d4 + d[j].d5;
            if (jSum == iSum) {
            if (d[j].d5 == d[i].d0) Dice('N', d, j), Dice('N', d, j);
            else if (d[j].d1 == d[i].d0) Dice('N', d, j);
            else if (d[j].d4 == d[i].d0) Dice('S', d, j);
            else if (d[j].d2 == d[i].d0) Dice('W', d, j);
            else if (d[j].d3 == d[i].d0) Dice('E', d, j);
            if (d[j].d0 == d[i].d0) {
                for (l = 0; l < 4; l++) {
                    if (d[j].d1 == d[i].d1)if (d[i].d2 == d[j].d2&&d[i].d3 == d[j].d3&&d[i].d4&&d[j].d4&&d[i].d5 == d[j].d5)  return 1;
                    Dice('L', d, j);
                }
            }
            if (Count(d, i) >= 10 && Count(d, j) >= 10) return 1;
        }
    }
    return 0;
}
 
void Dice(char p, DICE d[], int n) {
    int tmp;
    if (p == 'S') { tmp = d[n].d0; d[n].d0 = d[n].d4; d[n].d4 = d[n].d5; d[n].d5 = d[n].d1; d[n].d1 = tmp; }
    if (p == 'W') { tmp = d[n].d0; d[n].d0 = d[n].d2; d[n].d2 = d[n].d5; d[n].d5 = d[n].d3; d[n].d3 = tmp; }
    if (p == 'E') { tmp = d[n].d0; d[n].d0 = d[n].d3; d[n].d3 = d[n].d5; d[n].d5 = d[n].d2; d[n].d2 = tmp; }
    if (p == 'N') { tmp = d[n].d0; d[n].d0 = d[n].d1; d[n].d1 = d[n].d5; d[n].d5 = d[n].d4; d[n].d4 = tmp; }
    if (p == 'L') { tmp = d[n].d1; d[n].d1 = d[n].d3; d[n].d3 = d[n].d4; d[n].d4 = d[n].d2; d[n].d2 = tmp; }
}
 
int Count(DICE d[], int n) {
    int cnt = 0;
    if (d[n].d0 == d[n].d1)++cnt;
    if (d[n].d0 == d[n].d2)++cnt;
    if (d[n].d0 == d[n].d3)++cnt;
    if (d[n].d0 == d[n].d4)++cnt;
    if (d[n].d0 == d[n].d5)++cnt;
    if (d[n].d1 == d[n].d2)++cnt;
    if (d[n].d1 == d[n].d3)++cnt;
    if (d[n].d1 == d[n].d4)++cnt;
    if (d[n].d1 == d[n].d5)++cnt;
    if (d[n].d2 == d[n].d3)++cnt;
    if (d[n].d2 == d[n].d4)++cnt;
    if (d[n].d2 == d[n].d5)++cnt;
    if (d[n].d3 == d[n].d4)++cnt;
    if (d[n].d3 == d[n].d5)++cnt;
    if (d[n].d4 == d[n].d5)++cnt;
    return cnt;
}


Measured memory_bytes: 2084
W,a,b = map(int,input().split())

min1 = W + a
min2 = W + b
if b > a:
	if b - min1 > 0 :
		print(b-min1)
	else:
		print(0)
if a > b:
	if a - min2 > 0 :
		print(a-min2)
	else:
		print(0)
if a == b:
	print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	int left = 0, right = 0;
	int res = 0;

	for(int i = 1; i <= n+1; i++) {
		left += i - 1;
		right += n - (i - 1);
		if(i >= k) {
			res += (right - left + 1);
			res %= MOD;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3656
n = int(input())
a = list(map(str, (range(1, 10))))
total = a[:]
cnt = 9
while cnt < n:
    new = []
    for i in a:
        if i[-1] == "0":
            new.append(i + "0")
            new.append(i + "1")
            cnt += 2
            if cnt >= n:
                break
        elif i[-1] == "9":
            new.append(i + "8")
            new.append(i + "9")
            cnt += 2
            if cnt >= n:
                break
        else:
            new.append(i + str(int(i[-1]) -1))
            new.append(i + str(int(i[-1])))
            new.append(i + str(int(i[-1]) + 1))
            cnt += 3
            if cnt >= n:
                break
    total += new[:]
    a = new[:]
                
print(total[n-1])

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

using namespace std;

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

  size_t n;
  cin >> n;

  vector <int> v;
  copy_n (istream_iterator <decay_t <decltype (v.front ())>> (cin), n, back_inserter (v));

  sort (v.begin (), v.end ());

  auto ans_min = v [n / 2 - 1];
  auto ans_max = v [n / 2];
  cout << ans_max - ans_min << endl;
}


Measured memory_bytes: 892
import itertools
def main():
  a,b,c,d = map(int,input().split())
  ans = False
  if abs(c-a) <= d:
    ans = True
  elif abs(a-b) <= d and abs(b-c) <= d:
    ans = True
  else:
    ans = False
#  print("Yes" if abs(c-a) <= d else"No")
  print("Yes" if ans else "No")
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
  
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder st = new StringBuilder();
          
        int i = 1;
          
        while(true){
            int line = Integer.parseInt(br.readLine());
            if(line == 0){
                break;
            }
              
            st.append("Case ").append(i).append(": ").append(line).append("\n");
            i++;
        }
          
        System.out.print(st);
    }
}

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

int main(){
    string o, e; cin >> o >> e;

    rep(i,e.size()){
        cout << o[i] << e[i];
    }
    if(o.size() != e.size()){
        cout << o[o.size()-1];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=105;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int a[N][N];
int main()
{
    std::ios::sync_with_stdio(false);
    int w,h,n;
    cin>>w>>h>>n;
    int ss=h,xx=0,zz=0,yy=w;
    for(int i=1; i<=n; i++)
    {
        int x,y,a;
        cin>>x>>y>>a;
        if(a==1)
        {
            zz=max(zz,x);
        }
        if(a==2)
        {
            yy=min(yy,x);
        }
        if(a==3)
        {
            xx=max(xx,y);
        }
        if(a==4)
        {
            ss=min(ss,y);
        }
    }
    if(ss<=xx||yy<=zz)
        cout<<0<<endl;
    else
        cout<<(ss-xx)*(yy-zz)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


//System.out.println();
public class Main implements Runnable { //クラス名はMain

    public static void main(String[] args) {
    	Thread.setDefaultUncaughtExceptionHandler((t,e)->System.exit(1));
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
        String s = sc.next();
        String rep = s.replaceAll(".", "x");
        System.out.println(rep);
    }
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 28624
#include<iostream>

using namespace std;

int A1, A2, A3;

int main() {
	cin >> A1 >> A2 >> A3;
	if (A1 + A2 + A3 >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  long N, p = 1, t = 10*10*10*10*10*10*10*10*10+7;
  cin >> N;
  for(int i = 1; i <= N; i++){
    p *= i;
    p %= t;
  }
  cout << p;
  return 0;
}

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

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }

const int MAX = 24;
int n;
int x[MAX], y[MAX], r[MAX], c[MAX];
int under[MAX];
short memo[1 << MAX];

short dfs(int rest) {
	if(memo[rest] >= 0)
		return memo[rest];

	int can = rest;
	for(int i = 0; i < n; ++i)
		if(rest & (1 << i))
			can &= ~under[i];

	int res = 0;
	for(int i = 0; i < n; ++i) {
		if(can & (1 << i)) {
			const int tmp = rest & (~(1 << i));
			for(int j = i + 1; j < n; ++j) {
				if(c[i] == c[j] && (can & (1 << j))) {
					const int next = tmp & (~(1 << j));
					chmax(res, dfs(next) + 2);
				}
			}
		}
	}

	return memo[rest] = res;
}

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

	while(cin >> n, n) {
		for(int i = 0; i < n; ++i)
			cin >> x[i] >> y[i] >> r[i] >> c[i];

		memset(under, 0, sizeof(under));
		for(int i = 0; i < n; ++i)
			for(int j = i + 1; j < n; ++j)
				if(hypot(x[i] - x[j], y[i] - y[j]) < r[i] + r[j])
					under[i] |= (1 << j);

		memset(memo, -1, sizeof(memo));
		cout << dfs((1 << n) - 1) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 33980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    ll n;
    string s;
    cin >> n >> s;
    ll a[n][4];
    
    a[0][0] = 0;
    a[0][1] = 0;
    a[0][2] = 0;
    a[0][3] = 0;
    for (ll i = 1; i < n; i++) {
        if (s[i] == 'E') {
            a[0][2]++;
        }else{
            a[0][3]++;
        }
    }
    /*
    for (int j = 0; j < 4; j++) {
        cout << a[0][j] << ' ';
    }
    cout << endl;
    */
    
    

    ll min = a[0][2];
    
    
    ll cnt;
    
    
    
    for (ll i = 1; i < n; i++) {
        if (s[i-1] == 'E') {
            a[i][0] = a[i-1][0] + 1;
            a[i][1] = a[i-1][1];
        }else{
            a[i][1] = a[i-1][1] + 1;
            a[i][0] = a[i-1][0];
        }
        if (s[i] == 'E') {
            a[i][2] = a[i-1][2] - 1;
            a[i][3] = a[i-1][3];
        }else{
            a[i][3] = a[i-1][3] - 1;
            a[i][2] = a[i-1][2];
        }
        
        
        
        if (s[i] == 'E') {
            if (i == n - 1) {
                cnt = a[i][1];
            }else{
                cnt = a[i][1] + a[i][2];
            }
            if(cnt < min){
                min = cnt;
            }
        }else{
            if (i == n - 1) {
                cnt = a[i][1];
            }else{
                cnt = a[i][1] + a[i][2];
            }
            if(cnt < min){
                min = cnt;
            }
        }
        
        /*
        for (int j = 0; j < 4; j++) {
            cout << a[i][j] << ' ';
        }
        cout << cnt << endl;
         */
    }
    cout << min << endl;
    return 0;
}

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

using namespace std;


int get_diameter_of_tree(vector<vector<int>>& adj_list) {
    function<pair<int, int> (int, int)> diam_and_longest = [&](int i, int parent) {
        int longest_1 = -1, longest_2 = -1;
        int diam = 0;
        for (int j : adj_list[i]) {
            if (j == parent) continue;
            auto p = diam_and_longest(j, i);
            diam = max(diam, p.first);
            int tmp_long = p.second;
            if (tmp_long >= longest_1) {
                longest_2 = longest_1;
                longest_1 = tmp_long;
            } else if (tmp_long >= longest_2) {
                longest_2 = tmp_long;
            }
        }
        diam = max(diam, longest_1 + longest_2 + 2);
        diam = max(diam, longest_1 + 1);
        return make_pair(diam, longest_1 + 1);
    };
    return diam_and_longest(0, -1).first;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> adj_list(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj_list[a].push_back(b);
        adj_list[b].push_back(a);
    }

    int total_diam = get_diameter_of_tree(adj_list);
    cerr << "diam = " << total_diam << endl;
    
    if (total_diam % 3 == 1) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 29184
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;

void solve(){
	int n;cin>>n;vector<int> v(n) , dp(n,INT_MAX);
	for(int i=0;i<n;++i) cin>>v[i];
	dp[0]=0;
	for(int i=0;i<n;++i){
		for(int j : {i+1,i+2}){
			if(j<n){
				dp[j]=min(dp[j],dp[i]+abs(v[j]-v[i]));
			}
		}
	}
	cout<<dp[n-1];
}		
 
int main(){
	//ll t;cin>>t;while(t--)	
	solve();
	return 0;
}

Measured memory_bytes: 4056
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

const int Maxn = 55;

int h, w;
char B[Maxn][Maxn];

int main()
{
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++)
		scanf("%s", B[i]);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++)	if (B[i][j] == '.') {
			int cnt = 0;
			for (int di = -1; di <= 1; di++)
				for (int dj = -1; dj <= 1; dj++) if (di || dj) {
					int ni = i + di, nj = j + dj;
					if (0 <= ni && ni < h && 0 <= nj && nj < w && B[ni][nj] == '#')
						cnt++;
				}
			B[i][j] = '0' + cnt;
		}
		B[i][w] = '\0';
		printf("%s\n", B[i]);
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
seq = [int(x) for x in input().split()]
cur_id = 1
ans = 0
for i in range(len(seq)):
  if seq[i] == cur_id:
    cur_id += 1
  else:
    ans += 1
if cur_id == 1:
  ans = -1
print(ans)

Measured memory_bytes: 25768
# include <iostream>
using namespace std;
const int N=100006;
int a[N];
int n,m,p,f;
int gcd (int x,int y)
{
	if (x%y==0)
	return y;
else return gcd (y,x%y);
}
void work (void)
{
	int i,t;
	if (p>=m&&f==0)
	{
		i=2;
		t=a[1];
		while (i<=n)
		{
			t=gcd (t,a[i]);
			if (t==1)
			break;
			i++;
		}
		if (m%t==0)
		f=1;
	}
	if (f==1)
	cout<<"POSSIBLE";
else cout<<"IMPOSSIBLE";
}
int main (void)
{
	int i;
	cin>>n>>m;
	for (i=1;i<=n;i++)
	{
		cin>>a[i];
		if (a[i]==m)
		f=1;
		if (a[i]>p)
		p=a[i];
	}
	work ();
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()


int main() {
    ll n, c[MAX_N], dp[MAX_N]{};
    vector<vector<int> > ls(MAX_N);
    cin >> n;
    REP(i,n){
        cin >> c[i];
        ls[c[i]].push_back(i);
    }
    REP(i,MAX_N) ls[i].push_back(IINF);
    dp[0] = 1;
    REP(i,n){
        dp[i+1] += dp[i];
        dp[i+1] %= MOD;
        int j = *upper_bound(ALL(ls[c[i]]),i);
        if(j!=IINF && j-i>1){
            dp[j] += dp[i];
            dp[j] %= MOD;
        }
    }
    cout << dp[n] << endl;

    return 0;
}


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

int main(){
    string s1,s2;
    cin>>s1;
    cin>>s2;

    int m=s1.length(),n=s2.length();
    int dp[m+1][n+1];
    char con[m+1][n+1];
    for(int i=0;i<=m;i++) dp[i][0]=0;
    for(int i=0;i<=n;i++) dp[0][i]=0;

    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(s1[i-1]==s2[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
                con[i][j]='d';
            }
            else{
                if(dp[i][j-1]>=dp[i-1][j]){
                    dp[i][j]=dp[i][j-1];
                    con[i][j]='l';
                }
                else{
                    dp[i][j]=dp[i-1][j];
                    con[i][j]='u';
                }
            }
        }
    }
    int i=m,j=n;
    string s3;
    while(i>=1 && j>=1){
        if(con[i][j]=='d'){
            s3.append(s1,i-1,1);
            i--;
            j--;
        }
        else if(con[i][j]=='u') i--;
        else j--;
    }
    reverse(s3.begin(),s3.end());
    cout<<s3;
    return 0;
}

Measured memory_bytes: 44288
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <iostream>


using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		double x[2], y[2], r[2];
		for (int j = 0; j < 2; ++j)
			scanf("%lf %lf %lf", x+j, y+j, r+j);
		double d = sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]));
		if (d > r[0]+r[1])
			puts("0");
		else if (r[0]-d > r[1])
			puts("2");
		else if (r[1]-d > r[0])
			puts("-2");
		else
			puts("1");
	}

	return 0;
}

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

using namespace std;

#define MAX (int)1e5 + 5
template <typename T> T max3 (T num1, T num2, T num3) {return max(num1, max(num2,num3)); }
template <typename T> T min3 (T num1, T num2, T num3) {return min(num1, min(num2,num3)); }


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int total_day = 0;
	cin >> total_day;
	vector<int> dp(3);
	for (int day = 0; day < total_day ; day++) 
	{
		vector<int> v(3);
		for (int i = 0 ; i < 3 ; i++) cin >> v[i];
		vector<int> dp2(3,INT_MIN);
		// dp[i]: tong gt ma ta lam viec i cuoi cung
		for (int i = 0 ; i < 3 ; i++) 
		{
			for (int j = 0 ; j < 3 ; j++)
			{
				if (i != j) dp2[j] = max(dp2[j], dp[i] + v[j]);
			}		
		}
		dp = dp2;
	}
	cout << max3(dp[0],dp[1],dp[2]) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"

#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}

#define SHOW(x) std::cout << #x << " = " << x << std::endl;

int const maxn = 200005;

int fromone[maxn];
int ton[maxn];


int main()
{
//    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);


    int n, m;
    cin >> n >> m;

    while (m--)
    {
        int a,b;
        cin >> a >> b;
        if (a == 1)
            fromone[b] = 1;
        if (b == n)
            ton[a] = 1;
    }

    for(int i = 2; i < n; ++i)
        if (fromone[i] & ton[i])
            FINAL_OUT("POSSIBLE");

    FINAL_OUT("IMPOSSIBLE");
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int A[110], sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] >= sum * 1.0 / (4 * M)) cnt++;
    }

    if (cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, T[101], V[101];
double dp[105][105];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> T[i];
    rep(i, 0, N) cin >> V[i];

    dp[0][0] = 1;
    rep(i, 0, N) rep(v, 0, 105) if (dp[i][v] and v <= V[i]) {
        rep(vv, 0, 105) if(vv <= V[i]) {
            int a = V[i] - v;
            int b = V[i] - vv;
            if (a + b <= T[i]) {
                double up = 1.0 * (v + V[i]) * a / 2;
                double stay = V[i] * (T[i] - a - b);
                double down = 1.0 * (vv + V[i]) * b / 2;
                double c = up + stay + down;
                dp[i + 1][vv] = max(dp[i + 1][vv], dp[i][v] + c);
            } else if (T[i] < abs(vv - v)) {
                // can't
            } else {
                // v + x = vv + y
                // x + y = T[i]

                // x - y = vv - v
                // x + y = T[i]

                // 2x = vv - v + T[i]
                // x = (vv - v + T[i]) / 2

                // y = T[i] - x
                //   = T[i] - (vv - v + T[i]) / 2
                //   = (T[i] - vv + v) / 2

                double x = 1.0 * (vv - v + T[i]) / 2;
                double y = 1.0 * (T[i] - vv + v) / 2;
                double vvv = v + x;

                double up = 1.0 * (v + vvv) * x / 2;
                double down = 1.0 * (vv + vvv) * y / 2;

                double c = up + down;

                dp[i + 1][vv] = max(dp[i + 1][vv], dp[i][v] + c);
            }

        }
    }
    printf("%.10f\n", dp[N][0] - 1);
}

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

int main(void){
    int N, M;
    cin >> N >> M;
    
    vector<int> L(M), R(M), x(M);
    for(int i=0; i < M; i++){
        cin >> L.at(i) >> R.at(i);
        if(L.at(i)+N >= R.at(i)){
            x.at(i) = R.at(i);
        }else{
            x.at(i) = L.at(i) + N;
        }
    }
    sort(L.begin(), L.end());
    sort(x.begin(), x.end());
    if(x.at(0)-L.at(M-1) >= 0){
        cout << x.at(0)-L.at(M-1)+1 << endl;
    }else{
        cout << 0 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int k,a,b;
  cin >> k >> a >> b;
  if ((b / k)* k >= a)
  {
  	cout << "OK" << endl;
  }
  else
  {
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mk make_pair
#define ll long long

int a,b;
signed main() {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b))<<endl;
	return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int x;
  cin >> x;

  int ans = 1;
  for (int i = 2; i * i <= x; ++i) {
    int powi = i * i;
    for (int powi = i * i; powi <= x; powi *= i) {
      ans = max(ans, powi);
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256