akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	/** 歩数 */
	private static final int STEP = 0;

	/** 方向 */
	private static final int DEGREE = 1;

	/**
	 * 宝探しをシミュレートする。
	 *
	 * @param args
	 */
	public static void main(String[] args) throws IOException {

		// 入力値を受け取る
		List<int[]> pairList = readPairList();

		// 初期位置
		int degree = 90; // 北を向いているものとする
		double x = 0;
		double y = 0;

		// 指示どおりに移動する
		for (int[] pair : pairList) {

			// 向いている方向から x, y それぞれの移動距離を計算する
			double radian = Math.toRadians(degree);
			double moveX = Math.cos(radian) * pair[STEP];
			double moveY = Math.sin(radian) * pair[STEP];

			// 移動する
			x += moveX;
			y += moveY;

			// デバッグ
			// printResult(x, y);

			// 向いている方向を変える
			degree -= pair[DEGREE];
		}

		// 結果を出力する
		printResult(x, y);
	}

	/**
	 * 標準入力からカンマ区切りの数値を取得し、2次元配列として返却する。
	 *
	 * @return 整数ペアの2次元配列（2×データ数）
	 */
	protected static List<int[]> readPairList() throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));

		// 1行につき2データ取り込む
		List<int[]> pairList = new ArrayList<int[]>();
		while (true) {
			String[] line = reader.readLine().split(",");
			int step = Integer.parseInt(line[STEP]);
			int degree = Integer.parseInt(line[DEGREE]);

			if (step == 0 && degree == 0) {
				// 0,0 が指定されたら終了する
				break;
			}

			// 数値ペアを作成し、リストに追加する
			int[] pair = new int[2];
			pair[STEP] = step;
			pair[DEGREE] = degree;
			pairList.add(pair);
		}

		if (reader != null) {
			reader.close();
		}

		return pairList;
	}

	/**
	 * 結果を出力する。
	 *
	 * @param x
	 *            X 座標
	 * @param y
	 *            Y 座標
	 */
	protected static void printResult(double x, double y) {
		printAsInteger(x);
		printAsInteger(y);
	}

	/**
	 * 引数で与えられた数値の整数部のみを出力する。
	 *
	 * @param value
	 *            出力する数値
	 */
	protected static void printAsInteger(Double value) {
		System.out.println(value.intValue());
	}

}

Measured memory_bytes: 17060
n, a, b=map(int, input().split())
s=str(input())
cnt_a=0
cnt_b=0
for i in range(len(s)):
    if s[i]=='c':
        print('No')
    if s[i]=='a':
        if cnt_a+cnt_b<a+b:
            cnt_a+=1
            print('Yes')
        else:
            print('No')
    if s[i]=='b':
        if cnt_a+cnt_b<a+b and cnt_b<b:
            cnt_b+=1
            print('Yes')
        else:
            print('No')
        
    
    

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

using namespace std;

int main()
{   string A,B,C;
cin  >>A>>B>>C;
if ((A[(A.size())-1]==B.at(0)) && (B[(B.size())-1]==C.at(0)))
    cout << "YES";
else
    cout << "NO";




    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

string toString(int n){
  ostringstream oss;
  oss << n;
  return oss.str();
}

int toInt(string s){
  istringstream iss(s);
  int ret;
  iss >> ret;
  return ret;
}


int main(){
  string s;
  while(cin >> s){
    if(s == "0000") break;
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
      cout << "NA" << endl;
      continue;
    }
    int cnt = 0;
    bool f = false;
    while(s != "6174"){
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
      cout <<"NA"<<endl;
      f = true;
      break;
    }
      cnt++;
      string L, S;
      L = s;
      sort(L.begin(), L.end());
      S = L;
      reverse(L.begin(), L.end());
      int a, b;
      a = toInt(L);
      b = toInt(S);
      s = toString(a-b);
      while(s.size() != 4){
	s += "0";
      }
    }
    if(!f)cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
package main

import "fmt"

import "math"

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)
	h := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &h[i])
	}
	c := make([]int, N)
	c[0] = 0
	for i := 1; i < N; i++ {
		c[i] = math.MaxInt64
		for k := 1; k <= K && i-k >= 0; k++ {
			chmin(&c[i], c[i-k]+abs(h[i]-h[i-k]))
		}
	}
	fmt.Println(c[N-1])
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func chmin(v1 *int, v2 int) {
	if *v1 > v2 {
		*v1 = v2
	}
}


Measured memory_bytes: 5504
#include <stdio.h>
 
