akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Node
{
public:
    string shiin, boin;
};

int main()
{
    vector<bool> isBoin(128, false);
    isBoin['a'] = isBoin['i'] = isBoin['u'] = isBoin['e'] = isBoin['o'] = true;

    set<string> boin;
    boin.insert("a");
    boin.insert("i");
    boin.insert("u");
    boin.insert("e");
    boin.insert("o");

    set<string> musei, museiSoku;
    museiSoku.insert("k");
    museiSoku.insert("s");
    museiSoku.insert("t");
    museiSoku.insert("h");
    museiSoku.insert("p");
    for(set<string>::iterator it=museiSoku.begin(); it!=museiSoku.end(); ++it){
        musei.insert(*it);
        musei.insert(*it + 'y');
    }
    for(set<string>::iterator it=musei.begin(); it!=musei.end(); ++it){
        museiSoku.insert(*it);
        museiSoku.insert((*it)[0] + *it);
    }

    for(;;){
        string s;
        cin >> s;
        if(s == "#")
            return 0;
        int n = s.size();

        vector<Node> nodes;
        int i = 0;
        while(i < n){
            Node node;
            if(s[i] == 'n'){
                if(i+1 < n && s[i+1] == '\''){
                    node.shiin = "n\'";
                    nodes.push_back(node);
                    i += 2;
                    continue;
                }else if(i + 1 >= n || (s[i+1] != 'y' && !isBoin[s[i+1]])){
                    node.shiin = "n";
                    nodes.push_back(node);
                    ++ i;
                    continue;
                }
            }

            while(!isBoin[s[i]]){
                node.shiin += s[i];
                ++ i;
            }
            while(i < n && isBoin[s[i]]){
                node.boin += s[i];
                ++ i;
            }
            nodes.push_back(node);
        }
        int m = nodes.size();

        vector<bool> ret(m, false);
        for(int i=0; i<m; ++i){
            if(nodes[i].boin == "i" || nodes[i].boin == "u"){
                if(museiSoku.find(nodes[i].shiin) != museiSoku.end()){
                    if(i == m-1 || museiSoku.find(nodes[i+1].shiin) != museiSoku.end())
                        ret[i] = true;
                }
            }
            if(i < m-1 && (nodes[i].boin == "a" || nodes[i].boin == "o")){
                if(museiSoku.find(nodes[i].shiin) != museiSoku.end() && musei.find(nodes[i+1].shiin) != musei.end()){
                    if(nodes[i].boin == nodes[i+1].boin.substr(0,1))
                        ret[i] = true;
                }
            }
        }

        for(int i=0; i<m; ++i){
            if(ret[i]){
                cout << nodes[i].shiin << '(' << nodes[i].boin << ')';
                if(i < m-1)
                    ret[i+1] = false;
            }else{
                cout << nodes[i].shiin << nodes[i].boin;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1212
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
cin.tie(0);
ll x[5];
cin >>x[0]>>x[1]>>x[2]>>x[3]>>x[4];
  
for(int i=0;i<=5;i++){
 if(x[i]==0){
  cout << i+1; 
  return 0;
 }
}


return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

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

  string s; cin >> s;
  int n = s.size();
  ll ans = 0;
  ll b = 0;
  rep(i, n) {
    if(s[i] == 'W') {
      ans += b;
    } else {
      ++b;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 720
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ab = abs(a-b), bc = abs(b-c), ca = abs(c-a);
    VI s = {ab, bc, ca};
    SORT(s);
    cout << s[0] + s[1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main (){
    string S;
    cin >> S;
    string t[6] = {"abc","acb","bac","bca","cab","cba"};
    for(int i=0; i<6; i++){
        if( S == t[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

#define REP(i,n) for (int i=0;i<(n);++i)
#define REP2(i,n) for (int i=0;i<=(n);++i)
#define REP3(i,n) for (int i=1;i<=(n);++i)

static const int MAXN = 1001;
static const int MAXM = 1001;
static const int INF = 1e5;

int N, M;
int G[MAXN][MAXN];

int a[MAXM],b[MAXM];

int dist[MAXN][MAXN];

int main() {

	REP(i, MAXN) {
		REP(j, MAXN) {
			G[i][j] = INF;
		}
	}

	cin >> N >> M;
	REP(i, M) {
		int ai,bi,ci;
		cin >> ai >> bi >> ci;
		G[ai][bi] = ci;
		G[bi][ai] = ci;
		a[i] = ai;
		b[i] = bi;
	}

	//Dijkstra's Algorithm
	REP3(i, N) {
		int color[MAXN];//white=1,gre=2,black=3
		int p[MAXN];
		REP3(j, N) {
			dist[i][j] = INF;
			color[j] = 1;
		}
		dist[i][i] = 0;
		p[i] = -1;

		while (true) {
			int mincost,u;
			mincost = INF;
			REP3(j, N) {
				if ((color[j] != 3) && (dist[i][j] < mincost)) {
					mincost = dist[i][j];
					u = j;
				}
			}

			if (mincost == INF) {
				break;
			}

			color[u] = 3;

			REP3(j, N) {
				if ((color[j] != 3) && (G[u][j] < INF)) {
					if (dist[i][u] + G[u][j] < dist[i][j]) {
						dist[i][j] = dist[i][u] + G[u][j];
						p[j] = u;
						color[j] = 2;
					}
				}
			}
		}

	}

	/*
	REP3(i, N) {
		REP3(j, N) {
			cout << i << " " << j << " " << dist[i][j] << endl;
  		}
	}
	*/

	int res,tmp;
	res = 0;

	REP(i, M) {
		tmp = 0;
		REP3(j, N) {
			if ((dist[j][b[i]] == dist[j][a[i]] + G[a[i]][b[i]]) && (j != b[i])) {
				++tmp;
			}
		}
		if (tmp == 0)++res;
	}
	
	cout << res << endl;

	int end;
	cin >> end;

	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <vector>

using namespace std;

const int kInf = 1e9;

int a[510][510];

void Solve() {
	int n, m, h, w;
	cin >> n >> m >> h >> w;

	int pos = 600;
	int neg = -(pos * (h * w - 1) + 1);
	long long sum = 0;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (i % h == h-1 && j % w == w-1) {
				a[i][j] = neg;
			} else {
				a[i][j] = pos;
			}

			// cerr << a[i][j] << " ";

			sum += a[i][j];
		}
		// cerr << "\n";
	}

	if (sum < 0) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				cout << a[i][j] << " ";
			}
			cout << "\n";
		}
	}
}

int main() {
	int tests = 1;
	for (;tests; --tests) {
		Solve();
	}
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

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

    vector<long long> cost(N,LLONG_MAX);

    cost[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            if (i + j < N)
                cost[i + j] = min(cost[i + j], cost[i] + abs(a[i + j] - a[i]));
        }
        
    }
    cout << cost[N-1] << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int N, K;
vector <int> G[2005];
int visited[2005];

void dfs(int x, int c) {
    if (visited[x] > 0 && visited[x] < c) {
        return;
    } else {
        visited[x] = c;
    }

    for (int i = 0; i < G[x].size(); i++) {
        dfs(G[x][i], c+1);
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> K;
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int mn = N;
    if (K % 2 == 0) {
        for (int i = 1; i <= N; i++) {
            fill(visited, visited+2005, 0);
            dfs(i, 1);

            int tmp = N;
            for (int i = 1; i <= N; i++) {
                if (visited[i] <= K / 2 + 1) {
                    tmp--;
                }
            }
            mn = min(mn, tmp);
        }
    } else {
        for (int i = 1; i <= N; i++) {
            for (int j = 0; j < G[i].size(); j++) {
                fill(visited, visited+2005, false);
                dfs(i, 1);
                dfs(G[i][j], 1);

                int tmp = N;
                for (int i = 1; i <= N; i++) {
                    if (visited[i] <= K / 2 + 1) {
                        tmp--;
                    }
                }
                mn = min(mn, tmp);
            }
        }
    }

    cout << mn << "\n";
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
string i;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a;
  cin >>a;
  if(a>=1200) cout <<"ARC\n";
  else cout <<"ABC\n";
  return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
ans = 0
first = min(b, c)
b -= first
c -= first
ans += first * 2
if b == 0 and c == 0:
    pass
elif b == 0:
    if a == c:
        ans += c
    elif a > c:
        ans += c
    else:
        ans += a+1
else:
    ans += b
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int64_t INF = (1LL << 62);
int64_t N, K, MAXN = 100010;
vector<vector<pair<int, int>>> Graph(MAXN);

int64_t dijkstra(int64_t start, int64_t goal)
{
  priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>, greater<pair<int64_t, int64_t>>> PQ;
  vector<int64_t> Color(MAXN, 0), D(MAXN, INF);

  D.at(start) = 0;
  PQ.push(make_pair(0, start));
  Color.at(start) = 1;

  while (!PQ.empty())
  {
    pair<int64_t, int64_t> f = PQ.top();
    PQ.pop();
    int64_t u = f.second;
    Color.at(u) = 2;
    if (D.at(u) < f.first)
      continue;
    for (int i = 0; i < Graph.at(u).size(); i++)
    {
      int64_t v = Graph.at(u).at(i).first;
      if (Color.at(v) == 2)
        continue;
      if (D.at(v) > D.at(u) + Graph.at(u).at(i).second)
      {
        D.at(v) = D.at(u) + Graph.at(u).at(i).second;
        PQ.push(make_pair(D.at(v), v));
        Color.at(v) = 1;
      }
    }
  }
  return D.at(goal);
}

int main()
{
  cin >> K;
  for (int i = 0; i < K; i++)
  {
    Graph.at(i).push_back(make_pair((i + 1) % K, 1));
    Graph.at(i).push_back(make_pair((i * 10) % K, 0));
  }
  cout << dijkstra(1, 0) + 1 << endl;
}


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

long long MOD = 1000000007;

long long Calc(long long A, long long B) {
	if (B == 0) return 1;
	if (B % 2 == 0) {
		long long C = Calc(A, B / 2);
		return (C * C) % MOD;
	}
	return (A * Calc(A, B - 1)) % MOD;
}

int main() {
	long long N, ANS = 0;
	map<long long, long long> mpX;
	cin >> N;
	vector<long long> B(N);

	for (int i = 0; i < N; i++) {
		cin >> B[i];
		long long A = B[i];
		for (int j = 2; j * j <= A; j++) {
			long long COUNT = 0;
			while (A % j == 0) {
				COUNT++;
				A /= j;
			}
			if (COUNT != 0) {
				mpX[j] = max(mpX[j], COUNT);
			}
		}
		if (A != 1) {
			mpX[A] = max(mpX[A], 1LL);
		}
	}
	long long MUL = 1;
	for (auto it = mpX.begin(); it != mpX.end(); it++) {
		MUL *= Calc(it->first, it->second);
		MUL %= MOD;
	}
	for (int i = 0; i < N; i++) {
		ANS += (MUL * Calc(B[i], MOD - 2)) % MOD;
		ANS %= MOD;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>

#define PI 3.1415923565
using namespace std;


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

    cout<<std::fixed<<std::setprecision(10);
    cout << 2*r* PI<< endl;
    return 0;
}


Measured memory_bytes: 3784
from collections import Counter
from sys import stdin
input = stdin.readline

n = int(input())
d = list(map(int, input().split()))

c=Counter(d)
d_max=max(d)
ans=1
flag=True

if d[0]!=0:
    print(0)
elif d.count(0)>1:
    print(0)
else:
    for i in range(1, d_max+1):
        if c[i-1]==0:
            flag=False
        else:
            ans=ans*(c[i-1]**c[i])%998244353

    print(ans%998244353 if flag else 0)


Measured memory_bytes: 19872
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int n,m,p;
	scanf("%d%d%d",&n,&m,&p);
	int ans=0;
	for(int i=min(n,m);i>=1;i--){
		if(n%i==0&&m%i==0) ans++;
		if(ans==p){ans=i;break;}
	}
	cout<<ans;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll a, b, m;
  cin >> a >> b >> m;
  vector<ll> s(a);
  vector<ll> t(b);
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
  ll ans = INF;
  rep(i, m) {
    ll x, y, c;
    cin >> x >> y >> c;
    ll tmp = s[x-1]+t[y-1]-c;
    ans = min(ans,tmp);
  }
  Sort(s);
  Sort(t);
  ll tmp = s[0]+t[0];
  cout << min(ans,tmp) << '\n';
}

Measured memory_bytes: 4780
use std::io::*; //Not mine.
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: i64 = read();
    let m: i64 = read();
    let mut ans: i64 = 0;
    if (n - m).abs() >= 2 {
        ans = 0;
    } else if n == m {
        let mut tmp: i64 = 1;
        for i in 1..n + 1 {
            tmp *= i;
            tmp %= 1000000007;
        }
        tmp *= tmp;
        tmp %= 1000000007;
        tmp *= 2;
        tmp %= 1000000007;
        ans = tmp;
    } else {
        let k = std::cmp::max(n,m);
        let j = std::cmp::min(n,m);
        let mut tmp:i64 = 1;
        for i in 1.. k + 1 {
            tmp *= i;
            tmp %= 1000000007;
        }
        let mut tmp2:i64 = 1;
        for i in 1.. j + 1 {
            tmp *= i;
            tmp %= 1000000007;
        }
        ans = tmp * tmp2;
        ans %= 1000000007;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
n = int(input())
c = [[0 for i in range(13)] for j in range(4)]

for i in range(n):
    a, b = (i for i in input().split())

    if a == "S":
        c[0][int(b)-1] = 1
    elif a == "H":
        c[1][int(b)-1] = 1
    elif a == "C":
        c[2][int(b)-1] = 1
    elif a == "D":
        c[3][int(b)-1] = 1

for i in range(4):
    for j in range(13):
        if c[i][j] == 0:
            if i == 0:
                print('S ' + str(j+1))
            elif i == 1:
                print('H ' + str(j+1))
            elif i == 2:
                print('C ' + str(j+1))
            elif i == 3:
                print('D ' + str(j+1))



Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  string S;
  cin >> S;
  for (int i = 0; i < S.size() - 8; i++) {
    cout << S[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
if sum(A)<sum(B):
    print(-1)
else:
    a=0
    s=0
    l=[]
    for i in range(N):
        if A[i]<B[i]:
            a+=1
            s+=B[i]-A[i]
        else:
            l.append(A[i]-B[i])
    l.sort(reverse=1)
    for i in range(len(l)):
        if s<=0:
            break
        s-=l[i]
        a+=1
    print(a)

Measured memory_bytes: 18356
#!/bin/python

import os
import sys


def solution(A, B):
    if A>8 or B>8:
        return ":("
    return "Yay!"
    
if __name__ == '__main__':
    
    bnm = raw_input().split()

    A = int(bnm[0])

    B = int(bnm[1])

    result = solution(A,B)

    print str(result)


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

typedef struct{
  char pic;
  int num;
  int id;
}trnp;

void bubble_sort(int , trnp []);
void selection_sort(int , trnp []);

int main(void){
  int n;
  trnp a[36], b[36];
  int i;

  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf(" %c%d", &a[i].pic, &a[i].num);
    a[i].id = i;
    b[i] = a[i];
  }

  bubble_sort(n, a);
  selection_sort(n, b);

	return 0;
}

void bubble_sort(int n, trnp x[]){
  int i, j, stable;
  trnp y;
  for(j = 0; j < n -1; j++){
    for(i = n-1; i > j; i--){
      if(x[i].num < x[i - 1].num){
        y = x[i];
        x[i] = x[i - 1];
        x[i - 1] = y;
      }
    }
  }
  stable = 1;
  for(i = 0; i < n; ++i) {
    printf("%c%d%c", x[i].pic, x[i].num, " \n"[i==n-1]);
    if(i > 0 && x[i].num == x[i-1].num && x[i].id < x[i-1].id) stable = 0;
  }
  puts((stable ? "Stable" : "Not stable"));
}

void selection_sort(int n, trnp x[]){
  int i, j, min, stable;
  trnp y;

  for(i = 0; i < n; i++){
    min = i;
    for(j = i; j < n; j++){
      if(x[j].num < x[min].num){
        min = j;
      }
    }
    if(i != min){
      y = x[i];
      x[i] = x[min];
      x[min] = y;
    }
  }
  stable = 1;
  for(i = 0; i < n; ++i) {
    printf("%c%d%c", x[i].pic, x[i].num, " \n"[i==n-1]);
    if(i > 0 && x[i].num == x[i-1].num && x[i].id < x[i-1].id) stable = 0;
  }
  puts((stable ? "Stable" : "Not stable"));
}



Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,W;
cin>>N>>W;
vector<long> w(N);
vector<long> val(N);
  for(int i=0;i<N;i++){
  cin>>w[i]>>val[i];
  }
  
  long  dp[N+1][W+1];
  for(int i=0;i<=N;i++){
      for(int j=0;j<=W;j++){
          if(i==0 || j==0) dp[i][j]=0;
          else{
              if(w[i-1]<=j) dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-w[i-1]]);
              else dp[i][j]=dp[i-1][j];
          }
      }
  }
  cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 82320
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head


vector<int> G[100010];

int dp[100010];
bool used[100010];

void dfs(int x){
  used[x] = true;
  YYS(w, G[x]){
    if(!used[w]){
      dfs(w);
    }
    chmax(dp[x], dp[w] + 1);
  }
}

int main(){

  int n = in();
  int m = in();
  REP(i, m){
    int a = in() - 1;
    int b = in() - 1;
    G[a].pb(b);
  }

  int ans = 0;
  REP(i, n){
    if(!used[i]){
      dfs(i);
    }
    chmax(ans, dp[i]);
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int w, h, n;
  cin >> w >> h >> n;

  V<V<bool>> white(h + 1, V<bool>(w + 1, true));

  // white[i][j]は正方形の右上を表す
  rep(i, n) {
    int x, y, a;
    cin >> x >> y >> a;

    if(a == 1) {
      rep(i, h + 1) {
        rep(j, x + 1) {
          white[i][j] = false;
        }
      }
    } else if (a == 2) {
      rep(i, h + 1) {
        repf(j, x + 1, w + 1) {
          white[i][j] = false;
        }
      }
    } else if (a == 3) {
      rep(i, y + 1) {
        rep(j, w + 1) {
          white[i][j] = false;
        }
      }
    } else if (a == 4) {
      repf(i, y + 1, h + 1) {
        rep(j, w + 1) {
          white[i][j] = false;
        }
      }
    }
  }

  int area = 0;

  repf(i, 1, h + 1) {
    repf(j, 1, w + 1) {
      if(white[i][j]) {
        area++;
      }
    }
  }

  cout << area << endl;
}

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

using namespace std;
typedef long long int ll;
bool comp(ll a, ll b)
{
   return a>b;
}

int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, k;
    cin>>n>>k;
    ll h[n], sum=0;
    for(ll i=0; i<n; i++)
    {
        cin>>h[i];
        sum+=h[i];
    }
    sort(h, h+n,comp);
    if(k>=n)
        cout<<0;
    else {
    for(ll i=0; i<k; i++)
        sum-=h[i];
    cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 1792
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
import bisect
ans=0
a.sort()
b.sort()
c.sort()
for i in range(n):
    lift=bisect.bisect_left(a,b[i])
    right=bisect.bisect_right(c,b[i])
    right=n-right
    ans+=lift*right
print(ans)


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

typedef long long ll;

const int N = 1 * 1e5 + 10;
const ll inf = 1 * 1e9 + 10;

ll res;
ll a[N];

void solve() {
	ll  n, k;
	cin >> n >> k;
	for (int i = 0; i < n; ++i){
		cin >> a[i];
	}
	std::vector<ll> dp(n, inf);
	dp[0] = 0;
	for (int i = 1; i < n; ++i){
		for (int j = i - 1; j >= max((ll)0, (ll)i - k); --j){
			dp[i] = min(dp[i], dp[j] + abs(a[j] - a[i]));
		}
	}
	cout << dp[n - 1];

}

int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  ll t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
    return 0;
}

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

using ll = long long;
#define sz(x) ((int)x.size())
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int n;

int main() {
	fastio();	
	cin>>n;
	cout << 1000*((n+999)/1000)-n<<endl;
}


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

using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define double long double



int a[200];
int b[200];
int c[200];

signed main(){
	int n;
	cin>>n;
	lp(i,n){
		cin>>a[i];
		a[i]--;
	}
	lp(i,n){
		cin>>b[i];
	}
	lp(i,n-1)cin>>c[i];
	int ans=0;
	int bef=-2;
	lp(i,n){
		if(bef+1==a[i]){
			ans+=c[bef];
		}
		ans+=b[a[i]];
		bef=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  int x = a.length();
  if(a[x-1] == 's')
  {
    cout << a << "es" << endl;;
  }
  else
  {
  cout << a << 's' << endl;
  }
}


Measured memory_bytes: 3620
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);
	printf("%d\n", (int)min(ceil((double)n / h), ceil((double)n / w)));

	Please AC;
}


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

typedef long long int ll;



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

	ll i,j,t,k,l,m,n,x,y,z,a,b,c;

	cin >> n >> k;

	ll ans = 0;

	for(i=0;i<n;i++)
	{
		cin >> x >> y;

		// cout << x*x+y*y << " " << k*k << '\n';

		if(x*x+y*y <= k*k)
			ans++;
	}

	cout << ans << '\n';

	
	

}

Measured memory_bytes: 3616
//To compile : type "$     g++ test.cpp -std=c++14 -I .    "
#include <atcoder/all>
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
using namespace atcoder;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

int main() {
	cin>>Q;
	rep(_, Q){
		cin>>N>>M>>A>>B;
		cout<<floor_sum(N, M, A, B)<<endl;
	}
}

Measured memory_bytes: 3556
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 20){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}


ll H, N;
vector<pair<ll, ll>> AB;
ll dp[10010];//i番目の魔法まで使って、残り体力がj
void solve(){
  cin >> H >> N;
  AB.resize(N);
  rep(i, N) cin >> AB[i].f >> AB[i].s;
  sort(AB.begin(), AB.end());
  rep(i, 10010) dp[i] = INFL;
  dp[H] = 0;
  rep(i, N){
    for(ll j = H; j >= 0; j--){
      dp[max(j - AB[i].f, 0LL)] = min(dp[max(j - AB[i].f, 0LL)], dp[j] + AB[i].s);
    }
  }
  cout << dp[0] << endl;
}

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


Measured memory_bytes: 384
#include <iostream>

using namespace std;

void vecTurn(int x1, int y1, int x2, int y2, int *x, int *y)
{
  int sx = x2 - x1;
  int sy = y2 - y1;
  *x = x2 - sy;
  *y = y2 + sx;
}

int main(void)
{
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x3, y3;
  vecTurn(x1, y1, x2, y2, &x3, &y3);

  int x4, y4;
  vecTurn(x2, y2, x3, y3, &x4, &y4);

  cout << x3 << " ";
  cout << y3 << " ";
  cout << x4 << " ";
  cout << y4 << endl;

  return 0;
}


Measured memory_bytes: 256
A, B, C, K = map(int, input().split())
ans = 0
flag = 0
if A > 0:
    if K > A:
        ans += A
        K -= A
    else:
        ans += K
        flag += 1
if B > 0 and flag == 0:
    K -= B
    if K < 1:
        flag += 1
if C > 0 and flag == 0:
    if K > C:
        ans -= C
    else:
        ans -= K
print(ans)


Measured memory_bytes: 61760
#include <iostream>
#include <cstdio>

using namespace std;

int main(void)
{
	int a, b;
	while (scanf("%d %d", &a, &b) != EOF){
		int c = a + b, ret = 0;
		while (c > 0){
			ret++;
			c /= 10;
		}
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <deque>
typedef long long lint;
const int N=1e5+5;
int n;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x<y?y:x;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

namespace G{
	int cnt,fir[N],dis[N];
	struct edge{
		int to,wi,nx;
	}eg[N<<1];

	inline void add(const int a,const int b,const int v){
		eg[++cnt]=(edge){b,v,fir[a]};
		fir[a]=cnt;
	}

	int bfs(){
		static bool vis[N];
		memset(dis,10,(n+1)*sizeof(dis[0]));
		dis[1]=0;
		std::deque <int> dq;
		dq.push_back(1);
		while(!dq.empty()){
			const int x=dq.front();
			dq.pop_front();
			if(vis[x]) continue;
			vis[x]=1;
			for(int i=fir[x]; i; i=eg[i].nx){
				const int y=eg[i].to,v=eg[i].wi;
				if(dis[y]>dis[x]+v){
					dis[y]=dis[x]+v;
					if(v) dq.push_back(y);
					else dq.push_front(y);
				}
			}
		}
		return dis[0];
	}
}

int main(){
#ifdef LOCAL
	freopen("multiple.in","r",stdin);
	freopen("multiple.out","w",stdout);
#endif
	n=nxi();
	for(int i=0; i<n; ++i){
		G::add(i,i*10%n,0);
		G::add(i,(i+1)%n,1);
	}
	printf("%d\n",G::bfs()+1);
	return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
int main() {

int a, b, c, d = 0;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);

if ( a > b ){
    d = a;
    a = b;
    b = d;
}
if ( a > c ){
    d = a;
    a = c;
    c = b;
    b = d;
}
else if ( b > c ){
    d = b;
    b = c;
    c = d;
}
printf("%d %d %d\n", a, b, c);

    return 0;
}



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

#define lld long long
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007

using namespace std;

int H,W,N;
int ans[10];
map<pii,int> Map;

int main(){
	scanf("%d %d %d",&H,&W,&N);
	while(N--){
		int x,y;
		scanf("%d %d",&x,&y);
		for(int i=x-2; i<=x; i++){
			for(int j=y-2; j<=y; j++){
				if(i < 1 || j < 1 || i > H-2 || j > W-2) continue;
				Map[pii(i,j)]++;
			}
		}
	}
	for(auto &i : Map) ans[i.second]++;
	for(int i=1; i<10; i++) ans[0] -= ans[i];
	printf("%lld\n",(lld)(H-2)*(W-2)+ans[0]);
	for(int i=1; i<10; i++) printf("%d\n",ans[i]);

	return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
bitset<305> a[305],b;
int n,m,i,j,pw[305],mod=998244353,cnt;
int main()
{
	scanf("%d%d",&n,&m);
	pw[0]=1;
	for (i=1;i<=300;i++) pw[i]=pw[i-1]*2ll%mod;
	for (i=1;i<=n;i++)
	{
		b.reset();
		for (j=1;j<=m;j++)
		{
			int x;
			scanf("%d",&x);
			b[j]=x;
		}
		for (j=m;j>=1;j--)
		{
			if (b[j])
			{
				if (a[j].any())
				{
					b^=a[j];
				}
				else
				{
					a[j]=b;
					break;
				}
			}
		}
		if (j<1) cnt++;
	}
	cout<<((1ll*(pw[n]-pw[cnt])*pw[m-1]%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveIntArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = inputArray[0];
			var displayR = inputArray[1];



			//答えの出力
			var ans = getAns(N,displayR);
			Console.WriteLine(ans);

		}

		private static int getAns(int N, int displayR) {

			if (N >=10) {
				return displayR;
			}
			else {
				var inR = displayR + 100 * (10 - N);
				return inR;
			}

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static int[] retreiveIntArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var intArray = inputArray.Select(s => int.Parse(s));
			return intArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    long long n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    cout << (n - 1) / min(a, min(b, min(c, min(d, e)))) + 5 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int main() 
{long long n,m;
 cin>>n>>m;
 if (2*n>m){cout<<m/2; system("pause"); return 0;}
 cout<<n+(m-2*n)/4;
 system("pause");
 return 0;
}        


Measured memory_bytes: 504
package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var a, b, c string
	con.Scan(&a, &b, &c)
	con.Printf("A%cC\n", b[0])
	return nil
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
        string S; cin >> S;
        if (S == "#") break;
        int y,m,d; cin >> y >> m >> d;
        if (y > 31) {
            y -= 30;
            S = "?";
        } else if (y == 31 && m >= 5) {
            y = 1;
            S = "?";
        }

        cout << S << " " << y << " " << m << " " << d << endl;           
    }
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>

using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;


#include <list>
const ll inf = INT_MAX; //changeable 
ll Dinic_DFS(ll v,ll g,ll maxflow,vector<set<ll>>& lines, vector<map<ll,ll>>& cost,vector<ll>& level){

    if (v == g) return maxflow;

    ll realflow = 0;
    vector<ll> tmp(0);
    for ( ll tmpv : lines[v] ) tmp.push_back(tmpv);

    for ( ll nex : tmp ){
        if (level[nex] > level[v]){
            ll plusflow = Dinic_DFS(nex,g,min(maxflow,cost[v][nex]),lines,cost,level);
            cost[v][nex] -= plusflow;
            if (cost[v][nex] == 0) lines[v].erase(nex);
            if (cost[nex][v] == 0) lines[nex].insert(v);
            cost[nex][v] += plusflow;

            realflow += plusflow;
            maxflow -= plusflow;

            if (maxflow <= 0) return realflow;
        }
    }

    return realflow;
}

ll Dinic(ll s,ll g,vector<set<ll>>& lines, vector<map<ll,ll>>& cost){

    ll N = cost.size();
    ll ans = 0;

    while (true){

        //bfs
        list<ll> q;
        q.push_back(s);
        vector<ll> level(N,inf);
        level[s] = 0;
        while (!q.empty()){
            ll now = q.front();
            q.pop_front();
            for ( ll nex : lines[now] ){
                if (level[nex] > level[now] + 1){
                    level[nex] = level[now] + 1;
                    q.push_back(nex);
                }
            }
        }

        if (level[g] == inf){
            return ans;
        }

        //dfs
        ll delta_flow = Dinic_DFS(s,g,inf,lines,cost,level);
        while (delta_flow > 0){
            ans += delta_flow;
            delta_flow = Dinic_DFS(s,g,inf,lines,cost,level);
        }

    }
}

int main(){

    ll V,E;
    cin >> V >> E;

    vector<set<ll>> lines (V);
    vector<map<ll,ll>> cost (V);

    rep (i,0,E){
        ll u,v,c;
        cin >> u >> v >> c;
        if (c != 0){
            lines[u].insert(v);
            cost[u][v] += c;
        }
    }

    cout << Dinic(0,V-1,lines,cost) << endl;
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,f[2];
int a[N],ans[N];
inline void Rd(int &res){
	char c;res=0;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	return;
}
int main(){
	Rd(n);
	f[1]=-1;f[0]=1;
	for(int i=1;i<=n;i++)Rd(a[i]);
	long long x=0;
	for(int i=1;i<n;i++)x+=f[i&1]*2ll*a[i];
	x+=a[n]*2;
	ans[n]=x/2;
	for(int i=n-1;i>=1;i--)ans[i]=2ll*a[i]-ans[i+1];
	for(int i=1;i<n;i++)printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] c = s.toCharArray();

		StringBuilder ans = new StringBuilder();

		for (char ch : c) {
			if (ch == '0')
				ans.append("0");

			if (ch == '1')
				ans.append("1");

			if (ch == 'B') {
				if (ans.length() == 1)
					ans = new StringBuilder();
				if (!ans.toString().isEmpty())
					ans.setLength(ans.length() - 1);
			}
		}

		System.out.println(ans.toString());

	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#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 debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
const int FIVE = 101010;

//=============================
int N, M, K;
string S, T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin >> S;
}
//=============================
void func() {}
//=============================
void solve()
{
    int N = S.size();
    int l = 77;
    vector<vector<int>> DP(l + 1, vector<int>(N, -1));
    rep(i, N)
    {
        DP[0][i] = i + (S[i] == 'R' ? 1 : -1);
    }
    rep(i,N){
    }
    for (int k = 0; k < l; ++k)
    {
        rep(i, N)
        {
            DP[k + 1][i] = DP[k][DP[k][i]];
        }
    }

    vector<int> aa(N);
    for(auto x : DP[l]){
        aa[x]++;
    }
    rep(i, N)
    {
        cout << aa[i] << (i == N - 1 ? "\n" : " ");
    }

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+50;
ll num[MAXN];
int main()
{
    int n,ans=0;
    cin>>n;
    char s[100];
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
            ans++;
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a,b,c,e;
    char A[2000000];
    char B[2000000];    
    scanf("%s",A);
    scanf("%s",B);
    a=0;
    b=0;
    e=0;
    while(A[b])
        b++;
    
   
   for(c=0;c<b;c++){
       if(A[c]==B[c]){

       }else{
           e=e+1;
       }
   }
printf("%d",e);
    }

Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;

ll N;
vector<ll> x, y;

ll solve()
{
    if (N == 1) {
        return 1;
    }

    ll res = N;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (i == j) {
                continue;
            }
            ll dx = x[j] - x[i], dy = y[j] - y[i];

            ll sub = 0;
            for (int i2 = 0; i2 < N; ++i2) {
                for (int j2 = 0; j2 < N; ++j2) {
                    if (i2 == j2) {
                        continue;
                    }
                    if (dx == x[j2] - x[i2] && dy == y[j2] - y[i2]) {
                        ++sub;
                    }
                }
            }

            res = min(res, N - sub);
        }
    }
    return res;
}

int main()
{
    cin >> N;
    x.resize(N);
    y.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i];
    }
    cout << solve() << endl;
}

Measured memory_bytes: 256
set_num = int(input())
list_a = []
list_b = []
for i in range(set_num):
    card_set = input().split()
    list_a.append(card_set[0])
    list_b.append(card_set[1])

a_s = 0
b_s = 0
for a_dic,b_dic in zip(list_a,list_b):
    if a_dic > b_dic:
        a_s += 3
    elif a_dic < b_dic:
        b_s += 3
    else:
        a_s += 1
        b_s += 1

print('{} {}'.format(a_s,b_s))



Measured memory_bytes: 5624
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int r;
int n, m;
int grid[2][101];
int sol(int r,int c){

	if (r >= n || c >= m){
		return 0 ;
	}
	if (r == n - 1 && c == m - 1){
		return grid[r][c];
	}
	int path1 = 0, path2 = 0;

	if (c + 1 < m)
	{
		path1 = sol(r, c + 1);
	}
	if (r + 1 < n)
	{
		path2 = sol(r + 1, c);
	}
	return grid[r][c] + max(path1, path2);
}
int main(){
	cin  >> m;
	n = 2;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> grid[i][j];
		}
	}
	
	cout << sol(0, 0);
}

Measured memory_bytes: 256
//a.c A-Programming Education
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    if(n==1){
        printf("Hello World\n");
    }else{
        int a,b;
        scanf("%d",&a);
        scanf("%d",&b);
        printf("%d\n",a+b);
    }
    return 0;
}

Measured memory_bytes: 128
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N,K;
    cin >> N >> K;
    ll p[1010];
    rep(i,0,N) cin >> p[i];
    sort(p,p+N);
    ll ans = 0;
    rep(i,0,K) ans += p[i];
    print(ans);


}

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

Measured memory_bytes: 3660
strength=[2,3,4,5,6,7,8,9,10,11,12,13,1]
A,B=map(int,input().split())
a=strength.index(A)
b=strength.index(B)
if a>b:
    print("Alice")
elif b>a:
    print("Bob")
elif a==b:
    print("Draw")

Measured memory_bytes: 9064