akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n,m,Q,u[100010],d[100010],t=0,c[100010],Link[100010],color[100010][15];
vector <int> edge[100010];
struct dsa
{
	int v,nex;
}e[200010];
void Insert(int xx,int yy) {e[++t].nex=Link[xx];e[t].v=yy;Link[xx]=t;}
void dfs(int now,int dis,int col)
{
	if (dis==-1) return;
	if (color[now][dis]) return;
	color[now][dis]=col;
	for (int i=0;i<edge[now].size();i++) 
	  dfs(edge[now][i],dis-1,col);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) {
		int xx,yy;
		scanf("%d%d",&xx,&yy);
		edge[xx].push_back(yy);
		edge[yy].push_back(xx);
	}
	scanf("%d",&Q);
	for (int i=1;i<=Q;i++)
	  scanf("%d%d%d",&u[i],&d[i],&c[i]);
	for (int i=1;i<=n;i++)	edge[i].push_back(i);
	for (int i=Q;i;i--)
	  dfs(u[i],d[i],c[i]);
	for (int i=1;i<=n;i++)
	  printf("%d\n",color[i][0]);
}

Measured memory_bytes: 13944
#include <iostream>
#include <string.h>
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	char buf[16];
	cin >> buf;

	const char *p[] = { "00", "11", "22", "33", "44", "55", "66", "77", "88", "99", };
	for (int i = 0; i <= 9; i++) {
		if (strstr(buf, p[i]) != NULL) {
			cout << "Bad";
			return 0;
		}
	}
	cout << "Good";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int N = 2e5 + 10;
int n, k, c;
char s[N];
int vis[N];

int main()
{
	cin >> n >> k >> c;
	cin >> s + 1;
	
	int res = 0;
	vector<int>pos;
	for (int i = 1; i <= n; i++)
	{
		if (s[i] == 'o' && res == 0)
		{
			vis[i] = 1;
			pos.push_back(i);
			res = c;
			if (pos.size() == k) break;
		}
		else if (res > 0) res--;
	}
	
	int posr;
	res = 0;
	vector<int>ans;
	for (int i = n; i >= 1; i--)
	{
		if (s[i] == 'o' && res == 0)
		{
			if (i > pos.back()) pos.pop_back();
			else ans.push_back(i), pos.pop_back();
			res = c;
		}
		else if (res > 0) res--;
		if (pos.size() == 0) break;
	}
	
	reverse(ans.begin(), ans.end());
	for (auto x: ans) cout << x << endl;
}

Measured memory_bytes: 4212
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<long long>;
template<class T>using vv = vector<vector<T>>;
using vvi = vv<int>;
using vvl = vv<long long>;

#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}


// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}


#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif

int main() {
  int in(N); ll in(M);

  vi A(N);
  rep(i, N) cin >> A[i];
  all(sort, A);
  vl sum(N+1, 0);
  rep(i, N) {
    sum[i+1] = sum[i] + A[i];
  }

  auto f = [&](ll mid) {
    // mid以上がいくつあるか？
    ll count = 0;
    rep(i, N) {
      count += A.end() - all(lower_bound, A, mid - A[i]);
    }
    return count < M;
  };
  // 上からM個取りたい
  // -> 上からM番目を探す
  ll ng = 0, ok = 1800000000000000000ll; // okの数字は上からM番目の数以上
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (f(mid))
      ok = mid;
    else
      ng = mid;
  }
  ll ans = 0;
  ll count = 0;
  rep(i, N) {
    ans += sum[N] - sum[(int)(all(lower_bound, A, ok - A[i]) - A.begin())];
    ans += 1ll * (int)(A.end() - all(lower_bound, A, ok - A[i])) * A[i];
    count += A.end() - all(lower_bound, A, ok - A[i]);
  }
  ans += ng * (M - count);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	string s;
	cin>>s;
	int y,d,m;
	for(int i = 0; i < 4; i++){
		y += (s[i]-'0')*pow(10,3-i);
	}
	for(int i = 5; i < 7; i++){
		m += (s[i]-'0')*pow(10,6-i);
	}
	for(int i = 8; i < 10; i++){
		d += (s[i]-'0')*pow(10,9-i);
	}

	if(m == 4){
		if(d<= 30) cout << "Heisei"<<endl;
		else cout <<"TBD"<<endl;
	}else if(m<4) cout << "Heisei"<<endl;
	else cout <<"TBD"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,d,e,f,g,h,i;
