akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define int long long int
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
 
int32_t main()
{
  int x,y;
  cin>>x>>y;
  while(1)
  {
    if(x*2==y){cout<<"Yes";break;}
    x--;
    y-=4;
    if(x*2==y){cout<<"Yes";break;}
    if(x==0){cout<<"No";break;}
  }
}

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

int main()
{
	int a,b,c,d;
        cin>> a>> b >> c>> d;
    
    int na = (c%b==0?c/b:c/b+1);
    int nb = (a%d==0?a/d:a/d+1);
    
    if(na <= nb)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout <<"No" <<endl;
    }
	return 0;
}

Measured memory_bytes: 3636
import math

A, B, H, M = map(int, input().split())

wA = 360 / (12*60)
wB = 360 / 60

theta_A = (60*H+M) * wA
theta_B = M * wB

theta = abs(theta_A - theta_B)
output = math.sqrt(abs(A**2 + B**2 - 2*A*B*math.cos(math.radians(theta))))
print(output)

Measured memory_bytes: 9516
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
using namespace std;
#define ll long long

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

int main()
{
    stringstream ss;
    // 入力
    string S;
    cin>>S;
    int ans=0;
    REP(i,4){
    	if(S[i]=='+') ans++;
    	else ans--;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    ll q = N / (A+B);
    ll r = N % (A+B);
    ll rr = min(A,r);

    cout << q*A+rr << endl;
}


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

using i64 = long long;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

i64 dp[100010][13];
const i64 M = 1000000007;
signed main() {
	i64 k = 0;
	dp[0][0] = 1;
	while(true) {
		char c = getchar();
		if (c == '\n') {
			break;
		} else if (c == '?') {
			REP(r, 13) {
				i64 s = 0;
				REP(j, 10) {
					s += dp[k][(j - r + 13) * 9 % 13];
				}
				dp[k + 1][r] = s % M;
			}
		} else {
			i64 d = c - '0';
			REP(r, 13) {
				i64 s = dp[k][(d - r + 13) * 9 % 13];
				dp[k + 1][r] = s % M;
			}
		}
		k += 1;
	}
	printf("%d", dp[k][5]);
}


Measured memory_bytes: 10368
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>

using namespace std;

int main() {
    int c[3][3];
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    bool ans = false;
    for(int i = 0; i < 101; i++) {
        int h[3],w[3];
        h[0] = i;
        w[0] = c[0][0] - h[0];
        w[1] = c[0][1] - h[0];
        w[2] = c[0][2] - h[0];
        h[1] = c[1][0] - w[0];
        h[2] = c[2][0] - w[0];

        bool ok = true;
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(c[j][k] != h[j] + w[k]) {
                    ok = false;
                    j = 100;
                    break;
                }
            }
        }
        if(ok) {
            ans = true;
            break;
        }
    }

    if(ans) cout << "Yes" << endl;
    else    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int mod = (int)1e9 + 7;
typedef long long ll;
int f[maxn], dp[maxn], pre[maxn];
int pw(int a, int n) {
	int res = 1;
	while(n) {
		if(n & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod;
		n >>= 1;
	}
	return res;
}
int INV(int a) {return pw(a, mod - 2);}
void add(int& a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}
int main() {
	int n, h, d;
	scanf("%d%d%d", &n ,&h, &d);
	f[0] = 1;
	int tot = 0;
	for(int i = 1; i <= n; i++) 
		f[i] = 1ll * f[i-1] * i % mod, add(tot, f[i]);
	dp[0] = pre[0] = 1;
	for(int i = 1; i <= h; i++) {
		dp[i] = 1ll * tot * (pre[i - 1] + mod - (i <= d ? 0 : pre[i - d - 1])) % mod;
		pre[i] = pre[i - 1];
		add(pre[i], dp[i]);
	}
	int ans = 1ll * dp[h] * f[n] % mod * INV(tot) % mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 11904
s = input()
t = input()
lt = len(t)
ans = lt
for i in range(len(s) - lt + 1):
  cnt = 0
  for j,k in zip(s[i:i + lt], t):
    if j != k:
      cnt += 1
      
  ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 9044
#include<iostream>
using namespace std;
 
 
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++;
   }
  }
 }
 return sw;
 }
  
 int main(){
 int A[100],N,sw;
 cin >>N;
 for(int i=0;i<N;i++) cin>>A[i];
  
 sw=bubbleSort(A,N);
  
 for(int i=0;i<N;i++){
  if(i)cout<<" ";
  cout<<A[i];
 }
 cout<<endl;
 cout<<sw<<endl;
  
 return 0;
}


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


