akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

int main() {
    string S;
    cin >> S;
    vector<int> v;
    for (int i = 0; i < S.size();) {
        int j = i;
        while (j < S.size() && S[j] == S[i]) ++j;
        v.push_back(j-i);
        i = j;
    }
    vector<int> res(S.size(), 0);
    int sum = 0;
    int i = 0;
    if (S[i] == 'L') sum += v[i++];
    for (; i + 1 < v.size(); i += 2) {
        res[sum + v[i] - 1] = (v[i]+1)/2 + v[i+1]/2;
        res[sum + v[i]] = v[i]/2 + (v[i+1]+1)/2;
        sum += v[i] + v[i+1];
    }
    for (int i = 0; i < res.size(); ++i) cout << res[i] << " ";
    cout << endl;
}




Measured memory_bytes: 4092
H = int(input())
W = int(input())
N = int(input())

if H < W:
    if (N % W != 0):
        print(N // W + 1)
    else:
        print(N // W)
elif(H >= W):
    if (N % H != 0):
        print(N // H + 1)
    else:
        print(N // H)

Measured memory_bytes: 3060
import numpy as np
N,M = map(int,input().split())
AB_list = np.array([list(map(int,input().split())) for _ in range(N)])

cheapStore = np.argsort(AB_list[:,0])
ans = 0
need = M
store = 0
while need > 0:
    store_num = cheapStore[store]
    drink_num = AB_list[store_num][1]
    drink_cost = AB_list[store_num][0]
    if need>=drink_num:
        ans += drink_num * drink_cost
        need -= drink_num
    else:
        ans += need * drink_cost
        need = 0
    store += 1
        
print(ans)
     

Measured memory_bytes: 37868
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

int hmax[100005];
int acmax[100005];

signed main() {
    int W,H,N;cin >> W >> H >> N;
    REP (i,N) {
        int w,h;cin >> w >> h;
        hmax[h] = max(hmax[h],w);
    }

    for (int i = H - 1;i >= 0;i--) {
        acmax[i] = max(acmax[i+1],hmax[i]);
    }

    int ans = INF;
    REP (i,H) {
        ans = min(ans,i+acmax[i+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()

int main(){
	string S;
	ll K;
	cin >> S >> K;
	ll i=0;
	ll ans_one = 0;
	while(i < S.size()) {
		ll cnt = 1;
		while(S[i] == S[i+cnt] and i+cnt < S.size()) {
			cnt++;
		}
		ans_one += (cnt/2);
		i += cnt;
	}
	if(S[0] == S[S.size()-1]) {
		ll fcnt = 1, bcnt = 1;
		while(S[0] == S[fcnt] and fcnt < S.size()) fcnt++;
		while(S[S.size()-1] == S[S.size()-1-bcnt] and bcnt < S.size()) bcnt++;
		if(fcnt == S.size()) cout << ((ll)S.size() * K) / 2 << endl;
		else cout << ans_one * K + (K-1) * ((fcnt+bcnt)/2 - fcnt/2 - bcnt/2) << endl;
	} else {
		cout << ans_one * K << endl;
	}
}

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

int h, w;
char x[26][26];

int main(){
    cin >> h >> w;
    rep(i,h) rep(j,w){
        string str;
        cin >> str;
        if(str == "snuke"){
            char zz = 'A'+j;
            cout << zz <<i+1 << endl;
            return 0;
        }
    }
}


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

int main(int argc, char *argv[])
{
    int x, y, z, e, m;
    while (cin >> e, e) {
        m = 1000000;
        for (z = 0; z * z * z <= e; ++z) {
            y = sqrt(e - z * z * z);
            x = e - z * z * z - y * y;
            m = min(m, x + y + z);
        }
        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

// must be a <= b
long euclid(long a, long b) {
    if (a == 0)
        return b;
    return euclid(b % a, a);
}

void swap(long *a, long *b) {
    long tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int main() {
    long a, b;
    while (~scanf("%ld %ld", &a, &b)) {
        if (a > b)
            swap(&a, &b);
        long gcd = euclid(a, b);
        long lcm = a * b / gcd;
        printf("%ld %ld\n", gcd, lcm);
    }
    return 0;
}



Measured memory_bytes: 2040
N = input()
ans = 0
if len(N) % 2 == 0:
    a = len(N) - 1
    for i in range(1, a+1, 2):
        ans += 9*(10**(i-1))
else:
    a = len(N) - 2
    for i in range(1, a+1, 2):
        ans += 9*(10**(i-1))
    ans += int(N) - 10**(len(N)-1) + 1

print(ans)


Measured memory_bytes: 3060
from bisect import bisect_right, bisect_left
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A = [0] + A
a = list(accumulate(A))
answer = a[-1]

# 切り口はN-1個, 真ん中の選び方はN-3
for i in range(N - 3):
    left = a[i + 2]
    right = a[-1] - left
    p = bisect_left(a, left // 2)
    P1 = a[p]
    Q1 = left - P1
    P2 = a[p - 1]
    Q2 = left - P2
    if abs(P1 - Q1) <= abs(P2 - Q2):
        P = P1
        Q = Q1
    else:
        P = P2
        Q = Q2

    s = bisect_right(a, a[-1] - right // 2)
    S1 = a[-1] - a[s - 1]
    R1 = right - S1
    S2 = a[-1] - a[s]
    R2 = right - S2
    if abs(S1 - R1) <= abs(S2 - R2):
        S = S1
        R = R1
    else:
        S = S2
        R = R2

    answer = min(answer, max(P, Q, R, S) - min(P, Q, R, S))

print(answer)

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

int main(){
  string a,b;
  cin >> a >> b;
  bool ok=false;
  vector<char>ave(a.size());
  vector<char>bve(b.size());
  if(a.size()==b.size()){
  for(int i=0;i<a.size();i++){
    ave.at(i)=a.at(i);
  }
  for(int i=0;i<b.size();i++){
    bve.at(i)=b.at(i);
  }
  for(int i=0;i<a.size();i++){
    ok=true;
    int j=0;
    for(j=0;j<a.size()-i;j++){
      if(ave.at(j+i)!=bve.at(j)){
        ok=false;
        break;
      }
    }
    for(j=0;j<i;j++){
      if(ave.at(j)!=bve.at(a.size()+j-i)){
        ok=false;
        break;
      }
    }
    if(ok)
      break;
  }
  }
  cout << (ok?"Yes":"No") << endl;
  return 0;
}

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

class dice{	
public:
	int d[7];
	int set();
	int E();
	int W();
	int N();
	int S();
	int R();//?°´???????????¢
	int C(int *,int *,int *,int *);//??\??????????????????
};
int dice::set(){
	for(int i=1;i<=6;i++){
		cin>>d[i];
	}
	return 0;
}
int dice::C(int *w,int *x,int *y,int *z){
	int a[4];
	a[0]=*w;
	a[1]=*x;
	a[2]=*y;
	a[3]=*z;
	*w=a[3];
	*x=a[0];
	*y=a[1];
	*z=a[2];
	return 0;
}
int dice::E(){
	C(&d[1],&d[3],&d[6],&d[4]);
	return 0;
}
int dice::W(){
	C(&d[1],&d[4],&d[6],&d[3]);
	return 0;
}
int dice::N(){
	C(&d[1],&d[5],&d[6],&d[2]);
	return 0;
}
int dice::S(){
	C(&d[1],&d[2],&d[6],&d[5]);
	return 0;
}
int dice::R(){
	C(&d[2],&d[4],&d[5],&d[3]);
	return 0;
}
int main(){
	dice D[110];
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		D[i].set();
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)continue;
			int t=0;
			for(int k=0;k<4;k++){
				D[i].E();
				if(D[i].d[1]==D[j].d[1])break;
				if(k==3)t++;
			}
			for(int k=0;k<4;k++){
				D[i].N();
				if(D[i].d[1]==D[j].d[1])break;
				if(k==3)t++;
			}
			if(t==2)continue;
			t=0;
			for(int k=0;k<4;k++){
				D[i].R();
				if(D[i].d[2]==D[j].d[2])break;
				if(k==3)t++;
			}
			if(t==1)continue;
			t==0;
			for(int k=3;k<=6;k++){
				if(D[i].d[k]!=D[j].d[k])break;
				if(k==6){
					cout<<"No"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ");

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 200000;
int n, a;

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

    cin >> n;
    int cnt = 0;
    int bef = 0;
    REP(i, n) {
        cin >> a;
        if (bef < a) {
            bef = a;
        } else {
            cnt += (bef - a);
        }
    }
    
    cout << cnt << "\n";
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;

using Gragh = vector<vector<int>>;
struct LowLink
{
    int V;
    Gragh G;
    vector<int> used, order, lowlink, articulation;
    vector<pair<int, int>> bridges;
    LowLink(int V) : V(V)
    {
        G.resize(V);
        used.resize(V, 0);
        order.resize(V, 0);
        lowlink.resize(V, 0);
    }
    void add_edge(int s, int t) { G[s].emplace_back(t); }
    void dfs(int v, int p)
    {
        static int k = 0;
        used[v] = 1;
        order[v] = lowlink[v] = k++;
        int cnt = 0;
        bool flag = false;
        for(auto &u : G[v])
        {
            if(not used[u])
            {
                cnt++;
                dfs(u, v);
                lowlink[v] = min(lowlink[v], lowlink[u]);
                if(order[v] <= lowlink[u] and p != -1) flag = true;
                if(order[v] <= lowlink[u]) bridges.emplace_back(min(v, u), max(v, u));
            }
            else if(u != p) lowlink[v] = min(lowlink[v], order[u]);
        }
        if(p == -1 and cnt > 1) flag = true;
        if(flag) articulation.push_back(v);
    }
    void build() { dfs(0, -1); }
};

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E; cin >> V >> E;
    LowLink L(V);
    for(int i = 0; i < E; i++)
    {
        int s, t; cin >> s >> t;
        L.add_edge(s, t);
        L.add_edge(t, s);
    }
    L.build();
    sort(L.articulation.begin(), L.articulation.end());
    for(auto &ans : L.articulation) cout << ans << endl;
    return 0;
}


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

int main() {

  int N, W;
  cin >> N >> W;
  
  int w[N], v[N];
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  
  long dp[N+1][W+1];
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= W; j++) {
      dp[i][j] = 0L;
    }
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if(j-w[i]<0) {
        dp[i+1][j] = dp[i][j];
        continue;
      }
      dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 79104
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int M = Integer.parseInt(sc.next());
    int sum  = 0;
    for (int i = 0; i < M; i++) {
      sum = sum + Integer.parseInt(sc.next());
    }
    if(sum > N){
       System.out.print(-1);  
    }else{
       System.out.print(N - sum);
    }  
  }
}



Measured memory_bytes: 41488
//https://blog.csdn.net/hesorchen
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define lowbit(a) (a & (-a))
#define mod 1000000007
#define INF 0x3f3f3f3f
#define endl "\n"
#define MAX 100010
// 11000101011001101110100010101*
//   111010110111100110100010101
//  1011011100001101110100010101

string p;
string ans;
int main()
{
    int n;
    cin >> n;
    if (n > 0)
    {
        int m = n;
        while (m > 0)
        {
            if (m & 1)
                ans = '1' + ans;
            else
                ans = '0' + ans;
            m /= 2;
        }
        // cout << ans << endl;
        ans = "00" + ans;
        int len = ans.size();
        int temp = 0;
        for (int i = len - 1; i > 0; i--)
        {
            temp++;
            if (ans[i] >= '2')
            {
                ans[i] -= 2;
                ans[i - 1]++;
            }
            if (ans[i] >= '1' && temp % 2 == 0)
                ans[i - 1]++;
        }
        int f = 1;
        for (int i = 0; i < len; i++)
            if (ans[i] == 0 && f)
            {
                continue;
            }
            else if (ans[i] != '0' || f == 0)
            {
                f = 0;
                cout << ans[i];
            }
        cout << endl;
    }
    else if (n == 0)
        cout << "0" << endl;
    else
    {
        int m = -n;
        while (m > 0)
        {
            if (m & 1)
                ans = '1' + ans;
            else
                ans = '0' + ans;
            m /= 2;
        }
        ans = "00" + ans;
        int len = ans.size();
        int temp = 0;
        for (int i = len - 1; i > 0; i--)
        {
            temp++;
            if (ans[i] >= '2')
            {
                ans[i] -= 2;
                ans[i - 1]++;
            }
            if (ans[i] >= '1' && temp % 2)
                ans[i - 1]++;
        }
        int f = 1;
        for (int i = 0; i < len; i++)
            if (ans[i] == 0 && f)
            {
                continue;
            }
            else if (ans[i] != '0' || f == 0)
            {
                f = 0;
                cout << ans[i];
            }
        cout << endl;
    }

    return 0;
}

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

using P = pair<int, int>;

constexpr int INF = 1e9;

int main() {
    ll N, T;
    cin >> N >> T;
    ll res = 0;
    vector<ll> t(N);
    for(int i=0; i<N; ++i) {
        cin >> t[i];
        res += T;
        if(i != 0 && t[i] - t[i-1] <= T) {
            res += t[i] - t[i-1] - T;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
while(x->left!=NIL)
x=x->left;
return x;
}

Node treeMaximum(Node x){
while(x->right!=NIL)
x=x->right;
return x;

}

Node treeSearch(Node u, int k){
if(u == NIL || k == u->key) return u;
if (k < u->key)
return treeSearch(u->left, k);
else
return treeSearch(u->right, k);


}

Node treeSuccessor(Node x){
	Node y;
if (x->right != NIL)
return treeMinimum(x->right); // case 1
y = x->parent;
while (y != NIL && x == y->right) {
x = y;
y = y->parent;
}
return y; // case 2

}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL) {
  	y=x;
  	if(z->key < x->key) x = x->left;
  	else x = x->right;
  }
  	z->parent = y;
  	
  if (y == NIL) root =z;
  
  else if (z->key < y->key) y->left = z;

else y->right = z;



}

void inorder(Node u){
if(u==NIL) return;
inorder(u->left);
printf(" %d",u->key);
inorder(u->right);

}
void preorder(Node u){
if(u==NIL) return;
printf(" %d",u->key);
preorder(u->left);
preorder(u->right);

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}



Measured memory_bytes: 20456
# ABC110b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

if (max(max(x), X) < min(min(y), Y)):
    print('No War')
    exit()
print('War')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);

void solve(){
    int a, b, c; cin >> a >> b >> c;
    int res = a-b;
    if(res >= c) cout << 0 << endl;
    else cout << c-res << endl;
}

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

Measured memory_bytes: 256
N = int(input())
h = [int(x) for x in input().split()]
dp = []
dp1 = 0
dp2 = 0
for i in range(N):
    if i == 0:
        dp.append(0)
        continue

    if i == 1:
        dp.append(abs(h[0] - h[1]))
        continue

    dp1 = dp[i - 1] + abs(h[i] - h[i - 1])
    dp2 = dp[i - 2] + abs(h[i] - h[i - 2])

    if dp1 < dp2:
        dp.append(dp1)
    else:
        dp.append(dp2)
print(dp[-1])


Measured memory_bytes: 20444
s = input()
ans = 0
for i in range(1,len(s)+1):
    if i%2 == 1:
        if s[i-1] == "R" or s[i-1] == "U" or s[i-1] == "D":
            ans += 1
        else:
            print('No')
            exit()
    elif i%2 == 0:
        if s[i-1] == 'L' or s[i-1] == "U" or s[i-1] == "D":
            ans += 1
        else:
            print('No')
            exit()
if ans == len(s):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, M, studyDay, studyTime;
  cin >> N >> M;
  studyDay = 0;
  
  for (int i = 0; i < M; i++){
    cin >> studyTime;
		studyDay += studyTime;
  }

	if (N < studyDay){
		cout << "-1" << endl;
	}
	else
	{
		cout << N - studyDay << endl;
	}
}

Measured memory_bytes: 3620
import java.util.*;

import static java.lang.System.*;

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

        Map<Integer, Map<Integer, Long>> graph = new HashMap<>();
        for (int n = 0; n < N - 1; n++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            long c = sc.nextLong();

            updateGraph(a, b, c, graph);
            updateGraph(b, a, c, graph);
        }

        long[] distances = new long[N + 1];

        int Q = sc.nextInt();
        int K = sc.nextInt();

        dijkstra(N, graph, K, distances);

        int[] x = new int[Q];
        int[] y = new int[Q];
        for (int i = 0; i < Q; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        for (int i = 0; i < Q; i++) {
            out.println(distances[x[i]] + distances[y[i]]);
        }
    }

    public static void updateGraph(int a, int b, long c, Map<Integer, Map<Integer, Long>> graph) {
        Map<Integer, Long> to = new HashMap<>();
        if (graph.containsKey(a)) {
            to = graph.get(a);
        }
        to.put(b, c);
        graph.put(a, to);
    }

    // 空間計算量を減らすため、graphは配列で持たず、Map構造で持つ
    // valueのmapは、key: 次のノード, value: 次のノードにいくためのコスト
    public static void dijkstra(int n, Map<Integer, Map<Integer, Long>> graph, int start, long[] distances) {
        final long INF = Long.MAX_VALUE;

        // 初期化
        Arrays.fill(distances, INF);
        distances[start] = 0;
        Queue<Integer> nodesQueue = new PriorityQueue<Integer>();
        nodesQueue.add(start);

        // 計算
        while (!nodesQueue.isEmpty()) {
            int node = nodesQueue.poll();

            Map<Integer, Long> toNodeCosts = graph.get(node);
            for (Map.Entry<Integer, Long> e : toNodeCosts.entrySet()) {
                int toNode = e.getKey();
                long moveCost = e.getValue();
                if (moveCost > 0 && distances[node] != INF && distances[toNode] > distances[node] + moveCost) {
                    distances[toNode] = distances[node] + moveCost;
                    nodesQueue.add(toNode);
                }
            }
        }
    }
}

Measured memory_bytes: 190276
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;

    vector<long long> dp(4, 0);
    dp[0] = 1;
    auto ndp = dp;

    const long long MOD = 1000000007;
    for (int i = 0; i < n; ++i) {
        fill(ndp.begin(), ndp.end(), 0);
        for (int j = 0; j < 4; ++j) {
            if (dp[j] == 0) {
                continue;
            }
            (ndp[j] += dp[j] * 8 % MOD) %= MOD;
            {
                int nj = j | 1;
                (ndp[nj] += dp[j]) %= MOD;
            }
            {
                int nj = j | 2;
                (ndp[nj] += dp[j]) %= MOD;
            }
        }
        swap(ndp, dp);
    }

    cout << dp[3] << '\n';

    return 0;
}

Measured memory_bytes: 3640
S=list(input())
N=len(S)
alphabet="abcdefghijklmnopqrstuvwxyz"
Appeared,A_to_N={},{}
for i in range(26):
  Appeared[alphabet[i]]=False
  A_to_N[alphabet[i]]=i
if N<26:
  for i in range(N):
    Appeared[S[i]]=True
  for i in range(26):
    if not Appeared[alphabet[i]]:
      S.append(alphabet[i])
      print("".join(S))
      exit()

last=A_to_N[S[-1]]
a=[S[-1]]
for i in range(N-1)[::-1]:
  if A_to_N[S[i]]>last:
    a.append(S[i])
    last=A_to_N[S[i]]
  else:
    for k in a:
      if A_to_N[S[i]]<A_to_N[k]:
        S[i]=k
        print("".join(S[:i+1]))
        exit()
print(-1)
    


Measured memory_bytes: 38484
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    int D, T, S;
    cin >> D >> T >> S;

    if ((S * T) < D)
    {
        cout << "No"
             << "\n";
    }
    else
    {
        cout << "Yes"
             << "\n";
    }
}


Measured memory_bytes: 3052
n=int(input())
a = list(map(int,input().split()))
i = 0
while True:
    if i==n:
        print('APPROVED')
        break
    elif a[i]%2==0 and a[i]%3!=0 and a[i]%5!=0:
        print('DENIED')       
        break       
    else:
        i+=1

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << a + b << endl;
	}
}

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

using namespace std;

int main(){
    int bkt[26] = {0};
    int cnt = 0;
    char S;

    for(int i=0;i<4;i++)
    {
        cin >> S;
        bkt[S-65]+=1;
    }

    for(int j=0;j<26;j++)
    {
        if(bkt[j] == 2) cnt += 1;
    }

    if(cnt == 2)
    {
        cout << "Yes" << endl;
        return(0);
    }

    cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define take freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);freopen("error.txt","w",stderr);
#define speed ios_base::sync_with_stdio(false);
#define int long long
#define endl "\n"
#define maxi 10000007
int maxo=1e9+7;
int sum=0;
#define rof(i,a,b) for(int i=a;i<b;i++)
void solve(int a[],int i,int s,int p,int n)
{
    if(s==2)
    {
        sum=sum%maxo+ p%maxo;
        return;
    }
    for(int j=i;j<n;j++)
    {
        solve(a,j+1,s+1,((p%maxo)*a[j]%maxo)%maxo,n);
    }
}
int32_t main()
{
    speed
    //take
    int n;
    cin>>n;
    int a[n];
    int sum1=0;
    int sum2=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum1+=a[i];
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        sum2+=a[i];
        ans=((a[i]%maxo)*((sum1-sum2)%maxo))%maxo+ans%maxo;

    }
    cout<<ans;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	VL a(n);
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += a[i];
	}
	vector<PLL> cb(m);
	VL b(m),c(m);
	for (int i = 0; i < m; i++) {
		int b,c;
		cin >> b >> c;
		cb[i] = {c,b};
	}
	SORT(a);
	sort(RALL(cb));
	int v = 0;
	for (int i = 0; i < m; i++) {
		if (a[v] < cb[i].first) {
			for (int j = 0;j < cb[i].second;j++) {
				ans += cb[i].first - a[v];
				a[v] = cb[i].first;
				if (a[v+1] >= cb[i].first or v+1 == n) {
					break;
				}
				v++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
const int Maxn = 1e5 + 1000;
int n, m, p, q, c, dis[ Maxn ];
vector < pair < int, int > > v[ Maxn ];
std::set < int > elvahs[ Maxn ];
bool vis[ Maxn ];
using std::make_pair;
int main( )
{
	std::ios::sync_with_stdio( false );
	cin >> n >> m;
	For( i, 1, m )
	{
		cin >> p >> q >> c;
		v[ q ].push_back( make_pair( p, c ) );
		v[ p ].push_back( make_pair( q, c ) );
	}
	std::priority_queue < pair < int, int >, vector < pair < int, int > >, std::less < pair < int, int > > > Q;
	std::memset( dis, 63, sizeof dis );
	Q.push( make_pair( dis[ 1 ] = 0, 1 ) );
	while( !Q.empty( ) )
	{
		auto tp = Q.top( );
		Q.pop( );
		if( vis[ tp.second ] )
			continue;
		vis[ tp.second ] = 1;
		for( auto &i: v[ tp.second ] )
		{
			bool k = elvahs[ tp.second ].count( i.second );
			if( !k + dis[ tp.second ] < dis[ i.first ] )
			{
				dis[ i.first ] = !k + dis[ tp.second ];
				elvahs[ i.first ].clear( );
				Q.push( make_pair( -dis[ i.first ], i.first ) );
				elvahs[ i.first ].insert( i.second );
			}
			else if( !k + dis[ tp.second ] == dis[ i.first ] )
				elvahs[ i.first ].insert( i.second );
		}
	}
	cout << ( dis[ n ] == 0x3f3f3f3f ? -1 : dis[ n ] );
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);

  for(int i = 0;i < N;i++)cin >> H[i];

  for(int i = 1;i < N;i++){
    if(H[i-1] > H[i])H[i]++;
  }

  bool flag = true;

  for(int i = 1;i < N;i++){
    if(H[i-1] > H[i])flag = false;
  }

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


Measured memory_bytes: 640
import java.io.File;
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		for(int i = 0; i < H; i++){
			String s = sc.next();
			System.out.println(s+"\n"+s);
		}
	}
}

Measured memory_bytes: 24276
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Friends
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];
  UFT() {}

  void init(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }

  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }

  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }

  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (r0 == r1) return r0;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    }
    else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    }
    else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};