int main(){
    cin>>a>>b>>e;
    c=3*e-a-b;
    h=2*e-b;
    f=2*a-h;
    i=3*e-c-f;
    d=2*e-f;
    g=3*e-h-i;
    printf("%d %d %d\n%d %d %d\n%d %d %d",a,b,c,d,e,f,g,h,i);   //输出
    return 0;
}

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

int main(int argc, char const *argv[]) {
  string str;
  getline(cin, str);
  string ans = "";
  int len = str.size();
  for (int i = 0; i < len; i++) {
    if ('a' <= str[i] && str[i] <= 'z') {
      str[i] = 'A' + (str[i] - 'a');
      ans += str[i];
    } else if ('A' <= str[i] && str[i] <= 'Z') {
      str[i] = 'a' + (str[i] - 'A');
      ans += str[i];
    } else {
      ans += str[i];
    }
  }

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

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int n,m,k;
int x,y;
map<int,int> mp1,mp2;
map<pair<int,int>,int> mp;
vector<int> v1,v2;

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	cin>>n>>m>>k;
	forn(i,0,k){
		cin>>x>>y;
		x--,y--;
		mp1[x]++;
		mp2[y]++;
		mp[make_pair(x,y)]++;
	}
	int mx1=0,mx2=0;
	forn(i,0,n)
		mx1=max(mx1,mp1[i]);
	forn(i,0,m)
		mx2=max(mx2,mp2[i]);
	forn(i,0,n)
		if (mp1[i]==mx1)
			v1.push_back(i);
	forn(i,0,m)
		if (mp2[i]==mx2)
			v2.push_back(i);
	forn(i,0,v1.size())
		forn(j,0,v2.size())
			if (mp[make_pair(v1[i],v2[j])]==0){
				cout<<mx1+mx2<<endl;
				return 0;
			}
	cout<<mx1+mx2-1<<endl;
	return 0;
}

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