struct Node
{    
    Node *next, *prev;
    int key;
};

Node *nil;

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->prev = nil;
    nil->next = nil;
}

Node* listSearch(int key){
    Node* cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void printList(){
    Node* cur = nil->next;
    int isFirst = 0;
    while(1){
        if(cur == nil) break;
        if(isFirst++ > 0)   printf(" ");
        printf("%d" , cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void insert(int key){
    Node* x = (Node *)malloc(sizeof(Node));
    x->key = key;
    
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}


void deleteNode(Node* del)
{
    if(del == nil) return;
    del->prev->next = del->next;
    del->next->prev = del->prev;
    free(del);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

int main(){
    char op[20];
    int key, n, i;

    scanf("%d", &n);
    init();
    for(i = 0; i < n; i++){
        scanf("%s%d" , op , &key);
        if(op[0] == 'i'){
            insert(key);
        }else if(op[0] == 'd'){
            if(strlen(op) > 6){
                if(op[6] == 'F'){
                    deleteFirst();
                }else if(op[6] == 'L'){
                    deleteLast();
                }
            }else{
                deleteKey(key);
            }
        }
    }

    printList();

    return 0;
}



Measured memory_bytes: 34460
import java.util.*;
 
 
class Main {
    static int abc[];
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int H = sc.nextInt();
        int W = sc.nextInt();
        String s[][] = new String[H][W];
        for(int i=0; i<H; i++){
            String scan[] = sc.next().split("",0);
            for(int j=0; j<scan.length; j++){
                s[i][j] = scan[j];
            }
        }
        int[] d[] = {{-1,0},{1,0},{0,-1},{0,1}};

        boolean ans = true;
        for(int i=0; i<H; i++){          
            for(int j=0; j<W; j++){
                if(s[i][j].equals("#")){
                    int cnt = 0;
                    for(int k=0; k<4; k++){
                        
                        if((i==0 && k==0) || (i==H-1 && k==1) || (j==0 && k==2) || (j==W-1 && k==3)) continue;
                        if(s[i + d[k][0]][j + d[k][1]].equals("#")){
                            cnt++;
                        }
                    }
                    if(cnt==0) ans=false;
                }
            }
        }
        if(ans){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}

Measured memory_bytes: 21972
#  --*-coding:utf-8-*--

def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in range(N-1)]
    
    nodes = [[] for _ in range(N+1)]

    for a, b in AB:
        nodes[a].append(b)
        nodes[b].append(a)

    K = max(map(lambda x: len(x), nodes))
    print(K)
    C = {}

    Q = [(1, None, None)]
    while len(Q) > 0:
        nodeIdx, parent, parentNodeColor = Q.pop()
        colorIdx = 1
        
        for subNodeIdx in nodes[nodeIdx]:
            if subNodeIdx == parent:
                continue

            if colorIdx == parentNodeColor:
                colorIdx += 1

            C[(nodeIdx, subNodeIdx)] = colorIdx
            Q.append((subNodeIdx, nodeIdx, colorIdx))
            colorIdx += 1

    for a, b in AB:
        if (a, b) in C:
            print(C[(a, b)])
        else:
            print(C[(b, a)])



if __name__ == '__main__':
    main()


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

ll n, a, b, sum;

bool valid() {
    return (a + b) % 2 == 0;
}

bool kiri() {
    return (a - 1) <= (n - b);
}

void solve() {
    cin >> n >> a >> b;
    sum = 0;
    if(valid()) cout << b - ((a + b) / 2) << "\n";
    else if(kiri()) {
        b -= (a - 1);
        sum += (a - 1);
        a = 1;
        b--;
        sum++;
        sum += (b - ((a + b) / 2));
        cout << sum << "\n";
    } else {
        a += (n - b);
        sum += (n - b);
        b = n;
        a++;
        sum++;
        sum += (b - ((a + b) / 2));
        cout << sum << "\n";
    }
}

int main() {

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

    solve();

}

Measured memory_bytes: 3656
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<b)return 0; a=b; return 1;}

bool dp[101][101][222][2];

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

    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    if(s[0][0]=='.') dp[0][0][0][0] = 1;
    else dp[0][0][1][1]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<=h+w;k++){
                if(i+1<h){
                    if(s[i+1][j] == '#'){
                        dp[i+1][j][k][1] |= dp[i][j][k][1];
                        dp[i+1][j][k+1][1] |= dp[i][j][k][0];
                    }
                    else{
                        dp[i+1][j][k][0] |= dp[i][j][k][0];
                        dp[i+1][j][k][0] |= dp[i][j][k][1];
                        // dp[i+1][j][k+1][0] |= dp[i][j][k][1];
                    }
                }
                if(j+1<w){
                    if(s[i][j+1]=='#'){
                        dp[i][j+1][k][1] |= dp[i][j][k][1];
                        dp[i][j+1][k+1][1] |= dp[i][j][k][0];
                    }else{
                        dp[i][j+1][k][0] |= dp[i][j][k][0];
                        dp[i][j+1][k][0] |= dp[i][j][k][1];
                        // dp[i][j+1][k+1][0] |= dp[i][j][k][1];
                    }
                }
            }
        }
    }
    int ans = 1e7;
    for(int i=0;i<=w+h;i++){
        if(dp[h-1][w-1][i][0] || dp[h-1][w-1][i][1]){
            cout << i << endl;
            return 0;
        }
    }
    
}