/* global variables */

UFT uft;

/* subroutines */

/* main */

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

  uft.init(n);
  
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    uft.merge(a, b);
  }

  int maxsz = 0;
  for (int i = 0; i < n; i++) {
    int sz = uft.size(i);
    if (maxsz < sz) maxsz = sz;
  }

  printf("%d\n", maxsz);
  return 0;
}


Measured memory_bytes: 6168
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int K = Integer.parseInt(S[1]);
    int[] val = new int[N];
    for(int i = 0; i < K; i++){
      int A = Integer.parseInt(sc.nextLine());
      S = sc.nextLine().split(" ");
      for(int j = 0; j < A; j++){
        int b = Integer.parseInt(S[j])-1;
        val[b]++;
      }
    }
    int ans = 0;
    for(int c : val){
      if(c == 0){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 36968
N = int(input())
list = [input() for i in range(N)]

c_0 = 0
c_1 = 0
c_2 = 0
c_3 = 0

for string in list:
  if string == 'AC':
    c_0 += 1
  elif string == 'WA':
    c_1 += 1
  elif string == 'TLE':
    c_2 += 1
  elif string == 'RE':
    c_3 += 1

print('AC x ' + str(c_0))
print('WA x ' + str(c_1))
print('TLE x ' + str(c_2))
print('RE x ' + str(c_3))

Measured memory_bytes: 16168
#include <iostream>
#include <math.h>
using namespace std;


int main(){
	long long int ans = 1;
	int n, m;
	cin >> n >> m;
	if(abs(n - m) >= 2){
		cout << 0 << endl;
		return 0;
	}
	else if(abs(n-m) == 0){
		ans = 2;
	}
	for(int i = n;i>0;i--){
		ans = ans * i % (long long int)(pow(10, 9) + 7);
	}
	for (int i = m; i>0; i--) {
		ans = ans * i % (long long int)(pow(10, 9) + 7);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  vl sum(n+1);
  sum[0]=0;
  rep(i,n){
    cin >> a[i];
    sum[i+1]=sum[i]+a[i];
  }
  sort(sum.begin(),sum.end());
  ll cnt=0;
  ll k=0;
  rep(i,n){
    if(sum[i]==sum[i+1]){
      k++;
    }
    else{
      cnt+=k*(k+1)/2;
      k=0;
    }
  }
  cnt+=k*(k+1)/2;
  cout << cnt << endl;
}

Measured memory_bytes: 3328
import java.util.*;
import java.beans.IntrospectionException;
import java.io.*;
 
public class Main {
	public static long GCD(long a, long b) {
		if(b==0)return a;
		if(a==0)return b;
		return (a>b)?GCD(a%b, b):GCD(a, b%a);
	}
	public static long LCM(long a, long b) {
		return a*b/GCD(a, b);
	}
	public static long nCk(int n, int k) { //O(K)
		if (k > n) {
			return 0;		
		}
		long res = 1;
		for(int i = 1; i<=k; i++) {
			res = (n - k + i) * res/i;
		}
		return res;
	}
	public static long C(int a, int b, long[][] s) {
		int m = (int) 1e9 + 7;
		if (s[a][b] >= 0) {
			return s[a][b];
		} else if (a < b | a < 0 | b < 0) {
			s[a][b] = 0;
			return 0;
		} else if (a == b | b == 0) {
			s[a][b] = 1;
			return 1;
		} else {
			return s[a][b] = (C(a - 1, b, s) % m + C(a - 1, b - 1, s) % m) % m;
		}
 
	}
 
	public static void main(String[] args) throws Exception {
 
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n=sc.nextInt();
		Integer[] s=new Integer[n];
		boolean t=true;
		for(int i=0;i<n;i++) {
			s[i]=sc.nextInt();
		}
		Arrays.sort(s);
		for(int i=1;i<n;i++) {
			if(s[i].equals(s[i-1])) {
				t=false;
				break;
			}
		}
		System.out.println(t?"YES":"NO");
		pw.close();
		
		
	}
 
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
			
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}
	static class pair implements Comparable<pair>  {
		int x;
		int y;
		public pair(int x,int y) {
			this.x=x;
			this.y=y;
		}
		public String toString(){
			return x+" "+y;
		}
		public int compareTo(pair other) {
			if(this.x==other.x) {
				return this.y-other.y;
			}
			else {
				return this.x-other.x;
			}
		}
	}
 
}


Measured memory_bytes: 48560
n=int(input())
cc=[int(input()) for _ in range(n)]


c=[cc[0]]
for i in range(1,n):
    if cc[i]!=cc[i-1]:
        c.append(cc[i])

n=len(c)

right_index=[-1]*n
tmp_right_index=[-1]*(max(c)+1)

for i in range(n):
    if tmp_right_index[c[i]]==-1:
        tmp_right_index[c[i]]=i
    else:
        right_index[i]=tmp_right_index[c[i]]
        tmp_right_index[c[i]]=i

dp=[0]*n
mod=10**9+7
#print(0,c)
for i in range(n):
    if i==0:
        dp[i]=1
    else:
        if right_index[i]==-1:
            dp[i]+=dp[i-1]%mod
        else:
            dp[i]+=dp[i-1]+dp[right_index[i]]%mod

print(dp[-1]%mod)







    



Measured memory_bytes: 106244
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

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

  string S,T;
  cin>>S>>T;
  int sn=S.length(),tn=T.length();
  vector<vector<ll>>table(26,vector<ll>(sn, -1));

  REP(i,26){
    REP(j,sn){
      if(S[j]==i+'a'){
        table[i][0]=j+1;
        break;
      }
    }
  }

  REP(i,26){
    if(table[i][0]==-1)continue;
    FOR(j,1,sn){
      table[i][j]=table[i][j-1]-1;
      if(table[i][j]==0){
        FOR(k,j,sn){
          if(S[k]==i+'a'){
            table[i][j]=k-j+1;
            break;
          }
        }
      }
      if(table[i][j]==0){
        table[i][j]=table[i][0]+sn-j;
      }
    }
  }

  // REP(i,26){
  //   cout<<(char)('a'+i)<<endl;
  //   REP(j,sn){
  //     cout<<table[i][j]<<endl;
  //   }
  // }

  ll ans=0ll;
  REP(i,tn){
    if(table[T[i]-'a'][ans%sn]==-1){
      ans=-1;
      break;
    }
    ans+=table[T[i]-'a'][ans%sn];
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 21712
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            double x1 = sc.nextDouble();
            double y1 = sc.nextDouble();
            double x2 = sc.nextDouble();
            double y2 = sc.nextDouble();
            System.out.println(Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
        }
    }

}



Measured memory_bytes: 27920
#include<iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    
    if(a < b){
        cout << "a < b" << endl;
    }
    else if(a > b){
        cout << "a > b" << endl;
    }
    else{
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3080
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int m1=in.nextInt();
		int d1=in.nextInt();
		int m2=in.nextInt();
		int d2=in.nextInt();
		if(d2==1&&m1+1==m2)
		{
			System.out.println(1);
		}
		else
		{
			System.out.println(0);
		}
	}
}
	

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

