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

INF = float('inf')

dr = (-1, 0, 0, 1)
dc = (0, -1, 1, 0)

H, W = map(int, input().split())

s = []
total_white_count = 0
for _ in range(H):
    t = input()
    s.append(t)
    total_white_count += t.count('.')
p = [[INF for _ in range(W)] for _ in range(H)]

ans = -1

dq = deque()
dq.append((0, 0, 1))
while dq:
    r, c, d = dq.popleft() # 直した

    nd = d + 1
    for i in range(4):
        nr = r + dr[i]
        nc = c + dc[i]
        if not (0 <= nr < H and 0 <= nc < W): continue
        if s[nr][nc] == '#' : continue
        if p[nr][nc] <= nd: continue
        p[nr][nc] = nd
        if nr == H - 1 and nc == W - 1:
            ans = total_white_count - nd
            break
        dq.append((nr, nc, nd))
    else:
        continue
    break

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int X, Y;
    cin >> X >> Y;
    
    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            if(i + j == X && i * 4 + j * 2 == Y){
                cout << "Yes" << endl;
                return 0;
        
            }    
        }
    }
    cout << "No" << endl;
}


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

#define MAX_VERTEX 100
#define INF 1000000

int cost[MAX_VERTEX][MAX_VERTEX];
int d[MAX_VERTEX];
bool used[MAX_VERTEX];

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

  for(int i = 0; i < vertex_num; i++) {
    d[i] = INF;
    used[i] = false;
    for(int j = 0; j < vertex_num; j++) {
      cost[i][j] = INF;
    }
  }

  for (int i = 0; i < vertex_num; i++) {
    int vertex, out;
    cin >> vertex >> out;
    for(int j = 0; j < out; j++) {
      int to, c;
      cin >> to >> c;
      cost[vertex][to] = c;
    }
  }

  d[0] = 0;
  while(true) {
    int vertex = -1;
    for(int u = 0; u < vertex_num; u++) {
      if(!used[u] && (vertex == -1 || d[u] < d[vertex])) {
        vertex = u;
      }
    }

    if (vertex == -1) break;

    used[vertex] = true;

    for(int u = 0; u < vertex_num; u++) {
      d[u] = min(d[u], d[vertex] + cost[vertex][u]);
    }
  }

  for(int i = 0; i < vertex_num; i++) {
    cout << i << " " << d[i] << endl;
  }

  return 0;
}

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

using namespace std;
int serch1(int input_max,int num)
{
  int a = 0;
  int b = 0;
  int max = 0;
  int cnt = 0;
  max = input_max;
  while(1)
  {
    a = num - max;
    for(int i = 1 ; i < a ; i++)
    {
      b = a - i;
      if(b <= i)
      {
        break;
      }
      if(b < max) cnt += 1;
    }
    max--;
    if(max < 3)break;
  }
  return cnt;

}

int main()
{
  int a,b;
  int cnt;
  int min;
  int max;
  while(1)
  {
    cin >> a >> b;
    cnt = 0;
    if(a == 0 && b == 0 )break;
    cout << serch1(a,b) << endl;
  }
  return 0;
}


Measured memory_bytes: 3072
def linearSearch(A, n, key):
    i = 0
    A.append(key)
    while A[i] != key:
        i += 1
        if i == n:
            return False
    return True

def main():
    n = int(input())
    S = input().split(" ")
    _ = int(input())
    T = input().split(" ")

    sum = 0

    for s in T:
        if linearSearch(S, n, s):
            sum += 1
    
    print(sum)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6068
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashMap;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static int n,x,y;
	static List <Integer> [] Edge;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		 n = Integer.parseInt(sc.next());
		 x = Integer.parseInt(sc.next());
		 y = Integer.parseInt(sc.next());
		
		Edge = new ArrayList [n];
		
		for(int i = 0 ;i < n ;i++) {
			Edge[i] = new ArrayList<Integer>();
		}
		Edge[x-1].add(y-1);
		Edge[y-1].add(x-1);
		
		for(int i = 0 ;i < n-1 ; i++) {
			Edge[i].add(i+1);
			Edge[i+1].add(i);
		}
		
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
		
		for(int i = 0 ; i <= n ;i++) {
			map.put(i, 0);
		}
		
		int ans [][] = new int [n][n];
		
		for(int i = 0 ; i < n ; i++) {
			ans[i] = solve(n , i);
			for(int j = 0 ; j < n ; j++) {
				if(ans[i][j] != 0 && ans[i][j] != n) {
					if(i < j) {
					map.put(ans[i][j],1+map.get(ans[i][j]));
					}
				}
			}
		}
		
		for(int num : map.keySet()) {
			if(num == 0 || num == n) {
				continue;
			}
			System.out.println(map.get(num));
		}
		
	}
	
	static int [] solve(int n,int st) {
		PriorityQueue <Pos> que = new PriorityQueue<Pos>();
		int []d = new int [n];
		
		for(int i = 0 ; i < n ;i++) {
			d[i] = n;
		}
		BitSet used = new BitSet(n);
		que.add(new Pos(0,st));
		d[st] = 0;
		

		while(!que.isEmpty()) {
			Pos p = que.poll();		
			int v = p.getTo();
			if(used.get(p.getTo())) {
				continue;
			}
			used.set(p.getTo());
			for(int num: Edge[v]) {
				if(d[num] > d[v] + 1 ) {
					d[num] =  d[v] + 1;
					que.add(new Pos(d[num],num));
				}
			}
		}
		
		return d;
		
		
	}

}


class Pos implements Comparable<Pos>{
	
	private int cost;
	private int to;
	
