akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int N = ReadInt();
            int sum = 0;
            var dict = new Dictionary<string, int>();
            for (int i = 0; i < N; ++i)
            {
                var V = Read().Split();
                int t = int.Parse(V[1]);
                sum += t;
                dict[V[0]] = sum;
            }
            var X = Read();
            Console.WriteLine(sum - dict[X]);
        }
    }
}


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

int main() {
  int s1s2s3;
  
  cin  >> s1s2s3;
  
  cout << s1s2s3/100 + (s1s2s3 / 10) %10 + s1s2s3 % 10 << endl;
}

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

int main(){
  string A;
  cin >> A;
  if(A.at(0)==A.at(1)&&A.at(1)==A.at(2)){
  cout << "No" << endl;
  }
  else{
   cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>

using namespace std;

int N;

int main() {
  while (true) {
    scanf("%d ", &N);
    int cnt = 0;

    if (N == 0) {
      return 0;
    }
    
    for (int i = 1; i <= N - 1; i++) {
      for (int j = i + 1; j <= N - 1; j++) {
        int sum = 0;
        for (int k = i; k <= j; k++) {
          sum += k;
        }
        if (sum == N) {
          cnt++;
        }
      }
    }
    printf("%d\n", cnt);
  }
}

Measured memory_bytes: 876
s = input()
t = input()
alf = 'abcdefghijklmnopqrstuvwxyz'
r = 'No'
if len(s)<len(t) and s==t[:len(s)]:
    r = 'Yes'

s = sorted(s)
t = sorted(t, reverse=True)
for i in range(min(len(s),len(t))):
    si = alf.index(s[i])
    ti = alf.index(t[i])
    if si < ti:
        r = 'Yes'
        break
    elif si == ti:
        continue
    else:
        break
print(r)

Measured memory_bytes: 3064
#include <stdio.h>

#define MAX 100

//static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n, M[MAX][MAX];

int prim(){
  int i, v, sum, u, minv, d[MAX], p[MAX], color[MAX];
  for(i=0; i<n; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }
  d[0] = 0;
  while(1){
    minv = INFTY;
    u = -1;
    for(i=0; i<n; i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u==-1) break;
    color[u] = BLACK;
    for(v=0; v<n; v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  sum = 0;
  for(i=0; i<n; i++){
    if(p[i]!=-1) sum+=M[i][p[i]];
  }
  return sum;
}

int main(){
  int i, j, e;
  
  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d", &e);
      if(e==-1) M[i][j]=INFTY;
      else M[i][j]=e;
    }
  }

  printf("%d\n", prim());

  return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f(k,n) for(auto i =k; i<n; i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie();
#define test ll t; cin>>t;

long long base(long long n, long long  k){
    long long  m = 0;
    while(n){
        n = n/k; m += 1;
    }
    return m;
}

int main(){
    IOS
    long long n , k ; 
    cin>>n>>k;
    string s = to_string(n);
    if(k == 10) cout<<s.size()<<endl;
    else{
        ll m = base(n,  k);
        cout<<m<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {

    int n;
    int sum = 0;

    std::cin >> n;

    for(int i = 0; i < n; ++i) {
        int l, r;
        std::cin >> l >> r;
        sum += r - l + 1;
    }

    std::cout << sum << std::endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

$arrayS = str_split($s);
$arrayT = str_split($t);
$cntS = count($arrayS);
$cntT = count($arrayT);
$diff = $cntT - $cntS;
$equalLength = 0;
for($i = 0; $i < $cntS; $i++){
	if($arrayS[$i] === $arrayT[$i]){
    	$equalLength++;
    }
}
if($equalLength === $cntS && $diff === 1){
	echo 'Yes';
}else{
	echo 'No';
}

Measured memory_bytes: 16156
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int a,b,c;
  int n,m;
  string s;
  cin >> s;
  if(s=="ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int a,b,k;
  cin>>a>>b>>k;
  vector<int> v;
  for(int i = 1; i <= min(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      v.push_back(i);
    }
  }
  sort(v.begin(), v.end(), greater<int>());
  cout << v[k - 1];
}


Measured memory_bytes: 256
#include<stdio.h>
long long int z(int a,int b){
	long long int t;
	if(b>a){
		t=b;
		b=a;
		a=t;
	}
	while(b!=0){
	t=b;
	b=a%b;
	a=t;
}
return a;
}
int main(){
	long long int a,b,c;
	scanf("%lld%lld",&a,&b);
	c=z(a,b);
	printf("%lld",(a*b)/c);
	return 0;
}

Measured memory_bytes: 128
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
const long long Maxn=1e6;
typedef long long ll;

int main(){
	ll n,m;
	ll ans=0;
	scanf("%lld %lld",&n,&m);
	if(n*m==1) ans=1;
	else if(n==2||m==2) ans=0;
	else if((n==1&&m>=2)||(m==1&&n>=2)) ans=n*m-2;
	else ans=n*m-2*n-2*m+4;
	printf("%lld",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 1; i <= n; i ++)
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define mem(x, y) memset(x, y, sizeof(x))

using namespace std;
const int N = 25;
int a[N];

int main()
{
	int n, len = 0, ans = 0;
	bool flag = 1;
	scanf("%d", &n);
	while(n) a[++len] = n % 10, n /= 10;
	REP(i, len - 1) if(a[i] != 0) { flag = 0; break; }
	if(a[len] != 1) flag = 0;
	if(flag) { puts("10"); return 0; }
	REP(i, len) ans += a[i];
	printf("%d\n", ans);
	return 0;
}

/*

15

100000

*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

 
int main(){
  int k;
  cin >> k;

  if(k%2==0) cout << k/2*k/2 << endl;
  else cout << k/2*(k+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import collections
import copy

input = sys.stdin.readline


def main():
    N = int(input())
    A = [collections.deque([int(x) for x in input().split()]) for _ in range(N)]

    day = 0
    c = 0
    nxt = [x for x in range(N)]
    oppo = [0] * N

    while c != N * (N - 1):
        day += 1

        for i in nxt:
            oppo[i] = A[i].popleft() if A[i] else -1

        tmp = set()
        for i in nxt:
            if i == -1 or i in tmp:
                continue
            if i == oppo[oppo[i] - 1] - 1:
                tmp.add(i)
                tmp.add(oppo[i] - 1)
                c += 2
        if not tmp:
            print(-1)
            return

        nxt = tmp

    print(day)


if __name__ == '__main__':
    main()


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

typedef int64_t ll;
using namespace std;

int main() {
    // freopen("output.txt", "w", stdout);

    int n, x, t;
    cin >> n >> x >> t;


    int time = 0, count = 0;
    while (n != 0) {
        count++, n--;
        if (count == x) {
            time += t;
            count = 0;
        }
    }
    if (count != 0)
        time += t;
    cout << time << endl;
    return 0;
}

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

 int main() {
 int n;
 cin >> n;
 vector<int>p(n);
 for(int i = 0; i < n; i++) cin >> p[i];
 int ans = 0;
 for(int i = 1; i < n - 1; i++) {
 if((p[i - 1] < p[i]) && (p[i] < p[i + 1])) ans++;
 else if((p[i - 1] > p[i]) && (p[i] > p[i + 1])) ans++;
 }
 cout << ans << endl;
 return 0;
 }


Measured memory_bytes: 256
import sys
def solve():
    input = sys.stdin.readline
    N = int(input())
    K = int(input())
    X = [int(x) for x in input().split()]
    ans = 0
    for x in X: ans += min(x, K - x) * 2
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3060
import Control.Monad

main :: IO ()
main = do
  [n,m,c] <- map read . words <$> getLine :: IO [Int]
  bs <- map read . words <$> getLine :: IO [Int]
  print . length . filter id =<< do
    replicateM n $ do
      as <- map read . words <$> getLine :: IO [Int]
      return $ (sum $ zipWith (*) as bs) + c > 0


Measured memory_bytes: 1020
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

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

  vector<long long> A(N);
  for (int i = 1; i <= N; i++) {
    cin >> A[i-1];
    A[i-1] -= i;
  }

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

  long long ans = 0;
  for (long long a : A) {
    ans += abs(a - A[N/2]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
import java.math.BigInteger;
import java.util.Scanner;

public class Main 
{
	static int mod(int x)
	{
		int an = x%2019;
		while(an<0)an+=2019;
		return an;
	}

	public static void main(String[] args) 
	{
		BigInteger bi = new BigInteger("10");
		int x = 141;
//		System.out.println("test: " + mod(10*202));
		
		int inverse = 202;
		int goback = 1;
		
//		System.out.println(bi);
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		int n = s.length();
		int[] a = new int[n];
		
		int target = 0;
		
		for(int i = 0; i < n; i++)
		{
			a[i] = s.charAt(i) - '0';
		}
		
		long[] avail = new long[2019];
		int suffix = 0;
		int digitval = 1;
		
		int cur = 0;
		
		int backtransmul = 1;
		int backtransadd = 0;
		long score = 0;
//		int digsz = 1;
		int curval = 0;
		for(int i = 0; i < n; i++)
		{
			curval = mod(curval*10 + a[i]);
			
//			System.out.println("curval " + curval);
//			int cura = mod((a[i] * backtransmul) - backtransadd);
			int cura = mod((0 * backtransmul) - backtransadd);
			avail[cura]++;
//			System.out.println("cura " + cura);
			
			int curb = mod((0 * backtransmul) - backtransadd);
//			System.out.println("curb " + curb + " " + avail[curb]);
			
//			if(i>0)
			{
				backtransmul = mod(backtransmul*202);
//				backtransadd = mod(backtransadd*202    + a[i] * 202);
				backtransadd = mod(backtransadd + backtransmul*a[i]);
			}
//			digsz = mod(digsz*202);
//			System.out.println("trans x" + backtransmul + " " + " - " + backtransadd);
			
			{
				int curc = mod((0 * backtransmul) - backtransadd);
//				System.out.println("curc " + curc + " " + avail[curc] + "\n");
				score += avail[curc];
			}
		}
		
		System.out.println(score);
	}

}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    string s;
    cin >> s;
    rep(i, 3) {
        if (s[i] == '7') {
            puts("Yes");
            return 0;
        }
    }
    puts("No");

    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int flag=0;
  while(n>0)
  {
    if(n%10==7)
      flag=1;
    n/=10;
  }
  if(flag)
    cout<<"Yes\n";
  else
    cout<<"No\n";
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R, G, B, n;
    cin >> R >> G >> B >> n;
    ll ans = 0;
    for(int r = 0; r*R <= n; ++r){
        for(int g = 0; r*R + g*G <= n; ++g){
            if((n - r*R - g*G)%B == 0) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1000000000
#define MOD 1000000007
#define MAX 100001
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back 
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
ll a,b,c;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b>>c;
	if(b*c>=a){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)
#define INF 100000009

int sx,sy,tx,ty;
int N;
double ans = 0;
vector<pair<int,int> > V;
int dp[200010];
bool fx = false,fy = false;
double mem;

int main()
{
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    if(sx > tx)swap(sx,tx),fx = true;;
    if(sy > ty)swap(sy,ty),fy = true;;
    ans += (double)(tx - sx + ty - sy) * 100.0;
    scanf("%d",&N);

    for(int i = 0; i < N + 1; i++)dp[i] = INF
;    for(int i = 0; i < N; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(sx <= x && sy <= y && tx >= x && ty >= y)V.push_back(mk(x,y));
    }

    for(int i = 0; i < V.size(); i++)
    {
        if(fx)V[i].fi = sx + tx - V[i].fi;
        if(fy)V[i].se = sy + ty - V[i].se;
    }

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

    for(int i = 0; i < V.size(); i++)
    {
        if(i == 0 || V[i].fi != V[i - 1].fi)
        {
            *lower_bound(dp,dp + V.size() + 1,V[i].se) = V[i].se;
        }
    }

    mem = (double)(lower_bound(dp,dp + V.size() + 1,INF) - dp);

    if(min(tx - sx,ty - sy) + 1 == (int)mem)
        printf("%.11lf\n",ans + 10.0 * M_PI - 20.0 - (mem - 1.0) * (20.0 - 5.0 * M_PI));
    else
        printf("%.11lf\n",ans - mem * (20.0 - 5.0 * M_PI));
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2") 
#pragma GCC optimization ("unroll-loops")

using namespace std;
using ll = long long;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define Ceil(x, y) ((x+y-1)/y)
#define PI acos(-1)
const int mod = (int) 1000000007;



void solve()
{
    int n;
    cin>>n;
    vector<int> A(n);
    for(int &i : A)
        cin>>i;
    ll ans = 0;
    for(int i=1; i<n; i++)
        if(A[i-1] > A[i])
        {
            ans += abs(A[i-1]-A[i]);
            A[i] = A[i-1];
        }
    cout<<ans;
}
 

int main(int argc, char *argv[])
{
    clock_t clk_start = clock();
    fast;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    int cases = 1;
    // cin>>cases;
    while(cases--)
    {
        solve();
    }
    cerr<<"Execution Time: "<<fixed<<double(clock() - clk_start)/double(CLOCKS_PER_SEC)<<setprecision(6)<<" sec\n"; 
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,S;
    cin >> N >> M >> S;
    struct edge{
        int to,a;
        ll b;
    };
    vvec<edge> g(N);
    for(int i=0;i<M;i++){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g[u].push_back({v,a,b});
        g[v].push_back({u,a,b});
    }
    vec<int> C(N),D(N);
    for(int i=0;i<N;i++) cin >> C[i] >> D[i];
    int ma = 5001;
    struct state{
        int node,s;
        ll dist;
        bool operator<(const state& R)const{
            return dist>R.dist;
        }
    };
    priority_queue<state> Q;
    ll inf = 1e18;
    vvec<ll> dp(N+1,vec<ll>(ma+1,inf));
    S = min(S,ma);
    dp[0][S] = 0;
    Q.push({0,S,0});
    while(!Q.empty()){
        auto [cur,s,d] = Q.top(); Q.pop();
//        cerr << cur << " " << s << " " << d << "\n";
        if(dp[cur][s]<d) continue;
        int ns = min(ma,s+C[cur]);
        ll nd = d+D[cur];
        if(dp[cur][ns]>nd){
            dp[cur][ns] = nd;
            Q.push({cur,ns,nd});
        }
        for(auto& e:g[cur]){
            if(s<e.a) continue;
            int ne = e.to;
            int ns = s-e.a;
            ll nd = d+e.b;
            if(dp[ne][ns]>nd){
                dp[ne][ns] = nd;
                Q.push({ne,ns,nd});
            }
        }
    }
    for(int i=1;i<N;i++) cout << *min_element(dp[i].begin(),dp[i].end()) << "\n";
}

Measured memory_bytes: 9412
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c){
		cout<<"No";
	}
	else if(a!=b&&b!=c&&c!=a){
		cout<<"No";
	}
	else{
		cout<<"Yes";
	}
return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    solver(s)
}

fun solver(s: String) {
    // println(s.length)
    var ans = 0
    val rev = s.reversed()
    for( cnt in 0..(s.length / 2).toInt()-1 ){
        if (!s.get(cnt).equals(rev.get(cnt))){
            ans++
        }
        // println("s = " + s.get(cnt) + " , rev = " + rev.get(cnt))
    }
    println(ans)
}

Measured memory_bytes: 33848
from itertools import combinations, count
 
n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
r = next(i for i in count(n, - 1) for x in combinations(r, i)
         if all(a[j][0].isdisjoint(x) and a[j][1].issubset(x) for j in x))
print(r)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);
#define Accepted 0
using namespace std;
typedef long long ll;
const int maxn = 1000000 + 10;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1);
int T, cases, n, m;

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int main() {
	int N, M, K;
	cin >> N >> M >> K;
	rep(x, 0, N + 1) {
		rep(y, 0, M + 1) {
			if (x * y + (N - x) * (M - y) == K) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}


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

int main(){
    
    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;
    }
    return 0;
}


Measured memory_bytes: 3104
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<numeric>
#include<deque>
using namespace std;
typedef long long ll;
int main()
{
	int n,k;
	cin>>n>>k;
	int sum=0;
	if(n==0)
		sum=1;
	while(n)
	{
		sum++;
		n/=k;
	}

	cout<<sum<<endl;
	return 0;
}

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

int main(){

  int dat[3][3];
  char in;
  int sum;

  while(cin>>in){

    if(in=='o')dat[0][0]=1;else if(in=='x')dat[0][0]=-1;else dat[0][0]=0;

    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        if(!i && !j)continue;
        cin>>in;
        if(in=='o')dat[i][j]=1;
        else if(in=='x')dat[i][j]=-1;
        else dat[i][j]=0;
      }
    }

    /*judge*/
    for(int i=0; i<3; i++){
      sum=0;
      for(int j=0; j<3; j++){
        sum+=dat[i][j];
      }
      if(sum==3||sum==-3)goto END;
    }

    for(int i=0; i<3; i++){
      sum=0;
      for(int j=0; j<3; j++){
        sum+=dat[j][i];
      }
      if(sum==3||sum==-3)goto END;
    }

    sum=0;
    for(int i=0; i<3; i++)sum+=dat[i][i];
    if(sum==3||sum==-3)goto END;

    sum=0;
    for(int i=0; i<3; i++)sum+=dat[i][2-i];

    END:;
    if(sum==3)cout<<'o'<<endl;
    else if(sum==-3)cout<<'x'<<endl;
    else cout<<'d'<<endl;

  }


  return 0;

}

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

void solve(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    string ans;
    for(int i=0;i<n;i++){
        ans+=s[i];
        ans+=t[i];
    }

    cout << ans << endl;
}


int main(){
    solve();
}

Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        ans += bisect_left(L, L[i] + L[j]) - j - 1
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#define MAX_P 100001
using namespace std;

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    int p[d][n];
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < n; j++) {
            cin >> p[i][j];
        }
    }

    int dp[MAX_P];
    for (int i = 0; i < d - 1; i++) {
        for (int j = 0; j <= x; j++) {
            dp[j] = j;
        }
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < x + 1; k++) {
                if (k >= p[i][j]) {
                    dp[k] = max(dp[k], dp[k - p[i][j]] + p[i + 1][j]);
                }
            }
        }

/*
        for (int j = 0; j < x; j++) {
            cout << dp[j] << " ";
        }
        cout << endl;
*/
        int res = dp[0];
        for (int j = 1; j <= x; j++) {
            res = max(res, dp[j]);
        }
        x = res;
    }

    cout << x << endl;
    return 0;
}

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

#define pb push_back
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(),(X).end()
#define ll long long
#define pi pair<int,int>
const int N=1e5+5,MOD=100;

using namespace std;

int n,a[N];
ll memo[N][2];

ll solve(int indx,bool changed){
	if(indx==n-1){
		if(changed)return -a[indx];
		return a[indx];
	}
	ll &ret = memo[indx][changed];
	if(~ret)return ret;
	int val = a[indx];
	if(changed)val = -val;
	ret = max(-val+ solve(indx+1,1),val+solve(indx+1,0));
	return ret;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);


	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	memset(memo,-1,sizeof(memo));

	printf("%lld\n",solve(0,0));

}


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