void linear_search();
void linear_search2();


int main() {
  linear_search2();
  return 0;
}

//愚直に計算するとこうなる
void linear_search() {
  int n, q;
  cin >> n;
  vector<ll> S(n);
  rep(i, n) cin >> S[i];
  cin >> q;
  vector<ll> T(q);
  rep(i, q) cin >> T[i];

  int sum = 0;
  rep(j, q) {
    rep(i, n) {
      if (T[j] == S[i]) {
        sum++;
        i = n;
      }
    }
  }
  cout << sum << endl;
}

//”番兵”による高速化
void linear_search2() {
  int n, q;
  cin >> n;
  vector<ll> S(n);
  rep(i, n) cin >> S[i];
  cin >> q;
  vector<ll> T(q);
  rep(i, q) cin >> T[i];

  int sum = 0;
  rep(j, q) {
    int key = T[j];
    S.push_back(key);
    int i = 0;
    while (S[i] != key) i++;

    if (i != n) sum++;
    S.pop_back();
  }

  cout << sum << endl;
}



Measured memory_bytes: 3220
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 1e6 + 20 , mod = 998244353 ;
int n , m , ans , tot ;
int fac[N] , ifac[N] , inv[N] ;

inline int f (int a , int b) {
	return 1ll * fac[a + b] * ifac[a] % mod * ifac[b] % mod ;
}