int main(){
	int mon;
  	int fh=0;
  	int f=0;
  	int res=0;
  	cin >> mon;
  	while(mon >= 500){
		mon -= 500;
      	fh++;
    }
  	while(mon>=5){
		mon -= 5;
      	f++;
    }
  	res=fh*1000+f*5;
  	cout << res;
  	return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
//#define NDEBUG
int main(void){
	using namespace std;
	
	static const int INPUT_MIN = 0;
	static const int INPUT_MAX =  100;
	int input_num1 = 0;
	int input_num2 = 0;
	int input_num3 = 0;
	cin >> input_num1;
	cin >> input_num2;
	cin >> input_num3;
	 
	assert(INPUT_MIN <= input_num1 && input_num1 <= INPUT_MAX); /* Precondition */
	assert(INPUT_MIN <= input_num2 && input_num2 <= INPUT_MAX); /* Precondition */
	assert(INPUT_MIN <= input_num3 && input_num3 <= INPUT_MAX); /* Precondition */
	
	/* Comparison */
	if(input_num1 < input_num2 && input_num2 < input_num3){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	
	return 0;
}

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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 2000005;

void solve()
{
	int H, n;
	cin >> H  >> n;
	int a[n], b[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	int dp[H + 2];
	loop(i, 0, H + 1) dp[i] = INT_MAX;
	dp[0] = 0;
	for (int hlth = 0; hlth <= H; hlth++) {
		for (int i = 0; i < n; i++) {
			dp[hlth] = min(dp[max((int)0, hlth - a[i])] + b[i], dp[hlth] );
		}
	}
	cout << dp[H] << endl;
	return;
}

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

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        char[][] map = new char[H][W];
        int mod = 1_000_000_007;
        for (int i=0;i<H;i++) {
            String S = sc.next();
            for (int j=0;j<W;j++) {
                map[i][j] = S.charAt(j);
            }
        }

        long[][] dp = new long[H+1][W+1];
        dp[1][1] = 1;
        for (int i=0;i<H;i++) {
            for (int j=0;j<W;j++) {
                if (!(i==0 && j==0) && map[i][j]=='.') {
                    dp[i+1][j+1] = (dp[i][j+1]+dp[i+1][j])%mod;
                }
            }
        }
        System.out.println(dp[H][W]);
    }
}

Measured memory_bytes: 39400
def combs_mod(n,k,mod):
    #nC0からnCkまで
    inv = [1]*(k+1)
    for i in range(1,k+1):
        inv[i] = pow(i,mod-2,mod)
    ans = [1]*(k+1)
    for i in range(1,k+1):
        ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
    return ans

def solve():
    ans = 0
    mod = 10**9+7
    N, M = map(int, input().split())
    NCi = combs_mod(N,N,mod)
    MPi = [1]*(N+1)
    for i in range(1,N+1):
        MPi[i] = MPi[i-1]*(M+1-i)%mod
    MiPNi = [1]*(N+1)
    for i in range(N-1,-1,-1):
        MiPNi[i] = MiPNi[i+1]*(M-i)%mod
    for i in range(N+1):
        ans += pow(-1,i)*NCi[i]*MPi[i]*(MiPNi[i]**2)%mod
        ans %= mod
    return ans
print(solve())

Measured memory_bytes: 133756
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include<set>
#include<stdio.h>
#include <bitset>
#include<string.h>
#define ii int64_t
#define PI 3.14
#define lli long long int
#define li long int
#define deb(x) cout<<"\nhi"<<x<<"\n"
#define mod 1000000007
#define f(x,n) for(int x=0;x<n;++x)
#define ff(x,y,z) for(x=y;x<=z;++x)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// while(scanf("%d",&n)!=EOF)




using namespace std;
 

int main()
 
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    string s,t,ans;
    int64_t i,j,x,y;
    int dp[3004][3004];
    memset(dp, 0, sizeof(dp));
    cin>>s>>t;
    
    
    for(i=1;i<=s.length();i++)
        for(j=1;j<=t.length();j++)
        {
            if(s[i-1]==t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    

    
    i=s.length();j=t.length();
    while(true)
    {
        if(i>0 && dp[i][j] == dp[i-1][j]) i--;
        else if(j>0 && dp[i][j] == dp[i][j-1]) j--;
        else if(i>0 && j>0&&s[i-1]==t[j-1])
            {ans +=s [i-1];i--;j--;}

        else break;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    
    
}





Measured memory_bytes: 35584
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
using ll = int64_t;

ll solve(int N, const string& S, int k) {
  ll answer = 0;
  ll currentSum = 0;

  deque<int> dPositions;
  deque<int> mPositions;

  for (int i = 0; i < N; i++) {
    char c = S[i];

    if (!dPositions.empty() && dPositions.front() + k == i) {
      dPositions.pop_front();
      currentSum -= mPositions.size();
    }
    if (!mPositions.empty() && mPositions.front() + k == i) {
      mPositions.pop_front();
    }
    assert(currentSum >= 0);

    if (c == 'D') {
      dPositions.push_back(i);
    } else if (c == 'M') {
      mPositions.push_back(i);
      currentSum += dPositions.size();
    } else if (c == 'C') {
      answer += currentSum;
    }
  }

  return answer;
}

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

  int N;
  cin >> N;
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    int k;
    cin >> k;
    cout << solve(N, S, k) << "\n";
  }

  return 0;
}



Measured memory_bytes: 5396
package main

import (
  "fmt"
  "sort"
)

func pow(args ...int) int {
  x, y := args[0], args[1]
  res := 1
  if len(args) == 3 {
    mod := args[2]
    for y != 0 {
      if y & 1 == 1 {res = res * x % mod}
      y >>= 1
      x = x * x % mod
    }
  }  else {
    for y != 0 {
      if y & 1 == 1 {res *= x}
      y >>= 1
      x *= x
    }
  }
  return res
}

func main() {
  a := make([]int, 3)
  var k int
  for i := 0; i < 3; i++ {
    fmt.Scan(&a[i])
  } 
  fmt.Scan(&k)
  sort.Ints(a)
  res := a[0] + a[1] + a[2] * pow(2, k)
  fmt.Println(res)

}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long ll;

int main()
{
	vector<int> v;
	int n;
	while (cin>>n)
	{
		if (n != 0) v.push_back(n);
		else
		{
			cout << v.back() << endl;
			v.pop_back();
		}

	}
	return 0;
}

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

int main(){
	int r, c;
	cin >> r >> c;
	vector< vector<int>> v(r + 1, vector<int>(c + 1));
	
	for (int i = 0; i < r;i++){
		for (int j = 0; j < c; j++){
			cin >> v[i][j];
		}
	}
	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			v[i][c] += v[i][j];
			v[r][j] += v[i][j];
		}
		v[r][c] += v[i][c];
	}
	for (int i = 0; i < r+1; i++){
		for (int j = 0; j < c; j++){
			cout << v[i][j] << " ";
		}
		cout << v[i][c] << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
const int a[9]={111,222,333,444,555,666,777,888,999};
int n;

int main(){
	cin>>n;
	for(int i=0;i<=8;i++)
		if(a[i]>=n){
			cout<<a[i];
			return 0;
		}
}

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np


def main():
	n=II()

	s="abcdefghijklmnopqrstuvwxyz"

	ans=""

	while n:
		n-=1
		ans+=(s[n%26])
		n//=26
	print(ans[::-1])





















if __name__ == "__main__":
	main()


Measured memory_bytes: 9008
N = int(input())
A = list(map(int,input().split()))
max = A[0]
step = 0
for i in range(N-1):
    if A[i+1]<=A[i]:
        step += A[i]-A[i+1]
        A[i+1]=A[i]
    else:
        max = A[i+1]

print(step)

Measured memory_bytes: 32236
#include <limits.h>
#include <stdio.h>
#include <algorithm>

int main() {
  int n;
  scanf("%d", &n);
  int a[n][n];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      scanf("%d", &a[i][j]);
  long long group[1 << n];
  for (int mask = 0; mask < (1 << n); mask++) {
    group[mask] = 0;
    for (int i = 0; i < n; i++) {
      if (((mask >> i) & 1) == 1) {
        for (int j = i + 1; j < n; j++) {
          if (((mask >> j) & 1) == 1) {
            group[mask] += a[i][j];
          }
        }
      }
    }
  }
  long long partition[1 << n];
  partition[0] = 0;
  for (int mask = 1; mask < (1 << n); mask++) {
    partition[mask] = INT_MIN;
    for (int mask2 = mask; mask2 > 0; mask2 = (mask2 - 1) & mask) {
      int mask3 = mask ^ mask2;
      partition[mask] = std::max(partition[mask], partition[mask3] + group[mask2]);
    }
  }
  printf("%lld\n", partition[(1 << n) - 1]);
  return 0;
}


Measured memory_bytes: 1152
import collections 
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
c=defaultdict(int)
for s in a:
    c[s]+=1

a1=list(set(a))

total=0
for j in range(len(a1)):
    x=c[a1[j]]
    total+=x*(x-1)/2

for i in range(n):
    ans=total-c[a[i]]+1
    print(int(ans))

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

int main() {
  int N,M,fn;
  cin>>N;
  M=N;
  fn=0;
  while(M>0){
    int a;
    a=M%10;
    fn+=a;
    M=(M-a)/10;
  }
  if(N%fn==0){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

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

using namespace std;

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A+B<C+D) {
    cout << "Right" << endl;
  } if (A+B==C+D) {
    cout << "Balanced" << endl;
  } if (A+B>C+D) {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
        }
        System.out.println((N + K - 3) / (K - 1));
        sc.close();
    }
}

