akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			int n = sc.nextInt();
			int[] x = new int[n];
			int min = 100;
			int max = 0;
			
			for(int i=0;i<n;i++) {
				x[i] = sc.nextInt();
				min = Math.min(min, x[i]);
				max = Math.max(max, x[i]);
			}
			
			int ret = Integer.MAX_VALUE;
			int reti = 0;
			
			for(int i=min;i<=max;i++) {
				reti = 0;
				for(int j=0;j<n;j++) {
					reti += Math.pow((x[j]-i), 2);
				}
				
				ret = Math.min(ret, reti);
			}
			
			System.out.println(ret);
		}
	}


Measured memory_bytes: 23508
#include <cstdio>
#include <cstring>
#include <cctype>
#include <set>
using namespace std;
typedef long long int64;
inline int64 read(int f = 1, int64 x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f  = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
int64 a, b, p, l1, r1, l2, r2, ans;
int lg(int64 s) { return s?lg(s>>1)+1:0; }
int main()
{
    a = read(), b = read(), ans = b-a+1;
    for( ; lg(a) == lg(b)&&a&&b; a ^= (1ll<<(lg(a)-1)), b ^= (1ll<<(lg(b)-1)));
    p = 1ll<<(lg(b)-1);
    l1 = b+1, r1 = p+(1ll<<lg(b-p))-1;
    if(l1 <= r1) ans += r1-l1+1;
    l2 = max(a+p, b+1), r2 = (p<<1)-1;
    if(l2 <= r2) ans += r2-l2+1;
    if(l1 <= r1&&l2 <= r2&&max(l1, l2) <= min(r1, r2)) ans -= min(r1, r2)-max(l1, l2)+1;
    printf("%lld\n", ans);
    return 0;
}


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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;
const double PI = acos(-1);

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()


int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double longAngle = 360.0 / 60 * M;
    double shortAngle = 360.0 / 720 * (60*H+M);
    double angle = abs(longAngle - shortAngle);
    double ang = PI*(angle)/180.0;
    double ans_square = A*A + B*B -2*A*B*cos(ang);
    cout << setprecision(20) << pow(ans_square, 0.5) <<endl;
}


Measured memory_bytes: 4356
#include<bits/stdc++.h>
using namespace std;
long long n,k,tot,ans = 9223372036854775807,a,f[200005];
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a;
		f[i] = f[i - 1] + a;
		tot += a;
	}
	for(int i = 1; i < n; i++)
		ans = min(ans,abs(tot - 2 * f[i]));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	long long N, M;
	cin >> N >> M;
	long long i;
	vector<pair<long long,long long>> AB;
	for (i = 0; i < N; i++) {
		long long a, b;
		cin >> a >> b;
		AB.push_back(make_pair(a, b));
	}
	sort(AB.begin(),AB.end());
	long long S = 0;
	i = 0;
	while(M > 0) {
		if (AB.at(i).second < M) {
			S += AB.at(i).first * AB.at(i).second;
			M -= AB.at(i).second;
		}
		else {
			S += AB.at(i).first * M;
			M = 0;
		}
		i++;
	}
	cout << S;

}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define vi vector<int>
#define pb(a) push_back(a)
using namespace std;

typedef long long ll;

typedef pair<ll,int> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 100002

map<int,int> dp[MAX_N];
vector<edge> G1[MAX_N],G2[MAX_N],G3[1000002];
int dp1[MAX_N];
priority_queue<P2,vector<P2>,greater<P2>> que;

P1 a[200001]={};

