akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         long K=gl();
         long S=gl();
         long[] a=new long[N];

         for (int i=0; i<N;i++) {
        	 if(i<K) {
        		 a[i]=S;
        	 } else {
        		 long q=S+1;
        		 if(q>1000000000) q=1;
        		 a[i]=q;
        	 }
         }

         StringBuilder sb=new StringBuilder();
         for (int i=0;i<N;i++) {
        	 if(i!=0);sb.append(" ");
        	 sb.append(a[i]);
         }

         System.out.println(sb);
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 41848
from collections import defaultdict
from operator import mul
from functools import reduce


def main():
    n = int(input())
    p = [1] * (n + 1)
    for i in range(2, n + 1):
        if p[i] != 1:
            continue
        for j in range(i, n + 1, i):
            if p[j] == 1:
                p[j] = i
    ans = 1
    for i in range(2, n):
        m = i
        k = defaultdict(int)
        while m > p[m]:
            k[p[m]] += 1
            m //= p[m]
        k[m] += 1
        ans += reduce(mul, [e + 1 for e in k.values()])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <iomanip>

using namespace std;

typedef struct {
	uint32_t i;
	uint32_t p;
	uint32_t y;
}info_t;

int main()
{
	int32_t n, m;
	cin >> n >> m;

	vector<info_t> v(m);
	for(auto i = 0; i < m; ++i) {
		cin >> v[i].p >> v[i].y;
		v[i].i = i;
	}

	sort(v.begin(), v.end(), [](info_t x1, info_t x2){ return x1.y < x2.y;});

	vector<uint64_t> number(m);
	vector<uint32_t> count(n, 0);
	for(auto& x : v) {
		++count[x.p];
		number[x.i] = count[x.p] + 1e6 * x.p;
	}

	for(auto& x : number) {
		cout << setw(12) << std::setfill('0') << x << '\n';
	}
}


Measured memory_bytes: 3968
S = input()
if S == 'MON':
  print(6)
elif S == 'TUE':
  print(5)
elif S == 'WED':
  print(4)
elif S == 'THU':
  print(3)
elif S == 'FRI':
  print(2)
elif S == 'SAT':
  print(1)