	public Pos (int cost, int to) {
		this.cost = cost;
		this.to = to;
	}
	
	public int getCost() {
		return cost;
	}

	public int getTo() {
		return to;
	}

	public void setCost(int cost) {
		this.cost = cost;
	}

	public void setTo(int to) {
		this.to = to;
	}

	@Override
	public int compareTo(Pos o) {
		return Integer.compare(cost, o.cost);
	}
	
}

Measured memory_bytes: 126552
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
  int cnt = 0;
rep(i,6){
  char x;
  cin >> x;
  if(x=='1')cnt++;
}
cout << cnt << endl;
}


Measured memory_bytes: 3584
#include<iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int A1,A2,A3,A_min,A_max;

    cin>>A1>>A2>>A3;
    A_max=max(max(A1,A2),A3);
    A_min=min(min(A1,A2),A3);
    cout<<A_max-A_min<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

int main(void){
	int x,t;
	cin >> x >> t;
	cout << (max(0,x-t)) << endl;
	return 0;
}

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

using namespace std;



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

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

	cout<<(n*(n-1))/2+(m*(m-1))/2<<'\n';



	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int n, d;

   scanf("%d%d",&n,&d);

   if(n%(d*2+1)==0)
      printf("%d\n",n/(d*2+1));
   else
      printf("%d\n",n/(d*2+1)+1);
   return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
	public static int solve(int y, int m, int d){
		int x = 1000-y;
		int day = x*195;
		if( x%3 == 0 ){
			day += (x/3)*5;
		} else {
			day += (x/3 + 1)*5;
		}
		if( y%3 == 0 ){
			day -= (m-1)*20+d-1;
		} else {
			day -= ((m-1)/2)*39+((m-1)%2)*20+d-1;
		}
		return day;
	}
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i = 0; i < n; i++){
			int y = stdIn.nextInt();
			int m = stdIn.nextInt();
			int d = stdIn.nextInt();
			System.out.println(solve(y, m, d));
		}
	}
}

Measured memory_bytes: 12000
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	string S; int N;

	vector<int> P; int R;

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		P = vector<int>(N, 0); R = 0;

		cin >> S;

		for (int i = 0; i < S.size(); i++)
		{
			int turn = i % N;

			if (S[i] == 'M')
			{
				P[turn] += 1;
			}
			else if (S[i] == 'S')
			{
				R += P[turn] + 1; P[turn] = 0;
			}
			else
			{
				P[turn] += R + 1; R = 0;
			}
		}

		sort(P.begin(), P.end());

		for (int i = 0; i < N; i++)
		{
			cout << P[i] << ' ';
		}

		cout << R << endl;
	}

	return 0;
}

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

int main(){
    int N, H[100], ans = 0;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    for(int i = 1; i < N; i++){
        bool  isView = true;
        for(int j = 0; j < i; j++){
            if(H[j] > H[i]){
                isView = false;
                break;
            }
        }
        if(isView){
            ans++;
        }
    }
    cout << ans+1 << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
c.append(0)
for i in range(n-1):
  if a[i]!=a[i+1]-1:
    c[a[i]-1]=0
c[a[n-1]-1]=0
print(sum(b)+sum(c))

Measured memory_bytes: 3064
from functools import lru_cache
import math
def main():
    n=int(input())
    a=list(map(int,input().split()))
    pair,setwise=True,True
    x,y=set(),a[0]
    for i in a:
        if pair:
            ap=set(prime_factorize(i))
            if len(x & ap) > 0:
                pair=False
            x |= ap
        y=math.gcd(y, i)
    if pair:
        print("pairwise coprime")
    elif y == 1:
        print("setwise coprime")
    else:
        print("not coprime")

def prime_factorize(n: int) -> list:
    '''引数nの素因数分解結果のlistを返す。'''
    arr = []
    # 2で割り続け奇数まで還元する
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    # sqrt(n)までの素数で試し割
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

@lru_cache(maxsize=None)
def primes(n:int) -> list:
    '''n以下の全素数をlistで返す'''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

@lru_cache(maxsize=None)
def is_prime(n: int) -> bool:
    '''引数nが素数であればTrue、そうでなければFalseを返す'''
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True

if __name__ == "__main__":
    main()

Measured memory_bytes: 127852
#include<iostream>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
bool dp1[17000][4001];
bool ch1[17000][4001];
bool dp2[17000][4001];
bool ch2[17000][4001];
vector<int> vt;
int n, m;
bool func1(int ch, int x)
{
	if (x*2 >= vt.size())
	{
		if (ch == n) {
			return 1;
		}
		else
			return 0;
	}
	bool &ret = dp1[ch][x];
	if (ch1[ch][x])return ret;
	ch1[ch][x] = 1;
	ret = max(ret, func1(ch + vt[x*2], x + 1));
	if(x)
	ret = max(ret, func1(ch - vt[x*2], x + 1));
	return ret;
}
bool func2(int ch, int x)
{
	if (x*2+1 >= vt.size())
	{
		if (ch == m)
			return 1;
		else
			return 0;
	}
	bool &ret = dp2[ch][x];
	if (ch2[ch][x])return ret;
	ch2[ch][x] = 1;
	ret = max(ret, func2(ch + vt[x*2+1], x + 1));
	ret = max(ret, func2(ch - vt[x*2+1], x + 1));
	return ret;
}
int main()
{
	string a;
	cin >> a;
	int t = a.size();
	int cnt = 0;
	for (int i = 0; i < t; i++)
	{
		if (a[i] == 'F')
			cnt++;
		else
		{
			vt.push_back(cnt);
			cnt = 0;
		}
	}
	vt.push_back(cnt);
	scanf("%d %d", &n, &m);
	n += 8000; m += 8000;
	if (func1(8000, 0) && func2(8000, 0))
		puts("Yes");
	else
		puts("No");
}

Measured memory_bytes: 127232
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// Date d1 = new Date();
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		
		Queue<Long> que = new ArrayDeque<>();
		
		for (long i = 1; i <= 9; i++) {
			que.add(i);
		}
		
		int cnt = 1;
		long num = -1;
		while (!que.isEmpty()) {
			num = que.poll();
			// System.out.printf("cnt=%d, num=%d\n", cnt, num);
			if (cnt++ == k) {
				break;
			}
			
			for (long nn = num % 10 - 1; nn <= num % 10 + 1; nn++) {
				// System.out.printf("  nn=%d\n", nn);
				if (nn < 0 || 9 < nn) {
					continue;
				}
				que.add(num * 10 + nn);
			}
		}
		
		System.out.println(num);
		// Date d2 = new Date();
		// System.out.println(d2.getTime() - d1.getTime());
	}
}