int main() {
	ll w,h;
	cin>>w>>h;
	ll p=0,q=0;

	rep(i,w){
		cin>>p;
		a[i]=P1(p,1);
	}
	rep(i,h){
		cin>>q;
		a[i+w]=P1(q,0);
	}
	sort(a,a+h+w);
	p=0;
	q=0;
	ll t=0;
	rep(i,h+w){
		ll n=a[i].first;
		ll r=a[i].second;
		if(r==1){
			t+=n*(h+1-q);
			p++;
		}else{
			t+=n*(w+1-p);
			q++;
		}
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 36608
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  map<int,bool> memo;

  int N;
  cin >> N;

  int cnt=0;

  for(int i=0;i<N;i++){
    int p[3];
    cin >> p[0] >> p[1] >> p[2];

    sort(p,p+3);

    int k=((p[0]-1)*1000+(p[1]-1))*1000+(p[2]-1);

    if(memo.find(k)!=memo.end()){
      cnt++;
    }else{
      memo[k] = true;
    }
  }

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3192
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");

  //   String nyu=sc.nextLine();
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu[3]);


//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/
int flag=0;
if(A<=B){
flag=1;
}

if(A==1){
System.out.println(flag);
}else{
System.out.println(flag+(A-1));

}




	}
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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


    int K, X;
    cin >> K >> X;

    REP(i, 2 * K - 1) {
        cout << X - K + 1 + i;
        if (i == 2 * K - 2) {
            cout << "\n";
        } else {
            cout << " ";
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N){
    REP(i, N+1){
        if((ll)(i*1.08)== N){
            cout << i << endl;
            return;
        }
    }
    cout << ":(" << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include "stdio.h"

char s[4][20] = {};
char t[4] = {};

int main() {
	for (int i = 1; i <= 3; i++) {
		scanf("%s", s[i]);
		t[i] = s[i][0]-32;
	}
	for (int i = 1; i <= 3; i++) {
		printf("%c", t[i]);
	}
}

Measured memory_bytes: 128
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    vl v;
    v.pb(0);
    rep(i,n)
    {
        ll c;
        cin>>c;
        v.pb(c);
    }
    ll fact[n+1]={0};
    fact[0]=1;
    for(int i=1;i<=n;i++)
    {
        fact[i]=(fact[i-1]*i);
        fact[i]%=mod;
    }
    ll pre[n+1];
    pre[1]=1;
    for(int i=2;i<=n;i++)
    {
        ll add=modInverse(i);
        pre[i]=pre[i-1]+add;
        pre[i]%=mod;
    }
    ll ans=0;
    for(int i=1;i<n;i++)
    {
        ll temp=v[i+1]-v[i];
        temp%=mod;
        temp*=(pre[i]);
        temp%=mod;
        ans+=temp;
        ans%=mod;
    }
    ans*=fact[n-1];
    ans%=mod;
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 14452
h, w = map(int, input().split())
As = [list(input()) for i in range(h)]

x,y = 0,0

ans = "Possible"

while True:
    cnt = 0
    tmpX,tmpY = x,y
    # 上か左が"#" -> error
    if (x > 0 and As[y][x-1] == "#") or (y > 0 and As[y-1][x] == "#"):
        ans = "Impossible"
        break
    
    # 右も下も"#" -> error
    if x < w - 1 and As[y][x+1] == "#" and y < h - 1 and As[y+1][x] == "#":
        ans = "Impossible"
        break
    
    # 右に移動
    if x < w - 1 and As[y][x+1] == "#":
        As[y][x] = "."
        x += 1
    # 左に移動
    if y < h - 1 and As[y+1][x] == "#":
        As[y][x] = "."
        y += 1
        
    # 右下に到着
    if x == w - 1 and y == h - 1:
        As[y][x] = "."
        break

    # 移動していない
    if x == tmpX and y == tmpY:
        ans = "Impossible"
        break
        
for A in As:
    if "#" in A:
        ans = "Impossible"

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n;
string s,a,b;
int32_t main(){
CODE_START;
cin>>n;
cin>>s;
if(n%2==1){
    rc("No");
}else {
    for(ll i=0;i<n/2;i++)
    a.pb(s[i]);
    for(ll i=n/2;i<n;i++)
    b.pb(s[i]);
    if(a==b){
        cout<<"Yes";
    }else cout<<"No";
}
}


Measured memory_bytes: 256
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

use std::io::{stdout, BufWriter, Write};

fn main() {
   let out = stdout();
   let mut out = BufWriter::new(out.lock());
   input! {
      n:usize,k:usize
   }

   let mut ans = 0_usize;

   for i in k..=n + 1 {
      let max = (i * (n + n - i + 1)) / 2;
      let min = ((i - 1) * i) / 2 - 1;
      ans += max - min;
      ans %= 1_000_000_007;
      //println!("{}", ans);
   }
   println!("{}", ans);
}


Measured memory_bytes: 2164
from functools import reduce

mod = 10 ** 9 + 7


def comb(n, r):
    r = min(n - r, r)
    if r < 0:
        return 0

    if r == 0:
        return 1

    nu = reduce(lambda a, b: (a * b) % mod, range(n, n - r, -1))
    de = reduce(lambda a, b: (a * b) % mod, range(1, r + 1))
    return ((nu % mod) * pow(de, mod - 2, mod)) % mod


def main():
    n, k = [int(e) for e in input().split()]

    for ki in range(1, k + 1):
        ans = comb(n - k + 1, ki) * comb(k - 1, ki - 1)
        print(ans % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45040
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, k; cin >> h >> w >> k;
  vector<string> S(h); rep(i, h) cin >> S[i];
  vector<string> Sorig(h);
  copy(all(S), Sorig.begin());
  int ans = 0;
  rep(i, 1<<h) {
    rep(j, 1<<w) {
      copy(all(Sorig), S.begin());
      rep(k, h) {
        if((i>>k)&1) {
          rep(l, w) S[k][l] = 'o';
        }
      }
      rep(k, w) {
        if((j>>k)&1) {
          rep(l, h) S[l][k] = 'o';
        }
      }
      int cnt = 0;
      rep(k, h) rep(l, w) {
        if(S[k][l] == '#') cnt++;
      }
      if(cnt == k) ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3688
#include <stdio.h>

#define SOSUU_TABLE_MAX 1000000

int sosuu_count[SOSUU_TABLE_MAX+1];

void make_sosuu_table(void) {
	int i,j;
	for(i=0;i<=SOSUU_TABLE_MAX;i++)sosuu_count[i]=1;
	sosuu_count[0]=sosuu_count[1]=0;
	for(i=2;i<=SOSUU_TABLE_MAX;i++) {
		if(sosuu_count[i]) {
			for(j=i+i;j<=SOSUU_TABLE_MAX;j+=i)sosuu_count[j]=0;
		}
	}
	for(i=1;i<=SOSUU_TABLE_MAX;i++) {
		sosuu_count[i]+=sosuu_count[i-1];
	}
}

int count_sosuu(int p,int m) {
	int min=p-m;
	int max=p+m;
	if(min<1)min=1;
	if(max>SOSUU_TABLE_MAX)max=SOSUU_TABLE_MAX;
	return sosuu_count[max]-sosuu_count[min-1];
}

int main(void) {
	int n,i;
	int p,m;
	int money_sum;
	make_sosuu_table();
	while(1) {
		scanf("%d",&n);
		if(n==0)break;
		money_sum=0;
		for(i=0;i<n;i++) {
			scanf("%d%d",&p,&m);
			money_sum+=count_sosuu(p,m)-1;
		}
		printf("%d\n",money_sum);
	}
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

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

const int MAX = 1000000;

int main()
{
	vi hamming;
	for(int i=1; i<=MAX; i*=2){
		for(int j=i; j<=MAX; j*=3){
			for(int k=j; k<=MAX; k*=5){
				hamming.push_back(k);
			}
		}
	}
	sort(hamming.begin(), hamming.end());
	
	int m;
	while(scanf("%d", &m), m){
		int n;
		scanf("%d", &n);
		m = distance(hamming.begin(), lower_bound(hamming.begin(), hamming.end(), m));
		n = distance(hamming.begin(), upper_bound(hamming.begin(), hamming.end(), n));
		printf("%d\n", n-m);
	}
	
	return 0;
}

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

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> to;
  for(int i=0; i<r; i++){
    int tt;
    cin >> tt;
    tt--;
    to.push_back(tt);
  }

  d = Matrix(n, vector<int>(n, INF));
  
  for (int i = 0; i < n; i++) d[i][i] = 0;
  
  sort(to.begin(), to.end());

  for (int i = 0; i < m; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    from--;
    to--;
    d[from][to] = min(d[from][to], cost);
    d[to][from] = min(d[to][from], cost);
  }
  
  warshall_floyd(n);
  
  long long ans=INF;
  
  do{
    long long ans_tmp=0;
    for(int i=0; i<r-1; i++){
      ans_tmp += d[to[i]][to[i+1]];
    }
    ans = min(ans, ans_tmp);
  }while(next_permutation(to.begin(),to.end()));

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

Measured memory_bytes: 384
p = str(input()).upper()
line = []
 
while True:
    tmp_line = str(input())
    if tmp_line == 'END_OF_TEXT':
        break
    line += tmp_line.upper().split()
 
ans = 0

for tmp_word in line:
    if tmp_word == p:
        ans += 1
 
print("%d"%(ans))


Measured memory_bytes: 5560
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define Inf 100000000000ll
#define MAXN 100000
#define ll long long
using namespace std;

int counts[111];


int main() {
    int K,T;

    
    cin>>K>>T;
    int pop = 0;
    for(int i=1;i<=T;i++) {
        int x;
        cin>>x;
        counts[i]=x;
        pop=max(pop,x);
    }
    
    int ans;
    if (K%2==0) {
        if (pop <= K/2) {
            ans = 0;
        }
        if(pop==K/2+1) {
            ans = 1;
        }
        if (pop>K/2+1) {
            ans = 1+2*(pop-1-K/2);
        }
    } else {
        if (pop <= (K+1)/2) {
            ans = 0;
        } else {
            ans = 2*(pop-(K+1)/2);
        }
    }
    
    cout << ans << endl;
    
    
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;

ll n,m;
ll cnt;
ll a[3]={3,5,7};
void dfs(ll s,ll t){
    if(t==m){
        return;
    }
    rep(i,3){
        ll r=s*10+a[i];
        if(r<=n){
            string q=to_string(r);
            set<char> w;
            rep(i,t+1){
                w.insert(q[i]);
            }
            if(w.size()==3) cnt++;
        }
        dfs(s*10+a[i],t+1);
    }
    return;
}
int main()
{
    cin >> n;
    ll p=n;
    m=0;
    while(p){
        p/=10;
        m++;
    }
    cnt=0;
    dfs(0,0);
    cout << cnt << endl;
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 4e2+5, inf = 1e9+7;
int n, k, i, j;
int A[N], dp[N][N];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    cin>>n;
    rep(i, 1, n+1){
        cin>>A[i];
        int p=A[i];
        sep(j, i-1, 0){
            p += A[j];
            dp[j][i] = dp[j][j]+dp[j+1][i]+p;
            rep(k, j+1, i) dp[j][i] = min(dp[j][i], dp[j][k]+dp[k+1][i]+p);
        }
    }
    cout<<dp[1][n];
}

Measured memory_bytes: 1536
#!/usr/bin/env ruby
# encoding: utf-8

n = gets.chomp.to_i
while n > 0
	a = gets.split.map(&:to_i)
	a.sort!
	if a[2]**2 == a[0]**2 ++ a[1]**2
		puts "YES"
	else
		puts "NO"
	end
	a.clear
	n -= 1
end

Measured memory_bytes: 6108
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import Data.Char

main :: IO ()
main = do
  [h,w] <- map read . words <$> getLine
  ss <- replicateM h $ words <$> getLine
  nya ss $ \y x -> putStrLn $ chr (x + 65) : show y

nya :: [[String]] -> (Int -> Int -> a) -> a
nya [] con = undefined
nya (x:xs) con = case elemIndex "snuke" x of
  Just y -> con 1 y
  Nothing -> nya xs $ \p q -> con (p+1) q

Measured memory_bytes: 1020
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
prique que;
signed main() {
	int n, m;
	cin >> n >> m;
	rep(i, n) {
		int a;
		cin >> a;
		que.push(a);
	}
	rep(i, m) {
		int a = que.top();
		que.pop();
		que.push(a / 2);
	}
	int ans = 0;
	rep(i, n) {
		ans += que.top();
		que.pop();
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll a,b;cin>>a>>b;
  if(a+b>=10)out("error");
  else out(a+b);

  return 0;
}


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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	string s;
	cin >> s;
	for(int i=0; i<3; i++) {
		if(s[i] == s[i+1])
			return !(cout << "Bad");
	}
	cout << "Good";
}

Measured memory_bytes: 764
# Inputs

n, m, l = list(map(int, input().split()))
A = []
B = []
for i in range(n):
    A.append(list(map(int, input().split())))
for j in range(m):
    B.append(list(map(int, input().split())))

# Calculation
C = [[0 for a in range(l)] for b in range(n)]

for row in range(n):
    for col in range(l):
        for num in range(m):
            C[row][col] += A[row][num] * B[num][col]

# Output
for k in C:
    print(*k)


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

int main(){
    int h,w;
    cin >> h >> w;
    
    string s;
    vector<string> ans(h);
    for (int i = 0;i < h;i++){
        cin >> s;
        ans.at(i) = s;
    }
    for (int i = 0;i < h;i++){
        cout << ans.at(i) << endl;
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
Height = []
Good = []
for i in range(N):
    Height.append(H[i])
    Good.append(0)
for i in range(M):
    A, B = map(int, input().split())
    if Height[A - 1] < Height[B - 1]:
        Good[A - 1] = 1
    elif Height[A - 1] > Height[B - 1]:
        Good[B - 1] = 1
    else:
        Good[A - 1] = 1
        Good[B - 1] = 1
n = 0
for i in range(N):
    if Good[i] == 0:
        n += 1
print(n)

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

using namespace std;

const int N=5e5+5;

using ll=long long;

int u,v,k,d,c,n,m,dp[N][19],ans[N],tc;

pair<int,int> a[N];

int main(){
	scanf("%d%d",&n,&m);
	int l=1,r=n;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a[i].first,&a[i].second);
		l=max(a[i].first,l);
		r=min(a[i].second,r);
	}
	printf("%d\n",max(r-l+1,0));

}



Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int p[100],j,i,n,m,t[100],a,b,c,d;

	scanf("%d",&n);
	for(i = 0; i < n; i++){
		t[i] = 0;
		p[i] = 1;
	}

	for(i = 0; i < n * (n-1)/2; i++){
		scanf("%d %d %d %d",&a,&b,&c,&d);

		if(c > d)
			t[a-1]+= 3;
		else if(c == d){
			t[a-1]+= 1;
			t[b-1]+= 1;
		}
		else
			t[b-1]+= 3;
	
	}

	for(i = 0; i < n ; i ++){
		for(j = 0; j < n; j++){
			if(t[i] < t[j])
				p[i]++;
		}
		printf("%d\n",p[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int n;
  cin>>n;
  if(n<1000)cout<<"ABC"<<endl;
  else if(n>=1000)cout<<"ABD"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int H, W, N;
set<int> S[MAX_N];

void solve() {
	cin >> H >> W >> N;
	rep(i, 0, N) {
		int a, b; cin >> a >> b; a--; b--;
		S[b].insert(a);
	}
	rep(i, 0, W + 1) S[i].insert(H);
	rep(i, 0, H + 1) S[W].insert(i);
	int ans = inf;
	int x = 0;
	rep(i, 0, W) {
		x++;
		int t = *S[i].lower_bound(x);
		MIN(ans, t);
		if(t == x) break;
		while(x < H) {
			if(!S[i + 1].count(x)) break;
			else x++;
		}
		if(x == H) break;
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 42496
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  int T = 0;
  rep(i, 4) {
    int s; cin >> s;
    T += s;
  }
  int x = T / 60;
  int y = T % 60;
  println(x);
  println(y);
  return 0;
}

Measured memory_bytes: 1192
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

template<typename T>
vector<T> smallest_prime_factors(T n) {

    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;


    for (T i = 2; i * i <= n; i++) {

        // 素数だったら
        if (spf[i] == i) {

            for (T j = i * i; j <= n; j += i) {

                // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }

    return spf;
}

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

    auto spf = smallest_prime_factors(N);

    map<int, int> p;
    reple(i, 2, N)
    {
        int tmp = i;
        while (tmp != 1)
        {
            auto s = spf[tmp];

            p[s]++;

            tmp /= s;
        }
    }

    ll ans = 1;
    for (auto x : p)
    {
        ans *= (x.second + 1);
        ans %= MOD;
    }

    cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(){

    vector<long long> v(3);
    cin >> v[0] >> v[1] >> v[2];

    if(v[0] % 2 == 0 || v[1] % 2 == 0 || v[2] % 2 == 0){
        cout << 0 << endl;
    }
    else{
        sort(v.begin(), v.end());
        cout << v[0] * v[1] << endl;
    }


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <unordered_map>

using namespace std;

class Node{
private:
    int name;
    long long cnt;
    long long sum;
    list<Node*> next;
public: 
    Node(int n){
        name = n;
        cnt = 0;
        sum = 0;
    }
    void setNext(Node* n){
        next.emplace_back(n);
    }
    void setCnt(int n){
        cnt += n;
    }
    void sumCnt(int n){
        sum += cnt+n;
        for(auto itr = next.begin(); itr != next.end(); ++itr){
            (*itr)->sumCnt(cnt+n);
        }
    }
    void sumcnt(int n){

    }
    long long printSum(){
        return sum;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    unordered_map<int, Node*> Map;
    int count = 1;
    for(int i = 1; i <= N; ++i){
        Node* tmp = new Node(i);
        Map.insert(make_pair(count, tmp));
        count++;
    }
    for(int i = 1; i <= N-1; ++i){
        int a, b;
        cin >> a >> b;
        Map[a]->setNext(Map[b]);
    }
    for(int i = 0; i < Q; ++i){
        int p, x;
        cin >> p >> x;
        Map[p]->setCnt(x);
    }
    Map[1]->sumCnt(0);
    for(int i = 1; i <= N; ++i){
        cout << Map[i]->printSum() << " ";
    }
    cout << endl;
    

    return 0;
}

Measured memory_bytes: 32200
import sys

n, k = map(int, sys.stdin.readline().split())

h = list(map(int, input().split()))

dp = [1000000000] * n
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = min(dp[i + j], (dp[i] + abs(h[i] - h[i + j])))

print(dp[n - 1])

Measured memory_bytes: 52448
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>
#include <array>
#include <utility>
#include <functional>
#include <stack>

using namespace std;
typedef long long Int;
#define REP(i , x) for(int i = 0 ; i < x ; ++i)

typedef pair<int, int> P;



int main()
{
	stack<int> st;

	int n;
	while (cin >> n){
		if (n){
			st.push(n);
		}
		else{
			cout << st.top() << endl;
			st.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,k,v[60],f[60][60][105];
bool b[60][60][105];
int dp(int l,int r,int k){
	if (b[l][r][k]) return f[l][r][k];
	b[l][r][k]=1;
	int &ans=f[l][r][k];
	ans=0;
	if (!k) return 0;
	if (l==r){
		if (k&&v[l]>0) return ans=v[l];
		return 0;
	}
	int te;
	te=dp(l+1,r,k-1)+v[l];
	if (te>ans) ans=te;
	te=dp(l,r-1,k-1)+v[r];
	if (te>ans) ans=te;
	if (k>1){
		te=dp(l+1,r,k-2);
		if (te>ans) ans=te;
		te=dp(l,r-1,k-2);
		if (te>ans) ans=te;
	}
	return ans;
}
int main(){
	scanf("%d%d",&n,&k);
	fo(i,1,n) scanf("%d",&v[i]);
	printf("%d\n",dp(1,n,k));
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        for(int i = 0; i < 3; i++){
            int d = sc.nextInt();
        }
        int y = sc.nextInt();
        int n = sc.nextInt();
        if(y - x > n){
            System.out.println(":(");
        }else{
            System.out.println("Yay!");
        }
        
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define readvec(vec)    \
  for (auto& e : vec) { \
    cin >> e;           \
  }
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> g(n + 1);
  vecint l(m), r(m), x(q), y(q);
  vecint ans(q, 0);
  REP(i, m) cin >> l[i] >> r[i];
  REP(i, q) cin >> x[i] >> y[i];
  REP(i, m) { g[l[i]].push_back(r[i]); }
  // cout << endl;
  REP(i, n + 1) { sort(all(g[i])); }
  // REP(i, n) {
  //   if (g[i + 1].empty()) continue;
  //   cout << i + 1 << ": ";
  //   for (auto& e : g[i + 1]) cout << e << " ";
  //   cout << endl;
  // }

  REP(i, q) {
    int num = 0;
    int a = x[i];
    int b = y[i];
    // cout << "a = " << a << ", b = " << b << endl;
    for (int j = a; j <= b; j++) {
      if (g[j].size() == 0) continue;
      if (g[j][0] > b) continue;
      if (g[j].back() <= b) {
        num += g[j].size();
        continue;
      }
      auto itr = upper_bound(all(g[j]), b);
      num += distance(g[j].begin(), itr);
      // if (i == 0) cout << distance(g[j].begin(), itr) << endl;
    }
    ans[i] = num;
  }
  // cout << endl;

  for (auto& e : ans) cout << e << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<P>> g(n);
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back(P(b, c));
		g[b].push_back(P(a, c));
	}
	int q, k;
	cin >> q >> k;
	k--;
	priority_queue<P, vector<P>, greater<P>> pq;
	vector<ll> d(n, linf);
	pq.emplace(0, k);
	d[k] = 0;
	while (pq.size()) {
		P p = pq.top(); pq.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (auto c : g[v]) {
			if (d[c.first] > d[v] + c.second) {
				d[c.first] = d[v] + c.second;
				pq.emplace(d[c.first], c.first);
			}
		}
	}
	while (q--) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << d[x] + d[y] << endl;
	}
	return 0;
}


Measured memory_bytes: 11624
#include <stdio.h>

int alpha[26];

int main(void){
    long n;
    scanf("%ld\n", &n);
    for(long i=0; i<n; i++){
        int c = getchar_unlocked();
        alpha[c-'a']++;
    }
    long ans = 1;
    for(long i=0; i<26; i++){
        ans = ans * (alpha[i]+1) % 1000000007;
    }
    printf("%ld\n", ans-1);
    return 0;
}

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

#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    char x,y,z;
    cin>>s;
    int n=s.length(),ans=10000,b;
    for(int i=0;i<n-2;i++){
        x=s[i];
        y=s[i+1];
        z=s[i+2];
        b=100*(x-'0')+10*(y-'0')+(z-'0');
        ans=min(ans,abs(753-b));
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
n,m = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
h = []
for i in l:
    i = -1*i
    heapq.heappush(h,i)
    
for _ in range(m):
    v = -heapq.heappop(h)
    heapq.heappush(h,-1*(v//2))
    
print(-sum(h))

Measured memory_bytes: 14180
def solve():
    S = input()
    s1 = S[:int((len(S)-1)/2)]
    s2 = S[int((len(S)+1)/2):]

    for i in range(len(s1)):
        if(s1[i] == s1[len(s1)-i-1]):
            pass
        else:
            print("No")
            return

    if s1 == s2:
        print("Yes")
    else:
        print("No")

solve()


Measured memory_bytes: 3060
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    print('NO' if sum(map(int,input().split()))%2 else 'YES')
if __name__ == '__main__':
  main()


Measured memory_bytes: 13248
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N,K;
    string S;
    cin >> N >> K >> S;
    vector<ll> v;
    ll now = 1;
    ll cnt = 0;
    rep(i,N){
        if(S[i]-'0' != now){
            v.push_back(cnt);
            cnt = 1;
            now = (now?0:1);
        }else{
            cnt++;
        }
    }
    if(!now){
        v.push_back(cnt);
        v.push_back(0);
    }else{
        v.push_back(cnt);
    }
    ll M = v.size();
    vector<ll> s(M+1);
    //PR(v,M);
    rep(i,M){
        s[i+1] = s[i] + v[i];
    }
    ll ans = 0;
    rep(i,M+1-K-K-1){
        cmax(ans, s[min(i+2*K+1,M)]-s[i]);
        i++;
    }
    if(M+1-K-K-1 <= 0){
        ans = s[M];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2164
#include<stdio.h>
int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a == b && a !=c){
    printf("Yes");
    }
    else if(a == c && a != b){
        puts("Yes");
    }
    else if(b == c && b != a){
        puts("Yes");
    }
    else{
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;


int main(){
  ll X;
  cin >> X;
  
  ll n500, n5;
  n500 = X/500;
  n5 = (X - n500*500)/5;
  
  cout << 1000*n500 + 5*n5;
}

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

using namespace std;

using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;


pair<long long,long long> dp[110][110*1100];
//long long dpv[110][110*11000];
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);

	int n = 0;
	int w = 0;
	cin >> n >> w;
	vector<pll> data(n);
	long long vs = 0;
	for(int i = 0;i < n;++i){
		cin >> data[i].first >> data[i].second;
		vs+=data[i].second;
	}
	for(int i = 0;i < 110; ++i){
		for(int j = 0; j < 110*1100; ++j){
			dp[i][j].first = 1e18;
		}
	}
	for(int i = 0;i < 110; ++i){
		dp[i][0].first = 0;
	}
/*	for(int i = 0;i < 110 * 1100; ++i){
		dp[0][i].first = 0;
	}*/

	//dp[0][0].first = 0;
	for(int i = 0;i <= vs;++i){
		for(int j = 0;j < n; ++j){
			if(dp[j][i].first /*+ data[j].first*/ <= w){
				for(int k = j; k < n; ++k)
				{
					if(dp[j][i].first + data[k].first <= w)
		//			cout << "hello\n";
					dp[k + 1][i + data[k].second].first = min(dp[k + 1][i + data[k].second].first,
															  dp[j][i].first + data[k].first);
				}
			}
		}
	}
	for(int i = vs; i >=0; --i){
		for(int j = 0; j <=n; ++j){
			if(dp[j][i].first <= w)
			{
				cout << i;
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 208384
#include <iostream>
 
using namespace std;
 
int main()
{
    int x,y,a,b,c;
    cin>>x>>y;
    if(x==0){
        if(y==0){
            cout<<"Yes";
        }
        cout<<"No";
    }
    else{
        if(y%2==0){
            if(y<=x*4 and y>=x*2){
                cout<<"Yes";
            }
            else{
                cout<<"No";
            }
        }
        else{
          cout<<"No";  
        }
        return 0;
    }
}

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

int main(){
	int n;cin >> n;
	long long tmp;
	int a[n];
	long long cnt[n] = {0};
	long long ans;

	rep(i,n){
		cin >> tmp;
		a[i] = tmp;
	}

	for(auto ite:a){
		cnt[ite-1]++;
	}

	long long total = 0;
	rep(i,n){
		tmp = cnt[i];
		total += tmp * (tmp-1) / 2;
	}

	rep(i,n){
		ans = total - cnt[a[i]-1] + 1;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 4864
import sys
from math import ceil


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    S = [input() for _ in range(5)]
    mi = 10
    for s in S:
        if not s[-1] == '0':
            mi = min(mi, int(s[-1]))
    S = list(map(lambda x: ceil(int(x) / 10) * 10, S))
    print(sum(S) - (10 - mi))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9096
//税
using System;

namespace tst
{
    
    class Program
    {
        public static void Main()
        {
            //数値読み込み
            int n = int.Parse(Console.ReadLine());
            //小数点以下切捨て
            int x = (int)Math.Floor(n / 1.08);
            //xの周辺で全数調査
            bool nonmatch = true;
            for(int i=x-10; i<=x+10; i++)
            {
                if (Math.Floor(i * 1.08) == n)
                {
                    nonmatch = false;
                    Console.WriteLine(i);
                }
            }
            if (nonmatch)
            {
                Console.WriteLine(":(");
            }
            
        }

    }
}

Measured memory_bytes: 13140