else:
  print(7)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	int n,k;
	// nyuryoku
	string s;
	cin >> n >> k >> s;
	k--;
	// keisan
	char c = s[k];
	s[k] = 'a' + c - 'A';
	// syutsuryoku
	cout << s << endl;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int sum = 0;
    vector<int> in(n);
    rep(i, n){
        cin >> in.at(i);
        sum += in.at(i);
    }
    int s = 0;
    rep(i, n){
        if(sum%(4*m) == 0){
            if(in.at(i) >= sum/4/m) s++;
        }else{
            if(in.at(i) > sum/4/m) s++;
        }
    }
    if(s >= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
  int n;
  cin>>n;
  int a[n];
  for (int i = 0; i < n; ++i) cin>>a[i],cout<<((i!=0)?" ":"")<<a[i];
  cout<<endl;
  for (int i = 1; i < n; ++i)
  {
    int k=a[i];
    int j=i-1;
    while(j>=0&&a[j]>k) a[j+1]=a[j],--j;
    a[j+1]=k;
    for (int i = 0; i < n; ++i) cout<<((i!=0)?" ":"")<<a[i];
    cout<<endl;
  }
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n+m-1)/m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long F(long long A,long long B){
	int na=0,nb=0;
	while(A>0){
		na++;
		A/=10;
	}
	while(B>0){
		nb++;
		B/=10;
	}
	return max(na,nb);
}
int main(){
	long long n;
	cin>>n;
	long long ans=10000000000;
	for(long long i=1;i*i<=n;i++)
		if(n%i==0){
		  long long cur=F(i,n/i);
		  ans=min(ans,cur);	
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  int a, b, c, d, e, f;
  cin >> a >> b>>c>>d;
  e = a+b; f= c+d;
  if(e<f) cout <<"Right"<<endl;
  else if(e>f)  cout<<"Left"<<endl;
  else cout<<"Balanced"<<endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
t = 0
u = 0
n = len(s)
for i in range(n):
  if s[i] == "A":
    t = i
    break
for j in range(n):
  if s[n-j-1] == "Z":
    u = n-j-1
    break
print(u-t+1)

Measured memory_bytes: 3512
#include <stdio.h>

int main()
{
    int h1, m1, h2, m2, k;
    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);

    printf("%d\n", (h2 - h1) * 60 + (m2 - m1) - k);

    return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

char a[4][4];

bool f(char c){
	for(int y = 0; y < 3; y++){
		int cnt = 0;
		for(int x = 0; x < 3; x++){
			if( a[y][x] == c ) cnt++;
		}
		if( cnt == 3 ) return true;
	}
	for(int x = 0; x < 3; x++){
		int cnt = 0;
		for(int y = 0; y < 3; y++){
			if( a[y][x] == c ) cnt++;
		}
		if( cnt == 3 ) return true;
	}
	if( a[0][0] == c && a[1][1] == c && a[2][2] == c ) return true;
	if( a[0][2] == c && a[1][1] == c && a[2][0] == c ) return true;
	return false;
}

int main(){
	while( cin >> a[0][0] ){
		for(int i = 1; i < 9; i++){
			int x = i % 3, y = i / 3;
			cin >> a[y][x];
		}
		if( f('x') ){
			cout << "x" << endl;
		}else if( f('o') ){
			cout << "o" << endl; 
		}else{
			cout << "d" << endl;
		}
		cin.ignore();
	}
}

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

int main(int argc, char** argv) {
	unsigned long X; std::cin >> X;
	std::vector<unsigned long> prime_box;
	for (auto i = 2;i <= X;++i) {
		bool find = false;
		for (auto prime : prime_box) {
			if (i % prime == 0) {
				find = true;
				break;
			}
		}
		if (find == false) prime_box.push_back(i);
	}
	if (std::find(prime_box.begin(), prime_box.end(), X)!=prime_box.end()) {
		std::cout << X << '\n';
		return 0;
	}
	for (auto i = X+1;;++i) {
		bool find = false;
		for (auto prime : prime_box) {
			if (i % prime == 0) {
				find = true;
				break;
			}
		}
		if (find == false) {
			std::cout << i << '\n';
			break;
		}	
	}
}


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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k, i, j;
    cin >> h >> w >> k;
    int x0,y0,x1,y1;
    cin >> x0 >> y0 >> x1 >> y1;
    x0--;y0--;x1--;y1--;
    char grid[h][w];
    for(i=0;i<h;i++){
        string s;
        cin >> s;
        for(j=0;j<w;j++){
            grid[i][j] = s[j];
        }
    }
    vvi dist(h, vi(w, inf));
    vvi used(h, vi(w));
    dist[x0][y0] = 0;
    used[x0][y0] = 1;
    queue<pii> Q;
    Q.push({x0,y0});
    int x,y;
    while(!Q.empty()){
        tie(x,y) = Q.front();
        Q.pop();
        used[x][y] = 2;
        if(x == x1 && y == y1) break;
        for(int dd = 0;dd < 4;dd++){
            i = x + dx[dd];
            j = y + dy[dd];
            while(  (i >= 0 && i < h) 
                    && (j >= 0 && j < w) 
                    && grid[i][j] != '@'){
                if(used[i][j] == 2) break;
                if(abs(i - x) > k || abs(j - y) > k) break;
                if(!used[i][j]){
                    dist[i][j] = dist[x][y] + 1;
                    used[i][j] = 1;
                    Q.push({i,j});
                }
                i += dx[dd];
                j += dy[dd];
            }
        }
    }
    
    if(dist[x1][y1] == inf){
        cout << "-1\n";
    }else{
        cout << dist[x1][y1] << "\n";
    }

    return 0;
}

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

int main() {
int a,b;
cin >> a >> b ;
if (a > b) {
  cout << "a > b" << endl;
}else if (a < b){
  cout << "a < b" << endl;
}
else {
  cout << "a == b" << endl;
}
return 0;
}

Measured memory_bytes: 1160
N,K=map(int,input().split())
D={int(i) for i in input().split()}

C = {0,1,2,3,4,5,6,7,8,9} - D
A=[]
for i in range(9*N+1):
    if (N+i)%10 in C:
        if ((N+i)%100)//10 in C:
            if ((N+i)%1000)//100 in C:
                if ((N+i)%10000)//1000 in C:
                    if (N+i)//10000 in C:
                        A.append(N+i)
                    elif (N+i)//10000==0:
                        A.append(N+i)
                elif (N+i)//1000==0:
                    A.append(N+i)
            elif (N+i)//100==0:
                A.append(N+i)
        elif (N+i)//10==0:
            A.append(N+i)



print(min(A))


Measured memory_bytes: 5432
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b<c+d)
	cout<<"Right";
	else if(a+b>c+d)
	cout<<"Left";
	else
	cout<<"Balanced";
	return 0;
} 

Measured memory_bytes: 256
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 900;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

string s[maxn];
int dist[maxn][maxn];
queue < pii > q,q2;
int w , h , k;
int dx [] = {1 , -1 , 0 , 0};
int dy [] = {0 , 0 , 1 , -1};
bool mark[maxn][maxn];

void bfs1(){
    while(!q.empty()){
        q2.push(q.front());
        auto v = q.front();
        q.pop();
        int x = v.first , y = v.second;
        if(x == 0 or y == 0 or x == w-1 or y == h-1){
            cout << 1;
            exit(0);
        }
        if(dist[x][y] == k)
            continue;
        for(int i = 0 ; i < 4 ; i ++){
            if(s[x + dx[i]][y + dy[i]] == '.' and dist[x + dx[i]][y + dy[i]] > dist[x][y] + 1){
                dist[x + dx[i]][y + dy[i]] = dist[x][y] + 1;
                q.push({x + dx[i] , y + dy[i]});
            }
        }
    }
}

void bfs2(){
    int ans = 1e9;
    while(!q2.empty()){
        auto [x , y] = q2.front();
        q2.pop();
        int val = min(min(x , h - x - 1) , min(y , w - y - 1));
        ans = min(ans , (val+k-1)/k);
    }
    cout << ans+1;
}

int32_t main(){
    migmig
    ms(dist , 63);
    cin >> h >> w >> k;
    for(int i = 0 ; i < h ; i ++){
        cin >> s[i];
        for(int j = 0 ; j < w ; j ++)
            if(s[i][j] == 'S')
                q.push({i , j}),
                dist[i][j] = 0;
    }
    bfs1();
    bfs2();
    return(0);
}

Measured memory_bytes: 7716
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
from bisect import *
mod = 10**9+7

S = input()[:-1]
for i in range(5):
    if 'hi' * (i+1) == S:
        print('Yes')
        exit()
