akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    string card;
    int mem,field,deck;
    for(;;){
        int poi[11]={0};
        deck=100,field=0;
        cin>>mem;
        if(mem==0)break;
        cin>>card;
        for(int i=0;i<100;i++){
            if(card[i]=='\0')break;
            if(card[i]=='M'){
                poi[i%mem]++;
                deck--;
            }
            if(card[i]=='S'){
                poi[i%mem]++;
                field+=poi[i%mem];
                poi[i%mem]=0;
                deck--;
            }
            if(card[i]=='L'){
                poi[i%mem]+=field+1;
                field=0;
                deck--;
            }
        }
        for(int i=0;i<mem;i++){
            sort(poi,poi+mem);
            cout<<poi[i]<<" ";
        }
        cout<<field<<endl;
    }
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    float v=sum/(4.0*m);
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>=v)
        {
            count++;
        }
    }
    if(count>=m)
    {
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int W = input.nextInt();
        int H = input.nextInt();
        int x = input.nextInt();
        int y = input.nextInt();
        int r = input.nextInt();

        if (0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H){
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 17356
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;

int main() {
    int s, w;
    cin >> s >> w;
    if (s <= w)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
}

Measured memory_bytes: 3596
#include <cstdio>
using namespace std;

int Up(int a){
	return (a / 1000) * 1000 + 1000;
}

int main(){
	int n;
	int debt = 100000;
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		debt += debt / 20;
		if(debt % 1000 > 0) debt = Up(debt);
	}
	
	printf("%d\n", debt);
	
	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll a;

void input() { 
  cin >> a;
}

void solve() {
  cout << a + a*a + a*a*a << endl;
}

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


Measured memory_bytes: 3592
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using indx = size_t;

#define endl '\n'
#define get(type, args...) type args; read(args)
#define all(v) v.begin(), v.end()
#define debug(args...) { string _s = #args; \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s); istream_iterator<string> _it(_ss); \
    err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
template <typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
template <typename T>
void read(vector<T>& v) {
    for (auto& x : v) cin >> x;
}
template <typename... T>
void write(T&&... args) {
    ((cout << args << " "), ...);
    cout << '\n';
}
template <typename T>
void write(vector<T>& v) {
    for (auto x : v) cout << x << " ";
    cout << '\n';
}

int main() {
    get(int, k, a, b);
    bool ans = false;
    for (int i = a; i <=b; i++) {
        if (i%k == 0)
            ans = true;
    }
    if (ans) write("OK");
    else write("NG");
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int a, b;
  cin >> a >> b;
  int ans = (a+b-3)/(a-1);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
table = [ list(map(int,input().split())) for i in range(N)]
dp = [[0 for i in range(3)] for j in range(N)]

for i in range(3):
    dp[0][i] = table[0][i]

for i in range(1,N):
    dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + table[i][0]
    dp[i][1] = max(dp[i-1][2],dp[i-1][0]) + table[i][1]
    dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + table[i][2]

print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))


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

using namespace std;

int main(void)
{
	int n;
	string s;
	cin >> n;
	cin >> s;

	char* character = new char[s.size() + 1];

	for (int i = 0; i < s.size(); i++)
	{
		character[i] = s[i];

		for (int j = 0; j < n; j++)
		{
			character[i] += 0x01;
		}

		if (character[i] > 'Z')
			character[i] -= 0x1a;
	}

	character[s.size()] = '\0';

	cout << character << endl;

	delete[] character;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
  ll a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    ans = (n-1)/(k-1);
    if((n-1)%(k-1)!=0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3756
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }
  
};

ll ind(ll n, ll i){
  return n*3+i;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M, S, T;
  cin >> N >> M;
  dijkstra dijk(3*N);
  rep(i, M){
    ll u, v;
    cin >> u >> v;
    u--;v--;
    dijk.add_edge(ind(u, 0), ind(v, 1), 1);
    dijk.add_edge(ind(u, 1), ind(v, 2), 1);
    dijk.add_edge(ind(u, 2), ind(v, 0), 1);
  }

  cin >> S >> T;
  S--;T--;
  dijk.run(ind(S, 0));
  ll ans = dijk.d[ind(T, 0)];
  if(ans==1e18){
    cout << -1;
  }else{
    cout << ans/3;
  }
  return 0;
}


Measured memory_bytes: 18944
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format, std.numeric;

void main(string[] args)
{
    long a, b;
    readf("%d %d", &a, &b);
    writeln(a * b / gcd(a, b));

}

Measured memory_bytes: 256
h,w,a,b = map(int, input().split())
def find_power(n,mod=10**9+7):
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist
def find_inv_power(n):
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist
mod = 10**9+7
p_lis=find_power(4*10**5+100,mod)
ip_lis=find_inv_power(4*10**5+100)

def comb(n,r,mod=10**9+7):
    if n<r:
        return 0
    elif n>=r:
        return (p_lis[n]*ip_lis[r]*ip_lis[n-r])%(mod)
ans=0
for i in range(h-a):
    pre=comb(i+b-1,i)
    post=comb(h+w-b-2-i,h-i-1)
    ans+=pre*post
    ans%=10**9+7
print(ans)

Measured memory_bytes: 85428
import itertools
N, M = map(int, input().split())
l = []
seq = []
for i in range(N):
  seq.append(i)
  i+=1
for _ in range(M):
    a,b = list(map(int, input().split()))
    l.append([a-1,b-1])
cnt = 0
for i in list(itertools.permutations(seq)):
  if i[0]!=0:
    continue
  for j in range(N-1):
    if sorted([i[j],i[j+1]]) in l:
      if j == N-2:
        cnt += 1
    else:
      break
print(cnt)

Measured memory_bytes: 8052
n = int(input())
D = []
for _ in range(n):
    a,b = map(int,input().split())
    D.append((a,b))
cnt = 0
for a,b in D:
    if a==b:cnt += 1
    else:
        cnt =0
    if cnt ==3:
        print('Yes');exit()
print('No')

Measured memory_bytes: 62300
H, W = map(int, input().split())
INF = H+W+W

grid = [[v for v in input()] for _ in range(H)]

dp = [[INF]*W for _ in range(H)]

DX = [0, 1]
DY = [1, 0]

dp[0][0] = 0

for x in range(H):
    for y in range(W):
        for dx, dy in zip(DX, DY):
            nx = x+dx
            ny = y+dy
            if 0 <= nx < H and 0 <= ny < W:
                if grid[x][y] == "." and grid[x][y] != grid[nx][ny]:
                    dp[nx][ny] = min(dp[nx][ny], dp[x][y]+1)
                else:
                    dp[nx][ny] = min(dp[nx][ny], dp[x][y])
if grid[0][0] == "#":
    dp[-1][-1] += 1
print(dp[-1][-1])


Measured memory_bytes: 3188
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		sc.close();
		sc = null;
		int sum = 0;
		int ab =0;
		for(i=1;i<=n;i++) {
			if(i<10) {
				ab=i;
			} else if(i<100) {
				ab= i/10 + i % 10;
			} else if(i<1000) {
				ab= i / 100 + (i % 100)/10 + i % 10;
			} else  if(i<10000) {
				ab= i / 1000 + (i % 1000)/100 + (i % 100)/10 + i % 10;
			} else {
				ab=1;
			}
			if(a <= ab && ab <= b) {
				sum += i;
			}
		}
		System.out.println(sum);
	}
}

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