main(){
  char data[101];
  int i,temp,ans,p;
 
  while(1){
    if(scanf("%c", &data[0])==EOF) break;
    if(data[0]=='\n') continue;
    for(i=1;i<100;i++){
      scanf("%c", &data[i]);
      if(data[i]=='\n'){
    temp=i;
    break;
      }
    }
     
    ans=0; 
    p=0;
    for(i=temp-1;i>=0;i--){
      if(data[i]=='I'){
    if(p<=1){
      p=1;
      ans+=1;
    }
    else ans-=1;
      }
      if(data[i]=='V'){
    if(p<=2){
      p=2;
      ans+=5;
    }
    else ans-=5;
      }
      if(data[i]=='X'){
    if(p<=3){
      p=3;
      ans+=10;
    }
    else ans-=10;
      }
      if(data[i]=='L'){
    if(p<=4){
      p=4;
      ans+=50;
    }
    else ans-=50;
      }
      if(data[i]=='C'){
    if(p<=5){
      p=5;
      ans+=100;
    }
    else ans-=100;
      }
      if(data[i]=='D'){
    if(p<=6){
      p=6;
      ans+=500;
    }
    else ans-=500;
      }
      if(data[i]=='M'){
    if(p<=7){
      p=7;
      ans+=1000;
    }
    else ans-=1000;
      }
    }
 
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 540
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#define ll long long

using namespace std;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    int count=0;
    for(int i=0;i<N;i++){
        if(A[i]<0){
            count++;
        }
    }
    for(int i=0;i<N;i++){
        A[i]=abs(A[i]);
    }
    sort(A.begin(),A.end());
    ll ans=0;
    if(count%2==0){
        for(int i=0;i<N;i++){
            ans+=A[i];
        }
    }
    else{
        for(int i=1;i<N;i++){
            ans+=A[i];
        }
        ans-=A[0];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  int e[n], w[n];
  int en = 0, wn = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'E') {
      en++;
    } else {
      wn++;
    }
    e[i] = en;
    w[i] = wn;
  }

  int ans = e[n - 1] - e[0];
  for (int i = 1; i < n; i++) {
    int cnt = w[i - 1] + e[n - 1] - e[i];
    ans = min(ans, cnt);
  }

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


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  long long ans = 0;
  long long have = 0;
  for(int i = 0; i < n; i++){
    have += a.at(i);
    ans += have / 2;
    have %= 2;
    if(a.at(i) == 0) have = 0;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
import fractions

A,B,C,D=map(int,input().split())
c=B//C-(A-1)//C 
d=B//D-(A-1)//D 
l=C*D//fractions.gcd(C,D)
cd=B//l-(A-1)//l
print(int(B-(A-1)-c-d+cd))


Measured memory_bytes: 5048
rooms = Array.new(4){ Array.new(3){ Array.new(10, 0) } }
gets.to_i.times do
    b, f, r, v = gets.split.map(&:to_i)
    rooms[b-1][f-1][r-1] += v
end

bs = "#" * 20 + "\n"
puts rooms.map{ |f| f.map{ |r| r.reduce(""){ |pr, nr| "#{pr} #{nr}" } }.join("\n") + "\n" }.join(bs)

Measured memory_bytes: 8760
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
dp[i][j]=i番目の数字をj個使う
*/

struct d{
	ll a,b,c;
};

ll n,m,b[10]={0,2,5,5,4,5,6,3,7,6},dp[10][10010],a[10],tmp,ans[10];
// d a[10];
d from[10][10010];

int main(void){
	cin>>n>>m;
	rep(i,m){
		ll c;
		cin>>c;
		a[i]=c;
	}
	//
	sort(a,a+m);
	//
	reg(j,0,n)dp[0][j]=-1e18;
	dp[0][0]=0;//1つも使わないのは0桁
	rep(i,m){
		reg(j,0,n){
			if(j-b[a[i]]>=0){
				dp[i+1][j]=max(dp[i+1][j-b[a[i]]]+1,dp[i][j]);
				if(dp[i+1][j-b[a[i]]]+1>=dp[i][j]){
					from[i+1][j]={i+1,j-b[a[i]],1};
				}else{
					from[i+1][j]={i,j,0};
				}
			}else{
				dp[i+1][j]=dp[i][j];
				from[i+1][j]={i,j,0};
			}
		}
	}
	d tmp=from[m][n];
	while(tmp.a!=0 || tmp.b!=0 || tmp.c!=0){
		rep(i,tmp.c)cout<<a[tmp.a-1];
		tmp = from[tmp.a][tmp.b];
	}
	cout<<endl;
	// cout<<dp[m][n]<<endl;
	return 0;
}

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

int main()
{

        int Q, H, S, D;
        cin >> Q >> H >> S >> D;
        int N;
        cin >> N;

        int s_min = std::min(Q*4, H*2);
        s_min = std::min(S, s_min);
        int d_min = std::min(D, Q*8);
        d_min = std::min(d_min, H*4);
        d_min = std::min(d_min, S*2);

        long long ans = 0;
        long long  dd = N / 2;
        long long  ss = N % 2;
        ans = dd * d_min + ss * s_min;
        cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>
#include <cmath>


using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR(v,it) for(auto it=(v).begin();it!=(v).end();++it)
#define RIFOR(v,it) for(auto it=(v).rbegin();it!=(v).rend();++it)
#define IN_LL(v) LL v;cin>>v;
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<(v)<<endl
#define MOD 1000000007

int main() {
  IN_LL(S);
  LL a = 0, b = 0, c = 0, d = 0;
  a = 1000000000;
  // abs(a*d-b*c)==S
  if (S <= 1000000000)
    b = 1, c = S, d = 0;
  else {
    // ad > bc
    // bc = ad - S
    d = S / a;
    while (a * d < S)
      ++d;
    if (a * d - S <= 1000000000) {
      b = 1;
      c = a * d - S;
    } else {
      for (b = 1; a * d - b * c != S && b * b <= a * d - S; ++b) {
        c = (a * d - S) / b;
      }
    }
  }
  cout << 0 << " "
    << 0 << " "
    << a << " "
    << b << " "
    << c << " "
    << d << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    xy = [[0,0] for _ in range(N)]
    for a in xy:
        a[0], a[1] = map(int, input().split())
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ans += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** 0.5
    print(ans*2/N)


if __name__ =='__main__': main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
string s;
cin >> s;
int n=(int)(s.length());
ll t[n]={};
rep(i,n-1){
    if(s[i]=='B')if(s[i+1]=='C'){
        t[i]=1;
    }
    if(s[i]=='B')if(s[i+1]=='B'){
        t[i]=-1;
    }
    if(s[i]=='B')if(s[i+1]=='A'){
        t[i]=-1;
    }
    if(s[i]=='A')if(s[i+1]=='C'){
        t[i]=-1;
    }
    if(s[i]=='C')if(s[i+1]=='C'){
        t[i]=-1;
    }
}

/* for (int i = 0; i < n; ++i) {
    cout << t[i] << " ";
}cout  << endl; */

rep(i,n){
    if(t[n-i-2]==-1)t[n-i-2]=0;
    else t[n-i-2]+=t[n-i-1];
}
rep(i,n){
    if(s[i]=='A')ans+=t[i];
}

/* for (int i = 0; i < n; ++i) {
    cout << t[i] << " ";
}cout  << endl; */

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

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair
#define clamp(v,lo,hi) min(max(v,lo),hi)

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


bool solve(int N,ll A,ll B,ll C,ll D){
  ll w=N-1;
  ll dif=abs(B-A);
  ll delta=D+C;

  ll mx=D*w, mn=C*w;
  if (IN(dif, mn, mx)) return true;
  rep(i,w) {
    mx-=delta; mn-=delta;
    if (IN(dif, mn, mx)) return true;
  }
  return false;
}

int main() {
    int n,a,b,c,d; cin>>n>>a>>b>>c>>d;
    cout << (solve(n,a,b,c,d) ? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
ma = max(A) + n -1 
P = [i+a+1 for i,a in enumerate(A) if i+a+1 <= ma]
Q = [j-a+1 for j,a in enumerate(A) if j-a+1 > 0]
 
cQ = Counter(Q)
cP = Counter(P)
ans = 0
for p in cP.keys():
    ans += cQ[p]*cP[p]
print(ans)

Measured memory_bytes: 46108
#include<bits/stdc++.h>
using namespace std;
long long int dp[101][100001] = {0}; 

int main(){
    int N,W;
    cin >> N >> W;
    long long int w[2][100];

    for(int i=0;i<N;i++) cin >> w[0][i] >> w[1][i];

    for(int i=0;i<N;i++){
        for(int sum=0;sum<=W;sum++){
            if(sum - w[0][i]>=0) dp[i+1][sum] = max( dp[i+1][sum], dp[i][sum-w[0][i]] + w[1][i]);

            dp[i+1][sum] = max( dp[i+1][sum], dp[i][sum]);
        //    cout << "dp[" << i+1 << "][" << sum << "]:" << dp[i+1][sum] << endl;
        }
    } 

    cout << dp[N][W] << endl;
    return 0;
 }

Measured memory_bytes: 78336
#include <stdio.h>
#include <limits.h>
#define inf INT_MAX
#define white 0
#define gray 1
#define black 2
#define nil -1

int arr[100][100];
int d[100];
int pi[100];
int color[100];

void dijkstra();
int n;

int main(){
 
  int i,j,k,u,v,c;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      arr[i][j]=inf;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      arr[u][v]=c;
    }
  }

  dijkstra();

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

void dijkstra(){
  int mincost;
  int i,v,u;

  for(i=0;i<n;i++){
    d[i]=inf;
    color[i]=white;
    pi[i]=nil;
  }

  d[0]=0;
  
  while(1){
    u=nil;
    mincost=inf;
    for(i=0;i<n;i++){
      if(color[i]!=black&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==inf) break;
    color[u]=black;
    
    for(v=0;v<n;v++){
      if(color[v]!=black && arr[u][v]!=inf){
        if(d[v]>d[u]+arr[u][v]){
	  pi[v]=u;
	d[v]=d[u]+arr[u][v];
	color[v]=gray;
	}
      }
    }
  }
  
}



Measured memory_bytes: 2080
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
    if(a % b == 0){return b;}
    ll c = a - b;
    return (c >= b)?gcd(c, b):gcd(b, c);
}

int main(){
    ll m, n;
    cin >> m >> n;
    
    ll ans = (m >= n)?gcd(m, n):gcd(n, m);
    
    cout << ans << endl;
    
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2, m);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

const int N = 5050;
ll dp[N][N];

void solve()
{
    int n; cin >> n;
    vector<pll> v;
    for (int i = 0; i < n; i++) {
        ll s, w; cin >> s >> w;
        v.emplace_back(s, w);
    }
    sort(all(v), [](const pll &a, const pll &b) {
        return a.first + a.second < b.first + b.second;
        /* return min(a.first-b.second, b.first) < min(b.first-a.second, a.first); */
    });

    for (int i = 0; i < n; i++) for (int j = 0; j <= n; j++)
        dp[i][j] = (j) ? INFL : 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            ll ret = dp[i][j];
            if (dp[i][j-1] <= v[i].first)
                ret = min(ret, dp[i][j-1] + v[i].second);
            dp[i+1][j] = ret;
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (dp[n][i] != INFL)
            ans = max(ans, i);
    }
    cout << ans << endl;
}

int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 199216
import java.util.Scanner;

class Pair {
    String name;
    int time;
}

public class Main {
    static int LEN;
    static int head;
    static int tail;
    static Pair[] pairs;

    // データの追加
    public static void enqueue(Pair x) {
        pairs[tail] = x;
        tail = (tail + 1) % LEN;
    }

    // データを取り出す
    public static Pair dequeue() {
        Pair x = pairs[head];
        head = (head + 1) % LEN;
        return x;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // n個のプロセス
        int q = sc.nextInt(); // 最大実行時間
        LEN = 100005;
        pairs = new Pair[LEN];
        for (int i = 1; i <= n; i++) {
            pairs[i] = new Pair();
            pairs[i].name = sc.next();
            pairs[i].time = sc.nextInt();
        }
        head = 1;
        tail = n + 1;
        int now = 0;
        while (tail != head) {
            Pair u = dequeue();
            if (u.time - q > 0) {
                now += q;
                u.time = u.time - q;
                enqueue(u);
            } else {
                now += u.time;
                System.out.println(u.name + " " + now);
            }
        }
        sc.close();
    }

}


Measured memory_bytes: 78788
def permu(lis,n,prog):
  if len(lis)==1:
    result.append(prog+[lis[0]])
    n+=5
  
  else:
    for i in range(n):
      lx = lis.copy()
      x = lx[i]
      lx.remove(x)
      permu(lx,n-1,prog + [x])
      
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
import math
l_sum = 0
dic={}
lx = list(range(0,N))
 
for k,i in enumerate(xy):
  l = []
  for j in xy:
    length = ((i[0]-j[0])**2 + (i[1]-j[1])**2)**(1/2)
    l.append(length)
    
  dic[k]=l
  
  

result = []
permu(lx,N,[])
for i in result:
  for j in range(N-1):
    l_sum += dic[i[j]][i[j+1]]
    
print(l_sum/math.factorial(N))

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

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

  int A[N];
  rep(i, N) in(A[i]);

  int r = 0, sum = 0;
  long long ans = 0;
  rep(l, N) {
    while (r < N && sum + A[r] == (sum ^ A[r])) {
      sum += A[r];
      ++r;
    }
    ans += r - l;
    if (l == r)
      ++r;
    sum -= A[l];
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<tll,vector<tll>,greater<tll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll p(n);
  vll num(n+1);
  rep(i,n){
    cin>>p[i];
    num[p[i]]=i+1;
  }
  set<ll> s;
  s.insert(0);
  s.insert(n+1);
  s.insert(num[n]);
  ll ans=0;
  for(int i=n-1;i>0;i--){
    auto itr=s.lower_bound(num[i]);
    itr--;
    ll k=*itr;
    ll cu=0;
    if(k!=0){
      itr--;
      ll kk=*itr;
      cu=k-kk;
      itr++;
      itr++;
      ll kkk=*itr;
      ans+=cu*(kkk-num[i])*i;
    }
    itr=s.lower_bound(num[i]);
    k=*itr;
    if(k!=n+1){
      itr++;
      ll kk=*itr;
      ll cu=kk-k;
      itr--;
      itr--;
      ll kkk=*itr;
      ans+=cu*(num[i]-kkk)*i;
    }
    s.insert(num[i]);
  }
  COUT(ans);
}

Measured memory_bytes: 9404
import sys
sys.setrecursionlimit(10000000)


def main():
    N, K = map(int, input().split())
    A = [0]
    B = [int(c) for c in input().split()]
    A.extend(B)
    dicts = {i: 0 for i in range(1, N + 1)}

    now = 1
    dicts[now] = 0
    num = 0
    flag = False
    while(num < K):
        now = A[now]
        num += 1
        if dicts[now] == 0:
            dicts[now] = num
            continue
        elif not flag:
            cycle = num - dicts[now]
            left = (K - num) % cycle
            K = left
            num = 0
            flag = True
    print(now)







if __name__ == '__main__':
    main()


Measured memory_bytes: 41208
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <deque>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

int main()
{
    string s;
    deque<char> out;

    cin >> s;

    for (char c: s)
    {
        switch (c)
        {
            case '0':
                out.push_back(c); 
                break;
            case '1':
                out.push_back(c); 
                break;
            case 'B':
                if (0 == out.size())
                    continue;

                out.pop_back(); 
                break;
        }
    }

    while (!out.empty())
    {
        cout << out.front();
        out.pop_front();
    }

    cout << endl;

    return 0;
}


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

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

	for (int i = 1; i <= 1000; i++)
	{
		if ((i * 8 / 100) == a)
		{
			if ((i / 10) == b)
			{
				cout << i << endl;
				return 0;
			}
		}
	}

	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <math.h>
using namespace std; 
int main()
{
  double a,b;
  int c,d;
  cin >> a >> b;
  if(b<10)c=10;
  else if(b<100)c=100;
  else c=1000;
  d=sqrt(a*c+b);
  if(d*d==a*c+b)printf("Yes");
  else printf("No");
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))



A = sorted(A)
L = []
ANS = 0

A_max = max(A)

for i in range(N-1):
    L.append(abs(A[i+1]-A[i]))
        
L.append(K + A[0] - A_max)

L = sorted(L)


L.pop(-1)

for i in range(len(L)):
    ANS = ANS + L[i]
    
print(ANS)
    

Measured memory_bytes: 32360
#include <stdio.h>

int main(void)
{
	char s[3], t[3];
	scanf("%s", s);
	scanf("%s", t);

	int i, count;
	count = 0;
	for (i = 0; i < 3; i++)
	{
		if (s[i] == t[i])
		{
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int r = in.nextInt();
        println(r*r);
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 21204
using ll=long long;using ull=unsigned long long;
#include<limits>
namespace pcl{template<typename T>constexpr T TNF=std::numeric_limits<T>::max()/2;constexpr int INF=TNF<int>;constexpr ll LNF=TNF<ll>;constexpr double DNF=TNF<double>;constexpr double EPS=1e-8;constexpr int P7=1'000'000'007;constexpr int DX[]={1,0,-1,0,1,1,-1,-1};constexpr int DY[]={0,1,0,-1,-1,1,1,-1};}
#include<algorithm>
#include<cmath>
#include<iostream>
namespace pcl{template<typename T>void updmax(T&a,T const&b){a=std::max(a,b);}template<typename T>void updmin(T&a,T const&b){a=std::min(a,b);}template<typename T,typename U,typename V>bool in_range(T const&begin,U const&mid,V const&end){return begin<=mid&&mid<end;}template<typename T,typename U,typename V>bool in_range(T const&begin,std::initializer_list<U>list,V const&end){auto p=std::minmax_element(list.begin(),list.end());return begin<=*p.first&&*p.second<end;}template<typename T,typename U,typename V>bool in_range_strict(T const&begin,std::initializer_list<U>list,V const&end){if(!std::is_sorted(list.begin(),list.end()))return false;return in_range(begin,list,end);}template<typename T>inline T cget(){T x;std::cin>>x;return x;}}
#include<iostream>
#include<vector>
namespace pcl{template<typename T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){os<<'[';for(size_t i=0;i<v.size();i++){if(i!=0)os<<",";os<<v[i];}os<<']';return os;}template<typename T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(size_t i=0;i<v.size();i++)is>>v[i];return is;}}
#include<bits/stdc++.h>
using namespace std;using namespace pcl;int main(){int W,H;int x,y;cin>>W>>H>>x>>y;cout<<setprecision(10)<<fixed<<((double)W*(double)H)/2.0<<' '<<(W==x*2&&H==y*2)<<endl;}


Measured memory_bytes: 256
def isBingo(input):
  for i in range(3):
    if input[i][0] is None and input[i][1] is None and input[i][2] is None:
      return True
  for i in range(3):
    if input[0][i] is None and input[1][i] is None and input[2][i] is None:
      return True
  if input[0][0] is None and input[1][1] is None and input[2][2] is None:
    return True
  if input[0][2] is None and input[1][1] is None and input[2][0] is None:
  	return True

bingoCard=[] 
bingoCard.append(list(map(int,input().split())))
bingoCard.append(list(map(int,input().split())))
bingoCard.append(list(map(int,input().split())))

readTimes = int(input())
readNumbers = [int(input()) for i in range(readTimes)]

for row in range(3):
  for col in range(3):
    if bingoCard[row][col] in readNumbers:
      bingoCard[row][col] = None
if isBingo(bingoCard):
  print('Yes')
else:
  print('No')



Measured memory_bytes: 3064
<?php
$s = str_split((string) trim(fgets(STDIN)));
$t = str_split((string) trim(fgets(STDIN)));

$count = 0;
foreach ($s as $i => $char) {
    if ($s[$i] === $t[$i]) {
        $count += 1;
    }
}

echo $count . "\n";


Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
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> inline T powerM(T a,T b){if (b==0) return a;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int n,w; cin >>n >>w;
  vector<int> weight(n+1); //荷物iの重さ(weight[0] = 0)
  vector<ll> value(n+1);   //荷物iの価値(value[0] = 0)
  rep(i,n) cin >>weight.at(i+1) >>value.at(i+1);

  vector<vector<ll>> dp(n+1, vector<ll>(w+1));
  // 荷物iまで重さj以下という条件を満たす最大の価値
  // dp[0][j] = 0

  for (int i=1; i<=n; i++){
    for (int j=0; j<=w; j++){
      chmax(dp.at(i).at(j), dp.at(i-1).at(j));
      if (j >= weight.at(i)) chmax(dp.at(i).at(j), dp.at(i-1).at(j-weight.at(i)) + value.at(i));
    }
  }

  cout <<dp.at(n).at(w) <<endl;
}

Measured memory_bytes: 80256
import java.util.Scanner;
public class Main{
    
    public void solve(){
		Scanner sc = new Scanner(System.in);
		int x;
		x = sc.nextInt();
        System.out.println(x*x*x);
    }
    
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

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


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  int k;
  cin>>k>>s;
  if(s.length()>k){
    for(int i=0;i<k;i++){
      cout<<s[i];
    }
    cout<<"...";
  }else{
    cout<<s;
  }

  
  

}

Measured memory_bytes: 3652
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAXLEN 200005

int i,m,n;
int a[MAXLEN];
long long ans = 0;
    
inline int _abs(int a) {
  return (a>0?a:(-a));
}                     
                      
int main() {          
  scanf("%d", &n);
  for (i = 0; i<n; ++i) {
    scanf("%d", &a[i]);
    a[i] -= i+1;
  } 
  
  m = (n>>1);
  sort(a, a+n);
  
  for (i = 0; i<n; ++i) {
    ans += _abs(a[i]-a[m]);
  } 
  
  printf("%lld\n", ans);
  return 0;
} 

Measured memory_bytes: 896
#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>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, l;
	cin >> n >> l;
	int sum = 0;
	for(int i = 0; i < n; i++){
		sum += l + i;
	}
	int ans = 0;
	for(int i = 1; i < n; i++){
		if(abs(sum - (sum - (l + ans))) > abs(sum - (sum - (l + i)))){
			ans = i;
		}
	}
	cout << sum - (l + ans) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<(x)<<endl
#define DivHim() cout<<">>>>>>>>>>>>>>>"<<endl
#define DivHer() cout<<"<<<<<<<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!!!!!!"<<endl

template<typename T> bool GetMin(T &a,T b)
{
	return ((a<=b)?false:(a=b,true));
}

template<typename T> bool GetMax(T &a,T b)
{
	return ((a>=b)?false:(a=b,true));
}

/*
	 -<Unlimited Blade Works>-
 */

const int N=1e5+10;

void GG()
{
	puts("-1");
	exit(0);
}

char s[N];
int n,fa[N],nw,cnt;

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;++i)
		s[i]-=48;
	if(s[n])
		GG();
	if(!s[n-1])
		GG();
	for(int i=1;i<n;++i)
		if(s[i]^s[n-i])
			GG();
	fa[1]=nw=cnt=2;
	for(int i=n-2;i>=1;--i)
	{
		if(s[i])
		{
			fa[nw]=++cnt;
			nw=cnt;
		}
		else
			fa[++cnt]=nw;
	}
	for(int i=1;i<=n;++i)
		if(fa[i])
			printf("%d %d\n",fa[i],i);
	return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>

int main(){
   int n, i;
   scanf("%d", &n);
   i = n % 10;

   if( i==2 || i==4 || i==5 || i==7 || i==9 ) {
      printf("hon\n");
   } else if( i== 0 || i==1 || i==6 || i==8 ) {
      printf("pon\n");
   } else {
      printf("bon\n");
   }

   return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n = 5;
  vector<int> x(n);
  rep(i, n) cin >> x.at(i);
  rep(i, n) {
    if (x.at(i) == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3592
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

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

int main(){
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if((v-w)*t>=abs(a-b)) cout << "YES" << endl;
    else  cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) :x((x% mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

mint comb(ll n, ll a) {
  mint x = 1, y = 1;
  for (ll i = 0; i < a; i++) {
    x *= (i + 1);
    y *= (n - i);
  }
  return y / x;
}

int main(void) {
  ll n, a, b;
  cin >> n >> a >> b;
  mint ans = mint(2).pow(n) - 1;
  ans -= comb(n, a);
  ans -= comb(n, b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;

fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {

    let (a, b, k) = {
        let n = read::<usize>();
        (n[0], n[1], n[2])
    };

    let mut nums = Vec::new();
    for i in a..(b + 1) {
        if ((i < a + k) || (i > b - k)) {
            nums.push(i);
        }
    }
    nums.sort();
    for i in nums {
        println!("{}", i);
    }
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  return 0;
}


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

int dp[30010][4][1000];

int main(int argc, char const *argv[])
{
	int n; string s; cin >> n >> s;
	rep(i, 30010)rep(j, 4)rep(k, 1000) dp[i][j][k] = 0;
	dp[0][0][0] = 1;

	rep(i, n)rep(j, 4)rep(k, 1000) {
		if (not dp[i][j][k]) continue;
		// select
		if (j < 3) {
			dp[i + 1][j + 1][k * 10 + (s[i] - '0')] = 1;
		}
		// not select
		dp[i + 1][j][k] = 1;
	}

	int ans = 0;
	rep(k, 1000) ans += dp[n][3][k];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 469248
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll a,b;
  cin >> a >> b;
  ll cnt = b - a + 1;
  if(a & 1){
    ll ichi = (cnt - 1) / 2;
    ll ans = ichi & 1;
    ans ^= a;
    if((cnt - 1) & 1) ans ^= b;
    cout << ans << endl;
  }else{
    ll ichi = cnt / 2;
    ll ans = ichi & 1;
    if(cnt & 1) ans ^= b;
    cout << ans << endl;
  }
}

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

int main() {
	int n, max_freq = 0;
	cin >> n;
	map<string, int> freq;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		freq[s]++;
		max_freq = max(max_freq, freq[s]);
	}
	for (auto it : freq) {
		if (it.second == max_freq)
			cout << it.first << "\n";
	}
	return 0;
}


Measured memory_bytes: 25216
h1, m1,h2,m2,k = map(int,input().split())
if h2 * 60 + m2 >h1* 60 + m1:
    r = (h2 * 60 + m2)  -(h1* 60 + m1) - k
else:
    r = (h2 * 60 + m2) + 24 * 60 - (h1* 60 + m1)  - k
print(r)

Measured memory_bytes: 9164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

int a[10010];
vector<int> v;

int s_add(int a, int b){
	string s = to_string(a) + to_string(b);
	int res;
	stringstream ss;
	ss << s;
	ss >> res;
	return res;
}

int main(){
	int n;
	cin >> n;
	REP(i, n){
		cin >> a[i];
	}
	sort(a, a + n);
	REP(i, min(4, n)){
		REP(j, min(4, n)){
			if (i == j)continue;
			v.push_back(s_add(a[i], a[j]));
		}
	}
	sort(ALL(v));
	//REP(i, v.size()){
	//	cout << v[i] << endl;
	//}
	cout << v[2] << endl;
}

Measured memory_bytes: 3316
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		int n, m, a[], b[];
		long graph[], graph2[];
		n = sc.nextInt();
		m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		graph = new long[n];
		graph2 = new long[n];

		int j = 0, k = 0;

		for (int i = 0; i < m; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			if (a[i] == 1 && b[i] != n)
				graph[j++] = b[i];
			if (b[i] == 1 && a[i] != n)
				graph[j++] = a[i];
			if (a[i] == n && b[i] != 1)
				graph2[k++] = b[i];
			if (b[i] == n && a[i] != 1)
				graph2[k++] = a[i];
		}
		sc.close();

		Arrays.sort(graph);
		Arrays.sort(graph2);

		boolean ans = false;

		if (j != 0) {
			for (int i = 0; i < n; ++i) {
				if (graph[i] != 0) {
					int tmp = Arrays.binarySearch(graph2, graph[i]);
					if (tmp >= 0)
						ans = true;
				}
			}
		}

		if (ans)
			System.out.println("POSSIBLE");
		else
			System.out.println("IMPOSSIBLE");
	}

}


Measured memory_bytes: 99128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int a,b; cin >> a >> b;
  string s; cin >> s;

  string ans = "Yes";
  for(int i = 0; i < a + b + 1; i++) {
    if(i >= 0 && i < a) {
      if(s[i] < '0' || s[i] > '9') {
        ans = "No"; break;
      }
    }

    if(i == a && s[i] != '-') {
      ans = "No"; break;
    }

    if(i > a) {
      if(s[i] < '0' || s[i] > '9') {
        ans = "No"; break;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
using namespace std;
#include<string.h>
#include <sstream>
typedef long long int ll;
typedef long double ld;
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <map>
//#define N 4
#include <stack>
#include <unordered_set>
#include <math.h>
#include <cstring>
#include <bitset>
#include <numeric>
#include <set>
#include <sstream>
#include <list>
#include <queue>
#define PI 3.14159265358979323846264338327950
#define mp make_pair
#define inf 1e9
//#define M 1000000007
#define M 1000000007
#define N 100000

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, m, x;
	cin >> n >> m >> x;

	int a[n][m];
	int c[n];

	for (ll i = 0; i < n; i++) {
		cin >> c[i];
		for (ll j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}

	int ans = 1e9;

	for (int i = 0; i < (1 << n); i++) {

		int sum = 0;
		vector<int> arr(m, 0);

		for (int j = 0; j < n; j++) {

			if (i & (1 << j)) {

				sum += c[j];
				for (int k = 0; k < m; k++) {
					arr[k] += a[j][k];
				}
			}
		}

		int f = 1;
		for (int k = 0; k < m; k++) {
			if (arr[k] < x) {
				f = 0;
				break;
			}
		}

		if (f == 1) {
			ans = min(ans, sum);
		}
	}

	if (ans == 1e9) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}

}



Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    vector<ll>x(n);
    for(ll i=0;i<n;i++) cin >> x[i];
    ll ans=0;
    for(ll i=1;i<n;i++){
        if((x[i]-x[i-1])*a<b){
            ans+=(x[i]-x[i-1])*a;
        }else{
            ans+=b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define  rep(i,n) for(li i = 0; i < (n); ++i)
#define  red(i,n) for(li i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    x-=z+z;
    cout<<x/(y+z)+(x%(y+z)>=y)<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int min = Integer.MAX_VALUE;
		for (int i = 1; i <= n / 2; i++) {
			int a = i;
			int b = n - a;
			int sum = sum(a, b);
			if (sum < min)
				min = sum;
		}

		System.out.println(min);

		sc.close();
	}

	static int sum(int a, int b) {
		return sumDigits(a) + sumDigits(b);
	}

	static int sumDigits(int num) {
		int sum = 0;
		while (num != 0) {
			sum += num % 10;
			num /= 10;
		}
		return sum;
	}

}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
int main(){
    int N,x=0;
    string S;
    cin >> N >> S;
    if(N%2!=0){
        cout << "No" << endl;
      return 0;
    }
    for(int i=0; i<N/2; i++){
        if(S.at(i)!=S.at(i+N/2)){
                x=1;
        }
    }

    if(x==1){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;



int main() {
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
	return 0;
}

Measured memory_bytes: 256