akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<set>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    usize n,m,k;
    cin >> n >> m >> k;
    set<usize> st;
    st.insert(n * m);
    for(usize i = 1; i <= n;/*たて*/ i++){
        for(usize j = 1; j <= m;/*よこ*/ j++){
            st.insert(i*(m - j) + (n - i) * j);
        }
    }
    cout << (st.count(k) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 16440
#
# abc088 d
#
import sys
from io import StringIO
import unittest
from collections import deque


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
..#
# ..
..."""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
....................................."""
        output = """209"""
        self.assertIO(input, output)


def resolve():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    F = [[-1]*W for _ in range(H)]

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

    Q = deque()
    Q.append([0, 0])
    F[0][0] = 1

    while Q:
        p = Q.popleft()
        x, y = p

        if x == W-1 and y == H-1:
            break

        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if nx < 0 or nx >= W or ny < 0 or ny >= H or S[ny][nx] == "#" or F[ny][nx] != -1:
                continue

            Q.append([nx, ny])
            F[ny][nx] = F[y][x] + 1

    if F[H-1][W-1] == -1:
        print(-1)
    else:
        NS = 0
        for s in S:
            NS += s.count("#")
        print(W*H-F[H-1][W-1]-NS)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

int main() {
  int N, M;
  int count, ans = 0;

  cin >> N;
  
  vector<string>s(N);

  for(int i=0; i<N; i++){
    cin >> s.at(i);
  }
  
  cin >> M;
  
  vector<string>t(M);

  for(int i=0; i<M; i++){
    cin >> t.at(i);
  }

	for (int i=0;i<s.size();i++) {
    
    count = 0;
    
    for(int j=0; j<s.size();j++){
      if(s.at(j) == s.at(i)){
        count++;
      }
    }

    for(int k=0; k<t.size();k++){
      if(t.at(k) == s.at(i)){
        count--;
      }
    }

    if(ans < count){
      ans = count;
    }
  }
 
	cout << ans << endl;
 
	return 0;
}


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

int main()
{
  int n;
  double x[10], y = 0;
  string u[10];
  
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> u[i];
    
    if (u[i] == "JPY") {
      y += x[i];
    }
    else {
      y += 380000 * x[i];
    }
  }
  
  cout << y << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (a, b, ab, x, y int) {
	return scanInt(sc), scanInt(sc), scanInt(sc), scanInt(sc), scanInt(sc)
}

func resolve(a, b, ab, x, y int) int {
	minCost := 0
	if 2*ab < a+b {
		minNum := min(x, y)
		x -= minNum
		y -= minNum
		minCost += ab * 2 * minNum
	}
	if x > 0 {
		if ab*2 < a {
			minCost += ab * 2 * x
		} else {
			minCost += a * x
		}
	}
	if y > 0 {
		if ab*2 < b {
			minCost += ab * 2 * y
		} else {
			minCost += b * y
		}
	}
	return minCost
}

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

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
n,h=map(int,input().split())
sword=[]
for i in range(n):
    a,b=map(int,input().split())
    sword.append([a,"a"])
    sword.append([b,"b"])
sword.sort()
ans=0
swordi=[0,"b"]
while(h>0):
    if(swordi[1]=="b"):
        swordi=sword.pop()
        ans+=1
        h-=swordi[0]
    else:
        attack=swordi[0]
        ans+= -(-h//attack)
        h-=attack * -(-h//attack)
print(ans)


Measured memory_bytes: 30656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  //int a = 1, b = 1, c = 1;
  string x;
  int ans = 0;
  
  cin >> x;
  if(x[0] == '1') ans++;
  if(x[1] == '1') ans++;
  if(x[2] == '1') ans++;
  
  cout << ans << endl;
}

Measured memory_bytes: 3620
#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)++)

int main(){
  int H,W;
  cin >> H >> W;
  vector<char>vec(H*W);
  REP(i,H*W)cin >> vec.at(i);
  REP(i,W+2)cout <<"#";
  cout << endl;
  REP(i,H){
    cout <<"#";
    REP(j,W)cout << vec.at(i*W+j);
    cout <<"#" << endl;
  }
  REP(i,W+2)cout << "#";
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    ll x = a[0];
    for(int i = 1; i < n; i++){
        if(i%2) x -= a[i];
        else    x += a[i];
    }
    x /= 2;
    vector<ll> ans(n);
    ans[0] = x;
    for(int i = 1; i < n; i++){
        ans[i] = a[i-1] - ans[i-1];
    }
    for(int i = 0; i < n; i++)  cout << 2*ans[i] << " \n"[i+1 == n];
    return 0;
}

Measured memory_bytes: 2816
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1


int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

int X[N][N];

void initialize(){
  int i;

  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<N*2-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}

void printBoard(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
        if(row[i]!=j) return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
if(row[i]==j){
  printf("Q");
 }
 else printf(".");
}
printf("\n");
}
}