Measured memory_bytes: 30416
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int n,m;
bool maze[22][22];
bool visited[22][22];
int dist[22][22];
int dy[4] = {0,0,1,-1};
int dx[4] = {1,-1,0,0};

vector<pi> road;
int desty,destx;

int bfs(int curr_y,int curr_x){
	
	memset(visited,0,sizeof(visited));
	memset(dist,0,sizeof(dist));
	queue<pi>q;
	q.push(pi(curr_y,curr_x));
	visited[curr_y][curr_x]=true;
	while(!q.empty()){
		curr_y = q.front().first;
		curr_x = q.front().second;
		q.pop();
		for(int i=0; i<4; i++){
			int yy = curr_y+dy[i];
			int xx = curr_x+dx[i];
			if(yy<1 || xx<1 || yy>n || xx>m || !maze[yy][xx]) continue;
			if(visited[yy][xx]) continue;
			visited[yy][xx] = true;
			dist[yy][xx] = dist[curr_y][curr_x]+1;
			q.push(pi(yy,xx));
		}
	}	
	return dist[desty][destx];
}
int main(){
	cin>>n>>m;
	for(int i=1; i<=n; i++){
		string s;
		cin>>s;
		for(int j=0; s[j]; j++){
			if(s[j]=='.'){
				maze[i][j+1]=true;
				road.push_back(pi(i,j+1));
			}
		}
	}
	int maxdist = 0;
	for(int i=0; i<road.size(); i++){
		for(int j=i+1; j<road.size(); j++){
			desty = road[j].first;
			destx = road[j].second;
			maxdist = max(maxdist,bfs(road[i].first,road[i].second));
		}
	}
	cout<<maxdist;
}

