akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

ll dp[110][4][4][4];

int main(int argc, char const *argv[])
{
	int n; cin >> n;

	reps(i, 1, 4)rep(j, 4)rep(k, 4)rep(l, 4) {
		if ((j == 0 && k == 2 && l == 1) || (j == 2 && k == 0 && l == 1) || 
			(j == 0 && k == 1 && l == 2)) continue;
		dp[i][j][k][l] = 1;
	}

	reps(i, 3, n)rep(j, 4)rep(k, 4)rep(l, 4) {
		rep(m, 4) {
			if (m == 0) { // A
			} else if (m == 1) { // C
				if ((k == 0 && l == 2) || (k == 2 && l == 0)) continue; // ?AG, ?GA
				if (j == 0 && k == 2) continue; // AG?
				if (j == 0 && l == 2) continue; // A?G
			} else if (m == 2) { // G
				if (k == 0 && l == 1) continue; // ?AC
			} else { // T
			}
			(dp[i + 1][k][l][m] += dp[i][j][k][l]) %= MOD;
		}
	}

	ll ans = 0;
	rep(i, 4)rep(j, 4)rep(l, 4) {
		(ans += dp[n][i][j][l]) %= MOD;
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>

using namespace std;
int main(){
  long long int xs, ys, xt, yt;
  scanf("%lld%lld%lld%lld", &xs, &ys, &xt, &yt);
  int N;
  scanf("%d", &N);
  vector<pair<pair<double, double>, double> > xyr(N+2, pair<pair<double,double>, double>());
  xyr[0].first.first = xs;
  xyr[0].first.second = ys;
  xyr[0].second = 0;
  xyr[N+1].first.first = xt;
  xyr[N+1].first.second = yt;
  xyr[N+1].second = 0;
  for (int i = 1; i <= N; i++){
    scanf("%lf%lf%lf", &(xyr[i].first.first), &(xyr[i].first.second), &(xyr[i].second));
  }

  vector<vector<double> > edge(N+2, vector<double>(N+2, 0));
  for (int i = 0; i < N+2; i++){
    for (int j = 0; j < N+2; j++){
      edge[i][j] = sqrt((xyr[i].first.first-xyr[j].first.first)*(xyr[i].first.first-xyr[j].first.first)+(xyr[i].first.second-xyr[j].first.second)*(xyr[i].first.second-xyr[j].first.second)) - xyr[i].second-xyr[j].second;
      if (edge[i][j] < 0){
        edge[i][j] = 0;
      }
    }
  }
  vector<double> dist(N+2, 0);
  for (int i = 0; i < N+2; i++){
    dist[i] = edge[0][i];
  }  
  set<int> already;
  already.insert(0);
  while(already.size() < (N+2)){
    int minindex = 0;
    double mindist = pow(10.0, 18.0)+1.0;
    for (int i = 0; i < N+2; i++){
      if (already.find(i) == already.end()){
        if (mindist > dist[i]){
          minindex = i;
          mindist = dist[i];
	}
      }
    }
    if (minindex == 0){
      break;
    }
    already.insert(minindex);
    for (int i = 0; i < N+2; i++){
      if (already.find(i) == already.end()){
        dist[i] = min(dist[minindex]+edge[minindex][i], dist[i]);
      }
    }
  }
  printf("%.18lf\n", dist[N+1]);
  return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var raw = ReadLine().Split().Select(int.Parse).ToArray();
            var N = raw[0];
            var M = raw[1];

            var favlist = new int[N][];
            for (int i = 0; i < N; i++)
            {
                raw = ReadLine().Split().Skip(1).Select(int.Parse).ToArray();
                favlist[i] = raw;
            }

            var ans = M;
            for (int i = 1; i <= M; i++)
            {
                foreach (var item in favlist)
                {
                    if (!item.Contains(i))
                    {
                        ans--;
                        break;
                    }
                }
            }

            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13524
#include <sstream>
#include <string>
#include <iostream>
using namespace std;

int main () {
    int a, b, c;
    cin >> a >> b >> c;
    bool s = (a * 100 + b * 10 + c) % 4 == 0;
    if (s==true){
        cout << "YES" << endl;
    }
    else if (s==false){
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define repr(i, a, n) for (ll i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  string S;
  cin >> S;
  if (S[0] != S[1] && S[1] != S[2] && S[0] != S[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
  std::cin.tie(nullptr);                 // 標準入出力高速化
  std::ios_base::sync_with_stdio(false); // CとC++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15); // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N;
  cin>>N;
  
  if(N%2==0){
    co(N*(N-2)/2);
    for(int i=1; i<=N; ++i){
      for(int j=1; j<=N; ++j){
        if(j!=i && j!=N+1-i && i<j) cout<<i<<" "<<j<<endl;
      }
    }
  }
  else{
    co((N-1)*(N-1)/2);
    for(int i=1; i<=N; ++i){
      for(int j=1; j<=N; ++j){
        if(j!=i && j!=N-i && i<j) cout<<i<<" "<<j<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2) 
#include<bits/stdc++.h>
#define rg register
#define il inline
using namespace std;
typedef long long ll;
const int mod=1e9+7;
il int gi(){
	rg int o=0,fl=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')fl=-1,ch=getchar();
	while(isdigit(ch))o=o*10+ch-'0',ch=getchar();
	return fl*o;
}
int n,m,k,cnt[10];
map<pair<int,int>,int>book;
int main(){
	n=gi(),m=gi(),k=gi();
	while(k--){
		int x=gi(),y=gi();
		for(int i=max(1,x-2);i<=min(n-2,x);++i)
			for(int j=max(1,y-2);j<=min(m-2,y);++j)
				book[make_pair(i,j)]++; 
	}
	for(map<pair<int,int>,int>::iterator It=book.begin();It!=book.end();++It)
		++cnt[It->second],++k;
	printf("%lld",1ll*(n-2)*(m-2)-k-1);
	for(int i=1;i<=9;++i)printf("\n%d",cnt[i]);
	return 0;
}


Measured memory_bytes: 56448
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int x; cin >> x;
	int now = 0;
	int cnt = 0;
	int i = 1;
	while (now < x)
	{
		now += i;
		++cnt;
		++i;
	}
	cout << cnt << endl;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

int BitNum(int n){
  int tmp = n;
  int res = 0;
  while(tmp > 0){
    if(tmp % 2 == 1) res ++;
    tmp /= 2;
  }
  return res;
}

int main(){
  int n;
  const int max_n = 15;
  int a[max_n + 1];
  vector<vector<int>> x(max_n+1);
  vector<vector<int>> y(max_n+1);

  // input
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    for(int j = 0; j < a[i]; j++) {
      int b,c;
      cin >> b >> c;
      b--;
      x.at(i).push_back(b);
      y.at(i).push_back(c);
    }
  }

  // bit full search
  bool flag = 0;
  int ans = 0;
  for(int bit = 0; bit < (1<<n); bit++){
    flag = 0;
    // cout << "bit = " << bit << endl;
    for(int i = 0; i < n; i++){
      if(bit&(1<<i)){
        // cout << "person " << i << " = honest" << endl;
        // person i is the honest man
        // check the remark of person i
        for(int j = 0; j < a[i]; j++){
          if((y[i][j] == 1) && (((1<<x[i][j])&bit) > 0)) continue;
          if((y[i][j] == 0) && (((1<<x[i][j])&bit) == 0)) continue;
          // cout << "anser" << j << " = uncorrect" << endl;
          flag = 1;
        }
      }
    }
    if(flag == 0){
      // all remark is correct.
      // cout << bit << endl;
      ans = max(ans, BitNum(bit));
    }
  }

  cout << ans << endl;

  return 0;
}

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

long long gcd(long long a, long long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
long long lcm(long long a, long long b)
{
   return a * b / gcd(a, b);
}

int main() {
    long long a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

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 P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k, a, b; cin >> k >> a >> b;
	if (b - a <= 2) {
		cout << k + 1 << endl;
	}
	else {
		int ans = 1;
		ans += (b - a) * max(0LL, (k - (a - 1)) / 2);
		ans += k - 2 * max(0LL, (k - (a - 1)) / 2);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def f(s):
    for t in ['o', 'x']:
        if s[::4].count(t) == 3 or s[2:7:2].count(t) == 3:
            return t

        for i in range(3):
            if s[i::3].count(t) == 3 or s[3 * i:3 * i + 3].count(t) == 3:
                return t
    return 'd'


while 1:
    try:
        print(f(input()))
    except:
        break



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

int main(){
  string a;
  cin >> a;
  int count = 0;
  for(int i = 0; i<2; i++){
    if(a.at(i) == '9'){
      count++;
    }
  }
  if(count == 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
N, X = map(int, input().split())

L = [0] * (N + 1)
P = [0] * (N + 1)
for i in range(N+1):
    L[i] = 2 ** (i + 2) - 3
    P[i] = 2 ** (i + 1) - 1

def rec(N, X):    

    if X <= 0:
        return(0)
        
    if N == 0:
        return(1)
    
    if X < L[N - 1] + 2:
        return(rec(N - 1, X - 1))
        
    if X == L[N - 1] + 2:
        return(P[N - 1] + 1)
    
    if X > L[N - 1] + 2:
        return(P[N - 1] + 1 + rec(N - 1, X - L[N - 1] - 2))


print(rec(N, X))

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main() {
	
	int X;
	int ans;
	int esc = 0;
	scanf("%d", &X);

	for (int i = X; i < 1000000; i++) {

		if (i == 2 || i == 3 || i == 5 || i == 7) {
			ans = i;
			break;
		}
		
		if (i % 2 == 0) {
			continue;
		}
		else if (i % 3 == 0) {
			continue;
		}
		else if (i % 5 == 0) {
			continue;
		}
		else if (i % 7 == 0) {
			continue;
		}
		for (int j = 11; j < i; j++) {
			if (i % j == 0) {
				esc = 1;
				continue;
			}
		}
		if (esc == 1) {
			esc = 0;
			continue;
		}
		ans = i;
		break;
	}
	
	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

typedef long long ll;
int H, W, N;
map<pair<int, int>, ll> mp, vis;
ll cnt[10];

int main() {
	register int i, j; int x, y;
	scanf("%d%d%d", &H, &W, &N); cnt[0] = 1ll * (H - 2) * (W - 2);
	while(N--) {
		scanf("%d%d", &x, &y);
		if(!vis[make_pair(x, y)]) {
			vis[make_pair(x, y)] = 1;
			for(i = -1; i <= 1; ++i)
				for(j = -1; j <= 1; ++j)
					if(2 <= x + i && x + i <= H - 1 && 2 <= y + j && y + j <= W - 1)
						--cnt[mp[make_pair(x + i, y + j)]],
						++mp[make_pair(x + i, y + j)],
						++cnt[mp[make_pair(x + i, y + j)]];
		}
	}
	for(i = 0; i <= 9; ++i)
		printf("%lld\n", cnt[i]);
	return 0;
}

Measured memory_bytes: 62720
import heapq
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
lab=[]
for i in range(N):
    llab=list(map(int,input().split()))
    lab.append(llab)
lab.sort(key=lambda ab:ab[0])
hq=[]
ind=0
ans=0
for i in range(M):
    for j in range(ind,N):
        if lab[j][0]==i+1:
            heapq.heappush(hq,-lab[j][1])
        else:
            ind=j
            break
    if hq:
            ans-=heapq.heappop(hq)
print(ans)


Measured memory_bytes: 31980
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template<typename T> T mo(T x, T y) { x %= y; return x <= 0 ? x + y : x; }

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;
    for (char c : s) {
        if (c == 'R') {
            x++;
        } else {
            x--;
        }
    }
    if (x > 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<char> vec;
typedef vector<vec> mat;

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

int H,W,ty,tx;
int cnt=0;

mat t;

mat func(mat s,int y,int x,int dir){
  while(1){
    int ny=y+dy[dir];
    int nx=x+dx[dir];
    if(ny<0 || nx<0)break;
    if(ny>=H || nx>=W)break;
    swap(s[y][x],s[ny][nx]);
    y=ny;
    x=nx;
  }
  return s;
}

bool solve(){
  if(cnt>=3 && H>1 && W>1)return true;
  queue< mat > Q;
  map< mat , bool > d;
  Q.push(t);
  d[t]=true;
  while(!Q.empty()){
    mat s=Q.front();Q.pop();

    if(s[ty][tx]=='o')return true;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(s[i][j]=='.')continue;
        for(int k=0;k<4;k++){
          mat next=func(s,i,j,k);
          if(d.count(next)>0)continue;
          d[next]=true;
          Q.push(next);
        }
      }
    }
  }
  return false;
}

int main(){
  cin>>H>>W;
  t.resize(H);
  for(int i=0;i<H;i++){
    t[i].resize(W);
    for(int j=0;j<W;j++){
      cin>>t[i][j];
      if(t[i][j]=='o')cnt++;
      if(t[i][j]=='@'){
        ty=i;
        tx=j;
        t[i][j]='.';
      }
    }
  }
  cout<< (solve()?"yes":"no") <<endl;
  return 0;
}

Measured memory_bytes: 3448
#include <bits/stdc++.h>
using namespace std;
const int n = 100002;

int N;

int sC(int i){
	int c = 0;
	while(i != 0){
		c += i % 10;
		i /= 10;
	}
	return c;
}

int main(){
	cin >> N;
	int C = 1000000;
	for(int a = 1; a < N; ++a){
		int b = N-a;
		C = min(C, sC(a) + sC(b));
	}
	cout << C << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

class union_find {
    protected :
        std::vector<int> par;
    public :
        union_find(int);
        int find(int);
        bool same(int, int);
        virtual void unite(int, int);
};

union_find::union_find(int n) {
    par.resize(n);
    for (int i=0; i<n; i++) {
        par.at(i) = i;
    }
}

int union_find::find(int x) {
    if (par.at(x) == x) return x;
    else return par.at(x) = find(par.at(x));
}

bool union_find::same(int x, int y) {
    return find(x) == find(y);
}

void union_find::unite(int x, int y) {
    int x_par = find(x);
    int y_par = find(y);
    if (x_par == y_par) return;

    par.at(x_par) = y_par;
}

int main() {
    int n = 0, m = 0;
    cin >> n >> m;
    union_find uf(n);
    int x = 0, y = 0, z = 0;
    for (int i=0; i<m; i++) {
        cin >> x >> y >> z;
        x--; y--;
        uf.unite(x, y);
    }

    vector<bool> par(n, false);
    for (int i=0; i<n; i++) {
        par.at(uf.find(i)) = true;
    }

    cout << count(par.begin(), par.end(), true) << endl;

    return 0;
}
 

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

int main(){
  int H;
  int W;
  cin >> H;
  cin >> W;
  char c[H][W];
  int a[H]={};
  int b[W]={};

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> c[i][j];
       if(c[i][j]=='.'){
         a[i]++;
         b[j]++;
        }
      }
  }

  for(int i=0;i<H;i++){
    while(a[i]==W && i<H){
      i++;
      }
      if(i==H){
        break;
      }
    for(int j=0;j<W;j++){
      while(b[j]==H && j<W){
        j++;
      }
      if(j==W){
        break;
      }
      
      cout <<c[i][j];
      
    }
  cout << '\n';
  }
  
  return 0;
}
   


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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

int n,d;

int main(){
    
   
    cin >> n >> d;
    d *= 2;
    d++;
    P((n+d-1)/d);
    
    return  0;
}


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

using namespace std;

int main(void) {
    int N, W;
    cin >> N >> W;

    int w1;
    vector<int> st[4];
    for (int i = 0; i < N; ++i) {
        int w, v;
        cin >> w >> v;
        if (i == 0) w1 = w;
        st[w - w1].push_back(v);
    }

    for (int i = 0; i < 4; ++i) {
        sort(st[i].begin(), st[i].end());
        st[i].push_back(0);
        reverse(st[i].begin(), st[i].end());
        for (int j = 1; j < st[i].size(); ++j) {
            st[i][j] += st[i][j - 1];
        }
    }

    int ret = 0;
    for (long long i = 0; i < st[0].size(); ++i) {
        for (long long j = 0; j < st[1].size(); ++j) {
            for (long long k = 0; k < st[2].size(); ++k) {
                for (long long l = 0; l < st[3].size(); ++l) {
                    long long fact = w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l;
                    if (fact <= W) {
                        ret = max(ret, st[0][i] + st[1][j] + st[2][k] + st[3][l]);

                    }
                }
            }
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>
#define MAX_M 10
#define MAX_N 10

vector<int> k(MAX_M);
vector<vector<int>> s(MAX_M, vector<int>(MAX_N));
vector<int> p(MAX_M);

int main(){
  int n,m;
  cin >> n >> m;
  
  s.resize(m);
  for(int i = 0; i < m; i++){
    cin >> k[i];
    s[i].resize(k[i]);
    for(int j = 0; j < k[i]; j++){
      cin >> s[i][j];
    }
  }
  
  for(int i = 0; i < m; i++){
    cin >> p[i];
  }
  
  int answer = 0;
  for(int pat = 0; pat < (1<<n); pat++){
    for(int lamp = 0; lamp < m; lamp++){
      int sw_count = 0;
      for(auto sw: s[lamp]){
        if(pat>>(sw-1) & 1)
          sw_count++;
      }
      if(sw_count % 2 != p[lamp])
        break;
      if(lamp == m-1){
        answer++;
      }
    }
  }
  
  cout << answer << endl;
}


Measured memory_bytes: 256
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      ArrayList<Integer> list = nextIntArray();
      Collections.sort(list, Comparator.reverseOrder());
      int a = 0;
      int b = 0;
      for(int i = 0; i < N; i++){
        if(i % 2 == 0){
          a += list.get(i);
        }else{
          b += list.get(i);
        }
      }
      myout(a - b);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 32920
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 200000 + 5;
const double PI = acos(-1);
#define ll long long

class TaskC {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int n, k;
		cin >> n >> k;
		vector<int> nums(n);
		for(int i = 0; i < n; i++) {
			cin >> nums[i];
		}
		for(int i=k; i < n; i++) {
			cout << (nums[i] > nums[i-k] ? "Yes":"No") << endl;
		}

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskC solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#define INF 9999999
using namespace std;

int W;
int R[12];
int N;


double calcCost(int u, int v) {
  if(u == N || R[u] == R[v]) return R[v] * 2;
  double d;
  d = sqrt((R[u]+R[v])*(R[u]+R[v]) - (R[u]-R[v])*(R[u]-R[v]));
  return d - R[u] + R[v];
}
/*
double rec(int s, int u) {
  double res = INF;
  if(s == (1 << N) - 1) return 0;
  for(int v = 0; v < N; ++v) {
    if((s >> v) & 1) continue;
    res = min(res, rec(s | (1 << v), v) + calcCost(u, v));
  }
  return res;
}

void solve() {
  double tmp = rec(0, N);
  cout << tmp << " ";
  if(tmp <= W) cout << "OK" << endl;
  else                cout << "NA" << endl;
}
*/
double dp[(1 << 12)][13];

void solve() {
  for(int s = 0; s < (1 << N); ++s) {
    if(s == (1 << N) - 1) fill(dp[s], dp[s] + N+1, 0);
    else                  fill(dp[s], dp[s] + N+1, INF);
  }

  for(int s = (1 << N)-2; s >= 0; --s) {
    for(int u = 0; u <= N; ++u) {
      for(int v = 0; v < N; ++v) {
	dp[s][u] = min(dp[s][u], dp[s | (1 << v)][v] + calcCost(u, v));
      }
    }
  }
  if(dp[0][N] <= W) cout << "OK" << endl;
  else         cout << "NA" << endl;
}

main() {
  string str;
  while(getline(cin, str) && !cin.eof()) {
    stringstream ss; ss << str;
    ss >> W;
    N = 0;
    while(!ss.eof()) {
      int tmp;
      ss >> tmp;
      R[N++] = tmp;
    }
    solve();
  }
}

Measured memory_bytes: 1344
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

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

	const int INF = 0xfffffff;
	for(int n, m, s, g1, g2; cin >> n >> m >> s >> g1 >> g2, n;) {
		--s;
		--g1;
		--g2;
		vector<vector<int> > mat(n, vector<int>(n, INF));
		for(int i = 0; i < n; ++i)
			mat[i][i] = 0;

		for(int i = 0; i < m; ++i) {
			int from, to, cost;
			cin >> from >> to >> cost;
			mat[from - 1][to - 1] = cost;
		}

		for(int k = 0; k < n; ++k)
			for(int i = 0; i < n; ++i)
				for(int j = 0; j < n; ++j)
					chmin(mat[i][j], mat[i][k] + mat[k][j]);

		int ans = INT_MAX;
		for(int i = 0; i < n; ++i)
			chmin(ans, mat[s][i] + mat[i][g1] + mat[i][g2]);

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

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

const int rh_mod = 1e9 + 7;
const int rh_b1 = 1009, rh_b2 = 10007;

class rolling_hash {
	const int n;
	vector<int> r1, r2, h1, h2;
public:
	rolling_hash(const string& s)
		: n(s.size()), r1(n + 1), r2(n + 1), h1(n + 1), h2(n + 1) {
		r1[0] = r2[0] = 1;
		for (int i = 0; i < n; i++) {
			r1[i + 1] = (ll)r1[i] * rh_b1 % rh_mod;
			r2[i + 1] = (ll)r2[i] * rh_b2 % rh_mod;
			h1[i + 1] = ((ll)h1[i] * rh_b1 + s[i]) % rh_mod;
			h2[i + 1] = ((ll)h2[i] * rh_b2 + s[i]) % rh_mod;
		}
	}
	ll get(int l, int r) {
		assert(0 <= l && l <= r && r <= n);
		ll x1 = (h1[r] - (ll)h1[l] * r1[r - l] % rh_mod + rh_mod) % rh_mod;
		ll x2 = (h2[r] - (ll)h2[l] * r2[r - l] % rh_mod + rh_mod) % rh_mod;
		return (x1 << 32LL) | x2;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	string T, P;
	cin >> T >> P;
	int n = T.size(), m = P.size();
	rolling_hash rh(T);
	ll h = rolling_hash(P).get(0, m);
	for (int i = 0; i + m <= n; i++) if (rh.get(i, i + m) == h) {
		printf("%d\n", i);
	}
	return 0;
}



Measured memory_bytes: 19760
#include <stdio.h>
int main(){
    int i,j;
    int n;
    scanf("%d",&n);
    int a[n],v,cnt=0;
    int minj;
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    
    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++)
            if(a[j]<a[minj])
              minj=j;
        v=a[i];
        a[i]=a[minj];
        a[minj]=v;
        if(minj!=i)
            cnt++;
    }
    for(i=0;i<n;i++)
    {
        if(i>0)
        printf(" ");
        printf("%d",a[i]);
    }
    printf("\n%d\n",cnt);
}


Measured memory_bytes: 2144
def getInterval time
  day = Time.local(2014, 12, 8, time[3], time[4], time[5]) - Time.local(2014, 12, 8, time[0], time[1], time[2])
  day = day.divmod(24*60*60)
  hour = day[1].divmod(60*60)
  min = hour[1].divmod(60)
  sec = min[1]
  [hour[0], min[0], sec.to_i]
end

3.times do
  puts getInterval($stdin.gets.chomp.split(" ").map(&:to_i)).join(" ")
end

Measured memory_bytes: 6132
A, B, C = map(int, input().split())
i = 0
if A%2==1 or B%2==1 or C%2==1:
    print(0)
    exit()
elif A == B == C:
    print(-1)
    exit()
while(True):
    A, B, C = (B+C)//2, (C+A)//2, (A+B)//2
    i += 1
    if A%2 == 1 or B%2 == 1 or C%2 == 1:
        break
print(i)


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

using namespace std;

#define INT_MAX 2147483647

int main( void ){

	int ans1 = 0;
	int ans2 = 0;

	for(int i = 0; i < 3; i++ ){
		int tmp;
		cin >> tmp;
		if( tmp == 5 ) ans1++;
		if( tmp == 7 ) ans2++;
	}
	if(ans1 == 2 && ans2 == 1){
		cout << "YES";
	}else{
		cout << "NO";
	}
	return 0;

}

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

bool vis[100];
vector< vector<int> > vec;

int dfs(int cur)
{
	int i,cnt=1;
	for(i=0;i<vec[cur].size();i++)
	{
		if(!vis[vec[cur][i]])
		{
			vis[vec[cur][i]]=1;
			cnt+=dfs(vec[cur][i]);
		}
	}
	return cnt;
}

int main()
{
	int n,m,cnt,ans,u,v,i,j;	
	vector<int> vecto;
	vector< pair<int,int> > vp;
	cin>>n>>m;
	for(i=0;i<=n;i++)
		vec.push_back(vecto);
		
	for(i=0;i<m;i++)
	{
		cin>>u>>v;
		vp.push_back(make_pair(u,v));
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	ans=0;
	for(i=0;i<m;i++)
	{
		u=vp[i].first;
		v=vp[i].second;
		cnt=0;
		for(j=0;j<=n;j++)
			vis[j]=0;
		vis[v]=vis[u]=1;
		cnt+=dfs(u);	
		for(j=0;j<=n;j++)
			vis[j]=0;
		vis[v]=vis[u]=1;
		cnt+=dfs(v);
		if(cnt==n)
			ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline())
a = list(map(int,stdin.readline().split()))
a.sort(reverse = True)
ans = a[0]
count = 0
cur = 1
for _ in range(n-2):
    ans += a[cur]
    count += 1
    if count == 2:
        count = 0
        cur += 1
print(ans)


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

long long X;

int main(){
	cin >> X;

	for(long long a = -1000; a < 1000; a++) {
		for(long long b = -1000; b < 1000; b++) {
			if(a*a*a*a*a - b*b*b*b*b == X) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	return 1;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 1e9 + 7;

signed main() {
    int n, x, l;
    cin>>n;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        cin>>x>>l;
        v.push_back(make_pair(x + l, x - l));
    }
    sort(v.begin(), v.end());
    int ans = 0, now = -INF;
    for (auto p: v) {
        if (now <= p.second) {
            ans++;
            now = p.first;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2420
N = int(input())
S = [0] * N
for i in range(N):
    S[i] = input()

count_list = [0]*4
count_list[0] = S.count('AC')
count_list[1] = S.count('WA')
count_list[2] = S.count('TLE')
count_list[3] = S.count('RE')

print('AC x' , count_list[0])
print('WA x' , count_list[1])
print('TLE x' , count_list[2])
print('RE x' , count_list[3])


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

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

  vector<int> dp(W + 1, 0);
  for (int i = 0; i < N; i++) {
    int v, w;
    cin >> v >> w;

    for (int j = W; j - w >= 0; j--) {
      dp[j] = max(dp[j], dp[j - w] + v);
    }
  }

  cout << dp[W] << endl;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
int n,s,a[3005];
ll dp[3005],ans=0;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>s; 
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		dp[0]++;
		for(int j=s;j>=a[i];j--){
			dp[j]=(dp[j]+dp[j-a[i]])%mod;
//			cout<<j<<" "<<dp[j]<<endl;
		}
		ans=(ans+dp[s])%mod;
	} 
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const long long int MOD = 1000003;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<pair<int,int>>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i.first] > depth[cn] + i.second) {
				depth[i.first] = depth[cn] + i.second;
				Q.push(i.first);
			}
		}
	}
	return;
}

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

	while (cin >> N, N) {
		vector<int>p(N);
		vector<int>c(N);
		int sum = 0;
		vector<vector<pair<int, int>>>edge(N);
		for (int i = 1; i < N; i++) {
			cin >> p[i];
			p[i]--;
		}
		for (int i = 1; i < N; i++)cin >> c[i];
		sum = accumulate(c.begin(), c.end(), 0);
		vector<int>nsum(N);
		int nsumsum = 0;
		vector<int>dir(N);
		for (int i = 1; i < N; i++) {
			dir[i]++;
			dir[p[i]]++;
			edge[i].push_back({ p[i],c[i] });
			edge[p[i]].push_back({ i,c[i] });
		}
		vector<vector<int>>depth(N, vector<int>(N, MOD));
		for (int i = 0; i < N; i++) {
			Calculate_Depth(edge, depth[i], i);
		}
		vector<int>cand;
		for (int i = 1; i < N; i++) {
			if (dir[i] == 1) {
				//cout<<"dir "<<i<<endl;
				cand.push_back(p[i]);
				nsum[p[i]] += c[i];
			}
			if (dir[0] == 1 && p[i] == 0) {
				cand.push_back(i);
				nsum[i] += c[i];
			}
		}
		nsumsum = accumulate(nsum.begin(), nsum.end(), 0);
		int ans = MOD;
		//for (auto i : cand)cout << i << endl;
		for (int i = 0; i < cand.size(); i++) {
			for (int j = i; j < cand.size(); j++) {
				int x = cand[i], y = cand[j];
				int box = depth[x][y];
				ans = min(ans, box * 2 + nsumsum + (sum - nsumsum - box) * 3);
				//cout << sum << " " << nsumsum << " " << box << " " << ans << endl;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 5512
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<i64>();
    println!("{}", n*(n-1)/2);
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
//k_k_dubey_
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
#define non __builtin_popcount
#define ml map<ll, ll> 
#define ms map<string , ll> 
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	
	ll l,r,i,j;
	cin>>l>>r;
	ll kk= r-l, ans=0;
	if(kk<700){
	    ll an= inf;
	    for(i=l; i<r+1; i++){
	        for(j=i+1; j<r+1; j++){
	            ll tmp= (i*j)%2019;
	            if(tmp<an)
	            an= tmp;
	        }
	    }
	    ans= an;
	}
	
	cout<<ans;
    return 0;
}























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

//What is the Most Popular Shop in Tokaichi?
public class Main{

	static class E implements Comparable<E>{
		char a;
		int s;
		public E(char a, int s) {
			this.a = a;
			this.s = s;
		}
		public int compareTo(E o) {
			return o.s-s;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int s = sc.nextInt()+sc.nextInt();
			if(s==0)break;
			E[] e = new E[5];
			e[0]=new E('A',s);
			for(int i=1;i<5;i++)e[i]=new E((char)(i+'A'),sc.nextInt()+sc.nextInt());
			Arrays.sort(e);
			System.out.println(e[0].a+" "+e[0].s);
		}
	}
}

Measured memory_bytes: 12000
<?php
$n = trim(fgets(STDIN));
$array = explode(" ", trim(fgets(STDIN)));

for($i = 0; $i < $n; $i++){
    for($j = count($array) - 1; $j >= 0 ; $j--){
        if($array[$j] == $j + 1){
            unset($array[$j]);
            $array = array_values($array);
            $stack[] = ($j + 1);
            break;
        }
        if($j == 0){
            echo -1;
            exit;
        }
    }
}
echo implode("\n", array_reverse($stack));

Measured memory_bytes: 4856
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define forn(i,n)            for(int i=0; i<n; i++)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zeus()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	//zeus();

	int n; cin >> n;

	int a[n], b[n], c[n];

	forn(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}

	int dp[n + 1][3];

	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;

	for (int day = 1; day <= n; day++) {

		dp[day][0] = max(dp[day - 1][1] + a[day - 1], dp[day - 1][2] + a[day - 1]);
		dp[day][1] = max(dp[day - 1][0] + b[day - 1], dp[day - 1][2] + b[day - 1]);
		dp[day][2] = max(dp[day - 1][0] + c[day - 1], dp[day - 1][1] + c[day - 1]);

	}

	cout << max({dp[n][0], dp[n][1], dp[n][2]});
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
using ll=long long;

int main() {
  ll N,K;cin>>N>>K;
  double sum = 0.0;
  for(ll i=1;i<=N;++i) {
    ll p=i;
    double pp=1;
    while(p<K) p*=2,pp/=2.0;
    sum+=pp;
  }
  printf("%.10lf\n",sum/N);
}



Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
ans = "Yes"

for i in range(1,n):
  if h[-i-1] > h[-i]:
    h[-i-1] = h[-i-1] - 1
  
  if h[-i-1] > h[-i]:
    ans = "No"
    break

print(ans)

Measured memory_bytes: 14396
#include <iostream>
#include <stdlib.h>

using namespace std;
int main(){
  int H,W;
  std::cin >> H>>W;
  int A[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      std::cin >> A[i][j];
    }
  }
  int min_value=10000000;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      //幹線道路は北からi,西からjのところ
      int value=0;
      for(int k=0;k<H;k++){
        for(int l=0;l<W;l++){
          if(k==i||l==j){
            continue;
          }else{
            int short_length;
            if(abs(k-i)<abs(l-j)){
              short_length=abs(k-i);
            }else{
              short_length=abs(l-j);
            }

            value +=short_length*A[k][l];
          }
        }
      }
      if(value<min_value){
        min_value=value;
      }

    }
  }
  std::cout << min_value << '\n';

}


Measured memory_bytes: 3096
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int cost = 700;
      for(char c : s.toCharArray())
        if(c != 'x')
          cost += 100;
      System.out.println(cost);
  }
}

Measured memory_bytes: 21716
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = a * 800;
		
		if (a >= 15) {
			double c = b - 200 * Math.floor(a/15);
			System.out.println((int)c);
		} else {
			System.out.println(b);
		}
	}
}

Measured memory_bytes: 21844