akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));

string dream = "maerd";
string dreamer = "remaerd";
string erase = "esare";
string eraser = "resare";

signed main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	if (sx < tx) { //スタート地点からみてゴールは右上にある
		int x = tx - sx;
		int y = ty - sy;
		string a;
		rep(i, y)a += 'U';
		rep(i, x)a += 'R';
		string b;
		rep(i, y)b += 'D';
		rep(i, x)b += 'L';
		string c = "LU" + a + "RD";
		string d = "RD" + b + "LU";
		cout << a << b << c << d << endl;
	}
	else {
		int x = sx - tx;
		int y = sy - ty;
		string a;
		rep(i, y)a += 'D';
		rep(i, x)a += 'L';
		string b;
		rep(i, y)b += 'U';
		rep(i, x)b += 'R';
		string c = "RD" + a + "LU";
		string d = "LU" + b + "RD";
		cout << a << b << c << d << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int a,b;
    cin>>a>>b;
    if(a<10&&b<10)cout<<a*b<<endl;
    else cout<<-1<<endl;
    return 0;
}

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

int main(){
    int N, A[200001];
    cin >> N;
    for(int i=1; i<=N; i++) cin >> A[i];
    bitset<200001> B;
    for(int i=N; i>0; i--){
        for(int j=2*i; j<=N; j+=i) A[i] ^= B[j];
        B[i] = A[i];
    }
    vector<int> ans;
    for(int i=1; i<=N; i++) if(B[i]) ans.push_back(i);
    int sz = ans.size();
    cout << sz << endl;
    for(int i=0; i<sz; i++) cout << ans[i] << " \n"[i==sz-1];
    return 0;
}


Measured memory_bytes: 2424
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String C1 = sc.next();
		String C2 = sc.next();
		
		if(C1.charAt(0) == C2.charAt(2) && C1.charAt(1) == C2.charAt(1) && C1.charAt(2) == C2.charAt(0)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	}
}


Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        if(n == 100) n = 101;
        if(d == 0) {
            System.out.println(n);
        } else if(d == 1) {
            System.out.println(n * 100);
        } else {
            System.out.println(n * 100 * 100);
        }
    }
}