long sum(long k){  
  return k*(k+1)/2;
}

int main(){
  int N;
  //long s3, s5, s15, sn;
  long ret;
  cin >> N;
  ret = sum(N)-3*sum(N/3)-5*sum(N/5)+15*sum(N/15);
  cout << ret << endl;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int digit=0;
	while(n>0)
	{
		n>>=1;
		digit++;
	}
	int res=pow((double)2,(double)digit);
	if(res==n)cout<<n;
	else
	{
		int r=pow((double)2,(double)digit-1);
		cout<<r;
	}
}

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



int main () {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int A, B, cur = 1, ans = 0;
  cin >> A >> B;
  while (cur < B) {
    cur += A - 1;
    ++ans;
  }
  cout << ans << '\n';
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int reizou = sc.nextInt(); //冷蔵庫の種類
        int renzi = sc.nextInt(); //電子レンジの種類
        int discount = sc.nextInt(); //割引券の種類
        int[] reizous = new int[reizou];
        for(int i = 0 ; i < reizou; i++)
          reizous[i] = Integer.parseInt(sc.next());
        int[] renzis = new int[renzi];
        for(int i = 0; i < renzi; i++)
          renzis[i] = Integer.parseInt(sc.next());
        int[][] discounts = new int[discount][3];
        for(int i = 0; i < discount; i++){
          for(int j = 0; j < 3; j++){
            discounts[i][j] = Integer.parseInt(sc.next());
          }
        }

        int lower = Integer.MAX_VALUE;
        for(int i = 0 ; i < discount; i++){
          if(reizous[discounts[i][0]-1] + renzis[discounts[i][1]-1] - discounts[i][2] < lower){
            lower = reizous[discounts[i][0]-1] + renzis[discounts[i][1]-1] - discounts[i][2];
          }
        }

        Arrays.sort(reizous);
        Arrays.sort(renzis);
        if(reizous[0]+renzis[0] < lower){
          lower = reizous[0] + renzis[0];
        }

        System.out.println(lower);
    }
}