print('No')


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi w(n);
    rep(i, n) cin >> w[i];
    int ans = 1e9;
    for (int i=1; i<n; ++i) {
        int l = 0, r = 0;
        rep(j, i) l += w[j];
        for (int j=i; j<n; ++j) r += w[j];
        ans = min(ans, abs(r-l));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
Uses math;
var n,i,b,count:int64;
    a:array[1..100010]of int64;    
begin
read(n);count:=0;
for i := 1 to n+1 do read(a[i]);
for i := 1 to n do begin
read(b);
if a[i]>b then begin count:=count+b;continue end;
count:=count+a[i]+min(b-a[i],a[i+1]);
a[i+1]:=max(a[i+1]-b+a[i],0)
 end;
write(count);
end.

Measured memory_bytes: 1024
N = int(input())
A = [int(input()) for i in range(N)]

A.sort()
ans = 0
if N % 2 == 0:
    h = (N - 2) // 2
    ans = -2 * sum(A[:h]) - A[h] + A[h + 1] + 2 * sum(A[h + 2:])
else:
    h = (N - 3) // 2
    m1 = -2 * sum(A[:h + 1]) + sum(A[h + 1:h + 3]) + 2 * sum(A[h + 3:])
    m2 = -2 * sum(A[:h]) - sum(A[h:h + 2]) + 2 * sum(A[h + 2:])
    ans = max(m1, m2)
print(ans)


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

int main(){
  int N,sum1=0,sum2=0;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  sort(a,a+N);
  reverse(a,a+N);
  for(int i=0;i<N;i+=2){
    sum1 += a[i];
  }
  for(int j=1;j<N;j+=2){
    sum2 += a[j];
  }
  cout << sum1-sum2 << endl;
}


Measured memory_bytes: 768
import sys
from collections import defaultdict, deque
n = int(sys.stdin.readline().split()[0])
A = defaultdict(deque)
ans = []
for query in sys.stdin:
    if query[0] == '0':
        t, x = query[2:].split()
        A[t].append(x)
    elif query[0] == '1':
        if A[query[2: -1]]:
            ans.append(A[query[2:-1]][-1] + '\n')
    else:
        if A[query[2: -1]]:
            A[query[2: -1]].pop()

sys.stdout.writelines(ans)



Measured memory_bytes: 20136
#include <stdio.h>
int main(void){
    int n, x, min, max, i;
    long long sum=0;
    scanf("%d", &n);
    for(i=1; i<=n; i++){
        scanf("%d", &x);
        if(i==1)
        min = x;
        else if(x < min)
        min = x;
        
        if(i==1)
        max = x;
        else if(x > max)
        max = x;
        
        sum += x;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}



Measured memory_bytes: 2104
from collections import deque
import sys
input = sys.stdin.readline

def main():
    while True:
        w, h = map(int, input().split())
        if w == 0:
            break
        # 読み込み
        board = [list(map(int, input().split())) for i in range(h)]
        # 地図を整形
        # wall : ID( 1~ )
        # air: 0
        s_x, s_y, g_x, g_y = 0, 0, 0, 0; id = 1;
        for y in range(h):
            for x in range(w):
                if board[y][x] == 1:
                    board[y][x] = id
                    id += 1
                elif board[y][x] == 2:
                    s_x = x; s_y = y;
                    board[y][x] = 0
                elif board[y][x] == 3:
                    g_x = x; g_y = y;
                    board[y][x] = 0
        # スタートから幅優先探索
        search_list = deque()
        search_list.append([s_x, s_y, 0, 0, 0, [0], 1])
        ans = -1
        check = []
        while len(search_list) > 0:
            # print(search_list)
            x, y, step, dx, dy, through, count = search_list.popleft()
            if x == g_x and y == g_y:
                ans = step
                break
            if dx == 0 and dy == 0:# 動き始めの処理
                if step+1 < 11:
                    for next_x, next_y in [[x-1, y], [x+1, y], [x, y+1], [x, y-1]]:
                        if 0 <= next_x and next_x < w and 0 <= next_y and next_y < h:
                            tmp = board[next_y][next_x]
                            if tmp in through[:count]:
                                search_list.append([next_x, next_y, step+1, next_x-x, next_y-y, through[:count], count])
            else:# 壁にぶつかるまで滑る
                t_x = x; t_y = y;
                drop = False
                goal = False
                while True:
                    n_x = t_x + dx; n_y = t_y + dy;
                    if n_x == g_x and n_y == g_y:
                        ans = step
                        goal = True
                        break
                    if 0 <= n_x and n_x < w and 0 <= n_y and n_y < h:
                        if board[n_y][n_x] not in through[:count]:
                            break
                    else:
                        drop = True
                        break
                    t_x += dx; t_y += dy;
                if goal:
                    break
                if not drop:
                    tmp = board[t_y+dy][t_x+dx]
                    through = through[:count] + [tmp]
                    search_list.append([t_x, t_y, step, 0, 0, through, count+1])
        print(ans)

if __name__ == "__main__":
    main()



Measured memory_bytes: 30552
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		for(;;){

			int n = sc.nextInt();

			if(n==0) break;

			int a = 0;

			int b = 0;

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

				int a1 = sc.nextInt();

				int b1 = sc.nextInt();

				if(a1 > b1){

					a+=a1 + b1;

				}

				if(b1 > a1){

					b+= a1+b1;

				}

				if(a1 == b1){

					a += a1;

					b += b1;

				}

			}

			System.out.println(a + " "+ b);

		}		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 999999999;

int main(){
   int x,y;
   cin >> x >> y;
   int a[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
   if(a[x] == a[y])cout << "Yes";
   else cout << "No";
   return 0;
}

Measured memory_bytes: 256
# AtCoder
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]


def isValid(n):
    sn = str(n)
    if len(sn) != N:
        return False
    for s, c in sc:
        if sn[s-1] != str(c):
            return False
    return True


for i in range(1000):
    if isValid(i):
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3064
H,W = map(int,input().split())
maze = []
from collections import deque
for _ in range(H):
    s = list(input())
    maze.append(s)
direction = [[1,0],[0,1],[-1,0],[0,-1]]
ans = -1
for row in range(H):
    for col in range(W):
        if maze[row][col] == "#":
            continue
        distance = [[-1 for _ in range(W)] for _ in range(H)]
        d = deque([[row,col]])
        distance[row][col] = 0
        while(len(d)>0):
            nowrow, nowcol = d.popleft()
            for subrow, subcol in direction:
                subrow += nowrow
                subcol += nowcol
                if subrow < 0 or subrow >= H or subcol < 0 or subcol >= W:
                    continue
                if maze[subrow][subcol] == "#":
                    continue
                if distance[subrow][subcol] != -1:
                    continue
                d.append([subrow, subcol])
                distance[subrow][subcol] = distance[nowrow][nowcol] + 1
            ans = max(ans,max([max(maxrow) for maxrow in distance]))
print(ans)

Measured memory_bytes: 49756
def main():
    a, b, c = map(int, input().split())
    list = []
    list.append(a)
    list.append(b)
    list.append(c)

    if list.count(5) == 2 and list.count(7) == 1 :
        print("YES")
    else :
        print("NO")

if __name__ == '__main__':
    main()


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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    string str;
    deque<char> q;
    int m;
    int rev = 0;
    cin >> str;
    for (auto c: str)
        q.push_back(c);
    cin >> m;
    while (m--) {
        int a, b;
        char c;
        cin >> a;
        if (a == 1) {
            rev = !rev;
        } else if (a == 2) {
            cin >> b >> c;
            if (b == 1 && rev == 0) {
                q.push_front(c);
            } else if (b == 1  && rev == 1) {
                q.push_back(c);
            } else if (b == 2 && rev == 0) {
                q.push_back(c);
            } else if (b == 2 && rev == 1) {
                q.push_front(c);
            }
        }
    }
    str.clear();
    while (!q.empty()) {
        if (rev == 0) {
            str.push_back(q.front());
            q.pop_front();
        } else if (rev == 1) {
            str.push_back(q.back());
            q.pop_back();
        }
    }
    cout << str << endl;

    return 0;
}