Measured memory_bytes: 4608
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	ll n, k;
	cin >> n >> k;
	map<ll, ll> a;
	REP(i, n){
		ll x, y;
		cin >> x >> y;
		a[x] += y;
	}
	ll sum = 0;
	for(auto i = a.begin(); i != a.end(); ++i){
		ll nsum = sum + i->second;
		if(sum < k && k <= nsum) cout << i->first << endl;
		sum = nsum;
	}
	return 0;
}


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

int main() {
  int m, f, r;
  char g;
  while (true) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) return 0;
    if (m == -1 || f == -1) {
      g = 'F';
    } else if ((m + f) >= 80) {
      g = 'A';
    } else if ((m + f) >= 65) {
      g = 'B';
    } else if ((m + f) >= 50) {
      g = 'C';
    } else if ((m + f) >= 30 ) {
      if (r >= 50) g = 'C';
      else g = 'D';
    } else {
      g = 'F';
    }
    cout << g << endl;
  }
}

Measured memory_bytes: 1152
using System;
using System.Linq;

namespace B___Harshad_Number
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();

            Console.WriteLine(int.Parse(N) % N.Select(x => int.Parse(x.ToString())).Sum() == 0 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

ll n,m,r;
ll dist[205][205];
ll tar[10];

ll search(ll now,ll cost,ll ans,set<ll> visited){
    if (visited.empty()){
        return min(ans, cost);
    }
    if (now==-1){
        set<ll> nex_vis(visited);
        for (auto nex:visited){
            nex_vis.erase(nex);
            ans = search(nex, cost, ans, nex_vis);
            nex_vis.insert(nex);
        }
    }
    else{
        set<ll> nex_vis(visited);
        for (auto nex:visited){
            nex_vis.erase(nex);
            ans = search(nex, cost + dist[now][nex], ans, nex_vis);
            nex_vis.insert(nex);
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> r;
    rep(i,r){
        cin >> tar[i];
        tar[i]--;
    }
    rep(i,n){
        rep(j,n){
            if (i==j)
                dist[i][j] = 0;
            else
                dist[i][j] = infl;
        }   
    }
    rep(i,m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[j][k]);
            }
        }
    }
    ll ans = infl;
    set<ll> visited;
    rep(i,r){
        visited.insert(tar[i]);
    }
    ans = search(-1,0,ans,visited);
    cout << ans << endl;
}


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

int main(){
    int N, Y;
    cin >> N >> Y;
    for(int i = 0; i <= N;i++){
        for(int j = 0; j <= N - i; j++){
            int k = N - (i + j);
            if(10000*i + 5000*j + 1000*k == Y){
                cout << i << ' ' << j << ' ' << k << endl;
                return 0;
            }
        }
    }
    cout << "-1" <<' ' << "-1" << ' ' << "-1" << endl;
    return 0;
}



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

int main()
{
	int ans = 0,sum = 0,N,S[100];

	cin >> N;

	for (int n = 0; n < N; n++) {
		cin >> S[n];
		sum += S[n];
	}

	sort(S, S+N);

	if (sum % 10 == 0) {
		for (int n = 0; n < N; n++) {
			if (S[n] % 10 != 0) {
				ans = sum - S[n];
				break;
			}
		}
	}
	else ans = sum;

	cout << ans << endl;

	return 0;
}

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

const int kMaxn = 2e5 + 5;
const int MOD = 1e9 + 7;
int qpow(int x, int n);
int T, N, M, K;
int p[kMaxn];

