akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int ans[505][505],c[505][505];
int fx[4][2]={
0,1,
1,0,
-1,0,
0,-1
};
int n;
void dfs(int x,int y){
	rep(i,0,4){
		int tx=x+fx[i][0],ty=y+fx[i][1];
		if(tx&&ty&&tx<=n&&ty<=n){
			if(ans[tx][ty]>ans[x][y]+c[tx][ty]){
				ans[tx][ty]=ans[x][y]+c[tx][ty];
				dfs(tx,ty);
			}
		}
	}
} 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	FOR(i,1,n){
		FOR(j,1,n){
			c[i][j]=1;
			ans[i][j]=min(min(i,j),min(n-i+1,n-j+1));
		}
	}
	int x,y,t,sum=0;
	FOR(i,1,n*n){
		cin>>t;
		x=(t-1)/n+1;
		y=(t-1)%n+1;
		sum+=--ans[x][y];c[x][y]=0;
		dfs(x,y);
	}
	cout<<sum;
	RE 0;
}




Measured memory_bytes: 17180
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 3000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000
const int MAX = 1000000;
const int MOD = 1000000007;

int main(){
	int l;
    cin>>l;
    double a=(double)l/3;
    double ans=pow(a,3.0);
    printf("%.8lf\n",ans);
    return 0;
}

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

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

    vector<int> A(3);
    for(int i = 0; i < 3; i++){
        cin >> A[i];
    }

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

    if(A[0] + A[1] == A[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    cout << (h2 - h1) * 60 + m2 - m1 - k << endl;
    return 0;
}

Measured memory_bytes: 3636
AB = tuple(map(int, input().split()))
WB = ".#"

grid = [[[WB[-1-i]]*100 for _ in range(50)] for i in range(2)]

for i in range(2):
  H, W = divmod(AB[i]-1, 50)
  for h in range(H):
    for j in range(50):
      grid[i][2*h+i][2*j] = WB[i]
  for w in range(W):
    grid[i][2*H+i][2*w] = WB[i]

print(100, 100)
for G in grid:
  for ans in G:
    print("".join(ans))

Measured memory_bytes: 9288
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, h;
	cin >> n >> h;
	ll a[n], b[n];
	for(int i=0; i<n; i++) cin >> a[i] >> b[i];
	sort(a, a+n, greater<ll>());
	sort(b, b+n, greater<ll>());
	ll ans=0;
	for(int i=0; i<n && h>0 && b[i]>=a[0]; i++){
		ans++;
		h-=b[i];
	}
	if(h>0) ans+=(h+a[0]-1)/a[0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
int a[100005];
int inc(const void *a, const void *b)
{
    return *(int *)a-*(int *)b;
}
int main()
{
	int n,m,min=-1;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	qsort(a,n,sizeof(int),inc);
	for(int i=0;i<=(n-m);i++)
	{
		if(min==-1)min=a[i+m-1]-a[i];
		if(min>a[i+m-1]-a[i])min=a[i+m-1]-a[i];
	}
	printf("%d\n",min);
}

Measured memory_bytes: 1020
#include<cstdio>
char s[100001];
int main(){
    int c[26]={};
    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++)c[s[i]-'a']++;
    for(int i=0;i<26;i++){
        if(c[i]==0){
            printf("%c",'a'+i);
            return 0;
        }
    }
    printf("None");
    return 0;
}

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 n, m;
  cin >> n >> m;
  vector<int> ac(n), wa(n);
  rep(i, m) {
    int p;
    string s;
    cin >> p >> s;
    p--;

    if (s == "AC")
      ac[p] = 1;
    else if (!ac[p])
      wa[p]++;
  }
  int ans1 = 0, ans2 = 0;
  rep(i, n) {
    ans1 += ac[i];
    if (ac[i]) ans2 += wa[i];
  }
  printf("%d %d\n", ans1, ans2);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100000], b[100000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
        cin >> a[i];

    sort(a, a + m);
    for (int i = 1; i < m; ++i)
        b[i - 1] = a[i] - a[i - 1];

    sort(b, b + m - 1);
    int sol = 0;
    for (int i = 0; i < m - n; ++i)
        sol += b[i];
    cout << sol;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	char tem;
	int i,j;
	cin>>s;
	if(s=="zyxwvutsrqponmlkjihgfedcba")
	{
		cout<<-1<<endl;
		return 0;
	}
	if(s.size()!=26)
		for(i=0;i<26;i++)
			if(s.find(i+'a')==-1)
			{
				tem=i+'a';
				cout<<s<<tem<<endl;
				return 0;
			}
	for(i=25;i>=0;i--)
	{
		tem=s[i];
		for(j=tem-'a'+1;j<26;j++)
			if(s.find(j+'a')==-1)
			{
				tem=j+'a';
				s=s.substr(0,s.size()-1);
				cout<<s<<tem<<endl;
				return 0;
			}
		s=s.substr(0,s.size()-1);
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int main(void){
  static bool cmp[10000000] = {true};
  static int npr[10000000];
  loop(i,2,10000000){
    if(!cmp[i]){
      for(int j = 2 ; j * i < 10000000 ; j ++){
	cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1] + !cmp[i];
  }
  int n ;
  while(cin>>n){
    cout<<npr[n]<<endl;
  }
}
  

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a <= b && b <= c) {
    /* code */
    cout << a << " " << b << " " << c << endl;
  }
  else if (a <= c && c <= b)
  {
    /* code */
    cout << a << " " << c << " " << b << endl;
  }
  else if (b <= a && a <= c)
  {
    /* code */
    cout << b << " " << a << " " << c << endl;
  }
  else if (b <= c && c <= a)
  {
    /* code */
    cout << b << " " << c << " " << a << endl;
  }
  else if (c <= a && a <= b)
  {
    /* code */
    cout << c << " " << a << " " << b << endl;
  }
  else
  {
    /* code */
    cout << c << " " << b << " " << a << endl;
  }

  return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

vector<int> edge[100010];
int dp[100010];
int color[100010];
void bfs(int vv,int dd,int cc){
    queue<pair<int,int>> q;
    q.push({vv,dd});
    while(q.size()){
        auto x=q.front(); q.pop();
        int vvv=x.first,ddd=x.second;
        if(!color[vvv]) color[vvv]=cc;
        if(dp[vvv]>=ddd) continue;
        dp[vvv]=ddd;
        for(auto to:edge[vvv]){
            q.push({to,ddd-1});
        }
    }
}
int main(){
    int n,m; cin>>n>>m;
    rep(i,m){
        int a,b; cin>>a>>b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    int q; cin>>q;
    int v[q],d[q],c[q];
    rep(i,q) cin>>v[i]>>d[i]>>c[i];
    rep(i,q){
        bfs(v[q-1-i],d[q-1-i],c[q-1-i]);
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",color[i]);
    }
    return 0;
}


Measured memory_bytes: 8952
# -*- coding:utf-8 -*-
H, W = map(int, input().split())
factors = []
for h1 in range(1,H):
    subHeight = H-h1
    h2 = subHeight//2
    h3 = subHeight-h2
    w2 = W//2
    w3 = W-w2
    s1 = [ h1*W, h2*W, h3*W ]
    s2 = [ h1*W, subHeight*w2, subHeight*w3 ]
    factors.append(max(s1)-min(s1))
    factors.append(max(s2)-min(s2))

for w1 in range(1,W):
    subWidth = W-w1
    w2 = subWidth//2
    w3 = subWidth-w2
    h2 = H//2
    h3 = H-h2
    s1 = [ H*w1, H*w2, H*w3 ]
    s2 = [ H*w1, h2*subWidth, h3*subWidth ]
    factors.append(max(s1)-min(s1))
    factors.append(max(s2)-min(s2))

print(min(factors))

Measured memory_bytes: 18968
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);
    int r = cin.nextInt();
    int g = cin.nextInt();
    int b = cin.nextInt();
    int n = cin.nextInt();
//    int record = n;
    int res = 0;
    for (int i = 0; i <= n / r; i++) {
      int remainedTwo = n - i * r;

      for (int j = 0; j <= remainedTwo / g; j++) {
        int remainedOne = remainedTwo - j * g;
//        System.out.println(i+" "+j+" "+remainedOne/b);
        if (remainedOne % b == 0){
          res++;
        }
      }
    }
    System.out.println(res);

  }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int b[n];
    int num=0;
    for(int i=0;i<n;i++){
        cin>>b[i];
        b[i]/=400;
        if(b[i]>=8){
            num++;
        }
    }
    int c[100]={0};
    for(int i=0;i<n;i++){
        c[b[i]]++;
    }
    int niko=0;
    for(int i=0;i<8;i++){
        if(c[i]){
            niko++;
        }
    }

    if(niko){
        cout << niko<<" "<< niko+num<<endl;
    }
    else{
        cout << 1<<" "<<num<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
s=list(map(int,list(input())))
#print(s)
first=10*s[0]+s[1]
second=10*s[2]+s[3]
# print(first)
# print(second)

if (13<=first or first ==0) and (13<=second or second ==0):
    print("NA")

elif 1 <= first <= 12 and 1 <= second <= 12:
    print("AMBIGUOUS")

elif 1 <= first <= 12 and (second >= 13 or second==0):
    print("MMYY")
elif 1 <= second <= 12 and (first >= 13 or first==0):
    print("YYMM")


Measured memory_bytes: 3060
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

K, Q = list(map(int, sys.stdin.buffer.readline().split()))
D = list(map(int, sys.stdin.buffer.readline().split()))
NXM = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]

D = np.array(D, dtype=int)


def solve(n, x, m):
    cum = (D % m).cumsum()
    zerocum = (D % m == 0).cumsum()
    last = x % m + cum[-1] * ((n - 2) // K) + cum[(n - 2) % K]
    # a[i] < [i + 1] になる数: x → last になるまでに何周するか
    gt = last // m
    # a[i] == a[i + 1] になる数
    eq = zerocum[-1] * ((n - 2) // K) + zerocum[(n - 2) % K]
    return n - 1 - gt - eq


for n, x, m in NXM:
    ans = solve(n, x, m)
    print(ans)


Measured memory_bytes: 15696
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

long long Gcd(long long m, long long n)
{
	long long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

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

	long long A, B, C, D, E, temp1, temp2, temp3;

	cin >> A >> B >> C >> D;

	temp1 = B / C - ((A + (C - 1)) / C) + 1;

	temp2 = B / D - ((A + (D - 1)) / D) + 1;

	E = C * D / Gcd(C, D);

	temp3 = B / E - ((A + (E - 1)) / E) + 1;

	cout << (B - A + 1) - (temp1 + temp2 - temp3) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(int i =(a);i<(n);i++)
#define urep(i,a,n) for(int i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

ll W, H, N,ans,a,b,w;
ll A[200000];
string s;
int main() {
	cin >> s >> w;
	for (int i = 0; i < s.size(); i += w) {
		cout << s[i];
	}
	cout << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    ll ans = 0;
    for(ll b=k+1;b<=n;b++){
        if(k == 0){
            ans += n;
            continue;
        }
        ll s = n/b;
        ll t = n%b;
        ans += max(b-k, (ll)0)*s + max(t-k+1,(ll)0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#define llint long long

using namespace std;
typedef pair<llint, pair<llint, llint> > J;

llint n, k;
vector<llint> vec[200005];
vector<J> vec2, vec2r;
priority_queue<J> Q;
set<pair<llint, llint> > S;
llint preS, preP;

int main(void)
{
	cin >> n >> k;
	llint c, v;
	for(int i = 1; i <= n; i++){
		cin >> c >> v;
		vec[c].push_back(2*v);
	}
	for(int i = 1; i <= k; i++){
		sort(vec[i].rbegin(), vec[i].rend());
		llint m = vec[i][0] + vec[i][1];
		vec[i][0] = vec[i][1] = m/2;
		for(int j = 0; j < vec[i].size(); j++) vec2.push_back(make_pair(vec[i][j], make_pair(-i, -j)));
	}
	sort(vec2.rbegin(), vec2.rend());
	
	preS = preP = -1;
	for(int i = 1; i <= k; i++){
		if(vec[i].size() >= 3) S.insert(make_pair(vec[i][0] + vec[i][1] + vec[i][2], i));
	}
	
	llint sum = 0;
	for(int i = 1; i <= n; i++){
		sum += vec2[i-1].first;
		
		llint c = -vec2[i-1].second.first, ans = sum;
		if(Q.size() && Q.top() == vec2[i-1]){
			Q.pop();
			preS = vec2[i-1].first;
		}
		if(-vec2[i-1].second.second == 1){
			for(int j = 2; j < vec[c].size(); j++) Q.push(make_pair(vec[c][j], make_pair(-c, -j)));
			preP = vec[c][0] + vec[c][1];
			S.erase(make_pair(vec[c][0] + vec[c][1] + vec[c][2], c));
		}
		
		if(i < n && vec2[i-1].second.first == vec2[i].second.first && vec2[i-1].second.second == 0){
			ans = -2;
			if(Q.size()) ans = max(ans, sum - vec2[i-1].first + Q.top().first);
			if(S.size() && preP != -1){
				auto p = S.end();
				p--;
				ans = max(ans, sum - (preP + vec2[i-1].first) + p->first);
			}
			if(preS != -1) ans = max(ans, sum - preS + vec2[i].first);
		}
		cout << ans/2 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 25836
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    S = input()
    r = S.count('R')
    ans = 0
    for c in S[:r]:
        ans += c != 'R'
    print(ans)
resolve()

Measured memory_bytes: 67912
#include<bits/stdc++.h>
using namespace std;
struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

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

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

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

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

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

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

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

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


int main() {
    int key,n;
    int size = 0;
    char com[20];
    scanf("%d", &n);
    init();
    for(int i = 0; i < n; i++) {
        scanf("%s%d",com, &key);
        if(com[0] == 'i') {
            insert(key);
            size++;
        }
        else if(com[0] == 'd') {
            if(strlen(com) > 6) {
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            }
            else {
                deleteKey(key);
            }
            size--;
        }
    }
    printList();
    
    return 0;
}


Measured memory_bytes: 34412
#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int main()
{
  int t=1;
  //cin>>t;
  while(t--)
  {
    ll a,b,c,d,mx1,mx2;
   cin>>a>>b>>c>>d;
   mx1=(a*c);
   mx2=(b*d);
   mx1=max(mx2,mx1);
   mx1=max(mx1,(a*d));
   mx1=max(mx1,(b*c));
   cout<<mx1<<endl;
  }
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int sum = 0;
  for (int i = 0;i < n;i++){
    int loc;
    cin >> loc;
    if (abs(loc-k) >= loc)
      sum += loc * 2;
    else
      sum += abs(loc-k) * 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int N=200002;
int n,a[N];
int b[N];
int h[N],w;
int to[N];
LL K;

void read(int &x){ scanf("%d",&x); }
void read(LL &x){ scanf("%lld",&x); }

void gooo(int p,int s){ //暴力按题意加入数字
    memset(b,0,sizeof b);
    fr(i,1,s){
        if (!b[a[p]]) h[++w]=a[p],b[a[p]]=1;
         else{
            while(h[w]!=a[p]) b[h[w]]=0,w--;
            b[h[w]]=0;w--;
          }
        p=p%n+1;
    }
    fr(i,1,w) printf("%d ",h[i]);
}

void goo(int p,LL s){ //暴力跳到最后一次清空
// printf("%d %lld\n", p, s);
    while(to[p]-p+1<=s){
        s-=to[p]-p+1;
        p=to[p]%n+1;
    }
    gooo(p,s);
}

int main(){
    read(n);read(K);
    fr(i,1,n) read(a[i]);
    rf(i,n,1) b[a[i]]=i+n;
    rf(i,n,1) to[i]=b[a[i]],b[a[i]]=i;
    memset(b,0,sizeof b);
    int p=1;LL s=0,sc=0; //s表示从1走完循环节的总次数，sc表示循环节上的总次数
    while(!b[p]){
        b[p]=1;
        s+=to[p]-p+1;
        p=to[p]%n+1;
    }
    int q=p;
    while(1){
        sc+=to[q]-q+1;
        q=to[q]%n+1;
        if (q==p) break;
    }
    if (n*K<=s) goo(1,n*K);
     else goo(p,(n*K-s)%sc);
    return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int INF = 1000000009;

int main() {
  int n; cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  vector<int> dp(n+2, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    if (i+1 < n) dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    if (i+2 < n) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
from operator import itemgetter

N = int(input())
list = []
for i in range(N):
  line = input()
  list.append((line.split()[0], int(line.split()[1]), i + 1))

a = sorted(list, key=itemgetter(1), reverse=True)
b = sorted(a, key=itemgetter(0))  

for city, score, index in b:
  print(index)

Measured memory_bytes: 3064
n,k=map(int,input().split())
a=list(map(int,input().split()))
k-=1
ans=1<<99
for i in range(n-k):
    ans=min(ans,abs(a[i])+a[k+i]-a[i],abs(a[k+i])+a[k+i]-a[i])
print(ans)


Measured memory_bytes: 62576
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	return fac[a] * ifac[a - b] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int a;
	cin >> a;
	cout << 3 * a*a << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
#define erase(s) s.erase(s.end()-1) //文字列sの末尾削除

ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  ll w,h,n;
  cin3(w,h,n);
  vec x(n);
  vec y(n);
  vec a(n);
  loop(i,n)cin3(x[i],y[i],a[i]);
  ll field[w][h];
  loop(i,w)loop(j,h)field[i][j]=1;
  loop(i,n){
    if(a[i]==1)loop(j,x[i])loop(k,h)field[j][k]=0;
    if(a[i]==2)Loop(j,x[i],w)loop(k,h)field[j][k]=0;
    if(a[i]==3)loop(k,y[i])loop(j,w)field[j][k]=0;
    if(a[i]==4)Loop(k,y[i],h)loop(j,w)field[j][k]=0;
  }
  ll ans=0;
  loop(i,w)loop(j,h)ans+=field[i][j];
  putout(ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0);
	//freopen("in.txt", "r", stdin);
	char c;
	cin >> c;
	c = c+1;
	cout << c;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(long long int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll inf = (1LL << 60);
const int MOD = 1000000007;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main() {
    int n; cin >> n; vector<ll> c(n), s(n), f(n);
    rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];
    rep(i, n) {
        int t = 0;
        for (int j = i; j < n - 1;j++) {
            if (t < s[j]) t = s[j];
            else if (t % f[j] == 0);
            else t = t + f[j] - (t % f[j]);
            t += c[j];
        }
        cout << t << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0

signed main() {
	int n;
	cin >> n;
	int t[1005], a[1005];
	for (int i = 0; i < n; i++) cin >> t[i] >> a[i];
	for (int i = 1; i < n; i++) {
		int b, c;
		if (t[i - 1] % t[i] == 0) b = t[i - 1] / t[i];
		else b = t[i - 1] / t[i] + 1;
		if (a[i - 1] % a[i] == 0) c = a[i - 1] / a[i];
		else c = a[i - 1] / a[i] + 1;
		t[i] *= max(b, c);
		a[i] *= max(b, c);
	}
	cout << t[n - 1] + a[n - 1] << endl;

	END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

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

int main(){
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    ll ans=0;
    if(n==1&&m==1) ans=1;
    else if(n==1) ans=m-2;
    else if(m==1) ans=n-2;
    else ans=(m-2)*(n-2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000000000009
using namespace std;
int n,m,maxi=0,a[1009];
ll b[1009],dp[30009],ans=inf;
int main()
{
    fill(dp,dp+30009,inf);
    dp[0]=0;
    scanf("%d%d",&m,&n);
    for(int i=1; i<=n; i++)
        scanf("%d%lld",&a[i],&b[i]),maxi=max(maxi,a[i]);
    for(int i=1; i<=n; i++)
        for(int j=a[i]; j<=m+maxi; j++)
            dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
    for(int i=m; i<=m+maxi; i++)
        ans=min(ans,dp[i]);
    printf("%lld",ans);
    return 0;
}


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

int main()
{
	int direct = 0; // ↑0、→1、↓2、←3
	int x = 1;
	int y = 1;
	char ch[100];
	int num;
	int map_x,map_y;
	scanf("%d %d",&map_x,&map_y); // マップの読み込み
	while(map_x != 0 || map_y != 0){
		scanf("%s", ch); // 命令の読み込み
		
		x = 1;
		y = 1;
		direct = 0;
		num = 0;

		while(strcmp(ch,"STOP")){
	
			// 各命令に対して
	
			if(strcmp(ch,"FORWARD") == 0){
				scanf("%d", &num);
				
				if(direct == 0){
					y += num;
				}if(y > map_y){
					y = map_y;
				}
				if(direct == 1){
					x += num;
				}if(x > map_x){
					x = map_x;
				}
				if(direct == 2){
					y -= num;
				}if(y < 1){
					y = 1;
				}
				if(direct == 3){
					x -= num;
				}if(x < 1){
					x = 1;
				}

				//printf("(%d,%d) direct %d\n",x,y,direct);
			}
			if(strcmp(ch,"BACKWARD") == 0){
				scanf("%d", &num);

				if(direct == 2){
					y += num;
				}if(y > map_y){
					y = map_y;
				}
				if(direct == 3){
					x += num;
				}if(x > map_x){
					x = map_x;
				}
				if(direct == 0){
					y -= num;
				}if(y < 1){
					y = 1;
				}
				if(direct == 1){
					x -= num;
				}if(x < 1){
					x = 1;
				}

				//printf("(%d,%d) direct %d\n",x,y,direct);
			}
			if(strcmp(ch,"RIGHT") == 0){
				direct++;
				if(direct > 3){
					direct = 0;
				}
				//printf("direct %d\n",direct);
			}
			if(strcmp(ch,"LEFT") == 0){
				direct--;
				if(direct < 0){
					direct = 3;
				}
				//printf("direct %d\n",direct);
			}
			scanf("%s", ch); // 命令の読み込み
		}
		printf("%d %d\n",x,y);
		scanf("%d %d",&map_x,&map_y); // マップの読み込み
	}
	return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
using vs= vector<string>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  bool rvsd=0;
  char c;
  string s,front,back;
  int q,t,f;
  cin >> s >> q;

  rep(i,0,q){
    cin >> t;
    if(t==2){
      cin >> f >> c;
      if((f==2&&!rvsd) || (f==1&&rvsd)){
        front+=c;
      }else{
        back+=c;
      }
    }else{
      rvsd^=1;
    }
  }
  reverse(all(back));
  s= back+s+front;
  if(rvsd){
    reverse(all(s));
  }
  cout << s << endl;
}


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

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

using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}
typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  rep(i,N){
    v[i] = i+1;
  }
  vector<int> P(N),Q(N);
  rep(i,N){
    cin >> P[i];
  }
  rep(i,N){
    cin >> Q[i];
  }
  sort(v.begin(),v.end());
  int a = 1;

  do{
    vector<int> t;
    for(int x : v){
      t.push_back(x);
    }
    if(t == P) break;
    a++;
  }while(next_permutation(v.begin(),v.end()));
 
  sort(v.begin(),v.end());
  
  int b = 1;

  do{
    vector<int> t;
    for(int x : v){
      t.push_back(x);
    }
    if(t == Q) break;
    b++;
  }while(next_permutation(v.begin(),v.end()));

  
  cout << abs(a-b) << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	vi data(3);
	REP(i, 3) {
		cin >> data[i];
	}
	sort(data.begin(), data.end());
	REP(i, 3) {
		if (i == 2) cout << data[i] << endl;
		else cout << data[i] << " ";
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  ll ans=(b*(n-1)+a)-(a*(n-1)+b)+1;
  if(ans<0) cout<<0<<endl;
  else cout<<ans<<endl;
}


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

int main (){
	int N;cin>>N;
	if(N==1){
		cout<<"Hello World"<<endl;
	}else{
		int A,B;cin>>A>>B;
		cout<<A+B<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
/**
 *  author: andychen
 *  created: 09.14.2020 00:44:40
**/

#include <bits/stdc++.h>

using namespace std;

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

    long long plus_mx = LLONG_MIN, plus_mn = LLONG_MAX, minus_mx = LLONG_MIN, minus_mn = LLONG_MAX;
    for (int i = 0; i < n; i++){
        long long x, y;
        cin >> x >> y;
        plus_mx = max(plus_mx, x + y);
        plus_mn = min(plus_mn, x + y);
        minus_mx = max(minus_mx, x - y);
        minus_mn = min(minus_mn, x - y);
    }

    cout << max(plus_mx - plus_mn, minus_mx - minus_mn) << '\n';

    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B;
    cin >> A >> B;
    ll temp = A + B;
    if(temp >= 10) cout << "error";
    else cout << temp;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3532
A,B,C,D = map(int,input().split())

# n 以下の数に m の倍数が何個あるかを返す関数
def baisuNum(n,m):
    return n // m

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a,b):
    return (a*b) // gcd(a,b)


# B以下　―　(A-1)以下　にCの倍数何個ある
CC = baisuNum(B,C) - baisuNum(A-1,C)
# B以下　―　(A-1)以下　にDの倍数何個ある
DD = baisuNum(B,D) - baisuNum(A-1,D)
# B以下　―　(A-1)以下　にCかつDの最小公倍数の倍数何個ある
LCM = lcm(C,D)
CD = baisuNum(B, LCM) - baisuNum(A-1, LCM)

print(B-A+1-CC-DD+CD)


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.siz = [1] * n
    
    def root(self, x):
        if self.par[x] == x: return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def size(self, x):
        self.siz[self.root(x)]

    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        if rx != ry:
            if self.siz[rx] < self.siz[ry]: 
                rx, ry = ry, rx
            self.par[ry] = rx
            self.siz[rx] += self.siz[ry]
    
    def same(self, x, y):
        return self.root(x) == self.root(y)

n, m = map(int, input().split())
p = list(map(int, input().split()))
uf = UnionFind(n)

for i in range(m):
    x, y = map(int, input().split())
    uf.unite(x-1, y-1)

ans = 0
for i, val in enumerate(p):
    if uf.same(i, val-1):
        ans += 1
print(ans)


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

int main() {
  string s;
  cin>>s;
  
  int i=0;
  int j=s.length()-1;
  
  while(s.at(i)!='A')i++;
  while(s.at(j)!='Z')j--;
  cout<<j-i+1<<endl;
  
}


Measured memory_bytes: 640
nums = [c for c in input()]
n = int(nums[0])
if nums[0] == nums[1]:
    if nums[2] <= nums[1]:
        print ('%d%d%d' % (n, n, n))
    else:
        print ('%d%d%d' % (n+1, n+1, n+1))
elif nums[0] > nums[1]:
    print ('%d%d%d' % (n, n, n))
else:
    print ('%d%d%d' % (n+1, n+1, n+1))

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }





int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);


    string s;
    cin >> s;
    ll n = sz(s) + 1;
    vl down(n);
    for (ll i = 1; i < n; ++i) {
        down[i] = down[i - 1] + 1;
        if (s[i - 1] == '>') down[i] = 0;
    }

    vl up(n);
    for (ll i = n - 1; i >= 1; --i) {
        up[i - 1] = up[i] + 1;
        if (s[i - 1] == '<') up[i - 1] = 0;
    }

    ll ans = 0;
    for (ll i = 0; i < n; ++i) {
        ans += max(up[i], down[i]);
    }

    cout << ans << endl;



    print_time();
    return 0;
}


Measured memory_bytes: 8732
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int a,b,c,k; cin >> a >> b >> c >> k;
    int res=0;
    while(a>=b){
        b*=2;
        res++;
    }
    while(b>=c){
        c*=2;
        res++;
    }
    
    yn(res<=k);
}

Measured memory_bytes: 3648
//you never give up.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define v32 vector<int>
#define v64 vector<ll>

using namespace std;

void solve()
{
    int x;
    cin >> x;
    if (x >= 30)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
}

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

#define sz(x) (int)(x.size())
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
#define rep(i, a, b) for(int i=a;i<b;++i)
//////////////////////

int const N = 1e6 + 41;
ll const INF = N * 1LL * N;


ll n, s;

ll f(ll b, ll n){
	if(n < b) return n;
	return n % b + f(b, n/b);
}

void solve(){
	ll ans = INF;
	cin >> n >> s;
	rep(i, 2, N) if(f(i, n) == s){
		cout << i << endl;
		return;
	}

	rep(i, 1, N){
		ll cur = n / i;
		if(cur <= 1) continue;
		ll val = f(cur, n);
		ll nxt = n / (i + 1);
		ll cnt = cur - nxt - 1;
		if(cnt <= 0) continue;
		if(s >= val){
			if((s- val) % i == 0){
				if( (s-val) / i <= cnt){
					ans = cur - (s-val)/i;
				}
			}
		}
	}
	if(n == s) ans = min(ans, n+1);

	if(ans == INF) ans = -1;
	if(ans != -1){
		assert(s == f(ans, n));
		//rep(i, -10, 10) cout << f(ans + i, n) << endl;
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

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

const int maxn=2e5+10;

int n,a[maxn],deg[maxn];
int tote,FIR[maxn],TO[maxn],NEXT[maxn];
bool vis[maxn],leaf[maxn];
queue<int> q;
vector<int> son[maxn];

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

int main()
{
#ifdef h10
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
		deg[u]++; deg[v]++;
	}
	for (i=1;i<=n;i++)
		if (deg[i]==1) leaf[i]=1,q.push(i);
	while (!q.empty())
	{
		u=q.front(); q.pop();
		vis[u]=1;
		if (!leaf[u])
		{
			int sum=0,mx=0;
			for (i=0;i<(int)son[u].size();i++)
				sum+=son[u][i],mx=max(mx,son[u][i]);
			int A=sum-a[u],B=a[u]-A;
			if (A<0||B<0) {puts("NO"); return 0;}
			if (sum-mx<A) {puts("NO"); return 0;}
			a[u]=B;
		}
		if (!deg[u]) break;
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (vis[v]) continue;
			deg[v]--;
			if (deg[v]==1) q.push(v);
			if (leaf[v])
			{
				int times=min(a[u],a[v]);
				a[u]-=times; a[v]-=times;
			}
			else son[v].push_back(a[u]),a[u]=0;
		}
	}
	for (i=1;i<=n;i++)
		if (a[i]) {puts("NO"); return 0;}
	puts("YES");
}


Measured memory_bytes: 11904