void recursive(int i){
  int j;

  if(i==N){
    printBoard();
    return;
  }

  for(j=0;j<N;j++){
    if(NOT_FREE==col[j] || NOT_FREE==dpos[i+j] || NOT_FREE==dneg[i-j+N-1]) continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}

int main(){
  int i,j,k,r,c;

  initialize();

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j]=0;
    }
  }

  scanf("%d",&k);

  for(i=0;i<k;i++){

    scanf("%d%d",&r,&c);
    X[r][c]=1;
  }

  recursive(0);

  return 0;

}


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

using namespace std;

typedef long long ll;

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

	int n, p;
	cin >> n >> p;

	string s;
	cin >> s;

	if(p == 2 || p == 5){
        ll ans = 0;
        rep(i, n){
            if((s[i] - '0') % p == 0){
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    vector<ll> dp(p, 0);
    ll ans = 0;
    ll t = 0;
    ll d = 1;
    for(int i = n - 1; i >= 0; i--){
        t += (s[i] - '0') * d;
        t %= p;

        d *= 10;
        d %= p;
        
        ans += dp[t];
        if(t == 0) ans++; 
        dp[t]++;
    }

    cout << ans << endl;
}


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

long long g(long long a, long long b){

    if(a < b){
        long long t = a;
        a = b;
        b = t;
    }
    if(b == 0) return a;
    else return g(b, a % b);
}

int main(){

    int n; cin >> n;
    vector<long long> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];
    for(int i = 1; i < n; i++) t[0] = t[0]/g(t[0], t[i])*t[i];
    cout << t[0] << endl;
    return 0;
}

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

int main()
{
	static char S[100001];
	scanf("%s", S);
	int N = (int)strlen(S);

	static int len[100000];

	int left = 0;
	for (int i = 0; i < N;) {
		if (S[i] == 'R') {
			i++;
			continue;
		}
		// find L
		for (int k = left; k < i; k++) {
			len[k] = i - k;
		}
		while (i < N && S[i] == 'L') {
			i++;
		}
		left = i;
	}

	int right = N - 1;
	for (int i = N - 1; i >= 0;) {
		if (S[i] == 'L') {
			i--;
			continue;
		}
		// find R
		for (int k = right; k > i; k--) {
			len[k] = k - i;
		}
		while (i >= 0 && S[i] == 'R') {
			i--;
		}
		right = i;
	}

	static int ans[100000];
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') {
			int p = i + len[i];
			if (len[i] % 2 == 0) {
				ans[p]++;
			}
			else {
				ans[p - 1]++;
			}
		}
		// L
		else {
			int p = i - len[i];
			if (len[i] % 2 == 0) {
				ans[p]++;
			}
			else {
				ans[p + 1]++;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		printf("%d%c", ans[i], (i == N - 1) ? '\n' : ' ');
	}

	return 0;
}


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

using namespace std;

struct Bipartite_Matching {
  vector< vector< int > > graph;
  vector< int > dist, match, used;
  vector< bool > vv;

  Bipartite_Matching(int n, int m) {
    graph.resize(n);
    match.assign(m, -1);
    used.assign(n, -1);
  }

  void add_edge(int u, int v) {
    graph[u].push_back(v);
  }

  void bfs() {
    dist.assign(graph.size(), -1);
    queue< int > que;
    for(int i = 0; i < graph.size(); i++) {
      if(used[i] == -1) {
        que.emplace(i);
        dist[i] = 0;
      }
    }

    while(!que.empty()) {
      int a = que.front();
      que.pop();
      for(auto &b : graph[a]) {
        int c = match[b];
        if(c >= 0 && dist[c] == -1) {
          dist[c] = dist[a] + 1;
          que.emplace(c);
        }
      }
    }
  }

  bool dfs(int a) {
    vv[a] = true;
    for(auto &b : graph[a]) {
      int c = match[b];
      if(c < 0 || (!vv[c] && dist[c] == dist[a] + 1 && dfs(c))) {
        match[b] = a;
        used[a] = b;
        return (true);
      }
    }
    return (false);
  }

  int bipartite_matching() {
    int ret = 0;
    while(true) {
      bfs();
      vv.assign(graph.size(), false);
      int flow = 0;
      for(int i = 0; i < graph.size(); i++) {
        if(used[i] == -1 && dfs(i)) ++flow;
      }
      if(flow == 0) return (ret);
      ret += flow;
    }
  }
};

vector< int > h[200000];
int p[200000];
bool used[200000];

int dfs(int idx, int par) {
  if(used[idx]) return 0;
  used[idx] = true;
  int times = 1;
  p[idx] = par;
  for(auto &to : h[idx]) times += dfs(to, idx);
  return times;
}

int main() {
  int N;
  cin >> N;
  Bipartite_Matching flow(N, N);
  for(int i = 0; i < N - 1; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int x;
      cin >> x;
      --x;
      flow.add_edge(i, x);
    }
  }
  if(flow.bipartite_matching() < N - 1) {
    cout << -1 << endl;
    return 0;
  }
  for(int i = 0; i < N; i++) {
    if(flow.match[i] == -1) {
      flow.match[i] = N - 1;
      flow.used[N - 1] = i;
    }
  }

  for(int i = 0; i < N - 1; i++) {
    for(auto &to : flow.graph[i]) {
      if(flow.match[to] != i) {
        h[flow.match[to]].push_back(i);
      }
    }
  }

  if(dfs(N - 1, -1) < N) {
    cout << -1 << endl;
    return 0;
  }

  for(int i = 0; i < N - 1; i++) {
    cout << flow.used[i] + 1 << " " << flow.used[p[i]] + 1 << endl;
  }

}