Measured memory_bytes: 1168
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
alice,bob=0,0
cnt=0
for x in range(n):
    global alice
    global bob
    if cnt<n:
        alice+=a[cnt]
        cnt+=1
    if cnt<n:
        bob+=a[cnt]
        cnt+=1
print(abs(alice-bob))

Measured memory_bytes: 3064
from operator  import mul
from functools import reduce

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact    = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv     = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#kari1 = '2 3 1 1'                   #2
#kari1 = '10 7 3 4'                  #3570
#kari1 = '100000 100000 99999 99999' #1
#kari1 = '100000 100000 44444 55555' #738162020

"""
in1 = kari1.split()
"""
in1 = input().split()

H = int(in1[0])
W = int(in1[1])
A = int(in1[2])
B = int(in1[3])

allCNT = 0
for idx1 in range(W - B):
    beforeCNT = cmb(H - A + B - 1 + idx1, H - A - 1, p)
    afterCNT  = cmb(W + A - B - 2 - idx1, A - 1, p)
    allCNT    = (allCNT + (beforeCNT * afterCNT) % p) % p

print(allCNT)


Measured memory_bytes: 124380
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

//集合を表すデータ構造、根は大きさを負で持ち、子は根を正で持つ
//[0]に全体の集合の数を入れる
//swapを使用するため<utility>をインクルードする
struct UnionFind{
    vector<int>data;
    UnionFind(int size) :   data(size+1, -1){
        data[0] = size;
    }

    //集合のmerge
    //すでに同じならfalse
    bool merge(int x, int y){
        x = root(x);    y = root(y);
        if(x == y)  return false;
        //要素数の少ない方を多い方に繋げる
        if(data[y] < data[x])   swap(x, y);
        data[x] += data[y];
        data[y] = x;
        data[0]--;
        return true;
    }

    //どの集合に属しているか
    int root(int x){
        //根に繋ぎ直す
        return (data[x] < 0) ? x : (data[x] = root(data[x]));
    }

    //ある要素が属する集合の大きさ
    int size(int x){
        return -data[root(x)];
    }

    //集合の数
    int set(){
        return data[0];
    }
};

int main(){
    int n,m,k;  cin >> n >> m >> k;
    UnionFind frend(n);
    vector<vector<int> >F(n+1);
    vector<vector<int> >B(n+1);
    rep(i, m){
        int a,b;    cin >> a >> b;
        frend.merge(a, b);
        F[a].push_back(b);
        F[b].push_back(a);
    }
    rep(i, k){
        int c,d;    cin >> c >> d;
        B[c].push_back(d);
        B[d].push_back(c);
    }
    vector<int>ans(n);
    rep(i, n){
        int now = i+1;
        int tmp = frend.size(now);
        tmp--;  //自身を引く
        tmp -= F[now].size();
        rep(j, B[now].size()){
            if(frend.root(now) == frend.root(B[now][j]))    tmp--;
        }
        ans[i] = tmp;
    }
    rep(i, n){
        printf("%d%c", ans[i], (i == n-1)?'\n':' ');
    }
}


