akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

typedef struct{
	int a;
	int b;
	int c;
}data;

int sortfnc(const void *x,const void *y){
	if(((data*)x)->a > ((data*)y)->a){return 1;}
	if(((data*)x)->a < ((data*)y)->a){return -1;}
	if(((data*)x)->b > ((data*)y)->b){return 1;}
	if(((data*)x)->b < ((data*)y)->b){return -1;}
	if(((data*)x)->c > ((data*)y)->c){return 1;}
	if(((data*)x)->c < ((data*)y)->c){return -1;}
	return 0;
}

int main(void) {
	int n,a,b,c,i,r=0;
	data d[1024];
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d%d%d",&a,&b,&c);
		if(a<=b&&a<=c&&b<=c){d[i].a=a;d[i].b=b;d[i].c=c;}
		else if(a<=b&&a<=c&&c<=b){d[i].a=a;d[i].b=c;d[i].c=b;}
		else if(b<=a&&b<=c&&a<=c){d[i].a=b;d[i].b=a;d[i].c=c;}
		else if(b<=a&&b<=c&&c<=a){d[i].a=b;d[i].b=c;d[i].c=a;}
		else if(c<=a&&c<=b&&a<=b){d[i].a=c;d[i].b=a;d[i].c=b;}
		else if(c<=a&&c<=b&&b<=a){d[i].a=c;d[i].b=b;d[i].c=a;}
	}
	qsort(d,n,sizeof(data),sortfnc);
	for(i = 1;i < n;i++){
		if(d[i-1].a==d[i].a&&d[i-1].b==d[i].b&&d[i-1].c==d[i].c){r++;}
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int a, b;
	cin >> a >> b;
	cout << (a * b);

	return 0;
}