Measured memory_bytes: 20196
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_map>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<29;
const double EPS = 1e-8;
const int MOD = 1000000007;

class BIT2D {
	int h, w;
	vector<vi> vs;
public:
	BIT2D(int W, int H): vs(H, vi(W, -INF)){
		h = H;
		w = W;
	}
	//O(log n)
	void update(int X, int Y, int a) {
		for(int y = Y; y < h; y |= y + 1)
			for(int x = X; x < w; x |= x + 1) vs[y][x] = max(vs[y][x], a);
	}
	//[s,t)	O(log n)
	int query(int tx, int ty) {
		int res = -INF;
		for(int y = ty - 1; y >= 0; y = (y & (y + 1)) - 1)
			for(int x = tx - 1; x >= 0; x = (x & (x + 1)) - 1){
				res = max(res, vs[y][x]);
			}
		return res;
	}
};

int N, V, Xl, Xr;

struct Mogura{
	ll x, y, p;
	Mogura(int X, int T, int P){
		x = T-X;
		y = T+X;
		p = P;
	}
	Mogura(){}
	bool operator <(const Mogura &opp) const {
		return x != opp.x ? x < opp.x : y < opp.y;
	}
};

main(){
	scanf("%d%d%d%d", &N, &V, &Xl, &Xr);
	vector<Mogura> mog;
	vector<int> ItoP;
	ItoP.push_back(Xl);
	ItoP.push_back(Xr);
	REP(i, N){
		int x, t, p;
		scanf("%d%d%d", &x, &t, &p);
		mog.emplace_back(x, V*t, p);
		ItoP.push_back(mog.back().y);
	}
	sort(ALL(mog));
	sort(ALL(ItoP));
	UNIQUE(ItoP);
	int n = ItoP.size();
	unordered_map<int, int> PtoI;
	REP(i, n) PtoI[ItoP[i]] = i;
	BIT2D bit(n, n);
	bit.update(PtoI[Xl], PtoI[Xr], 0);
	REP(i, N){
		int x = PtoI[mog[i].y];
		int p = mog[i].p;
		RREP(j, n){
			if(j > x && -Xl <= mog[i].x){
				// 左手が x 右手が j
				int my = bit.query(x+1, j+1);
				bit.update(x, j, my + p);
			}else if(j <= x && -Xr <= mog[i].x){
				// 左手が j 右手が x
				int mx = bit.query(j+1, x+1);
				bit.update(j, x, mx + p);
			}
		}
	}
	cout << bit.query(n, n) << endl;
	return 0;
}

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

//Differential Pulse Code Modulation
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int INF = 255*255*20000;
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			int[] x = new int[n], c = new int[m];
			for(int i=0;i<m;i++)c[i]=sc.nextInt();
			for(int i=0;i<n;i++)x[i]=sc.nextInt();
			int[] dp = new int[256];
			Arrays.fill(dp, INF);
			dp[128] = 0;
			for(int i=0;i<n;i++){
				int[] next = new int[256];
				Arrays.fill(next, INF);
				for(int y=0;y<256;y++){
					if(dp[y]==INF)continue;
					for(int j=0;j<m;j++){
						int nx = y+c[j];
						if(nx<0)nx=0;
						if(255<nx)nx=255;
						int v = dp[y]+(x[i]-nx)*(x[i]-nx);
						next[nx] = Math.min(next[nx], v);
					}
				}
				dp = next;
			}
			int res = INF;
			for(int i=0;i<256;i++)res = Math.min(res, dp[i]);
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