int main() {
  //
  scanf("%d", &N);
  int sum = 0, sumpow2 = 0;
  for (int i = 1; i <= N; i++) {
    int x;
    scanf("%d", &x);
    sum = (sum + x) % MOD;
    sumpow2 = (sumpow2 + qpow(x, 2)) % MOD;
  }
  int ans;
  ans = 1LL * (qpow(sum, 2) - sumpow2 + MOD) % MOD * qpow(2, MOD - 2) % MOD;
  printf("%d\n", ans);
  return 0;
}

int qpow(int x, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res = 1LL * res * x % MOD;
    x = 1LL * x * x % MOD;
    n >>= 1;
  }
  return res;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    v_int a(100001, 0),b(100001, 0);

    int n; 
    cin >> n;
    irep(i, n) {
        int l, r;
        cin >> l >> r;
        a[l] += 1;
        a[r+1] += -1;
    }

    irep2(i, 1, 100000) {
        b[i] = b[i-1] + a[i];
    }

    int ans = 0;
    irep2(i, 1, 100000) {
        if(b[i]) { ans++; }
    }
    cout << ans << endl;
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        long k = scan.nextInt(), a = scan.nextInt(), b = scan.nextInt();
        if(b <= a) System.out.println(k+1);
        else {
            long total = 1;
            long yen = 0;
            for(int i = 0; i < k; i++) {
                if(yen > 0) {
                    total += yen * b;
                    yen--;
                }
                else if(total >= a && i < k-1) {
                    total -= a;
                    yen++;
                }
                else total++;
            }
            System.out.println(Math.max(k+1, total));
        }
    }
}


Measured memory_bytes: 23124
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main(){
	char str[1025];
	vector<string>vec;
	gets(str);
	int leng=strlen(str);
			string s;
	for(int i=0;i<leng;i++){
		if(str[i]==' ' || str[i]==',' || str[i]=='.'){
			if(s.size()>=3 && s.size()<=6){
				vec.pb(s);
			}
			s="";
		}
		else{
			s.pb(str[i]);
		}
	}
	cout << vec[0];
	for(int i=1;i<vec.size();i++){
		cout << " " << vec[i];
	}
	cout << endl;
}

Measured memory_bytes: 1168
fun main(){
    val n = readLine()!!.toInt()
    val (s,t) = readLine()!!.split(" ")
    var ans = ""
    for(i in 0 until n){
        val sub1 = s.substring(i,i+1)
        val sub2 = t.substring(i,i+1)
        ans += sub1+sub2
    }
    println(ans)
}

Measured memory_bytes: 35752
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
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; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);