Measured memory_bytes: 3556
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    int n,d;
    int i,j,k;
    int tmp, tmp2;
    double dis;
    int count = 0;
    vector<vector<int>> x;
    cin >> n >> d;
    x.assign(n,vector<int>(d));
    for(i=0;i<n;i++) for(j=0;j<d;j++){
        cin >> x[i][j];
    }
    for(i=0;i<n-1;i++) for(j=i+1;j<n;j++){
        tmp2 = 0.;
        for(k=0;k<d;k++){
            tmp2 += (tmp = x[i][k] - x[j][k]) *tmp; 
        }
        dis = sqrt(tmp2);
        if(ceil(dis) == (int)dis) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 888
#include <stdio.h>

int
main()
{
	for (;;) {
		int w, h;
		scanf("%d %d", &h, &w);

		if (w == 0 && h == 0)
			break;

		int x, y;
		for (y = 0; y < h; y++)
		{
			for (x = 0; x < w; x++)
			{
				putchar('#');
			}
			putchar('\n');
		}
		putchar('\n');
	}

	return 0;
}

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

bool order(pair<pair<string,int>,int >pre,pair<pair<string,int>,int >post){
    if(pre.first.first > post.first.first){
        return true;
    }
    else if(pre.first.first==post.first.first){
        if(pre.first.second<post.first.second){
            return true;
        }
    }
    return false;
}

int main(){
    int N;
    cin>>N;
    pair<pair<string,int>,int > vp[N];
    for(int i=0;i<N;i++){
        cin>>vp[i].first.first>>vp[i].first.second;
        vp[i].second=i+1;
    }
    sort(vp,vp+N,order);
    for(int i=N-1;i>=0;i--){
        cout<<vp[i].second<<endl;
    }
}


Measured memory_bytes: 256
N  = int(input())
A = sorted([int(a) for a in input().split()], reverse=True)
cnt = N
if N == 2:
    ans = A[0]
else:
    ans = A[0]
    cnt = N - 2
    A = A[1:]
    chk = 0
    for a in A:
        if cnt == 0:
            break
        elif cnt == 1:
            ans += a
            break
        ans += 2*a
        cnt -= 2
print(ans)


Measured memory_bytes: 31496
fun main(args: Array<String>) {
    val s = readLine()!!.split(' ')
    val n = s[0].toInt()
    val mw = s[1].toLong()

    val dp = Array(100001) { 1000000001L }
    dp[0] = 0L

    for (i in 0 until n) {

        val (s1, s2) = readLine()!!.split(' ')
        val w = s1.toLong()
        val v = s2.toInt()

        for (tv in 100000 downTo 0) {
            if (tv - v >= 0) {
                dp[tv] = Math.min(dp[tv], dp[tv - v] + w)
            }
        }
    }

    var res = 0

    dp.forEachIndexed { v, w ->
        if (w <= mw) {
            res = v
        }
    }

    println(res)
}


Measured memory_bytes: 123416
#include <iostream>
#include <algorithm>
#include <cmath>

int main()
{
    int a, b, c, k;
    std::cin >> a >> b >> c >> k;
    std::cout << a + b + c + (std::pow(2, k) - 1) * std::max(a, std::max(b, c)) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
#define MOD 1000000007
#define EPS 10e-8

ll p[3];  //kazu
ll g[3];  //p[i]no kazu

int main(){
    ll n;
    ll c=0;
    cin >> n;
    ll a[100007];

    rep(i,n){
        cin >> a[i];
    }
    c=a[0];
    rep(i,n-1){
        c=(c^a[i+1]);
    }

    if(c==0){
        cout << "Yes" << endl;
    }
    else{
        cout <<  "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

using ll = long long;
using pii = pair<int,int>;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;


int N;
ll a[222];
ll z[66];
string s;

inline int get(ll a, int j) {
  return (a>>j)&1;
}

bool add(ll n) {
  for (int i=0;i<60;i++) {
    if (!get(n,i)) continue;
    if (!get(z[i], i)) {
      z[i] = n;
      return 1;
    }
    n ^= z[i];
  }
  return 0;
}


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

  bitset<200> bs;

  int T;cin>>T;
  while (T --> 0) {
    cin>>N;
    for (int i=0;i<N;i++) cin>>a[i];
    cin>>s;
    memset(z,0,sizeof z);

    int winner = 0;
    for (int i=N-1;i>=0;i--) {
      if (add(a[i]) && s[i]=='1') {
        winner = 1;
        break;
      }
    }
    cout << winner << '\n';
  }

  return 0;
}


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

// 頂点数、変数
int v, e;
const int MAX_N = 100100;
// 隣接リスト
vector<int> g[MAX_N];
bool used[MAX_N];
// トポロジカルソートされた数列
vector<int> ans;

void dfs(int u) {
    if(used[u]) return;
    used[u] = true;
    for(auto& i: g[u]) dfs(i);
    // 帰りがけ順で追加
    ans.push_back(u);
}

void tsort() {
    for(int i=0; i<v; ++i) dfs(i);
    reverse(ans.begin(), ans.end());
}


int main() {
    ll N, M;
    cin >> N >> M;
    v = N, e = M;
    vector<vector<ll>> connect(N);
    vector<bool> in(N, false);
    vector<ll> out(N, 0);
    for (ll i = 0; i < N - 1 + M; i++) {
        ll A, B;
        cin >> A >> B;
        A--; B--;
        connect[A].push_back(B);
        out[A]++;
        in[B] = true;
        g[A].push_back(B);
    }

    tsort();

    vector<ll> tnum(N, -1);
    for (ll i = 0; i < N; i++) {
        tnum[ans[i]] = i;
    }

    ll root = -1;
    for (ll i = 0; i < N; i++) {
        if (!in[i]) {
            root = i;
            break;
        }
    }

    ll s = root;
    vector<ll> par(N, -1);
    vector<ll> cost(N, 0);
    par[s] = -1;
    priority_queue<pair<ll, pair<ll, ll>>> qu;
    qu.push({ 0, { 0, s }});
    while (!qu.empty()) {
        auto t = qu.top();
        qu.pop();
        if (t.first < cost[t.second.second]) {
            continue;
        }

        for (ll n : connect[t.second.second]) {
            if (t.first + 1 > cost[n]) {
                qu.push( { t.first + 1, {N - tnum[n], n} } );
                par[n] = t.second.second;
                cost[n] = t.first + 1;
            }
        }
    }

    for (ll i = 0; i < N; i++) {
        cout << par[i] + 1 << endl;
    }
}

Measured memory_bytes: 18684
from sys import stdin
import sys

data = []

N = int(stdin.readline().rstrip())
for i in range(0, N):
    data.append(stdin.readline().rstrip().split())

cur_t = 0
cur_x = 0
cur_y = 0

for i in range(0, len(data)):
    (next_t, next_x, next_y) = data[i]
    next_t = int(next_t)
    next_x = int(next_x)
    next_y = int(next_y)

    sub_t = next_t - cur_t
    sub_x = abs(next_x - cur_x)
    sub_y = abs(next_y - cur_y)
    #print(sub_t)
    #print(sub_x)
    #print(sub_y)
    

    ## do something
    # sub_t > sub_x + sub_y
    if sub_t < sub_x + sub_y:
        print('No')
        sys.exit()

    if sub_t % 2 != (sub_x + sub_y)%2:
        print('No')
        sys.exit()



    cur_t = next_t
    cur_x = next_x
    cur_y = next_y

print('Yes')


Measured memory_bytes: 32148
#include <stdio.h>
int a, b, c;
int main()
{
    scanf("%d %d %d", &a, &b, &c);
    if (a == b) printf ("%d\n", c);
    else if (a == c) printf ("%d\n", b);
    else printf("%d\n", a);
    return 0;
}

Measured memory_bytes: 128
mat = readlines.map{|n| n.chomp.split(" ").map(&:to_i)}
n,d = mat.shift

cnt = 0
if d == 1
  puts n*(n-1)/2
else
  mat.combination(2).each do |arr|
    sum = 0
    arr[0].zip(arr[1]).each do |i,j|
      sum+=(i-j)**2
    end
    dist=Math.sqrt(sum)
    if dist.floor == dist
      cnt+=1
    end
  end
  puts(cnt)
end


Measured memory_bytes: 3836
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	res := 1
	for i := 0; i < n; i++ {
		tmp1 := 2 * res
		tmp2 := k + res
		if tmp1 < tmp2 {
			res = tmp1
		} else {
			res = tmp2
		}
	}
	fmt.Println(res)
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int res = 0;
    for(int i = 1;i < n-1;i++){
        if(p[i-1] < p[i] && p[i] < p[i+1]) res++;
        if(p[i-1] > p[i] && p[i] > p[i+1]) res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,a,i,flag=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&a);
    
    if(a%2==0){
      if(a%3!=0 && a%5!=0){
        flag=1;
      }
    }
  }
  
  if(flag==0){
    printf("APPROVED");
  } else {
    printf("DENIED");
  }
}

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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
  ios:: sync_with_stdio(false);
  cin.tie();
  int a, b, t;
  cin >> a >> b >> t;
  cout << b * (t / a);

  return 0;
}




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

