akhauriyash/Code-Regression huggingface dataset:
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
//ベルマンフォード法
#include<iostream>
#define MAX_V 100000
#define MAX_E 500000
#define INF 1e9
using namespace std;
struct edge {
	int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;



bool find_negative_loop(int s)
{
	d[s] = 0;
	int count = 0;
	while (true)
	{
		bool update = false;
		count++;
		for (int i = 0; i < E; i++)
		{

			if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost)
			{
				if (count == V)
				{
					return true;
				}
				d[es[i].to] = d[es[i].from] + es[i].cost;
				update = true;
			}
		}
		if (update == false)
		{
			break;
		}


	}
	return false;
}

int main()
{

	int r;
	cin >> V >> E >> r;
	for (int i = 0; i < MAX_V; i++)
	{
		d[i] = INF;
	}
	for (int i = 0; i < E; i++)
	{
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	if (find_negative_loop(r))
	{
		cout << "NEGATIVE CYCLE" << endl;
	}
	else
	{
		for (int i = 0; i < V; i++)
		{
			if (d[i] == INF)
			{
				cout << "INF" << endl;
			}
			else
			{
				cout << d[i] << endl;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 9212
//Partition

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

bool IsPrime(int num){
    if(num<2)return false;
    else if(num==2)return true;
    else if(num%2==0)return false;
    double sqrtNum=sqrt(num);
    for (int i=3;i<=sqrtNum;i+=2)if(num%i==0)return false;
    return true;
}

signed main (){
    int n,m,ans=1;cin>>n>>m;
    if(n==1){cout<<m<<nnn;return 0;}
    if(IsPrime(m)){cout<<1<<nnn;return 0;}
    for(int i=2;i*i<1000001000;i++){
        if(m%i==0&&m/i>=n){
            ans=max(ans,i);
            if(i>=n){
                ans=max(ans,m/i);
            }
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3608
import numpy as np

def main():
    s = input().split("T")
    x, y = map(int, input().split())
    xs = []
    x -= len(s[0])
    for i in range(2, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            xs.append(tmp)
    ys = []
    for i in range(1, len(s), 2):
        tmp = len(s[i])
        if tmp != 0:
            ys.append(tmp)
    
    sum_x = sum(xs)
    sum_y = sum(ys)
    x = abs(x)
    y = abs(y)
    if sum_x < x or sum_y < y:
        print("No")
    else:
        rest_x = sum_x - x
        rest_y = sum_y - y
        if rest_x&1 or rest_y&1:
            print("No")
        else:
            ok = True
            if rest_x > 0:
                dp = np.array([[False]*8001 for i in range(len(xs)+1)])
                dp[0][0] = True
                for i in range(1, len(xs)+1):
                    dp[i] = dp[i] | dp[i-1]
                    dp[i][xs[i-1]:] = dp[i-1][xs[i-1]:] | dp[i-1][:-xs[i-1]]
                    # dp[i][:-xs[i-1]] = dp[i-1][:-xs[i-1]] | dp[i-1][xs[i-1]:]
                if not dp[-1][rest_x//2]:
                    ok = False
            if rest_y > 0:
                dp = np.array([[False]*8001 for i in range(len(ys)+1)])
                dp[0][0] = True
                for i in range(1, len(ys)+1):
                    dp[i] = dp[i] | dp[i-1]
                    dp[i][ys[i-1]:] = dp[i-1][ys[i-1]:] | dp[i-1][:-ys[i-1]]
                    # dp[i][:-ys[i-1]] = dp[i-1][:-ys[i-1]] | dp[i-1][ys[i-1]:]
                if not dp[-1][rest_y//2]:
                    ok = False
            if ok:
                print("Yes")
            else:
                print("No")
                    

if __name__ == "__main__":
    main()

Measured memory_bytes: 153052
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  int la = 0, ra = N;
  F0R(i, M) {
    int l, r;
    cin >> l >> r;
    chmax(la, l);
    chmin(ra, r);
  }
  int result = ra - la + 1;
  cout << (result < 0 ? 0 : result);
}
#endif


Measured memory_bytes: 3632
s=input()
q=int(input())

sb=""
sa=""
rev=1
for i in range(q):
    qu=input()
    if qu=="1":
        rev=-rev
    else:
        t,f,c=qu.split()
        if f=="1" and rev==1:
#            s=c+s
            sb=c+sb
#            print(s)
        elif f=="2" and rev==1:
#            s=s+c
            sa=sa+c
#            print(s)
        elif f=="1" and rev==-1:
#            s=s+c
            sa=sa+c
#            print(s)
        elif f=="2" and rev==-1:
#            s=c+s
            sb=c+sb
#            print(s)
s=sb+s+sa
if rev==-1:
    s=s[::-1]
#    print(s)
print(s)     

Measured memory_bytes: 4544
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    int n;
    cin >> n;

    vector<string> v(n + 1);

    for(int i = 0; i < n; i++){
        string s;
        cin >> s;

        sort(all(s));

        v[i] = s;
    }

    v[n] = "{";

    ll ans = 0, cnt = 1;

    sort(all(v));

    for(int i = 1; i < n + 1; i++){
        if(v[i].compare(v[i - 1]) == 0) cnt++;
        else{
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }

    cout << ans;
}


Measured memory_bytes: 6332
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double a, b, h, m;
        a = sc.nextDouble();
        b = sc.nextDouble();
        h = sc.nextDouble();
        m = sc.nextDouble();
        double angle = Math.min(Math.abs(h * 30 + m * 0.5 - m * 6), 360 - Math.abs(h * 30 + m * 0.5 - m * 6));
        double pi = angle / 180 * Math.PI;
        System.out.println(Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(pi)));
    }
}

Measured memory_bytes: 37456
n = int(input())
 
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i ==0:
      divisors.append(i)
  return divisors
 
def digit(n):
  for i in range(11):
    if n>=10**i and n<10**(i+1):
      return i+1
      break
 
list = make_divisors(n)
 
ans = 12
 
for i in list:
  if max(digit(i), digit(n/i)) < ans:
    ans = max(digit(i), digit(n/i))
 
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
const ll mod=1000000007,N=1e5+5,M=1e5+5,INF=0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head

int main(void){
    int n,ans=0;
    scanf("%d",&n);
    map<string,bool>mp;
    rep(i,0,n){
        char s[11]={0};
        scanf("%s",s);
        if(!mp[s]){
            ++ans;
            mp[s]=1;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 19268
#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()
const double PI = acos(-1);
const ll MOD = 1000000007;
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); //入出力高速化
    int N,K; cin >> N >> K;
    int M = (N-1) * (N-2) / 2;
    if (K > M) cout << -1 << endl;
    else {
        vector<pair<int, int>> A;
        for (int i = 0; i < N-1; i++) A.emplace_back(0,1+i);
        int j = 1;
        int k = 2;
        for (int i = 0; i < M - K; i++) {
            A.emplace_back(j,k);
            k++;
            if (k == N) {
                j++;
                k = j+1;
            }
        }

        cout << A.size() << endl;
        rep(i,A.size()) cout << A[i].first+1 << " " << A[i].second+1 << endl;
    }
}

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

int main() {
  int N;
  int ans = 0;
  string S;
  
  cin >> S;
  N = S.size();
  
  for (int i = 0; i < N / 2; i++) {
    if (S.at(i) != S.at(N-1-i)) {
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};


//-----------------------------------------------------------------------------

int w,a,b;

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

	cin>>w>>a>>b;
	if(a>b) swap(a,b);
	cout<<max(0,b-(a+w))<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

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

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

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

using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin>>n && n){
        int y;cin>>y;
        double mr = 0;
        int maxb = -1;
        rep(i,n){
            double b, r, t;
            cin >> b >> r >> t;
            double rate = 1;
            if(t==1) rate = (1+y*r/100);
            else{
                rep(j,y)rate *= (1+r/100);
            }
            if(rate > mr){
                mr = rate;
                maxb = b;
            }
        }
        cout << maxb << endl;
    }
}

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

int main(){
	int n;
	int max,min;
	char in[9];
	cin>>n;
	while(n--){
		cin >>in;
		max=min=0;
		for(int i=0;i<8;i++){
			in[i]=in[i]-'0';
		}
		sort(in,in+8);
		for(int i=0;i<8;i++){
			max=max+in[i]*pow(10,i);
			min=min+in[i]*pow(10,7-i);
		}
		cout<<max-min<<endl;
	}
	return 0;
	
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<char>> a(y,vector<char>(x))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]

vector<int> ta={1,0,-1,0};
vector<int> su={0,1,0,-1};
using p=pair<int,int>;

int main(){
  int h,w,x,y,nx,ny;
  cin>>h>>w;
  vec2(a,h,w);
  rep(i,h)rep(j,w) cin>>a[i][j];
  queue<p> bfs;
  vector<vector<int>> seen(h,vector<int>(w,10000000));
  rep(i,h)rep(j,w) if(a[i][j]=='#') {bfs.push(p(i,j));seen[i][j]=0;}
  
  while(!bfs.empty()){
    y=bfs.front().first;x=bfs.front().second;
    bfs.pop();
    rep(i,4){
      ny=y+ta[i];nx=x+su[i];
      if(ny<0||nx<0||nx>=w||ny>=h) continue;
      if(a[ny][nx]=='#') continue;
      a[ny][nx]='#';
      seen[ny][nx]=seen[y][x]+1;
      bfs.push(p(ny,nx));
    }
  }
  int maxi=seen[0][0];
  rep(i,h)rep(j,w){
    maxi =max(maxi,seen[i][j]);
  }
  cout<<maxi<<endl;
}


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

int main(){
  string s;cin>>s;int ans=1e9,n=s.size();
  REP(i,n-2){
    int t=(s.at(i)-'0')*100+(s.at(i+1)-'0')*10+(s.at(i+2)-'0');
    ans=min(ans,abs(t-753));
  }  
  cout<<ans;
}

Measured memory_bytes: 256
import heapq

n, m = list(map(int, input().split()))
V = [i for i in range(n)]
E = [{} for _ in range(n)]

for _ in range(m):
    ef, et, ed = list(map(int, input().split()))
    E[ef][et] = ed
    # E[et][ef] = ed

INF = int(1e18)
pred = {i: None for i in range(n)}

d = {i: {j: INF for j in range(n)} for i in range(n)}
for u in range(n):
    d[u][u] = 0
    for v in E[u]:
        d[u][v] = E[u][v]

neg_cycle = False
for k in range(n):
    for u in range(n):
        if d[u][k] == INF:
            continue
        for v in range(n):
            if d[k][v] == INF:
                continue
            if d[u][v] > d[u][k] + d[k][v]:
                d[u][v] = d[u][k] + d[k][v]


for k in range(n):
    if d[k][k] < 0:
        print("NEGATIVE CYCLE")
        exit()

for u in range(n):
    for v in range(n):
        if d[u][v] == INF:
            print("INF", end="")
        else:
            print(d[u][v], end="")
        if v < n - 1:
            print(" ", end="")
    print()


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

int main() {
    int n, m;
    cin >> n >> m;
    cout << (n-1) * (m-1) <<endl;
}


Measured memory_bytes: 256
S=input()
if S=='SUN':
    print(7)
elif S=='MON':
    print(6)
elif S=='TUE':
    print(5)
elif S=='WED':
    print(4)
elif S=='THU':
    print(3)
elif S=='FRI':
    print(2)
elif S=='SAT':
    print(1)


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

using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	int mxp = -2e9, mxm = -2e9, mnp = 2e9, mnm = 2e9;
	rep(i, n) {
		int a,b;
		cin >> a >> b;
		mxp = max(mxp, a + b);
		mxm = max(mxm, a - b);
		mnp = min(mnp, a + b);
		mnm = min(mnm, a - b);
	}
	int ans = 0;
	ans = max(mxp - mnp, mxm - mnm);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<typeinfo>
#include<cassert>
#include<functional>
#include<algorithm>
#include<climits>
#include<map>

using namespace std;

int main(){

    int N,M;

    cin >> N;

    map<string,int> a,b;

    while(N--){
    	string s;
    	cin >> s;
    	a[s]++;
    }

    cin >> M;

    while(M--){
    	string t;
    	cin >> t;
    	b[t]++;
    }

	int ans = 0;

	for(auto m:a){
		ans = max(ans,a[m.first] - b[m.first]);
	}

    cout << ans << endl;

    return 0;

}


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

int main(){
	int n;
	scanf("%d", &n);
	multiset<int> s;
	for(int i = 0; i < n; i++) {
		int id, x;
		scanf("%d%d", &id, &x);
		if(id == 0) {
			s.insert(x);
			printf("%lu\n", s.size());
		}else if(id == 1) {
			printf("%lu\n", s.count(x));
		}else if(id == 2) {
			s.erase(x);
		}else if(id == 3) {
			int y;
			scanf("%d", &y);
			auto itr = s.lower_bound(x);
			for(; itr != s.end() && *itr <= y; itr++)
				printf("%d\n", *itr);
		}
	}
}


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

int main()
{
	stack<int> s,t,shonn,thonn;
	int n, q,st,goukei=0; cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> st;
		s.push(st);
	}cin >> q;
	shonn = s;
	for (int i = 0; i < q; i++)
	{
		cin >> st;
		t.push(st);
	}
	thonn = t;
	while (1){
		int top = thonn.top();
		while (1){
			if (top != shonn.top()){

			}
			else{
				goukei++;
				break;
			}
			shonn.pop();
			if (shonn.empty() == true){
				break;
			}
		}
		thonn.pop();
		shonn = s;
		if (thonn.empty() == true){ break; }
	}
	cout << goukei << endl;
	return 0;
}

Measured memory_bytes: 3172
n=int(input())
if(n<600):
  print(8)
elif(n<800):
  print(7)
elif(n<1000):
  print(6)
elif(n<1200):
  print(5)
elif(n<1400):
  print(4)
elif(n<1600):
  print(3)
elif(n<1800):
  print(2)
else:
  print(1)

Measured memory_bytes: 61824
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int people = scanner.nextInt();
        int train_one =  scanner.nextInt();
        int taxi_people =  scanner.nextInt();
      
        int min_price = Math.min(people * train_one, taxi_people);
        System.out.println(min_price);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline void pv(vector<T> v) { for(ll i=0, N=v.size()-1; i<=N; i++) if(i!=N) cout << v[i] << ' '; else cout << v[i] << endl; }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

signed main() {
	ll N,M;
	cin>>N>>M;
	vector<vector<pair<ll,ll>>> a(N+1);
	vector<string> ans(M,"");
	rep(i,M){
		ll p,y;
		cin>>p>>y;
		a[p].push_back(make_pair(y,i));
	}
	debug(a);
	rep(i,N+1){
		sort(all(a[i]));
		debug(a[i]);
		string s=to_string(i);
		while(s.size()<6)s="0"+s;
		rep(j,a[i].size()){
			string t=to_string(j+1);
			while(t.size()<6)t="0"+t;
			ans[a[i][j].second]=s+t;

		}
	}

	rep(i,M){p(ans[i]);}
	return 0;
}


Measured memory_bytes: 12416
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, M;
  cin >> N >> M;
  ll ans = pow(2, M) * (1900 * M + 100 * (N - M));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,d,s,i,j,t;
    while(cin>>d>>t>>s)
    {
        if(s*t>=d)
        {
            printf("Yes\n");
        }
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int n,k,a,pyy,h;
int main()
{
    cin>>n>>k>>a;h=a;
    for(int i=2;i<=n;i++)
    {
        cin>>pyy;
        a=__gcd(a,pyy);
        h=max(pyy,h);
    }
    if(k%a==0&&k<=h)cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 256
import copy

s = input()
l = len(s) - 1
count = 0

for i in range(2**l):
  code = list(copy.deepcopy(s))
  bin_str = bin(i).replace('0b', '').zfill(l)
  
  plus_count = 0
  for j in range(len(bin_str)):
    if bin_str[j] == '1':
      code.insert(j+1+plus_count,'+')
      plus_count += 1
      
  code = ''.join(code)
  if '++' in code:
    continue
    
  count += eval(''.join(code))
  
print(count)

Measured memory_bytes: 3444
# 空白区切の入力値を数値の配列で返す
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, M, C = gets_i_list
b = gets_i_list
a_list = []
N.times do
  a_list.push(gets_i_list)
end

count = 0
a_list.each do |a|
  total = C
  (0...M).each do |i|
    total += a[i] * b[i]
  end
  count += 1 if total > 0
end

puts count


Measured memory_bytes: 1788
#include <stdio.h>
#include <math.h>
 
int main() {
	int bit, i, j , N, M, onoff, cont, acont = 0;
	int k[10], s[10][10], P[10];
 
	{ /*入力 */
		scanf("%d %d", &N, &M);
		for (i = 0; i < M; i++) {
			scanf("%d", &k[i]);
			for (j = 0; j < k[i]; j++) {
				scanf("%d", &s[i][j]);
			}
		}
		for (i = 0; i < M; i++) {
			scanf("%d", &P[i]);
		}
	}
 
 
	{ /* 計算 */
		for (bit = 0; bit < pow(2.0, (double)N); bit++) {
			for (i = 0; i < M; i++) {
				cont = 0;
				for (j = 0; j < k[i]; j++) {
					onoff = (bit >> (s[i][j] - 1)) % 2;
					cont += onoff;
				}
				if (cont % 2 != P[i]) break;
			}
			if (i == M)acont++;
		}
	}
 
	printf("%d\n", acont);
 
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b)
    cout<<c<<endl;
  else
  {
      if(a==c)
        cout<<b<<endl;
      else
        cout<<a<<endl;
  }
}


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

int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int sum = 0;
  int counts = 0;
  rep(i,a+1)rep(j,b+1)rep(k,c+1){
    sum = i*500 + j*100 + k*50;
    if(sum == x) counts++;
  }
  cout << counts << endl;
}


Measured memory_bytes: 3628
#c
n,m = map(int,input().split())
h = list( map(int,input().split()))

tree=[[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1) #aがbの親、とかが保証されてれば不要。


ans=0
for i,t in enumerate(tree):
    if all(h[i] > h[tt] for tt in t):
        ans+=1
print(ans)

Measured memory_bytes: 93176
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

void solve(){
    string s;
    cin >> s;

    int lens = s.size();

    vi white_pos;
    for (int i = 0; i < lens; i++) {
        if (s[i] == 'W') {
            white_pos.push_back(i);
        }
    }

    ll ans = 0;
    int idx = 0;
    for (int i = 0; i < (int)white_pos.size(); i++) {
        ans += white_pos[i] - idx;
        idx++;
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

//typedef __int128_t ll;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int maxN = 2e5 + 10;
const int maxC = 1e6 + 10;
const int INF1 = 1e9;
const ll INF = 1LL<<62;

ll a[maxN];
ll s[maxN];
ll Z;
int n;
int main()
{
	scanf("%d%lld",&n,&Z);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	s[0] = 0ll;
	for(int i=1;i<=n;i++)
	{
		s[i] = s[i-1] + a[i];
	}
	ll ans = INF;
	for(int k=1;k<=n;k++)
	{
		ll cur = 0ll;
		ll cof = 3ll;
		for(int i = n;i>=0;i-=k)
		{
			cur += (s[i] - s[max(0,i-k)]) * max(cof,5ll);
			cof += 2ll;
			if(cur > ans) break;
		}
		cur += (n+k)*Z;
		ans = min(ans,cur);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main {
	public static void main(String[] args){
		stringRotation();
	}
	
	public static void stringRotation() {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		for (int i=0; i<s.length(); i++) {
			int j=0;
			int k=i;
			while (s.charAt(k) == t.charAt(j)) {
				k++;
				j++;
				if (k == s.length()) k=0;
				if (j == t.length()) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   int a,b; cin>>a>>b;
   cout << a-1+(a<=b?1:0) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int a, b, c;
	scanf("%d", &a);
	if (a == 19 || a == 29 || a == 39 || a == 49 || a == 59 || a == 69 || a == 79 || a == 89 || a == 90 || a == 91 || a == 92 || a == 93 || a == 94 || a == 95 || a == 96 || a == 97 || a == 98 || a == 99) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a == b){
            if(a == 0){
                System.out.println("Zero");
                System.exit(0);
            }
            else if(a < 0){
                System.out.println("Negative");
                System.exit(0);
            }
            else{
                System.out.println("Positive");
                System.exit(0);
            }
        }
        else{
            if(a > 0 && b > 0){
                System.out.println("Positive");
                System.exit(0);
            }
            else if(a <= 0 && b >= 0){
                System.out.println("Zero");
                System.exit(0);
            }
            else{
                int sum = - (a + b);
                if(sum%2 == 0){
                    System.out.println("Negative");
                    System.exit(0);
                }
                else{
                    System.out.println("Positive");
                    System.exit(0);
                }
            }
        }
    }
}


Measured memory_bytes: 9552
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        int same = 0;
        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i) != s.charAt(i + 1)) {

            } else {
                same++;
            }
        }
        int ans = Math.min(n - 1, same + k * 2);
        System.out.println(ans);
        sc.close();
    }
}


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

#define ll long long
#define ld long double

char nthLetter(int n) {
    return "abcdefghijklmnopqrstuvwxyz"[n];
}

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

    char n;
    cin >> n;
    cout << nthLetter(int(n - 96)) << '\n';
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n;
string s;

int zalgo()
{
    vector<int> a(n);
    a[0] = s.size();
    int i = 1, j = 0;
    while (i < s.size())
    {
        while (i + j < s.size() && s[j] == s[i + j])
            j++;
        a[i] = j;
        if (j == 0)
        {
            i++;
            continue;
        }
        int k = 1;
        while (i + k < s.size() && k + a[k] < j)
            a[i + k] = a[k], k++;
        i += k;
        j -= k;
    }
    int res = 0;
    rep(i, n) a[i] = min(a[i], i);
    Rep(i, 1, n) res = max(res, a[i]);
    return res;
}

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

    cin >> n >> s;
    int ans = -1;
    while (n != 0)
    {
        ans = max(ans, zalgo());
        s = s.substr(1);
        n--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n; cin >> n;
  map<int, int> m;

  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    if (m[a] > 0) {
      cout << "NO" << endl;
      return 0;
    }

    m[a]++;
  }

  cout << "YES" << endl;
}

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

using namespace std;

typedef long long int lli;

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

    int n, d[100000];

    cin >> n;
    for (int i=0; i<n; i++) cin >> d[i];

    sort(d, d+n);

    int mid = n/2;

    cout << d[mid] - d[mid-1] << endl;

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(int argc, char *argv[])
{
	int num, cnt = 0, n = 0;
	char c, dummy;

	scanf("%d", &n);
	scanf("%c", &dummy);

	char cList[n];
	int numList[n];
	int S[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	int H[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	int C[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	int D[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	cnt = 0;
	while (cnt < n)
	{
		// scanf("%c %d\n",&c ,&num);
		scanf("%c",&c);
		scanf("%d",&num);
		scanf("%c", &dummy);
		cList[cnt] = c;
		numList[cnt] = num;
		cnt++;
	}

	cnt = 0;

	while (cnt < n)
	{
		if (cList[cnt] == 'S')
		{
			S[numList[cnt] - 1] = 1;
		}
		if (cList[cnt] == 'H')
		{
			H[numList[cnt] - 1] = 1;
		}
		if (cList[cnt] == 'C')
		{
			C[numList[cnt] - 1] = 1;
		}
		if (cList[cnt] == 'D')
		{
			D[numList[cnt] - 1] = 1;
		}
		cnt++;
	}

	cnt = 0;
	while (cnt < 13)
	{
		if (S[cnt] == 0)
		{
			printf("S %d\n", cnt + 1);
		}
		cnt++;
	}

	cnt = 0;
	while (cnt < 13)
	{
		if (H[cnt] == 0)
		{
			printf("H %d\n", cnt + 1);
		}
		cnt++;
	}
	cnt = 0;
	while (cnt < 13)
	{
		if (C[cnt] == 0)
		{
			printf("C %d\n", cnt + 1);
		}
		cnt++;
	}
	cnt = 0;
	while (cnt < 13)
	{
		if (D[cnt] == 0)
		{
			printf("D %d\n", cnt + 1);
		}
		cnt++;
	}
	return 0;
}



Measured memory_bytes: 2044
N,W=map(int,input().split())
A=[]
W1,W2,W3,W4=[],[],[],[]
for i in range(N):
  w,v=map(int,input().split())
  if i==0:
    a=w
  A.append((v,w))
  if w-a==0:
    W1.append(v)
  elif w-a==1:
    W2.append(v)
  elif w-a==2:
    W3.append(v)
  else:
    W4.append(v)
  

W1,W2,W3,W4=sorted(W1)[::-1],sorted(W2)[::-1],sorted(W3)[::-1],sorted(W4)[::-1]

l1,l2,l3,l4=len(W1),len(W2),len(W3),len(W4)
ans=0
for i in range(l1+1):
  for j in range(l2+1):
    for k in range(l3+1):
      for l in range(l4+1):
        value=sum(W1[:i])+sum(W2[:j])+sum(W3[:k])+sum(W4[:l])
        if a*i+(a+1)*j+(a+2)*k+(a+3)*l<=W:
          ans=max(ans,value)
print(ans)

Measured memory_bytes: 80108
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll

void solve() {
    
    char c;
    cin >> c;
    c++;
    cout << c << endl;

}
int32_t main(){ _
    ll t;
    // cin >> t;
    t = 1;
    while(t--) solve();
}

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

using namespace std;

void b_popular_vote(void) {
	int n, m;
	cin >> n >> m;
	vector<int>a(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	int select = 0;
	double thr = (sum*1.0) / (4 * m);

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

	for (int i = 0; i < n; i++) {
		if ((double) a[i] >= thr) select++;
	}

	if (select >= m) cout << "Yes" << endl;
	else             cout << "No" << endl;
}

int main()
{
    b_popular_vote();

    return 0;
}

Measured memory_bytes: 3600
import sys

N, M = [int(i) for i in input().split()]
wa_dict = {}
for line in sys.stdin:
  line = line.rstrip().split()
  if len(line) == 0: break
  p = int(line[0])
  S = line[1]
  if p not in wa_dict:
    if S == "WA":
      wa_dict[p] = 1
    else:
      wa_dict[p] = 0
  elif wa_dict[p] > 0:
    if S == "WA":
      wa_dict[p] += 1
    else:
      wa_dict[p] *= -1
ac = sum([1 for i in wa_dict.values() if i <= 0])
wa = sum([abs(i) for i in wa_dict.values() if i <= 0])
print("{} {}".format(ac, wa))


Measured memory_bytes: 15104
N = gets.to_i

xyh = []

N.times do
  s = gets.split.map(&:to_i)
  xyh << s if s[2] != 0
end

if xyh.size == 1
  puts xyh.join(" ")
  exit
end

for cx in 0..100 do
  for cy in 0..100 do
    h = xyh[0][2]+(xyh[0][0]-cx).abs+(xyh[0][1]-cy).abs
    1.upto(xyh.size-1) do |i|
      if h!= xyh[i][2]+(xyh[i][0]-cx).abs+(xyh[i][1]-cy).abs
        break
      end

      if i == xyh.size-1
        puts [cx,cy,h].join(" ")
      end
    end
  end
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

ll n;
ll cnt=0;

void dfs(ll num, bool three, bool five, bool seven){
    if(num>n){
        ;
    }else{
        if(three==1&&five==1&&seven==1) cnt++;
        dfs(10*num+3,1,five,seven);
        dfs(10*num+5,three,1,seven);
        dfs(10*num+7,three,five,1);
    }
}

int main(){
    cin>>n;

    dfs(0,0,0,0);
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
{
  const main = (input: string) => {
    const r = reader(input)
    const R = r.n()

    console.log(R * R)
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}


Measured memory_bytes: 7500
import sys
import time
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = [S() for i in range(N)]

d = [0]*4
for i in range(N):
  if s[i] == "AC":
    d[0] += 1
  elif s[i] == "WA":
    d[1] += 1
  elif s[i] == "TLE":
    d[2] += 1
  else:
    d[3] += 1

print("AC x",d[0])
print("WA x",d[1])
print("TLE x",d[2])
print("RE x",d[3])

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint comb(int n, int m) {
    return perm(n) / (perm(n - m) * perm(m));
}

// 定数 //
#define pi acos(-1)
// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
        
    int N, M;   
    cin >> N >> M;
   
    int min_ = max(-1000000, M - N + 1);
    int max_ = min(1000000, M + N);
    for (int i = min_, k = 0; k < max_ - min_; k++, i++) {
        cout << i << " ";
    }
    cout << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    ll n;
    cin >> n;
    ll x, y;
    cin >> x >> y;
    rep2(i, 1, n) {
        ll a, t;
        cin >> a >> t;
        ll k, l;
        k = (x + (a - 1)) / a;
        l = (y + (t - 1)) / t;
        x = a * max(k, l);
        y = t * max(k, l);
    }
    cout << x + y << endl;
}

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

int main()
{
    bool flag_finish = false;

    int N_MAX = 3;
    int N, M;
    std::cin >> N >> M;
    std::vector<int> s(M);
    std::vector<int> c(M);
    std::vector<int> sc(N_MAX+1, -1);


    for (int i = 0; i < M; i++)
    {
        std::cin >> s[i] >> c[i];

        // 2桁以上で先頭が0のときは終了
        if (N >= 2 && s[i] == 1 && c[i] == 0)
            flag_finish = true;

        // 重複があった場合は終了
        if (sc[s[i]] == -1)
            sc[s[i]] = c[i];
        else if (sc[s[i]] != c[i])
            flag_finish = true;

        // 
    }


    if (flag_finish == true)
        std::cout << -1 << std::endl;
    else
    {
        // 初期化
        std::vector<int> v(N, 0);

        // 桁ごとに入れ替え
        for (int i = 0; i < M; i++)
            v[s[i]-1] = c[i];

        // 2桁以上で先頭が不定のときは1にする
        if (N >= 2 && v[0] == 0)
            v[0] = 1;

        // 値に変換
        std::string ans = "";
        for (int i = 0; i < N; i++)
            ans += std::to_string(v[i]);

        std::cout << std::stoi(ans) << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  vector<int> X(M);
  for(int i=0;i<M;++i) cin>>X[i];
  sort(X.begin(), X.end());
  vector<int> dist(M-1);
  for(int i=0;i<M-1;++i) {
    dist[i] = X[i+1]-X[i];
  }
  sort(dist.begin(), dist.end(), greater<int>());
  int ans = 0;
  for(int i=N-1;i<M-1;++i) {
    ans += dist[i];
  }
  cout<<ans<<endl;
}



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

int main() {
  int n; cin >>n;
  vector<int> b(n);
  for (int i=1; i<n; i++) cin >>b.at(i);
  int ans = 0;
  ans += b.at(1)+b.at(n-1); // a1とanはB被らない
  
  for (int i=2; i<n; i++){
    ans += min(b.at(i-1),b.at(i));
  }
  
  cout <<ans;
  cout <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <functional>
#include <cstring>
#include <set>
using namespace std;

typedef long long ll;
#define MAX 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int cnt=0;
	rep(i, n) {
		if (a[a[i] - 1] == i + 1)cnt++;
	}

	cout << cnt / 2 << endl;

	return 0;
}



Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		List<MyList> L  = new ArrayList<>();
		
		int n = sc.nextInt();
		
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++) {
			MyList List = new MyList();
			L.add(List);
		}
		
		
		for(int i=0;i<q;i++) {
			
			int ver = sc.nextInt();
			int t=0,s=0,x=0;
			switch(ver) {
			
			case 0 :
				t = sc.nextInt();
				x = sc.nextInt();
				
				L.get(t).insert(x);
				
				break;
			case 1 :
				t = sc.nextInt();
				
				L.get(t).dump();
				break;
			case 2 :
				s = sc.nextInt();
				t = sc.nextInt();
				
				L.get(t).splice(L.get(s));
				break;
			}
		}
	}

}

class MyNode{
	int x;
	MyNode after;
	MyNode(int x_ , MyNode after_){
		x = x_;
		after = after_;
	}
}

class MyList{
	MyNode start;
	MyNode end;
	int size;
	
	MyList(){
		
		start = new MyNode(0,null);
		end = start;
		size = 0;
	}
	
	void insert(int x) {
		
		MyNode newNode = new MyNode(x,null);
		
		end.after = newNode;
		end = end.after;
		size++;
	}
	
	void dump() {
		
		MyNode cursor = start.after;
		for( int i = 0; i < size; i++ ){
			if( i == 0 )
				System.out.print( cursor.x );
			else
				System.out.print( " " + cursor.x ); 
			cursor = cursor.after;
		}
		System.out.println();
	}
	
	void splice(MyList Ls) {
		
		end.after = Ls.start.after;
		end = Ls.end;
		size += Ls.size;
		
		Ls.end = Ls.start;
		Ls.size = 0;
	}
}



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

int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> P(N, pair<int, int>(0, 0));
    for (int i = 0; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        P[i].first = x + y;
        P[i].second = x - y;
    }
    sort(P.begin(), P.end());
    int ans = 0;
    int flag = -P[N - 1].first;
    for (int i = 0; i < N; i++)
    {
        if (flag <= P[i].second)
        {
            ans++;
            flag = P[i].first;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include<algorithm>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 
using namespace std;

using ll = long long;

int main()
{
	int H, W;
	cin >> H >> W;
	int N;
	cin >> N;

	vector< vector<int> > data(H,vector<int>(W,0));

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		for (int j = 0; j < a; j++) {
			data[cnt/W][cnt%W] = i+1;
			cnt++;
		}
	}

	for (int i = 0; i < H; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < W; j++) {
				if (j != 0)
					cout << " " << data[i][j];
				else
					cout << data[i][j];
			}
		}
		else {
			for (int j = W-1; j >= 0; j--) {
				if (j != W-1)
					cout << " " << data[i][j];
				else
					cout << data[i][j];
			}
		}
		cout << endl;
	}
	

	





	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=30005,P=2*3*5;

int n,s,ptr,ok[P];
bool chk(int x){return x%2==0||x%3==0||x%5==0;}
int nxt(){ 
	int x=ptr++;
	while(!chk(ptr))++ptr;
	return x;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
//	freopen("dat.in","r",stdin);
//	freopen("my.out","w",stdout);
#endif
	ptr=2;
	scanf("%d",&n);
	if(n==3){ puts("2 5 63"); return 0; }
	rep(i,1,n-2){
		int x=nxt(); 
		printf("%d ",x);
		s+=x;
		s%=P;
	}
	int lst;
	lst=nxt(); ok[lst%P]=lst;
	for(lst=nxt();;lst=nxt()){
		int z=lst%P;
		if(ok[(P+P-s-z)%P]){
			printf("%d %d\n",ok[(P+P-s-z)%P],lst);
			break;
		}else ok[z]=lst;
	}
	return 0 ;
}

Measured memory_bytes: 384