akhauriyash/Code-Regression huggingface dataset:
from collections import deque


def bfs():
    d = [[float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]


h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
sx, sy = 0, 0
gx, gy = h - 1, w - 1

# 白いマスを数える
white = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            white += 1

res = bfs()
if 0 < res < float("inf"):
    # 白いマスの数から最短経路でかかるコスト分を引く
    # ゴールを黒いマスに変えることはできないためその分も引く
    print(white - res - 1)
else:
    print(-1)

Measured memory_bytes: 9508
#include<stdio.h>
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
  int D, G;
  scanf("%d%d", &D, &G);
  int p[D], c[D];
  for (int i=0 ; i<D ; i++) {
    scanf("%d%d", &p[i], &c[i]);
  }

  int res = 1000000000;
  for (int comp = 0 ; comp < (1 << D) ; comp++) {
    int score = 0;
    int problems = 0;
    for (int i=0 ; i<D ; i++) {
      if ((comp >> i) & 1) {
        score += p[i] * 100 * (i+1) + c[i];
        problems += p[i];
      }
    }

    for (int i=D-1 ; i>=0 ; i--) {
      if (!((comp >> i) & 1)) {
        int ps = 1;
        while (ps <= p[i]-1 && score < G) {
          score += 100 * (i+1);
          ps += 1;
          problems += 1;
        }
      }
    }

    //G以上になってるか
    if (score >= G) {
      res = min(res, problems);
    }

  }

  printf("%d\n", res);
}