Measured memory_bytes: 3640
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    if(input.split(" ").map(_.toInt).product%2==0){"Even"}else{"Odd"}
  }

  val tests=List("""3 4""" -> """Even""",
    """1 21""" -> """Odd""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}.zipWithIndex.map{case ((input,outputExpect),i)=>{
      val output=solve(input).trim();
      s"test${i+1}:"+(if(output==outputExpect){
        "Passed"
      }else{
        s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
      })
    }}.mkString("\n");
  }
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll a;
  IN(a);
  OUT(a+a*a+a*a*a);

  return 0;
}

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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int,int>

int main(){
	vector<int>v;
	f(3){
		int add;
		cin >> add;
		v.pb(add);
	}
	sort(v.begin(),v.end());
	cout<<v[0]+v[1]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    int dp[] = {-1,-1,-1,-1};
    ll ans = 1, color = 0;
    rep(i,0,N){
        if(V[i] == 0){
            color++;
            ans *= color;
            rep(j,0,4)if(dp[j] == -1){
                dp[j] = 0;
                if(j == 3)ans = 0; // invalid
                break;
            }
            continue;
        }
        int cnt = 0;
        rep(j,0,3){
            if(V[i] == dp[j] + 1){
                cnt++;
            }
        }
        if(cnt == 0){
            ans = 0;
            break;
        }
        rep(j,0,3){
            if(V[i] == dp[j] + 1){
                dp[j]++;
                break;
            }
        }
        ans *= cnt;
        ans %= MOD;
    }

    if(color != 3)ans *= 3;
    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

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

		int N = sc.nextInt();
		List<Integer> a = new ArrayList<>();
		int alice = 0;
		int bob = 0;

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

		Collections.sort(a, (i1,i2) -> { return i2 - i1; });

		alice = sum(a, 0, N, 2);
		bob = sum(a, 1, N, 2);

		System.out.println(alice - bob);
	}

	static int sum(List<Integer> a, int start, int end,  int n) {
		int sum = 0;
		int s = start;
		int e = end;

		for (int i = s; i < end; i += n) {
			sum += a.get(i);
		}

		return sum;
	}

	static class FastScanner {

		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

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

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

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

	        return tokenizer.nextToken("\n");
	    }

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

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

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

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

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

	}

}


Measured memory_bytes: 26964
#include<stdio.h>

int main(){
		int f=0,i;
		char s[101];
		scanf("%s",s);
		for(i=0;s[i]!=0;i++){
				if(f==0){
						if(s[i]=='C')f++;
				}
				if(f==1){
						if(s[i]=='F'){
								f++;
								break;
						}
				}
		}
		if(f==2)puts("Yes");
		else puts("No");
		return 0;
}


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

int main()
{
  bool ok=false;
  string s1,s2;
  cin>>s1>>s2;
  for(int i=0;i<s1.size();i++){
    s1 = s1.substr(s1.size()-1)+s1.substr(0,s1.size()-1);
    if(s1==s2){
      ok=true;
     break;
    } 
 }
  if(ok){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
}


Measured memory_bytes: 256
function Main(input) {
    var data = input.split("\n")
    var split = parseInt(data[0])/2;
	var cdn = [];
	for (var i = 0; i < data[1].length; i+=split) {
    	cdn.push(data[1].slice(i, i+split));
	}
	if(cdn[0]==cdn[1]) {
		console.log('Yes');
	}else{
		console.log('No');
	}
}

// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 23092
A = list(map(int, input().split()))
k = int(input())

ans = 0
for i in range(k):
    ptn = [
        A[0]*2+A[1]+A[2],
        A[0]+A[1]*2+A[2],
        A[0]+A[1]+A[2]*2,
    ]
    idx = ptn.index(max(ptn))
    A[idx] *= 2

    ans = max(ptn)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,c[10][10],e,f,g,h,t=0;
    cin>>n;
    string s;
    char a,b;
    for(int i=1;i<=9;++i)
    {
        for(int j=1;j<=9;++j)
            c[i][j]=0;
    }
    for(int i=1;i<=n;++i)
    {
        string s=to_string(i);
            int l=s.size();
            if(s[l-1]!='0'){
                int x=s[0]-'0';
                int y=s[l-1]-'0';

                c[x][y]++;
            }
    }
    for(int i=1;i<=9;++i)
    {
        for(int j=1;j<=9;++j)
            t=t+c[i][j]*c[j][i];
    }
    cout<<t<<endl;
    return 0;
}


Measured memory_bytes: 3672
N = int(input())
A = list(map(int, input().split()))
sum=1

if 0 in A:
    print(0)
else:
    for n in range(N):
        sum = sum * A[n]
        if sum>1000000000000000000:
            print(-1)
            break
    else:
        print(sum)

Measured memory_bytes: 21664
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int hmn = sc.nextInt();
        int nam[] = new int[200000];
        
        int now = 0;
        for(int i = 0;i < hmn;i++ ){
            now = sc.nextInt();
             nam[now]++;
             nam[now + 1]++;
             nam[now + 2]++;
        }
        Arrays.sort(nam);
        System.out.println(nam[200000-1]);
    }
}

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

main() {
  int N; cin >> N;
  int sum = 0;
  vi noten;
  rep(i, N) {
    int s;
    cin >> s;
    sum += s;
    if (s % 10) noten.push_back(s);
  }
  if (sum % 10 == 0) {
    if (noten.size() > 0) {
      sort(noten.begin(), noten.end());
      sum -= noten[0];
    } else {
      sum = 0;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define GET(a) cin >> (a)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;


int main()
{
	string s;
	cin >> s;
	
	int red = 0;
	int blue = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == '0') {
			red++;
		}
		else {
			blue++;
		}
	}
	
	cout << s.size() - abs(red - blue) << endl;
	
    return 0;
}

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

#define lli long long int
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define INF 1000000007
#define endl "\n"

lli a,n,k,ilk,son,fark,cvp=-INF,eski=-1;

int main(){
	cin>>k>>n;
	for (int i = 0; i < n; i++){
		eski=a;
		cin>>a;
		if(i==0){
			ilk=a;
		}
		if(i==n-1){
			son=a;
		}
		if(eski!=-1)
			fark=a-eski;
		cvp=max(cvp,fark);

	}
	fark=k-son+ilk;
	cvp=max(cvp,fark);
	cout<<k-cvp;
	//system("pause");
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){

  int n, C;

  cin >> n >> C;

  int D[C][C];
  //int c[n][n];
    int r;

  int auau;
  for (int i=0; i < C; i++){
    for(int j=0; j < C; j++){
      r = scanf("%d", &D[i][j]);
    }
  }
  int a[3][31] = {};

  for (int i=0; i < n; i++){
    for(int j=0; j < n; j++){
      r = scanf("%d", &auau);
      a[(i+j)%3][auau-1]++;
    }
  }
  // for(int i = 0; i < 3; i++){
  //   for (int j = 0; j < C; j++){
  //     cout << a[i][j];
  //   }
  //   cout << endl;
  // }
  long long res = 0;
  long long min_res = 999999999;
  for(int i=0; i < C; i++){
    for (int j = 0; j< C; j++){
      for (int k = 0; k < C; k++){
        if((i != j) && (j != k) && (i != k)){
          res = 0;
          for (int l = 0; l < C; l++){
            res += (a[0][l] * D[l][i] + a[1][l] * D[l][j] + a[2][l] * D[l][k]);
          }
          //cout << res << endl;
          min_res = min(min_res, res);
        }
      }
    }
  }

  cout << min_res << endl;


  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  rep(i,h)cin>>s[i];
  rep(i,h){
    rep(j,w){
      if(j)cout<<" ";
      for(k=j;k>=0;k--)
        if(s[i][k]=='c'){
          cout<<j-k;
          break;
        }
      if(k<0)cout<<-1;
    }
    cout<<endl;
  }

}

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

int main() {
    ll a,b,n;
    cin >> a >> b >> n;

    ll x;
    if (b <= n) {
        x = b-1;
    }
    else {
        x = n;
    }

    ll ans = (a*x)/b - a*(x/b);

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

Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
ll n;
int main()
{
	FAST
	cin>>n;
	ll digits=0, sum=0;
	FOR(i,0,n-1) {
		ll d, c; cin>>d>>c;
		digits+=c;
		sum+=d*c;
	}
	cout<<digits-1+(sum-1)/9<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n,m,x;
  cin >> n >> m >> x;
  vi a(m);
  REP(i,m) cin >> a[i];
  auto iter = upper_bound(ALL(a), x);
  int ans=a.end()-iter;
  cout << min(ans,m-ans) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll x[200001],s[200001];
	ll ruisekiwa[400001]={};
	ll ruisekimin=0;
	ll ans=0;
	scan(N);
	rep(i,N){
		scan(x[i]);scan(s[i]);
	}
	rep1(i,2*N-1){
		if(i%2){
			ruisekiwa[i]=ruisekiwa[i-1]+s[i/2];
		}
		else{
			ruisekiwa[i]=ruisekiwa[i-1]-(x[i/2]-x[i/2-1]);
		}
		ruisekimin=min(ruisekimin,ruisekiwa[i]);
		ans=max(ans,ruisekiwa[i]-ruisekimin);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 6528
from collections import deque, defaultdict
n,m=map(int,input().split())
ab = [[int(x) for x in input().split()] for _ in range(n-1+m)]
outs = defaultdict(list)
ins = defaultdict(int)

for v1,v2 in ab:
    outs[v1].append(v2)
    ins[v2]+=1 
ans=[0]*(n+1)
q=deque(int(x) for x in range(n) if ins[x] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2]-=1
        if ins[v2]==0:
            q.append(v2)
            ans[v2]=v1

for i in range(n):
    print(ans[i+1])

Measured memory_bytes: 49328
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.nextInt()
    println(problem97b(x))
}

fun problem97b(x: Int): Int {
    val array = Array(1010) { false }
    for (i in 1..x) {
        for (j in 2..x) {
            val num = Math.pow(i.toDouble(), j.toDouble())
            if (num <= x) array[num.toInt()] = true
        }
    }
    return array.lastIndexOf(true).let { if (it == -1) 1 else it }
}

Measured memory_bytes: 34560
mod=1e9+7,dp[3333][3333];
c,i,j;
main(n)
{
	scanf("%d\n",&n);
	dp[0][0]=1;
	for(;++i<n;)
	{
		c=getchar();
		for(j=0;j<=i;j++)
		{
			dp[i][j]=c=='<'?*dp[i-1]-dp[i-1][j]:dp[i-1][j];
		}
		for(;j--;)dp[i][j]=(1L*dp[i][j]+dp[i][j+1]+mod)%mod;
	}
	printf("%d",*dp[n-1]);
}

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

int main(){
  int n;
  cin>>n;
  int a,b[n];
  for(int i=0;i<n;i++){
    cin>>a;
    b[a-1]=i+1;
  }
  for(int i=0;i<n;i++){
    cout<<b[i];
    if(i!=n-1){cout<<' ';}
  }
}

Measured memory_bytes: 1280
#cording: utf-8

N = int(input())

x, u = [], []
for i in range(N):
    x_tmp, u_tmp = map(str, input().split())
    x_tmp = float(x_tmp)
    if u_tmp == 'BTC':
        x_tmp = x_tmp * 380000.0
    x.append(x_tmp)
    u.append(u_tmp)

print(sum(x))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <list>
#include <stdio.h>
 
using namespace std;
 
int main() {
    int i,j;
    int n;
    int x;
    char command[16];
    list<int> l;
    list<int>::iterator it_l; // lのイテレータ作成


	//fgets(command,16,stdin);
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s%d", command, &x);
        if(command[0] == 'i'){
            //cin >> x;
            l.push_front(x);
        }
        else if(command[0] == 'd' && command[6] == '\0'){
            //cin >> x;
            it_l = l.begin(); // lのイテレータを最初の要素に合わせる
            while(it_l != l.end()){ //ｘをもつ最初の要素（ノード）を探して削除
                if((*it_l)==x){
					l.erase(it_l);
					break;
                    /*このbreakが大切。　要素を消した後は、その要素で it_l++ すると　
                    「list iterator not incrementable」が出てできない
                    消した後も探索したい場合は、消す前にほかのに保存して
                    イテレーターを進めておくこと。
                    */
                }
                it_l++; 
 
            }
        }
        else if(command[0] == 'd' && command[6] == 'F'){
            l.pop_front();
        }
        else if(command[0] == 'd' && command[6] == 'L'){
            l.pop_back();
        }
        //else {cout << "error" << endl; }
    }
    
        //出力普通版
        /*
        it_l = l.begin(); // lのイテレータを最初の要素に合わせる
    while(it_l != l.end()){ //出力
        cout << *it_l;
        it_l++;
        if(it_l == l.end()){ //悪い書き方。　だが適切な改行を出すのにこれが簡単
            cout << endl;
            break;
        } 
        cout << ' ';
    }
        */
 
        //出力三項演算子版
        it_l = l.begin(); // lのイテレータを最初の要素に合わせる
    while(it_l != l.end()){ //出力
                printf("%d", *it_l);//cout << *it_l;
                it_l++;
                (it_l == l.end()) ? printf("\n") : printf(" ") ;
    }
 
        return 0;
}
 

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

int main(void){
  int n, t, a, ans = 0;
  vector<double> z;
  cin >> n >> t >> a;
  z.resize(n);
  for (int i = 0; i < n; i++) {
    int in;
    cin >> in;
    z[i] = abs(a - (t - in * 0.006));
  }
  for (int i = 1; i < n; i++)
    if (z[ans] > z[i])
      ans = i;
  cout << ans + 1 << endl;
}


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

using namespace std;
typedef long long ll;

ll N,K;
ll P[200000];

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> P[i];
    for(int i=1;i<N;i++) P[i] += P[i-1];
    ll max_p = P[K-1];
    for(int i=K;i<N;i++){
        max_p = max(max_p, P[i] - P[i-K]);
    }
    cout << fixed << setprecision(15) << ((double)max_p+K)/2.0 << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, M = map(int, input().split())
    S = [0] + list(map(int, input().split()))
    T = [0] + list(map(int, input().split()))

    dp = [[0] * (M+1) for _ in range(N+1)]
    for i in range(1, N+1):
        for j in range(1, M+1):
            if S[i] == T[j]:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] + 1
            else:
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
            dp[i][j] %= MOD

    return (dp[N][M] + 1) % MOD


if __name__ == '__main__':
    print(main())


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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILL(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){
  
  int n;
  cin >> n;
  vector<int> v;
  vector<P> w;
  REP(i,n){
    int x;cin >> x;
    v.push_back(x);
    if(i+1 != x)w.push_back({i+1,x});
  }
  if(w.size() >= 3){
    cout << "NO";
    return 0;
  }
  cout << "YES";





  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()

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

    int rep=0;
    rep += max(A,B);
    if(A>=B){
        A--;
    }else{
        B--;
    }

    rep+=max(A,B);

    PRINT(rep);


}


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

using ll = long long;

int main() {
    string s, t;
    cin >> s >> t;
    bool ans = false;
    for(int i = 0; i <= (int)t.size(); ++i) {
        ans |= s == t;
        auto c = t.back(); t.pop_back();
        t = c + t;
    }
    cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Control.Monad (replicateM)

cReadLn :: IO Int
cReadLn = fst . fromJust . C.readInt <$> C.getLine

getParms :: IO [Int]
getParms = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [w,h,n] <- getParms              :: IO [Int]
  xya     <- replicateM n getParms :: IO [[Int]]
  print $ area $ f w h xya

initialize
  :: Int -> Int -> ([Int],[Int])
initialize w h = ([1 .. w], [1 .. h])

cut :: ([Int],[Int]) -> [Int] -> ([Int], [Int])
cut (xs,ys) [x,y,a]
  | a == 1 = (xs1, ys)
  | a == 2 = (xs2, ys)
  | a == 3 = (xs,  ys3)
  | a == 4 = (xs,  ys4)
  where
    xs1 = dropWhile (<= x) xs
    xs2 = takeWhile (<= x) xs
    ys3 = dropWhile (<= y) ys
    ys4 = takeWhile (<= y) ys

f :: Int -> Int -> [[Int]] -> ([Int], [Int])
f w h = foldl cut (initialize w h) 

area (xs,ys) = length xs * length ys

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

int main() {
  string s,t; cin >>s >>t;
  int ans = 0;
  for (int i=0; i<3; i++){
    if (s.at(i) == t.at(i)) ans++;
  }
  cout <<ans;
  cout <<endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll mini = numeric_limits<ll>::max();
    string S, T;
    cin >> S >> T;
    rep(i, S.size() - T.size() + 1) {
        ll count = 0;
        rep(j, T.size()) {
            if(S[i + j] != T[j]) count++;
        }
        mini = min(mini, count);
    }
    cout << mini << endl;
    return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

// for flow algorithm
struct EdgeF{
  int to, cap, rev;
  EdgeF(int to_=0, int cap_ = 0, int rev_ = 0)
	:to(to_), cap(cap_), rev(rev_){}
};
using GraphF = vector<vector<EdgeF>>;

// add edge with (from -> to, capacity)
void add_edge(GraphF& G, int from, int to, int cap){
  G[from].emplace_back(to, cap, G[to].size());
  G[to].emplace_back(from, 0, G[from].size()-1);
}


/**
 * Dinic
 * O(VVE)
 * find increase path by bfs
 */
int max_flow(GraphF& G, int s, int t) {
  int N = G.size();
  int total = 0;
  for(bool up=true;up;){
	up = false;
	// bfs
    vector<int> level(N, -1);
	level[s] = 0;
    queue<int> Q;
	Q.push(s);
	while(!Q.empty()){
      int u = Q.front(); Q.pop();
      if(u == t) break;
      for(auto& e: G[u])
		if(e.cap > 0 && level[e.to] == -1){
		  Q.push(e.to);
		  level[e.to] = level[u] + 1;
		}
    }

	// dfs
    vector<bool> finished(N);
	function<int(int,int)> dfs = [&](int u, int f){
	  if(u == t || f == 0) return f;
	  if(finished[u]) return 0;
	  finished[u] = true;
	  for(auto& e: G[u]){
		if(level[e.to] > level[u]){
		  int fp = dfs(e.to, min(f, e.cap));
		  if(fp > 0){
			e.cap -= fp;
			G[e.to][e.rev].cap += fp;
			finished[u] = false;
			return fp;
		  }
		}
	  }
	  return 0;
	};

	while(true){
      int f = dfs(s, INF);
      if (f == 0) break;
      total += f;
	  up = true;
    }
  }
  return total;
}

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

  int V, E;
  cin >> V >> E;
  GraphF G(V);
  REP(i,E){
	int u, v, c;
	cin >> u >> v >> c;
	add_edge(G, u, v, c);
  }
  cout << max_flow(G, 0, V-1) << endl;

  return 0;
}

Measured memory_bytes: 3260
# input
N = int(input())
As = list(map(int, input().split()))

# Nの偶奇。区間幅がNの偶奇と一致すれば太郎君目線
oe = N % 2

# def print_list(lis):
#   for l in lis:
#     print(l)


# score[i][j][p] : Asのi番目を左端、j番目を右端とした時の最終スコア
#                  p = 0 が太郎君目線、p = 1 が次郎くん目線
score = [[None for _ in range(N)] for _ in range(N)]

for i in range(N):
  # 初期化
  # 区間長さ1であれば1通りしかない
  if oe == 1:
    score[i][i] = As[i]
  else:
    score[i][i] = -As[i]

# print_list(score)

for k in range(1, N):
  # 配列の幅を広げながら計算を進める
  for i in range(0, N-k):
    # if k == 0:
    #   continue
    j = i + k
    if i == N - 1:
      if (k + 1) % 2 == oe:
        score[i][j] = score[i][j-1] + As[j]
      else:
        score[i][j] = score[i][j-1] - As[j]
    else:
      # print(i,j)
      if (k + 1) % 2 == oe:
        score[i][j] = max(score[i+1][j] + As[i], score[i][j-1] + As[j])
      else:
        score[i][j] = min(score[i+1][j] - As[i], score[i][j-1] - As[j])
    # print_list(score)

print(score[0][N-1])


Measured memory_bytes: 173448
#ABC 067 B - Snake Toy
N,K = map(int,input().split())
ln = list(map(int,input().split()))

an = []
for i in range(K):
    an.append(max(ln))
    del ln[ln.index(max(ln))]

k = 0 
for i in range(len(an)):
    k += an[i]

print(str(k))

Measured memory_bytes: 9092
#include <stdio.h>

int main()
{
	int red, green, blue, num;
  	scanf("%d%d%d", &red, &green, &blue);
  	num = red * 100 + green * 10 + blue;
  	if (num % 4){
    	printf("NO");
    } else {
    	printf("YES");
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <utility>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <stack>
#define N 100010

using namespace std;

char str[N];

int main()
{
    scanf("%s",str);
    int len = strlen(str);
    if (str[0]==str[len-1])
    {
        if (len%2)
        {
            printf("Second\n");
        }
        else
        {
            printf("First\n");
        }
    }
    else
    {
        if (len%2)
        {
            printf("First\n");
        }
        else
        {
            printf("Second\n");
        }
    }
    return 0;
}


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

int calc(int n,int a[10],int k){
	
	int count=0,j=log10(n);
	for(int i=0;i<=j;i++){
		int num=n/pow(10,i);
		int num1=num%10;
		for(int x=0;x<k;x++){
			if(num1==a[x])count++;
		}
	}
	if(count==0)return n;
	
	return calc(n+1,a,k);	
}

int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int N,K;
	cin>>N>>K;
	
	int a[K];
	for(int i=0;i<K;i++){
		cin>>a[i];
	}
	
	int ans= calc(N,a,K);
	cout<<ans;	
	return 0;
	
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<vector>
#include<set>

int main(){
	int x, n;
	std::cin >> x >> n;
	std::set<int> s;
	for(int i=0; i<n; i++){
		int p;
		std::cin >> p;
		s.insert(p);
	}

	int ans = 1e9;
	for(int i=0; i<=101; i++){
		if(!s.count(i) && abs(i-x) < abs(ans-x)){
			ans = i;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3640
N = gets.to_i
S = gets.chomp

a = Array.new(N)
b = Array.new(N)
N.times do |i|
  if i==0
    if S[0] == "E"
      a[0] = 1
    else
      a[0] = 0
    end
  else
    if S[i] == "E"
      a[i] = a[i-1] + 1
    else
      a[i] = a[i-1]
    end
  end
end

N.times do |i|
  b[i] = a[N-1]-a[0] if i==0
  b[i] = (i-a[i-1]) + (a[N-1]-a[i]) if i>0
end

p b.min

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

int main(){
  string s,t[4]={"maerd","remaerd","esare","resare"};cin>>s;
  reverse(s.begin(),s.end());
  bool f;
  
  while(s.size()){
    f=0;
    REP(i,4) if(!(s.find(t[i]))){
      s=s.substr(t[i].size());
      f=1;
    }
    if(!f) break;
  }
  
  cout<<(f?"YES":"NO");
}

Measured memory_bytes: 512
n,k = map(int,input().split())
cast = 0
mulp = 1
while mulp < k:
  mulp *= 2
  cast += 1
  
ans = 0.0
for i in range(1,1+n):
  if mulp * i >= 2 * k and cast > 0:
    cast -= 1
    mulp //= 2
  ans += 2 ** (-cast)
print(ans/n)

Measured memory_bytes: 3064
#include<iostream>
#include<cassert>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define rep(i, n) for ( int i = 0; i < (int)n; i++ )
static const int N_MAX = 100000;
static const int MAX_LOG_V = 17;
static const int INF = 2000000000;

typedef long long ll;

int N;
vector<pair<int, int> > G[N_MAX];
int root;

int parent[MAX_LOG_V][N_MAX];
int depth[N_MAX], W[N_MAX];

void dfs(int v, int p, int d, int w){
  parent[0][v] = p;
  depth[v] = d;
  W[v] = w;
  for ( int i = 0; i < G[v].size(); i++ ){
    if ( G[v][i].first != p ) dfs(G[v][i].first, v, d + 1, w + G[v][i].second);
  }
}

void init(int V){
  root = 0;
  W[root] = 0;
  dfs(root, -1, 0, 0);
  for ( int k = 0; k + 1 < MAX_LOG_V; k++ ){
    for ( int v = 0; v < V; v++ ){
      if ( parent[k][v] < 0 ) parent[k + 1][v] = -1;
      else parent[k + 1][v] = parent[k][parent[k][v]];
    }
  }
}

int lca(int u, int v){
  if (depth[u] > depth[v]) swap(u, v);
  for ( int k = 0; k < MAX_LOG_V; k++ ){
    if ((depth[v] - depth[u]) >> k & 1 ){
      v = parent[k][v];
    }
  }
  if ( u == v ) return u;
  for ( int k = MAX_LOG_V - 1; k >=0 ; k-- ){
    if (parent[k][u] != parent[k][v] ){
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}

int getDist(int s, int t){
  int l = lca(s, t);
  return W[s] + W[t] - W[l]*2;
}

int getNode(int B, int H){
  int v = B;
  for ( int k = 0; k < MAX_LOG_V; k++ ){
    if (H >> k & 1) v = parent[k][v];
  }
  return v;
}
int bsearch(int s, int t, int D ){
  int B = s;
  int H = t;
  int M, left, right;
  int ans = INF;
  for ( int i = 0; i < 20; i++ ){
    M = getNode(s, depth[s] - depth[B] + (depth[B] - depth[H])/2);
    left = W[s] - W[M];
    right = D - left;
    ans = min(ans, max(left, right));
    if ( left == right ) return ans;
    else if ( left < right ) B = parent[0][M];
    else if ( left > right) H = M;
  }
  return ans;
}

int search(int s, int t, int D){
  int p = s, w = 0, ans = INF;
  while(1){
    ans = min(ans, max(w, D-w));
    if ( p == t ) break;
    p = parent[0][p];
    w = W[s] - W[p];
  }
  return ans;
}

int solve(int a, int b, int c){
  int S = a;
  int T = b;
  int d, D= getDist(a, b);
  d = getDist(a, c);
  if ( D < d ){
    S = a;
    T = c;
    D = d;
  }
  d = getDist(b, c);
  if ( D < d ){
    S = b;
    T = c;
    D = d;
  }

  int L = lca(S, T);
  int SL = getDist(S, L);
  int LT = getDist(L, T);
  if ( SL == LT ) return SL;
  if ( SL > LT ){
    return bsearch(S, L, D);
  } else if ( SL < LT ){
    return bsearch(T, L, D);
  }
}

int main(){
  int Q, u, v, w, a, b, c;
  cin >> N >> Q;
  for ( int i = 0; i < N-1; i++ ) {
    cin >> u >> v >> w;
    u--; v--;
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
  }

  init(N);

  for ( int i = 0; i < Q; i++ ) {
    cin >> a >> b >> c; a--; b--; c--;
    cout << solve(a, b, c) << endl;
  }

  return 0;
}


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

			int n = in.nextInt();
			int m = in.nextInt();

			if (n == 0 && m == 0)break;

			int result = 0, now = 0;
			int[] a = new int[n];

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

			for (int i = 0; i < a.length; i++) {
				for (int j = i + 1; j < a.length; j++) {
					now = a[i] + a[j];
					if (now <= m && now > result) {
						result = now;
					}
				}
			}

			if (result == 0) {
				System.out.println("NONE");
			}else{
				System.out.println(result);
			}
		}

	}
}

Measured memory_bytes: 45280
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

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

ll n, x[MAX_10p5 * 2], sorted[MAX_10p5 * 2], ansL, ansR;

int main() {
	cin >> n;
	repi(i, 0, n) {
		rd(x[i]);
		sorted[i] = x[i];
	}
	sort(sorted, sorted + n);
	ansL = sorted[n / 2 - 1];
	ansR = sorted[n / 2];
	repi(i, 0, n) {
		if (x[i] <= ansL) wrln(ansR);
		else wrln(ansL);
	}
	return 0;
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
const string sp = " ";

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

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

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

class unionfind {
private:
	int par[200010], rankth[200010], sizeth[200020];
public:
	void init(int n) {
		rep(i, n) {
			par[i] = i;
			rankth[i] = 0;
			sizeth[i] = 1;
		}
	}
	int root(int x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

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

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

int n, l;
int a[100010];
signed main() {
	cin >> n >> l;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n - 1) {
		if (l <= a[i] + a[i + 1]) {
			printf("Possible\n");
			rep(j, i) printf("%lld\n", j + 1);
			for (int j = n - 1; j > i; j--) printf("%lld\n", j);
			return 0;
		}
	}
	printf("Impossible\n");
}

Measured memory_bytes: 1664
x,y,z,k = gets.split.map(&:to_i)
X,Y,Z = 3.times.map{ gets.split.map(&:to_i).sort.reverse }
ANS = []

(1 .. x).each do |a|
  (1 .. y).each do |b|
    break if a * b > k
    (1 .. z).each do |c|
      break if a * b * c > k
      ANS << X[a-1] + Y[b-1] + Z[c-1]
    end
  end
end

puts ANS.sort.reverse.shift(k)

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	ll N;
	
	cin >> N;
	
	if(N % 2 != 0){
		cout << 0 << endl;
	}else{
		ll ans = 0;
		N /= 2;
		while(N >= 5){
			N /= 5;
			ans += N;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
ans = 0
while s:
  a = s[0]
  b = s[-1]
  if a == b:
    s = s[1:-1]
  elif a == "x" and b != "x":
    s = s[1:]
    ans += 1
  elif a != "x" and b == "x":
    s = s[:-1]
    ans += 1
  else:
    print(-1)
    exit()
print(ans)

Measured memory_bytes: 3316