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

typedef struct {
	long x1,x2,y1,y2;
} board;

long cx[2002],cy[2002];
int xc,yc,map[2000][2000];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};

int compress(long xory,int mode){
	int i;
	switch(mode){
		case 0:
		i=0;
		while(xory!=cx[i]){
			i++;
		}
		return i;
		case 1:
		i=0;
		while(xory!=cy[i]){
			i++;
		}
		return i;
	}
}

void area(int x,int y){
	map[x][y]=1;
	int i;
	for(i=0;i<4;i++){
		if(x+dx[i]>=0 && x+dx[i]<xc && y+dy[i]>=0 && y+dy[i]<yc){
			if(map[x+dx[i]][y+dy[i]]==0) area(x+dx[i],y+dy[i]);
		}
	}
}

int cmp(const void*,const void*);

int main(){
	int n,i,j,num;
	long *x,*y,w,h;
	board *tape;
	while(1){
		scanf("%ld %ld",&w,&h);
		if(w==0) break;
		scanf("%d",&n);
		tape=(board *)malloc(sizeof(board)*n);
		x=(long*)malloc(sizeof(long)*n*2);
		y=(long*)malloc(sizeof(long)*n*2);
		for(i=0;i<n;i++){
			scanf("%ld %ld %ld %ld",&tape[i].x1,&tape[i].y1,&tape[i].x2,&tape[i].y2);
			x[i*2]=tape[i].x1;
			x[i*2+1]=tape[i].x2;
			y[i*2]=tape[i].y1;
			y[i*2+1]=tape[i].y2;
		}
		qsort(x,n*2,sizeof(long),cmp);
		qsort(y,n*2,sizeof(long),cmp);
		cx[0]=0;
		cy[0]=0;
		xc=1;
		yc=1;
		for(i=0;i<n*2;i++){
			if(cx[xc-1]==x[i]) continue;
			cx[xc]=x[i];
			xc++;
		}
		if(cx[xc-1]==w){
			xc--;
		}
		for(i=0;i<n*2;i++){
			if(cy[yc-1]==y[i]) continue;
			cy[yc]=y[i];
			yc++;
		}
		if(cy[yc-1]==h){
			yc--;
		}
		free(x);
		free(y);
		memset(map,0,sizeof(map));
		for(i=0;i<n;i++){
			tape[i].x1=compress(tape[i].x1,0);
			tape[i].y1=compress(tape[i].y1,1);
			tape[i].x2=compress(tape[i].x2,0);
			tape[i].y2=compress(tape[i].y2,1);
			for(j=tape[i].y1;j<tape[i].y2;j++){
				map[tape[i].x1][j]+=1;
				map[tape[i].x2][j]-=1;
			}
		}
		for(i=0;i<yc;i++){
			num=0;
			for(j=0;j<xc;j++){
				num+=map[j][i];
				map[j][i]=num;
			}
		}
		num=0;
		for(i=0;i<xc;i++){
			for(j=0;j<yc;j++){
				if(map[i][j]==0){
					area(i,j);
					num++;
				}
			}
		}
		printf("%d\n",num);
		free(tape);
	}
	return 0;
}

int cmp(const void* a,const void* b){
	return *(long*)a-*(long*)b;
}