void pre () {
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1 ;
	for (int i = 2 ; i < N ; i ++) {
		inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod ;
		fac[i] = 1ll * i * fac[i - 1] % mod ;	
		ifac[i] = 1ll * inv[i] * ifac[i - 1] % mod ;
	}
}

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

	pre() ;

	cin >> n >> m ;

	if (n > m) swap(n , m) ;

	ans = m ;
	tot = 1ll * ifac[n + m] * fac[n] % mod * fac[m] % mod ;

	for (int i = 1 ; i <= n ; i ++) {
		ans = (ans + 1ll * f(n - i , m - i) * f(i , i) % mod * tot % mod * inv[2]) % mod ;	
	}

	cout << ans << '\n' ;
}


Measured memory_bytes: 12032
#include<stdio.h>
int main()
{
  int n,w,h;
  int x,y;
  int place[100][100];
  int s,t;
  int i,j,k,l;
  int sum,max;
  while(1)
    {
      scanf("%d",&n);
      if(n==0) break;
      scanf("%d%d",&w,&h);
      for(i=0;i<w;i++)
	{
	  for(j=0;j<h;j++)
	    {
	      place[i][j]=0;
	    }
	}
      for(i=0;i<n;i++)
	{
	  scanf("%d%d",&x,&y);
	  place[x-1][y-1]=1;
	}
      scanf("%d%d",&s,&t);
      max=0;
      for(i=0;i<w-s+1;i++)
	{
	  for(j=0;j<h-t+1;j++)
	    {
	      sum=0;
	      for(k=0;k<s;k++)
		{
		  for(l=0;l<t;l++)
		    {
		      sum+=place[i+k][j+l];
		    }
		}
	      if(sum>max) max=sum;
	    }
	}
      printf("%d\n",max);
    }
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x) (x.begin(),x.end()) 
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 
 