#define READ() 	    freopen("in.txt","r",stdin)
#define WRITE()     freopen("out.txt","w",stdout)
#define sf(n) 	    scanf("%d",&n)
#define sl(x)       scanf("%I64d",&x)
#define lsf(n) 	    scanf("%lld", &n)
#define pb(n) 	    push_back(n)
#define mem(x,y)    memset(x,y,sizeof(x))
#define D(x)      	cout << #x << " = " << x << endl
#define CHKRTE		assert(false)
#define YOLO        cout << "YOLO" << endl
#define NL			printf("\n")
#define EPS 	    1e-10
#define INF         INT_MAX
#define MAX         INT_MAX
#define MOD         1000000007
#define LL          long long
#define endl        "\n"
#define pi          2.0*acos(0.0)
#define cnd         tree[idx]
#define lnd         tree[left]
#define rnd         tree[right]
#define callLeft    left,st,mid
#define callRight   right,mid+1,ed

bool mulIsOv(LL x,LL y)
{
    LL ret = x*y;
    if(ret/x != y)return true;
    if(ret/y != x)return true;
    return false;
}

int main()
{
//	ios_base::sync_with_stdio(false);
//    cin.tie(0); /// use "\n" instead of endl

/**
#ifndef ONLINE_JUDGE
    READ();
    WRITE();
#endif
**/

#ifdef JAMILPC
	READ();
//	WRITE();

//    int t;
//    cin >> t;
//    while(t--)
//    {
#endif

    LL x,y;
    cin >> x >> y;

    int iCnt = 1;
    x *= 2LL;
    while(1)
    {
        if(x > y || mulIsOv(x,2LL))break;
        iCnt++;
        x *= 2LL;
    }

    cout << iCnt << endl;

#ifdef JAMILPC
//	}
#endif


    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	float sum = 0;
	float s = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> s;
		sum = sum + 1 / s;
	}
	cout << 1 / sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int seen[20][20];

int main(void) {
  int h,w;
  cin >> h >> w;
  vs s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(i,h)rep(j,w){
    if(s[i][j] == '#') continue;
    int kamo = 0;
    queue<pair<int,int>> Q;
    Q.push(make_pair(i,j));
    rep(k,20)rep(l,20){
      seen[k][l] = -1;
    }
    seen[i][j] = 0;
    while(!Q.empty()){
      int p = Q.front().first;
      int q = Q.front().second;
      Q.pop();
      rep(k,4){
        int ey = p + dy[k];
        int ex = q + dx[k];
        if(ey < 0 || ex < 0 || ey >= h || ex >= w) continue;
        if(s[ey][ex] == '.' && seen[ey][ex] == -1){
          seen[ey][ex] = seen[p][q] + 1;
          Q.push(make_pair(ey,ex));
          
          kamo = max(kamo,seen[ey][ex]);
          //cout << kamo << endl;
        }
      }
    }
    ans = max(kamo,ans);
  }
  cout << ans << endl;
                 
              
          
  
  
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	dp := make([]int, N+1)
	dp[0] = 1
	dp[1] = 1
	for i := 2; i <= N; i++ {
		dp[i] = dp[i-1] + dp[i-2]
	}

	fmt.Fprintln(wtr, dp[N])
	wtr.Flush()
}



Measured memory_bytes: 1120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

vector<pair<ll, ll>> path[100001];
bool used[100001];
ll x[100001];

bool dfs(ll n){
    used[n] = true;
    fore(a, path[n]){
        if(used[a.first]){
            if(x[a.first] != x[n] + a.second){
                return false;
            }
        }else{
            x[a.first] = x[n] + a.second;
            if(!dfs(a.first)){
                return false;
            }
        }
    }
    return true;
}