Measured memory_bytes: 69716
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define f first
#define s second
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;
const ll mod = INF + 7;
const double EPS = 1e-9;
int a[10000] , b[10000];
vector<ll> s;
int n ,l , r;
int maleBegin = 0 , maleEnd = 0;
int main()
{
	//freopen("input.txt" , "r" , stdin);
	cin >> n;
	int l = 0 , r = n;
	int i = 0;
	cout << i << endl;
	fflush(stdout);
	string s;
	cin >> s;
	if(s == "Vacant")
	{
		return 0;
	}
	if(s == "Male")
		maleEnd = maleBegin = 1;
	else
		maleEnd = maleBegin = 0;
	for(int i = 0; i < 19; i++)
	{
		bool maleMid;
		int m = (l + r) / 2;
		cout << m << endl;
		fflush(stdout);
		string s;
		cin >> s;
		if(s == "Vacant")
		{
			return 0;
		}
		else
		{
			if(s == "Male")
				maleMid = 1;
			else
				maleMid = 0;
		}
		int distLeft = m - l;
		int distRight = r - m;
		if((distRight % 2) && ((maleMid ^ 1) != maleEnd))
		{
			l = m;
			maleBegin = maleMid;
			continue;
		}
		if(not(distRight % 2) && maleMid != maleEnd)
		{
			l = m;
			maleBegin = maleMid;
			continue;
		}
		if((distLeft % 2) && ((maleMid ^ 1) != maleBegin))
		{
			r = m;
			maleEnd = maleMid;
			continue;
		}
		if(not(distLeft % 2) && maleMid != maleBegin)
		{
			r = m;
			maleEnd = maleMid;
			continue;
		}
	}
	cout << 1 / 0;
}