Measured memory_bytes: 48384
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

typedef struct{
  string name;
  int sum;
}TEAM;

int main(){
  int rev = 0;
  int num;
  while(cin >> num && num){
    if(rev) cout << endl;
    rev++;
    int win, lose, draw;
    TEAM team[num];
    for(int i = 0; i < num; i++){
      cin >> team[i].name >> win >> lose >> draw;
      team[i].sum = win*3 + draw;
    }
    for(int i = 0; i < num-1; i++){
      for(int j = 0; j < num-i-1; j++){
	if(team[j].sum < team[j+1].sum){
	  TEAM tmp = team[j];
	  team[j] = team[j+1];
	  team[j+1] = tmp;
	}
      }
    }
    for(int i = 0; i < num; i++){
      cout << team[i].name <<"," << team[i].sum<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String s = in.next();
            for (int i = 0; i < s.length() - 2; i++) {
                if (s.charAt(i) == s.charAt(i + 1)) {
                    out.printf("%d %d\n", i + 1, i + 2);
                    return;
                }
                if (s.charAt(i) == s.charAt(i + 2)) {
                    out.printf("%d %d\n", i + 1, i + 3);
                    return;
                }
            }

            if (s.charAt(s.length() - 2) != s.charAt(s.length() - 1))
                out.println("-1 -1");
            else
                out.printf("%d %d\n", s.length() - 1, s.length());
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isPrintableChar(int c) {
            return c >= 33 && c <= 126;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();

            int b = readByte();
            while (!isPrintableChar(b))
                b = readByte();

            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }

            return sb.toString();
        }

    }
}



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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

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

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int p[252521];
int rev[252521];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",p+i),p[i]--;
  REP(i,n)rev[p[i]] = i;
  int ans = n;
  int st = 0;
  int lmost = n;
  FORR(i,0,n){
    int pos = rev[i];
    int add = i;
    if(pos < lmost){
      // ok
      lmost = pos;
    }else{
      // ng
      st = n-1-i;
      lmost = pos;
    }
    CHMIN(ans, st + add);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}
	cnt := 0
	t := 1
	for _, a := range as {
		if a == t {
			cnt++
			t += 1
		}
	}

	if cnt == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(n - cnt)
	}
}