Measured memory_bytes: 12664
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    sort(all(a), greater<lint>());

    lint res[2] = {-1, -1};
    int j = 0;

    rep(i, n-1) {
        if (a[i] == a[i+1]) {
            if (j >= 2) continue;
            res[j] = a[i];
            i++;
            j++;
        }
    }
    if (res[1] != -1) cout << res[0] * res[1] << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,q;
vector<int> ed1[200100];
vector<int> ed[200100];
int par[200100];
int point[200100]={};
int ans[200100]={};

int main(){
	speed_up;
	cin>>n>>q;
	REP(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		ed[a].push_back(b);
		ed[b].push_back(a);
	}
	REP(i,q){
		int p,x;
		cin>>p>>x;
		p--;
		point[p]+=x;
	}
	REP(i,200100)ans[i]=-1;
	ans[0]=point[0];
	stack<int> q;
	q.push(0);
	while(q.size()){
		int q1=q.top();
		q.pop();
		int node=q1;
		for(int i=0;i<ed[node].size();i++){
			if(ans[ed[node][i]]!=-1)continue;
			ans[ed[node][i]]=ans[node]+point[ed[node][i]];
			q.push(ed[node][i]);
		}
	}
	REP(i,n){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

const int N = 2e5 + 77;

int main(){
    string s;
    cin >> s;
    int n = 0;
    for(char i : s) n += i-'0';
    if(n%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

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

int main(){
	int n;	cin>>n;
	string order,P,Q;
	for(int i=0;i<n;i++){
		char c;	cin>>c;
		P.push_back(c);
	}
	for(int i=0;i<n;i++){
		char c;	cin>>c;
		Q.push_back(c);
	}
	for(int i=0;i<n;i++)order.push_back(i+1+'0');

	//cout<<P<<endl;
	//cout<<Q<<endl;
	//cout<<order<<endl;

	int a,b,cnt=0;
	do{
		++cnt;
		if(order==P)a=cnt;
		if(order==Q)b=cnt;

	}while(next_permutation(ALL(order)));

	cout<<abs(a-b)<<endl;

	return 0;
}


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n, m;
bool a[100005];
ll dp[100005];
int main() {
	std::cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int tmp;
		std::cin >> tmp;

		a[tmp] = true;
	}

	dp[0] = 1;
	for (int i = 0; i < n; ++i) {
		if (!a[i + 1])
			dp[i + 1] = (dp[i + 1] + dp[i]) % mod;
		if (!a[i + 2])
			dp[i + 2] = (dp[i + 2] + dp[i]) % mod;
		dp[i] = 0;
	}

	std::cout << dp[n] << std::endl;
	return 0;
}


Measured memory_bytes: 1152
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, a[100010], b[100010], c[100010];
vector<int> vec[100010], ans;
set<int> res[100010];
bool used[100010];
void visit(int node) {
	if (!used[node]) {
		used[node] = true;
		for (int i : vec[node])visit(i);
		ans.push_back(node);
	}
}
signed main() {
	cin >> n >> m;
	rep(i, n + m - 1) {
		cin >> a[i] >> b[i];
		vec[a[i]].push_back(b[i]);
	}
	REP(i, n)visit(i);
	reverse(ans.begin(), ans.end());
	rep(i, n)c[ans[i]] = i;
	rep(i, n + m - 1)res[c[b[i]]].insert(c[a[i]]);
	REP(i, n) {
		if (!res[c[i]].empty())cout << ans[*res[c[i]].rbegin()] << endl;
		else cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 22128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for (auto &e : p)
    cin >> e;

  sort(p.begin(), p.end());
  cout << accumulate(p.begin(), p.end(), 0) - p[p.size() - 1] / 2 << endl;

  return 0;
}


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

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int memo[1000001];
int sosu[1000001];

int main(){
  rep(i,1000001)sosu[i]=0;
  sosu[0]=sosu[1]=1;
  rep(i,1000001){
    if(sosu[i]==1)continue;
    for(int j=i*2;j<1000001;j+=i){
      sosu[j]=1;
    }
  }

 A:;
  int n,m;
  cin>>n>>m;
  if(n==0)return 0;

  int sina[101];
  rep(i,n){
    cin>>sina[i];
  }
  sort(sina, sina+n);

  rep(i,1000001)memo[i]=0; 

  memo[0]=1;

  rep(i,m+1){
    if(memo[i]==1){
      rep(j,n){
	if(i+sina[j]>m)break;
	memo[i+sina[j]]=1;
      }
    }
  }

  int maxi=-1;
  rep(i,m+1){
    if(sosu[i]==0 && memo[i]==1)maxi=max(maxi,i);
  }

  if(maxi==-1)puts("NA");
  else printf("%d\n",maxi);

  goto A;
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  string s, t;
  cin >> s >> t;
  int n = s.size();
  bool flag = false;

  for(int i=0; i<n; ++i){
    if(s==t){
      flag = true;
      break;
    }
    s = s.back() + s.substr(0, n-1);
  }

  if(flag) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void)
{
	int a,b;

	scanf("%d %d", &a, &b);

	if (a<b)
	{
		printf("a < b\n");
	}
	if (a>b)
	{
		printf("a > b\n");
	}
	if (a==b)
	{
		printf("a == b\n");
	}

	return 0;
}



Measured memory_bytes: 2104
#include<cstdio>

int div(int x, int y){
    int value = 0;
    int count;
    if(x<y){
        count = x;
        x = y;
        y = count; 
    }
    while (y>0){
        value = x%y;
        x = y;
        y = value;
    }
    return x;
}

int main(){
    int x,y;
    scanf("%d %d", &x,&y);
    int v = div(x,y);
    printf("%d\n", v);
}


Measured memory_bytes: 2712
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <vector>

#define REP(i,n) for(int i=0;i<n;i++)
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


using namespace std;
using ll=long long;
ll mod = 1e9 + 7;

//int dp[1e5];
//memset(dp, BMAX*HMAX, sizeof(dp));
  
int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i];
    }
    vector<ll> dp(H+1, 1e9);
    dp[0] = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<N;j++){
            chmin(dp[min(i+A[j], H)], dp[i]+B[j]);
        }
    }
    cout << dp[H] << endl;
	return 0;
}


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