Measured memory_bytes: 128
#include <stdio.h>
#include<string.h>
int main(int argc, char const *argv[])
{
  int a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++)
      scanf("%d",&a[i][j]);
  }
  int n;
  scanf("%d",&n);
  int b[101];
  for(int i=0;i<101;i++) b[i]=1;
  int x;
  for(int i=0;i<n;i++){
    scanf("%d",&x);
    b[x]=0;
  }
  int sum=0;
  for(int i=0;i<3;i++){
    sum=0;
    for(int j=0;j<3;j++){
      sum+=b[a[i][j]];
    }
    if(sum==0){
      printf("Yes");
      return 0;
    }
  }
  for(int i=0;i<3;i++){
    sum=0;
    for(int j=0;j<3;j++){
      sum+=b[a[j][i]];
    }
    if(sum==0){
      printf("Yes");
      return 0;
    }
  }
  sum=b[a[0][0]]+b[a[1][1]]+b[a[2][2]];
  if(sum==0){
    printf("Yes");
    return 0;
  }
  sum=b[a[0][2]]+b[a[1][1]]+b[a[2][0]];
  if(sum==0){
    printf("Yes");
    return 0;
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
int n;
int a[200],r;
double b,v,e,f;
double dp[200];
int main(){
  while(cin>>n&&n){
    for(int i=1;i<=n;i++)cin>>a[i];
    cin>>b;
    cin>>r>>v>>e>>f;
    for(int i=0;i<=n;i++)dp[i]=INF;
    dp[0]=0;
    a[0]=0;
    for(int i=0;i<n;i++){
      int x=0;
      double sum=0;
      for(int j=i+1;j<=n;j++){
    while(a[i]+x<a[j]){
      double d;
      if(x>=r){
        d=x-r;
        sum += 1.0/(v-e*d);
      }else{
        d=r-x;
        sum += 1.0/(v-f*d);
      }
      x++;
    }
    if(i!=0)dp[j]=min(dp[j],dp[i]+b+sum);
    else dp[j]=min(dp[j],sum);
      }
    }
 
    printf("%.6f\n",dp[n]);
  }
  return 0;
}

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


int main(){
    string s;
    int n,k;
    cin>>n;
    cin>>s;
    cin>>k;
    char S = s[k-1];
    for(int i=0;i<s.size();i++) {
        if(s[i]==S) {
            cout<<s[i];
        }
        else {
            cout<<"*";
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc138/submissions/9369775
import java.util.*;
import java.io.PrintWriter;
 
public class Main {
 
  public static ArrayList[] edge;
  public static long[] point;
  public static boolean[] visit;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int q = Integer.parseInt(sc.next());
    point = new long[n];
    visit = new boolean[n];
    edge = new ArrayList[n];
    for(int i = 0; i < n; i++) {
      edge[i] = new ArrayList<Integer>();
    }
    for(int i = 0; i < n - 1; i++) {
      int a = Integer.parseInt(sc.next()) - 1;
      int b = Integer.parseInt(sc.next()) - 1;
      edge[a].add(b);
      edge[b].add(a);
    }
    for(int i = 0; i < q; i++) {
      int p = Integer.parseInt(sc.next()) - 1;
      long x = sc.nextLong();
      point[p] += x;
    }
 
    dfs(0, -1);
    PrintWriter out = new PrintWriter(System.out);
    for(int i = 0; i < n; i++) {
      out.print(point[i] + " ");
    }
    out.flush();
  }
 
  public static void dfs(int v, int p) {
    ArrayList<Integer> list = edge[v];
    long x = point[v];
    for(int i = 0; i < list.size(); i++) {
      int t = list.get(i);
 
      if(!visit[t] && t != p) {
        point[t] += x;
        dfs(t, v);
      }
    }
  }
}

Measured memory_bytes: 210664
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int r, g, b;
    cin >> r >> g >> b;
    
    // calculation
    int sum = 100*r + 10*g + b;
    if (sum%4 == 0) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

bool chk(set<int> a,int b,int l){
	queue<int> que;
	bool ok[51] = {};
	for(auto it : a){
		ok[it] = true;
		que.push(it);
	}
	while(!que.empty()){
		int v = que.front();que.pop();
		for(int i = 1;i <= l;i++){
			int to = v % i;
			if(!ok[to]){
				ok[to] = true;
				que.push(to);
			}
		}
	}
	return ok[b];
}

signed main(){
	int n,b[50],ans = 0;
	set<int> st[50];
	cin >> n;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		st[i].insert(a);
	}
	for(int i = 0;i < n;i++) cin >> b[i];
	for(int i = 0;i < n;i++){
		if(!chk(st[i],b[i],50)){
			cout << -1 << endl;
			return 0;
		}
	}
	while(1){
		bool flag = true;
		for(int i = 0;i < n;i++){
			if(!st[i].count(b[i])) flag = false;
		}
		if(flag) break;
		int ma = 0;
		for(int i = 0;i < n;i++){
			for(int j = 1;j <= 50;j++){
				if(chk(st[i],b[i],j)){
					chmax(ma,j);
					break;
				}
			}
		}
		for(int i = 0;i < n;i++){
			vector<int> vec;
			for(auto it : st[i]) vec.pb(it % ma);
			for(int v : vec) st[i].insert(v);
		}
		ans += (1ll << ma);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R;
    cin >> R;
    cout << R * R << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, itertools, fractions, math, collections, heapq
sys.setrecursionlimit(10**7)
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

n, a, b = LI()
s = list(input())

aq, bq = 0, 0
for ss in s:
    if ss=='a':
        if aq + bq < a+b:
            print('Yes')
            aq+=1
        else:
            print('No')
    if ss=='b':
        if aq + bq < a+b and bq+1<=b:
            print('Yes')
            bq+=1
        else:
            print('No')
    if ss=='c':
        print('No')


Measured memory_bytes: 6736
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    long double cnt = 0;
    FOR(i, 1, N+1) if (i % 2 == 1) cnt++;

    print(cnt / N);
    
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    ull A, B;
    cin >> A >> B;
    ull ans = 0;
    FOR(i, 1, 63) {
        ull tob = B / (1ULL << i) * (1ULL << (i - 1));
        if (B % (1ULL << i) >= (1ULL << (i - 1))) {
            tob += B % (1ULL << i) + 1 - (1ULL << (i - 1));
        }
        ull toa = (A - 1) / (1ULL << i) * (1ULL << (i - 1));
        if ((A - 1) % (1ULL << i) >= (1ULL << (i - 1))) {
            tob += (A - 1) % (1ULL << i) + 1 - (1ULL << (i - 1));
        }
        // cout << "i:" << i << " " << tob << " " << toa << endl;

        ull dif = tob - toa;
        if (dif % 2 == 1) {
            ans |= (1ULL << (i - 1));
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n1=0,n2=0;
	cin>>n1>>n2;
	char t[n1][n2];
	int x[n1][n2];
	for(int i=0;i<n1;++i)
	 for(int j=0;j<n2;++j)
	  x[i][j]=0;
	for(int i=0;i<n1;++i)
	 for(int j=0;j<n2;++j)
	  cin>>t[i][j];
	for(int i=0;i<n1;++i)
	{
	 for(int j=0;j<n2;++j)
	 {
	  if(t[i][j]=='#')continue;
	  if(t[i][j]=='.')
	  {
	  //↓检查是否越界
	    if(j+1<n2){if(t[i][j+1]=='#')x[i][j]++;}
	  	if(j-1>=0){if(t[i][j-1]=='#')x[i][j]++;}
	  	if(i+1<n1){if(t[i+1][j]=='#')x[i][j]++;}
	  	if(i-1>=0){if(t[i-1][j]=='#')x[i][j]++;}
	  	if(j-1>=0 && i-1>=0){if(t[i-1][j-1]=='#')x[i][j]++;}
	  	if(j+1<n2 && i+1<n1){if(t[i+1][j+1]=='#')x[i][j]++;}
	  	if(j-1>=0 && i+1<n1){if(t[i+1][j-1]=='#')x[i][j]++;}
	  	if(j+1<n2 && i-1>=0){if(t[i-1][j+1]=='#')x[i][j]++;}
	  }
     }
    }
    for(int i=0;i<n1;++i)
    {
	 for(int j=0;j<n2;++j)
	 {
	  if(t[i][j]=='#')cout<<t[i][j];
	  else cout<<x[i][j];
     }
	 cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
count = 0
for v in C.values():
	count += v * (v - 1) // 2
for a in A:
	x = C[a]
	print(count - (x * (x - 1) // 2) + ((x - 1) * (x - 2) // 2))

Measured memory_bytes: 88012
from collections import *
from heapq import *
H,W=map(int,input().split())
S=[input() for i in range(H)]
if S[0][0]=="#":
    count=1
else:
    count=0
idlemax=10**5
visited=[[idlemax for w in range(W)] for h in range(H)]
stack=deque([[0,0,bool(S[0][0]=="#")*1,bool(S[0][0]=="#")*1]])
while stack:

    h,w,m,flag=stack.popleft()
    if m>visited[h][w]:
        continue
    for y,x in [[0,1],[1,0]]:
        Y=h+y;X=w+x
        if Y<H and X<W:
            if flag:
                if visited[Y][X]>m:
                    if S[Y][X]==".":
                        nflag=0
                    else:
                        nflag=1
                    visited[Y][X]=m
                    stack.append([Y,X,m,nflag])
            else:
                if S[Y][X]=="#":
                    nflag=1
                    M=m+1
                else:
                    nflag=0
                    M=m
                if visited[Y][X]>M:
                    visited[Y][X]=M
                    stack.append([Y,X,M,nflag])
#print(visited)
print(visited[-1][-1])


Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, x;
    cin >> n >> x;
    vector <int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }   
    vector <int> cur = a;
    int ans = 1e18;
    for (int sh = 0; sh < n; ++sh) {
        int nn = sh * x;
        for (int i = 0; i < n; ++i) {
            cur[i] = min(cur[i], a[(i - sh + n) % n]);
            nn += cur[i];
        }   
        ans = min(ans, nn);
    }   
    cout << ans << endl;
}

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

int main(void)
{
    int x[5]={};
    for(int i=0;i<5;i++)
    {
        cin >> x[i];
    }

    for(int i=0;i<5;i++)
    {
        if(x[i]==0)
        {
            cout << i+1 << endl; 
        }
    }
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,i,c=0;
    string s;
    cin>>k>>s;
    for(i=0;i<=k-3;i++)
    {
        if(s[i]=='A')
              if(s[i+1]=='B')
                if(s[i+2]=='C')
                c++;
    }
   cout<<c<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string a;
    cin>>a;
    int w[n],e[n],f;
    for(int i=0;i<n;i++)
    {
    	w[i]=0;
    	e[i]=0;
	}
	if(a[0]=='E')
	    e[0]=1;
	else
	    w[0]=1;
	for(int i=1;i<n;i++)
	    if(a[i]=='E')
	     {
	     	e[i]=e[i-1]+1;
			w[i]=w[i-1]; 
		 }
		 else
	     {
	     	e[i]=e[i-1];
			w[i]=w[i-1]+1; 
		 }
	int minv=3000005;
	for(int i=0;i<n;i++) 
	{
		if(i==0)
		    f=e[n-1]-e[0];
		else if(i==n-1)
		    f=w[n-2];
		else
		    f=w[i-1]+(e[n-1]-e[i]);
		minv=min(minv,f);
	}
	cout<<minv;
}


Measured memory_bytes: 2948
n=int(input())

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

max=0
for i in range(n):
    for j in range(n):
        if i!=j:
            x=int(a[i]-a[j])
            y=abs(x)
            if max<=y:
                y
                max=y


print(max)
    

Measured memory_bytes: 2940
#include <iostream>
#include <map>
#include <set>
#include <queue>
using namespace std;

int main(void){
  int n;
  while(cin>>n,n){
    map<string,set<string> > teams;
    bool f=false;
    string fteamname;
    for(int i=0;i<n;++i){
      string s;cin>>s;
      int b = s.find(":");
      string teamname = s.substr(0,b);
      if(f==false) fteamname = teamname;
      f=true;
      vector<string> splitted;
      int cur = b+1,nxt;
      while((nxt = s.find(',',cur)) != string::npos || (nxt = s.find('.',cur)) != string::npos){
      	splitted.push_back(s.substr(cur,nxt-cur));
      	cur = nxt+1;
      }
      for(int i=0;i<splitted.size();++i) teams[teamname].insert(splitted[i]);
    }
    
    set<string> firstteam;
    set<string> done;
    priority_queue<string> Q;
    Q.push(fteamname);
    while(!Q.empty()){
      string teamname = Q.top();Q.pop();
      set<string>::iterator it = teams[teamname].begin();
      for(;it!=teams[teamname].end();++it){
        if(teams.find(*it) != teams.end()){
        	if(done.find(*it)==done.end()){
	        	Q.push(*it);
	        	done.insert(*it);
        	}
        }else firstteam.insert(*it);
      }
    }
    cout<<firstteam.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1376
# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, L, T, pos, dir):
    # 円形だからどんなにぶつかっても1-Nまで順番に並んでいることは変わりない。
    pos_mov = []
    for i in range(1, N + 1):
        if dir[i] == 1:
            pos_mov.append((pos[i] + T) % L)
        elif dir[i] == 2:
            pos_mov.append((pos[i] - T) % L)

    pos_mov.sort()

    count = 0

    for i in range(2, N + 1):
        dif = pos[i] - pos[1]
        if dir[1] == 1:
            if dir[i] == 2:
                if dif <= 2 * T:
                    count += ((2 * T - dif) // L + 1)
        elif dir[1] == 2:
            if dir[i] == 1:
                if (L - dif) <= 2 * T:
                    count += ((2 * T - (L - dif))// L + 1)

    if dir[1] == 1:
        pos1 = (pos[1] + T) % L
        num1 = count % N + 1
    elif dir[1] == 2:
        pos1 = (pos[1] - T) % L
        num1 = -count % N + 1

    if dir[1] == 1:
        ind = max([i for i in range(1, N + 1) if pos_mov[i - 1] == pos1])
    else:
        ind = min([i for i in range(1, N + 1) if pos_mov[i - 1] == pos1])

    ans = []
    for i in range(1, N + 1):
        ans.append(pos_mov[(ind - num1 + i) % N - 1])

    return ans


def main():
    N, L, T = ILI()
    pos = dict()
    dir = dict()
    for i in range(1, N + 1):
        X, W = ILI()
        pos[i] = X
        dir[i] = W

    ans = solve(N, L, T, pos, dir)
    for i in ans:
        print(i)


if __name__ == "__main__":
    main()


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

int main(){
    int n,k;
  cin >> n >> k;
  
  vector<bool> D(10);
  for(int i=0; i<10; i++){
    D[i] = true;
  }
  
  int s;
  for(int i=0; i<k; i++){
    cin >> s;
    D[s] = false;
  }
  
  for(int i=n;;i++){
    int r = i;
    bool ok = true;
    while(r){
      if(D[r%10]==false){
        ok = false;
        break;
      }
      r/=10;
    }
    if(!ok)continue;
    cout << i << endl;
    break;
  }
  
  
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    int n, d;
    cin >> n >> d;
    if(n%(2*d+1) == 0) cout << n/(2*d+1) << endl;
    else cout << n/(2*d+1)+1 << endl;
}

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

using namespace std;

using Weight=long long;

struct Edge{
    int src,dst;
    Weight weight;
    Edge(int src,int dst,Weight weight):
    src(src),dst(dst),weight(weight){}
};

auto operator < (const Edge &e,const Edge &f){
    if(e.weight!=f.weight)return e.weight>f.weight;
    else if(e.src!=f.src)return e.src<f.src;
    else return e.dst<f.dst;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;

template<typename T>
class UnionFind{
public:
    vector<T>data;
    UnionFind(T n):data(n,-1){}
    bool unite(T x,T y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    T root(T x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    bool same(T x,T y){
        return root(x)==root(y);
    }
    T size(T x){
        return -data[root(x)];
    }
};

pair<Weight,Edges>kruskal(const Graph &g){
    int n=g.size();
    UnionFind<int> uf(n);
    priority_queue<Edge>q;
    for(int i=0;i<n;++i){
        for(auto e:g[i]){
            if(i<e.dst)q.push(e);
        }
    }
    Weight total=0;
    Edges forest;
    while(forest.size()<n-1 && !q.empty()){
        Edge e=q.top();q.pop();
        if(uf.unite(e.src,e.dst)){
            forest.push_back(e);
            total+=e.weight;
        }
    }
    return {total,forest};
}

int main(){
    int v,e;cin>>v>>e;
    Graph g(v);
    for(int i=0;i<e;++i){
        int s,t,w;cin>>s>>t>>w;
        g[s].emplace_back(s,t,w);
        g[t].emplace_back(t,s,w);
    }
    cout<<kruskal(g).first<<endl;
    return 0;
}
// be checked by AOJ(GRL-2-A).

Measured memory_bytes: 10352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder03a
{
    class Program
    {
        static void Main(string[] args)
        {

            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            int e = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());
            if ((b - a) <= k && (c - a) <= k && (d - a) <= k && (e - a) <= k && (c - b) <= k && (d - b) <= k && (e - b) <= k && (d - c) <= k && (e - c) <= k && (e - d) <= k && a >= 0 && k >= 0 && e <= 123 && k <= 123 && a < b && b < c && c < d && d < e)
                {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>

int64_t solve(int64_t a, int64_t b) {
  if (a == 1 || b == 1) return 1;
  return b / 2 * a + b % 2 * ((a + 1) / 2);
}

int main() {
  int a, b;
  std::cin >> a >> b;
  std::cout << solve(a, b) << std::endl;
  return 0;
}


Measured memory_bytes: 256
/*s1190073  Rina Sato
  File name: prog8a.c
  This is a binary search tree program.
*/

#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;

Node treeSearch(Node u,int k){
  while((u != NIL) && (k != u->key)){
    if(k < u->key){
      u = u->left;
    }
    else {
      u = u->right;
    }
  }
  
  return u;
}

void Insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else {
      x = x->right;
    }
  }
  z->parent = y;
  
  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else {
    y->right = z;
  }
}

void Inorder(Node u){
  if(u->left != NIL){
    Inorder(u->left);
  }
  printf(" %d",u->key);
  
  if(u->right != NIL){
    Inorder(u->right);
  }
}

void Preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL){
    Preorder(u->left);
  }
  if(u->right != NIL){
    Preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  Node t;
  
  scanf("%d", &n);
  
  root = malloc(sizeof(struct node));
  root = NIL;
  
  for (i = 0 ; i < n ; i++){
    scanf("%s", com);
    
    if (com[0] == 'f'){ /*if I find 'x',print yes.else print no.*/
      scanf("%d", &x);
      t = treeSearch(root, x);
      if (t != NIL) printf("yes\n");
      else printf("no\n");
    } 
    else if (com[0] == 'i'){
      scanf("%d", &x);
      Insert(x);
    } 
    else if (com[0] == 'p'){ /*print inorder tree walk and preorder tree walk*/
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    } 
  }
  
  return 0;
}

Measured memory_bytes: 9840
N = int(input())
LL = [int(n) for n in input().split(" ")]


#N = 10
#LL = [9,4,6,1,9,6,10,6,6,8]
OO = [n for n in range(N)]

import copy
import itertools

def makeCombination(candidate, n, lessFlag):
    if len(candidate) <= 0:
        return [[]]
    _candidate = [n for n in candidate]
    _candidate = sorted(_candidate)
    result = []
    if lessFlag is False:
        tmp = list(set(list(itertools.combinations(_candidate, n))))
        for t in tmp:
            result.append(list(t))
    else:
        for i in range(n):
            result += makeCombination(candidate, i + 1, False)
        result += [[]]
    return result

def triangle(ll):
    lll = copy.deepcopy(ll)

    maxlen = max(lll)

    lll.remove(maxlen)

    if lll[0] + lll[1] > maxlen:
        return True
    return False

ok = 0
candidates = makeCombination(OO, 3, False)
for cand in candidates:
    a = LL[cand[0]]
    b = LL[cand[1]]
    c = LL[cand[2]]
    if a != b and b != c and a != c:
        if triangle([a, b, c]):
            ok += 1
print(ok)


Measured memory_bytes: 37688
def c_attention(N, S):
    count_lookme = S.count('W')
    if S[0] == 'W':
        count_lookme -= 1
    ans = N - count_lookme - 1
    for k in range(1, N):
        if S[k] == 'W':
            count_lookme -= 1
        if S[k - 1] == 'E':
            count_lookme += 1
        ans = min(ans, N - count_lookme - 1)
    return ans

N = int(input())
S = input().strip()
print(c_attention(N, S))

Measured memory_bytes: 3700
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define mo 1000000007
#define maxn 1000000000000000000LL
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,a,b,i,j,p[5005],f[5005][5005],g[5005][5005];
long long minn(long long u,long long v){
	return u<v?u:v;
}
int main(){
	//freopen("buinss.in","r",stdin);
	//freopen("buinss.out","w",stdout);
	n=read();a=read();b=read();
	for(i=1;i<=n;i++)
		p[read()]=i;
	for(i=1;i<=n;i++)
		for(j=0;j<=n;j++){
			if(p[i]==j)
				f[i][j]=g[i-1][j];
			if(p[i]<j)
				f[i][j]=g[i-1][j]+a;
			if(p[i]>j)
				f[i][j]=g[i-1][j]+b;
			if(j==0)
				g[i][j]=f[i][j];
			else
				g[i][j]=minn(g[i][j-1],f[i][j]);
		}
	pus(g[n][n],2);
	return 0;
}

Measured memory_bytes: 391552
#include <bits/stdc++.h>
using namespace std;
int p = 1000000007;
vector<long long> modfact;
long long modpow(long long a, long long b){
  //returns a^b mod p
  long long res = 1;
  while (b > 0){
    if (b % 2 == 1) res = res * a % p;
    a = a * a % p;
    b >>= 1;
  }
  return res;
}
long long modinv(long long a){
  //returns the inverse of a
  return modpow(a, p - 2);
}
long long modlast(long long n){
  //returns last coefficient
  //a[n]=(n-1)a[n-1]+(n-2)! (n>=3)
  long long res = 1;
  for (int i = 3; i <= n; i++){
    //res = a[i-1]
    res = ((i - 1) * res % p + modfact[i - 2])% p;
    //res = a[i]
  }
  return res;
}
int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  for (int i = 0; i < N; i++){
    cin >> x[i];
  }
  //modfact計算
  long long v = 1;
  for (int i = 1; i <= N; i++){
    modfact.push_back(v);
    v = (v * i) % p;
  }
  long long res = 0;
  long long coef = modfact[N - 1];
  for (int i = 0; i < N - 1; i++){
    res = (res + x[i] * coef) % p;
    coef = coef * (i + 1) % p;
    coef = coef * modinv(i + 2) % p;
  }
  res = p - res;
  res += x[N - 1] * modlast(N) % p;
  cout << res % p << endl;
}

Measured memory_bytes: 1784
#include <stdio.h>

int main(void) {
	// your code goes here
	int a;
	int b;
	scanf("%d%d",&a,&b);
	if((a+b)>=(a-b)&&(a+b)>=(a*b)){
		printf("%d",a+b);
		
	}else if((a-b)>=(a+b)&&(a-b)>=(a*b)){
		printf("%d",a-b);
	}else if((a*b)>=(a+b)&&(a*b)>=(a-b)){
		printf("%d",a*b);
	}
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
n,k = map(int, input().split())
a = list(map(int, input().split()))

def gcd(a,b):
    if a<b:
        a,b = b,a
    while b>0:
        a,b = b,a%b
    return a

g = a[0]
for i in range(1,n):
    g = gcd(g,a[i])

if max(a)>=k and k%g==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 14252
#include <map>
#include <iostream>
#include <vector>
using namespace std;
map<string,int> item;
map<string,vector<string> > rec;

int saiki(string str){
	int ret = 0;
	if(rec[str].size()){
		for(int i=0;i<rec[str].size();i++){
			ret += saiki(rec[str][i]);
		}
	}else{
		ret=item[str];
	}
	if(item[str]&&item[str]<ret)ret=item[str];
	return ret;
}

int main(){
	int n,m,t;
	string s,rs;
	while(cin >> n && n){
		item.clear();
		rec.clear();
		for(int i=0;i<n;i++){
			cin >>	s;
			cin >> item[s];
		}
		cin >> m;
		for(int i=0;i<m;i++){
			cin >> rs >> t;
			for(int j=0;j<t;j++){
				cin >> s;
				rec[rs].push_back(s);
			}
		}
		cin >> s;
		cout << saiki(s) << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(ll i=0;i<(n);i++)
int main() {
	ll n, a[200020], b[200020];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a, a + n);
	ll mia = a[n / 2 - 1], mib = a[n / 2];
	for (int i = 0; i < n; i++) {
		if (b[i] <= mia)cout << mib << endl;
		else cout << mia << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
int n, i, p, dist, ans = INT_MAX;
cin >> n;
int x[n];
for(i=0; i<n; i++) cin >> x[i];
for(p=1; p<=100; p++){
    dist = 0;
    for(i=0; i<n; i++){
        dist += (p-x[i])*(p-x[i]);
    }
    ans = min(ans, dist);
}
cout << ans;
}


Measured memory_bytes: 3644
#include<stdio.h>

int main(void)
{
	unsigned long int a, b, c;
	

	scanf("%ld", &a);

	if (a % 1000 != 0) {
		printf("%ld", 1000 - (a % 1000));
	}

	else {
		printf("%ld", 0);
	}

	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i=1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

void solve(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> mp(2020202);
    REP(i,N){
        cin >> A[i];
        mp[A[i]]++;
    }
    int ans = 0;
    REP(k,N){
        mp[A[k]]--;
        bool ok = true;
        for(ll i=1; i*i <= A[k]; i++){
            if(A[k] % i == 0){
                if(mp[i] > 0){
                    ok = false;
                }
                if(i != A[i] / i) if(mp[A[k]/i] > 0){
                    ok = false;
                }
            }
            if(!ok) break;
        }
        if(ok){
            // cout << k << endl;
            ans++;
        }
        mp[A[k]]++;
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 11904
<?php
  	fscanf(STDIN,"%d",$n);
	$h_li = explode(" ",trim(fgets(STDIN)));
	
	$max=$h_li[0];
	foreach($h_li as $h){
      
      if($h-1>=$max){
        $masu = $h-1;
      }else{
        $masu = $h;
      }
      if($masu<$max){
        echo "No\n";
        exit;
      }
      $max=$masu;
    }

echo "Yes\n";

	


Measured memory_bytes: 14840
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
//        int K = Integer.parseInt(sc.nextLine());
        int K = sc.nextInt();
        String S = sc.next();

//        System.out.println("aaa\n");
        if (S.length() <= K){
            System.out.println(S);
        } else {
            System.out.println(S.substring(0,K)+"...");
        }

    }
}


Measured memory_bytes: 38484
#include <iostream>
#include <algorithm>
#include <vector>
constexpr int N = 20;
int n, k;
int dp[1 << (N + 1)][N + 1], to[1 << (N + 1)][2];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n >> k;
    for (int len = 0; len <= n; ++len) {
        for (int s = 0; s < (1 << len); ++s) {
            int t = s | 1 << len;
            int i = len - 1;
            while (i >= 0 && (s >> i & 1))
                --i;
            to[t][0] = i;
            i = len - 1;
            while (i >= 0 && (~s >> i & 1))
                --i;
            to[t][1] = i;
        }
    }
    for (int len = 0; len <= n; ++len) {
        for (int s = 0; s < (1 << len); ++s) {
            char c;
            std::cin >> c;
            if (c == '1')
                dp[s | 1 << len][0] = 1;
        }
    }
    for (int len = n; len >= 0; --len) {
        for (int s = 0; s < (1 << len); ++s) {
            for (int p = 0; p < len; ++p) {
                int t = len - p;
                int suf = s & ((1 << t) - 1) | 1 << t, pre = s >> t | 1 << p;
                if (to[suf][0] != -1)
                    dp[pre << (to[suf][0] + 1) | s & ((1 << to[suf][0]) - 1)][p + 1] += dp[s | 1 << len][p];
                if (to[suf][1] != -1)
                    dp[(pre << 1 | 1) << to[suf][1] | s & ((1 << to[suf][1]) - 1)][p + 1] += dp[s | 1 << len][p];
                dp[pre][p] += dp[s | 1 << len][p];
            }
        }
    }
    for (int len = n; len >= 0; --len) {
        for (int s = 0; s < (1 << len); ++s) {
            if (dp[s | 1 << len][len] >= k) {
                for (int i = len - 1; i >= 0; --i)
                    std::cout << (s >> i & 1);
                std::cout << "\n";
                return 0;
            }
        }
    }
}

Measured memory_bytes: 188800
N = STDIN.gets.chomp.to_i
d = STDIN.gets.chomp.split(" ").map(&:to_i)

d.sort!

center = (d.size - 1) / 2

if N % 2 == 1 then
  puts 0
elsif d[center] == d[center+1]
  puts 0
else
  puts d[center+1] - d[center]
end

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> s=a;
  sort(s.rbegin(), s.rend());
  rep(i,n){
    int ans = s[0];
    if (s[0] == a[i]) ans = s[1];
    cout << ans << endl;
  }
  return 0;
}


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

int main() {
    long long N;
    cin >> N;
    vector <long long> H(N);
    for (long long i=0; i<N; i++) cin >> H.at(i);
    long long m = H.at(N-1);
    for (long long i=N-1; i>=0; i--) {
        if (H.at(i)-1 > m) {
            cout << "No\n";
            return 0;
        }
        m = min(m, H.at(i));
    }
    cout << "Yes\n";
}

Measured memory_bytes: 4032
#include <cstdio>
#include <algorithm>
using namespace std;
#define LL long long
#define MAX_SIZE 1010
int n, m;
LL r, a;
LL x[MAX_SIZE], y[MAX_SIZE], z[MAX_SIZE], t[MAX_SIZE];

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);

	int P[8][3] = { { 1,1,1 },{ 1,1,-1 },{ 1,-1,1 },{ 1,-1,-1 },{ -1,1,1 },{ -1,1,-1 },{ -1,-1,1 },{ -1,-1,-1 } };
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < n; ++j)
			t[j] = x[j] * P[i][0] + y[j] * P[i][1] + z[j] * P[i][2];
		sort(t, t + n);
		a = 0;
		for (int k = n - m; k < n; ++k)
			a += t[k];
		if (r < a)
			r = a;
	}
	printf("%lld\n", r);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pshb(a) cin >> x;a.push_back(x)
#define fr(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false);
using namespace std;
int main()
{
    ll n ,a ;
    cin>>n>>a ;
    ll  cnt =0 ;
    for (int i =0 ; i<a ; i++)
    {
        ll x ; cin>>x ;
        cnt+=x ;
    }
    if (cnt>=n)
        cout<<"Yes" ;
    else
        cout<<"No" ;
}




Measured memory_bytes: 256
#include<stdio.h>
int count[26];
int main(){
    char ch;
    while(scanf("%c",&ch) != EOF){
        if(ch >= 'a' && ch <= 'z'){
            int num = ch - 'a';
            count[num]++;
        }else if(ch >= 'A' && ch <= 'Z'){
            int num = ch - 'A';
            count[num]++;
        }
    }
    for(int i=0;i<26;i++){
        printf("%c : %d\n",97+i,count[i]);
    }
}


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


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;


lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	string str;
	cin >> str;

	lli a = 0, b = 0;

	for (int i = 0; i < str.size(); i++) {
		if (str[i] - '0' == i % 2) {
			a++;
		}
		else {
			b++;
		}
	}

	COUT(min(a,b));

	return 0;
}

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



void solve() {
  long long int n, t;
  cin >> n >> t;
  long long int a, b;
  long long int total = 0;
  cin >> b;
  for (int i = 1; i < n; i++) {
    cin >> a;

    total += min(t, (a - b));
    b = a;
  }
  cout << total + t;
}


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


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

int main()
{
  int N; cin >> N;
  vector<int> d(N);
  rep(i,N) cin >> d[i];
  
  set<int> kagami;
  rep(i,N)
  {
    kagami.insert(d[i]);
  }
  cout << kagami.size() << endl;
}

Measured memory_bytes: 256
#abc112 b
n,T=map(int,input().split())
c=[]
t=[]
ans=10001
for i in range(n):
    a,b=map(int,input().split())
    c.append(a)
    t.append(b)
for i in range(n):
    if t[i]>T:
        continue
    ans=min(ans,c[i])
if ans==10001:
    print("TLE")
else:
    print(ans)


Measured memory_bytes: 3060
n = int(input())
*a, = map(int, input().split())
ans = [0] * n
for i in range(n-1, -1, -1):
    if not sum(ans[i::i+1]) % 2 == a[i]:
        ans[i] = 1
print(sum(ans))
print(*[i+1 for i in range(n) if ans[i] == 1])


Measured memory_bytes: 77916
MAX = 1000001
primes = list()
for i in range(MAX):
    primes.append(True)
primes[0] = False
primes[1] = False

for i in range(2, MAX):
    j = i + i
    while j < MAX:
        primes[j] = False
        j = j + i

while True:
    n = int(input())
    if n == 0:
        break

    ans = 0
    for i in range(1, n // 2 + 1):
        if primes[i] and primes[n-i]:
            ans += 1
    print(ans)


Measured memory_bytes: 13500
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  long long a,b,v,w,t;
  cin>>a>>v>>b>>w>>t;
  if(b>a){
  if(a+v*t<b+w*t){
    cout<<"NO"<<endl;
  }else{
    cout<<"YES"<<endl;
  }
  }else{
     if(b-w*t<a-v*t){
      cout<<"NO"<<endl;
     }else{
      cout<<"YES"<<endl;
     }
  }
 
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    vector<string> S(H);
    vector<vector<int>> cho(H,vector<int>(W+1));
    rep(i,H){
        cin >> S[i];
        rep(j,W){
            cho[i][j+1]=cho[i][j]+(S[i][j]-'0');
        }
    }
    int ans = H*W;
    for(int bit=0;bit<(1<<(H));bit++){
        vector<int> B(H-1);
        int tmp=0;
        int cut = 0;
        for(int i=0;i<H-1;i++){
            if(bit&(1<<i)){
                B[i]=1;
                cut++;
            }
        }
        tmp+=cut;
        int l=0;
        bool flg=false;
        int cnt=0;
        for(int w=0;w<W;w++){
            for(int h=0;h<H;h++){
                cnt += cho[h][w+1]-cho[h][l]; 
                if(cnt>K){
                    l=w;
                    tmp++;
                    if(w==W-1&&l==w-1){
                        tmp+=100000;
                    }
                    cnt=0;
                    continue;
                }
                if(B[h]==1){
                    cnt=0;
                }
            }
            cnt=0;
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
    a: usize,
    b: usize,
    c: usize,
    );
    let ans = if (a == b && b == c && a == c) || (a != b && b!=c && a != c) {"No"} else { "Yes" };
    print!("{}", ans);
}


Measured memory_bytes: 4352
def solve():
    i = X
    while not prime(i):
        i += 1
#        print(i)
    print(i)

def prime(x):
    for i in range(2, int(x**0.5)+1):
        if (x % i == 0):
            return False
    return True


if __name__=="__main__":
    X = int(input())

    solve()

Measured memory_bytes: 3064
//Trial code here
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
bool f=0;
int c[N],cnt[3];
vector<int>G[N];
void dfs(int x,int ff=1)
{
    if(c[x])
    {
        f|=ff!=c[x];
        return;
    }
    c[x]=ff;
    cnt[ff]++;
    for(int u:G[x])
    dfs(u,3-ff);
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0; i<m; ++i)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1);
    printf("%lld\n",f?1LL*n*(n-1)/2-m:1LL*cnt[1]*cnt[2]-m);
    return 0;
}

Measured memory_bytes: 6528
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for i in range(N):
  if A[i] != B[i] and B[i] != C[i] and C[i] != A[i]:
    ans += 2
  elif A[i] == B[i] != C[i] or A[i] != B[i] == C[i] or C[i] == A[i] != B[i]:
    ans += 1
  else:
    ans += 0
print(ans)

Measured memory_bytes: 3064
n, *t = map( int, open( 0 ).read().split() )
 
# manemane
A, B, C = 0, 0, 0
for i in  range( n ):
  A, B, C = t[ 3 * i  ] + max( B, C ), t[ 3 * i + 1 ] + max( A, C ), t[ 3 * i + 2 ] + max( A, B )
 
print( max( A, B, C ) )


Measured memory_bytes: 35636
using System;

namespace AtcoderProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);

            Console.WriteLine(a-b+1);

        }
    }

}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	unsigned long n,c5;

	while(1){
		cin>>n; if(n==0) return 0;
		c5=0;
		for(unsigned long i=1;i<=n;i++){
			unsigned long j=i;

			while(j%5==0){c5++;j/=5;}
		}
		cout<<c5<<endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>
int main(void)
{
	int i,n[100],j,min=100000000000,max=1;
	scanf("%d", &i);
	for (j = 0; j < i; j++)
	{
		scanf("%d", &n[j]);
		if (min > n[j])
			min = n[j];
		if (max < n[j])
			max = n[j];
	}
	printf("%d\n",max-min);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main()
{
    fast_cin;
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    int N=0;
    cin>>N;
    vector<int> h(N);
    vector<int> dp(N,INT_MAX);
    for(ll i=0;i<N;i++){
        cin>>h[i];
    }

    dp[0]=0;
    
    for(int i=0;i<N;i++){
        for(int j:{i+1,i+2}){
            if(j<N){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }


    cout<<dp[N-1]<<"\n";

    return 0;
}

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

int main()
{
	long long int n,temp,sum=0;
	cin>>n;
	temp=n;
	while(temp)
	{
		temp=temp/2;
		sum++;
	}
	cout<<((long long int)pow(2,sum)-1);
	
	
	return 0;
}

Measured memory_bytes: 256