Measured memory_bytes: 6440
n = int(input())
S = [input() for i in range(n)]
Chars = [[0 for i in range(n)] for i in range(26)]

for i in range(n):
    for s in S[i]:
        Chars[ord(s)-97][i] += 1

Chars_min = list(map(min,Chars))

ans = ''
for i in range(26):
    ans += chr(i+97)*Chars_min[i]

print(ans)

Measured memory_bytes: 3064
#![allow(unused_imports)]

use std::cmp;
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

#[macro_export]
macro_rules! minimum {
    ($($e:expr),+) => {
        {
            let mut res = Vec::new();
            $(
                res.push($e);
            )+
            res.into_iter().min().unwrap()
        }
    };
}

pub const MOD: usize = 1000000007;

fn main() {
    let n: usize = input();
    let h: usize = input();
    let w: usize = input();

    let ans = (n - h + 1) * (n - w + 1);
    println!("{}", ans);
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


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


int main(){
  int H,W;

  while(1){
  cin >> H >> W;
  if(H==0 && W==0){break;}

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(i==0 || i==(H-1)){
        printf("#");
      }else if(j==0 || j==(W-1)){
        printf("#");
      }else{
        printf(".");
      }
    }
    printf("\n");
  }

    printf("\n");

  }

}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

// s と全点間の距離
void bfs(vector<vector<int>>& g, const int& s, vector<int>& d) {
  queue<int> q;
  q.push(s);

  while (!q.empty()) {
    int f = q.front(); q.pop();
    for (int& to : g[f]) {
      if (chmin(d[to], d[f] + 1)) q.push(to);
    }
  }
}


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

  int n, u, v;
  cin >> n >> u >> v;
  u--; v--;

  vector<vector<int>> g(n, vector<int>());

  rep(i, n-1) {
    int a, b; cin >> a >> b; a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  if (g[u].size() == 1 && g[u][0] == v) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> dt(n, INF), da(n, INF);
  dt[u] = 0;
  da[v] = 0;

  bfs(g, u, dt);
  bfs(g, v, da);

  // 高橋君の方に近いノードのうち，青木君から最も遠いノード
  int ft = 0;
  int fa = 0;
  rep(i, n) {
    if (dt[i] < da[i]) {
      if (chmax(fa, da[i])) ft = dt[i];
    }
  }

  cout << fa - 1 << endl;

  return 0;
}


Measured memory_bytes: 9512
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const data = line[1].split(' ').map(Number);

data.map((x, i, arr) => {
    const p = Math.floor((i+1) / 2);
    const l = (i+1) * 2;
    const r = l + 1;

    const pStr = p > 0 ? `parent key = ${arr[p-1]}, ` : '';
    const lStr = l <= arr.length ? `left key = ${arr[l-1]}, ` : '';
    const rStr = r <= arr.length ? `right key = ${arr[r-1]}, ` : ''

    return [`node ${i+1}: key = ${x}, `, pStr, lStr, rStr].join('');
})
.forEach(x => console.log(x));