Measured memory_bytes: 852
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//







int main(void) {

    string o, e;
    cin >> o >> e;
    string ans = "";
    rep(i,e.size()) {
        ans += o[i];
        ans += e[i];
    }
    if (o.size() != e.size()) ans += o[o.size()-1];
    out(ans);

    
    return 0;
}











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

int n, x;
vector < int > v;


int main (){
  cin >> n >> x;
  int p[2* n];

  int mid = (2*n-1)/2;
  bool bio[2*n];

  for (int i = 0; i < (2*n); i++){
    p[i] = -1;
    bio[i] = 0;
  }

  //cout << n-2 << endl;
  p[mid] = x;
  bio[x] = 1;

  if (x == 1 || x == 2 * n - 1){
    cout << "No";
    return 0;

  }
  else if (x == 2){
    p[mid + 1] = 1;
    p[mid + 2] = x + 2;
    p[mid - 1] = x + 1;
    bio[1] = 1;
    bio[x + 1] = 1;
    bio[x + 2] = 1;
  }

  else{
    p[mid - 1] = x - 1;
    p[mid + 1] = x + 1;
    p[mid + 2] = x - 2;
    bio[x + 1] = 1;
    bio[x - 1] = 1;
    bio[x - 2] = 1;
  }

  cout << "Yes\n";

  int curr = 1;


  for (int i = 0; i < 2 * n - 1; i++){
    while (bio[curr]){
      curr++;
    }
    //cout << curr << "s" <<endl;
    if (p[i] == -1){
        p[i] = curr;
        bio[curr] = 1;
    }

  }
  for (int i = 0; i < 2 * n - 1; i++){
    cout << p[i] << endl;
  }




}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  int r,g,b;
  cin >> r >> g >> b;

  if ((100*r+g*10+b)%4==0) {
    cout << "YES" << endl;
  }

  else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
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())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int tmp = C;
        for (int j = 0; j < M; j++) {
            tmp += A[i][j] * B[j];
        }
        if (tmp > 0) ans++;
    }

    cout << ans << endl;

    return;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
 cin>>n;
 vector<pair<int,int> >v[n+1];

 for(int i=0;i<n-1;i++){
 int a,b,w;
 cin>>a>>b>>w;

 v[a].push_back(make_pair(b,w));
 v[b].push_back(make_pair(a,w));
 }
 int ans[n+1];
 queue<int>q;
 q.push(1);
 int vis[n+1]={0};
 vis[1]=true;
   ans[1]=0;
   while(!q.empty()){
      int p=q.front();
      q.pop();
      for(int i=0;i<v[p].size();i++)
        if(vis[v[p][i].first]==false){
          vis[v[p][i].first]=true;
          ans[v[p][i].first]=(ans[p]+v[p][i].second)%2;
          q.push(v[p][i].first);
        }
   }
   for(int i=1;i<=n;i++)
   cout<<ans[i]<<"\n";
}

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

