akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}

int keta(int x){
  for(int i=1;i<11;i++){
    if(x==0||x==1){
      return 1;
    }

    if(x!=0&&x!=1){
    if(x%int(pow(10,i))==x){
return i;
      break;
    }
  }
}

}

int main(){
  ll X;
  cin>>X;
  ll max=0;
  
  while(max*(max+1)/2<=X){
    max++;
  }
  
  ll ans=0;
  ll sum=0;
for(ll i=1;i<=max;i++){
  sum+=i;
  ans++;
  if(sum>=X){
    break;
  }
}

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

// A
signed main(){
  int n; cin>>n;
  if(n==1) cout<<"Hello World"<<en;
  else{
    int a,b; cin>>a>>b;
    cout<<a+b<<en;
  }
}


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

int main() {

	int x, a, b; cin >> x >> a >> b;
	string ans;
	if (b <= a) ans = "delicious";
	else {
		if (b - a <= x) ans = "safe";
		else ans = "dangerous";
	}	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
# import sys
import math #sqrt,gcd
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import permutations #順列生成
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    x,y,z = readInt()
    ans = 0
    while True:
        if y*(ans+1)+z*(ans+1)<=x-z:
            ans += 1
        else:
            break
    print(ans)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 38512
//i hate _____
#include<bits/stdc++.h>

#define ll long long int 
#define ld long double 
#define pb push_back
#define mk make_pair
#define ii pair<int , int>

using namespace std;
double pi = 2 * acos(0.0) ;
const int M=1e5;

template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << " " << x;
        return os << '}'; 
}

vector<int>v(M+1);
map<ll,int>mp;

void solve(){
    
}

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

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll n,x,m; cin>>n>>x>>m;
    ll ans = 0;
    int move ;
    for (move=1;move <= n ; move++){
        //x %= m;
        mp[x]++;
        if (mp[x]==2) break;
        ans += x;
        v[x] = move ;
        x *= x; x %= m;
    }
    if (move > n) {
        cout << ans << endl;
        return 0;
    }
    //cout << move << endl;
    ll majhe = move - v[x] ; //cout << majhe << endl;
    ll baki = n-move+1;
    vector<int>sum; sum.pb(0);
    ll ss=0;
    for (int i=0;i<majhe;i++){
        //x %= m;
        //mp[x]++;
        //if (mp[x]==2) break;
        ss += x; sum.pb(ss);
        //v[x] = move ;
        x *= x; x %= m;
    }
    ans += (ss*(baki/majhe));
    ans+= sum[baki%majhe];
    cout << ans << endl;
    
    return 0;
}
/*
    problems are the sign of life
*/


Measured memory_bytes: 7052
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=int(input())
h=c-b
i=d-b
j=e-b
k=f-b
l=d-c
m=e-c
n=f-c
o=e-d
p=f-d
q=f-e
r=int(input())
s=":("
if r<h:
  print(s)
elif r<i:
  print(s)
elif r<j:
  print(s)
elif r<k:
  print(s)
elif r<l:
  print(s)
elif r<m:
  print(s)
elif r<n:
  print(s)
elif r<o:
  print(s)
elif r<p:
  print(s)
elif r<q:
  print(s)
else:
  print("Yay!")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	cin >> n;
	map<string, bool> gacha;
	for (int i = 0; i < n; ++i)
	{
		string in;
		cin >> in;
		gacha[in] = 1;
	}
	cout << gacha.size() << endl;
	return 0;
}

Measured memory_bytes: 19148
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int n;
    cin >> n;

    vs32 a(n + 1);
    rep (i, n) cin >>  a[i + 1];

    for (int i = 1; i <= n; ++i)
    {
        cout << "node " << i << ": ";
        cout << "key = " << a[i] << ", ";
        if (i / 2 > 0)
        {
            cout << "parent key = " << a[i / 2] << ", ";
        }
        if (2 * i <= n)
        {
            cout << "left key = " << a[2 * i] << ", ";
        }
        if (2 * i + 1 <= n)
        {
            cout << "right key = " << a[2 * i + 1] << ", ";
        }
        cout << "\n";
    }

    return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pi;
typedef vector <int> vi;
typedef vector <pair <int, int>> vpi;

int n;

vpi v;

void read() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    v.pb({x, y});
  }
}

bool cmp(pi a, pi b) {
  if (a.se < b.se)
    return true;
  return false;
}