Measured memory_bytes: 19400
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x, n; cin >> x >> n;
	set<int> st;
	for (int i = 0; i <= 101; i++)
		st.insert(i);
	for (int i = 0; i < n; i++) {
		int t; cin >> t;
		st.erase(t);
	}
	auto it = st.lower_bound(x);
	int abs1 = abs(*it - x);
	int abs2 = INT_MAX;
	if (it != st.begin())
		abs2 = abs(*(--it) - x);
	cout << (abs1 < abs2 ? x + abs1 : x - abs2);
}


Measured memory_bytes: 3644
n, q = list(map(int, input().split()))

s = input()
plc = [0] * n

for i in range(len(s)-1):
  if s[i] == 'A' and s[i + 1] == 'C':
    plc[i+1] = 1
  else:
    plc[i+1] = 0
    
for i in range(len(s)-1):
  plc[i+1] = plc[i] + plc[i+1]
    
for _ in range(q):
  l, r = list(map(int, input().split()))
  
  print(plc[r-1] - plc[l-1])

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

int a,b,c,licznik=0,mx;

int main() 
{

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin>>a>>b>>c;
	while(a%2!=b%2||b%2!=c%2)
	{
		if(a%2==b%2)
		{
			a+=1;
			b+=1;
			licznik++;
		}
		else if(a%2==c%2)
		{
			a+=1;
			c+=1;
			licznik++;
		}
		else if(b%2==c%2)
		{
			b+=1;
			c+=1;
			licznik++;
		}
	}
	while(a!=b||a!=c||b!=c)
	{
		mx=max(a,b);
		mx=max(mx,c);
		licznik+=(mx-a)/2;
		a=mx;
		licznik+=(mx-b)/2;
		b=mx;
		licznik+=(mx-c)/2;
		c=mx;
	}
	cout<<licznik;
	return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int H, W;
	cin >> H >> W;
	int N;
	cin >> N;

	cout << (N+ max(H, W)-1) / max(H, W) << endl;

	return 0;
}

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


int main(){
    int n;
    string s;
    cin>>n>>s;
    int a=0;
    int b=0;
    int ans=0;
    rep(i,n)if(s[i]=='R')a++;
    ans=max(a,b);
    rep(i,n){
        if(s[i]=='R')--a;
        else ++b;
        int now=max(a,b);
        ans=min(ans,now);
    }
    
    cout<<ans<<endl;
    }

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

int main(){
  int N;
  cin >> N;
  vector<int> rod(N);
  rep(i,N) cin >> rod[i];
  
  sort(rod.begin(),rod.end());
  int ans=0;
  
  rep(i,N){
    rep(j,i){
      rep(k,j){
        if(rod[k]!=rod[j] and rod[j]!=rod[i] and rod[k]+rod[j]>rod[i]) ans++;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
  
  
}

Measured memory_bytes: 3624
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int S = 300;
int dp[S+10][S+10], coeff[S+10][S+10];
signed main() {
    int N, K, M; cin >> N >> K >> M;
    
    // 挿入する場所の候補が i 個、j 個挿入した
    coeff[0][0] = 1;
    for(int i=1; i<=N+1; i++) {
        for(int j=0; j<=N+1; j++) {
            int mul = 1;
            for(int k=0; k<=j; k++) {
                (coeff[i][j] += coeff[i-1][j-k] * mul) %= M;
                (mul *= i) %= M;
            }
        }
    }

    // i 以下の整数を挿入、長さが j
    dp[0][0] = 1;
    for(int i=1; i<=K; i++) {
        for(int j=0; j<=N; j++) {
            for(int k=0; k<=j; k++) {
                (dp[i][j] += dp[i-1][j-k] * coeff[j-k+1][k]) %= M;
            }
        }
    }
    printf("%lld\n", dp[K][N]);
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    
    string s;
    cin >> s;
    n = s.size();
    int sum = 0;
    int b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'B')
            b++;
        else
            sum += b;
    }
    cout << sum << endl;
}

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String
    }
    let s = s.chars().collect::<Vec<char>>();
    let mut n = 0;
    for c in s {
        if c == '+' {
            n += 1;
        } else {
            n -= 1;
        }
    }
    println!("{}", n);
}


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