const int N = 2e5+7, K = 18;

struct Tree{
    vector<int> adj[N];

    int anc[N][K];
    int level[N];
    bool mark[N];
    int dis[N];

    void addEdge(int u, int v) {
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    void setup(int u, int par) {
        level[u] = level[par]+1;
        anc[u][0] = par;
        for (int k=1; k<K; k++)     anc[u][k] = anc[anc[u][k-1]][k-1];

        for (int v: adj[u]) {
            if (v == par)   continue;
            setup(v, u);
        }
    }

    int lca(int u, int v) {
        if (level[u] > level[v])    swap(u, v);
        for (int k=K-1; k>=0; k--)
            if (level[u] + (1<<k) <= level[v])  v = anc[v][k];

        if (u == v) return u;
        for (int k=K-1; k>=0; k--)
            if (anc[u][k] != anc[v][k])
                u = anc[u][k], v = anc[v][k];
        return anc[u][0];
    }

    int getanc(int u, int d) {
        for (int k=0; k<K; k++)
            if (d & (1<<k))
                u = anc[u][k];
        return u;
    }

    int dist(int u, int v) {
        int g = lca(u, v);
        return level[u] + level[v] - 2*level[g];
    }

    int solve(int u, int par, int dep) {
        if (dis[u] <= dep)  return 0;
        if (mark[u])        return N;
        int ans = dis[u];
        for (int v: adj[u]) {
            if (v == par)   continue;
            ans = max(solve(v, u, dep+1), ans);
        }
        return ans;
    }
};


///Given u, v, d per query find dth node (0 indexed) on path from u to v.
///https://codeforces.com/gym/102694/problem/C

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

    int n;
    cin>>n;

    int x, y;
    cin>>x>>y;

    Tree red, blue;

    for (int i=1; i<n; i++) {
        int u, v;
        cin>>u>>v;
        red.addEdge(u, v);
    }

    for (int i=1; i<n; i++) {
        int u, v;
        cin>>u>>v;
        blue.addEdge(u, v);
    }

    red.setup(1, 0);
    blue.setup(1, 0);

    for (int i=1; i<=n; i++) {
        bool found = false;
        for (int v: red.adj[i]) {
            if (blue.dist(i, v) >= 3)   found = true;
        }
        red.mark[i] = found;
        red.dis[i] = blue.dist(y, i);
    }
    int ans = red.solve(x, 0, 0);
    if (ans == N)   ans = -1;
    else            ans *= 2;
    cout<<ans<<endl;
}


