akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll n, t, a; cin >> n >> t >> a;
    ll ans = -1;
    double minv = 999999999;

    rep(i, n){
        ll x; cin >> x;
        double tmp = abs(a-(t-(x*0.006)));
        if(minv > tmp){
            minv = tmp;
            ans = i+1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
void main()
{
    int n = readln.chomp.to!int;

    int[] c = new int[n-1], s = new int[n-1], f = new int[n-1];
    foreach (i; 0 .. n-1)
    {
        int[] tmp = readln.split.to!(int[]);
        c[i] = tmp[0], s[i] = tmp[1], f[i] = tmp[2];
    }

    int[] time = new int[n];
    foreach (i; 0 .. n-1)
    {
        foreach (j; i .. n-1)
        {
            if (time[i] < s[j])
            {
                time[i] = s[j];
            }
            else
            {
                int m = (time[i] - s[j] + f[j] - 1) / f[j];
                time[i] = s[j] + f[j] * m;
            }

            time[i] += c[j];
        }
    }

    foreach (x; time)
    {
        x.writeln;
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 380
import java.util.Scanner;
public class Main {
    public  static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }
        if(a>b){
            System.out.println("a > b");
        }
        if(a==b) {
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26176
#include<stdio.h>

static const int N = 100;

int main(){
  int M[N][N];
  int n, u, k, v, i=0, j=0;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j] = 0;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      if(j!=0){
        printf(" ");
      }
        printf("%d",M[i][j]);
      }
      printf("\n");
    }

    return 0;
  }

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

using namespace std;

int main()
{
    int N;
    long X;
    cin >> N;   cin >> X;
    vector<int> m(N);
    int cnt = N;

    //残りの量を計算
    for (int i = 0; i < N; i++){
        cin >> m.at(i);
        X -= m.at(i);
    }

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


    while (X >= m.at(0)){
        cnt++;
        X -= m.at(0);
    }

    cout << cnt << endl;
}

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

const int dh[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dw[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H);
    for(int h = 0; h < H; ++h) cin >> S[h];
    
    for(int h = 0; h < H; ++h) {
        for(int w = 0; w < W; ++w) {
            if(S[h][w] == '#') continue;
            int count = 0;
            for(int dir = 0; dir < 8; ++dir) {
                int nh = h + dh[dir];
                int nw = w + dw[dir];
                if(nh < 0 || H <= nh || nw < 0 || W <= nw) continue;
                if(S[nh][nw] == '#') ++count;
            }
            S[h][w] = '0' + count;
        }
    }
    for(int h = 0; h < H; ++h) cout << S[h] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
//static const ll MOD = 1;
static const ll MAX_L = (ll)1 << 62;

static const ll FACT_SIZE = 1000000;

int main() {
	ll n; cin >> n;
	string s; cin >> s;
	string t = s;

	ll cnt = 0;
	rep(i, 0, s.size()) {
		if (s[i] == '(') {
			cnt++;
		}
		else if (s[i] == ')') {
			cnt--;
		}
		if (cnt < 0) {
			t = '(' + t;
			cnt++;
		}
	}

	rep(i, 0, cnt) {
		t = t + ')';
	}

	cout << t << endl;

	return 0;
}

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

#define ll long long
#define db double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ino freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vi vector <int>
#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))

#define todegree(rad) rad*(180.0/pi)
#define isnttriangle(a,b,c) (a+b<c||a+c<b||b+c<a)
#define pi acos(-1)
#define siz 1000


int main()
{
    int N,a,b,c;
    db k,m,num;
    cin>>N;
    num=N*1.0;
    bool ok=false;
    a=floor(num/1.08);
    if(floor(a*1.08)==N)
    {
        ok=true;
        cout<<a<<"\n";
    }
    a=ceil(num/1.08);
    if(floor(a*1.08)==N)
    {
        if(!ok)
        cout<<a<<"\n";
        ok=true;
    }
    if(!ok) cout<<":(\n";

    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

/**
 * @author yadavd5
 *
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long  a = sc.nextLong();
		long  b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long first= a*c;
		long  second = a*d;
		long third = b*c;
		long fourth = b*d;
		long firstmax = Math.max(first, second);
		long secondman = Math.max(third, fourth);
		System.out.println(Math.max(firstmax, secondman));
	}

}

Measured memory_bytes: 35644
#include<iostream>
#include<unordered_map>
#include<string>
#include<algorithm>
using namespace std;

unordered_map<string, int> bluemap;

// N blue cards   M red cards
//Ti               Si
int n, m;
int main()
{
	cin >> n;
	string a;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (bluemap.count(a))
		{
			bluemap[a]++;
		}
		else
		{
			bluemap[a] = 1;
		}		
	}
	int maxn = -1000;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> a;
		if (bluemap.count(a))
		{
			bluemap[a]--;
		}
		else
		{
			bluemap[a] = -1;
		}
	}
	for(auto var : bluemap)
	{
		maxn = max(var.second, maxn);
	}
	if (maxn < 0)maxn = 0;
	cout << maxn;
	return 0;
}

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

const int m=1000005;
int main(){
  int x;
  cin >> x;
  int y = ceil(x/1.08);
  if(int(y*1.08)==x) cout << y;
  else cout << ":(";

  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,int>um;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s = "AC";
  um[s]=0;
  s="WA";
  um[s]=0;
  s="TLE";
  um[s]=0;
  s="RE";
  um[s]=0;
  
  int t;
  cin>>t;
  for(int i=0;i<t;i++){
  	cin>>s;
    um[s]++;
  }
  cout<<"AC x "<<um["AC"]<<'\n';
  cout<<"WA x "<<um["WA"]<<'\n';
  cout<<"TLE x "<<um["TLE"]<<'\n';
  cout<<"RE x "<<um["RE"]<<'\n';
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
  string S, T;
  map<char,char> dict;
  map<char,char> dict2;
  int flg = 0;
  cin >> S >> T;
  for (int i = 0; i < S.size(); i++){
    decltype(dict)::iterator itr = dict.find(S[i]);
    if (itr != dict.end()){
      if (dict[S[i]] != T[i]){
        flg = 1;
      }
    }else{
      dict[S[i]] = T[i];
    }
  }

  for (int i = 0; i < T.size(); i++){
    decltype(dict2)::iterator itr = dict2.find(T[i]);
    if (itr != dict2.end()){
      if (dict2[T[i]] != S[i]){
        flg = 1;
      }
    }else{
      dict2[T[i]] = S[i];
    }
  }

  for (int i = 0; i < S.size(); i++){
    if (dict[dict[S[i]]] == dict[S[i]] && S[i] != T[i]){
      flg = 1;
    }
  }
  
  if (flg == 1){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
}


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

int main(){
  int n; cin >> n;
  int ret=0;
  int m=n+1;
  rep(i, n){
    int p; cin >> p;
    m=min(p, m);
    if(p<=m) ret++;
  }
  cout << ret;

}

Measured memory_bytes: 256
#include <queue>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge {
	int to, cost;
};
struct state {
	int pos, cost, c;
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost < s2.cost;
}
int N, M, T, s, g, cap, a[3009]; string s1, s2, s3[3009], s4[3009];
int main() {
	while (cin >> M >> T >> cap, M) {
		vector<string> l;
		cin >> s1 >> s2;
		l.push_back(s1);
		l.push_back(s2);
		for (int i = 0; i < M; i++) {
			cin >> s3[i] >> s4[i] >> a[i];
			l.push_back(s3[i]);
			l.push_back(s4[i]);
		}
		sort(l.begin(), l.end());
		l.erase(unique(l.begin(), l.end()), l.end());
		N = l.size();
		s = lower_bound(l.begin(), l.end(), s1) - l.begin();
		g = lower_bound(l.begin(), l.end(), s2) - l.begin();
		vector<vector<edge> > G(N);
		for (int i = 0; i < M; i++) {
			int p1 = lower_bound(l.begin(), l.end(), s3[i]) - l.begin();
			int p2 = lower_bound(l.begin(), l.end(), s4[i]) - l.begin();
			G[p1].push_back(edge{ p2, a[i] });
			G[p2].push_back(edge{ p1, a[i] });
		}
		vector<bool> isok(N);
		for (int i = 0; i < T; i++) {
			cin >> s1;
			isok[lower_bound(l.begin(), l.end(), s1) - l.begin()] = true;
		}
		cap *= 10;
		vector<vector<int> > dist(N, vector<int>(cap + 1, 999999999)); dist[s][cap] = 0;
		priority_queue<state> que; que.push(state{ s, 0, cap });
		while (!que.empty()) {
			state u = que.top(); que.pop();
			for (edge e : G[u.pos]) {
				int f = u.c - e.cost;
				if (f < 0) continue;
				if (isok[e.to]) f = cap;
				if (dist[e.to][f] > dist[u.pos][u.c] + e.cost) {
					dist[e.to][f] = dist[u.pos][u.c] + e.cost;
					que.push(state{ e.to, -dist[e.to][f], f });
				}
			}
		}
		int ret = *min_element(dist[g].begin(), dist[g].end());
		cout << (ret == 999999999 ? -1 : ret) << endl;
	}
	return 0;
}

Measured memory_bytes: 51800
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return

#B
def B():
    a,b = LI()
    for i in range(10000):
        if 1+i*a-i >= b:
            print(i)
            return
    return

#C
def C():
    n = I()
    a = LI()
    ans = 0
    r = 1
    for l in range(n):
        if r == l:
            r += 1
        while r < n and a[r-1] >= a[r]:
            r += 1
        ans = max(ans, r-l-1)
    print(ans)
    return

#D
def D():
    n = I()
    print(n*(n-1)>>1)
    return

#E
def E():
    def dfs(x,p):
        if dp[x] != None:
            return dp[x]
        dp[x] = -1
        for y in v[x]:
            if p[y]:
                dp[x] = float("inf")
                break
            p[y] = 1
            dp[x] = max(dp[x], dfs(y,p)+1)
            p[y] = 0
        return dp[x]

    n = I()
    a = LIR(n)
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1
    m = n*(n-1)
    v = [[] for i in range(m)]
    for i in range(n):
        p = n*min(i, a[i][0]) + max(i, a[i][0])
        for j in range(n-2):
            p_ = n*min(i, a[i][j+1]) + max(i, a[i][j+1])
            v[p_].append(p)
            p = p_
    dp = defaultdict(lambda : None)
    for i in range(m):
        if not v[i]:
            dp[i] = 1
    ans = 1
    p = [0]*m
    for x in range(m):
        p[x] = 1
        if ans < dfs(x,p):
            ans = dp[x]
        p[x] = 0
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)
    return

#F
def F():
    n = I()
    p = LIR(n)

    return

#Solve
if __name__ == "__main__":
    E()


Measured memory_bytes: 280908
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	s = min({s, h * 2, q * 4});
	d = min(s * 2, d);
	ll ans = 0;
	ans += (n / 2) * d;
	ans += (n % 2) * s;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll int t,n,i,k;
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]==s[2]&&s[2]=='R')
	{
		cout<<3<<endl;
		return 0;
	}
	if(s[0]=='R')k=1;
	else k=0;
	for(i=1;i<3;i++)
	{
		if(s[i]==s[i-1]&&s[i]=='R')
		{
			cout<<2<<endl;
			return 0;
		}
		if(s[i]=='R')k++;
	}
	if(k==3)cout<<3<<endl;
	else if(k==0)cout<<0<<endl;
	else cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 3624
def solve(N, A):
    m = sum(A) / N
    ans = 0
    for i in range(N):
        if A[i] <= m:
            ans += 1
    print(ans)

while True:
    N = int(input())
    if N == 0:
        break
    A = list(map(int, input().split()))
    solve(N, A)


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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

std::vector<int> node[2];

constexpr int INF = 1e9 + 10;

int m; //leafのサイズ

void init(int rsiz)
{

    m = 1;

    while (m < rsiz)
        m *= 2;

    node[0].resize(2 * m - 1);
    node[1].resize(2 * m - 1);

    for (int i = 0; i < 2 * m - 1; ++i)
    {
        node[0][i] = node[1][i] = INF;
    }

} //ここで初期化して

/*void debug()
{

    int x = 0;

    rep(i, 2 * m - 1)
    {
        std::cerr << node[i] << ' ';
        if (x == i)
        {
            std::cerr << std::endl;
            x = x * 2 + 2;
        }
    }
}*/

void upd(int x, int idx, int val)
{

    idx += m - 1;

    if (node[x][idx] <= val)
        return;

    node[x][idx] = val;

    while (idx > 0)
    {
        idx = (idx - 1) / 2;
        node[x][idx] = std::min(node[x][2 * idx + 1], node[x][2 * idx + 2]);
    }
}

int get(int x, int a, int b, int k = 0, int l = 0, int r = m)
{ //上からだんだんと下へ//[a,b) [l,r)

    if (r <= a || b <= l)
        return INF; //範囲外

    if (a <= l && r <= b)
        return node[x][k]; //完全に範囲内

    //部分的に範囲内

    int lv = get(x, a, b, 2 * k + 1, l, (l + r) / 2);
    int rv = get(x, a, b, 2 * k + 2, (l + r) / 2, r);

    return std::min(lv, rv);
}

int main()
{
    ll n, q;

    std::cin >> n >> q;

    init(n);
    upd(0, n - 1, n - 1);
    upd(1, n - 1, n - 1);

    ll ans = 0;

    rep(i, q)
    {
        int x, y;
        std::cin >> x >> y;
        --y;
        --x;
        int v = get(!x, y, n);
        ans += v - 1;
        upd(x, v - 1, y);
    }

    ans = (n - 2) * (n - 2) - ans;

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  int64_t K = abs(A - B);
  if(K - (V-W)*T <= 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

using namespace std;
#define INF (1 << 30)
int xs[] = {0, 1, 0, -1}, ys[] = {1, 0, -1, 0};
int x, y, dp[10][21][21][1 << 10];
int g[10], d[10], s[10], e[10], n;
char c[21][21];
int sale[10][105];
int main(){
    while(cin >> x >> y, x | y){
	for(int i = 0;i < y;i++)
	    for(int j = 0;j < x;j++)
		for(int k = 0;k < (1 << 8);k++)
		    dp[0][i][j][k] = -INF;
	for(int i = 0;i < y;i++){
	    for(int j = 0;j < x;j++){
		cin >> c[i][j];
		if(c[i][j] == 'P'){
		    c[i][j] = '.';
		    dp[0][i][j][0] = 0;
		}
	    }
	}
	cin >> n;
	int used[10];
	fill(used, used + 10, 0);
	for(int i = 0;i < 10;i++)
	    for(int j = 0;j < 105;j++)
		sale[i][j] = 0;
	for(int i = 0;i < n;i++){
	    cin >> g[i] >> d[i] >> s[i] >> e[i];
	    used[g[i]] = 1;
	}
	for(int i = 1;i < 10;i++)used[i] += used[i - 1];
	for(int i = 0;i < n;i++){
	    for(int j = s[i];j < e[i];j++)
		sale[used[g[i]] - 1][j] = d[i];
	}
	for(int i = 0;i < y;i++)
	    for(int j = 0;j < x;j++){
		if(c[i][j] != '.')c[i][j] = '0' + used[c[i][j] - '0'] - 1;
	    }
	int ans = 0;
	for(int i = 0;i <= 100;i++){
	    for(int j = 0;j < y;j++){
		for(int k = 0;k < x;k++){
		    if(c[j][k] != '.')continue;
		    int there = 0;
		    for(int l = 0;l < (1 << 8);l++){
			if(i){
			    dp[i & 1][j][k][l] = -INF;
			    for(int m = 0;m < 4;m++){
				int ty = j + ys[m], tx = k + xs[m];
				if(ty < 0 || ty >= y || tx < 0 || tx >= x)continue;
				if(c[ty][tx] == '.')
				    dp[i & 1][j][k][l] = max(dp[(i + 1) & 1][ty][tx][l], dp[i & 1][j][k][l]);
			    }
			}
			for(int m = 0;m < 4;m++){
			    int ty = j + ys[m], tx = k + xs[m];
			    if(ty < 0 || ty >= y || tx < 0 || tx >= x)continue;
			    if(c[ty][tx] == '.')continue;
			    int pr = c[ty][tx] - '0';
			    if(l & (1 << pr)){
				dp[i & 1][j][k][l] = max(dp[i & 1][j][k][l], dp[i & 1][j][k][l - (1 << pr)] + sale[pr][i]);
			    }
			}
			ans = max(dp[i & 1][j][k][l], ans);
		    }
		}
	    }
	}
	cout << ans << endl;
    }
}

Measured memory_bytes: 5076
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	var s = strings.Split(sc.Text(), "")

	var count int

	if s[0] == "1" {
		count++
	}
	if s[2] == "1" {
		count++
	}
	if s[1] == "1" {
		count++
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;


void solve(){
	int n ; cin >> n ;
	int x = 1000001;
	bool sieve[x];
	fill(sieve,sieve+x,true);
	for(int i=2;i*i<x;i++){
		if(sieve[i]){
			for(int j=i*i;j<x;j+=i) sieve[j] = false ;
		}
	}
	for(int i=n;i<x;i++){
		if(sieve[i]){
			cout << i << endl;
			return;
		}
	}
}

int32_t main(){IOS;

	int t =1; //cin >> t ;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  int q;
  cin >> q;
  vector<int> m(q);
  for(int i=0;i<q;i++) cin >> m[i];

  /*
  for(int i=0;i<q;i++){
    bool flag=false;
    for(int bit=0;bit<(1<<n);bit++){
      int sum = 0;
      for(int j=0;j<n;j++){
        if((bit>>j) & 1 == 1){
          sum += a[j];
        }
      }
      if(sum == m[i]){
        flag = true;
        break;
      }
    }
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;
  }*/
  vector<int> s(1<<n);
  for(int bit=0;bit<(1<<n);bit++){
    int sum = 0;
    for(int j=0;j<n;j++){
      if((bit>>j) & 1 == 1){
        sum += a[j];
      }
    }
    s.push_back(sum);
  }

  for(int i=0;i<q;i++){
    bool flag = false;
    for(int j=0;j<s.size();j++){
      if(s[j] == m[i]){
        flag = true;
        break;
      }
    }
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}


Measured memory_bytes: 10996
n, m = map(int, input().split())
p_y = []
for i in range(m):
    p, y = map(int, input().split())
    p_y.append([p, y, i])

p_y.sort()
# print(p_y)

res = [0] * m
order = 0
for i in range(m):
    ken, _, index = p_y[i]
    if ken != p_y[i - 1][0] and i > 0:
        order = 1
    else:
        order += 1
    res[index] = [ken, order]


# print(res)

for i in range(m):
    ken = str(res[i][0]).zfill(6)
    order = str(res[i][1]).zfill(6)
    print(ken + order)
    

Measured memory_bytes: 40560
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
// #define first first
// #define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

int dp[1100];

signed main(){
    int W;
    int cnt = 0;
    while(cin >> W, W){
        int n;
        cin >> n;
        cnt++;
        vector<int> v(n), w(n);
        rep(i, 0, n){
            char c;
            cin >> v[i] >> c >> w[i];
        }
        rep(i, 0, 1010){
            dp[i] = 0;
        }
        rep(i, 0, n){
            repb(j, W, 0){
                if(j + w[i] <= W){
                    dp[j + w[i]] = max(dp[j] + v[i], dp[j + w[i]]);
                }
            }
        }
        int ans = -1, wt;
        rep(i, 0, W + 1){
            if(dp[i] > ans){
                ans = dp[i];
                wt = i;
            }
        }
        cout << "Case " << cnt << ":" << endl;
        o(ans);
        o(wt);
    }
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; i++){
    cin >> a[i];
}
int cnt = 0,sum = 1;
for(int i = 1; ; i++){
    sum += (k - 1);
    cnt++;
    if(sum >= n)
    break;
}
cout << cnt << endl;
}


Measured memory_bytes: 640
import sys
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
if sum(A)<sum(B):
    print(-1)
    sys.exit()
H=[]
num=0
ans=0
for i in range(N):
    if A[i]>=B[i]:
        c=A[i]-B[i]
        H.append(c)
    else:
        num+=B[i]-A[i]
        ans+=1
H=sorted(H,reverse=True)
if len(H)==N:
    print(0)
    sys.exit()
for i in range(len(H)):
    num-=H[i]
    ans+=1
    if num<=0:
        break
print(ans)

Measured memory_bytes: 18356
#include<stdio.h>
typedef long long ll;

ll func(ll x){
	if(x == 1){
		return 1;
	}
	x /=2;
	return 1 + 2*func(x);
}

int main(){
	ll h;
	scanf("%lld",&h);
	ll ans = func(h);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    string S,T;
    cin>>S>>T;
    rep(i,0,S.size()-T.size()+1){
        ll i2 = S.size()-1-i;
        ll ok = true;
        rep(j,0,T.size()){
            if(S[i2-j] == '?')continue;
            if(S[i2-j] != T[T.size()-j-1])ok = false;
        }
        if(ok){
            ll j2 = i2-T.size()+1;
            rep(j,0,S.size()){
                if(j >= j2 && j<=i2)cout<<T[j-j2];
                else if(S[j] == '?')cout<<'a';
                else cout<<S[j];
            }
            return 0;
        }
    }
    cout<<"UNRESTORABLE";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<class T> inline bool chmin(T& a, T b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
    }
    template<class T> inline bool chmax(T& a, T b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll N,x;
        cin>>N>>x;
        if(x==2*N-1||x==1){
            cout<<"No"<<endl;
            return 0;
        }
        vl vec(2*N-1);
        rep(i,2*N-1)vec[i]=i+1;
        swap(vec[N-1],vec[x-1]);
        swap(vec[0],vec[N-2]);
        swap(vec[2*N-2],vec[N]);
        cout<<"Yes"<<endl;
        rep(i,2*N-1)cout<<vec[i]<<endl;
    }

Measured memory_bytes: 3072
import sys
import numpy as np

# input = sys.stdin.readline

n, b, a = map(int,input().split())

sho = n // (a + b) 

mod = n % (a + b)

if mod <= b:
    b_num = sho * b + mod
else:
    b_num = sho * b + b
print(b_num)

Measured memory_bytes: 21372
a, b, c = map(int, input().split())
k = int(input())

while k > 0 and a >= b:
    k -= 1
    b *= 2

while k > 0 and b >= c:
    k -= 1
    c *= 2

if a < b < c:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61648
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}


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

int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> ks;
  for (int i = 0; i < M; i++) {
    int k; cin >> k;
    vector<int> s(k);
    for (int i = 0; i < k; i++) cin >> s.at(i);
    ks.push_back(s);
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++) cin >> p.at(i);
  int ans = 0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<10> s(tmp);
    bool allon = true;
    for (int i = 0; i < M; i++) {
      int on = 0;
      for (int v : ks.at(i)) if (s.test(v-1)) on++;
      if (on % 2 != p.at(i)) allon = false;
    }
    if (allon) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
        
         ll n,a,b;
         cin>>n>>a>>b;
         if((b-a)%2==0)
         cout<<(b-a)/2<<endl;
         else 
         {
             ll can1 = a-1;
             ll b1 = b;
             b1-=can1;
             ll p1 = can1+b1/2;
             ll can2 = n-b;
             a+=can2;
             ll p3 = n-a+1;
             ll p2 = can2+(p3)/2;
             cout<<min(p1,p2)<<endl;
             
             
         }
         

      }
      






}





Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main() { 
    int n; ll k; cin >> n >> k;
    vector<ll>A(n), F(n);
    rep(i, n) cin >> A[i];
    rep(i, n) cin >> F[i];
  
    sort(all(A), greater<ll>());
    sort(all(F));
    ll ng = -1, ok = 1e12 + 1;
    while(ok - ng > 1){
        ll mid = (ok+ng)/2, sum = 0;
        rep(i, n){
            ll num = A[i]*F[i]-mid;
            if(num>0){
                sum += num / F[i];
                if(num%F[i]>0) sum++;
            }
        }
        if(sum <= k)ok = mid;   
        else ng = mid;    
    }
    cout << ok << ln;
}

Measured memory_bytes: 3328
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n, m = LI()
G = [set(range(n)) for _ in range(n)]
for i in range(n):
    G[i].remove(i)

for _ in range(m):
    a, b = LI()
    G[a - 1].remove(b - 1)
    G[b - 1].remove(a - 1)

color = [0] * n
def bipartite_or_not(s):
    color[s] = 1
    dq = deque([s])
    b = 1
    w = 0
    while dq:
        u = dq.popleft()
        for v in G[u]:
            if color[v] and color[u] != color[v]:
                continue
            elif color[v] and color[u] == color[v]:
                print(-1)
                exit()
            color[v] = -color[u]
            if color[v] == 1:
                b += 1
            else:
                w += 1
            dq += [v]
    return b, w

bit = 1
for i in range(n):
    if color[i]:
        continue
    p, q = bipartite_or_not(i)
    bit = bit << p | bit << q

for j in range(n // 2, -1, -1):
    if bit >> j & 1:
        print(n * (n - 1) // 2 - j * (n - j))
        break


Measured memory_bytes: 64988
N = int(input())
D = [map(int, input().split()) for i in range(N)]
D1, D2 = [list(i) for i in zip(*D)]
ans = 0
for i in range(N):
    if D1[i] == D2[i]:
        ans += 1
        if ans == 3:
            print("Yes")
            exit()
    else:
        ans = 0
print("No")

Measured memory_bytes: 9192
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#define FOR(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
#define MAXN (200000)
int a[MAXN],b[MAXN];
map<int,int> id;
int main (int argc, char *argv[])
{
	std::ios::sync_with_stdio(false);
	int n;cin>>n;
	FOR(i,1,n){
		cin>>a[i];
		id[a[i]]=i;
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	int ans=0;
	FOR(i,1,n){
		int t=id[b[i]];
		if (i%2!=t%2)	ans++;	
	}
	cout<<ans/2<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 998244353

const int MAXN = 1e5 + 50;
ll d[MAXN], pa[MAXN], sz[MAXN], depth[MAXN];
vector<int> adj[MAXN];
int n;

bool check(int root) {
	queue<int> que;
	que.push(root);
	ll sum = 0;
	depth[root] = 0;
	while(!que.empty()) {
		int v = que.front(); que.pop();
		for(auto c : adj[v]) {
			depth[c] = depth[v] + 1;
			sum += depth[c];
			que.push(c);
		}
	}
	return sum == d[root];
}


int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &d[i]);

	map<ll, int> M;
	for(int i = 1; i <= n; i++)
		M[d[i]] = i;
	for(int i = 1; i <= n; i++)
		sz[i] = 1;

	vector<int> v;
	for(int i = 1; i <= n; i++) v.push_back(i);
	sort(v.begin(), v.end(), [](int i, int j){ return d[i] > d[j]; });
	int root = v.back();
	for(auto c : v) {
		if(c == root) break;
		ll dval = d[c] + 2*sz[c] - n;
		if(M.find(dval) == M.end() || M[dval] == c) {
			printf("-1");
			exit(0);
		}
		int p = M[dval];
		adj[p].push_back(c);
		pa[c] = p;
		sz[p] += sz[c];
	}

	if(!check(root)) {
		printf("-1");
		exit(0);
	}

	for(int i = 1; i <= n; i++)
		if(i != root) printf("%d %d\n", i, pa[i]);
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

string s,t;
string no = "UNRESTORABLE";

int main(){
	cin >> s;
	cin >> t;
	repm(i,s.size(),-1){
		bool b = 1;
		repp(j,0,t.size()){
			if(i<j){
				b = 0;
				break;
			}
			if(s[i-j]==t[(int)t.size()-1-j] || s[i-j] == '?') continue;
			b = 0;
			break;
		}
		if(b){
			repp(k,0,i+1-(int)t.size()){
				cout << (s[k] == '?' ? 'a' : s[k]);
			}
			repp(k,0,t.size()){
				cout << t[k];
			}
			repp(k,i+1,s.size()){
				cout << (s[k] == '?' ? 'a' : s[k]);
			}
			cout << endl;
			return 0;
		}
	}
	cout << no << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;

long long f(long long m) {
	if (m == 0) return 1;
	else return m*f(m - 1);
}




int main()
{
	long long n;
	cin >> n;
	cout << f(n) << endl;
}

Measured memory_bytes: 1156
(R,C),*X=$<.map{|l|l.split.map &:to_i};s,*t=->x,y{y==C ?3e9+x:x==R ?6e9-y:y<1?9e9-x:y*1[x]};X.flat_map{|a,b,c,d|[[v=s[a,b],v],[w=s[c,d],v]]*-2[v*w]}.sort.map{|i,x|x==t[-1]?t.pop: t<<x};puts t[0]&&:NO||:YES

Measured memory_bytes: 31988
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

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

  {
    const auto C_it = std::find(s.begin(), s.end(), 'C');
    if (C_it == s.end()) goto FAILED;
    const auto F_it = std::find(s.rbegin(), s.rend(), 'F');
    if (F_it == s.rend()) goto FAILED;
    const i64 C = std::distance(s.begin(), C_it);
    const i64 F = std::distance(s.begin(), F_it.base()) - 1;
    if (C > F) goto FAILED;
  }

  std::cout << "Yes" << std::endl;
  return 0;

FAILED:
  std::cout << "No" << std::endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<vector<ll>> prod(vector<vector<ll>>& a, vector<vector<ll>>& b, ll mod) {
    vector<vector<ll>> ret(a.size(),vector<ll>(b[0].size(),0));
    for (int i = 0;i < a.size();++i) for (int j = 0;j < b[0].size();++j) for (int k = 0;k < a[0].size();++k) {
        ret[i][j] += a[i][k]*b[k][j];
        ret[i][j] %= mod;
    }
    return ret;
}

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<vector<ll>> a(n,vector<ll>(n)),b(1,vector<ll>(n,1));
    for (int i = 0;i < n;++i) for (int j = 0;j < n;++j) cin >> a[i][j];
    while (k) {
        if (k&1) b = prod(b,a,mod);
        a = prod(a,a,mod);
        k >>= 1;
    }
    ll ans = 0;
    for (int i = 0;i < n;++i) (ans += b[0][i]) %= mod;
    cout << ans << endl;
    return 0;
}

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

// コンテスト中のみ
#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int MOD = 1000000007;

ll H, W;
ll sx, sy, gx, gy;
char s[1010][1010];
int v = 0, e = 0;
vector<pair<int, int>>edge[1000010];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

vector<ll> dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>pq;
	vector<ll>dist(v, INF);
	dist[s] = 0;
	pq.push({ dist[s],s });
	while (!pq.empty()) {
		P p = pq.top(); pq.pop();
		ll d = p.first, from = p.second;
		if (dist[from] < d)continue;
		for (auto nv : edge[from]) {
			int to = nv.first; ll cost = nv.second;
			if (dist[from] + cost < dist[to]) {
				dist[to] = dist[from] + cost;
				pq.push({ dist[to],to });
			}
		}
	}
	return dist;
}
int f(int x, int y) {
	return x * W + y;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> H >> W;
	v = H * W;
	cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--;
	rep(i, H)rep(j, W)cin >> s[i][j];
	rep(i, H) {
		rep(j, W) {
			if (s[i][j] != '#') {
				rep(k, 4) {
					int nx = i + dx[k], ny = j + dy[k];
					if (0 <= nx && nx < H && 0 <= ny && ny < W&&s[nx][ny] != '#') {
						edge[f(i, j)].push_back({ f(nx,ny),0 });
						edge[f(nx, ny)].push_back({ f(i,j),0 });
					}
				}
				for (int k = -2; k <= 2; k++) {
					for (int l = -2; l <= 2; l++) {
						if (k == 0 && l == 0)continue;
						int nx = i + k, ny = j + l;

						if (0 <= nx && nx < H && 0 <= ny && ny < W&&s[nx][ny] != '#') {
							edge[f(i, j)].push_back({ f(nx,ny),1 });
							edge[f(nx, ny)].push_back({ f(i,j),1 });
						}
					}
				}
			}
		}
	}
	auto p = dijkstra(f(sx, sy));
	ll ans = p[f(gx, gy)];
	if (ans == INF)ans = -1;
	cout << ans << endl;
	return 0;
}

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

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

    ll k;
    cin >> k;

    ll sum_a[n + 1];
    ll sum_b[m + 1];
    sum_a[0] = 0;
    sum_b[0] = 0;
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        sum_a[i + 1] = sum_a[i] + a;
    }
    for(int i = 0; i < m; i++){
        ll b;
        cin >> b;
        sum_b[i + 1] = sum_b[i] + b;
    }

    int ans = 0;
    int j = m;
    ll now = 0;
    int flag = 0;
    for(int i = 0; i <= n; i++){
        now = sum_a[i];
        flag = 0;
        while(j >= 0){
            if(now + sum_b[j] <= k){
                flag = 1;
                break;
            }
            j--;
        }

        if(ans < i + j && flag == 1){
            ans = i + j;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 6748
// B - Digital Gifts
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	double BTC = 380000.0;
	double ans = 0.;
	for(int i=0; i<N; ++i){
		double x; string u; cin>>x>>u;
		ans += u=="JPY"? x: x*BTC;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
N = int(input())
abc = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3  for _ in range(N+1)] # どの行動を選んだか残しておくための３、

for i in range(N):
    for j in range(3): # 昨日の行動
        for k in range(3):
            if j == k:
                continue # 昨日と同じ行動はとれないので飛ばす
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abc[i][k]) 

print(max(dp[-1]))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    if (Abs(a - c) <= d) Out("Yes");
    else if (Abs(a - b) <= d && Abs(b - c) <= d) Out("Yes");
    else Out("No");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> cnt(1e+4+10,0);
    repr(i,1,200) {
        repr(j,1,200) {
            repr(k,1,200) {
                ll a = i*i+j*j+k*k+i*j+j*k+k*i;
                if (a<=ll(1e+4)) {
                    cnt[a]++;
                }
            }
        }
    }
    repr(i,1,n+1) {
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3732
n = int(input())
a = []

for i in range(n):
	a += [int(input())]

mx = max(a)
sum = 0
inc = False

for p in a:
	if p == mx and not inc:
		inc = True
		sum += int(p//2)
	else:
		sum += p

print(int(sum))


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MB 1000000007
#define NB 1000000000
#define N5 100007
#define ll long long int
int N;
int A[N5],B[N5],C[N5],dp[3][N5];

int main()
{

	cin >>N;
	REP(i,N){
		cin >> A[i] >> B[i] >> C[i];
	}
	dp[0][0] = A[0];
	dp[1][0] = B[0];
	dp[2][0] = C[0];
	FOR(i,1,N){
		dp[0][i] = max(dp[1][i-1],dp[2][i-1])+A[i];
		dp[1][i] = max(dp[0][i-1],dp[2][i-1])+B[i];
		dp[2][i] = max(dp[1][i-1],dp[0][i-1])+C[i];
	}
	cout << max(max(dp[0][N-1],dp[1][N-1]),dp[2][N-1]);
}




Measured memory_bytes: 2560