Measured memory_bytes: 18632
N = int(input())
q = []
for i in range(0,-(-N//2)+1):
    p = []
    for j in range(1,N+1):
        if (2*i-1) % j == 0:
            p.append(j)
    if len(p) == 8:
        q.append(1)
print(len(q))

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

typedef pair< int, int > PI;

int N, M;

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

  cin >> N >> M;
  vector< PI > d(M);
  
  REP(i, M) {
    CIN(p, q);
    d[i] = make_pair(p, q);
  }
  sort(ALL(d), [](PI x, PI y) { return x.second < y.second; });
  
  int ans = 0;
  int ub = 0;
  REP(i, M) {
    if (ub < d[i].first + 1) {
      ans++;
      ub = d[i].second;
    }
    // ub = max(ub, d[i].second - 1);
  }

  cout << ans << endl;

  

  return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#define S(A,B) if(B<A){A^=B;B^=A;A^=B;}
a,b;main(c){scanf("%d%d%d",&a,&b,&c);S(b,c);S(a,c);S(a,b);printf("%d %d %d\n",a,b,c);return 0;}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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


int main() {
  string w;
  cin >> w;
  int c[26];
  rep (i, 26) {
    c[i] = 0;
  }
  rep (i, w.size()) {
    int tmp = w[i] - 'a';
    c[tmp]++;
  }
  rep (i, 26) {
    if (c[i] % 2 == 1) {
      No;
      return 0;
    }
  }
  Yes;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	map<int, int> cnt;
	int maxa = 0, mina = mod;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if(cnt.find(a) == cnt.end()) cnt[a] = 0;
		cnt[a]++;
		maxa = max(maxa, a);
		mina = min(mina, a);
	}
	if(cnt.size() > 2){
		cout << "No" << endl;
	} else if(cnt.size() == 1){
		if(maxa <= n / 2 || maxa == n - 1) cout << "Yes" << endl;
		else cout << "No" << endl;
	} else {
		if(maxa - mina == 1 && maxa - cnt[mina] > 0 && cnt[maxa] / (maxa - cnt[mina]) >= 2) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 4992
import sys

N, K = map(int,input().split())
X = list(map(int,input().split()))

ans = (10**8)*K
for i in range(N-K+1):
    ans = min(ans, abs(X[i])+abs(X[i]-X[K-1+i]),abs(X[K-1+i])+abs(X[i]-X[K-1+i]))
print(ans)

Measured memory_bytes: 14224
#include <iostream>
#include <string.h>


int checkPal(char s[]) {
  int l = strlen(s);
  int check = 1;
  for (size_t i = 0; i < l / 2 && check == 1; i++) {
    if (s[i] != s[l - 1 - i]) {
      check = 0;
    }
    if (s[i] != s[l/2 - i - 1]) {
      check = 0;
    }
    if (s[l/2 + 1 + i] != s[l - 1 - i]) {
      check = 0;
    }
  }

  return check;
  // return s.substr(1, l - 2);
}

using namespace std;
int main() {
  // cout<<endl<<endl<<endl;

  char s[200];
  cin >> s;

  if (checkPal(s)) {
    cout<< "Yes";
  } else {
    cout <<"No";
  }

  // cout<<endl<<endl<<endl;
  return 0;
}


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

int main() {
    int arr[3];
    cin >> arr[0] >> arr[1] >> arr[2];
    for (int i = 2; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (arr[j] > arr[j+1]) { swap(arr[j], arr[j+1]); }
        }
    }
    cout << arr[0] << " " << arr[1] << " " << arr[2] << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;


long long  int N,M,K,A[200050],sum=0,res=0,num[200020]={};

int main()
{
    cout << fixed << setprecision(18);
    
    cin>>N;
    for(long long int i = 0; i < N; i++){
        cin>>A[i];
        num[A[i]]++;
        num[A[i]+1]++;
        num[A[i]+2]++;
    }
    for(long long int i = 0; i < 100100; i++){
        res=max(res,num[i]);
    }
    cout<<res<<endl;
    
}


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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<ll,ll> P;

int ans;
int main(){
  int N;cin>>N;
  map<string,int> m;
  string s;
  rep(i,N){
    cin>>s;
    m[s]+=1;
  }
  int M;cin>>M;
  string t;
  rep(i,M){
    cin >>t;
    m[t]-=1;
  }
  ans=0;
  for(auto v:m){
    ans=max(v.second,ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mx 1007
double arr[mx];

#define pi acos(-1)
using namespace std;


int main()
{
    ll n,item,temp,a,b,c,k;
    cin>>a>>b>>c;
    cin>>k;
    vector<ll>v;
    map<ll,ll>mp;
    ll sum=0;
    while(a>=b && k>0)
    {
        b=b*2;

        k--;
    }
   /// cout<<"k:"<<k<<endl;
    while(b>=c && k>0)
    {
        c=c*2;
        k--;
    }
   /// cout<<a<<" "<<b<<" "<<c<<endl;
    if(c>b && b>a)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 3592
n = int(input())
m = n
primes = {}
 
for i in range(2, int(n**0.5+2)):
  while m % i == 0:
    m //= i
    if i not in primes:
      primes[i] = 1
    else:
      primes[i] += 1
  if i > m:
    break
 
if m != 1:
  primes[m] = 1
 
cnt = 0
num = 0
flag = True
 
while flag == True:
  num += 1
  flag = False
  for i in primes:
    if 0 < primes[i] <= num*2:
      cnt += 1
      primes[i] = 0
    elif primes[i] > num*2:
      cnt += 1
      flag = True
      primes[i] -= num
 
print(cnt)

Measured memory_bytes: 9472
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int total = 0;
    for(int i = 0;i<n;i++){
      a[i] = sc.nextInt();
      total += a[i];
    }
    total *= 10;
    total /= n;
    if(total % 10 < 5){
      total /= 10;
    }else{
      total /= 10;
      total += 1;
    }
    int cost = 0;
    for(int i = 0;i<n;i++){
      int aa = total - a[i];
      aa *= aa;
      cost += aa;
    }
    System.out.println(cost);
  }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using ld = long double;
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vd = vector<ld>;
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)

#define DBG 1
#define TR(X) ({if(DBG) cerr << "TR: " << (#X) << " = " << (X) << endl; })


int main(){
  cin.sync_with_stdio(0);

	ll N;
	vvl a;
	cin >> N;
	FOR (i, 0, N){
		vl ai;
		FOR (j, 0, N){
			ll aij;
			cin >> aij;
			ai.pb (aij);
		}
		a.pb (ai);
	}

	vl sum (1ll << N, 0);
	FOR (m, 0, 1ll << N)
	{
		FOR (i, 0, N)
		{
			if (!((1ll << i) & m))
				continue;
			FOR (j, i, N)
			{
				if (!((1ll << j) & m))
					continue;
				sum[m] += a[i][j];
			}
		}
	}

	vl res (1ll << N, -oo);
	res[0] = 0;
	FOR (m, 0, 1ll << N)
	{
		for (ll sm = m; sm; sm--, sm &= m)
		{
			res[m] = max (res[m], sum[sm] + res[m ^ sm]);
		}
	}

	cout << res[(1ll << N) - 1] << endl;

  return 0;

} //cin.tie(0) bei schnellem Wechseln



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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
template<class T> inline T isqrt(T k) {T r = sqrt(k) + 1; while (r * r > k) r--; return r;}
template<class T> inline T icbrt(T k) {T r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}

const int maxn = 100;
int n, m;

void solve() {
	cin >> n >> m;
	vii v;
	FOR(i, 0, n) {
		string s; cin >> s;
		FOR(j, 0, m) {
			if (s[j] == '#') {
				v.pb(mp(i, j));
			}
		}
	}
	sort(all(v));
	FOR(i, 1, sz(v)) {
		if (v[i].se < v[i - 1].se) {
			cout << "Impossible\n";
			return;
		}
	}
	cout << "Possible\n";
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 764
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let s = read_as_string();
    let s = s.chars().filter(|c| !c.is_whitespace()).collect::<String>();

    let n: f64 = f64::from_str(&s).unwrap();
    if n.sqrt().ceil() == n.sqrt().floor(){
        println!("Yes");
    }else{
        println!("No");
    }

}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
using namespace std;
int main(void){
	int n,m;
	scanf("%d%d",&n,&m);
	int ans=0;
	if(n>=2)
	ans+=n*(n-1)/2;
	if(m>=2)
	ans+=m*(m-1)/2;
	cout<<ans<<"\n";
	return 0;
}

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

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

const long long INF = 1LL << 60;

int main(void){
	int n,m;cin >> n >> m;
	cout << n*(n-1)/2 + m*(m-1)/2 << endl;
	return 0;
}



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

int n, ans=0;

int main(){
	cin >> n;
	for (int i=1;i<=n;i++){
		int a;
		cin >> a;
		if (i%2==1 && a%2==1) ans++;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3596
S = input()
n = len(S)
S1 = S[:(n-1)//2]
S2 = S[(n+1)//2:]
flag = 0
for i in range(n):
    if S[0+i] == S[n-1-i]:
        continue
    else:
        flag = 1
for i in range((n-1)//2):
    if S1[0+i] == S1[(n-1)//2-1-i] and S2[0+i] == S2[(n-1)//2-1-i]:
        continue
    else:
        flag = 1
if flag == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using vl = vector<ll>;

int main() {
  ll n;
  cin >> n;
  vl x(n);
  rep(i, n) cin >> x[i];
  ll l, q;
  cin >> l >> q;
  vector<vl> r(20, vl(n));
  rep(i, n) r[0][i] = upper_bound(all(x), x[i] + l) - x.begin() - 1;
  rep(k, 19) rep(i, n) r[k + 1][i] = r[k][r[k][i]];
  rep(_, q) {
    ll a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    a--;
    b--;
    ll ans = 1;
    for(ll k = 19; k >= 0; k--)
      if(r[k][a] < b) {
        a = r[k][a];
        ans += 1 << k;
      }
    cout << ans << '\n';
  }
}

Measured memory_bytes: 20308
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<climits>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

int main(void) {
	int m, f, r;
	cin >> m >> f >> r;

	while (m != -1 || f != -1 || r != -1) {
		if (m == -1 || f == -1) {
			cout << "F" << endl;
		}
		else if (80 <= m + f) {
			cout << "A" << endl;
		}
		else if (65 <= m + f && 80 > m + f) {
			cout << "B" << endl;
		}
		else if (50 <= m + f && 65 > m + f) {
			cout << "C" << endl;
		}
		else if (30 <= m + f && 50 > m + f) {
			if (50 <= r) {
				cout << "C" << endl;
			}
			else {
				cout << "D" << endl;
			}
		}
		else {
			cout << "F" << endl;
		}
		cin >> m >> f >> r;
	}
}


Measured memory_bytes: 3032
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int K = Integer.parseInt(br.readLine());
        if (K % 2 == 0) {
            out.println(K / 2 * K / 2);
        } else {
            out.println((K + 1) / 2  * ((K + 1) / 2 - 1));
        }      
        out.close();
    }
}

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

using namespace std;

int dp[20000];
int k;

// 入力
int n, W;
int w[10000], v[10000];
//漸化式
void solve() {
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      if(j-w[i]<0);
      else dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    }
  }

  /*for (int j = 0; j <= W; j++) dp2[n][j] = 0;

  for (int i = n - 1; i >= 0; i--) {
  for (int j = 0; j <= W; j++) {
  dp2[i][j] = dp2[i + 1][j];
  if (j < w[i]);
  else{
  k=1;
  //cout << (int)k << endl;
  dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - w[i]*k] + v[i]*k);
  k=3;
  //cout << (int)k << endl;
  dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - w[i]*k] + v[i]*k);
  k=j/w[i];
  dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - w[i]*k] + v[i]*k);
}
*/
/*for(int k=1;k<=j/w[i];k++){
dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - w[i]*k] + v[i]*k);
}*/
/*  while(1){
int kc=j-w[i]*k;
if(kc<0){
k=1;
break;
}
else
dp2[i][j] = max(dp2[i][j], dp2[i + 1][kc] + v[i]*k);
k++;
}*/
//}
//}
/*for (int j = 0; j <= W; j++) {
for (int i = 0; i <= n; i++) {
cout << dp2[i][j];
}
cout << endl;
}
*/
cout << dp[W] << endl;
}

int main(){
  cin >> n >> W;
  for(int i=0;i<n;i++){
    cin >> v[i] >> w[i];
  }
  solve();
}



Measured memory_bytes: 3184
a,b,c,d=map(int,input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a  
nc=b//c-(a-1)//c
nd=b//d-(a-1)//d
x=c*d//gcd(c,d)
ncd=b//x-(a-1)//x
#print(nc,nd,x,ncd)
print(b-a+1-nc-nd+ncd)

Measured memory_bytes: 3060
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static final long[] fal_rnd(int size){
		AtomicInteger l=new AtomicInteger(-1),r=new AtomicInteger(size);
		long[] res=new long[size];
		INS(size).unordered().parallel().mapToLong(Long::parseLong).forEach(v->res[ThreadLocalRandom.current().nextBoolean()?l.incrementAndGet():r.decrementAndGet()]=v);
		return res;
	}
	static final IntStream REPS(int v){
		return IntStream.range(0,v);
	}
	static final Stream<String> INS(long size){
		return StreamSupport.stream(Spliterators.spliterator(s,size,Spliterator.NONNULL&Spliterator.IMMUTABLE),false).limit(size);
	}
	public static void main(String[]__){
		int n=s.nextInt();
		long k=s.nextLong();
		TreeMap<Integer,Long> map=new TreeMap<>();
		for(int i=0;i<n;i++) {
			map.merge(s.nextInt(),s.nextLong(),Long::sum);
		}
		long sum=0;
		for(Entry<Integer,Long> e:map.entrySet()) {
			sum+=e.getValue();
			if(k<=sum) {
				System.out.println(e.getKey());
				return;
			}
		}
	}
}


Measured memory_bytes: 88900
#include<stdio.h>

int main()
{
	int m, f, r;
	
	while(scanf("%d %d %d", &m, &f, &r))
	{
		if(m == -1 && f == -1 && r == -1)
		{
			break;
		}
		else if((m == -1 || f == -1) || (m + f < 30))
		{
			printf("F\n");
		}
		else if(m + f >= 80)
		{
			printf("A\n");
		}
		else if(m + f >= 65)
		{
			printf("B\n");
		}
		else if(m + f >= 50)
		{
			printf("C\n");
		}
		else if(m + f >= 30)
		{
			if(r >= 50)
			{
				printf("C\n");
			}
			else
			{
				printf("D\n");		
			}

		}

		
	}
}


Measured memory_bytes: 2564
import java.util.*;

public class Main {

    private static final int MOD = 1000000007;

    private static long[] fact;
    private static long[] finv;

    private static void setFact(int max) {
        fact = new long[max];
        finv = new long[max];
        long[] inv = new long[max];

        fact[0] = fact[1] = 1;
        finv[0] = finv[1] = 1;

        inv[0] = 1;
        inv[1] = 1;
        for (int i = 2; i < max; i++) {
            fact[i] = fact[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
        //System.out.println(Arrays.toString(fact));
        //System.out.println(Arrays.toString(finv));
    }

    private static long nCr(int n, int r) {
        if (n < r || n < 0 || r < 0) return 0;
        return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD;
    }

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

        final int H = sc.nextInt();
        final int W = sc.nextInt();
        final int A = sc.nextInt();
        final int B = sc.nextInt();

        setFact(H+W+1);

        long ret = 0;
        for (int i = B; i < W; i++) {
            ret += (nCr((H - A - 1) + i, i) * nCr((W - i - 1) + (A - 1), A - 1)) % MOD;
            ret %= MOD;
        }

        System.out.println(ret);
    }
}

Measured memory_bytes: 29524
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    int a;
    cin >> a;
    cout << a*a*a+a*a+a << endl;
    return 0;
}

Measured memory_bytes: 3588
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

typedef int SegT;
const SegT defvalue=0;
class SegTree{
	private:
		vector<SegT>val;
		int n;
		SegT combine(SegT a,SegT b){return (a+b);}
	public:
		SegTree(int size){
			n=1;
			while(n<size)n<<=1;
			val=vector<SegT>(2*n,defvalue);
		}
		SegTree(const vector<SegT> &in){
			n=1;
			while(n<in.size())n<<=1;
			val=vector<SegT>(2*n,defvalue);
			for(int i=n-1+in.size()-1;i>=0;i--){
				if(n-1<=i)val[i]=in[i-(n-1)];
				else val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		void update(int i,SegT a){
			i+=n-1;
			val[i]+=a;
			while(i>0){
				i=(i-1)/2;
				val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		SegT query(int a,int b,int k=0,int l=0,int r=-1){//[a,b)
			if(r==-1)r=n;
			if(r<=a||b<=l)return defvalue;
			if(a<=l&&r<=b)return val[k];
			else return combine(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
		}
		void tmp(){
			rep(i,val.size())cout<<" "<<val[i];cout<<endl;
		}
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<SegTree>st(26,SegTree(n));

	rep(i,n)st[s[i]-'a'].update(i,1);
	int q;
	cin>>q;
	while(q--){
		int x;
		cin>>x;
		if(x==1){
			int i;char c;
			cin>>i>>c;
			i--;
			st[s[i]-'a'].update(i,-1);
			st[c-'a'].update(i,1);
			s[i]=c;
		}else{
			int l,r;
			cin>>l>>r;
			l--;
			int c=0;
			rep(i,26)if(st[i].query(l,r))c++;
			cout<<c<<endl;
		}
	}

}


Measured memory_bytes: 222236
#include <iostream>
#include <algorithm>
const int N = 1e5 + 5;
using namespace std;

struct Node
{
	int index;
	int a;
}node[N];

bool cmp(const Node& a, const Node& b)
{
	return a.a < b.a;
}

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> node[i].a;
		node[i].index = i;
	}

	sort(node + 1, node + n + 1, cmp);

	for (int i = 1; i <= n; i++)
	{
		cout << node[i].index << ' ';
	}

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <climits>
#include <functional>
#include <queue>
#include <cmath>
#include <utility>

using namespace std;

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

int N, A, B;
vector<int> h;

bool check(int m)
{
	vector<int> v = h;

	int counter = 0;

	rep(i, N) {
		v[i] -= B * m;
		if (v[i] <= 0) continue;
		counter += (v[i] + A - B - 1) / (A - B);
	}

	return counter <= m;
}

signed main()
{
	cin >> N >> A >> B;
	h.resize(N);
	rep(i, N) cin >> h[i];

	int l = 0, r = 1000000000;
	while (r - l > 1) {
		int m = (r + l) / 2;

		if (check(m)) {
			r = m;
		} else {
			l = m;
		}
	}

	cout << r << endl;
}


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

int n,q,temp,p=0,c=0;
int a[100005],b[100005];

signed main()
{
	cin>>n>>q;
	for (int i=1;i<=q;i++)
	{
		string s;
		cin>>temp>>s;
		
		if (s=="AC")  a[temp]=1;
		else
		{
			if (a[temp]==0)  b[temp]++; 
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (a[i])
		{
			c++;
			p+=b[i];
		}
	}
	cout<<c<<' '<<p<<endl;
	
	return 0;
}

Measured memory_bytes: 1664
cash = input()
S = list(cash)
cash0 = ""
cash1 = ""
for i in range(len(S)):
	if i % 2 == 0:
		cash0 = cash0 + "0"
		cash1 = cash1 + "1"
	else:
		cash0 = cash0 + "1"
		cash1 = cash1 + "0"
cash0 = list(cash0)
cash1 = list(cash1)
num0=0
num1=0
for i in range(len(S)):
	if S[i]==cash0[i]:
		num0=num0+1
	if S[i]==cash1[i]:
		num1=num1+1
print(min(num0,num1))

Measured memory_bytes: 5748
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  set<string> ans;
  for(int i=0; i<n; i++){
    string s;
    cin>>s;
    ans.insert(s);
  }
  cout<<ans.size()<<endl;
}

Measured memory_bytes: 19180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if (N%10*100 + N/10%10*10 + N/100 == N){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

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

    int a[n];
    for( int i = 0; i < n; i++ )
        cin >> a[i];
    
    int b[m];
    for( int i = 0; i < m; i++ )
        cin >> b[i];

    vector<int> resa, resb;
    
    int i = 0, j = 0;
    while( i < n && j < m )
    {
        if( a[i] == b[j] )
        {
            resa.push_back( a[i] );
            resb.push_back( a[i] );
            i++; j++;
            continue;
        }
        else if( a[i] < b[j] )
        {
            resb.push_back( a[i] );
            i++;
        }
        else
        {
            resb.push_back( b[j] );
            j++;
        }
    }

    while( i < n )
        resb.push_back( a[i++] );
    while( j < m )
        resb.push_back( b[j++] );

    cout << resa.size() << " " << resb.size() << endl;
    
    for( int k = 0; k < resa.size(); k++ )
        cout << resa[k] << endl;
    
    for( int k = 0; k < resb.size(); k++ )
        cout << resb[k] << endl;

    return 0;
}


Measured memory_bytes: 5052
n, m = map(int, input().split())
ans = 1

if abs(n - m) > 1:
    print(0)
    exit()

for i in range(1, n + 1):
    ans = ans*i%(10**9 + 7)

for i in range(1, m + 1):
    ans = ans*i%(10**9 + 7)

if (n + m)%2 == 0:
    ans = ans*2%(10**9 + 7)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

bool check(int L, int s, char a, char b, string S, string T){
    int N = S.length();
    int left = 1;
    int right = L;
    bool ok = 1;
    for(int i = N-1; i>=0; i--){
        if(i != N-1){ //青木くんのターン
            if(T[i] == a){
                right = min(L,right+1);
            }
            else if(T[i] == b){
                left = max(1,left-1);
            }
        }

        //高橋くんのターン
        if(S[i] == a){
            left = left + 1;
        }
        else if(S[i] == b){
            right = right - 1;
        }

        if(left > right) ok = 0;

    }

    if(s < left || right < s) ok = 0;

    return ok;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,N; cin >> H >> W >> N;
    int sr,sc; cin >> sr >> sc;
    string S,T; cin >> S >> T;

    bool yoko = check(W,sc,'L','R',S,T);
    bool tate = check(H,sr,'U','D',S,T);

    if(yoko&&tate){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }


}


Measured memory_bytes: 1176
S = list(input())
N = len(S)
RL_num = []
R_index = [] #境界のRのインデックス

for i in range(N):
  if(i != N-1):
    if(i == 0):
      count_r = 0
      count_l = 0 
    if(S[i] == 'R'):
      count_r += 1 #count_r : Rの連続数
      if(S[i+1] == 'L'):
       r_num = (count_r+1)//2 #r_num : ...RL... の Rに入る数字
       R_index.append(i)
       #-------------------#    
    elif(S[i] == 'L'):
      count_l += 1 #count_l : Lの連続数
      if(S[i+1] == 'R'): 
       r_num += (count_l)//2 
       l_num = (count_r+count_l) - r_num #count_r+count_l : (..L)RRLLLL(R..) のブロックの要素数(ex: 6)
       RL_num.append([r_num,l_num]) 
       #-------------------# 
       count_r = 0 #リセット
       count_l = 0 #リセット
      
  else: #i = N-1
    count_l += 1
    r_num += (count_l)//2 
    l_num = (count_r+count_l) - r_num #count_r+count_l : (..L)RRLLLL(R..) のブロックの要素数(ex: 6)
    RL_num.append([r_num,l_num])

#print(R_index)   
#print(RL_num)

ans = []
for i in range(N):
  ans.append(str(0))

for i in range(len(R_index)):
  r_index = R_index[i]
  ans[r_index] = str(RL_num[i][0]) 
  ans[r_index+1] = str(RL_num[i][1])
 
ans_str = ' '.join(ans)
ans_str.rstrip() #末尾の空白削除
print(ans_str)
  
  

Measured memory_bytes: 17840
import java.util.*;
class Main {
    static int n;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int m = sc.nextInt();
        int[][] table = new int[n+1][n+1];
        int[][] table2 = new int[n+1][n+1];

        for(int i =0;i <m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            table[a][b] = 1;
            table[b][a] = 1;
            table2[a][b] = 1;
            table2[b][a] = 1;
        }
        int cnt = 0;
        for(int i = 0; i<=n; i++) {
            if(table[1][i] == 1) {
                System.err.println(i);
                for(int j = 0; j<=n; j++) {
                    table2[1][j] = table[1][j];
                    table2[j][1] = table[j][1];
                }
                for(int j = 0; j<=n; j++) {
                    table[1][j] = 0;
                    table[j][1] = 0;
                }
                cnt += dfs(table, i, 1);
                for(int j = 0; j<=n; j++) {
                    table[1][j] = table2[1][j];
                    table[j][1] = table2[j][1];
                }
            }
        }
        System.out.println(cnt);
    }
    public static int dfs(int[][] table, int s, int depth) {
        int[][] table2 = new int[n+1][n+1];
        if(depth == n-1) return 1;
        int cnt = 0;
        for(int i = 0; i<=n; i++) {
            if(table[i][s]==1) {
                System.err.println("s: "+s+" e: "+i +" "+ (depth+1));
                for(int j = 0; j<=n; j++) {
                    table2[s][j] = table[s][j];
                    table2[j][s] = table[j][s];
                }
                for(int j = 0; j<=n; j++) {
                    table[s][j] = 0;
                    table[j][s] = 0;
                }
                cnt += dfs(table,i, depth+1);
                for(int j = 0; j<=n; j++) {
                    table[s][j] = table2[s][j];
                    table[j][s] = table2[j][s];
                }
            }
        }
        return cnt;
    }
}

Measured memory_bytes: 36172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int head(int n) {
  string s = to_string(n);
  return s[0] - '0';
}
int tail(int n) {
  string s = to_string(n);
  return s[s.length() - 1] - '0';
}

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

  map<P, int> m;
  for (int i = 1; i <= n; i++) {
    int h = head(i);
    int t = tail(i);
    if (t == 0) continue;
    m[{h, t}]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    int h = head(i);
    int t = tail(i);
    if (t == 0) continue;
    ans += m[{t, h}];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3704
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.typecons;

alias Edge = Tuple!(int, "to", int, "weight");

Edge[][10 ^^ 5 + 1] ES;
long[10 ^^ 5 + 1] LS;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (i; 0..N - 1) {
        auto e = readln.split.to!(int[]);
        ES[e[0]] ~= Edge(e[1], e[2]);
        ES[e[1]] ~= Edge(e[0], e[2]);
    }

    auto qk = readln.split.to!(int[]);
    auto Q = qk[0];
    auto K = qk[1];
    
    auto roots = [K];
    LS[K] = 0;

    while (!roots.empty) {
        int[] nexts;
        foreach (r; roots) {
            foreach (e; ES[r]) {
                auto l = e.weight + LS[r];
                if (e.to == K || (LS[e.to] != 0)) continue;
                LS[e.to] = l;
                nexts ~= e.to;
            }
        }
        roots = nexts;
    }

    foreach (_; 0..Q) {
        auto xy = readln.split.to!(int[]);
        writeln(LS[xy[0]] + LS[xy[1]]);
    }
}

Measured memory_bytes: 32636
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){

  int a[101];
  int n,M;

  for(int i = 1; i <= 100;i++ )a[i] = 0;
  M = 0;
  while(~scanf("%d",&n)){
    a[n]++;
    M=max(M,a[n]);
  }
  for(int i = 1;i <= 100 ; i++ ){
    if(a[i] == M)cout << i << endl;
}
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="SAT"){
		cout<<1<<endl;
	}else if(s=="FRI"){
		cout<<2<<endl;
	}else if(s=="THU"){
		cout<<3<<endl;
	}else if(s=="WED"){
		cout<<4<<endl;
	}else if(s=="TUE"){
		cout<<5<<endl; 
	}else if(s=="MON"){
		cout<<6<<endl;
	}else if(s=="SUN"){
		cout<<7<<endl;
	}	 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ch char
#define st string
using namespace std;
ll a,b,c,d,e,f,g,h;
void Urvatullo_Atoev()
{
    cin>>a;
    if(a>=400 && a<=599)
    {
        cout<<8;
    }
    else if(a>=600 && a<=799)
    {
        cout<<7;
    }
    else if(a>=800 && a<=999)
    {
        cout<<6;
    }
    else if(a>=1000 && a<=1199)
    {
        cout<<5;
    }
    else if(a>=1200 && a<=1399)
    {
        cout<<4;
    }
    else if(a>=1400 && a<=1599)
    {
        cout<<3;
    }
    else if(a>=1600 && a<=1799)
    {
        cout<<2;
    }
    else
    {
        cout<<1;
    }
}
int main()
{
    Urvatullo_Atoev();
}


Measured memory_bytes: 3620
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
map<lint,lint> me;
int main()
{
	int n,a,b,c,q;lint now=0;
	cin>>n;
	rep(i,n){
		cin>>a;me[a]++;now+=a;
	}
	cin>>q;
	rep(i,q){
		cin>>b>>c;
		lint x=me[b];now+=x*(c-b);
		me[b]-=x;me[c]+=x;
		cout<<now<<endl;
	}
}


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

int main(void)
{
    int a;
    cin >> a;

    int count = 0;

    if (0 != (a & 100)) ++count;
    if (0 != (a & 10))  ++count;
    if (0 != (a & 1))   ++count;

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<utility>
#include<cmath>
const int MaxN = 1e5;
using namespace std;
int n ;
int cont , num;
int main()
{
	while(~scanf("%d" , &n)){
		cont = 0;
		for(int i = 1;i <= n;i++){
			scanf("%d" , &num);
			if(num & 1) cont++;
		}
		if(cont & 1) printf("NO\n");
		else printf("YES\n");
	}
}

Measured memory_bytes: 128
// AOJ 2007: Make Purse Light
// 2017.10.15

#include <stdio.h>

int n[4];
int c[4] = { 10, 50, 100, 500 };

int main()
{
	int t, p, a, i, sum;
	int f[4];

	t = 0; while (scanf("%d", &p) && p > 0) {
		for (sum = 0, i = 0; i < 4; i++) {
			scanf("%d", &a); n[i] = a, sum += a*c[i];
		}
		p = sum - p; for (i = 3; i >= 0; i--) f[i] = p/c[i], p %= c[i];

		if (t > 0) putchar('\n'); else t = 1;
		for (i = 0; i < 4; i++) if (n[i]-f[i] > 0)
			printf("%d %d\n", c[i], n[i]-f[i]);
	}
	return 0;
}

Measured memory_bytes: 1740
package main

import (
	"fmt"
)

func main() {
	var a string
	fmt.Scan(&a)

	cnt := 0
	for i := 0; i < len(a)/2; i++ {
		if a[i] != a[len(a)-i-1] {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
H,W=map(int,input().split())
a=[list(map(int,input().split())) for i in range(H)]
cells=[]
for i in range(H):
    if i%2==0:
        for j in range(W):
            cells.append((i,j))
    else:
        for j in range(W-1,-1,-1):
            cells.append((i,j))
ans=[]
for k in range(H*W-1):
    i,j=cells[k]
    if a[i][j]%2==1:
        ni,nj=cells[k+1]
        a[i][j]-=1
        a[ni][nj]+=1
        ans.append([i+1,j+1,ni+1,nj+1])
print(len(ans))
for i in range(len(ans)):
    print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])


Measured memory_bytes: 53984
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		boolean[] notPrime = new boolean[50022];
		notPrime[0] = true;
		notPrime[1] = true;
		final int limit = (int) Math.sqrt(50021);
		for (int i = 2; i <= limit; i++) {
			if (!notPrime[i]) {
				for (int j = i + i; j <= 50021; j = j + i) {
					notPrime[j] = true;
				}
			}
		}
		int primeCount = 1;
		for (int i = 3; i <= 50021; i += 2) {
			if (!notPrime[i]) {
				primeCount++;
			}
		}

		int[] primes = new int[primeCount];
		primes[0] = 2;
		int index = 1;
		for (int i = 3; i <= 50021; i += 2) {
			if (!notPrime[i]) {
				primes[index++] = i;
			}
		}
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int low = 2;
			int tg = in.nextInt();
			for (int i = 0; i < primes.length; i++) {
				if (primes[i] < tg) {
					low = primes[i];
				} else if (primes[i] > tg) {
					System.out.println(low + " " + primes[i]);
					break;
				}
			}
		}
	}

}

Measured memory_bytes: 20400
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

namespace ConsoleApp2
{
    class Program {
        static public int dfs(int v) {
            bool all_visited = true;
            for (int i = 0; i < N; i++)
                if (visited[i] == false) {
                    all_visited = false;
                    break;
                }
            if (all_visited) return 1;

            int ret = 0;

            for (int i = 0; i < N; i++) {
                if (isConnect[v, i] == false) continue;
                if (visited[i] == true) continue;

                visited[i] = true;
                ret += dfs(i);
                visited[i] = false;
            }

            return ret;
        }

        static bool[] visited;
        static int N;
        static public bool[,] isConnect;


        static void Main(string[] Args) {
            var tmp = new List<string>(ReadLine().Split(' ')).Select(int.Parse).ToList();
            N = tmp[0]; int M = tmp[1];

            isConnect = new bool[N, N];
            visited = new bool[N];
            for (int i = 0; i < N; i++) visited[i] = false;

            for(int i = 0;i < M; i++) {
                tmp = new List<string>(ReadLine().Split(' ')).Select(int.Parse).ToList();
                isConnect[tmp[0] - 1, tmp[1] - 1] = true;
                isConnect[tmp[1] - 1, tmp[0] - 1] = true;
            }

            visited[0] = true;
            Console.WriteLine(dfs(0));

            ReadLine();
        }
    }
}


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

int main() {
  string w;
  int c = 0;
  cin >> w;
  while(true){
    string t;
    cin >> t;
    if(t == "END_OF_TEXT"){
      cout << c << endl;
      return 0;
    }
    for(int i = 0;i < t.size();i++){
      if(isupper(t[i])) t[i] = tolower(t[i]);
    }
    if(t == w) c++;
  }
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    int p[n];
    rep(i,n)cin >> p[i];

    int mi[n];
    mi[0] = p[0];
    srep(i,1,n){
        mi[i] = min(mi[i-1], p[i]);
    }

    int ans = 0;

    rep(i,n){
        if(mi[i] >= p[i])ans++;
    }

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


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans[3];
    ans[0]=abs(a-b);
    ans[1]=abs(a-c);
    ans[2]=abs(c-b);
    sort(ans,ans+3);
    cout << ans[0]+ans[1] << endl;
}

Measured memory_bytes: 256