void solve() {
  sort(v.begin(), v.end(), cmp);
  ull currentTime = 0;
  for(auto x : v) {
    currentTime += x.fi;
    if (currentTime > x.se) {
      cout << "No";
      return;
    }
  }
  cout << "Yes";
}
;
int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  read();
  solve();
  return 0;
}


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

const int MAXN = 1e5+5;

ll n, a[MAXN], s;
ll indo = -1;

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

	if (n == 1) {
		cout << "Second\n";
		return 0;
	}

	int ct = 0;
	while (true) {
		indo = -1;
		s = 0;
		for (int i = 0; i < n; ++i)
			s += a[i];
		if (s%2 == (n+1)%2) {
			cout << ((ct%2 == 0) ? "First\n" : "Second\n");
			return 0;
		}

		for (int i = 0; i < n; ++i) {
			if (a[i]%2 == 1) {
				if (indo != -1) {
					cout << ((ct%2 == 0) ? "Second\n" : "First\n");
					return 0;
				}

				indo = i;
			}
		}

		if (a[indo] == 1) {
			cout << ((ct%2 == 0) ? "Second\n" : "First\n");
			return 0;
		}

		a[indo]--;

		ll g = 0;
		for (int i = 0; i < n; ++i)
			g = __gcd(g + a[i], a[i]);
		for (int i = 0; i < n; ++i)
			a[i] /= g;
		++ct;
	}
}

Measured memory_bytes: 1024
def comb(a,b,m):
	if b == 0 or b == a:
		ret = 1
	else:
		ret = 1
		for i in range(a-b+1,a+1):
			ret = (ret * i) % m
		for i in range(1,b+1):
			ret = (ret * pow(i,m-2,m) ) % m
	return ret % m

mod = 10**9+7
x, y = [ int(v) for v in input().split() ]

ans = 0
if (2*x-y) % 3 == 0 and (2*y-x) % 3 == 0:
    x, y = (2*x-y) // 3, (2*y-x) // 3
    if x >= 0 and y >= 0:
    	ans = comb(x+y,y,mod)
print(ans)


Measured memory_bytes: 38640
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n, v[51], c[51], a[51];
  cin >> n;
  for(int i=0;i<n;i++)cin >> v[i];
  for(int i=0;i<n;i++)cin >> c[i];
  for(int i=0;i<n;i++)a[i] = v[i] - c[i];
  sort(a, a+n, greater<int>());
  int ans = 0;
  if(a[0] <= 0)ans = 0;
  else{
      for(int i=0; i<n; i++){
          if(a[i] > 0){
              ans += a[i];
          }
      }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int mm = sc.nextInt();

        int[] u = new int[mm];
        int[] v = new int[mm];
        for(int i = 0; i < mm; i++) {
            u[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        int s = sc.nextInt();
        int t = sc.nextInt();
        ArrayList<ArrayList<Integer>> l = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            l.add(new ArrayList<>());
        }
        for(int i = 0; i < mm; i++) {
            l.get(u[i] - 1).add(v[i] - 1);
        }

        boolean[][] visit = new boolean[n][4];
        ArrayDeque<Move> q = new ArrayDeque<>();
        q.add(new Move(s-1, 0, 0));
        int ans = -1;
        while(!q.isEmpty()) {
            Move m = q.poll();
            if(visit[m.now][m.num]) {
                continue;
            }
            visit[m.now][m.num] = true;
            if(m.num == 0) {
                if(m.now == t-1) {
                    ans = m.cc;
                    break;
                }
                m.num = 3;
                m.cc++;
            } 
            ArrayList<Integer> ll = l.get(m.now);

            for(int i = 0; i < ll.size(); i++) {
                q.add(new Move(ll.get(i), m.num - 1, m.cc));
            }
        }

        System.out.println(ans);



    }
    static class Move {
        int now;
        int num;
        int cc;
        Move(int a, int b, int c) {
            now = a;
            num = b;
            cc = c;
        }
    }
}

Measured memory_bytes: 101388
n, k = map(int, input().split())
ans = 0

def expo(i, k):
    count = 0
    while i<k:
        i *= 2
        count+=1
    return count

for i in range(1, min(n+1, k)):
    exp = expo(i, k)
    ans += (1/n * (1/2)**exp)

if n >= k:
    ans += ((n - (k-1)) / n)
    