int main(void){
    ll n, m;
    cin >> n >> m;

    rep(i, 0, m){
        ll tmpl, tmpr, tmpd;
        cin >> tmpl >> tmpr >> tmpd;
        tmpl--;
        tmpr--;
        path[tmpl].push_back((pair<ll, ll>){tmpr, tmpd});
        path[tmpr].push_back((pair<ll,ll>){tmpl, -tmpd});
    }

    rep(i, 0, n){
        if(!used[i]){
            if(!dfs(i)){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


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


int N;
int main(){
	cin >> N;
	int a[N];
	int mina = 1000000009, maxa = 0;
	for(int i=0;i<N;i++){
		cin >> a[i];
		if(mina > a[i])mina = a[i];
		if(maxa < a[i])maxa = a[i];
	}
	cout << maxa - mina << endl;
	return 0;
}


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

bool prime(int n){
	if(n <= 2)return n == 2;
	if(!(n & 1))return 0;
	int x = sqrt(n);
	for(int d=3;d <= x;d+=2){
		if(n%d == 0)return false;
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	while(!prime(n))n++;
	cout << n << '\n';
	return 0;
}

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

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	int maxl = 0, minr = 100005;
	for (int i = 0; i < m; ++i) {
		int l, r; cin >> l >> r;
		maxl = max(maxl, l);
		minr = min(minr, r);
	}
	if (maxl <= minr)cout << minr - maxl + 1 << endl;
	else cout << 0;

	return 0;
}


Measured memory_bytes: 256
a = int(input())
k = a
for i  in range(a+1):
  al = 0
  t = i
  while t > 0:
    al += t%6
    t //=6
  t = a - i
  while t > 0:
    al += t%9
    t //=9
  if al < k:
    k = al

print(k)


Measured memory_bytes: 40812
#include<cstdio>
#include<cmath>

int n,l,min=9999999,pos,sum,i;

int main()
{
	scanf("%d%d",&n,&l);
	for(i=1;i<=n;i++)
		if(fabs(l+i-1)<min)
		{
			min=fabs(l+i-1);
			pos=i;
		}
	for(i=1;i<=n;i++)
		if(i!=pos)sum+=l+i-1;
	printf("%d",sum);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

long long getAllPattern(int n) {
	if (n == 0)return 1;
	else if (n == 1)return 1;
	else if (n == 2)return 2;
	else {
		long long num1 = 1;
		long long num2 = 2;
		long long ans = 0;
		rep(i, n - 2) {
			ans = (num1 + num2) % MOD;
			num1 = num2;
			num2 = ans;
		}
		return ans;
	}
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> a(M);
	rep(i, M) {
		cin >> a[i];
		if (i > 0 && a[i] == a[i - 1] + 1) {
			cout << 0;
			return 0;
		}
	}

	long long ans = 1;
	int now = 0;
	rep(i, M) {
		ans *= getAllPattern(a[i] - 1 - now);
		ans %= MOD;
		now = a[i] + 1;
	}
	ans *= getAllPattern(N - now);
	ans %= MOD;
	cout << ans;

}

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

int main() {
  int X;
  
  cin >> X;
  
  int thou = (X / 500) * 1000;
  
  int amari = X % 500;
  
  int fiv = (amari / 5) * 5;
  
  cout << thou + fiv << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
int32_t main(){
  int n,m;cin>>n>>m;
  string s,t;cin>>s>>t;
  int x=(n*m)/__gcd(n,m);
  //now check if first
  map<int,char>M;
  for(int i=0;i<n;++i){
    M[i*m+1]=s[i];
  }
  for(int i=0;i<m;++i){
    char ch=t[i];
    if(M.find(i*n+1)==M.end())continue;
    else if(M[i*n+1]!=ch){puts("-1");return 0;}
  }
  cout<<x<<"\n";
  return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

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

void d_err() {
    cerr << endl;
}

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

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

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

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

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


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

    ll K; cin >> K;

    ll ans = 0;
    REP(i, 1e7) {
        ans = (ans * 10 + 7) % K;
        if (ans == 0) {
            print(i + 1);
            return 0;
        }
    }

    print(-1);
    
}


Measured memory_bytes: 3652
S=str(input())

a=int(S[0]+S[1])
b=int(S[2]+S[3])



if 1<=a and a<=12:
    if 1<=b and b<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1<=b and b<=12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
line = input()
numbers = line.split(" ")
n = int(numbers[0])
max = int(numbers[1])

line = input()
lList = line.split(" ")
d, count = 0, 1
for i in range(n):
  d += int(lList[i])
  if d <= max:
    count += 1
  
print(count)

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

int main(){
    int n, k;
    cin >> n >> k;
    vector a(n, 0);
    for(auto& i : a) cin >> i;
    nth_element(a.begin(), a.begin() + k, a.end());
    cout << reduce(a.begin(), a.begin() + k) << endl;
}

Measured memory_bytes: 3600
K=int(input())
 
from collections import deque
query=deque()
 
for i in range(1,10):
    query.append(i)
cnt=0

while cnt<K:
    num=query.popleft()
    cnt +=1
    one=num%10
    if one == 0:
        query.append(num*10+one )
        query.append(num*10+(one+1))
    if one!=0 and one!=9:
        query.append(num*10+(one-1))
        query.append(num*10+one)
        query.append(num*10+(one+1))
    if one == 9:
        query.append(num*10+(one-1))
        query.append(num*10+one)

print(num)

Measured memory_bytes: 12396
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>


int main() {
	int n; std::cin >> n;
	std::vector<long long int> weights(n); for (auto& w : weights) std::cin >> w;
	std::vector<long long int> sum_weights(n + 1, 0);
	for (auto i = 0; i < n; ++i) sum_weights[i + 1] = sum_weights[i] + weights[i];
	std::vector<std::vector<int>> cut(n, std::vector<int>(n));
	std::vector<std::vector<long long int>> memo(n, std::vector<long long int>(n, 0));
	for (auto i = 0; i + 1 < n; ++i) {
		cut[i][i + 1] = i;
		memo[i][i + 1] = sum_weights[i + 2] - sum_weights[i];
	}
	for (auto d = 2; d < n; ++d) {
		for (auto i = 0; i + d < n; ++i) {
			const auto j = i + d;
			int min_idx{ -1 };
			long long int min{ LLONG_MAX };
			for (int k{ cut[i][j - 1] }; k <= cut[i + 1][j]; ++k) {
				const auto w = memo[i][k] + memo[k + 1][j];
				if (min > w) {
					min = w;
					min_idx = k;
				}
			}
			memo[i][j] = min + sum_weights[j + 1] - sum_weights[i];
			cut[i][j] = min_idx;
		}
	}
	std::cout << memo[0][n - 1] << '\n';
}



Measured memory_bytes: 190844
#include"iostream"
#include"vector"

int main()
{
  std::vector<int> S;
  std::vector<int> T;
  int buf;
  int n,q;
  int i,j;
  int left,mid,right;
  int C=0;
  std::cin>>n;
  std::cin>>buf;
  S.push_back(buf);
  for(i=1;i<n;i++)
    {
      std::cin>>buf;
      if(S[i-1]!=buf)
        {
          S.push_back(buf);
        }
    }
  std::cin>>q;
  for(i=0;i<q;i++)
    {
      std::cin>>buf;
      T.push_back(buf);
    }
  for(i=0;i<T.size();i++)
    {
      left=0;
      right=S.size();
      while(left<right)
        {
          mid=(left+right)/2;
          if(T[i]==S[mid])
            {
              C++;
              S.erase(S.begin()+mid);
              break;
            }
          else if(T[i]<S[mid])
            {
              right=mid;
            }
          else
            {
              left=mid+1;
            }
        }
    }
  std::cout<<C<<std::endl;
  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf=1e5+9,mod=1e9+7;
ll dp[inf][2],n;
vector<int> v[inf];

void dfs(int node,int par){

    dp[node][0]=dp[node][1]=1;
    for(auto o:v[node]){
        if(o==par)
            continue;
        dfs(o,node);
        dp[node][0]=(dp[node][0]*dp[o][1])%mod;
        dp[node][1]=(dp[node][1]*(dp[o][0]+dp[o][1]))%mod;
    }
}

int main(){

    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        v[b].push_back(a);
        v[a].push_back(b);
    }
    dfs(1,0);
    cout<<(dp[1][0]+dp[1][1])%mod;
}


Measured memory_bytes: 14208
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;





int main()
{
    int x,y;scanf("%d%d",&x,&y);
    int ans=0;
    if (x<=3){
        ans += (4-x);
    }
    if (y<=3){
        ans+=(4-y);
    }
    if (x==1 && y==1)
        ans+=4;
    ans*=100000;
    printf("%d",ans);


}



Measured memory_bytes: 128
X = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)

    return divisors
N = X -1
while(1):
    N +=1
    com = make_divisors(N)
    if len(com) == 2:
        ans = N
        break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

int calc(int x){
  int c=(x+1)/2%2;
  if(x%2==0)return x^c;
  return c;
}

signed main(){
  int a,b;
  cin>>a>>b;
  a--;
  cout<<(calc(a)^calc(b))<<endl;  

  return 0;
}



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

long gcd(long a,long b){
  if(b == 0){
    return a;
  }
  return gcd(b,a % b);
}

int main(){
  long n;
  cin >> n;
  long t[n];
  for(long i = 0;i < n;i++){
    cin >> t[i];
  }
  for(long i = 0;i < n-1;i++){
    long g = gcd(t[i],t[i+1]);
    t[i+1] = (t[i]/g)*t[i+1];
    //cout << t[i+1] << " "  << g << endl;
  }
  cout << t[n-1] << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
N, *L = map(int, open(0).read().split())
dic = [[] for i in range(N)]
ans = [-1]*N
cnt = [0]*N
hq = []
for a,b in zip(*[iter(L[:2*(N-1)])]*2):
  a -= 1
  b -= 1
  dic[a] += [b]
  dic[b] += [a]
  cnt[a] += 1
  cnt[b] += 1
C = L[2*(N-1):]
C.sort()
for i in range(N):
  heappush(hq,(cnt[i],i))
arg = 0
m = 0
while True:
  c, i = heappop(hq)
  if ans[i]!=-1:
    continue
  m += C[arg]*cnt[i]
  ans[i] = C[arg]
  arg += 1
  if arg==N:
    break
  for v in dic[i]:
    cnt[v] -= 1
    heappush(hq,(cnt[v],v))
print(m)
print(*ans)

Measured memory_bytes: 7948
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
	char s1[1001];
	char s2[] = " .\n";
	char w[11];
	char end[] = "END_OF_TEXT";
	int i;
	char *tok;
	char *tp;
	int cnt = 0;

	scanf("%s", w);

	for(i = 0;i< sizeof(w)/sizeof(w[0]);i++){
		w[i] = tolower(w[i]);
	}

	while(1){
		scanf("%s", s1);

		tok = strtok( s1, s2);

		while(tok != NULL){
			if(strcmp(end,tok) == 0){
				printf("%d\n", cnt);
				return 0;
			}

			tp = tok;

			while(*tok != '\0'){
				*tok = tolower(*tok);
				++tok;
			}

			tok = tp;

			if(strcmp(w,tok) == 0){
				cnt++;
			}
			tok = strtok(NULL,s2);
		}
	}
	return 0;
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin>>n;
    if((n%5)!=0) n=(n/5)*5;
    n+=(500*(n/500));
    cout<<n<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

int numD(int x) {
  int ans = 0;
  while (x % 100 == 0) {
    ans++;
    x/=100;
  }
  return ans;
}

VI D[3];

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int d, n; cin >> d >> n;

  for (int i = 1; i < 1e7; ++i) {
    int dd = numD(i);
    if (dd <= 2) {
      D[dd].push_back(i);
    }
  }
  assert(D[d].size() >= n);
  cout << D[d][n-1] << nl;
  return 0;
}



Measured memory_bytes: 68704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
        int n; cin>>n;
        vector<int> a(n);
        rep(i,0,n) cin>>a[i];
        sort(all(a));
        cout<<a[n-1]-a[0]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
vector<int> v;
string s,n="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?",m=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ",l[32]={"101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
int main(){
	while(getline(cin,s)){
		v.clear();
		for(int i=0;i<s.size();i++){
			int p=0;while(m[p]!=s[i])p++;
			for(int j=0;j<l[p].size();j++)v.push_back(l[p][j]-'0');
		}
		while(v.size()%5)v.push_back(0);
		for(int i=0;i<v.size();i+=5){
			int cnt=0;
			for(int j=0;j<5;j++)cnt*=2,cnt+=v[i+j];
			cout<<n[cnt];
		}cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  // 二分探索
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i, N) cin >> L[i];
  sort(L.begin(), L.end());
  ll ans = 0;
  rep(i, N) for (int j = i+1; j < N; j++) {
    int index = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
    ans += index - 1 - j;
  }
  cout << ans << '\n'; 
  return 0;
}

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

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

  int ans = 0;
  int cur = 1;
  REP(i, n) {
    int tmp;
    cin >> tmp;

    if(cur == tmp) {
      cur++;
    } else {
      ans++;
    }
  }

  if(cur == 1) {
    ans = -1;
  }

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


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<pi> w(n);
    rep(i,n){
        int a,b; cin>>a>>b;
        w[i] = mp(b,a);
    }
    sort(all(w));
    ll now=0;
    rep(i,n){
        now+=w[i].se;
        if (now>w[i].fi){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 1792
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    W,a,b = (int(_) for _ in input().split())
    if(a>b):
        tmp = a
        a = b
        b = tmp
        
    if b-(a+W) <= 0:
        ans = 0
    else:
        ans = b-(a+W)
    print(ans)
    
if __name__ == '__main__':
    main()


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

int flag[1000008];
int dp[1000008];
int main() {

    int n;
    cin >> n;

    dp[1] = flag[n] = n;
    for(int i = 2; i < 1000008; i++) {

        if(dp[i-1] % 2 == 0) dp[i] = dp[i-1] / 2;
        else dp[i] = 3 * dp[i-1] + 1;

        if(flag[dp[i]]) {

            cout << i << endl;
            return 0;
        }

        else flag[dp[i]] = 1;
    }


}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main(){
	ll n,w,a,b;
  	cin>>n>>w;
  	vector<ll> val,wgt;
  	for(int i=0;i<n;i++){
    	cin>>a>>b;
      	wgt.pb(a);
      	val.pb(b);
    }
  	ll p[w+1][n+1];
    memset(p,0,sizeof(p));
    for(int i=1;i<=w;i++){
        for(int j=1;j<=n;j++){
            if(wgt[j-1]<=i)
                p[i][j]=max(p[i][j-1],val[j-1]+p[i-wgt[j-1]][j-1]);
            else
                p[i][j]=p[i][j-1];
        }
    }
    cout<<p[w][n]<<endl;
  	return 0;
}


Measured memory_bytes: 82356
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
void gg(){puts("No"),exit(0);}

int s[MAXN],n;
int lowbit(int x){return x&-x;}
void modify(int x,int c){for(;x<=n;x+=lowbit(x))s[x]+=c;}
int qry(int x){int ret=0;for(;x>=1;x-=lowbit(x))ret+=s[x];return ret;}
int a[4][MAXN],cal[MAXN],num[5];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[1][i]=read();
	for(int i=1;i<=n;i++)a[2][i]=read();
	for(int i=1;i<=n;i++)a[3][i]=read();
	for(int i=1;i<=n;i++)
	{
		if(((a[2][i]-1)&1)^(i&1))gg();
		if(!(a[1][i]%3)&&a[2][i]==a[1][i]-1&&a[3][i]==a[2][i]-1)cal[i]=-(a[2][i]+1)/3;
		else if(!(a[3][i]%3)&&a[2][i]==a[3][i]-1&&a[1][i]==a[2][i]-1)cal[i]=(a[2][i]+1)/3;
		else gg();
	}
	for(int i=1;i<=n;i+=2)if(cal[i]<0)cal[i]=-cal[i],num[0]^=1;
	for(int i=2;i<=n;i+=2)if(cal[i]<0)cal[i]=-cal[i],num[1]^=1;
	
	for(int i=1;i<=n;i+=2)
	{
		if((qry(n)-qry(cal[i]))&1)num[1]^=1;
		modify(cal[i],1);
	}memset(s,0,sizeof(s));
	for(int i=2;i<=n;i+=2)
	{
		if((qry(n)-qry(cal[i]))&1)num[0]^=1;
		modify(cal[i],1);
	}
	if(!num[0]&&!num[1])puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
#include<math.h>
int m=1000000007;
int main()
{
    long long int n,k,a[200005],c,i,b[200005],j;long long max,min,s=0;
    scanf("%lld %lld",&n,&k);
    a[0]=0;b[n]=n;
    for(i=1;i<=200002;i++)
    {
        a[i]=(a[i-1]+i);
      //a[i]%=m;
    }


    for(i=k;i<=(n);i++)
    {
        min=a[i-1];
        max=a[n]-a[n-i];
        s=s+(max-min+1);
        s%=m;
    }

        printf("%lld",s%m+1);

}


Measured memory_bytes: 3296
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		int a = 0;
		for(var i=0;i<4;i++){
			if(str.Substring(i,1)=="+"){
				a += 1;
			}else {
				a -= 1;
			}
		}
		Console.WriteLine(a);
	}
}

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

int main()
{
    long long n,m,k;
    cin >> n >> m >> k;
    vector<long long> a(n) ,b(m),aa(n + 1, 0), bb(m + 1, 0);

    long long suma = 0,sumb= 0;

    for (long long i = 0; i < n; i++)
    {
        cin >> a[i];
        aa[i + 1] = aa[i] + a[i];
        suma += a[i];
    }
    for (long long i = 0; i < m; i++)
    {
        cin >> b[i];
        bb[i + 1] = bb[i] + b[i];
        sumb += b[i];
    }

    long long ans = 0,ia = 0,ib = 0;
    if(sumb + suma <= k)
    {
        ans = n + m;
    }
    else
    {
        
        for (ia = 0; ia <= n; ia++)
        {
            if(aa[ia] > k)break;
            ib = upper_bound(bb.begin(),bb.end(),k - aa[ia]) - bb.begin();
            if(ib > 0)ib--;
            if(ans < ia + ib)ans = ia + ib;
        }
        
    }
    


    cout << ans << endl;
}


Measured memory_bytes: 9540
#include <stdio.h>
int main() {
	int n, ans = 0, x, y, m;
	int a[210] = {}, b[210] = {};
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &x, &y);
		a[x+1] = y+1;
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &x, &y);
		b[x+1] = y+1;
	}
	for (int i = 1; i <= 2*n; i++)
	{
		if (b[i] > 0)
		{
			m = 0;
			for (int j = 1; j < i; j++)
			{
				if (a[j] > 0 && a[j] < b[i] && a[j]>a[m])
					m = j;
			}
			if (m != 0)
			{
				a[m] = 0;
				ans++;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

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

using namespace std;

typedef long long ll;

const int MAXN = 2031;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    bool ok = true;
    if (n % 2 == 1) {
        cout << "No";
        return 0;
    }
    for (int i = 0; i < n / 2; i++)
    {
        if (s[i] != s[n / 2 + i])
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 14.07.2019 15:43:48       
**/
#include <bits/stdc++.h>

using namespace std;

vector<long long> a;
int n;

long long Go(int from, int to, long long ca, long long cb) {
  if (to - from == 1) {
    return 0;
  }
  long long best;
  best = (long long) 1e18;
  for (int i = from + 1; i < to; i++) {
    long long cur = a[i] * (ca + cb) + Go(from, i, ca, ca + cb) + Go(i, to, ca + cb, cb);
    best = min(best, cur);
  }
  return best;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << Go(0, n - 1, 1, 1) + a[0] + a[n - 1] << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		int x = (int) Math.ceil((a + b) / 2);
		System.out.println(x);
	}

}



Measured memory_bytes: 23124
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    in_arr(int, a, n);
    int sum = accumulate(a.begin(), a.end(), 0);
    if(sum % 10 != 0){
        cout << sum << endl;
    }else if(all_of(a.begin(), a.end(), [](int a){ return a % 10 == 0; })){
        cout << 0 << endl;
    }else{
        sort(a.begin(), a.end());
        repi(i, a){
            if(*i % 10 != 0){
                cout << sum - *i << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256