ll Pow(ll x,ll n){
	ll res = 1;
	while(n > 0){
		if(n&1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	vi a(n);
	rep(i,n) cin >> a[i];
	map<int,int> mp;
	rep(i,n){
		int tmp = a[i];
		map<int,int> tmpt;
		for(int j = 2; j*j <= a[i]; j++){
			while(tmp%j == 0){
				tmp /= j;
				tmpt[j]++;
			}
		}
		if(tmp != 1) tmpt[tmp]++;
		for(auto t : tmpt){
			mp[t.first] = max(mp[t.first],t.second);
		}
	}

	//for(auto& m : mp) cout << m.first << " " << m.second << endl;
	ll sum = 1,ans = 0;
	for(auto& m : mp){
		sum = (sum*Pow(m.first,m.second))%MOD;
	}
	for(int i = 0; i < n; i++){
		ans = (ans+(sum*Pow(a[i],MOD-2))%MOD)%MOD;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 768
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator >> (istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif
int N;
vector<int> G[200000];
bool used[200000];
int grundy[200000];

int dfs(int i) {
	if (used[i]) return grundy[i];
	used[i] = true;
	if (G[i].empty()) return grundy[i] = 0;
	set<int> s;
	for (int to : G[i]) {
		int val = dfs(to);
		s.insert(val);
	}
	if(s.count(-1) > 0) return grundy[i] = -1;
	int ret = 0;
	while (s.count(ret) > 0) ++ret;
	return grundy[i] = ret;
}

bool loop(int i) {
	set<int> s;
	for (int to : G[i]) {
		int val = grundy[to];
		s.insert(val);
	}
	int p = 0;
	while (s.count(p) > 0) ++p;
	Fill(used, false);
	grundy[i] = p;
	if (dfs(i) == p) return true;

	s.insert(p);
	while (s.count(p) > 0) ++p;
	Fill(used, false);
	grundy[i] = p;
	if (dfs(i) == p) return true;
	return false;
}

int main() {
	cin >> N;
	REP(i, 0, N) {
		int a;
		cin >> a;
		G[a - 1].push_back(i);
	}
	Fill(grundy, -1);
	REP(i, 0, N) {
		if (used[i]) continue;
		dfs(i);
	}
	int* it = find(grundy, grundy + N, -1);
	cout << (loop(it - grundy) ? "" : "IM") << "POSSIBLE" << endl;
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);
    
    if (y >= 2019 && m > 4) {
        printf("TBD");
    }
    else {
        printf("Heisei");
    }
    
    return 0;
}

Measured memory_bytes: 256
N=int(input())

#正直者も発言に矛盾が生じない
L=[[-1]*N for _ in range(N)]
for i in range(N):
    A=int(input())
    for a in range(A):
        x,y=map(int, input().split())
        L[i][x-1]=y
ans=0
for b in range(2**N):
    ok=True
    for i in range(N):
        if b>>i&1==1:
            l=L[i]
            for j,x in enumerate(l):
                if x!=-1 and b>>j&1!=x:
                    ok=False
    if ok:
        ans=max(ans, bin(b).count("1"))

print(ans)


Measured memory_bytes: 3064
# AOJ 1102: Calculation of Expressions
# Python3 2018.7.14 bal4u

OVER = 10000

def factor():
	global w, pos
	if buf[pos] == '(':
		pos += 1
		f, v1 = calc()
		if not f: return [f, 0]
		pos += 1
	elif buf[pos] == 'i':
		pos += 1
		v1 = complex(0, 1)
	else:
		v1 = 0
		while pos < w and buf[pos].isdigit():
			v1 = 10*v1 + int(buf[pos])
			pos += 1
			if v1 > OVER: return [False, 0]
	return [True, v1]

def term():
	global w, pos
	f, v1 = factor()
	if not f: return [f, 0]
	while True:
		if pos >= w: break
		if buf[pos] != '*': break
		pos += 1
		f , v2 = factor()
		if not f: return [f, 0]
		v1 *= v2
		if abs(v1.real) > OVER or abs(v1.imag) > OVER: return [False, 0]
	return [True, v1]

def calc():
	global w, pos
	f, v1 = term()
	if not f: return [f, 0]
	while True:
		if pos >= w: break
		op = buf[pos]
		if op != '+' and op != '-': break
		pos += 1
		f , v2 = term()
		if not f: return [f, 0]
		if op == '+': v1 += v2
		else: v1 -= v2
		if abs(v1.real) > OVER or abs(v1.imag) > OVER: return [False, 0]
	return [True, v1]

while True:
	try: buf = list(input().strip())
	except: break
	w, pos = len(buf), 0
	f, ans = calc()
	if not f: print("overflow")
	elif ans.real == 0 and ans.imag == 0: print(0)
	elif ans.real == 0: print(int(ans.imag), 'i', sep='')
	elif ans.imag == 0: print(int(ans.real))
	else: print("{}{:+}i".format(int(ans.real), int(ans.imag)))



Measured memory_bytes: 5664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if ((a | b) == 0)
				break;
			b -= a;
			int ans1 = b / 1000;
			b %= 1000;
			int ans2 = b / 500;
			b %= 500;
			int ans3 = b / 100;
			System.out.println(ans3 + " " + ans2 + " " + ans1);
		}
	}
}

Measured memory_bytes: 24844
M, K = map(int, input().split())

if 2 ** M <= K:
    print(-1)
    exit()

if K == 0:
    ans = []
    for i in range(2 ** M):
        ans.append(i)
        ans.append(i)
    print(*ans, sep=' ')
    exit()

X = [a for a in range(2 ** M) if (a != 0) and (a != K)]
N = len(X)
L = X[: N // 2][::-1] + [0] + [K] + X[: N // 2]
R = X[N // 2:] + [K] + [0] + X[N // 2:][::-1]
ans = L + R


zl, zr = [i for i, a in enumerate(ans) if a == 0]
check = 0
for a in ans[zl : zr]:
    check ^= a

if check == K:
    print(*ans, sep=' ')
else:
    print(-1)


Measured memory_bytes: 18316
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;

int h,w;
char buf[55][55];

int dp[45][45][45][45];
int sum[55][55];
int gsum(int t,int l,int b,int r){
  return sum[b][r]-sum[b][l]-sum[t][r]+sum[t][l];
}
int main(){
  cin>>h>>w;
  REP(i,h) scanf("%s",buf[i]);
  int gx=-1,gy=-1;
  REP(i,h) REP(j,w) if(buf[i][j]=='P'){
    gy=i;gx=j;
  }
  REP(i,h) REP(j,w) sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+(buf[i][j]=='#'?1:0);
  REP(i,h+1) REP(j,h+1) REP(k,w+1) REP(l,w+1) dp[i][j][k][l]=INF;

  dp[0][h][0][w]=0;

  int res=INF;
  for(int hlen=h;hlen>=1;--hlen) for(int wlen=w;wlen>=1;--wlen){
    REP(i,h+1-hlen) REP(k,w+1-wlen){
      int j=i+hlen,l=k+wlen;
      int c=dp[i][j][k][l];
      if(i<=gy && gy<j && k<=gx && gx<l && c<INF){
        if(hlen==1 && wlen==1){
          chmin(res,c);
          continue;
        }

        auto doit=[&](int t,int y,int x){
          if(t==0) return gsum(i,k,i+y,k+x);
          if(t==1) return gsum(i,l-x,i+y,l);
          if(t==2) return gsum(j-y,l-x,j,l);
          if(t==3) return gsum(j-y,k,j,k+x);
        };
        chmin(res,c+doit(0,gy-i+1,gx-k+1));
        chmin(res,c+doit(1,gy-i+1,l-gx));
        chmin(res,c+doit(2,j-gy,l-gx));
        chmin(res,c+doit(3,j-gy,gx-k+1));

        REPN(i2,hlen,1) REPN(j2,wlen,1){
          REP(t,4){
            int co=c+doit(0,hlen,wlen)-doit(t,i2,j2)-doit((t+2)%4,hlen-i2,wlen-j2);
            if(t==0) chmin(dp[i+i2][j][k+j2][l],co);
            if(t==1) chmin(dp[i+i2][j][k][l-j2],co);
            if(t==2) chmin(dp[i][j-i2][k][l-j2],co);
            if(t==3) chmin(dp[i][j-i2][k+j2][l],co);
          }
        }
      }
    }
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 14848
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int N,K;	cin>>N>>K;
	vi A(N);
	rep(i,0,N) cin>>A[i];
	int ans;
	ans=1+(N-K)/(K-1);
	if((N-K)%(K-1)) ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3732
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//using ll=long long;
const double EPS = 1e-10;
inline bool equals(double a, double b) { return fabs(a - b) < EPS; }
const double PI = 3.141592653589793238;
class Point {
public:
	double x, y;
	Point(double x, double y) :x(x), y(y) {}
	Point() {}
	Point operator +(const Point &p) const{ return Point(x + p.x, y + p.y); };
	Point operator -(const Point &p) const{ return Point(x - p.x, y - p.y); }
	Point operator *(double k) { return Point(x*k, y*k); }
	Point operator /(double k) { return Point(x / k, y / k); }
};

using Vector = Point;
inline double norm(Vector a) {
	return a.x*a.x + a.y*a.y;
}
double absv(Vector a) {
	return sqrt(norm(a));
}
inline double dot(Vector a, Vector b) {
	return a.x*b.x + a.y*b.y;
}
inline double cross(Vector a, Vector b) {
	return a.x*b.y - a.y*b.x;
}
struct Segment {
	Point p1, p2;
};

using Line = Segment;
class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};
using Polygon = vector<Point>; 
Point project(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / norm(base);
	return s.p1 + base*r;
}
Point reflect(Segment s, Point p) {
	return p + (project(s, p) - p)*2.0;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2) {
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;
	if (cross(a, b) < -EPS) return CLOCKWISE;
	if (dot(a, b) < -EPS) return ONLINE_BACK;
	if (norm(a) < norm(b)) return ONLINE_FRONT;
	return ON_SEGMENT;
}

int main() {
	int x[2], y[2];
	int q, a, b;
	cin >> x[0] >> y[0] >> x[1] >> y[1] >> q;
	Point p0 = Point(x[0], y[0]);
	Point p1 = Point(x[1], y[1]);
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		Point p2 = Point(a, b);
		switch (ccw(p0, p1, p2)) {
		case 1:
			cout << "COUNTER_CLOCKWISE" << endl;
			break;
		case -1:
			cout << "CLOCKWISE" << endl;
			break;
		case 2:
			cout << "ONLINE_BACK" << endl;
			break;
		case -2:
			cout << "ONLINE_FRONT" << endl;
			break;
		default:
			cout << "ON_SEGMENT" << endl;
		}
	}
}

Measured memory_bytes: 3100
import sys
sys.setrecursionlimit(10**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 sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    p_list = LI()

    sortedp = sorted(p_list)

    cnt = 0
    for p, sp in zip(p_list, sortedp):
        if p != sp:
            cnt += 1

    if cnt == 0 or cnt == 2:
        print("YES")
    else:
        print("NO")

solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second

typedef long long ll;
const ll N=500;
const ll MAX = 10000000000000;
using namespace std;

ll n, a[N], pref[N];
ll dp[N][N];

ll solve(ll l, ll r){
	if(l==r)
		return 0;
	if(dp[l][r])
		return dp[l][r];

	ll ret=MAX;
	for(int i=l; i<r; i++){
		ll temp = solve(l, i) + solve(i+1, r);
		ret = min(ret, temp);
	}
	return dp[l][r] = ret + pref[r]-pref[l-1];
}

int main(){
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		pref[i] = pref[i-1]+a[i];
	}
	cout<<solve(1, n);
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		for(int i=0;i<N;i++) {
			array[i] = sc.nextInt();
		}
		int[] buff = array.clone();
		int M = sc.nextInt();
		int[][] arrayM = new int[M][2];
		long sum=0;

		for(int i=0;i<M;i++) {
			for(int j=0;j<2;j++) {
				arrayM[i][j] = sc.nextInt();
			}
		}

		for(int i=0;i<M;i++) {
			buff[arrayM[i][0]-1] = arrayM[i][1];
			for(int a:buff) {
				sum+=a;
			}
			System.out.println(sum);
			sum=0;
			buff=array.clone();
		}


	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int n;
ll wei;

//O(nW)では間に合わない、巨大ナップサック
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	cin>>n>>wei;
	vector<ll>v(n+1),w(n+1);
	rep(i,n)cin>>v[i]>>w[i];
	vector<pair<ll,ll>>p(1<<(n/2));//前半分を全列挙
	for(int i=0;i<1<<(n/2);++i){
		ll sw=0,sv=0;
		for(int j=0;j<n/2;++j){
			if(i>>j&1){
				sw+=w[j];
				sv+=v[j];
			}
		}
		p[i]=make_pair(sw,sv);
	}
	//無駄な要素を取り除く
	sort(p.begin(),p.end());
	int m=1;
	for(int i=1;i<1<<(n/2);++i){
		if(p[m-1].second<p[i].second){
			p[m]=p[i];//wi<=wjのとき、vi>=vjとなるものを更新せず、除去する
			m++;
		}
	}
	//後ろ半分も全列挙
	ll res=0;
	for(int i=0;i<1<<(n-n/2);++i){
		ll sw=0,sv=0;
		for(int j=0;j<n-n/2;++j){
			if(i>>j&1){
				sw+=w[n/2+j];
				sv+=v[n/2+j];
			}
		}
		if(sw<=wei){
			//無駄な要素を排除したので重さのおおきいものほど価値も大きくなっている
			ll tv=(lower_bound(p.begin(),p.begin()+m,make_pair(wei-sw,INF))-1)->second;
			//おなじものがあったとき、第二要素がINFになっているため、その直後のイテレータが返される。よって-1する。
			res=max(res,sv+tv);
		}
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 19200
#include<bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

struct edge {
  ll from, to, cost, dist;
};
struct vertex {
  ll cost, dist;
};
vector<vector<edge> > G;
vector<vertex> V;
vector<vll> D;
void answer() {
  ll INF = 1LL << 60;
  ll n, m, s;
  cin>>n>>m>>s;
  G.resize(n);
  V.resize(n);
  ll maxa = 0;
  rep(i,m) {
    ll u, v, a, b;
    cin>>u>>v>>a>>b;
    u--; v--;
    G[u].emplace_back((edge) {u, v, a, b});
    G[v].emplace_back((edge) {v, u, a, b});
    chmax(maxa, a);
  }
  ll max_cost = maxa*(n-1);
  chmin(s, max_cost);
  D.resize(max_cost+1, vector<ll>(n, INF));
  rep(i,n) {
    ll c, d;
    cin>>c>>d;
    V[i] = (vertex) {-c, d};
  }
  using node = tuple<ll, ll, ll>; // d, c, i
  priority_queue<node, vector<node>, greater<node> > que;
  que.push(make_tuple(0, s, 0));
  while(!que.empty()) {
    auto node = que.top(); que.pop();
    ll d = get<0>(node);
    ll c = get<1>(node);
    ll i = get<2>(node);
    if(D[c][i] <= d) continue;
    D[c][i] = d;
    if(c < max_cost) {
      que.push(make_tuple( d+V[i].dist, min(max_cost, c-V[i].cost), i ));
    }
    for(const auto& e : G[i]) if(e.cost <= c) {
      que.push(make_tuple( d+e.dist, c-e.cost, e.to ));
    }
  }
  REP(i, 1, n) {
    ll ans = INF;
    repc(j, max_cost) chmin(ans, D[j][i]);
    cout << ans << "\n";
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

int main() {
    double n, m, d;
    cin >> n >> m >> d;
    double ans;
    if (d == 0) {
        ans = (m - 1) / n;
    } else {
        ans = (m - 1) * 2 * (n - d) / pow(n, 2);
    }
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque


def bfs(links, s, limit):
    not_reachable = [True] * len(links)
    q = deque([(0, s, -1)])
    while q:
        cost, v, p = q.popleft()
        if cost > limit:
            break
        not_reachable[v] = False
        cost += 1
        q.extend((cost, u, v) for u in links[v] if u != p)
    return not_reachable


def solve(n, k, ab):
    if k == 1:
        return n - 2

    links = [set() for _ in range(n)]
    for a, b in zip(ab[0::2], ab[1::2]):
        a -= 1
        b -= 1
        links[a].add(b)
        links[b].add(a)

    ans = n
    thr = k // 2
    if k % 2 == 0:
        ans = min(sum(bfs(links, v, thr)) for v in range(n))
    else:
        dists = [bfs(links, v, thr) for v in range(n)]
        for a, b in zip(ab[0::2], ab[1::2]):
            a -= 1
            b -= 1
            ans = min(ans, sum(d1 and d2 for d1, d2 in zip(dists[a], dists[b])))
    return ans


n, k, *ab = map(int, sys.stdin.buffer.read().split())
print(solve(n, k, ab))


Measured memory_bytes: 81372
import sys

def main(n, a_n, q, bc_n):
    m = {}
    for i in range(n):
        if a_n[i] not in m:
            m[a_n[i]] = 0
        m[a_n[i]] += 1

    s = []
    for j in range(q):
        b, c = bc_n[j]

        diff = 0
        if b in m:
            diff = m[b] * c  - m[b] * b
            if c not in m:
                m[c] = m[b]
            else:
                m[c] += m[b]
            del m[b]

        ts = 0
        if len(s) == 0:
            for k, v in m.items():
                ts += k * v
        else:
            ts = s[-1] + diff
        s.append(ts)
    return s


n = int(sys.stdin.readline().strip())
a_n = [int(x) for x in sys.stdin.readline().strip().split(" ")]
q = int(sys.stdin.readline().strip())
bc_n = []
for _ in range(q):
    b, c = [int(x) for x in sys.stdin.readline().strip().split(" ")]
    bc_n.append((b, c))
for i in main(n, a_n, q, bc_n):
    print(i)


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

int main() {
  string s,ans;
  cin>>s;
  REP(i,s.size()) {
    if (s[i] == '0' || s[i] == '1') ans.push_back(s[i]);
    else if (ans.size() > 0) ans.pop_back();
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <set>


using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

template<class T> inline bool chmin(T& a, T b) {
  //aの方が大きければ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;
}
bool compare_a_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが小さい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second < r.second;
  }
}
bool compare_a_b_big(pair<int,int> l,pair<int,int> r){
  //firstが大きい方からソート、firstが同じならbが大きい方から
  if(l.first != r.first){
    return l.first>r.first;
  }
  else{
    return l.second > r.second;
  }
}
bool compare_b_small(pair<int,int> l,pair<int,int> r){
  //secondが小さい方からソート、firstが同じならfirstが小さい方から
  if(l.second != r.second){
    return l.second<r.second;
  }
  else{
    return l.first < r.first;
  }
}
const int INF = 1e9;




int main(){
  int a,b;
  cin >> a >> b;

  if(a>=10 || b>=10) cout << -1 << endl;
  else cout << a *b << endl;





}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



int main(){
    int n, ans = 0; cin >> n;
    ans += n / 25;
    n %= 25;
    ans += n / 10;
    n %= 10;
    ans += n / 5 + n % 5;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3112