akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int N = 55;
string s[N];
int h, w;

bool val(int x, int y) {
	return 0 <= x && x < h && 0 <= y && y < w;
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.') continue;
			bool is = false;
			is |= val(i - 1, j) && s[i-1][j] == '#';
			is |= val(i + 1, j) && s[i+1][j] == '#';
			is |= val(i, j - 1) && s[i][j-1] == '#';
			is |= val(i, j + 1) && s[i][j+1] == '#';
			if (!is) {
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int check[int(1e5+10)];

int main(){

    //TODO: 2つだけWA. 考え方はあっているっぽいが...?

    int n, a[int(1e5 + 10)];
    cin >> n;
    bool flag = true;
    int data = 1;
    int ck = 0;


    for(int i=0; i<n; i++){
        cin >> a[i];
        check[a[i]]++;
    }


    //対称性のチェック
    if(n % 2 == 0){
        for(int count=0; count<n; count++){
            if(count % 2 == 0) {continue;}
            if(check[count] != 2) {flag = false;}
        }
    }else{
        for(int odd_count=1; odd_count<n; odd_count++){
            if(odd_count % 2 != 0) {continue;}
            if(check[odd_count] != 2) {flag = false;}
        }
    }


    if(flag){
        int c = (n/2);
        for(int k=0; k<c; k++){
            data = (2*data) % MOD;
        }

        cout << data << endl;

    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1024
N, K = [int(p) for p in input().split(" ")]

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

def nHr(n, r):
    return comb(n+r-1, r, mod)

mod = 10**9 + 7
def f(i):
    if N-K-i+1 >= 0:
        return nHr(i, K-i) * nHr(i+1, N-K-i+1) % mod
    return 0

for i in range(K):
    print(f(i+1))


Measured memory_bytes: 3444
#include<iostream>

using namespace std;

int main() {
	int i = 0,n[10000];
	while (1) {
		cin >> n[i];
		if (n[i] == 0)break;
		i++;
	}
	i = 0;
	while (1) {
		if (n[i] == 0)break;
		cout << "Case " << i+1 << ": " << n[i] << endl;
		i++;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <ctime>
#include <numeric>


#ifndef M_PI
#define M_PI 3.141592653589
#endif
#define int long long
#define double long double

#ifdef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false);int32_t START = clock()
#define finish cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); return 0
#endif

#ifndef TIME
#define start cin.tie(NULL); cout.tie(NULL); cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false)
#define finish return 0
#endif

using namespace std;


//vector input
template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &i : vec) {
        cin >> i;
    }
    return is;
}

//pair output
template<typename E>
ostream &operator<<(ostream &os, pair<E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//"map" pair output
template<typename E>
ostream &operator<<(ostream &os, pair<const E, E> &t) {
    os << t.first << ' ' << t.second;
    return os;
}

//vector output
template<typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
    for (T i : vec) {
        os << i << ' ';
    }
    return os;
}

//2 dimensional vector output
template<typename T>
ostream &operator<<(ostream &os, vector<vector<T> > &vec) {
    for (vector<T> i : vec) {
        os << i << '\n';
    }
    return os;
}


int32_t main() {
    start;

    int n;
    string str;
    cin >> n;
    cin >> str;

    int j = n - 1;
    while (str[j] == 'W' && j > 0) {
        j -= 1;
    }

    int k = 0;
    while (k < n && str[k] == 'R') {
        k += 1;
    }

    int r = 0, w = 0;

    for (int i = k; i < j + 1; ++i) {
        if (str[i] == 'R') {
            r += 1;
        } else {
            w += 1;
        }
    }

    int rr = 0, ww = 0;
    for (int i = k; i < k + r; ++i) {
        if (str[i] == 'W') {
            rr += 1;
        }
    }

    for (int u = j; u >= j - w; --u) {
        if (str[u] == 'R') {
            ww += 1;
        }
    }

    cout << min(r, min(rr, min(w, ww))) << '\n';

    finish;
}

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

string s;
int ans;
int main(int argc,char const* argv[])
{
  cin >> s;
  ans=s.size();
  for(int i=1;i<s.size();i++)
    {
      if(s[i]!=s[i-1])
	{
	  ans=min(ans,max(i,(int)s.size()-i));
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    P = LF()

    # dp[i]: i枚のコインが表になる確率
    dp = [1]

    # 調和級数
    # O(NlogN)
    for i in range(n):
        tmp = [0] * (i + 2)
        p = P[i]
        q = 1 - P[i]
        for j in range(i + 1):
            tmp[j] += dp[j] * q
            tmp[j + 1] += dp[j] * p
        dp = tmp

    return sum(dp[n // 2 + 1:])


print(main())


Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

	
bool g[256][256];


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

void dfs(int y,int x){
	if(y<0||256<=y||x<0||256<=x||g[y][x])return;
	g[y][x]=true;
	rep(i,4){
		dfs(y+dy[i],x+dx[i]);
	}
}

int main(){
	int n;
	int l[50],t[50],r[50],b[50];
	while(cin>>n,n){
		vector<int> vx,vy;
		vx.push_back(-1);
		vy.push_back(-1);
		rep(i,n){
			cin>>l[i]>>t[i]>>r[i]>>b[i];
			l[i]*=2;
			t[i]*=2;
			r[i]*=2;
			b[i]*=2;
			vx.push_back(l[i]);vx.push_back(l[i]+1);
			vy.push_back(t[i]);vy.push_back(t[i]+1);
			vx.push_back(r[i]);vx.push_back(r[i]+1);
			vy.push_back(b[i]);vy.push_back(b[i]+1);
		}
		sort(all(vx));
		uniq(vx);
		sort(all(vy));
		uniq(vy);
		memset(g,false,sizeof(g));
		rep(i,n){
			int x1,y1,x2,y2;
			x1=lower_bound(all(vx),l[i])-vx.begin();
			y2=lower_bound(all(vy),t[i])-vy.begin();
			x2=lower_bound(all(vx),r[i])-vx.begin();
			y1=lower_bound(all(vy),b[i])-vy.begin();
			for(int j=y1;j<=y2;j++)g[j][x1]=g[j][x2]=true;
			for(int j=x1;j<=x2;j++)g[y1][j]=g[y2][j]=true;
		}
		int c=0;
		rep(i,256){
			rep(j,256){
				if(g[i][j])continue;
				c++;
				dfs(i,j);
			}
		}
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 3332
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

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

    int n;
    cin >> n;

    int a = n % 1000;
    if (a == 0) {
        cout << 0 << endl;
    } else {
        cout << 1000 - a << endl;
    }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N; cin >> N;
  for(int i = (100 * N + 107) / 108; i < (100 * N + 207) / 108; i++) {
    cout << i << endl;
    return 0;
  }
  cout << ":(" << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();

        long ans = solve(l, r);
        System.out.println(ans);
    }

    private static long solve(int l, int r) {
        long R = Math.min(l + 2019, r);
        long ans = 2018;
        for (long i = l; i <= R; i++) {
            for (long j = i + 1; j <= R; j++) {
                long x = i * j % 2019;
                ans = Math.min(ans, x);
                if (ans == 0) {
                    return 0;
                }
            }
        }
        return ans;
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define int long long
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#include "string"


int32_t main(){
	boost;
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int cur = 1000,ans = 1000;
	for(int i = 0; i < n;) {
		int stoke = cur  / a[i];
		int rem = cur % a[i];
		int j = i + 1;
		while(j < n && a[j] >= a[j - 1]) {
			cur = max(cur , stoke * a[j] + rem);
			j++;
		}
		i = j;
		ans = max(ans, cur);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3600
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int res=0;
  if(s[0]=='o') ++res;
  if(s[1]=='o') ++res;
  if(s[2]=='o') ++res;

  cout << 700 + res*100 << endl;

  return 0;
}


Measured memory_bytes: 256
def resolve():
    h, w = map(int, input().split())
    A = [[_ for _ in input()] for _ in range(h)]
    B = [i for i in A if '#' in i]
    C = zip(*[i for i in zip(*B) if '#' in i])
    for i in C:
        print(*i, sep='')

        # print(*C,sep='')


resolve()

Measured memory_bytes: 4596
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

temp = []
for i in H:
    temp.append(abs(T - i*0.006 - A))

mini = min(temp)
for i in range(len(temp)):
    if temp[i] == mini:
        print(i+1)
        break

Measured memory_bytes: 3060
#define r(a,i)for(i=0;i<a;i++)
#define s scanf("%d",&w)
#define c(a,b)a=a<b?a:b
d[999],p[999];main(i,j,w,n,m){s,n=w;s,m=w;r(n,i)s,d[i]=w;r(n,i)p[i]=1e9;r(m,j){s;r(n,i)c(p[i],p[i+1]+w*d[n-i-1]);}printf("%d\n",*p),exit(0);}

Measured memory_bytes: 604
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  lint N,C,K,check=1,ans=0;
  cin >> N >> C >> K;
  lint T[N+1];
  rep(i,N) cin >> T[i];
  T[N]=LINF;
  sort(T,T+N+1);
  lint Ccount=0,Tnow=0;
  rep(i,N){
    if(check==1) Tnow=T[i],check=0;
    Ccount++;
    if(Ccount==C || T[i+1]-Tnow>K) ans++,check=1,Ccount=0;
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    for(int i=1;i<=N;i++){
        for(int j=i+1;j<=N;j++){
            for(int k=0;k<10;k++){
                if(((i>>k)&1) != ((j>>k)&1)){
                    cout<<(k+1)<<" ";
                    break;
                }
            }
        }
        if(i==N) break;
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	int a, b, t;
	cin >> a >> b >> t;
	int ans = 0,x=a;
	while (a <= t) {
		ans += b;
		a += x;
	}
	cout << ans;
	return 0;
}










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

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

    int left = 0, right = 0;
    for (int i = 1; i <= m; i++) {
        int a;
        cin >> a;
        if (0 < a && a < x)
            left++;
        else if (x < a && a < n)
            right++;
    }

    int ans = min(left, right);
    cout << ans << endl;

    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);
    int n = sc.nextInt();
    long c = sc.nextLong();
    long[] x = new long[n + 1];
    long[] v = new long[n + 1];
    for (int i = 1; i <= n; i++) {
      x[i] = sc.nextLong();
      v[i] = sc.nextLong();
    }
    long[] a = new long[n + 1];
    long[] aa = new long[n + 1];
    long asum = 0;
    for (int i = 1; i <= n; i++) {
      asum += v[i];
      a[i] = Math.max(a[i - 1], asum - x[i]);
      aa[i] = Math.max(aa[i - 1], asum - x[i] * 2);
    }
    long[] b = new long[n + 2];
    long[] bb = new long[n + 2];
    long bsum = 0;
    for (int i = n; i > 0; i--) {
      bsum += v[i];
      b[i] = Math.max(b[i - 1], bsum - (c - x[i]));
      bb[i] = Math.max(bb[i - 1], bsum - (c - x[i]) * 2);
    }
    long res = 0;
    for (int i = n + 1; i > 0; i--) {
      res = Math.max(res, Math.max(a[i - 1] + bb[i], aa[i - 1] + b[i]));
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 65100
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  vector<int> p(n);
  REP(i,n) cin>>p[i];

  int ans=0,minv=INF;
  REP(i,n){
    if(minv>=p[i]){
      ans++;
      minv=p[i];
    }
  }

  cout<<ans<<endl;

  return 0;

}


Measured memory_bytes: 1024
N, x = map(int, input().split())
A = [0] + [int(x) for x in input().split()]
ans = 0
for i in range(1,N+1):
    if A[i-1] + A[i] > x:
        ans += A[i-1] + A[i] - x
        A[i] = x - A[i-1]
print(ans)


Measured memory_bytes: 19860
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MN = 1e5+1;

int N, A[MN];

bool solve() {
	int c1 = 0, ce = 0, co = 0, g = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] == 1) ++c1, ++co;
		else {
			A[i]&1 ? ++co, --A[i] : ++ce;
			g = __gcd(A[i], g);
		}
	}
	if (ce & 1) return 1;
	if (c1 || co > 1) return 0;
	for (int i = 0; i < N; ++i) A[i] /= g;
	return !solve();
}

int main() {
	if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
	ios_base::sync_with_stdio(0), cin.tie(0);

	cin >> N;
	for (int i = 0; i < N; ++i) cin >> A[i];
	cout << (solve() ? "First" : "Second");	
}


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

using namespace std;

void printVector(vector<int> A, int n)
{
	int i;
	for(i = 0; i < n-1; i++)
		printf("%d ", A[i]);
	printf("%d\n", A[i]);
}

void countingSort(vector<int> A, vector<int> B, vector<int> C, int MIN, int k, int n)
{
	for(int i = 0; i < n; i++)
		C[A[i]-MIN]++;
	
	for(int i = 1; i < k; i++)
		C[i] += C[i-1];
	
	for(int i = n-1; i >= 0; i--)
	{
		B[C[A[i]-MIN]-1] = A[i];
		C[A[i]-MIN]--;
	}
	
	for(int i = 0; i < n; i++)
		A[i] = B[i];
	
	printVector(A, n);
}

int main()
{
	int n, m, MIN = 1 << 25, MAX = 0, k = 0;
	scanf("%d", &n);
	
	vector<int> A;
	
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &m);
		
		A.push_back(m);
		
		if(A[i] > MAX)
			MAX = A[i];
		if(A[i] < MIN)
			MIN = A[i];	
	}
	
	k = MAX-MIN + 1;
	
	vector<int> B(n);
	vector<int> C(k);
	
	countingSort(A, B, C, MIN, k, n);
	
	return 0;
}


Measured memory_bytes: 42080
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val x = readLong()
    var ans = 0
    var sum = 0
    while (sum < x) {
        ans++
        sum += ans
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 34188
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mypair;
ll max(ll a,ll b){
	if(a>b)return a;
	else return b;
}
int main(){
	ll k,a,b;
	cin>>k>>a>>b;
	if(k<a+1|| a>=b)cout<<k+1<<endl;
	else if(b-a<=2) cout<<k+1<<endl;
	else{
		ll rest  = k;
		rest = k-(a-1);
		ll ans = a;
		ll t = max(0, (rest/2) );
			ans += (b-a)*t;
		
		/*
		while(t!=0){
			ans+= (b-a)*t;
			t /= a/(b-a);

		}*/

		cout<<ans+rest%2<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
 
	public static void main(String[] args) {
 
 
		double ans = 0;
		Scanner scan = new Scanner(System.in);
		int minutes_length  = scan.nextInt();
		int hour_length  = scan.nextInt();
		double hour_time  = scan.nextInt();
		double minutes_time  = scan.nextInt();
 
 
 
		double minutes_pi = Math.PI/30*minutes_time;
		double hour_pi = Math.PI/6*(hour_time+ minutes_time/60);
		double theta = Math.PI/30*(5*(hour_time+ minutes_time/60)-minutes_time);
		ans = minutes_length*minutes_length+hour_length*hour_length-2*hour_length*minutes_length*Math.cos(theta);
 
 
		System.out.println( Math.sqrt(ans));
	}
 
}

Measured memory_bytes: 35772
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=3e3+5;
const int mod=1e9+7;
const ll oo=1e18+5;

vector<pair<int,int>> v[55];
vector<int> path,found;

void add_self(int& a,int b){
	a+=b;
	if(a>=mod) a-=mod;
}

void dfs(int a,int goal,int par){
	if(a==goal){
		found=path;
		return;
	}
	for(pair<int,int> x:v[a]){
		int b=x.first;
		if(b==par) continue;
		path.push_back(x.second);
		dfs(b,goal,a);
		path.pop_back();
	}
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n-1;++i){
		int x,y;
		cin>>x>>y;
		v[x].push_back(mp(y,i));
		v[y].push_back(mp(x,i));
	}
	int m;
	cin>>m;
	vector<pair<int,int>> paths;
	vector<int> containMe(n-1 );
	for(int i=0;i<m;++i){
		int a,b;
		cin>>a>>b;
		found={-1};
		dfs(a,b,-1);
		for(int x:found){
			containMe[x]|=(1<<i);
		} 
	}
	vector<ll> dp(1<<m);
	dp[0]=1;
	for(int i=0;i<n-1;++i){
		// cout<<containMe[i]<<endl;
		vector<ll> new_dp(1<<m);
		for(int mask=0;mask<(1<<m);++mask){
			new_dp[mask]+=dp[mask];
			new_dp[mask|containMe[i]]+=dp[mask];
		}
		dp=new_dp;
	}
	cout<<dp[(1<<m)-1];
	return 0;
}
        


Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod=1000000007;
int main()
{
	int n,i;
	cin>>n;
	int h[n],dp[n];
	for(i=0;i<n;i++)
	cin>>h[i];
	dp[0]=0;
	for(i=1;i<n;i++)
	{
		if(i>=2) dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
		else dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
void init() {

}
#define int ll

map<char, int> val;

int num(State& now) {
	int ans = 0;
	while (*now >= '0' && *now <= '9') {
		ans *= 10LL;
		ans += (long long)(*now - '0');
		now++;
	}
	return ans;
}

int sol(State& now, int itr) {
	if (itr == 3) {
		if (*now == '(') {
			now++;
			int hoge = sol(now, 0);
			now++;
			return hoge;
		}
		else {
			return num(now);
		}
	}
	int hoge = sol(now, itr + 1);
	while (itr < 3) {
		if (*now == ')') break;
		if (val[*now] == itr) {
			int geko = *now;
			now++;
			if (geko == '+') {
				hoge += sol(now, itr + 1);
			}
			else if (geko == '-') {
				hoge -= sol(now, itr + 1);
			}
			else if (geko == '*') {
				hoge *= sol(now, itr + 1);
			}
		}
		else {
			itr++;
		}
	}
	return hoge;
}


void solve() {
	string s;
	cin >> s;
	s.push_back(')');
	string backup = s;
	ll ans = 0;
	for (int i = 0; i < 27; ++i) {
		s = backup;
		string neko = "+-*";
		int geko = i;
		REP(q, 3) {
			val[neko[q]] = geko%3;
			geko /= 3;
		}
		State start = s.begin();
		if (i == 0) ans = sol(start, 0);
		else ans = max(ans, sol(start, 0));
	}
	cout << ans << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3216
#include <iostream>
#include <array>
using namespace std;
int N, W;
int main() {
  cin >> N >> W;
  pair<int, int> s[N];
  for (int i = 0; i < N; i++) {
    int v, w;
    cin >> v >> w;
    s[i] = make_pair(v, w);
  }
  int T[W + 1][N + 1];
  for (int i = 0; i <= N; i++) {
    for (int c = 0; c <= W; c++) {
      if ( c <= 0 || i <= 0 ) {
        T[c][i] = 0;
      } else if ( c - s[i - 1].second < 0) {
        T[c][i] = T[c][i - 1];
      } else {
        T[c][i] = max(s[i - 1].first + T[c - s[i - 1].second][i - 1],  T[c][i - 1]);
      }
    }
  }
  cout << T[W][N] << endl;
}


Measured memory_bytes: 7052
#include<iostream>
#include<cstring>
#include<set>
#include<map>
using namespace std;
/*set<string> s;
int main()
{
    char com[100],str[100];
    int n;
    cin>>n;
    while(n--)
    {
        cin>>com>>str;
        if(com[0]=='i') s.insert(str);
        else
        {
            if(s.find(str)==s.end()) cout<<"no"<<endl;
            else cout<<"yes"<<endl;
        }
    }
    return 0;
}*/
map<string,bool> s;
int main()
{
    char com[100],str[100];
    int n; cin>>n;
    while(n--)
    {
        cin>>com>>str;
        if(com[0]=='i') s[str]=1;
        else
        {
            if(s[str]) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
    }
    return 0;
}


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 1000000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, z, w;
    cin >> n >> z >> w;
    int a[n];
    rep(i, 0, n)
        cin >> a[i];
    int dp[n][2];
    rep(i, 0, n)
    {
        dp[i][0] = -inf;
        dp[i][1] = inf;
    }
    repb(i, n - 1, -1)
        rep(j, 0, 2)
            if (j == 0)
            {
                int last = (i > 0 ? a[i - 1] : w);
                dp[i][0] = max(dp[i][0], abs(last - a[n - 1]));
                rep(k, i + 1, n)
                    dp[i][0] = max(dp[i][0], dp[k][1]);
            }
            else
            {
                int last = (i > 0 ? a[i - 1] : z);
                dp[i][1] = min(dp[i][1], abs(last - a[n - 1]));
                rep(k, i + 1, n)
                    dp[i][1] = min(dp[i][1], dp[k][0]);
            }
    cout << dp[0][0] << endl;
    return 0;
}

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

int main(){
   string s, t;
   cin >> s >> t;
   string res = "No";
   if(t.size() == s.size() + 1){
       if(s == t.substr(0, t.size()-1)){
           res = "Yes";
       }
   }
   cout << res << "\n";
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9 + 7;
pair<ll, ll>s4[4] = {{ -1, 0}, {1, 0}, {0, -1}, {0, 1}};
pair<ll, ll>s8[8] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}};

void judge() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    int a[6];
    for (int i = 1; i <= 5; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= 5; i++) {
        if (a[i] == 0) {
            cout << i << nl;
            break;
        }
    }
}

signed main() {
    judge();
    boost;
    solve();
}


Measured memory_bytes: 3688
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include <vector>
#include <map>
using namespace std;
int main() {
    char str[1010],s=0;//s用来判断是否按顺序 
    cin>>str;//输入字符 
    for(int i=0; i<strlen(str); i++) {
        if(s==0) {
            if(str[i]!='C') continue;
            if(str[i]=='C') {
                s+=1;
                continue;
            }
        }//判断字母C
        if(s==1) {
            if(str[i]!='F') continue;
            if(str[i]=='F') {
                s+=1;
                continue;
            }
        }//判断字母F 
    }    
    if(s==2) cout<<"Yes";//如果二个字母按按顺序都有那么，则输出Yes 
    else cout<<"No";//反之输出No 
    return 0;
}

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int64_t ketawa(int64_t N)
{
    int64_t d = 0;
    while (N != 0)
    {
        d += N % 10;
        N /= 10;
    }
    return d;
}

int main()
{
    int N;
    cin >> N;
    int Sn = ketawa(N);
    cout << (N % Sn == 0 ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int n,x;
	scanf("%d",&n);

	for(int i = 1; i<= n; i++)
	{
		if(i%3 == 0){
			printf(" %d",i);
		}else{
			x = i;
			do{
				if(x%10 == 3){
					printf(" %d",i);
					break;
				}
				x /=10;
			}while(x);
		}
	}
	printf("\n");
}

Measured memory_bytes: 1028
board, dp = [], []
bingo = False

for _ in range(3):
    board.append(list(map(int, input().split()))) 
    dp.append([0, 0, 0])

N = int(input())

for _ in range(N):
    num = int(input())

    for r in range(3):
        for c in range(3):
            if num == board[r][c]:
                dp[r][c] = 1

for i in range(3):
    if dp[i][0] == dp[i][1] == dp[i][2] == 1 or dp[0][i] == dp[1][i] == dp[2][i] == 1:
        bingo = True
        print("Yes")
        break

if not bingo:
    if dp[0][0] == dp[1][1] == dp[2][2] == 1 or dp[0][2] == dp[1][1] == dp[2][0] == 1:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 9188
import sys

s = input()
t = input()
s_ = s
num = 1

for i in range(len(t)):
    if s.find(t[i]) == -1:
        print(-1)
        sys.exit()
    elif s_.find(t[i]) == -1:
        num += 1
        s_ = s[s.find(t[i]) + 1:]
    else:
        s_ = s_[s_.find(t[i]) + 1:]

print(num*len(s) - len(s_))

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

int main() {
  
  string s;
  cin >> s;
  
  for ( int i = 0; i < s.size(); i++){
    int count = 0;
    for ( int j = 0; j < s.size(); j++){
      if ( s[i] == s[j] ){
        count++;
      }
    }
    if ( count % 2 != 0 ){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;  
  
}


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

const int N = 3e3 + 5;
int dp[N][N];
string s, t;
int solve(int i, int j) {
    if (i >= s.size() || j >= t.size())
        return 0;
    if (dp[i][j] != -1)
        return dp[i][j];
    int res = 0;
    if (s[i] == t[j])
        res = 1 + solve(i + 1, j + 1);
    else
        res = max(solve(i + 1, j), solve(i, j + 1));
    return dp[i][j] = res;
}

void build(int i, int j) {
    if (i >= s.size() || j >= t.size())
        return;
    if (s[i] == t[j]) {
        cout << s[i];
        build(i + 1, j + 1);
        return;
    }
    if (dp[i][j] == solve(i + 1, j))
        build(i + 1, j);
    else
        build(i, j + 1);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> s >> t;
    memset(dp, -1, sizeof dp);
    solve(0, 0);
    build(0, 0);
    return 0;
}


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

int N, K;

int main() {
    cin >> N >> K;
    int mod = N % K;

    int ans = 1;
    if (mod == 0) {
        ans = 0;
    }

    cout << ans << endl;
}

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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e16;
const int MB = 20;
const int MOD = 2019;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<bool> used(n);
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int x;
			cin >> x;
			used[x - 1] = true;
		}
	}
	int cnt = 0;
	for (auto b : used) cnt += !b;
	cout << cnt;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

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

int main(){
  int n,d,x,a,ttl=0;cin>>n>>d>>x;
  REP(i,n){
    cin>>a;
    REP(j,d){
      if(j*a+1>d) break;
      ttl++;
    }
  }
  cout<<ttl+x;
}

Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
d_li = [int(i) for i in input().split()]
all_digits = set(range(10))
dis_digits = set(d_li)
like_digits = all_digits - dis_digits
like_li = sorted(list(like_digits))

while set([int(i) for i in str(N)]) & dis_digits:
    N += 1
print(N)

Measured memory_bytes: 3060
#include "stdio.h"

void insertionSort(int A[],int N){
	for(int i=0;i<N;++i){
		if(i==0) printf("%d",A[i]);
		else printf(" %d",A[i]);
	}
	printf("\n");
	for(int i=1;i<N;++i){
		int v=A[i];
		int j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
		for(int j=0;j<N;++j){
			if(j==0) printf("%d",A[j]);
			else printf(" %d",A[j]);
		}
		printf("\n");
	}
}

int main(){
	int N; scanf("%d",&N);
	int A[100];
	for(int i=0;i<N;++i) scanf("%d",&A[i]);
	
	insertionSort(A,N);
	return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;
using p = pair<ll,  ll>;
using pp = pair<pair<ll, ll>, pair<ll, pair<ll, ll>>>;

int main () {
	string s, t;
	cin >> s >> t;
	int n = s.size ();
	int cc = 0;
	for (int i = 0; i < n; i++) {
		cc += s[i] != t[i];
	}
	cout << cc << "\n";
}


Measured memory_bytes: 3916
/**
*    author:  y_takano
*    created: 23.06.2020 09:24:55
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

using namespace std;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    double a, b, c;
    cin>>a>>b>>c;

    c = c/180.0*acos(-1.0);

    printf("%.8lf\n", a*b*sin(c)/2.0);
    printf("%.8lf\n", sqrt(a*a+b*b-2.0*a*b*cos(c))+a+b);
    printf("%.8lf\n", a*b*sin(c)/a);

    return 0;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, j, n) for (int i = j; i < (int)(n); i++)
#define brep(i, n) for (int i = n; i > 0; i--)
#define BREP(i, j, n) for(int i = n; i > j; i--)
#define TEST cout << "PASS" << endl
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 1e6 + 1e3 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;


//UnionFind

struct UnionFind{
  vector<int> d;

//コンストラクタ
  UnionFind(int n = 0): d(n, -1){};
//

  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }

  int size(int x){
    return -d[find(x)];
  }

};

int main(){
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--;b--;
    uf.unite(a, b);
  }
  int ans = -1;
  rep(i, n){
    ans = max(ans, uf.size(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INFTY = (1<<20);
static const int MAX =10000;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(){
    priority_queue<pair<int, int> > PQ;
    int d[MAX], color[MAX];
    
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;
    while(!PQ.empty() ){
        pair<int, int> f = PQ.top();PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        
        if(d[u] < f.first * (-1))continue;
        
        for(int j = 0; j < adj[u].size(); j++){
            int v = adj[u][j].first;
            if(color[v] == BLACK)continue;
            if(d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v] * (-1),v));
                color[v] = GRAY;
            }
        }
    }
    for(int i = 0; i < n; i++)cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
}
int main(){
    int k,c,u,v;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    return 0;
}


Measured memory_bytes: 8084
#!/usr/bin/env python3
import sys
import numpy as np


def solve(x: "List[int]"):
    for i in range(len(x)):
        if x[i] == 0:
            print(i+1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = [int(next(tokens)) for _ in range(5)]  # type: "List[int]"
    solve(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27112
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int m, g;
int dp[8][1024];


int main(){
  while(scanf("%d", &m) && m){
    int a[7], b[7];
    rep(i, m) scanf("%d%d", a+i, b+i);

    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;

    rep(i, m){
      rep(j, 1000){
	//	fprintf(stderr, "%d\n", j);
	rep(k, b[i]+1){
	  if(j+a[i]*k > 1000) continue;
	  dp[i+1][j+a[i]*k] += dp[i][j];
	}
      }
    }

    /*    rep(i, 7){
      rep(j, 50) printf("%d ", dp[i][j]);
      puts("");
      }*/
    scanf("%d", &g);
    rep(i, g){
      int n;
      scanf("%d", &n);
      printf("%d\n", dp[m][n]);
    }
  }
  return 0;
}

Measured memory_bytes: 1228
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
if N<=999
    puts "ABC"
else
    puts "ABD"
end

Measured memory_bytes: 1788
N=int(input())
TA=[list(map(int, input().split())) for i in range(N)]

nums=TA[0]

def f(points, rate):
  if points[0]%rate[0]>0:
    a=1
  else:
    a=0
  if points[1]%rate[1]>0:
    b=1
  else:
    b=0
    
  tmp=max(points[0]//rate[0]+a, points[1]//rate[1]+b)
  return [rate[0]*tmp, rate[1]*tmp]

for i in range(1, N):
  nums=f(nums, TA[i])
  
print(sum(nums))

Measured memory_bytes: 3188
def Show():
    print(' '.join([str(aa) for aa in a]))

n = int(input())
a = list(map(int, input().split()))
Show()
for i in range(1, n):
    target = a[i]
    j = i-1 
    while j >= 0 and a[j] > target:
        a[j+1] = a[j] 
        j -= 1
    a[j+1] = target
    Show()


Measured memory_bytes: 5612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			if (op.equals("+")) {
				System.out.println(a + b);
			} else if (op.equals("-")) {
				System.out.println(a - b);
			} else if (op.equals("/")) {
				System.out.println(a / b);
			} else if (op.contentEquals("*")) {
				System.out.println(a * b);
			} else {
				break;
			}
		}
	}
}


Measured memory_bytes: 26268
N = int(input())
seq = [int(input()) for _ in range(N)]
from collections import deque
import bisect
LIS = deque([seq[0]])
for i in range(1,len(seq)):
    if seq[i] <= LIS[0]:
        LIS.appendleft(seq[i])
    else:
        LIS[bisect.bisect_left(LIS, seq[i])-1] = seq[i]

print(len(LIS))

Measured memory_bytes: 81944
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 105, MAX = 1e5 + 5;
int n, W, w[N], v[N], dp[N][MAX];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> W;
	fw (i, 0, n) cin >> w[i] >> v[i];
	dp[0][0] = 0;
	fw (i, 0, n) fw (j, 0, W + 1) {
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		if (j + w[i] <= W) dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
//		cout << "dp[" << i << "][" << j <<"] = " << dp[i][j] << "\n";
	}
	int ans = 0;
	fw (j, 0, W + 1) ans = max(ans, dp[n][j]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 79360
#include <iostream>
#include <string>
#include <cstdlib>

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

    int min = 99999;
    for (std::size_t i = 0; i < str.size() - 2; ++i) {
        std::string sub_str = str.substr(i, 3);
        int diff = std::abs(std::stoi(sub_str) - 753);
        if (diff < min) {
            min = diff;
        }
    }

    std::cout << min << std::endl;

    return 0;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

vi par,sz,vis,dis,ans;

vector<vi> graph;

void init(li n)
{
    dis.resize(n);
    vis.resize(n);
    graph.resize(n);

    f(i,0,n-1)
    {
        dis[i]=1e18;
    }
}

void bfs(li u)
{
    dis[u]=0;

    queue<li> q;

    q.push(u);
    vis[u]=1;

    while(!q.empty())
    {
        li tp=q.front();
        q.pop();

        for(li v:graph[tp])
        {
            if(!vis[v])
            {
                vis[v]=1;
                dis[v]=dis[tp]+1;
                ans[dis[v]]++;
                q.push(v);
            }
        }
    }
}

int main()
{    
   

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n,x,y;

    cin>>n>>x>>y;

    init(n+1);

    ans.resize(n);

    f(i,1,n-1)
    {
        graph[i].PB(i+1);
        graph[i+1].PB(i);
    }

    graph[x].PB(y);
    graph[y].PB(x);

    f(i,1,n)
    {
        bfs(i);

        // f(i,1,n-1)
        // {
        //     cout<<ans[i]<<" ";
        // }

        // cout<<endl;

        f(i,0,n)
        {
            vis[i]=0;
        }
    }

    f(i,1,n-1)
    {
        cout<<ans[i]/2<<endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  string s;
  cin >> s;
  int ans = INF;
  rep(i, s.size() - 2) {
    int t = 0;
    rep(j, 3) { t += (s[i + j] - '0') * (int)pow(10, 2 - j); }
    // cout << t << endl;
    cmin(ans, abs(753 - t));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512