int main(int argc, char *argv[])
{
	int i;
	int num_week;
	unsigned int total = 100000;

	scanf("%d", &num_week);

	for (i = 0; i < num_week; i++) {
		total = total + ((unsigned int)(ceil((double)total * 0.05 / 1000)))*1000;
	} 

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

 	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

int main() {
	vector <int> h;
	int n ,k ;
	cin >> n >> k;
	int dp[n];
	for(int i = 0 ; i < n ; i++){
		int x;
		cin>>x;
		h.push_back(x);
		dp[i] = INT_MAX;
	}
	
	dp[0] = 0;
	for(int i = 0 ; i < n ; i++){
		for(int j = i-1 ; j >= i-k ; j--){
			if(j < 0)break;
			else{
				dp[i] = min(dp[j] + abs(h[i] - h[j]) , dp[i]);
			}
		}
	}
	cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
#define rep(i,s,n) for(ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(),a.end()
#define mod 1000000007
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/

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


/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll q;
    cin>>q;
    vector<ll>x(q),y(q);
    rep(i,0,q){
        cin>>x[i]>>y[i];
    }
    vector<ll>sum(1000001,0);
    vector<bool>arr(1000001,true);
    arr[1]=false;
    for (int i = 2; i < sqrt(1000001); i++) {
		if (arr[i]) {
			for (int j = 2*i; j <= 1000000; j+=i) {
				arr[j] = false;
			}
		}
	}
    ll t=0;
	rep(i,2,1000001) {
		if (arr[i]&&arr[(i+1)/2]) {
			t++;
            sum[i]=t;
		}
		else {
			sum[i]=sum[i-1];
		}
	}
    rep(i,0,q){
        cout<<sum[y[i]]-sum[x[i]-1]<<endl;
    }

       
}


Measured memory_bytes: 10112
N = int(raw_input())

A_str = raw_input().split()
A = map(int, A_str)

i = 0
r = A[-1]
for j in range(N):
    if A[j] <= r:
        A[i], A[j] = A[j], A[i]
        i += 1

print "%s [%d] %s" % (' '.join(map(str, A[:i-1])), A[i-1], ' '.join(map(str, A[i:])))

Measured memory_bytes: 20728
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e18;
const ll MAXN=100200;
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll n;
cin>>n;
if(n>=30)
    cout<<"Yes";
else
    cout<<"No";
return 0;
}


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

string s;

int main(){
	int n,q;
	cin>>n>>q;
	int y=1;
	
	s="kogakubu10gokan";
	
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		string sa;
		cin>>sa;
		if(y<a&&a<=q)s=sa;
		}
		cout<<s<<endl;
		return 0;
	}

Measured memory_bytes: 3156
//
// Created by keane on 19-6-16.
//