Measured memory_bytes: 65452
# ハミルトン閉路はどこから初めても答えは変わらない
V, E = map(int, input().split())
INF = 10**18
dist = [[INF] * V for _ in range(V)]
for _ in range(E):
  s, t, d = map(int, input().split())
  dist[s][t] = d
  
# dp[i][j]:= 状態i(2**V)にするための距離の最小値
# 最後に訪れたのがj
dp = [[INF] * V for _ in range(2**V)]

# 始点を0とする
dp[0][0] = 0

for s in range(2**V):# 現在の状態
  for j in range(V):# 次の頂点
    if (s >> j & 1)==0:# jが集合Sに含まれない
      for i in range(V):# 今いる頂点
        if i != j:
          dp[s|1<<j][j] = min(dp[s|1<<j][j],dp[s][i]+dist[i][j])

print(-1) if dp[2**V-1][0] == INF else print(dp[2**V-1][0])


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

using namespace std;
using LL = long long int;

const int MAX_N = 200005;

int N, K;
int A[MAX_N];
int P[MAX_N];

int main()
{
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    P[A[i]]++;
  }

  priority_queue<int, vector<int>, greater<int>> que;
  int ans = 0;
  int cnt = 0;

  for(int i = 0; i < MAX_N; i++) {
    if(P[i] > 0) {
      cnt++;
      que.push(P[i]);
    }
  }

  while(cnt > K) {
    cnt--;
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> wyst(100001, 0);
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        ++wyst[x];
    }
    for (int i = 0; i < 100001; ++i)
    {
        if (wyst[i] != 0)
        {
            if (wyst[i] % 2 == 0)
                wyst[i] = 2;
            else
                wyst[i] = 1;
        }
    }
    int pary = 0;
    int jed = 0;
    for (int i = 0; i < 100001; ++i)
    {
        if (wyst[i] != 0)
        {
            if (wyst[i] == 1)
                ++jed;
            else
                ++pary;
        }
    }
    if (pary % 2 == 0)
        cout << jed + pary;
    else
        cout << jed + pary - 1;
    return 0;
}


Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

M, D = MAP()
 
ans = 0
for i in range(1, M+1):
	for j in range(1, D+1):
		if 2 <= j//10 and 2 <= j%10 and (j//10)*(j%10) == i:
			ans += 1
 
print(ans)



Measured memory_bytes: 5160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;


char a[500][501];
int main(void){
    ll h, w; cin >> h >> w; for(int i = 0;i < h;i++)scanf("%s", &a[i]);
    for(int i = 0;i < h;i++){
        if(i%2==0){
            for(int j = 0;j < w-1;j++)printf("#");
            printf(".\n");
        }else{
            printf("#");
            for(int j = 1;j < w-1;j++){
                if(a[i][j]=='#')printf("#");
                else printf(".");
            }
            printf(".\n");
        }
    }
    printf("\n");
    for(int i = 0;i < h;i++){
        if(i%2==1){
            printf(".");
            for(int j = 1;j < w;j++)printf("#");
            printf("\n");
        }else{
            for(int j = 0;j < w-1;j++){
                if(a[i][j]=='#')printf("#");
                else printf(".");
            }
            printf("#\n");
        }
    }
 	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <unordered_map>

using namespace std;

#define ll long long
#define rep(i, n) for (i = 0; i < n; i++)

int main()
{
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] != t[i])
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int c[10][10];

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

  for(int i=1; i<=N; i++) {
    // 先頭の桁の数は a に等しく、末尾の桁の数は b に等しい
    int a, b;
    string s = to_string(i);
    a = s[0]-'0';
    b = s[s.length()-1]-'0';
    c[a][b] += 1;
  }

  int ans = 0;
  for(int i=1; i<10; i++)for(int j=1; j<10; j++) ans += c[i][j]*c[j][i];
  cout << ans << endl;
  return 0;
}


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

long long n,ans,maxi;
pair<long long,long long> val[100005][2];
pair<long long,long long> v[100005],l,r,tmp;

inline long long f(pair<long long,long long> x){
	return max(0ll,x.second-x.first+1ll);
}

inline long long calc(pair<long long,long long> a,pair<long long,long long> b){
	return max(0ll,min(a.second,b.second)-max(a.first,b.first)+1);
}

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

	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>v[i].first>>v[i].second;
	}
	
	sort(v,v+n);
	
	val[0][0]={0,1000000000ll};
	
	for(int i=1;i<n;i++){
		val[i][0]={max(val[i-1][0].first,v[i-1].first),min(val[i-1][0].second,v[i-1].second)};
	}
	
	val[n-1][1]={0,1000000000ll};
	
	for(int i=n-2;i>=0;i--){
		val[i][1]={max(val[i+1][1].first,v[i+1].first),min(val[i+1][1].second,v[i+1].second)};
	}
	
	ans=0;
	
	for(int i=0;i<n;i++){
		ans=max(ans,(v[i].second-v[i].first+1ll)+calc(val[i][0],val[i][1]));
	}
	
	for(int i=0;i<n-1;i++){
		ans=max(ans,f(val[i+1][0])+f(val[i][1]));
	}
	
	cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 4992