int main() {
    while (true) {
        int w;
        cin >> w;
        
        if (w==-1) {
            break;
        }
        
        int res;
        
        if (w<=10) {
            res = 1150;
        }
        else if (w<=20) {
            res = 1150+125*(w-10);
        }
        else if (w<=30) {
            res = 2400+140*(w-20);
        }
        else {
            res = 3800+160*(w-30);
        }
        
        cout << 4280-res << endl;
    }
}


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

int main ()
{
    int n;
    string ans;
    cin>>n;
    cin>>ans;
    int flag;
    for(int i=0;i<ans.size();i++)
    {
        flag=(ans[i]-'A'+n)%26;
        printf("%c",('A'+flag));
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define V 100
int main(){
	int i,j,k;
	int n,m,l;
	int a[V][V],b[V][V];
	long int c[V][V];
	
	scanf("%d %d %d",&n,&m,&l);
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			a[i][j]=0;
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			b[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			c[i][j]=0;
		}
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%d",&b[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			for(k=0;k<m;k++){
				c[i][j] += a[i][k]*b[k][j];
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			if(j==0){
			printf("%li",c[i][j]);
			}else{
				printf("% li",c[i][j]);
			}
		}
		printf("\n");
	}

}
	

Measured memory_bytes: 1188
#include<stdio.h>
#include<ctype.h>
int main(){
    int s;
    int i=0;
    int count[26]={0};
    while(i<1200){
        s=getchar();
        s=tolower(s);
        if(s>='a' && s<='z')count[s-'a']++;
        i++;
    }
    for(i=0; i<26; i++)printf("%c : %d\n", 97+i, count[i]);
    return 0;
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  REP(i, N) { cin >> p[i]; }
  ll ans = 0;
  REP(i, N-1) {
    if (p[i] != i + 1) continue;
    swap(p[i], p[i + 1]);
    ans++;
  }
  if (p[N - 1] == N) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int[] a = new int[N + 1];

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = N - 1; i > 0; i -= 2) {
			System.out.print(a[i] + " ");
		}

		System.out.print(a[0] + " ");
		
		if ((N % 2) == 0) {
			for (int i = 2; i <= N - 2; i += 2) {
				System.out.print(a[i] + " ");
			}
		} else {
			for (int i = 1; i <= N - 2; i += 2) {
				System.out.print(a[i] + " ");
			}
		}

		System.out.println();

		sc.close();
	}
}