#include <bits/stdc++.h>
using namespace std;
int n,x,l;
int main(void){
    scanf("%d%d",&n,&x);
    int sum=0;
    int ans=1;
    for(int i=1;i<=n;i++){
        scanf("%d",&l);
        sum+=l;
        if(sum<=x){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
import Foundation

func readInts() -> [Int]{
    readLine()!.split(separator: " ").map { Int($0)! }
}

func main(){
    let line = readInts()
    let(a,b,c,d) = (line[0],line[1],line[2],line[3])
    
    for i in 1...100 {
        if c - b * i <= 0 {
            print("Yes")
            return
        }
        if a - d * i <= 0 {
            print("No")
            return
        }
    }
}
main()


Measured memory_bytes: 13576
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unrolled-loops")
#define int long long
#define y1 hoainambimaysolokill
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,pair<int,int> >
#define PII3 pair<pair<int,int>,int >
const long long inf=1e18+3;
long long n;
void solve()
{
   cin>>n;
   --n;
   cout<<n*(n+1)/2;
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    //freopen("BOXES.inp", "r", stdin);
    //freopen("BOXES.out", "w", stdout);

    //int t;cin>>t;while(t--)

    solve();
}


Measured memory_bytes: 256
#連結グラフではない
n = int(input())
V = [[] for _ in range(n+1)]
for _ in range(n):
    inpt = list(map(int,input().split( )))
    if len(inpt)>2:
        V[inpt[0]] = inpt[2:]


D = [0]*(n+1)
F = [0]*(n+1)

time = 1
Q = [1]
D[0] = -1
D[1] = 1
while len(Q) > 0 or 0 in D[1:]:
    v = Q[-1]
    remains = False
    for i in V[v]:
        if D[i] == 0:
            D[i] = time+1
            Q.append(i)
            remains = True
            break
    if not remains:
        F[v] = time+1
        Q.pop()
        
    time += 1
    if len(Q) == 0:
        if 0 in D:
            time += 1
            nxt = D.index(0)
            Q.append(nxt)
            D[nxt] = time
        else:
            pass
        

for i in range(1,n+1):
    print(i,D[i],F[i])



Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; 
  cin >> n;

  int s1,s2,s3,s4;
  
  s1 = n / 1000;
  s2 = (n / 100) % 10;
  s3 = (n / 10) % 10;
  s4 = n % 10;

  if ((s1 == s2 && s2 == s3) || (s2 == s3 && s3 == s4)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


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

int main(){
  string T; cin >> T;
  for (int i = 0; i < T.size(); i++) {
    if (T[i] == '?') T[i] = 'D';
  }
  cout << T << endl;
}

Measured memory_bytes: 3748
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
int main(){
    int n=in();
    vector<string> s(n);
    rep(i,n){
        cin>>s[i];
        vector<char> c(10);
        rep(j,10)c[j]=s[i].at(j);
        sort(All(c));
        string x="";
        rep(j,10)x+=c[j];
        s[i]=x;
    }
    sort(All(s));
    ll ans=0;
    ll now=0;
    string tmp=s[0];
    rep(i,n-1){
        if(s[i+1].compare(tmp)==0)now++;
        else{
            ans+=now*(now+1)/2;
            now=0;
        }
        tmp=s[i+1];
    }
    ans+=now*(now+1)/2;
    cout<<ans<<endl;
}


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

 using namespace std;

 int main() {
   int N;

   cin >> N;

   vector<int> V(N);
   vector<int> C(N);

   for (int i = 0; i < N; i++) cin >> V.at(i);
   for (int i = 0; i < N; i++) cin >> C.at(i);

   int ans = 0;

   for (int i = 0; i < N; i++) {
     if (V.at(i) - C.at(i) > 0) ans += V.at(i) - C.at(i);
   }

   cout << ans << endl;

}


Measured memory_bytes: 256
n = int(input())
i = 0
flag = 0
m = [0,0,0,0]

m[0] = n // 1000
m[1] = n // 100 - m[0] * 10
m[2] = n // 10 - m[0] * 100 -  m[1] * 10
m[3] = n - m[0] * 1000 - m[1] * 100 - m[2] * 10

while i <= 3:
    if m[i] == 2 :
        flag = flag + 1
    i = i + 1
print(flag)

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

int main(){
  
  int64_t n, Lx=2, Ly=1, ans=0, i=2;
  cin >> n;  
  
  if(n==1) {cout << Ly; return 0;}
   
  else
  while(i <= n){
    ans = Lx + Ly;
    Lx = Ly;
    Ly = ans;
    i++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long w[100001], p[100001];
long long dp[101][100001];

long long recur(int i, long long m){
    if(i == n) return 0;
    if(dp[i][m] == -1){
        long long r = recur(i+1,m);
        if(w[i] <= m){
            return dp[i][m] = max ( r , recur ( i +  1 , m - w[i] ) + p[i] );
        }else{
            return r;
        }
    }
    return dp[i][m];
}


int main(){
    long long M;
    cin>>n>>M;
    memset(dp, -1, sizeof dp);
    for(int i = 0; i < n; i++){
        cin>>w[i]>>p[i];
    }
    cout<<recur(0,M);
}


Measured memory_bytes: 80128
while True:
  n = int(input())
  if not n: break
  lst = [0 for i in range(n * 2)]
  for i in range(n):
    lst[int(input()) - 1] = 1
  T = [i for i in range(n * 2) if lst[i]]
  H = [i for i in range(n * 2) if not lst[i]]
  f = -1
  t = 0
  while T and H:
    if not t:
      for i in range(len(T)):
        if T[i] >= f:
          f = T.pop(i)
          t = 1
          break
      else:
        t = 1
        f = -1
    elif t:
      for i in range(len(H)):
        if H[i] >= f:
          f = H.pop(i)
          t = 0
          break
      else:
        t = 0
        f = -1
  print(len(H))
  print(len(T))





Measured memory_bytes: 5604