Measured memory_bytes: 35672
W=gets.split[1].to_i+1
s=$<.read
b=s.tr('#.
','10').to_i 2
w=s.tr('
#.','01').to_i 2
c=0
(b|=b*2|b/2|b>>W|b<<W
b&=w
c+=1)while b<w
p c

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

int n,m;

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

signed main() {
  cin >> n >> m;
  UnionFind uf(n);
  rep(i,m) {
    int x,y,z; cin >> x >> y >> z; x--;y--;
    uf.union_(x,y);
  }
  vector<bool> t(n);
  int ans = 0;
  rep(i,n) {
    int r = uf.root(i);
    if (t[r]) continue;
    ans++;
    t[r] = true;
  }

  cout << ans << endl;

}


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


using namespace std;

int main(){
    string S;
    cin >>S;


    if(S[0]=='Y'&&S[1]=='A'&&S[2]=='K'&&S[3]=='I'){
        cout <<"Yes"<< endl;
    }
    else{
        cout <<"No"<< endl;
    }
    return 0;
}

Measured memory_bytes: 256
var
    n,p,s:int64;
    f:array[0..1000010] of longint;
    i,j,t:longint;
begin
    read(n,p);
    if n=1 then
    begin
        writeln(p);
        halt;
    end;
    if p=1 then 
    begin
        writeln(1);
        halt;
    end;
    fillchar(f,sizeof(f),0);
    i:=1;
    t:=trunc(sqrt(p))+1;
    while (p<>1) and (i<=t) do
    begin
        inc(i);
        while p mod i=0 do
        begin
            p:=p div i;
            inc(f[i]);
        end;
    end;
    s:=1;
    for i:=2 to t do
        if f[i]>=n then
            for j:=1 to f[i] div n do s:=s*i;
    writeln(s);
end.

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

vector<vector<ll>> d(300,vector<ll>(300,IINF));
vector<vector<ll>> e(300,vector<ll>(300,IINF));
ll N,M,L;
void WarshallFloyd(){
    rep(k,N){
        rep(i,N){
            rep(j,N){
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

void AarshallFloyd(){
    rep(k,N){
        rep(i,N){
            rep(j,N){
                chmin(e[i][j],e[i][k]+e[k][j]);
            }
        }
    }
}

int main(){
    cin >> N >> M >> L;
    rep(i,M){
        ll a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    rep(i,N){
        d[i][i]=0;
    }
    WarshallFloyd();
    rep(i,N){
        rep(j,N){
            if (d[i][j]<=L){
                e[i][j]=1;
            }
        }
        e[i][i]=0;
    }
    AarshallFloyd();
    ll Q;
    cin >> Q;
    rep(i,Q){
        ll s,t;
        cin >> s >> t;
        s--,t--;
        if (e[s][t]==IINF){
            e[s][t]=0;
        }
        cout << e[s][t]-1 << endl;
    }
}


Measured memory_bytes: 1920
import java.util.*;
class Main {
     
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        Dice[] list = new Dice[n];
        for(int i = 0; i < n; i++) {
            list[i] = new Dice(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
        }
        for(int i = 0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                if(solv(list[i],list[j],0)) {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
    public static boolean solv(Dice f, Dice dice,int count) {
        if(dice.Top == f.Top && dice.S == f.S && dice.Bottom == f.Bottom && dice.E == f.E && dice.N == f.N && dice.W == f.W) return true;
        if(count == 6) return false;
        Dice tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnN();
        if(solv(f,tmp,count+1)) {
            return true;
        }
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        if(solv(f,tmp,count+1)) {
            return true;
        }
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnE();
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnW();
        if(solv(f,tmp,count+1)) {
            return true;
        }
         
        return false;
    }
     
     
     
}
 
class Dice {
    int Top; //1
    int Bottom; //6
    int N; //   5
    int S; //   2
    int W; //左 4
    int E; //右 3
    Dice(int a, int b, int c, int d, int e, int f) {
        Top = a;
        S = b;
        E = c;
        W = d;
        N = e;
        Bottom = f;
    }
    public void TurnN() {
        int tmp = Top;
        Top = S;
        S = Bottom;
        Bottom = N;
        N = tmp;
    }
    public void TurnW() {
        int tmp = Top;
        Top = E;
        E = Bottom;
        Bottom = W;
        W = tmp;
    }
    public void TurnE() {
        int tmp = Top;
        Top = W;
        W = Bottom;
        Bottom = E;
        E = tmp;
    }
    public void TurnS() {
        int tmp = Top;
        Top = N;
        N = Bottom;
        Bottom = S;
        S = tmp;
    }
     
}


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

int main(){
  string s; cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == '1') s[i] = '9';
    else if(s[i] == '9') s[i] = '1';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do(): 
    s=STR()
    if s=='ARC':
        print('ABC')
    else:
        print('ARC')
if __name__ == '__main__':
    do()

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

int main(int argc, const char * argv[]) {



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

    int A,B,C,max,n;

    cin>>A>>B>>C;

    max=A;
    if(max<B)max=B;
    if(max<C)max=C;
    n=10*max+A+B+C-max;

    cout<<n<<endl;

    return 0;
}

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

int main(){
  int n,m;
  int arrayA[100][100];
  int array_b[100];
  int arrayX[100]={0};
  
  cin >> n >> m;

  for(int i=0 ; i<n ; i++ ){
    for(int j=0 ; j<m ; j++ ){
      cin >> arrayA[i][j];
    }
  }

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

  for(int i=0 ; i<n ; i++ ){
    for(int j=0 ; j<m ; j++ ){
      arrayX[i] += arrayA[i][j] * array_b[j];
    }
    cout << arrayX[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	cout.precision(20);
	int i,n,k;
	double ans = 0;
	cin >> n >> k;
	for(i=1;i<=n;i++){
		int x = i,res = 0;
		while(x<k){
			x *= 2;
			res++;
		}
		ans += pow((double)1/2,res);
	}
	ans /= (double)n;
	cout << ans << endl;
}
	

Measured memory_bytes: 384
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
def do():
    s=list(map(str,input().split(',')))
    print(*s)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin()

using namespace std;

signed main(){
    int n , k ;
    cin >> n >> k;
    if(k == 1)return cout << 0 , 0;
    n-=k;
    cout << n;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if (s.size() == 26) {
    	int ind = s.size();
    	if (s == "zyxwvutsrqponmlkjihgfedcba") {
    		cout << "-1\n";
    		return 0;
    	}
    	string aux = s;
    	next_permutation(s.begin(), s.end());
    	for (int i = 0; i < s.size(); ++i) {
    		if (aux[i] != s[i]) {
    			s = s.substr(0, i+1);
    			break;
    		}
    	}
    	cout << s << "\n";

    } else {
    	vi aux(26);
    	for (int i = 0; i < s.size(); ++i) {
    		aux[s[i]-'a'] = 1;
    	}
    	for (int i = 0; i < 26; ++i) {
    		if (!aux[i]) {
    			s.push_back(i+'a');
    			break;
    		}
    	}
    	cout << s << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll h,n;
  cin >> h >> n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  ll dp[h+1];
  fill(dp,dp+h+1,MAX);
  dp[0]=0;
  rep(j,h) {
    rep(i,n) {
      ll x=min(h,j+a[i].F);
      dp[x]=min(dp[x],dp[j]+a[i].S);
    }
  }
  pr(dp[h]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int i=0;
		while(i<1000){
		String line = sc.nextLine();
		String[] array = line.split(" ");
		int a = Integer.parseInt(array[0]);
		int b = Integer.parseInt(array[2]);
		String c = array[1];

		int result = 0;

		if (c.equals("?")) {
			break;
		} else if (c.equals("+")) {
			result = a + b;
		} else if (c.equals("-")) {
			result = a - b;
		} else if (c.equals("*")) {
			result = a * b;
		} else if (c.equals("/")) {
			result = a / b;
		}
		System.out.println(result);
		i++;
		}
	}

}

Measured memory_bytes: 26136
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      String c = sc.next();
      String[] s = new String[4];
      int[] cnt = new int[2];
      String ans;

      for(int i=0;i<4;i++){
        if(i!=3){
          s[i] = c.substring(i,i+1);
        }
        else{
          s[i] = c.substring(3);
        }
      }

if(s[0].equals(s[1])){
/////////////////////////////////////////////
  if(!s[2].equals(s[0]) && s[2].equals(s[3])){
    ans = "Yes";
  }
  else{
    ans = "No";
  }
/////////////////////////////////////////////
}
else{
/////////////////////////////////////////////
  for(int i=0;i<2;i++){
    for(int j=2;j<4;j++){
      if(s[i].equals(s[j])){
        cnt[i]++;
      }
    }
  }
  if(cnt[0]==1 && cnt[1]==1){
    ans = "Yes";
  }
  else{
    ans = "No";
  }
/////////////////////////////////////////////
}

System.out.println(ans);
    }
}

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

const int MAX_N = 105000;

vector<bool> a(MAX_N, false);
vector<int> w(MAX_N);

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

    int ac = 0;
    int wa = 0;
    for (int i = 0; i < M; ++i) {
        int p;
        string S;
        cin >> p >> S;
        if (a[p-1]) continue;
        if (S == "AC") {
            a[p-1] = true;
            ++ac;
            wa += w[p-1];
        } else {
            w[p-1] += 1;
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}

Measured memory_bytes: 768
/*
ID: wangyuxi20040901
TASK:  ()
LANG: C++
DATE: 20200419 20:30:04
*///using CRLF, UTF-8

#include <cstdio>
#include <algorithm>
#include <cstring>
#define pr printf
#define F(i, j, k) for(register int i = j, kkllkl = k; i <= kkllkl; ++i)
#define G(i, j, k) for(register int i = j, kkllkl = k; i >= kkllkl; --i)
#define clr(a, v) memset((a), v, sizeof(a))
using namespace std;
typedef long long ll;

#define isd(x) (('0' <= (x) && (x) <= '9') || (x) == '-')
int rd() {
    int ans = 0, sign = 1; char c = getchar();
    while(!isd(c)) c = getchar();
    if(c == '-') sign = -1, c = getchar();
    while(isd(c)) ans = (ans << 3) + (ans << 1) + c - '0', c = getchar();
    return sign == 1 ? ans : -ans;
}

/* --------------------------CSYZ1921------------------------- */

const int N = 200005;
int n, h[N];

int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    n = rd();
    F(i, 2, n) {
        int k = rd();
        ++h[k];
    }
    F(i, 1, n)
        pr("%d\n", h[i]);
    return 0;
}
/*
*/

Measured memory_bytes: 2360
// # ======================================= #
// # Ilham Firdausi Putra, 23 Desember 2017  #
// # ======================================= #
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define nl printf("\n");

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull; 


int main()
{
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  if (A+B > C+D)
  {
    printf("Left\n");
  } else if (A+B < C+D){
    printf("Right\n");
  } else {
    printf("Balanced\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

int main() {

	ll N;
	cin >> N;
	
	cout << "ABC" << N;
	system("PAUSE");
}


Measured memory_bytes: 504
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int X,k,q,t1=0,t2=1,f=-1,Max,Min=0,now=0,p=0,ans;
int t[100010],a[100010],r[100010];
int main()
{
	scanf("%d %d",&X,&k);
	for(int i=1;i<=k;i++) scanf("%d",&r[i]);
	scanf("%d",&q);
	for(int i=1;i<=q;i++) scanf("%d %d",&t[i],&a[i]);
	Max=X;
	while(t2<=q)
	{
		if(t[t2]>r[t1+1]&&t1<k)
		{
			t1++;
			now=f*(r[t1]-r[t1-1]);
			Max=max(0,min(X,Max+now));
			Min=max(0,min(X,Min+now));
			f*=-1;p+=now;
		}
		else
		{
			ans=max(Min,min(Max,a[t2]+p));
			ans=max(0,min(X,ans+f*(t[t2]-r[t1])));
			printf("%d\n",ans);t2++;
		}
	}
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>t(n),a;
    rep(i,0,n){
        cin>>t[i];
        t[i]--;
    }
    int tmp = 0;
    rep(i,0,n){
        if(i==t[i]){tmp++;}
        else{
            if(tmp>0){a.push_back(tmp);tmp=0;}
        }
    }
    if(tmp>0){a.push_back(tmp);}
    int ans = 0;
    rep(i,0,a.size()){
        ans+=(a[i]+1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define INT INT_MAX
#define LONG LLONG_MAX
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define int long long
typedef long long ll;
using namespace std;

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

ll LCM(ll a, ll b) {
	return a / GCD(a, b)*b;
}

ll mypow(ll a, ll b, ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}

ll longmax(ll a,ll b){
	if(a>b) return a;
	else return b;
}

ll longmin(ll a,ll b){
	if(a<b) return a;
	else return b;
}

signed main(){
	string s;
	cin>>s;
	f(i,s.size()){
		if(s[i]=='1') cout<<9;
		else cout<<1;
	}
	puts("");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,e;
  cin >> N ;
  

for (int i = 0; i < N; i++){
  		int a;
  		cin >> a;
      	int k=2,b=0,d=0;
      
		while (d==0){
          if((a%k)==0)  b++;
          else  d++;
          k*=2;          
        }
      if(i==0)  e=b;
      else if (b<e)  e=b;
    
 
    } 
    	  
 cout << e <<endl;     

  
 }
  

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = map(int,input().split())
PY = [list(map(int, input().split()))+[i] for i in range(M)]


PY.sort(key=lambda x: (x[0],x[1]))
ans = []
num = 1
for i in range(M):
    if i>0 and PY[i][0] != PY[i-1][0]:
        num = 1
    ken = str(PY[i][0]).zfill(6)
    shi = str(num).zfill(6)
    ans.append([PY[i][2],ken+shi])
    num+=1
ans.sort()
for i in range(M):
    print(ans[i][1])


Measured memory_bytes: 91484
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (a, b): (usize, usize) = parse_line().unwrap();

    let mut ret = 0;
    for i in a..=b {
        let s: Vec<_> = i.to_string().chars().collect();
        let mut s_rev: Vec<_> = i.to_string().chars().collect();
        s_rev.reverse();
        if &s == &s_rev {
            ret += 1;
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 2220
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
  public static void main(String... args){
    int[] t = new int[4];
    FastScanner fs = new FastScanner();
    for(int i = 0;i<4;i++){t[i] = fs.nextInt(); }

      if(t[0] < t[2] && t[1] < t[2] || t[2] < t[0] && t[3] < t[0]) System.out.println("0");
      else{
        Arrays.sort(t);
        System.out.println(t[2]-t[1]);
      }
  }
}
class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		String nextLine(){
			String line = "";
			try{
				line = br.readLine();
			}catch(IOException e){
				e.printStackTrace();
			}
			return line;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}


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

int main(void) {
	int a, b, t;
	
	scanf("%d %d %d", &a, &b, &t);
	
	printf("%d\n", t / a * b);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if(A>=K){
    cout << K <<endl;
  }
  else if(A+B>=K){
    cout << A <<endl;
  }
  else{
    cout << 2*A-K+B <<endl;
  }
}

Measured memory_bytes: 3580
N,M = map(int,input().split())
MAX = int(M**(1/2))
ans = 0
for i in range(MAX,0,-1):
    if M % i == 0:
        j = M // i
        if j >= N:
            ans = max(ans,i)
        if i >= N:
            ans = max(ans,j)
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    int H, W, i, j;
    
    while (1) {
        scanf("%d %d", &W, &H);
        if (H == 0 && W == 0)   break;
        
        for (i = 0; W > i; i++)
        {
            for (j = 0; H > j; j++) {
                if (((i % 2) == 0 && (j % 2) == 0) || ((i % 2) == 1 && (j % 2) == 1))
                {
                    putchar('#');
                } else {
                    putchar('.');
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 576
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>

char mark[50][50];

int main(void) {
	uint32_t h, w;
	bool isolatedCellsExist = false;

	scanf("%"PRIu32" %"PRIu32"\n", &h, &w);

	for (uint32_t row = 0; row < h; row++) {
		for (uint32_t col = 0; col < w; col++) {
			scanf("%c", &(mark[row][col]));
		}
		if (row != h - 1) {
			scanf("\n");
		}
	}

	for (uint32_t row = 0; row < h; row++) {
		for (uint32_t col = 0; col < w; col++) {
			if (mark[row][col] == '#') {
				bool isCellIsolated = true;

				if (row != 0) {
					if (mark[row - 1][col] == '#') {
						isCellIsolated = false;
					}
				}
				if (col != 0) {
					if (mark[row][col - 1] == '#') {
						isCellIsolated = false;
					}
				}
				if (row != h - 1) {
					if (mark[row + 1][col] == '#') {
						isCellIsolated = false;
					}
				}
				if (col != w - 1) {
					if (mark[row][col + 1] == '#') {
						isCellIsolated = false;
					}
				}

				if (isCellIsolated) {
					isolatedCellsExist = true;
				}
			}
		}
	}

	printf("%s", isolatedCellsExist ? "No" : "Yes");

	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int n, a;
    cin >> n >> a;
    int l = a;
    int r = a + n - 1;
    int eat;
    if (r <= 0) eat = r;
    else if (l >= 0) eat = l;
    else eat = 0;
    int ans = (r + l) * (r - l + 1) / 2 - eat;
    cout << ans << "\n";
    return 0;
}

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

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

inline int in() { int x; std::scanf("%d", &x); return x; }
inline void pr(int x, char c=10){ std::printf("%d%c", x, c); }

using namespace std;

int hw[16];
int hd[16];
int w, d;

signed main() {
    while (w = in(), d = in()) {
        rep(i, w) hw[i] = in();
        rep(i, d) hd[i] = in();

        int ans = 0;
        rep(i, d) ans += hd[i];
        rep(i, w) ans += hw[i];

        bool matched[16] = {};
        rep(i, d) {
            rep(j, w) {
                if (matched[j]) continue;
                if (hd[i] == hw[j]) {
                    matched[j] = true;
                    ans -= hw[j];
                    break;
                }
            }
        }
        pr(ans);
    }
    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	
	vector<int> x(n);
	for(int i = 0; i < n; i++)
	{
		cin >> x[i];
	}
	
	sort(x.begin(), x.end());
	
	vector<int> a;
	
	int cnt = 0;
	int variety = 0;
	int sum = 0;
	for(int i = 0; i < n; i++)
	{
		if(sum == 0)
		{
			variety++;
		}
		
		if(i == n - 1)
		{
			if(x[i] == x[i - 1])
			{
				sum++;
				a.push_back(sum);
				break;
			}
			else
			{
				a.push_back(1);
				break;
			}
		}
		
		if(x[i] == x[i + 1])
		{
			sum++;
		}
		
		else
		{
			sum++;
			
			a.push_back(sum);
			sum = 0;
		}
		
	}
	
	sort(a.begin(), a.end());
	
	int ans = 0;
	int d = 0;
	
	while(k < variety)
	{
		ans += a[d];
		d++;
		
		variety--;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2168
a = [list(map(int, input().split())) for l in range(3)]
n = int(input()) 
b = [int(input()) for i in range(n)] 

for x in range(n):
	for i in range(3):
		for j in range(3):
			if a[i][j] == b[x]:
				a[i][j] = 0

for r in range(3):
	if a[r]==[0, 0, 0]:
		print('Yes')
		exit()
	elif a[0][r]==a[1][r]==a[2][r]==0:
		print('Yes')
		exit()

if a[0][0]==a[1][1]==a[2][2]==0	or a[0][2]==a[1][1]==a[2][0]==0:	
		print('Yes')
		exit() 
print('No')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define req(x,y) for(ll j=x,k=y;j<k;j++,k--)
#define ss(x) s[x].size()
#define ch(w,x,y) if(s[b][w]!=s[x][y])
#define cm(w,x,y,z) w=min(w,c[i]+f(x,y,z))

ll n,c[51],d[51][21][2],v[51][21][2],a=1e18;
string s[51];

ll f(ll b,ll p,ll g){
	if(p==ss(b))return 0;
	ll &e=v[b][p][g];
	ll &m=d[b][p][g];
	if(e)return m;
	e=1,m=1e18;
	ll l=1;
	if(!g){
		req(p,ss(b)-1){
			ch(j,b,k)l=0;
		}
	}
	else{
		req(0,p){
			ch(j,b,k)l=0;
		}
	}
	if(l)return m=0;
	rep(i,n){
		ll y=1;
		ll j,k;
		if(!g){
			for(j=p,k=ss(i)-1;j<ss(b) && k>=0 && y;j++,k--) {
				ch(j,i,k)y=0;
			}
			if(y){
				if(k<0)cm(m,b,j,0);
				else cm(m,i,k,1);
			}
		}
		else{
			for(j=p,k=0;k<ss(i) && j>=0 && y;j--,k++){
				ch(j,i,k)y=0;
			}
			if(y){
				if(j<0)cm(m,i,k,0);
				else cm(m,b,j,1);
			}
		}
	}
	return m;
}

int main() {
	cin>>n;
	rep(i,n)cin>>s[i]>>c[i];
	rep(i,n)cm(a,i,0,0);
	cout<<(a==1e18 ? -1 : a)<<endl;
}


Measured memory_bytes: 3704
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def table_tenis(): 
    N, A, B = wczytaj_liste()
    if (B-A)%2 == 0: 
        print ((B-A)//2)
    else: 
        if A - 1 <= N - B: 
            print(A+((B-A-1)//2))
        else: 
            print((N-B)+1+((B-A-1))//2)
            
table_tenis()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int main(){
    int n;
    scanf("%d", &n);
    bool f = (int)n&1;
    printf("%.9lf\n", (double)((n/2+f))/n);
} 


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 100000000
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846


int main(){
    while(1){
        ll n;
        cin >> n;
        if(n==0) return 0;
        ld s[1000],sum=0;
        REP(i,n){
            cin >> s[i];
            sum += s[i];
        }
        ld m = sum / n;
        //printf("%.8llf\n",sum);
        //printf("%.8llf\n",m);
        sum = 0;
        REP(i,n){
            sum += (ld)pow(s[i]-m,2);
        }
        ld ans = sum/n;
        //printf("%.8llf\n",ans);
        ans = (ld)sqrt(ans);
        printf("%.8llf\n",ans);
    }
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define int long long
 
void solve()
{
    string s; cin>>s;
    int n=s.length();
    if(s[n-1]=='s')s+="es";
    else s+='s';
    cout<<s;
    return ;
    
}


 
 
 signed main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    
    
    
    int T; 
    T=1;
    //cin>>T;
    while(T--)
    {
          solve();
    }
    
    
        return 0;
	
}

Measured memory_bytes: 3620
//g++  5.4.0

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

    int dish[100];
    int b[100];
    int c[100];


int main()
{
   
    int i,n;
    cin>>n;

    int dish[100];
    int b[100];
    int c[100];
    
    for(i=1;i<=n;i++) cin>>dish[i];
    
    for(i=1;i<=n;i++)
        cin>>b[i];
    
    for(i=1;i<n;i++)
        cin>>c[i];
    
    int res=0;
    for(i=1;i<=n;i++){
        
        res = res+b[dish[i]];
        if(dish[i] == (dish[i-1]+1))
            res = res+c[dish[i-1]];
        
    }
    
    cout<<res;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int h, w;
    while(1) {
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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;
}

int main() {

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

	int n; cin >> n;
	cout << (n + 1) / 2 - 1 << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	int[] discover;
	int[] finish;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		
		for(int i = 0; i < adjMatrix.length; i++) {
			for(int j = 0; j < totalVertex ; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		
		int z = 0;
		//int j = 0;
		
		for(LinkedList<Integer> ll: this.adjList) {
			for(Integer ele : ll) {
				adjMatrix[z][ele] = 1;
			}
			z++;
		}
		
		for(int m = 0; m < adjMatrix.length; m++) {
			for(int n = 0; n < totalVertex; n++) {
				if(n == totalVertex - 1) {
					System.out.println(adjMatrix[m][n]);
				}
				else {
					System.out.print(adjMatrix[m][n] + " ");
				}
				//System.out.print(adjMatrix[m][n] + " ");
			}
		}
	}
	
	public int DFS(int v, int time) {
		
		
		return time;
	}
	
	public void searchGraph() {
		
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}


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

int main(){
  int n;
  cin >> n;
  int h[n][3];
  rep(i,n)rep(j,3) cin >> h[i][j];
  vvi dp(n, vi(3));
  dp[0][0] = h[0][0];
  dp[0][1] = h[0][1];
  dp[0][2] = h[0][2];
  for(int i=1; i<n; i++){
    rep(j,3){
      rep(k,3){
        if(j==k) continue;
        dp[i][j] = max(dp[i][j], dp[i-1][k] + h[i][j]);
      }
    }
  }
  int ans = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
  cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N+1);
    vector<ll>::iterator it;
    rep(i, N){
        cin >> A[i];
    }

    sort(A.begin(), A.end(), greater<ll>());
    B[0] = A[0];

    ll score = 0;
    int num = N-1;

    if(num > 0){
        score += A[0];
        num--;
    }
    int i = 1;

    while(num >= 2){
        score += 2 * A[i];
        i++;
        num -= 2;
    }

    if(num == 1){
        score += A[i];
        i++;
        num--;
    }

    // for(int i = 1; i < N; i++){    
    //     score += B[0];
    //     B.erase(B.begin());
    //     it = B.begin();
    //     B.insert(it, 2, A[i]);
    //     // B[0] = A[i];
    //     // it = B.begin();
    //     // B.insert(it,A[i]);
    //     for(int j = 0; j < N+1; j++){
    //         cout << B[j] << " ";
    //         sort(B.begin(), B.end(), greater<ll>());
    //     }
    //     cout << endl;
    // }

    cout << score << endl;

    return 0;
}

Measured memory_bytes: 6352
import java.util.Scanner;

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();
		int d = sc.nextInt();

		if(a + b > c + d) {
			System.out.println("Left");
		}else if(a + b < c + d){
			System.out.println("Right");
		}else {
			System.out.println("Balanced");
		}

	}

}


Measured memory_bytes: 21844
import sys
readline = sys.stdin.readline

K, Q = map(int, readline().split())

D = list(map(int, readline().split()))

Ans = [None]*Q
for q in range(Q):
    n, x, mod = map(int, readline().split())
    x%= mod
    D2 = [d%mod for d in D]
    res = 0
    cnt = 0
    zero = 0
    for d2 in D2:
        res += d2
        if res > mod:
            cnt += 1
            res -= mod
        if not d2:
            zero += 1
    
    loop =  ((n-1)//K)
    minus = loop*cnt
    zero *= loop
    res2 = 0
    for i in range((n-1)%K):
        res2 += D2[i]
        if not D2[i]:
            zero += 1
        if res2 > mod:
            res2 -= mod
            minus += 1
    minus += (x%mod + loop*res + res2)//mod
    Ans[q] = n-1 - zero - minus
print('\n'.join(map(str, Ans)))

Measured memory_bytes: 68024
#include<bits/stdc++.h>
#define LL long long
#define db long double
#define il inline
#define re register
#define mkpr make_pair

using namespace std;
const int N=2e5+10;
il int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
int to[N<<1],nt[N<<1],hd[N],tot=1;
LL ans,mi,de[N],w[N<<1],ww[N];
void add(int x,int y,int z)
{
	++tot,to[tot]=y,nt[tot]=hd[x],w[tot]=z,hd[x]=tot;
	++tot,to[tot]=x,nt[tot]=hd[y],w[tot]=z,hd[y]=tot;
}
int n,m,xx,sz[N],size,ma,rt,ff[N];
int findf(int x){return ff[x]==x?x:ff[x]=findf(ff[x]);}
bool ban[N];
void fdrt(int x,int fa)
{
	sz[x]=1;
	int mm=0;
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(y==fa||ban[y]) continue;
		fdrt(y,x),sz[x]+=sz[y],mm=max(mm,sz[y]);
	}
	mm=max(mm,size-sz[x]);
	if(ma>mm) ma=mm,rt=x;
}
void dfs(int x,int fa,LL dp)
{
	de[x]=dp+ww[x];
	if(de[xx]>de[x]) xx=x;
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(y==fa||ban[y]) continue;
		dfs(y,x,dp+w[i]);
	}
}
struct edge
{
	int x,y;
	LL z;
	bool operator < (const edge &bb) const {return z<bb.z;}
}e[N*20];
void link(int x,int fa)
{
	e[++m]=(edge){x,xx,de[x]+de[xx]};
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(y==fa||ban[y]) continue;
		link(y,x);
	}
}
void wk(int x)
{
	size=sz[x],ma=n,fdrt(x,0),x=rt;
	ban[x]=1;
	de[xx=x]=ww[x];
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(ban[y]) continue;
		dfs(y,0,w[i]);
	}
	e[++m]=(edge){x,xx,de[x]+de[xx]};
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(ban[y]) continue;
		link(y,0);
	}
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(ban[y]) continue;
		wk(y);
	}
}

int main()
{
    //wtm
	n=rd();
	for(int i=1;i<=n;++i) ww[i]=rd(),ff[i]=i;
	for(int i=1;i<n;++i)
	{
		int x=rd(),y=rd(),z=rd();
		add(x,y,z);
	}
	sz[1]=n,wk(1);
	sort(e+1,e+m+1);
	for(int i=1,j=n-1;j&&i<=m;++i)
		if(findf(e[i].x)!=findf(e[i].y)) --j,ans+=e[i].z,ff[findf(e[i].x)]=findf(e[i].y);
	printf("%lld\n",ans);
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N;
    cin >> N;

    vi rate(9, 0);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        for (int i = 0; i <= 7; i++) {
            if (400 * i <= a && a < 400 * (i+1)) {
                rate[i]++;
            }
        }
        if (a >= 3200) rate[8]++;
    }

    int ans=0;
    for (int i = 0; i < 8; i++) {
        if (rate[i] > 0) {
            ans++;
        }
    }
    cout << ans + (ans==0 && rate[8] > 0) << " " << ans + rate[8] << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
size_t monodecend (size_t i, const vector<int>& A) {
  int Min = A.at(i);
  for (size_t j = i+1; j < A.size(); j++) {
    if (Min >= A.at(j)) {
      Min = A.at(j);
    } else {
      return j;
    }
  }
  return A.size();
}

size_t monoincend (size_t i, const vector<int>& A) {
  int Max = A.at(i);
  for (size_t j = i+1; j < A.size(); j++) {
    if (Max <= A.at(j)) {
      Max = A.at(j);
    } else {
      return j;
    }
  }
  return A.size();
}

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

  for (int i = 0; i < N;) {
    i = monodecend(i,A);
    if (i == N) {
      break;
    }
    Sin.push_back(A.at(i - 1));
    
    i = monoincend(i,A);
    Sin.push_back(A.at(i - 1));
    if (i == N) {
      break;
    }
  }

  long long money = 1000;
  long long stock;
  for (size_t i = 0; i < Sin.size(); i+=2) {
    stock = money / Sin.at(i);
    money %= Sin.at(i);
    money += stock * Sin.at(i+1);
  }
  cout << money << endl;
}

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

int main() {
    int k,a,b;
    cin >> k >> a>> b;
    if ((b%k==0)||(a%k==0)){
        cout << "OK" << endl;
    }else if (b/k-a/k >=1) {
        cout << "OK" <<endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}


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

int main()
{
	int a,b;
	cin >> a >> b;
	if (a + b >= 10) cout << "error" << endl;
	else cout << a+b << endl;
	return 0;
}

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

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] x = new int[n];
    for(int i=0; i<n; ++i) x[i] = sc.nextInt();

    Arrays.sort(x);
    int x_min = x[0];
    int x_max = x[n-1];

    //nが最大でも100なので全探索でやる
    int move_min = Integer.MAX_VALUE;
    for(int j=x_min; j<=x_max; ++j) {
      int move_sum = 0;
      for(int i=0; i<n; ++i) {
        move_sum += (x[i] - j) * (x[i] - j);
      }
      if(move_sum <= move_min) {
        move_min = move_sum;
      }
    }
    System.out.println(move_min);
  }
}

Measured memory_bytes: 22612
#include <iostream>

using namespace std;

int main()
{
   int i, n, l;
   int flag = 0;
   string str;
   
   cin >> n;
   
   if(n % 2 == 1){
       cout << "No" << endl;
   }else{
       l = n/2;
   
      cin >> str;
   
        for(i = 0 ; i < l ; i++){
           if(str[i] != str[i+l]){
               flag = 1;
            break;
            }
        }
   
        if(flag == 1){
           cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
   }
   
   return 0;
}

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

int main(void)
{
    int M, D;
    cin >> M >> D;

    int count = 0;
    for (int m = 1; m <= M; m++) {
        for (int d = 1; d <= D; d++) {
            int d1, d10;
            d1 = d % 10;
            d10 = d / 10;
            if (d1 >= 2 and d10 >= 2 and d1 * d10 == m) {
                count++;
            }
        }
    }
    cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);
  
  ll res=0;
  
  for(int i=0;N/(10*power(5,i))!=0;i++){
    ll a=10*power(5,i);
    res+=N/a;
  }
  
  if(N%2==0)
    cout<<res;
  else
    cout<<0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int y = -max(a,c)+min(b,d);
	if(y<0)
		cout<<0<<endl;
	else
		cout<<y<<endl;
	return 0;
}

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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if(a[i] < a[i + 1]) ans += a[i + 1] - a[i];
	}
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 256