int32_t main(){
  fast; 
/*  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif */
    
  int T=1; //cin>>T; 
  while(T--){

    int n,k; cin>>n>>k; 
    int sum=0; 
    vi a(n); for(int i=0;i<n;i++){  cin>>a[i] ; sum+=a[i];  }

    SORTR(a); 

    if(n>k){
        for( int i=0;i<k;i++){
            sum-=a[i]; 
        }
    }
    else sum=0; 
    cout<<sum<<endl; 
  






  }
    


  return 0; 
} 

Measured memory_bytes: 4680
#include <iostream>
 
int main(){
    int d;
     
    while(std::cin >> d){
        int sum = 0;
        for(int i = d; i < 600; i += d){
            sum += i*i*d;
        }
         
        std::cout << sum << std::endl;
    }
     
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007


void solve(void)
{ 
  int N,T;
  cin>>N>>T;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }

  int MIN = INF;
  int MAX = 0;
  int count = 0;

  for (int i = 0; i < N; i++)
  {
    int profit = vec[i] - MIN;
    if(profit > MAX)
    {
      MAX = profit;
      count = 1;
    }
    else if(profit == MAX)
    {
      count++;
    }

    MIN = min(vec[i],MIN);
  }
  
  cout<<count<<endl;
  return;  
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 1024
a,b = map(int, input().split())

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

    divisors.sort()
    return divisors

def is_prime(n):
    if n <= 1: return False
    for i in range(2, int(n**0.5)+1):
        if n%i == 0: return False
    return True

ab = list(set(make_divisors(a)) & set(make_divisors(b)))

ans = 1
for i in ab[1:]:
    if is_prime(i): ans += 1
print(ans)

Measured memory_bytes: 5120
#include<iostream>
#include<string>

int main()
{
  std::string S;
  int w;
  
  std::cin >> S;
  std::cin >> w;

  int len_S = S.size();
  for(int i=0; i<len_S; i+=w)
    {
      std::cout << S[i];
    }

  putchar('\n');
  
  return 0;
}

Measured memory_bytes: 256