typedef long long ll;

int main()
{

    ll n,i,a,j,b;
    vector<ll>v;
    for(i=0; i<6; i++)
    {
        cin >> a;
        v.push_back(a);
    }
    for(i=0; i<5; i++)
    {
        for(j=i+1; j<5; j++)
        {
            a=v[i],b=v[j];
            if(abs(a-b)>v[5])
            {
                cout << ":(\n";
                return 0;
            }
        }
    }
    cout << "Yay!\n";


    return 0;
}





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

#define int long long
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int N;
string s;
int white[222222];
int black[222222];

signed main() {
  cin >> N >> s;
  // 1を立てる
  for (int i = 0; i < N; i++) {
    white[i+1] = s[i] == '.';
    black[i+1] = s[i] == '#';
  }

  // 累積を取る
  for (int i = 0; i <= N; i++) {
    black[i+1] += black[i];
  }
  for (int i = N; i >= 1; i--) {
    white[i-1] += white[i];
  }

  int ans = 1e18;
  for (int i = 0; i <= N; i++) {
    int t = black[i] + white[i+1];
    chmin(ans, t);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3716
#include <stdio.h>
#include <string.h>
int main(){
  char a[36][3],b[36][3],x[3];
  int n,i,j,c[36],d[36],t,min,o=1;
  
  scanf("%d",&n);
  for(i =0;i<n;i++){
    scanf("%s",a[i]);
    strcpy(b[i],a[i]);
    c[i]=d[i]=a[i][1]-'0';
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(c[j]<c[j-1]){
    t=c[j];
    c[j]=c[j-1];
    c[j-1]=t;
    strcpy(x,a[j]);
    strcpy(a[j],a[j-1]);
    strcpy(a[j-1],x);
      }
    }
  }  
  for(i=0;i<n;i++){
    if(i!=n-1){
      printf("%s ",a[i]);
    }else{
      printf("%s\n",a[i]);
      puts("Stable");
    }
  }
  for(i=0;i<n-1;i++){
    min=i;
    for(j=i+1;j<n;j++){
      if(d[j]<d[min]){
    min=j;
      }
    }   
    if(min!=i){
      t=d[i];
      d[i]=d[min];
      d[min]=t;
      strcpy(x,b[i]);
      strcpy(b[i],b[min]);
      strcpy(b[min],x);
    }
  }
  for(i=0;i<n;i++){
    if(strcmp(a[i],b[i])){
      o=0;
    }
    if(i!=n-1){
      printf("%s ",b[i]);
    }else{
      printf("%s\n",b[i]);
    }
  }
  if(o){
    puts("Stable");
  }else{
    puts("Not stable");
  }
  return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>

#define llong long long
#define rep(i,l,n) for(llong (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a) ((a)>0?(a):(-(a)))

using namespace std;

#define P (998244353)

class interval{
	public:
		int min,max,mid;
		llong cnt;
		interval *left,*right;
		interval(int a,int b):min(a),max(b),mid((a+b)/2),cnt(0){
			if( a==b ){
				left = right = 0;
			}else{
				left = new interval(a,mid),right = new interval(mid+1,b);
			}
		}
		void insert(int a,int b,llong c){
			if( min >= a && max <= b ){
				cnt = (c+cnt)%P;
				return;
			}
			if( mid >= a ){
				left->insert(a,b,c);
			}
			if( mid < b ){
				right->insert(a,b,c);
			}
		}
		llong search(int x){
			llong ans = cnt;
			if( min==max ){
				return ans;
			}else if( mid >= x ){
				ans = (ans+left->search(x))%P;
			}else{
				ans = (ans+right->search(x))%P;
			}
			return ans;
		}
};

int main(){
	int N,K;
	cin >> N >> K;
	int L[K],R[K];
	rep(i,0,K){
		cin >> L[i] >> R[i];
	}
	interval I(1,N);
	I.insert(1,1,1);
	rep(i,1,N){
		llong k = I.search(i);
		rep(j,0,K){
			if( i+L[j] <= N ){
				I.insert(i+L[j],_min(N,i+R[j]),k);
			}
		}
	}
	cout << I.search(N);
}


Measured memory_bytes: 22392
import copy

s = input()
n = len(s)
li = []
ans = 0

def make_list():
    global li
    if len(li) < n - 1:
        li.append(0)
        make_list()
        li.pop(-1)
        li.append(1)
        make_list()
        li.pop(-1)
    else:
        calc(li)

def calc(li):
    global ans
    tmp = 0
    cnt = 0
    s1 = copy.copy(s)
    for i in range(n-1):
        if li[i] == 0:
            tmp += int(s1[cnt:i+1])
            cnt = i+1
    tmp += int(s1[cnt:])
    ans += tmp

make_list()

print(ans)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

 int main(){

  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;

  int ans = 1e9;

  for(int i=0;i<=max(x,y);i++){
      int cnt = 2*i*c+max(x-i,0)*a+max(y-i,0)*b;
      ans = min(ans,cnt);
  }

  cout<<ans<<endl;

 return 0;
 }

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

mx = max(A)

med = -1
min_dist = mx*999

for a in A:
    if a == mx: continue
    d = abs(a*2 - mx)
    if d < min_dist:
        min_dist = d
        med = a

print(mx, med)

Measured memory_bytes: 14052
from sys import stdin
input = int(stdin.readline())
flag = False
if input == 2:
    flag = True
    output = 2
else:
    for i in range(input, 1000000):
        sqrt_i = int(i ** (1/2)) + 1
        flag = True
        for j in range(2, sqrt_i + 1):
            if i % j == 0:
                flag = False
        if flag:
            output = i
            break
print(output)

Measured memory_bytes: 3064
#include <iostream>

int main(int argc, const char *argv[])
{
    int A, B, C;
    std::cin >> A >> B >> C;
    if (C >= A && C <= B) std::cout << "Yes" << std::endl;
    else if (C <= A && C >= B) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
}

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

int main(){
	int b,c;
	int n,x[10];
	
	cin >> n;
	
	for(int i=0; i<n; i++){
		b=0; c=-1;
		for(int j=0; j<10;j++){
			cin >> x[j];
			if(b>c&&x[j]>b) b=x[j];
			else if(b<c&&x[j]>c) c=x[j];
			else if(b<c&&x[j]>b) b=x[j];
			else if(b>c&&x[j]>c) c=x[j];
			else b=11;
		}
		if(b==11) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    
    int N, M;
    cin >> N >> M;
    
    
    vector <pair <int, pair <int, int> > > DLR(M);
    for (int i = 0; i < M; i++){
        cin >> DLR[i].second.first;
        cin >> DLR[i].second.second;
        int D = DLR[i].second.second - DLR[i].second.first;
        DLR[i].first = D;
    }
    
    sort (DLR.begin(), DLR.end());
  
    int ans = 0;
    int L0 = DLR[0].second.first, R0 = DLR[0].second.second;
    bool flag = true;
    for (int i = 1; i < M; i++){
        int L = DLR[i].second.first;
        int R = DLR[i].second.second;

        if (R0 < L || R < L0){
            flag = false;
            break;
        }else{
            if (L0 < L){
                L0 = L;
            }
            if (R < R0){
                R0 = R;
            }
        }
    }

    if (flag == true && L0 <= R0){
        ans = R0 - L0 + 1;
    }        
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	if(2*x<=y&&y%2==0&&(y-x*2)%2==0&&((y/2)-x)<=x) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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


long long id(long long R,long long C,long long r,long long c){
	if( r == 0 ) {
		return c;
	}else if( c == C ){
		return C + r;
	}else if( r == R ){
		return C + R + C - c;
	}else{
		return C + R + C + R - r;
	}
}
typedef long long ll;

bool onBorder(long long R,long long C,long long r,long long c){
	if( R == r || r == 0 ) return 1;
	if( C == c || c == 0 ) return 1;
	return 0;
}

vector< pair<long long,long long> > ol[4];

void solve(long long R, long long C, long long N, vector<vector<long long>> X, vector<vector<long long>> Y){
	for(int i = 0 ; i < N ; i++){
		auto x = X[i];
		auto y = Y[i];
		if( onBorder(R,C,x[0],y[0]) and onBorder(R,C,x[1],y[1]) ){
			ll j = id(R,C,x[0],y[0]);
			ll k = id(R,C,x[1],y[1]);
			if( j > k ) swap(j,k);
			assert(j < k );
			ol[0].push_back({j,k});
		}
	}
	bool bad = 0;
	for(int i = 0 ; i < 4 ; i++){
		sort(ol[i].begin(),ol[i].end());
		stack<long long> S;
		S.push(1e9);
		for( auto &o : ol[i]) {
			while( S.top() < o.first ){
				S.pop();
			}
			if( o.first < S.top() and S.top() < o.second ){
				bad = 1;
			}else{
				S.push(o.second);
			}
		}
	}

	if(!bad){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}




}

int main(){	
	long long N;
	long long R;
	long long C;
	scanf("%lld",&R);
	scanf("%lld",&C);
	scanf("%lld",&N);
	vector<vector<long long>> x(N-1+1,vector<long long>(2-1+1));
	vector<vector<long long>> y(N-1+1,vector<long long>(2-1+1));
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&x[i][0]);
		scanf("%lld",&y[i][0]);
		scanf("%lld",&x[i][1]);
		scanf("%lld",&y[i][1]);
	}
	solve(R, C, N, x, y);
	return 0;
}



Measured memory_bytes: 24308
#include <stdio.h>

typedef struct {
	int num;
	double time;
}athlete;

int main(void) {
	athlete a[24];
	athlete final[8];
	athlete temp;
	int block[6];
	int i, j, k;
	
	for(i=0; i<24; i++) 
		scanf("%d %lf", &a[i].num, &a[i].time);

	for(i=0;i<3;i++) {
		for(j=8*i; j<8*i+8; j++) {
			for(k=j; k<8*i+8; k++) {
				if(a[j].time > a[k].time) {
					temp = a[j];
					a[j] = a[k];
					a[k] = temp;
				}
			}
		}
		//resister 1st 2nd
		final[2*i] = a[8*i];			
		final[2*i+1] = a[8*i+1];	
	}
	
	athlete first = a[2];
	athlete second = a[3];
	
	for(i=3; i<24; i++) {
		if(i%8==0 || i%8==1) continue;
		if(a[i].time < first.time) {
			second = first;
			first = a[i];
		}
		else if(a[i].time < second.time)
			second = a[i];	
	}
	
	final[6] = first;
	final[7] = second;
	
	for(i=0; i<8; i++) 
		printf("%d %.2lf\n", final[i].num, final[i].time);
	
	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <cstdlib>


int
main(int argc, char** argv) {
    int N;
    std::cin >> N;

    std::vector<int> W(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> W[i];
        sum += W[i];
    }

    int min = 0x7fffffff;
    int s1 = 0, s2 = sum;
    for (int i = 0; i < N; i++) {
        s1 += W[i];
        s2 -= W[i];

        int tmp = std::abs(s1 - s2);
        if (min > tmp) {
            min = tmp;
        }
    }
    std::printf("%d\n", min);

    return 0;
}

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

using namespace std;

int main(void)
{
    int n;
    cin >>n;

    vector<int> a;
    vector<int> b;

    for(int i = 0; i < n+1; i++){
        int tmp;
        cin >>tmp;
        a.push_back(tmp);
    }
    for(int i = 0; i < n; i++){
        int tmp;
        cin >>tmp;
        b.push_back(tmp);
    }

    long long maxKill = 0;
    for(int r = 0; r < 2; r++){
        vector<int> ac = a;
        vector<int> bc = b;
        long long kill = 0;

        for(int i = 0; i < n; i++){
            if(ac[i] > bc[i]){
                ac[i] -= bc[i];
                kill += bc[i];
                bc[i] = 0;
            }else{
                bc[i] -= ac[i];
                kill += ac[i];
                ac[i] = 0;
                if(bc[i] > 0){
                    if(ac[i+1] > bc[i]){
                        ac[i+1] -= bc[i];
                        kill += bc[i];
                        bc[i] = 0;
                    }else{
                        bc[i] -= ac[i+1];
                        kill += ac[i+1];
                        ac[i+1] = 0;
                    }
                }
            }
        }
        maxKill = max(maxKill, kill);
        reverse(a.begin(), a.end());
        reverse(b.begin(), b.end());
    }

    printf("%lld\n", maxKill);
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    long double ans = 0;
    for(int i=0;i<n;i++){
        double x;
        string u;
        cin >> x >> u;
        if(u[0] == 'J'){
            ans += x;
        }
        else{
            ans += 380000*x;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int num,tc,hc,ts,hs,s;
  ts = hs = 0;
  char taro[101], hanako[101];
  scanf("%d", &num);
  for (int i = 0; i < num; i++) {
    tc = hc = 0;
    scanf("%s",taro);
    scanf("%s",hanako);
    for (int j = 0; taro[j] != '\0'; j++) tc++;
    for (int j = 0; hanako[j] != '\0'; j++) hc++;
    if (tc > hc) s = hc;
    else s = tc;
    for (int k = 0; k < s; k++) {
      if(taro[k] > hanako[k]) {
        ts += 3;
        break;
      }
      else if (hanako[k] > taro[k]) {
        hs += 3;
        break;
      }
      else if(k == s-1) {
        if (hc == tc) {
          ts++;
          hs++;
        }
        else if (s == hc) ts += 3;
        else if (s == tc) hs += 3;
      }
    }
  }
  printf("%d %d\n", ts, hs);
  return 0;
}



Measured memory_bytes: 2612
import sys

def comb_mod(n, r, mod):
  x = 1
  y = 1
  for i in range(r):
    x = (x * (n - i)) % mod
    y = (y * (i + 1)) % mod
    
  ans = x * pow_k(y, mod-2, mod)
  
  return ans % mod
  
  
def pow_k(x, n, mod):
  if n == 0:
    return 1

  K = 1
  while n > 1:
    if n % 2 != 0:
      K = (x * K) % mod
        
    x = (x * x) % mod

    n //= 2

  return (x * K) % mod
  

n,a,b = map(int,input().split())
mod = 10 ** 9 + 7

if n == 2:
  print(0)
  sys.exit(0)

ans = pow_k(2, n, mod) - comb_mod(n,a,mod) - comb_mod(n,b,mod) - 1

print(ans % mod)

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

int N;

int dfs(string s){
    if(stol(s)>N) return 0;

    int ret=0;
    if(count(s.begin(), s.end(), '3')>0 && count(s.begin(), s.end(), '5')>0 && count(s.begin(), s.end(), '7')>0) ret++;
    ret+=dfs(s+'3')+dfs(s+'5')+dfs(s+'7');

    return ret;

}

int main(void){
    cin >> N;
    cout << dfs("0") << endl;
}

Measured memory_bytes: 256