print(ans)

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int x = a*100 + b*10 + c;
  if(x%4 == 0) cout << "YES";
  else cout << "NO";
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef int64_t int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int64 n;
  cin>>n;
  vector<int64> a(n);
  int64 unit=n*(n+1)/2;
  int64 sum=0;
  for(int i = 0; i < n; ++i){
    cin>>a[i];
    sum+=a[i];
  }
  if(sum%unit!=0){
    cout<<"NO"<<endl;
    return 0;
  }
  int64 operate_num=sum/unit;

  vector<int64> diff(n);
  for(int i=0;i<n-1;i++){
    diff[i]=a[i+1]-a[i];
  }
  diff[n-1]=a[0]-a[n-1];
  for(auto& v:diff){
    v-=operate_num;
  }
  int64 count=0;
  for(auto v:diff){
    if(v==0) continue;
    else if(v>0){
      cout<<"NO"<<endl;
      return 0;
    }else if(-v%n!=0){
      cout<<"NO"<<endl;
      return 0;
    }else{
      count+=(-v)/n;
    }
  }

  if(count==operate_num){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }





  return 0;
}

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

int main(){
	int n, a, b; cin >> n >> a >> b;
	string s; cin >> s;
	int jap = 0, fore = 0;
	for(int i = 0; i < n; ++i){
		if(s[i] == 'a'){
			if(jap + fore < a + b){
				cout << "Yes\n";
				++jap;
			}else{
				cout << "No\n";
			}
		}else if(s[i] == 'b'){
			if(jap + fore < a + b && fore < b){
				cout << "Yes\n";
				++fore;
			}else{
				cout << "No\n";
			}
		}else{
			cout << "No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long

using namespace std;
const int MAXN = 100005;
const int MOD = 1000000007;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,o;
	cin >> n;
	o = 0;
	for(int i=0;i<n;i++){
		int a; cin >> a;
		if(a & 1) o++;
	}
	if(o&1) cout << "NO\n";
	else cout << "YES\n";
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n, max = -INT_MAX, min = INT_MAX, in;
  long long sum = 0;
 
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> in;
    max = std::max(max, in);
    min = std::min(min, in);
    sum += in;
  }
  cout << min << " " << max << " " << sum << endl;
 
  return 0;
}


Measured memory_bytes: 3100
#include "stdio.h"

int main(void){
  int x,i;
  long a,b,max,min,gap;
  max = 0;
  min = 0;
  gap = -99999999999999;
  scanf("%d", &x);
  for(i = 0; i < x; i++){
    scanf("%ld", &a);
    if(i == 0){//初期化
      max = a;
      min = a;
    }else{
      if(a > max){
        max = a;//最大値更新
        b = max - min;
        if(b > gap){//差が今までより大きければ更新
          gap = b;
        }
      }else{
        b = a - max;
        max = a;
        if(a < min){
          min = a;
        }
        if(b > gap){
          gap = b;
        }
      }
    }
  }
  printf("%ld\n", gap);
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  vector<vector<int> > A(H, vector<int>(W));
  rep(i, H)
    cin >> S[i];
  rep(i, H) {
    int begin = 0;
    rep(j, W) {
      if(S[i][j] == '#') {
	REP(k, begin, j)
	  A[i][k] += j - begin;
	begin = j+1;
      }
    }
    REP(k, begin, W)
      A[i][k] += W - begin;
  }
  rep(j, W) {
    int begin = 0;
    rep(i, H) {
      if(S[i][j] == '#') {
	REP(k, begin, i)
	  A[k][j] += i - begin;
	begin = i+1;
      }
    }
    REP(k, begin, H)
      A[k][j] += H - begin;
  }
  int ans = 0;
  rep(i, H) {
    rep(j, W) {
      ans = max(A[i][j]-1, ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20736
import sys

d = [[1, 2, 1, 2, 1, 4, 1, 4],
     [1, 2, 1, 4, 1, 4, 1, 2],
     [1, 4, 1, 2, 1, 2, 1, 4],
     [1, 4, 1, 4, 1, 2, 1, 2],
     [2, 1, 2, 1, 4, 1, 4, 1],
     [2, 1, 4, 1, 4, 1, 2, 1],
     [4, 1, 2, 1, 2, 1, 4, 1],
     [4, 1, 4, 1, 2, 1, 2, 1]]

for s in sys.stdin:
    c = map(int, s.split())
    r = 0
    min = 0x7fffffff
    for i in range(8):
        rr = 0
        for j in range(8):
            if c[j] > d[i][j]:
                rr += c[j] - d[i][j]
        if rr < min:
            min = rr
            r = i
    print ' '.join(map(str, d[r]))
    a = 1

Measured memory_bytes: 4264
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  int n = in;
  auto a = in.Array(n);

  map<int, int> m;
  for (auto& i : a) {
    if (i >= 3200) {
      m[8]++;
    }
    else m[(i / 400)]++;
  }
  err(m);
  int mini = m.size();
  int size = mini;
  if (m[8]) {
    mini = max(1, mini - 1);
    size--;
  }

  int maxi = size;
  maxi = maxi + m[8];
  cout << (mini) << ' ' << maxi << endl;


}


Measured memory_bytes: 256
S = input()
even = 0
odd = 0
for i, s in enumerate(S):
    if (i + 1) % 2 == 0:
        even += int(s)
    else:
        odd += int(s)
N = len(S)
if even >= odd:
    ans = odd + N // 2 - even
else:
    if N % 2 == 0:
        ans = even + N // 2 - odd
    else:
        ans = even + N // 2 - odd + 1
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define REP(i,a,n) for(ll i=a;i<(n);i++)
#define RE return
#define FILL(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define pb push_back
#define saz(a) a.size()
#define V vector
#define ld long double
#define viit(a) vector<int>::iterator a
#define IT iterater
#define FOR(i,a,n) for(ll i=a;i<=(n);i++)
#define B(s) s.back()
#define all(a) a.begin(),a.end()
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
	V<int>x;
	int n,m,mini=INT_MAX,sum=0,xu;
	cin>>n>>m;
	REP(i,0,n)
	{
		int y;
		cin>>y;
		x.pb(y);
	}
	REP(i,0,m){
		mini=INT_MAX;
		REP(j,0,n){
			if(mini>x[j]){
				mini=x[j];
				xu=j;
			}
		}
		x[xu]=INT_MAX;
		sum+=mini;
	}
	cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main(){

    int N;
    cin >> N;

    bool ans = false;
    for(int i = 1; i <= 9; i++) {
        for(int j = 1; j <= 9; j++) {
            if(i * j == N) ans = true;
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
/*C - Count Order*/
#include <bits/stdc++.h>

using namespace std;

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

	int a, b;
	int tam;
	
	cin >> tam;

	vector <int> arr1(tam);
	vector <int> arr2(tam);
	vector <int> copy(tam);


	for (int i = 0; i < tam; ++i)
		cin >> arr1[i];
	

	for (int i = 0; i < tam; ++i)
		cin >> arr2[i];
	

	copy = arr1;

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

	a = 1;
	while(copy != arr1){
		next_permutation(copy.begin(), copy.end());
		a++;
	}

	copy = arr2;

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

	b = 1;
	while(copy != arr2){
		next_permutation(copy.begin(), copy.end());
		b++;
	}

	cout << abs(a - b);


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define num_max(p,q)((p)>(q)?(p):(q))
#define num_min(p,q)((p)<(q)?(p):(q))
int cmp(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;//昇順
	 //降順ならreturn *(int*)b - *(int*)a;
}
int main()
{
char S[110];
scanf("%s",S);
int top;
int bottom;
int ans=0;
for(top=0,bottom=strlen(S)-1;top<bottom;top++,bottom--)
{
	if(S[top]!=S[bottom])ans++;
}
printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
n = int(input())

l = []
for i in range(1, n):
    a = i
    b = n - i
    ra = 0
    rb = 0

    flg = True
    while flg:
        aa = a % 10
        a //= 10
        ra += aa
        if a == 0:
            flg = False
    flg = True
    while flg:
        bb = b % 10
        b //= 10
        rb += bb
        if b == 0:
            flg = False
    l.append(ra+rb)
print(min(l))

Measured memory_bytes: 3864
import java.io.*
import java.util.*

fun solve(A: Long, B: Long, K: Long){
    val a = if(K >= A) 0 else A - K
    val b = Math.max(if(K >= A) B - (K - A) else B, 0)
    println("$a $b")
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    val K = sc.next().toLong()
    solve(A, B, K)
}



Measured memory_bytes: 31524
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long int lint;
typedef long long int llint;

#define INF 2147483647
#define LINF 92233720370000000000

int n, w;
llint dp[110][110000];
llint we[110], v[110];

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

    for (int i = 1; i <= n; i++) {
        cin >> we[i] >> v[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= w; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - we[i] >= 0)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - we[i]] + v[i]);
        }
    }

    llint ans = 0;
    for (int i = 1; i <= w; i++) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 87424
#include <iostream>
#define rep(a,i,n) for(int i=(a);i<(n);i++)

using namespace std;

int main(){
	long long x,count=0,sum=100;
	cin >> x;
	while(sum < x){
		sum += sum/100;
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 3620
from collections import defaultdict

def prime_factorization(n):
    result = defaultdict(int)
    if n < 2:
        return result
    while n >= 2 and n % 2 == 0:
        result[2] += 1
        n //= 2
    p = 3
    while p*p <= n:
        while n % p == 0:
            n = n // p
            result[p] += 1
        p += 2
    if n > 1:
        result[n] += 1
    return result

n = int(input())
factors = prime_factorization(n)
ans = '{}:'.format(n)
for p, num in sorted(factors.items()):
    ans += ' {}'.format(p) * num
print(ans)


Measured memory_bytes: 6000
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;

int main()
{
	int N,M,C;
	cin >> N >> M >> C;
	vector<int>A(M), B(M);
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	int ans = 0;
	for (int _ = 0; _ < N; _++) {
		int a=0;
		for (int i = 0; i < M; i++) {
			cin >> A[i];
			int D = A[i] * B[i];
			a = a + D;
		}
		//cout << a+C << endl;
		if (a + C > 0)ans++;
	}
	cout << ans << endl;
	


	return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll X;
  cin >> X;

  ll y = 0;
  ll m = 100;
  while(m < X) {
    m = m * 1.01;
    y++;
  }
  cout << y << endl;

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back

int main() 
{ 
    int l,r,d;
    cin>>l>>r>>d;
    int i,ans = 0;
    for(i=l;i<=r;i++)
        if(i%d==0)
            ans++;
    cout<<ans; 
    return 0; 
} 

Measured memory_bytes: 3632
#include<iostream>
#define M std::cin>>
int s[200001];main(){int n,c,l,z,x,h=1e9+7;M n;M z;c=l=s[z] = 1;for(int i = 2; i <= n; i ++){M x;if(x!=z){c+=s[x];c%=h;s[x]+=l;s[x]%=h;}l=c;z=x;}std::cout<<c;}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

struct Edge{ll from, to, dist;};
vector<vector<Edge> > path;
ll col[100010];
Edge e[200010];
void solve() {
    ll N;
    cin >> N;
    path.resize(2*(N - 1));
    for(int i = 0; i < N; i++) {
        col[i] = -1;
    }
    REP(i, N - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        Edge e1 = {a, b, c};
        Edge e2 = {b, a, c};
        path[a].push_back(e1);
        path[b].push_back(e2);
    }
    queue<ll> q;
    q.push(0);
    col[0] = 0;
    while(!q.empty()) {
        ll f = q.front();
        q.pop();
        auto routes = path[f];
        for(auto &route:routes) {
            if(col[route.to] == -1) {
                if(route.dist % 2 == 0) {
                    col[route.to] = col[route.from];
                }else {
                    col[route.to] = 1 - col[route.from];
                }
                q.push(route.to);
            }
        }
    }
    REP(i, N) {
        out(col[i]);
    }
}

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


Measured memory_bytes: 12416
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

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

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}


int main()
{
	int h, n;
	cin >> h >> n;
	vector<int> a(n);
	vector<int> b(n);
	rep(i,n){
		cin >> a[i] >> b[i];
	}
	vector<vector<int>> dp(n + 1, vector<int>(h+1, inf));
	dp[0][0] = 0;
	rep(i,n){
		rep(j,min(h+1,a[i]+1)){
			if (j == 0){
				dp[i + 1][j] = 0;
			}
			else dp[i + 1][j] = b[i];
		}
	}
	rep(i, n)
	{
		rep(j,h+1){
			// rep2(k,max(j-a[i],0),j){
			// 	if (k >= 0){
			// 		dp[i + 1][j] = min({dp[i + 1][j], dp[i][j], dp[i + 1][k] + b[i]});
			// 	} else
			// 		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			// }
			if (j-a[i] >= 0)
				dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
			else
				dp[i + 1][j] = min(dp[i + 1][j],dp[i][j]);
		}
	}
	cout << dp[n][h] << endl;
	return 0;
}

Measured memory_bytes: 39424
#include<cstdio>
#include<cstring>
using namespace std;
int main(void){
    char c[1001];
    scanf("%s",c);
    for(int i = 0;i < strlen(c);i++){
        if(c[i] == 'A') c[i] = 'X';
        else if(c[i] == 'B') c[i] = 'Y';
        else if(c[i] == 'C') c[i] = 'Z';
        else c[i] -= 3;
    }
    printf("%s\n",c);
}

Measured memory_bytes: 944
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  ll n;
  cin >> n;
  ll a[n], b[n], sum = 0, ans = (1<<30);
  rep(i, n) cin >> a[i], sum += a[i];
  if(n == 2){
    cout << abs(a[0]-a[1]) << endl;
    return;
  }else{
    b[0] = a[0];
    for(int i = 1; i < n-1; i++){
      b[i] = a[i]+b[i-1];
      if(abs(b[i]*2-sum) < ans){
        ans = abs(b[i]*2-sum);
      }
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 3328
Public Class Program
  Shared Sub Main()
    Const Abc As String = "ABC"
    Dim n As Integer = Cin.Int()
    Dim s As String = Cin.Str()
    Dim ans As Integer = 0
    Dim i As Integer = s.IndexOf(Abc)
    Do While i >= 0
      ans += 1
      Dim j As Integer = i + Abc.Length()
      If j < s.Length() Then
        i = s.IndexOf(Abc, j)
      Else
        Exit Do
      End If
    Loop
    Console.WriteLine(ans.ToString())
  End Sub
End Class

Public Class Cin
  Public Shared Function Str() As String
    Return Console.ReadLine().Trim()
  End Function
  Public Shared Function Int() As Integer
    Return Integer.Parse(Str())
  End Function
  Public Shared Function Lng() As Long
    Return Long.Parse(Str())
  End Function
  Public Shared Function Dbl() As Double
    Return Double.Parse(Str())
  End Function
  Public Shared Function StrArr(Optional separator As String = " ") As String()
    Return Str().Split(separator)
  End Function
  Public Shared Function IntArr(Optional separator As String = " ") As Integer()
    Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
  End Function
  Public Shared Function LngArr(Optional separator As String = " ") As Long()
    Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
  End Function
  Public Shared Function DblArr(Optional separator As String = " ") As Double()
    Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
  End Function
End Class

Measured memory_bytes: 11360
#include <bits/stdc++.h>
#define el '\n'
using namespace std;

int dp[100005][3];

inline int max3(int a, int b, int c){
  return max(a, max(b,c));
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  int a[n], b[n], c[n];
  for(int i = 0; i< n; i++){
    cin >> a[i] >> b[i] >> c[i];
  }

  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];

  for(int i = 1; i < n; i++){
    dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = c[i] + max(dp[i-1][1], dp[i-1][0]);
  }
  cout << max3(dp[n-1][0], dp[n-1][1], dp[n-1][2]) << el;

  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int main()
{
    string s,t;
    cin>>s>>t;
    string ans = "";
    for (int i=0;i<=s.length();i++)
    {
        for (int j=0;j<=t.length();j++)
        {
            if (i==0 or j==0)
            dp[i][j]=0;
            else if (s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
            
        }
    }

    int i=s.size(),j=t.size();
    while (i>0 and j>0)
    {
        if (s[i-1]==t[j-1])
        {
        ans = s[i-1]+ans;
        i--;j--;
        }
        else if (dp[i-1][j]>dp[i][j-1])
        i--;
        else
        {
            j--;
        }
        
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 38764
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    string s;
    cin >> s;

    string ans;

    REP(i, s.size()) {
        if (s[i] == 'B' && ans.size() > 0)
            ans.pop_back();
        else if (s[i] != 'B')
            ans.push_back(s[i]);
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
import fractions
a,b,c,d = map(int,input().split())
lcm = c*d//fractions.gcd(c,d)
cnta = (a-1)//c + (a-1)//d - (a-1)//lcm
cntb = b//c + b//d - b//lcm
print(b-a+1 - (cntb - cnta))

Measured memory_bytes: 5048
n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
flg = True
cnt = 0

if sum(a) < x:
  cnt = n - 1
  flg = False
  
while flg:
  for i in range(n):
    if a[i] <= x:
      cnt += 1
      x -= a[i]
    else:
      flg = False
print(cnt)

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

int main() {
	char s[101];
	scanf("%s", s);
	int i, count = 0, len = strlen(s) - 1;
	printf("%c", s[0]);
	for (i = 1; i < len; i++) {
		count++;
	}
	printf("%d%c\n", count, s[len]);
	return 0; 
}

Measured memory_bytes: 128
"""
    Author: _YL_
"""
# b:blue, r:red
n, b, r = map(int, input().split())

if b == 0:
    print("0")
elif r == 0:
    print(n)
else:
    remainder = n % (b+r)
    if remainder > b:
        remainder = b

    print(n//(b+r)*b+remainder)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    if(n<10){
        cout<<"Yes"<<endl;
        return 0;
    }
    else{
    for(int i=2;i<10;i++){
        if(n%i==0 && (n/i)<10) {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
}
  cout<<"No"<<endl;
    return 0;
}


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

using namespace std;

void solve() {
    long long k, num = 0, ans = 0;
    cin >> k;

    for (int i = 0; i < 1000000; ++i) {
        num = ( (num*10) % k + 7 % k ) % k;

        ++ans;
        if (num == 0)
            break;
    }

    if (num == 0)
        cout << ans << endl;
    else
        cout << -1 << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3508
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 100000;


void solve() {
    string S;
    ll Q;
    cin >> S >> Q;
    string tmpS = "0";
    ll revCnt = 0;
    string first ;
    string last;

    bool isRev = false;
    bool isFirst = false;
    for (ll i = 0; i < Q; i++) {
        ll Q1, Q2;
        string Q3;

        cin >> Q1;
        if (Q1 == 1) {
            //reverse(tmpS.begin(), tmpS.end());
            revCnt++;
            isRev = !isRev;
        }
        else {
            cin >> Q2 >> Q3;
            if (Q2 == 1) {
                if (isRev) {
                    isFirst = false;
                }
                else {
                    isFirst = true;
                }
            }
            else {
                if (isRev) {
                    isFirst = true;
                }
                else {
                    isFirst = false;
                }
            }

            if (isFirst) {
                string Tmp = Q3 + first;
                first = Tmp;
            }
            else {
                string Tmp = last + Q3;
                last = Tmp;
            }
        }
    }
    auto pos = tmpS.find("0");  // 検索文字列が見つかった位置 （pos == 1）
    auto len = S.length(); // 検索文字列の長さ （len == 2）
//    tmpS.replace(pos, len, S); // s == "a|b"
    if (isRev) {
        reverse(first.begin(), first.end());
        reverse(last.begin(), last.end());
        reverse(S.begin(), S.end());

        cout << last + S + first;
    }
    else {
        cout << first + S + last;
    }
   
}



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







Measured memory_bytes: 1420
L, R = (int(i) for i in input().split())

if (R - L) <= 2019:
    temp1 = float("inf")
    for i in range(R - L):
        for j in range(R - L):
            temp2 = ((R-i) * (R - 1 -j)) % 2019
            if temp2 < temp1:
                temp1 = temp2
    print(temp1)
else:
    temp1 = float("inf")
    for i in range(2019):
        if (R-i-1) < L:
            break
        for j in range(2019):
            temp2 = ((R - i) * (R - 1 - j)) % 2019
            if temp2 < temp1:
                temp1 = temp2
    print(temp1)

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

const int INF = 2000000000;
const int MAX_V = 100001;

struct edge {
  int to, cost;
};
typedef pair<int, int> P; // firstは最短距離, secondは頂点の番号

int V, E;
vector<edge> G[MAX_V];
int d[MAX_V];

// 蟻本参照
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }

    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r;
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int si, ti, di;
    cin >> si >> ti >> di;
    G[si].push_back(edge{ti, di});
  }

  dijkstra(r);
  for (int i = 0; i < V; i++) {
    if (d[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 12996
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int k;cin >>k;
    int odd=(k-1)/2+1;
    int even=k/2;
    int ans=odd*even;
    cout <<ans <<endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fe(i,a,b) for(ll i=a;i<=b;i++)

int n=0,m=0,ans=0;
vector< vector<int>> adj;
vector<int> dp;

int dfs(int u)
{
  if(dp[u]!=-1)
    return dp[u];
  
  if(adj[u].size()==0)
    return dp[u] = 0;

  int k = 0;

  for(auto v : adj[u])
  { 
   k = max(k,dfs(v));
  }
  
 return dp[u] = k + 1;
}

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

  cin>>n>>m;

  adj.resize(n+1);
  dp.resize(n+1,-1);
  int x=0,y=0,k=0;

  fe(i,1,m)
   { 
    cin>>x>>y;
    adj[x].push_back(y);
   }
  
  fe(i,1,n)
   {
    ans = max(ans,dfs(i));
   }

  // f(i,1,n+1)
  //  { cout<<i<<" : ";
  //    f(j,0,adj[i].size())
  //      cout<<adj[i][j]<<"  ";
  //    cout<<endl;
  //  }
  cout<<ans<<endl;
return 0;
}


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

const int maxn = 2e5 + 3;
int cd[512];
int n;
struct pt {
    int x, y;
    char d;
    void read() {
        static char buf[8];
        scanf("%d%d%s", &x, &y, buf);
        d = cd[*buf];
    }
} p[maxn];

std::map<int, std::vector<int>> ul, ur, ud;
int ans = 0x7f7f7f7f;

void solve() {
    ul.clear();
    ur.clear();
    ud.clear();
    for(int i = 0; i < n; ++i) {
        if(p[i].d == 1) {
            ul[p[i].x - p[i].y].push_back(i);
        } else if(p[i].d == 2) {
            ud[p[i].x].push_back(i);
        } else if(p[i].d == 3) {
            ur[p[i].x + p[i].y].push_back(i);
        }
    }
    for(auto &&[_, vec] : ul) {
        std::sort(vec.begin(), vec.end(), [](int i, int j) {
            return p[i].y < p[j].y;
        });
    }
    for(auto &&[_, vec] : ur) {
        std::sort(vec.begin(), vec.end(), [](int i, int j) {
            return p[i].y < p[j].y;
        });
    }
    for(auto &&[_, vec] : ud) {
        std::sort(vec.begin(), vec.end(), [](int i, int j) {
            return p[i].y < p[j].y;
        });
    }
    for(int i = 0; i < n; ++i) {
        if(p[i].d != 0)
            continue;
        {
            auto &vec = ud[p[i].x];
            auto it = std::lower_bound(vec.begin(), vec.end(), i, [](int u, int v) {
                return p[u].y < p[v].y;
            });
            if(it != vec.end()) {
                int w = p[*it].y - p[i].y;
                ans = std::min(ans, w / 2 * 10 + w % 2 * 5);
            }
        }
        {
            auto &vec = ul[p[i].x - p[i].y];
            auto it = std::lower_bound(vec.begin(), vec.end(), i, [](int u, int v) {
                return p[u].y < p[v].y;
            });
            if(it != vec.end()) {
                int w = p[*it].y - p[i].y;
                ans = std::min(ans, w * 10);
            }
        }
        {
            auto &vec = ur[p[i].x + p[i].y];
            auto it = std::lower_bound(vec.begin(), vec.end(), i, [](int u, int v) {
                return p[u].y < p[v].y;
            });
            if(it != vec.end()) {
                int w = p[*it].y - p[i].y;
                ans = std::min(ans, w * 10);
            }
        }
    }
}

int main() {
    cd['U'] = 0; cd['L'] = 1; cd['D'] = 2; cd['R'] = 3;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        p[i].read();
    for(int i = 0; i < 4; ++i) {
        solve();
        for(int j = 0; j < n; ++j) {
            p[j].d = (p[j].d + 1) % 4;
            std::tie(p[j].x, p[j].y) = std::make_tuple(-p[j].y, p[j].x);
        }
    }
    if(ans >= 0x7f7f7f7f) {
        puts("SAFE");
        return 0;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 58548
#include<bits/stdc++.h>
using namespace std;
int n,a[55],b[55],c[55],ans;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<n;i++)cin>>c[i];
	for(int i=1;i<=n;i++){
		ans+=b[a[i]];
		if(a[i]==a[i-1]+1)ans+=c[a[i-1]];
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n,i,m=1,p=1;
    scanf("%d\n",&n);
    char a[n];
    for(i=0;i<n;i++){
        a[i]=getchar();
    }
    while(m<n){
        if((int)(a[m-1])!=(int)(a[m])){
            p++;
        };
        m++;
    };
    printf("%d",p);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

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

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

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    rep1(i, n){
        ll c = 0;
        for (ll x = 1; x * x <= i; ++x){
            ll k = i - x * x;
            for (ll y = 1; y * y <= k; ++y){
                ll f = k - y * y;
                ll l = 1,r = 100;
                while (l <= r) {
                    ll z = (l + r) / 2;
                    ll t = z*z + x*z + z*y + y*x;
                    if(f - t > 0)l = z + 1;
                    else if(f - t < 0)r = z - 1;
                    else{
                        ++c;
                        break;
                    }
                }
            }
        }
        pf(c);
    }
    return 0;
}



Measured memory_bytes: 3564
#include<stdio.h>

int main(void)
{
	char num[1005];
	int sum = 0;
	while (1)
	{
		scanf("%s", num);
		sum = 0;
		if (num[0] == '0') break;
		int i, sz = strlen(num);
		for (i = 0; i < sz; i++)

		{
			sum += num[i] - '0';
		}

		printf("%d\n", sum);
	}
}


Measured memory_bytes: 2112