using namespace std;

#define int long long

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define VDEL(v, n) v.erase(v.begin() + (n))
#define ALL(v) v.begin(), v.end()
#define INTMAX 2147483647
#define INF 200000000
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int>> VII;

int N;
int node[100][100];

int dijkstra(int from, int to)
{
    bool done[100];
    int cost[100];
    REP(i, N)
        done[i] = false;
    REP(i, N)
        cost[i] = -1;
    cost[from] = 0;
    while(true)
    {
        int donenode = -1;
        int mincost = INF;
        REP(i, N)
        {
            if(done[i] || cost[i] < 0) continue;
            if(cost[i] <= mincost)
            {
                mincost = cost[i];
                donenode = i;
            }
        }
        if(donenode == -1)
        {
            return cost[to];
        }
        done[donenode] = true; 
        REP(i, N)
        {
            if(done[i]) continue;
            if(node[donenode][i] < 0) continue;

            if(
                cost[i] < 0 ||
                cost[donenode] + node[donenode][i] < cost[i]
                )
            {
                cost[i] = cost[donenode] + node[donenode][i];
            }
        }
    }
}

signed main()
{
    while(true)
    {
        int K;
        cin >> N >> K;
        if(N == 0 && K == 0) break;
        REP(i, N)
            REP(h, N)
        {
            if(i == h) node[i][h] = 0;
            else node[i][h] = -1;
        }
        REP(i, K)
        {
            int h = 0;
            cin >> h;
            if(h == 1)
            {
                int c,d,e;
                cin >> c >> d >> e;
                c--;
                d--;
                if(node[c][d] == -1 || node[c][d] > e)
                {
                    node[c][d] = e;
                    node[d][c] = e;
                }
            }
            else
            {
                int a, b;
                cin >> a >> b;
                a--;
                b--;
                cout << dijkstra(a, b) << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3120
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n;
    string s;
    cin >> n >> s;
    reverse(ALL(s));
    ll high_bits = 0;
    REP(i,n)if(s[i]=='1')high_bits++;
    vector<ll>table_plus(n+10),table_minus(n+10);

    if(high_bits==0){
        REP(i,n){
            cout << 1 << endl;
        }
        return 0;
    }

    table_minus[0]=1;table_plus[0]=1;
    ll mod_plus = high_bits+1,mod_minus=high_bits-1;
    REP(i,n+9){
        if(mod_minus!=0)
            table_minus[i+1] = (table_minus[i]*2)%mod_minus;
        table_plus[i+1] = (table_plus[i]*2)%mod_plus;
    }

    ll default_plus = 0,default_minus = 0;

    REP(i,n){
        if(s[i]=='1'){
            if(mod_minus!=0)
                default_minus=(default_minus+table_minus[i])%mod_minus;
            default_plus=(default_plus+table_plus[i])%mod_plus;
        }
    }
    vector<ll>x(n);
    vector<int>answer(n,1);
    REP(i,n){
        if(s[i]=='1'){
            if(mod_minus==0){
                x[i]=0;
                answer[i]=0;
            }
            else{
                x[i]=default_minus-table_minus[i];
                if(x[i]<0)x[i]+=mod_minus;
            }
        }else{
            x[i]=(default_plus+table_plus[i])%mod_plus;
        }
    }
    FORR(i,n-1,0){
        while(x[i]>0){
            ll tmp = __builtin_popcount(x[i]);
            x[i]%=tmp;
            answer[i]++;
        }
        cout << answer[i] << endl;
    }
   /* REP(i,n){
        cerr << table_plus[i] << " ";
    }
    cout << endl;
    cerr<< default_minus << " " << default_plus << endl;
    cerr << s[0] << endl;*/
    return 0;
}

Measured memory_bytes: 9156
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin >> n;

	ll ans = 1;

	map<ll, ll> mp;
	mp[-1]=3;

	REP(i, n) {
		ll a;
		cin >> a;
		mp[a]++;
		ans *= mp[a - 1];
		ans %= MOD;
		mp[a - 1]--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6528
#include <map>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int ll;

int main() {
    int n; cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for (int i = 0; i < n; i++) {
        string tmp; cin >> tmp;
        if (tmp == "AC") {
            ac++;
        } else if(tmp == "WA") {
            wa++;
        } else if (tmp == "TLE") {
            tle++;
        } else if (tmp == "RE") {
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;
}

Measured memory_bytes: 3216
N = int(input())
V = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

V_C = []
for i in range(len(V)):
    V_C.append(V[i] - C[i])

result = 0
for i in range(len(V_C)):
    if V_C[i] > 0:
        result += V_C[i]

print(result)


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

int main() {
  int N, i;
  cin >> N;
  string Si;
  for (i = 1 ; i <= N ; i++) {
    cin >> Si;
    if (Si == "Y") {
      cout << "Four" << endl;
      break;
    }
    if (i == N) {
      cout << "Three" << endl;
    }
  }
}


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

int main()
{
  int A, B;
  cin >> A >> B;
  string ans = "Impossible";
  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
    ans = "Possible";

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

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

const ll MOD = 1e9+7;

void solve(){
  ll n, m; cin >> n >> m;
  vector<bool> damaged(n+1, false);
  rep(m, i) {
    ll ta; cin >> ta;
    damaged[ta] = true;
  }

  vector<ll> dp(n+1, 0);
  dp[0] = 1;
  if (!damaged[1]) dp[1] = 1;

  for(ll i = 2; i <= n; ++i) {
    if (!damaged[i-1]) dp[i] += dp[i-1];
    if (!damaged[i-2]) dp[i] += dp[i-2];
    dp[i] %= MOD;
  }

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

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3988
#include <iostream>
#include <cstring>
typedef long long ll;
using namespace std;

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

  ll ans = 0;
  int r = s.length() - 1;
  for(int i = s.length() - 1; i >= 0; i--) {
    if(s[i] == 'W') continue;
    ans += r - i;
    r--;
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
    public static boolean solve(String S, String T){
        int N = S.length();
        Map<Character,Character> StoT = new HashMap<>();
        Map<Character,Character> TtoS = new HashMap<>();
        for(int n=0;n<N;n++){
        	char s = S.charAt(n);
        	char t = T.charAt(n);
        	if(StoT.get(s)==null){
        	    StoT.put(s,t);
        	}else if(StoT.get(s)!=t){
        	    //System.out.println(s+"->"+StoT.get(s)+"?"+t);
        	    return false;
        	}
        	if(TtoS.get(t)==null){
        	    TtoS.put(t,s);
        	}else if(TtoS.get(t)!=s){
                //System.out.println(t+"->"+TtoS.get(t)+"?"+s);
        	    return false;
        	}
        }
        
        //System.out.println(StoT);
        return true;
        
        
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        System.out.println(solve(S,T) ? "Yes" : "No");
         
    }
}


Measured memory_bytes: 28876
#include<stdio.h>
#define MAX 100
#define INF 100000000

int min(int, int);

int main(){
  int n,i,j,k,l;
  int a[MAX][MAX],b[MAX];

  scanf("%d",&n);

  for(i = 1;i <= n;i++){
    scanf("%d%d",&b[i-1],&b[i]);
    a[i][i] = 0;
  }
  
  for(l = 2;l <= n;l++){
    for(i = 1;i <= n-l+1;i++){
      j = i+l-1;
      a[i][j] = INF;
      for(k = i;k <= j-1;k++){
	a[i][j] = min(a[i][j],a[i][k]+a[k+1][j]+b[i-1]*b[k]*b[j]);
      }
    }
  }
  printf("%d\n",a[1][n]);

  return 0;
}

int min(int a,int b){
  if(a < b){
    return a;
  } else {
    return b;
  }
}



Measured memory_bytes: 2104
Module Program
  Sub Main
    Dim s=GetInts()
    Dim a=s(0)
    Dim ans=24+24-a
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,y,x,a1,a2,s;
int main()
{
	cin>>n>>a>>b;
	cin>>y;
	for(int i=2;i<=n;i++)
	{
		scanf("%d",&x);
		a1=abs(y-x)*a;a2=b;
		s+=min(a1,a2);
		y=x;
	}
	cout<<s<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

const int N=8;
const string s="FESTIVAL";
ll n;

int main(){
	cin>>n;
	int t=1,B=0,l=0;
	int flag=2;
	vl dp(N+1),a,c;
	dp[0]=1;
	while(1){
		vl DP=dp;
		for(int i=0;i<N;i++) for(int j=0;j<t;j++) DP[i+1]+=DP[i];
		if(DP[N]>n) break;
		dp=DP;
		a.push_back(DP[N-1]);
		c.push_back(t);
		l+=t*N;
		if(flag){
			flag--;
			continue;
		}
		if(B%6<5) t++;
		B++;
	}
	while(t>0){
		vl DP=dp;
		for(int i=0;i<N;i++) for(int j=0;j<t;j++) DP[i+1]+=DP[i];
		if(DP[N]>n){
			t--;
			continue;
		}
		dp=DP;
		l+=N*t;
		a.push_back(DP[N-1]);
		c.push_back(t);
	}
	n-=dp[N];
	int S=a.size();
	vl b(S);
	while(n){
		for(int i=S-1;i>=0;i--) if(a[i]<=n){
			n-=a[i];
			b[i]++;
			l++;
		}
	}
	assert(l<=5000);
	for(int i=0;i<S;i++){
		for(int j=0;j<N;j++) for(int k=0;k<c[i];k++) cout<<s[j];
		for(int j=0;j<b[i];j++) cout<<'L';
	}
	cout<<endl;
}

Measured memory_bytes: 256
S = input()
N = len(S)
ACGT = ["A", "C", "G", "T"]
ans = 0

for head in range(0, N):
  for tail in range(head, N):
    for index in range(head, tail+1):
      check = True
      if not (S[index] in ACGT):
        check = False
        break
    if check:
      ans = max(ans, tail-head+1)
print(ans)

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

int n, ans = 0;
vector<int> c(500);
vector<int> v(500);

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> v.at(i);
    for (int i = 0; i < n; ++i) cin >> c.at(i);

    for (int i = 0; i < n; ++i)
    {
        if (v.at(i) > c.at(i))
        {
            ans += v.at(i) - c.at(i);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[int(input()) for _ in range(n)]
b=[int(input()) for _ in range(m)]
c=[0]*n
for j in range(m):
    for i in range(n):
        if a[i]<=b[j]:
            c[i]+=1
            break
print(c.index(max(c))+1)


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <math.h>

using namespace std;

void C_124()
{
  string S;
  cin >> S;

  int count[2][2] = {};
  for (int i = 0; i < S.length(); ++i)
  {
    if (S[i] == '0') ++count[i % 2][0];
    else if (S[i] == '1') ++count[i % 2][1];
  }

  int a = count[0][0] + count[1][1];
  int b = count[0][1] + count[1][0];
  if (a < b) cout << a << endl;
  else cout << b << endl;

  return;
}

int main()
{
  //C_120();
  //C_121();
  //C_122();
  //C_123();
  C_124();
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,X,K,Q;
ll A,B,C,D;
set<string> S;
ll ans;
int main(){
    cin>>N;
    REP(i,N){
        string s;
        cin>>s;
        S.insert(s);
    }

    cout<<S.size()<<endl;
}


Measured memory_bytes: 19164
#include<stdio.h>
 
int main(void){
    int a,b,ans;
    char op;
 
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op == '?')
            break;
        else if(op == '+')
            ans = a + b;
        else if(op == '-')
            ans = a - b;
        else if(op == '*')
            ans = a * b;
        else
            ans = a / b;
        printf("%d\n",ans);
    }
 
    return 0;
}


Measured memory_bytes: 2124
N = int(input())
ans = 0

if N >= 100000:
    N = 99999
if N >= 10000:
    ans = N - 9999
    N = 999
if N >= 1000:
    N = 999
if N >= 100:
    ans += N - 99
    N = 9
if N >= 10:
    N = 9
ans += N
print(ans)


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

ll h,w,k;
vector<string> s;
ll res=1e+16;

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  cin >> h >> w >> k;
  s.resize(h);
  rep(i,0,h) cin >> s[i];
  
  rep(bit,0,(1<<(h-1))){
   bool ok=true;
   vll index(h+1,0);
   ll n=0;
    rep(i,0,h-1){ 
     if((bit&(1<<i))!=0) index[i+1]=index[i]+1,n++;
     else index[i+1]=index[i];
    }
    ll m=0;
    vll num(n+1,0);
    rep(i,0,w){
      bool flag=true;
      vll r(n+1,0);
     rep(j,0,h){
      r[index[j]]+=int(s[j][i]-'0');
      num[index[j]]+=int(s[j][i]-'0');
      if(r[index[j]]>k) ok=false; 
      if(num[index[j]]>k) flag=false;
     }
     if(!flag) m++, num=r;
     
    }
    if(ok) res=min(res,m+n);
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
from copy import deepcopy as copy
n=int(input())
A=input().split()
C=copy(A)
for i in range(n):
  for j in range(n-1,i,-1):
    if C[j][1] < C[j-1][1]:
      k=C[j]
      C[j]=C[j-1]
      C[j-1]=k
print(*C)
for i in range(n-1):
  if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break
else:print('Stable')
C=copy(A)
for i in range(n):
  minj = i
  for j in range(i,n):
    if C[j][1] < C[minj][1]:
      minj = j
  k=C[i]
  C[i]=C[minj]
  C[minj]=k
print(*C)
for i in range(n-1):
  if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break
else:print('Stable')


Measured memory_bytes: 6344
def gcd(a,b):
    if a==b:
        return b
    elif b==1:
        return 1
    elif a%b == 0:
        return b
    else:
        return gcd(b,a%b)
    
N,X = map(int,input().split())
x = list(map(int,input().split()))

dist = []

for i in range(N):
    dist.append(abs(X-x[i]))
dist.sort
if len(dist) == 1:
    temp = dist[0]
else:
    temp = gcd(dist[1],dist[0])
for i in range(2,N):
    temp = gcd(dist[i],temp)
    
print(temp)

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

int n;

vector<long long int> v;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		long long int a;
		scanf("%lld", &a);
		v.push_back(a);
	}
	long long int cost = 0;
	while (*max_element(v.begin(), v.end()) >= (long long int)(n)){
		for (int i = 0; i < v.size(); i++){
			long long int up = max(0LL, v[i] - (n - 1));
			up += n - 1;
			up /= (n);
			v[i] -= up*(n);
			for (int j = 0; j < v.size(); j++){
				if (j != i){
					v[j] += up;
				}
			}
			cost += up;
		}
	}
	printf("%lld\n", cost);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a[110];
int main()
{
    int n,sum=0,ans=0;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    int f1,f2,f3,f4,f5,f6,f7,f8;
    f1=f2=f3=f4=f5=f6=f7=f8=1;
    for(int i=0; i<n; i++)
    {
        if(a[i]>=1&&a[i]<=399&&f1)
        {
            sum++;
            f1=0;
        }

        if(a[i]>=400&&a[i]<=799&&f2)
        {
            sum++;
            f2=0;
        }

        if(a[i]>=800&&a[i]<=1199&&f3)
        {
            sum++;
            f3=0;
        }

        if(a[i]>=1200&&a[i]<=1599&&f4)
        {
            sum++;
            f4=0;
        }

        if(a[i]>=1600&&a[i]<=1999&&f5)
        {
            sum++;
            f5=0;
        }

        if(a[i]>=2000&&a[i]<=2399&&f6)
        {
            sum++;
            f6=0;
        }

        if(a[i]>=2400&&a[i]<=2799&&f7)
        {
            sum++;
            f7=0;
        }

        if(a[i]>=2800&&a[i]<=3199&&f8)
        {
            sum++;
            f8=0;
        }
        if(a[i]>=3200)
            ans++;
        //printf("sum%d ans%d\n",sum,ans);
    }
    // if(sum+ans<=8)
    if(sum==0)
        printf("1 %d\n",ans);
    else
    printf("%d %d\n",sum,sum+ans);
    /*else
        printf("%d 8\n",sum);*/

    return 0;


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int a,b,c,d,e;
  int C;
  
  for (int i=0; i <= (B-A); i++){
  a = (A + i)/10000;
  b = ((A + i)/1000)%10;
  c = ((A + i)/100)%10;
  d = ((A + i)/10)%10;
  e = ( A + i)%10;
    
    if(a==e && b==d ){
    C++;
    }
    else{
    continue;
    }
  } 
  cout << C << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>

using namespace std;

int main()
{
	// 入力
	int N;
  	cin>>N;
  	vector<vector<int>> G(N); // 木Gの要素数N
  	vector<pair<int,int>> two_vertex_pair(N - 1);
  	
  	for (int i = 0; i < N - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		// 木Gの頂点aと結びつく頂点b
		G[a].push_back(b);
		// 木Gの頂点bと結びつく頂点a
		G[b].push_back(a);
		// pairの作成
		two_vertex_pair[i] = make_pair(a, b);
	}
  	
  	// 1行目に使用する色の数K
  	int K = 0;
  	
  	map<pair<int, int>, int> two_vertex_color_map;
  	vector<int> color(N, 0);
  	vector<int> used_color(N, 0);
  	
  	// BFS (幅優先探索)の準備
  	queue<int> que;
  	// 頂点0番目の色の指定
  	used_color[0]=1;
  	// キューに要素を追加
  	que.push(0);
  	
  	// BFS 開始 (キューが空になるまで探索を行う)
  	while(!que.empty())
  	{
		int v = que.front(); // キューから先頭頂点を取り出す
		que.pop();
		
		if (K < G[v].size()) {
			K = G[v].size();
		}
		
		int c = 1;
		// 先頭vからたどれる頂点をすべて調べる
		for (int u : G[v])
		{
			if (used_color[u] > 0)
			{
				// すでに頂点に色が塗られているので、次の頂点へ
				continue;
			}
			// 先頭の色と同じ場合
			if (c == color[v])
			{
				// 色の更新
				c++;
			}
			
			// 現在の頂点の色の設定
			color[u] = c;
			// 先頭と現在の頂点のペアに色の割り当て
			two_vertex_color_map[make_pair(u, v)] = c;
			two_vertex_color_map[make_pair(v, u)] = c;
			used_color[u] = 1;
			// 色の更新
			c++;
			// 頂点の追加
			que.push(u);
		}
	}
	
	// 出力
	cout<< K << endl;
	for (int i = 0; i < N - 1; i++)
	{
		cout << two_vertex_color_map[two_vertex_pair[i]] << endl;
	}
  	
	return 0;
}

Measured memory_bytes: 20096
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll N, X;
  scanf("%lld %lld", &N, &X);

  ll n_patty[N+1];
  ll n_all[N+1];
  n_patty[0] = 1;
  n_all[0] = 1;
  rep(i, N) n_patty[i+1] = n_patty[i] * 2 + 1;
  rep(i, N) n_all[i+1] = n_all[i] * 2 + 3;

  ll ans = 0;
  ll ptr = X;
  rrep(l, N+1){
    if(l == 0){
      ans++;
      break;
    }
    if(ptr == (n_all[l-1] + 2)){
      ans += n_patty[l-1] + 1;
      break;
    }
    else if(ptr == n_all[l]){
      ans += n_patty[l];
      break;
    }
    else if(ptr < (n_all[l-1] + 2)){
      ptr--;
      if(ptr < 1) break;
    }
    else{
      ans += n_patty[l-1] + 1;
      ptr -= n_all[l-1] + 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=1000000007;
const long long inf=1ll<<61;

signed main(){
    int x;cin>>x;x-=400;x/=200;cout<<8-x<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define deb(x) cout << #x << " --> " << x << endl;
#define print(x)                         \
    for (auto _x : x) cout << _x << " "; \
    cout << endl
#define pb push_back
typedef long long ll;
using namespace std;

int main() {
    int a[200] = {};
    bool hash[200] = {};
    int x, n;
    cin >> x >> n;
    for (int i = 0; i < n; ++i) cin >> a[i], hash[a[i]] = true;
    // if (n == 0) {
    //     cout << x << endl;
    //     return 0;
    // }
    int left = x - 1, right = x + 1;
    left = right = x;
    while (true) {
        if (!hash[left]) {
            cout << left << endl;
            break;
        }
        left--;
        if (!hash[right]) {
            cout << right << endl;
            break;
        }
        right++;
    }
}

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


int main()
{
    unsigned int H, W;
    unsigned int H_Odd = 0, H_Even = 0;
    long long res = 0;
    unsigned int i;
    cin >> H >> W;

    //奇数行目・偶数行目に到達可能なマスの特定
    H_Odd = W / 2 + (W % 2); //奇数行
    H_Even = W / 2;          //偶数行

    //数え上げ
    for (i = 0; i < H; i++) {
        if ((i + 1) % 2 == 0) {
            res = res + H_Even;
        }
        else {
            res = res + H_Odd;
        }
    }
    if (H == 1 or W == 1) {
        cout << "1";
    } else {
        cout << res;
    }
}

Measured memory_bytes: 256