N, A, B = list(map(int, input().split()))

ret = 0
for n in range(1, N+1):
  tmp_n = n
  tmp_cond = 0
  while tmp_n > 0:
    tmp_cond += tmp_n % 10
    tmp_n //= 10
  if A <= tmp_cond <= B:
    ret += n

print(ret)

Measured memory_bytes: 2940
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.


int main() {
long long int  N, W;
cin >> N >> W;
long long int a[N][2];
for (int i = 0; i < N; ++i)
{
	cin >> a[i][0] >> a[i][1];
}

long long int dp[100001];
for (int i = 1; i < 100001; ++i)
{
	dp[i] = INT_MAX;
}
dp[0] = 0;
long long int mx;

for (int i = 0; i < N; ++i)
{

	for (long long int j = 100000; j >=a[i][1]; --j)
	{
		dp[j] = min(dp[j], a[i][0] + dp[j-a[i][1]]);
	}

}
	mx = 0;
for (long long int i = 100000; i >=0; --i)
{
	if(dp[i] <= W) mx = max(mx, i);
}
cout << mx << endl;
return 0;
}

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

using ll = long long;
int a[20];
ll pw[20];

ll get_sum(ll n){
	ll ret = 0;
	while(n){
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

int main(){
//	freopen("res.txt", "w", stdout);
	pw[0] = 1;
	for(int i = 1; i < 20; i ++) pw[i] = pw[i - 1] * 10;
	int k;
	cin >> k;
	ll cur = 1;
	for(int i = 0; i < k; i ++){
		ll tmp = cur;
		for(int j = 0; j < 16; j ++){
			a[j] = tmp % 10;
			tmp /= 10;
		}
		for(int j = 0; j < 16; j ++){
			if(a[j] == 9) continue;
			if((long double)(cur) / get_sum(cur) < (long double)(cur + pw[j] * 9) / get_sum(cur + pw[j] * 9)){
				break;
			}
			else {
				cur += (9 - a[j]) * pw[j];
			}
		}
		cout << cur << '\n';
		cur ++;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<iomanip>
#include<cstdio>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
typedef long long int ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef pair<ll, ll>P;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
#define MAX_NUM 50
long long comb[MAX_NUM + 1][MAX_NUM + 1];

ll par[100000], depth[100000];
static void calc_comb()
{
	for (uint32_t i = 0; i <= MAX_NUM; i++) {
		for (uint32_t j = 0; j <= i; j++) {
			if ((j == 0) || (i == j)) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}
#define yo 100001
//------------------変数-----------------------//
ll n, W;
P p[200];
	ll kugire[4] = {}, M = 0, m = 0;
//-------------------関数----------------------//
ll keisan(ll i,ll kugiri) {
	if(kugire[kugiri]-i-1<0){return  p[kugire[kugiri] - 1].second -0;
	}
	ll kachi = p[kugire[kugiri] - 1].second - p[kugire[kugiri] - i - 1].second;
	return kachi;
}
int main() {
	cin >> n >> W;
	REP(i, n) { cin >> p[i].first >> p[i].second; }
	sort(p, p + n);
	ll mini = p[0].first;
	REP(i, n - 1) {
		if (p[i].first != p[i + 1].first) {
			ll izryt = p[i + 1].first - p[i].first;
			if (izryt == 1) {
				kugire[M ++] = i+1;
			}
			else if (izryt == 2) {
				kugire[ M++] = i + 1;
				kugire[ M++] = i + 1;
			}
			else if (izryt == 3) {
				kugire[M++] = i + 1; kugire[M++] = i + 1; kugire[M++] = i + 1;
			}
			else {
				kugire[M++] = i + 1; kugire[M++] = i + 1; kugire[M++] = i + 1; kugire[M++] = i + 1;
			}
		}
	}
	REP(i, 4) {
		if (kugire[i] == 0) { kugire[i] = n; }
	}
	
	REP(i, n) {
		p[i + 1].second += p[i].second;
	}
//	REP(i, 4) { cout << p[i].second << endl; }
	ll maxa = 0;
	REP(i, kugire[0] + 1) {
		REP(j, kugire[1] + 1-kugire[0]) {
			REP(k, kugire[2] + 1 - kugire[1]) {
				REP(l, n + 1 - kugire[2]) {
					ll ww = i*mini + j*(mini + 1) + k*(mini + 2) + l*(mini + 3);
					if (ww <= W) {
						ll kachi = keisan(i, 0) + keisan(j, 1) + keisan(k, 2) + keisan(l, 3);
					//	cout << i << " " << j << " " << k << " " << l << endl;
				//		cout << kachi << endl;
						maxa = max(maxa, kachi);
					}
				}
			}
		}
	}
	cout << maxa << endl;
	return 0;
}





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

static const int MAX = 200000;

int main() {
	int R[MAX], n;

	std::cin >> n;
	for (int i = 0; i < n; i++){
		std::cin >> R[i];
	}

	int maxv = -2000000000;
	int minv = R[0];

	for(int i = 1; i < n; i++){
		maxv = std::max(maxv, R[i]- minv);
		minv = std::min(minv, R[i]);
	}

	std::cout << maxv << std::endl;

	return 0;
}


Measured memory_bytes: 3912
H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
    exit()

if H % 2 == 0:
    print (H * W // 2)
else:
    tmp = ((H + 1) // 2) * ((W + 1) // 2)
    tmp += ((H) // 2) * (W // 2)
    print (tmp)

Measured memory_bytes: 3060
n = int(input())
s = [list(input()) for _ in range(2)]
MOD = 10 ** 9 + 7

if n == 1:
    print(3)
    exit()

ans = 0
p = 0
b = 0
if s[0][0] == s[1][0]:
    ans = 3
    p = 1
    b = 1
else:
    ans = 6
    p = 2
    b = 2

while p < n:
    if s[0][p] == s[1][p]:
        if b == 1:
            ans *= 2
            ans %= MOD
        else:
            b = 1
        p += 1
    else:
        if b == 1:
            ans *= 2
            ans %= MOD
            b = 2
        else:
            ans *= 3
            ans %= MOD
        p += 2

print(ans)


Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int canLoad(int P, int w[], int n, int k) {
	int k2 = 0;
	int temp;
	int i=0;
	while (++k2 <= k) {
		temp = P;
		while (temp > 0) {
			if (++i <= n) {
				temp -= w[i];
			}
			else {
				return 1;
			}
		}
		if(temp < 0){
			--i;
		}
		else if (i == n) {
			return 1;
		}
	}
	return 0;
}

int main() {
	int n, k;
	int w[100001];
	int c;
	int *a;
	int lowerBoundP, upperBoundP;
	int midP;

	scanf("%d%d", &n, &k);
	c = n;
	a = w;
	int maxW = 0;
	while (c--) {
		scanf("%d", ++a);
		if (*a > maxW) {
			maxW = *a;
		}
	}

	if (n <= k) {
		printf("%d\n", maxW);
		return 0;
	}

	lowerBoundP = maxW - 1;
	upperBoundP = maxW * n;
	
	while (lowerBoundP + 1 != upperBoundP) {
		midP = (lowerBoundP + upperBoundP) / 2;
		if (canLoad(midP, w, n, k) == 1) {
			upperBoundP = midP;
		}
		else {
			lowerBoundP = midP;
		}
	}

	printf("%d\n", upperBoundP);

	return 0;
}

Measured memory_bytes: 988
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    bool res;
    if (A==B and B==C)
        res = false;
    else
        res = A==B or B==C or C==A;
    if (res)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

int main() {
    int N,A,B;
    cin >> N >> A >> B;
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    for(int i = 0;i < N;i++) {
        int C;
        cin >> C;
        if(C <= A) {
            cnt1++;
        }
        else if(C <= B) {
            cnt2++;
        }
        else {
            cnt3++;
        }
    }
    cout << min(cnt1,min(cnt2,cnt3)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define int ll

using namespace std;

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

const int M = 1e9 + 7;

int a[2003], b[2003], dp[2003][2003];

int32_t main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=0;i<m;i++)
		cin >> b[i];
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			if(a[i] == b[j]) {
				dp[i][j]++;
				if(i) dp[i][j] += dp[i-1][j];
				if(j) dp[i][j] += dp[i][j-1];
				dp[i][j] %= M;
			} else {
				if(i) dp[i][j] += dp[i-1][j];
				if(j) dp[i][j] += dp[i][j-1];
				if(i && j) dp[i][j] -= dp[i-1][j-1];
				dp[i][j] %= M;
				if(dp[i][j] < 0) dp[i][j] += M;
			}
		}
	}
	cout << (dp[n-1][m-1] + 1) % M << endl;
	
}



Measured memory_bytes: 31616
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct question
{
	long long time; long long amount; ll name;
};

bool ord(question x, question y) {
	return x.time < y.time;
}

ll const MAX = 1e5 + 5;
ll t[MAX];
question q[MAX];
ll ans[MAX];
ll x;
void f(ll tim, ll cur_q, ll a, ll b, ll c, ll type) {
	//cout << "?"  << q[cur_q].time << endl;
	if (type == 1) {
		ll am = q[cur_q].amount;
		ll t_tilde = q[cur_q].time - tim;
		ll iii = q[cur_q].name;
		if (am <= b) {
			ans[iii] = max(ll(0), a - t_tilde);
		}
		else if(am >= b + c){
			ans[iii] = max(ll(0), a + c - t_tilde);
		}
		else {
			ans[iii] = max(ll(0), a + am - b - t_tilde);
		}
	}
	else {
		ll am = q[cur_q].amount;
		ll t_tilde = q[cur_q].time - tim;
		ll iii = q[cur_q].name;
		if (am <= b) {
			ans[iii] = min(x, a + t_tilde);
		}
		else if (am >= b + c) {
			ans[iii] = min(x, a + c + t_tilde);
		}
		else {
			ans[iii] = min(x, a + am - b + t_tilde);
		}
	}
}

int main() {
	ll k;
	cin >> x >> k;
	REP(i, 1, k) {
		cin >> t[i];
	}
	t[0] = 0;
	t[k + 1] = 1e10;
	ll qqq;
	cin >> qqq;
	REP(i, 1, qqq) {
		ll a, b;
		cin >> a >> b;
		q[i] = { a,b,i };
	}
	SORT_O(q, qqq, ord);
	
	ll a, b, c;
	a = 0; b = 0; c = x;
	ll cur = 1;
	REP(i, 1, k + 1) {
		//cout << t[i] << "%" << endl;
		if (i % 2 == 1) {
			while (t[i - 1] <= q[cur].time && q[cur].time < t[i] && cur <= qqq) {
				f(t[i - 1], cur, a, b, c, 1);
				cur++;
			}
			ll t_tilde = t[i] - t[i - 1];
			if (a >= t_tilde) {
				a -= t_tilde;
			}
			else {
				if (a + c <= t_tilde) {
					a = 0;
					b = x;
					c = 0;
				}
				else {
					b += t_tilde - a;
					c -= t_tilde - a;
					a = 0;
				}
			}
		}
		else {
			while (t[i - 1] <= q[cur].time && q[cur].time < t[i] && cur <= qqq) {
				f(t[i - 1], cur, a, b, c, 0);
				cur++;
			}
			ll t_tilde = t[i] - t[i - 1];
			ll ac = a + c;
			if (x - ac >= t_tilde) {
				a += t_tilde;
			}
			else {
				if (x - a <= t_tilde) {
					a = x;
					b = x;
					c = 0;
				}
				else {
					a += t_tilde;
					ll bc = b + c;
					c = x - a;
				}
			}

			
		}
		//cout << i << " ! " << a << " " << b << " " << c << endl;
	}
	REP(i, 1, qqq) {
		cout << ans[i] << endl;
	}
}

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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, l, t;
	cin >> n >> l >> t;
	vector<int> x(n), w(n), pos(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> w[i];
		//蟻同士が互いにすり抜けると仮定するとT秒後の蟻の位置がわかる
		if (w[i] == 1) {
			pos[i] = (x[i] + t % l) % l;
		} else {
			pos[i] = (x[i] - t % l + l) % l;
		}
	}

	//実際には蟻同士は衝突するので、蟻0-(n-1)(0-indexed)は時計回りに存在する
	//そこで、すり抜けた場合の蟻0の位置(tar=sort前のpos[0])==実際のT秒後の蟻iの位置とした時のiを求める
	//これにより、tar==sort後のpos[j]となるjと蟻iが対応していることがわかり、他の蟻の位置もわかる

	//以下、蟻iの候補を求める(iの初期値は0)
	//蟻0が時計回りに移動する場合、衝突の度にiが1増える
	//一方、蟻0が反時計回りに移動する場合、衝突の度にiが1減る
	//蟻0と進行方向が逆なものに対してそれぞれ衝突回数を求める
	int sum = 0; //衝突回数の合計
	for (int i = 1; i < n; i++) {
		if (w[i] == w[0]) continue;
		int tmp; //2匹の蟻の開始時点の距離
		if (w[0] == 1) tmp = (x[i] + l - x[0]) % l;
		else tmp = (x[0] + l - x[i]) % l;
		if (2 * t < tmp) continue; //衝突しない場合
		sum += (2 * t - tmp) / l + 1; //最初1回衝突すると次に会うのは2匹の進行距離の合計がLになる時
	}

	int tar = pos[0];
	int idx; //蟻i
	if (w[0] == 1) {
		idx = sum % n;
	} else {
		idx = (n - sum % n) % n;
	}

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

	int sidx; //tar==sort後のpos[j]となるj
	for (int i = 0; i < n; i++) {
		if (pos[i] == tar) {
			sidx = i;
			//T秒後の位置が同じになる場合がある
			//しかし、同じ位置になるのは、最初の位置がすべて異なり、同じ速度で動いているため2匹しかありえない
			//先程の衝突回数の数え方だと、T秒後に位置が同じになる場合は衝突したとみなす
			//よって、進行方向においてより遠い方に蟻iはいると考えれば良い
			if (i + 1 < n && pos[i + 1] == tar && w[0] == 1) sidx = i + 1;
			break;
		}
	}

	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		ans[(idx + i) % n] = pos[(sidx + i) % n];
	}

	for (int x : ans) cout << x << endl;

	return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>

int main(){

	int a,b;
	int x,y;


	while(scanf("%d%d",&a,&b) != EOF){
	fflush(stdin);
	x=a;
	y=b;
	if(a<b){
		int temp=a;
		a=b;
		b=temp;
	}
	if(a%b!=0)
	while(1){
		int temp=a%b;
		a=b;
		b=temp;
		if(a%b==0)break;
	}

	y=x/b*y;


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

Measured memory_bytes: 0
while 1:
    cheese=list(map(int,input().split()))
    if cheese[0]==0:break
    n=int(input())
    cheese=sorted(cheese)
    for i in range(n):
        radius = int(input())
        if radius*2>(cheese[0]**2+cheese[1]**2)**0.5:print("OK")
        else:print("NA")


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

void readInt(int *x) {
	scanf("%d", x);
	return;
}
void readInts(int n, int arr[]) {
	int i;
	for (i=0;i<n;i++) {
		readInt(&arr[i]);
	}
}
void readChar(char *x) {
	scanf("%c", x);
	return;
}
void readChars(char x[]) {
	scanf("%s", x);
	return;
}
void readString(char *x) {
	scanf("%s",x);
	return;
}
void printInts(int n, int *arr) {
	int i;
	for (i=0;i<n;i++) {
		printf("%d ", arr[i]);
	}
	printf("\n");
	return;
}
void swap(int *x, int *y) {
	int tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
	return;
}
void quicksort(int x[], int left, int right) {
	int i,j;
	int pivot;

	i = left;
	j = right;

	pivot = x[(left+right)/2];
	while (1) {
		while (x[i] < pivot) i++;
		while (pivot < x[j]) j--;
		if (i>=j) break;
		swap(&x[i],&x[j]);
		i++;
		j--;
	}
	if (left < i-1) quicksort(x, left, i-1);
	if (j+1 < right) quicksort(x, j+1, right);
}

int main(int argc, char const *argv[])
{
	int n,a,b;
	readInt(&n);
	readInt(&a);
	readInt(&b);
	char s[100001];
	char *p = s;
	readString(s);
	char item;
	int count = 0;
	int rank=1;

	while (*p!='\0') {
		//printf("%c\n", *p);
		item = *p;
		if (item=='c') {
			printf("No\n");
		} else if (item=='a') {
			if (count<a+b) {
				printf("Yes\n");
				count++;
			}else{
				printf("No\n");
			}
		} else {
			if (count<a+b && rank<=b) {
				rank++;
				count++;
				printf("Yes\n");
			}else{
				printf("No\n");
			}
		}
		p++;
	}

	return 0;
}

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

using namespace std;

#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)

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

  size_t n, m;
  cin >> n >> m;

  map <int, int> cards;
  rep (i, n)
  {
    int a;
    cin >> a;
    ++ cards [a];
  }

  rep (j, m)
  {
    int b, c;
    cin >> b >> c;
    cards [c] += b;
  }

  int64_t ans = 0;
  int ans_n = n;
  for (auto ite = cards.rbegin (); ite != cards.rend (); ++ ite)
  {
    int i, count;
    tie (i, count) = * ite;
    if (ans_n <= 0)
    {
      break;
    }
    if (count < ans_n)
    {
      ans += static_cast <int64_t> (i) * count;
      ans_n -= count;
    }
    else
    {
      ans += static_cast <int64_t> (i) * ans_n;
      ans_n = 0;
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
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); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;cin>>N;
  int ans=0;
  vector<int> A(N),B(N);
  REP(i,0,N){
    cin>>A[i]>>B[i];
  }
  reverse(ALL(A));reverse(ALL(B));
  REP(i,0,N){
    int a=A[i]+ans,b=B[i];
    if(a%b!=0)ans+=b-a%b;
  }
  print(ans);


}


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

int main(){
	double sum = 0;
	int n;
	cin >> n;
	double a;
	string b;
	for(int i = 0;i<n;i++){
		cin >> a;
		cin >> b;
		if(b=="JPY"){
			sum += a;
		}
		else{
			sum += (a*380000);
		}
	}
	cout << sum;
	return 0;
} 

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <string>

long long gcd(long long n1, long long n2) {
    if (n2 == 0) {
        return n1;
    }
    return gcd(n2, n1 % n2);
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    long long a, b;
    std::cin >> a >> b;
    if (b < a) {
        std::swap(a, b);
    }
    long long GCD = gcd(a, b);
    long long mult = 1;
    while (GCD > 1) {
        mult *= GCD;
        a /= GCD;
        b /= GCD;
        GCD = gcd(a, b);
    }
    std::cout << a * b * mult << '\n';
    return 0;
}
#endif

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<ll>a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  ll cnt=0;
  for(int i=1;i<n;i++)
  {
    if(a[i]<a[i-1])
    { 
      cnt+=a[i-1]-a[i];
      a[i]=a[i-1];
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 4820
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<' '<<x<<' '<<y;
	return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[-1]*N
l[0]=0
i=1
t=0
while 1:
    t=A[t]-1
    if l[t]!=-1:
        s=i-l[t]
        break
    l[t]=i
    i+=1
if K<i:
    print(l.index(K)+1)
else:
    k=K%s
    if (i//s)*s+k in l:
        print(l.index((i//s)*s+k)+1)
    else:
        print(l.index((i//s-1)*s+k)+1)

Measured memory_bytes: 92340
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
using namespace std;
int s[100001],n;
/*bool bin(int v)
{
	int left=0,right=n;
	int mid;
	while(left<right){
		mid=(left+right)/2;
		if(s[mid]==v){
			return true;
		}
		else if(s[mid]<v){
			 left=mid+1;
		}
		else{
			right=mid;
		}
	}
	return false;
}*/
int main(int argc, char *argv[]) {
	int t,q,i,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&s[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{
		scanf("%d",&t);
		if(*lower_bound(s,s+n,t)==t) sum++;
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 3544
import java.util.*;

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

    while(true) {
      int a0 = sc.nextInt();
      int l = sc.nextInt();
      if (a0 == 0 && l == 0) return;
      int count = 0;
      int a[] = new int[21];
      a[0] = a0;

      loop: while (true) {
        int a_tmp[] = new int[l];
        int tmp = a[count];
        for (int i = 0; i < l; i++) {
          a_tmp[i] = tmp % 10;
          tmp /= 10;
        }
        Arrays.sort(a_tmp);

        int min = 0;
        for (int i = 0; i < l; i++) {
          min = min * 10 + a_tmp[i];
        }

        int max = 0;
        for (int i = 0; i < l; i++) {
          max = max * 10 + a_tmp[l-1-i];
        }

        int an = max - min;
        a[++count] = an;
        //System.out.println(amax + " " + amin + ", D = " + an);
        for (int i = 0; i < count; i++) {
          if (an == a[i]) {
            System.out.println(i + " " + an + " " + (count - i));
            break loop;
          }
        }
      }
    }
  }
}



Measured memory_bytes: 27172
import numpy  as np

N = int(input())
W=list(map(int, input().split()))

W=np.array(W)

meanmin = 1000
for i in range(1,N):

  if meanmin > abs(W[:i].sum()-W[i:].sum()):
        meanmin = abs(W[:i].sum()-W[i:].sum())
       
print(meanmin)


Measured memory_bytes: 13160
package main

import "fmt"
var q int
var n int
var p []int
var rank []int
func main(){
	fmt.Scanf("%d %d",&n,&q)
	p=make([]int,n)
	rank=make([]int,n)
	
	for i := 0; i < n; i++ {
		makeSet(i)
	}
	var op,x,y int
	for i := 0; i < q; i++ {
		fmt.Scanf("%d %d %d",&op,&x,&y)
		if 1 == op {
			fmt.Println(same(x,y))
		}else {
			unite(x,y)
		}
	}
}
func same(x,y int) int {
	if	findSet(x)== findSet(y) {
		return 1
	}
	return 0
}
func makeSet(x int)  {
	p[x]=x
	rank[x]=0
}
func unite(x,y int){
	link(findSet(x),findSet(y))
}
func findSet(x int) int{
	if x != p[x]{
		p[x]= findSet(p[x])
	}
	return p[x]
}
func link(x,y int){
	if rank[x] > rank[y] {
		p[y]=x
	}else {
		p[x]=y
		if rank[x]== rank[y] {
			rank[y]=rank[y]+1
		}
	}
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s          second
#define sz(x)       (int)x.size()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep0(a,n)  for(int i=0;i<n;i++)cin>>a[i]
#define si(x)       cin>>x
#define sii(x,y)    cin>>x>>y
#define siii(x,y,z) cin>>x>>y>>z
#define ahell   998244353
#define hell 1000000007
#define N 1000001
#define fl 1.0000000000
//#define mod 998244353
#define cntbit(a) __builtin_popcountl(a)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
main()
{
  ios
int n,m,i;
int j;
int u,v,q,k;
int test=1;
//si(test);

while(test--)
{
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];

  bool dp[k+1];
  for(i=0;i<=k;i++)
    dp[i]=false;
  dp[0]=0;
sort(a,a+n);
for(i=a[0];i<=k;i++)
{
    bool ans=true;
    for(j=0;j<n;j++)
    {
        if(a[j]<=i)
        {
            ans&=(dp[i-a[j]]);
        }
    }
    dp[i]=!ans;
}
if(dp[k])
cout<<"First";
else cout<<"Second";

}

}


Measured memory_bytes: 3740
import java.util.Scanner;

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

        int c = b - a;

        System.out.println(c * (c - 1) / 2 - a);
    }
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.length() % 2 != 0) {
			System.out.println("No");
			System.exit(0);
		}
		for(int i = 0; i < s.length() - 1; i += 2) {
			if(s.charAt(i) != 'h' || s.charAt(i + 1) != 'i') {
				System.out.println("No");
				System.exit(0);
			}
		}
		System.out.println("Yes");

		sc.close();
	}
}


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

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int ilex = n/100;
	int maks = ilex*5;
	int mina = 0;
	int iley = n%100;
	if(iley >= mina && iley <= maks)
		cout<<1;
	else
		cout<<0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int a, b, ans;

int main() {
    scanf("%d %d", &a, &b);
    ans = a + b;
    if(ans % 2)
        puts("IMPOSSIBLE");
    else
        printf("%d", ans / 2);
    return 0;
}

Measured memory_bytes: 128