Measured memory_bytes: 94028
s = input()
t = input()

mps = dict()
mpt = dict()
ans = "Yes"
for i in range(len(s)):
  if s[i] in mps.keys():
    if t[i] != mps[s[i]]:
      ans = "No"
  elif t[i] in mpt.keys():
    if s[i] != mpt[t[i]]:
      ans = "No"
  else:
    mps[s[i]] = t[i]
    mpt[t[i]] = s[i]

print(ans)

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

int main()
{
  int N, T, A;
  cin >> N >> T >> A;
  
  int ans =1;
  int h1; cin >> h1;
  double d = abs(A - (T - h1*0.006));
  
  for (int i=1; i<N; i++) {
    int h2; cin >> h2;
    
    double td = abs(A - (T - h2*0.006));
    
    if (td<d)
    {
      ans = i+1;
      d = td;
    }
  }
  cout << ans << endl;  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=140005;
const LL inf=1LL<<60;
struct node { int y,next; } a[N];
struct node1 { LL x,y; } v[N*20],t[N<<1];
LL l,r,X;
int z[N],S[N],E[N],head[N],i,j,k,n,m,g;
bool F;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void jb(int x,int y)
{
	a[++k]=(node){y,head[x]},head[x]=k;
}

void dfs(int w)
{
	if (!head[w])
	{
		v[S[w]=E[w]=++g]=(node1){0,0};
		return;
	}
	int c1=a[head[w]].y,c2=a[a[head[w]].next].y;
	dfs(c1);
	if (!F) return;
	dfs(c2);
	if (!F) return;
	if (E[c1]-S[c1]>E[c2]-S[c2]) swap(c1,c2);
	register int i=S[c1],j=S[c2],k;
	LL D=inf,Y=X-z[c1]-z[c2];
	S[w]=g+1;
	for (;i<=E[c1];++i)
	{
		for (;j<=E[c2]&&v[i].y+v[j].x<=Y;++j)
			D=min(D,v[j].y);
		if (D<inf)
			v[++g]=(node1){v[i].x,D};
	}
	if (S[w]>g)
	{
		F=0;
		return;
	}
	k=S[w];
	for (i=S[w]+1;i<=g;++i)
		if (v[i].y<v[k].y)
			v[++k]=v[i];
	E[w]=g=k;
	for (i=g;i>=S[w];--i)
		v[i].x+=z[c1],v[i].y+=z[c2],
		v[++g]=(node1){v[i].y,v[i].x};
	int s=g-S[w];
	for (j=E[w]+1,i=S[w],k=0;i<=E[w]&&j<=g;)
		if (v[i].x==v[j].x)
			v[i].y<v[j].y?++j:++i;
		else
			t[k++]=v[i].x<v[j].x?v[i++]:v[j++];
	while (i<=E[w]) t[k++]=v[i++];
	while (j<=g) t[k++]=v[j++];
	for (i=0;i<k;++i)
		v[S[w]+i]=t[i];
	E[w]=S[w]+k-1;
}

int main()
{
	n=read();
	for (i=2;i<=n;++i) jb(read(),i),z[i]=read();
	l=0,r=(LL)n*100000;
	while (l<r)
	{
		X=l+r>>1,F=1,
		g=0,dfs(1);
		if (F) r=X; else l=X+1;
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 26624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] a = new boolean[256];
		String s = sc.next();
		for(int i=0;i<s.length();i++) {
			a[s.charAt(i)] = true;
		}
		if ((a['N'] ^ a['S']) || (a['W'] ^ a['E'])) {
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}

}


Measured memory_bytes: 9940
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000

int boss[NUM],BASE[NUM],ADD[NUM];

int get_boss(int id){
	if(boss[id] == id)return id;
	else{

		int next_boss = get_boss(boss[id]);

		BASE[id] += BASE[boss[id]];

		return boss[id] =  next_boss;
	}
}

int get_value(int id){
	return BASE[id]+ADD[id]-ADD[boss[id]];
}

void unite(int A,int B,int diff){

	int boss_A = get_boss(A);
	int boss_B = get_boss(B);

	if(boss_A == boss_B)return;

	boss[boss_B] = boss_A;
	BASE[boss_B] += BASE[A]+ADD[A]+diff-(BASE[B]+ADD[B]);
}

int main(){

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

	for(int i = 0; i < N; i++){
		boss[i] = i;
		BASE[i] = 0;
		ADD[i] = 0;
	}

	char buf[8];

	int A,B,diff;

	for(int loop = 0; loop < Q; loop++){
		scanf("%s",buf);

		if(buf[0] == 'I'){

			scanf("%d %d %d",&A,&B,&diff);
			A--;
			B--;

			ADD[A] += diff;
			ADD[B] += diff;

			unite(A,B,diff);

		}else{ //compare
			scanf("%d %d",&A,&B);
			A--;
			B--;

			if(get_boss(A) != get_boss(B)){
				printf("WARNING\n");
				continue;
			}

			printf("%d\n",get_value(B)-get_value(A));
		}
	}

	return 0;
}



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

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

  ll res = 1e16;  // 十分大きい値で初期化
  for (ll a = 1; a * a <= n; ++a) {
    if (n % a == 0) {
      ll b = n / a;
      ll sum = a + b;
      res = min(res, sum);
    }
  }
  cout << res - 2 << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

char s[maxn],t[maxn];

int main()
{
    fastio();
    cin>>s+1>>t+1;
    int n = strlen(s+1);
    int ans = 0;
    rep(i,1,n) if(s[i]!=t[i]) ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4028
/******************************\
*  Everyone has a different way of thinking, so God Created us
   Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Mo_Murad   *
\******************************/
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define SZ(c) int(c.size())
#define ff first
#define ss second
#define INF INT32_MAX
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
int LCM(int a, int b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
			n /= i;
		}
	}
	if (n > 2)printf("%d ", n);
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
void dijjkstra(int src, int n) {
	list<ipair>adj[1000005];
	vector<bool>visited(1000005, false);
	vector<int>dis(1000005, 1e9);
	PQ<ipair, vector<ipair>, greater<ipair>>pq;
	pq.push(MP(0, 1));
	dis[src] = 0;
	while (!pq.empty())
	{
		int u = pq.top().ss;
		visited[u] = true;
		pq.pop();
		list<ipair>::iterator i;
		for (i = adj[u].begin(); i != adj[u].end(); i++)
		{
			int v = i->ff;
			int we = i->ss;
			if (!visited[v] && dis[v] > dis[u] + we)
			{
				dis[v] = dis[u] + we;
				pq.push(MP(dis[v], v));
			}
		}
	}
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, m;
	cin >> n;
	cin >> m;
	int *a=new int[n + 1];
	for (int i = 0; i <= n; i++)
		a[i] = 0;

	for (int i = 0; i<m; i++) {
		int l, r;
		cin >> l >> r;
		a[l]++;
		a[r + 1]--;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		a[i] += a[i - 1];
		if (a[i] == m)ans++;
	}
	cout << ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np
 
N,T = map(int,readline().split())
m = map(int,read().split())
AB = sorted(zip(m,m))
 
can_add = [0] * N
for n in range(N-1,0,-1):
    x = can_add[n]
    y = AB[n][1]
    can_add[n-1] = x if x > y else y
dp = np.zeros(T,np.int64)
 
answer = 0
for i,(a,b) in enumerate(AB):
    np.maximum(dp[a:], dp[:-a] + b, out = dp[a:])
    x = dp.max() + can_add[i]
    if answer < x:
        answer = x
print(answer)

Measured memory_bytes: 22432
#include <iostream>

using namespace std;

int main()
{
    int s = 0;
    cin >> s;
    int h = s/(60*60);
    s = s%(60*60);
    int m = s/60;
    s = s%60;
    
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


Measured memory_bytes: 3136
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		String s = sc.next();
        String ans = "";
        switch (s) {
          case "Sunny" :
            ans = "Cloudy";
            break;
          case "Cloudy" :
            ans = "Rainy";
            break;
          case "Rainy" :
            ans = "Sunny";
            break;
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21460
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		// 入力
		final int n;	// 1≦N≦100
		try(Scanner scan = new Scanner(System.in)) {
			n = scan.nextInt();
		}
		
		int result = n * (n + 1) /2;
		
		// 出力
		out.println(result);
		out.close();
	}

}


Measured memory_bytes: 9552