akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	L = 'L'
	R = 'R'
)

var SIntListInitialValue int
var SIntListIsInitialized bool
var SIntListRecFunc func(int) int = nil

type SIntList []int

func lib_NewSIntList(length int, initialValue int) SIntList {
	if SIntListIsInitialized {
		panic("SIntList is already used")
	}
	ret := make([]int, length, length)
	for i := 0; i < length; i++ {
		ret[i] = initialValue
	}
	SIntListInitialValue = initialValue
	return ret
}
func lib_PrintIntSlice(values []int, sep string) {
	for i := 0; i < len(values)-1; i++ {
		fmt.Print(values[i], sep)
	}
	fmt.Println(values[len(values)-1])
}
func lib_TernaryOPInt(ok bool, v1, v2 int) int {
	if ok {
		return v1
	}
	return v2
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var S string
	scanner.Scan()
	S = scanner.Text()
	solve(S)
}
func (si SIntList) Rec(f func(index int) int) {
	SIntListRecFunc = f
}
func (si SIntList) Update(index int) int {
	if SIntListRecFunc == nil {
		panic("SIntListRecFunc is nil")
	}
	if si[int(index)] != SIntListInitialValue {
		return si[int(index)]
	}
	ret := SIntListRecFunc(index)
	si[int(index)] = ret
	return ret
}
func solve(S string) {
	s := []rune(S)
	N := len(s)
	lastPos := lib_NewSIntList(N, -1)
	lastPos.Rec(func(i int) int {
		nextPos := lib_TernaryOPInt(s[i] == R, i+1, i-1)
		if s[nextPos] != s[i] {
			return i
		}
		lPos := lastPos.Update(nextPos)
		return lPos + lib_TernaryOPInt(s[lPos] == L, -1, 1)
	})
	count := make([]int, N, N)
	for i := 0; i < len(lastPos); i++ {
		count[lastPos.Update(i)]++
	}
	lib_PrintIntSlice(count, " ")
}


Measured memory_bytes: 34304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int[][] H = new int[N+1][4];
		
		for(int i = 1; i <= N ; i++) {
			String[] S = br.readLine().split(" ");
			H[i][1] = Integer.parseInt(S[0]);
			H[i][2] = Integer.parseInt(S[1]);
			H[i][3] = Integer.parseInt(S[2]);
		}
		int[][] cache = new int[N+1][4];
		
		for(int i = 1; i <= N; i++) {
			Arrays.fill(cache[i], -1);
		}
		System.out.println(minCostJump(1, 0, N, H, cache));
	}
	
	public static int minCostJump(int day, int previousDay, int N, int[][] H, int[][] cache) {
		if(day > N) {
			return 0;
		}
		
		if(cache[day][previousDay] != -1) {
			return cache[day][previousDay];
		}
		
		int result = 0;
		for(int i = 1; i < 4; i++) {
			if(i != previousDay) {
				result = Math.max(result, H[day][i] + minCostJump(day+1, i, N, H, cache));
			}
		}
		
		
		cache[day][previousDay] = result;
		
		return result;
	}
}

Measured memory_bytes: 63860
#include<cstdio>

int main()
{
	int n,f=0;
	int a[100000];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);		
	}
	for(int i=0;i<n;i++){
		if((i+1)%2!=0&&a[i]%2!=0){
			f++;
		}
	}
	printf("%d",f);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define FOR(i,n) for(int i=1;i<=n;i++)
int main()
{
 ios::sync_with_stdio(false);
int A,B,K;
cin>>A>>B>>K;
for(int T=1;T<=K;T++)
{
	if(T%2==1)
	{
		B+=A/2;
		A=A/2;
	}
	else
	{
		A+=B/2;
		B=B/2;
	}
}
cout<<A<<" "<<B<<endl;
 return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int n,a[50],b[50];
bool use[50];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	bool f=0;
	for(int i=0;i<n;i++)f|=a[i]<=2*b[i]&&a[i]!=b[i];
	if(f)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int i=1;i<50;i++)use[i]=1;
	for(int i=49;i>0;i--)
	{
		use[i]=0;
		bool d[51][51]={};
		for(int j=0;j<=50;j++)d[j][j]=1;
		for(int j=1;j<50;j++)
		{
			if(!use[j])continue;
			for(int k=0;k<j;k++)
			{
				for(int l=k+j;l<=50;l+=j)d[l][k]=1;
			}
		}
		for(int k=0;k<=50;k++)for(int j=0;j<=50;j++)for(int l=0;l<=50;l++)d[j][l]|=d[j][k]&&d[k][l];
		f=1;
		for(int j=0;j<n;j++)f&=d[a[j]][b[j]];
		if(!f)use[i]=1;
	}
	long ans=0;
	for(int i=1;i<50;i++)ans|=(long)(use[i])<<i;
	cout<<ans<<endl;
}

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

    int main (){
        string s;
        cin >> s;
        vector<int> a(26);
        rep(i,26){
            a[i]=0;
        }
        
        int n=s.size();

        rep(i,n){
            a[s[i]-'a']++;
        }

    string ans ="Yes";

    rep(i,26){
        if(a[i]%2==1){
            ans="No";
        }
    }
    cout << ans << endl;
    }

Measured memory_bytes: 3604
#include <stdio.h>
#define rep(i,n)for(int i=0;i<(int)(n);i++)
int main(){
    int n,m,x,c[12]={0},a[12][12]={0},y,z[12],b,d=2e9;
    scanf("%d%d%d",&n,&m,&x);
    rep(i,n){
    scanf("%d",&c[i]);
        rep(j,m){
            scanf("%d",&a[i][j]);
        }
    }
    rep(i,2){rep(j,2){rep(k,2){rep(l,2){rep(o,2){rep(p,2){rep(q,2){rep(r,2){rep(s,2){rep(t,2){rep(u,2){rep(v,2){
        y=i*c[0]+j*c[1]+k*c[2]+l*c[3]+o*c[4]+p*c[5]+q*c[6]+r*c[7]+s*c[8]+t*c[9]+u*c[10]+v*c[11];
        for(b=0;b<m;b++){
            z[b]=i*a[0][b]+j*a[1][b]+k*a[2][b]+l*a[3][b]+o*a[4][b]+p*a[5][b]+q*a[6][b]+r*a[7][b]+s*a[8][b]+t*a[9][b]+u*a[10][b]+v*a[11][b];
            if(z[b]<x)break;
        }
        if(b==m&&y<d)d = y;
    }}}}}}}}}}}}
    if(d==(int)2e9)puts("-1");
    else printf("%d",d);
    return 0;
}

Measured memory_bytes: 1728
using System;
class Program
 {
   	static void Main(string[] args)
        {
    　　string sa = Console.ReadLine(); //標準入力
      	string a = sa.Substring(sa.Length-1, 1);
		if(a=="2"||a=="4"||a=="5"||a=="7"||a=="9"){
          Console.WriteLine("{0}", "hon");
        }else if(a=="3"){
          Console.WriteLine("{0}", "bon");
        }else{
          Console.WriteLine("{0}", "pon");
        }
    }
 }

Measured memory_bytes: 25948
#include <iostream>


using namespace std;

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

    char a[n];
    char b[n];

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

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

    for (int i=0;i<n;i++)
    {
        cout<<a[i]<<b[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  cin >> s;
  rep(i,s.size()) {
    if(s[i]=='9') {
      pr("Yes");
      return;
    }
  }
  pr("No");
}

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


Measured memory_bytes: 768
num = int(input())
data = list(map(int, input().split()))

count_fu = 0
count_zero = 0
for i in range(num):
    if data[i] == 0:
        count_zero += 1
    elif data[i] < 0:
        count_fu += 1

sum_data = 0
min_data = abs(data[0])
for i in range(num):
    sum_data += abs(data[i])
    if abs(data[i]) < min_data:
        min_data = abs(data[i])

if count_fu % 2 == 0:
    print(sum_data)
else:
    print(sum_data - 2 * min_data)
    # print(sum_data, min_data)




Measured memory_bytes: 14412
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 3004
#define INF 1e9+7

using namespace std;

ll n,k,ar[N];
ll dp[N][N][2];
bool vis[N][N][2];

ll solve(ll i,ll j,ll who)
{
    if(i > j)
        return 0;
    if(vis[i][j][who])
        return dp[i][j][who];

    vis[i][j][who] = true;

    ll res;

    if(who==0)
        res = max(solve(i+1,j,1)+ar[i],solve(i,j-1,1)+ar[j]);
    else
        res = min(solve(i+1,j,0)-ar[i],solve(i,j-1,0)-ar[j]);

    return dp[i][j][who]=res;
}

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

    cin >> n;

    rep(i,0,n)
    {
        cin >> ar[i];
    }

    cout << solve(0,n-1,0);

    return 0;
}



Measured memory_bytes: 158208
#include <iostream>
#include <vector>
#include <cmath>

long long solve(int N, std::vector<int> A) {
  long long count = 0;
  for(int i = 0; i < N; i++) {
    long long pair = 0;
    pair = std::floor(A[i] / 2);
    
    //A[i] % 2 = 1 → A[i], A[i + 1] : 1 pair
    if(i + 1 < N) {
      if(A[i] % 2 > 0 && A[i+1] > 0) {
        pair = pair + 1;
        A[i+1] = A[i+1] - 1;
      }
    }
    count = count + pair;
  }
  return count;
}

int main(void) {
  //input
  int N;
  std::cin >> N;
  
  std::vector<int> A;
  int a;
  while(std::cin >> a) {
    A.push_back(a);
  }
  
  long long O;
  O = solve(N, A);
  
  //output
  std::cout << O <<std::endl;
  
  return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	ll n;
	while (cin >> n) {
		n--;
		cout << (n * n + n) / 2 << endl;
	}
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int D;
vector<int> c(26);
vector<int> last(26, 0);
vector<vector<int>> s(365, vector<int>(26));
void input();
int score;
int next_num;
const int Way = 10;
const int Nest = 3;
/*void dfs(int nest, int d) {
	int M = 0, temp = score;
	int prev, n;
	vector<pair<int, int>> kouho(26);
	rep(j, 0, 26) {
		score = temp;
		score += s[d - 1][j];
		prev = last[j];
		last[j] = d;
		rep(k, 0, 26)score -= c[k] * (d - last[k]);
		kouho[j].first = score;
		kouho[j].second = j;
		last[j] = prev;
	}
	//sort(all(kouho), greater<pair<int, int>>());
	rep(j, 0, Way) {
		//prev = last[kouho[j].second];
		//last[kouho[j].second] = d;
		score = kouho[j].first;
		if (nest && d < D)dfs(nest - 1, d + 1);
		if (M < score)M = score, n = kouho[j].second;
		printf("j:%2d score:%d\n", j, score);
		//last[kouho[j].second] = prev;
	}
	score = M;
	next_num = n;
}*/
int dfs(int nest, int i) {
	ll M = -1 << 30, temp = score;
	int prev, p;
	vector<pair<int, int>> kouho(26);
	rep(j, 0, 26) {
		score = temp + s[i - 1][j];
		rep(k, 0, 26)if (j != k)score -= c[k] * (i - last[k]);
		kouho[j].first = score;
		kouho[j].second = j;
	}
	sort(all(kouho), greater<pair<int, int>>());
	rep(j, 0, Way){
		score = kouho[j].first;
		prev = last[kouho[j].second];
		last[kouho[j].second] = i;
		if (nest && i < D)dfs(nest - 1, i + 1);
		last[kouho[j].second] = prev;
		if (M < score)M = score, p = kouho[j].second;
	}
	score = M;
	return p;
}
int main()
{
	input();
	/*rep(i, 1, D + 1) {
		//score = 0;
		dfs(Nest, i);
		printf("%d\n", next_num + 1);
		last[next_num] = i;
		printf("%d\n", score);
	}*/
	rep(i, 1, D + 1) {
		score = 0;
		int p = dfs(Nest, i);
		last[p] = i;
		printf("%d\n", p + 1);
		//printf("%d\n", score);
	}
	return 0;
}
void input() {
	cin >> D;
	rep(i, 0, 26)cin >> c[i];
	rep(i, 0, D) {
		rep(i2, 0, 26)cin >> s[i][i2];
	}
}

Measured memory_bytes: 3764
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> s(m);
    rep(i, m) {
        int k; cin >> k;
        rep(j, k) {
            int ss; cin >> ss;
            s[i].push_back(ss-1);
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];
    int ans = 0;
    rep(i, (1<<n)) {
        int sum = 0;
        rep(j, m) {
            int l = 0;
            for(auto v : s[j]) if((1<<v) & i) l++;
            if(l % 2 == p[j]) sum++;
        }
        if(sum == m) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
N = int(input())
A = [list(map(int, input().split())) for i in range(2)]
max_candies = 0
for i in range(N):
    candies = sum(A[0][:i+1] + A[1][i:])
    if max_candies < candies:
        max_candies = candies
print(max_candies)

Measured memory_bytes: 3060
from sys import stdin

N, x = [int(a) for a in stdin.readline().rstrip().split()]
a = [int(b) for b in stdin.readline().rstrip().split()]
a.sort()

ans = 0
for i in range(len(a)):
    if i < len(a) - 1 and x >= a[i]:
        ans += 1
        x -= a[i]
    elif i == len(a) - 1 and x == a[i]:
        ans += 1
        break
    elif i == len(a) - 1 and x > a[i]:
        pass
    else:
        break

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

			int s = a * 100 + b * 10 + c;
			if (s % 4 == 0) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 21844
// This is the start of  template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vll vector<int>
#define pb push_back
#define pll pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
void input(){
#ifndef ONLINE_JUDGE 
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); 
#endif
}
#define INF LONG_LONG_MAX
#define mod 1000000007
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define cases int t; cin>>t; while(t--)
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
int power(int a,int n)
{
    if(n==0)
        return 1;
    if(n%2!=0)
    {
        return (a*power((a*a)%mod,n/2))%mod;
    }
    return power((a*a)%mod,n/2)%mod;
}

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  input();
  int maxPos = -1e10,maxNeg = -1e10,minPos = 1e10 ,minNeg = 1e10;
  int n ;
  cin>>n;

  for(int i = 0;i<n ;i++)
  {
  	int x,y;
  	cin>>x>>y;
  	maxPos = max(maxPos,x+y);
  	minPos = min(minPos,x+y);

  	maxNeg = max(maxNeg,x-y);
  	minNeg = min(minNeg,x-y);
  }
  // cout<<maxPos<<" "<<maxNeg<<endl;
  // cout<<minPos<<" "<<minNeg<<endl;
  cout<<max(abs(maxNeg-minNeg),abs(maxPos-minPos));
}

//

Measured memory_bytes: 3600
my $A = 0;
my $V = 0;
my $B = 0;
my $W = 0;
my $T = 0;
my $cnt = 0;
while(<STDIN>)
{
  chomp $_;
  my @cols = split(" ", $_);
  if($cnt == 0) {
  	$A = $cols[0];
  	$V = $cols[1];
  }elsif($cnt == 1) {
  	$B = $cols[0];
  	$W = $cols[1];
  }elsif($cnt == 2) {
  	$T = $cols[0];
  }
  $cnt++;
}
if($W >= $V) {
  print "NO";
}else {
  my $D = $V - $W;
  my $E = abs($B - $A)/$D;
  if($E <= $T && $E >= 1) {
  	print "YES";
  }else {
  	print "NO";
  }
}

Measured memory_bytes: 4724
n=int(input())
used=[False for i in range(n)]
d=[0 for i in range(n)]
f=[0 for i in range(n)]
mat=[]
for i in range(n):
    tmp=list(map(int,input().split()))
    mat.append(tmp[2:])

t=1
def dfs(now):
    global t
    if used[now]:
        return
    else:
        used[now]=True
    d[now]=t
    t+=1
    for i in range(len(mat[now])):
        dfs(mat[now][i]-1)
    f[now]=t
    t+=1

for i in range(n):
    if used[i]==False:
        dfs(i)
for i in range(n):
    print(i+1,d[i],f[i])



Measured memory_bytes: 5712
import sys
from math import log10, floor, ceil
from itertools import combinations, product
n = int(input())
n_start = int(str(n)[0])
n_last = int(str(n)[-1])
n_keta = floor(log10(n)) + 1
ans = 0
dic = {(i[0], i[1]) : 0 for i in product(range(10), repeat=2)}
for i in range(n+1):
    _i = str(i)
    dic[(int(_i[0]), int(_i[-1]))] += 1
dic[(0, 0)] = 0
for a, b in product(range(10), repeat=2):
    ans += dic[(a, b)] * dic[(b, a)]
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
    int i,j,H,W;
    
    for(;;){
        scanf("%d %d", &H, &W);
        if(H==0 || W==0){
            break;
        }else{
            for(i=0; i<H; i++){
                for(j=0; j<W; j++){
                    printf("#");
                }
                printf("\n");
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2068
while True:
    
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break    
    for a in range(H):
        for b in range(W):
             if (a + b) % 2 == 0:
                  print('#', end='')
             else:
                  print('.', end='')
        print()
    print()
         

Measured memory_bytes: 8988
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x=nxt();
    int q=x/500;
    x=x%500;
    int test=1000*q;
    q=x/5;
    test+=q*5;
    cout<<test<<endl;

    
    
    return 0;   
}


 
 


Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 580
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

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

void solve()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  vi v;
  v.pb(a*d);
  v.pb(a*c);
  v.pb(b*c);
  v.pb(b*d);
  sort(all(v));
  cout << v[3] << '\n';
  return;
} 

signed main()
{
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  
  vector<string> r(h);
  for(int i=0; i<h; i++){
    cin >> r.at(i);
  }

  for(int i=0; i<w+2; i++) cout << "#";
  cout << endl;
  
  for(int i=0; i<h; i++){
    cout << "#" << r.at(i) << "#" << endl;
  }
  
  for(int i=0; i<w+2; i++) cout << "#";
  cout << endl;
  
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

char beet[2222];

int H,W;
int A[2222][2222];

int h[2222];
int l[2222],r[2222];

int ans;
void calc(){
    stack<int>stk;
    rep(i,H-1){
        while(stk.size()&&h[stk.top()]>=h[i])stk.pop();
        if(stk.size())l[i]=stk.top()+1;
        else l[i]=0;
        stk.push(i);
    }

    stk=stack<int>();
    for(int i=H-2;i>=0;i--){
        while(stk.size()&&h[stk.top()]>=h[i])stk.pop();
        if(stk.size())r[i]=stk.top();
        else r[i]=H-1;
        stk.push(i);
    }

    rep(i,H-1){
        chmax(ans,(r[i]-l[i]+1)*h[i]);
    }
}

signed main(){
    scanf("%lld%lld",&H,&W);
    rep(i,H){
        scanf("%s",beet);
        rep(j,W)A[i][j]=beet[j]=='#';
    }

    ans=W;
    rep(i,H-1){
        rep(j,W){
            A[i][j]^=A[i+1][j];
        }
    }

    rep(i,H-1){
        rep(j,W){
            if(A[i][0]==A[i][j])h[i]++;
            else break;
        }
    }

    rep(j,W){
        calc();
        if(j+1==W)break;
        rep(i,H-1){
            h[i]--;
            if(h[i])continue;
            for(int k=j+1;k<W;k++){
                if(A[i][j+1]==A[i][k])h[i]++;
                else break;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 35072
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

inline bool simu(const ll k, ll n) {
    while (n>1) {
        if (n%k==0) n = n/k;
        else {
            n = n%k;
            break;
        }
    }
    if (n==1) return true;
    else return false;
}

int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    vector<ll> s;
    for (ll i = 1; i * i <= n; ++i) {
        if (i==1) {
            s.push_back(n/i);
            continue;
        }
        s.push_back(i);
        if (i!=n/i) s.push_back(n/i);
    }

    ll ans = 0;
    if (n-1!=1) ans++;
    for (auto &&e: s) {
        if (simu(e,n)) ans++;
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 18792
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,a[101010];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


  cin >> n;
  vi v;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      int cnt = 0;
      while(n%i==0){
        cnt++;
        n/=i;
      }
      v.pb(cnt);
    }
  }
  if(n>1)v.pb(1);
  int ans = 0;
  for(auto t:v){
    int cur = 0;
    for(int i=1;;i++){
      cur+=i;
      if(cur>t)break;
      ans++;
    }
  }
  cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
int r = get<int>();
cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,x,p,q,i;
    cin>>k>>x;
    p=x-(k-1);
    q=x+(k-1);
    for(i=p;i<=q;i++)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> b(N),ans(N),index(N);
  for(int i=0;i<N;i++){
    cin >> b.at(i);
    index.at(i)=i;
  }
  for(int i=N-1;i>=0;i--){
    if(index.size()<b.at(i)){
      cout << -1 << endl;
      return 0;
    }
    ans.at(index.at(b.at(i)-1))=b.at(i);
    index.erase(index.begin()+b.at(i)-1);
  }
  for(int i=0;i<N;i++){
    cout << ans.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
S = input()

for i in range(1 << 3):
  tmp = int(S[0])
  op = []
  for j in range(3):
    if ((i >> j) & 1) == 1:
      op += ["+"]
      tmp += int(S[j+1])
    else:
      op += ["-"]
      tmp -= int(S[j+1])
  if tmp == 7:
    res = ""
    for j in range(3):
      res += S[j]+op[j]
    print(res+S[3]+"=7")
    break


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
#define PAI 3.14159265358979
// ver1.6
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  cout << (n*(n-1))/2 << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
char c;
cin >> c;
if(c == 'A'){
	cout << "T" << endl;
}
else if(c == 'T'){
	cout << "A" << endl;
}
else if(c == 'G'){
	cout << "C" << endl;
}
else{
	cout << "G" << endl;
}

return 0;
}



Measured memory_bytes: 256
def MI():return map(int,input().split())
def LI():return list(MI())

from collections import deque
INF=float("inf")
n,x,y=MI()
x-=1
y-=1
ans=[0]*n

for sv in range(n):
  dist=[INF]*n
  q=deque()
  def push(v,d):
    if dist[v]!=INF:
      return
    dist[v]=d
    q.append(v)
  push(sv,0)
  while q:
    v=q.popleft()
    d=dist[v]
    if v-1>=0:
      push(v-1,d+1)
    if v+1<n:
      push(v+1,d+1)  
    if v==x:
      push(y,d+1)
    if v==y:
      push(x,d+1)
        
  for i in range(n):
    ans[dist[i]]+=1
for i in range(n):
  ans[i]//=2
for i in range(1,n):
  print(ans[i])


Measured memory_bytes: 55388
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int A[114514];
string s;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> s;
	s[3] = '8';

	cout << s << endl;
}


Measured memory_bytes: 256
//************************
//*  Date: 2018.8.3      *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int a,b;
	cin>>a>>b;
	cout<<(a-1)*(b-1)<<endl;
	rt0;
}

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

int main(){
  int stat[8]; for(int i=0;i<8;i++){stat[i]=0;}
  int n; cin>>n;
  
  int a,c; c=0;
  for(int i=0;i<n;i++){
    cin>>a; a=a/400;
    if(a<8){stat[a]=1;}
    else{c++;}
  }
  
  int d=0; for(int i=0;i<8;i++){d+=stat[i];}
  cout<<max(1,d)<<' '<<c+d;
  
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc128/tasks/abc128_a

package main

import "fmt"
import "bufio"
import "os"
import "strconv"

var _sw = bufio.NewScanner(os.Stdin)

func main() {
	A := nextInt()
	P := nextInt()

	fmt.Println((A*3 + P) / 2)
}

func init() {
	_sw.Split(bufio.ScanWords)
}

func nextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int INF = 1234567;
int n;
int f[100][100]={};

map<set<pi>,int> dp;
int dfs(const set<pi> &s)
{
    if(dp.count(s)) return dp[s];

    int ret = 0;
    for(auto &x:s) ret += x.se;

    // dbg(vector<pi>(all(s)));
    // dbg(ret);
    rep(i,n)
    {
        auto itr = s.lower_bound(pi(i,0));
        if(itr->fi == i) continue;

        bool ok = true;
        set<pi> ns;
        int a = INF;
        for(auto x:s)
        {
            ok &= (f[x.fi][i]>0);
            x.se = min(x.se,f[x.fi][i]);
            a = min(a,f[x.fi][i]);
            ns.insert(x);
        }
        ns.insert(pi(i,a));

        if(ok) ret = max(ret, dfs(ns));
    }
    return dp[s] = ret;
}

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

    vector<int> u(m),v(m),c(m);
    rep(i,m)
    {
        cin >>u[i] >>v[i] >>c[i];
        --u[i];
        --v[i];
        f[u[i]][v[i]] = f[v[i]][u[i]] = c[i];
    }

    int ans = 0;
    rep(i,m)
    {
        set<pi> s;
        s.insert(pi(u[i],c[i]));
        s.insert(pi(v[i],c[i]));
        ans = max(ans,dfs(s));
    }
    cout << ans << endl;
    return 0;
}

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

def calc(n, a, b, ans, move):
    if (b-a)%2 == 0:
        return ans + (b-a)//2
    else:
        if move == 1:
            a += move
        else:
            b += move
        return calc(n, a, b, ans+1, move)
            
        

def main():
    N,A,B = (int(x) for x in input().split())

    if (B-A)%2 == 0:
        print((B-A)//2)
    else:
        left = A - 1
        right = N - B
        
        if left <= right:
            print(calc(N, 1, B-left, left, -1))
        else:
            print(calc(N, A+right, N, right, 1))        



if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main()
{
	char s[3][7]={"Sunny","Cloudy","Rainy"};
	char S[7];
	gets(S);
	if(strcmp(S,s[0])==0) printf("%s",s[1]);
	else if(strcmp(S,s[1])==0) printf("%s",s[2]);
	else printf("%s",s[0]);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){
    
    return;
}


int main(){
    char s;
    cin >> s;
    if (s <= 'Z'){
        ctn("A");
    }
    else{
        ctn('a');
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint digit_sum(lint n, lint base) {
  lint res = 0;
  while (n) {
    res += n % base;
    n /= base;
  }
  return res;
}
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  lint n; cin >> n;
  lint res = 1e9;
  for (int i = 1; i < n; i++) {
    res = min(res, digit_sum(i, 10) + digit_sum(n - i, 10));
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
 int a,b,c,k;
 cin>>a>>b>>c>>k;

 if(max({a,b,c})==a){
  cout<<a*pow(2,k)+b+c<<endl;
 }

 else if(max({a,b,c})==b){
  cout<<b*pow(2,k)+a+c<<endl;
 }

 else{
  cout<<c*pow(2,k)+b+a<<endl;
 }
}

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

using namespace std;

const int maxn = 1e5+10;

int dp[maxn];

vector<int> grafo[maxn];

int solve(int u)
{
	if (dp[u] != -1) return dp[u];

	int ans = 0;
	for (auto v: grafo[u])
		ans = max(ans, 1+solve(v));

	return dp[u] = ans;
}

int main(void)
{
	int n, m;
	cin >> n >> m;

	for (int i = 1; i <= m; i++)
	{
		int u, v;
		cin >> u >> v;

		grafo[u].push_back(v);
	}

	memset(dp, -1, sizeof dp);

	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(ans, solve(i));

	cout << ans << "\n";
}

Measured memory_bytes: 8192
#include<iostream>
using namespace std;
int main(){
    int n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d>>s;
    bool f=true;
    for(int i=a-1;i<c-2;i++)if(s[i]=='#'&&s[i+1]=='#')f=false;
    for(int i=b-1;i<d-2;i++)if(s[i]=='#'&&s[i+1]=='#')f=false;
    if(d<c){
        f=false;
        for(int i=b-2;i<d-1;i++)if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.')f=true;
    }
    cout<<(f?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
 
using namespace std;
 
typedef long long ll;
 
int h, w, n;
set<int> s[200002];
 
int main()
{
 
    // ifstream cin("a.in");
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    cin >> h >> w >> n;
    for(int i = 1; i <= n; ++i)
    {
        int a, b;
        cin >> a >> b;
        s[b].insert(a);
    }
    for(int i = 1; i <= w; ++i)
        s[i].insert(h+1);
    int ans = (1<<20);
    int col = 1;
    for(int i = 1; i <= h; ++i)
    {
        ans = min(ans, (*s[col].lower_bound(i+1)) - 1);
        if(col < w && *s[col+1].lower_bound(i+1) != i+1)
            ++col;
    }
    cout << ans << '\n';
    return 0;
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, A, B, C;
            A = 0;B = 0;C = 0;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            A = a + b; B = b + c; C = c + a;

            if (A <= B && A <= C)
                Console.WriteLine(A);
            else if (B <= A && B <= C)
                Console.WriteLine(B);
            else Console.WriteLine(C);

            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.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};
const string dir = "DRUL";
*/
template<typename T>
vector<T> divisor(T N) {
    vector<T> res;
    for(T i = 1; i * i <= N; i++){
        if(N % i == 0){
            res.push_back(i);
            if(i * i != N)res.push_back(N / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}
template<typename T> 
map<T,int> factorize(T x){
    map<T,int> mp;
    for (T i = 2; i*i <= x; i++){
        while (x%i == 0) {
            x /= i;
            mp[i]++;
        }
        if (x == 1) break;
    }
    if (x != 1) mp[x]++;
    return mp;
}

int A[200010];
int mp[2000100];
int main() {
    int N;
    cin >> N;
    rep(i, N){
        cin >> A[i];
        mp[A[i]]++;
    }
    int ans = 0;
    rep(i,N){
        if(mp[A[i]] > 1)continue;
        bool ok = true;
        mp[A[i]]--;
        for(int j = 1; j * j <= A[i]; j++){
            if(A[i] % j == 0){
                if(mp[j] > 0){
                    ok = false;
                    break;
                }
                if(mp[A[i]/j] > 0){
                    ok = false;
                    break;
                }
            }
        }
        mp[A[i]]++;
        if(ok)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8268
n = gets.to_s.to_i
a = gets.to_s.split.map{|t| t.to_i }.sort.reverse
b = gets.to_s.split.map{|t| t.to_i }
c = gets.to_s.split.map{|t| t.to_i }.sort

ans = 0
b.each do |m|
  
  i = n - (a.bsearch_index{ |u| u < m } || n)
  j = n - (c.bsearch_index{ |b| m < b } || n)
  ans += i * j
  
end

puts ans

Measured memory_bytes: 25560
fun main(arg: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val po = (1..m).map {
        readLine()!!.split(' ').drop(1).map(String::toInt).fold(0) { acc, x ->
            acc + 1.shl(x - 1)
        }
    }
    val p = readLine()!!.split(' ').map(String::toInt)
    var count = 0
    for (i in 0 until 1.shl(n)) {
        val meu = (0 until m).map {
            digitSum(po[it].and(i), 2) % 2 == p[it]
        }.fold(true, Boolean::and)
        if (meu) count += 1
    }
    println(count)
}

fun digitSum(n: Int, d: Int): Int {
    return if (n < d) n else (n % d) + digitSum(n / d, d)
}


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

int main() {
	long n,a,b;
  	cin >> n >> a >> b;
  	if(n%(a+b)>=a){
      cout << n/(a+b)*a+a << endl;
    }
  	else{
      cout << n/(a+b)*a+n%(a+b) << endl;
    }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int x, y;
    scan(x, y);

    long ans;
    auto mc = ModComb(x + 1);

    foreach (a ; 0 .. x + 1) {
        auto xr = x - a;
        auto yr = y - 2*a;
        if (xr < 0 || yr < 0) continue;
        if (xr % 2 == 1 || xr / 2 != yr) continue;
        auto b = xr / 2;
        (ans += mc.c(a + b, a)) %= mod;
    }

    writeln(ans);
}


struct ModComb {
    int _N;
    long[] _fact, _factinv;
    long _mod;

    this(int n, long mod = 1_000_000_007L) {
        _N = n;
        _fact = new long[](_N + 1);
        _factinv = new long[](_N + 1);
        _mod = mod;

        _fact[0] = 1;
        foreach (i ; 1 .. _N + 1) {
            _fact[i] = (_fact[i-1] * i) % mod;
        }

        _factinv[_N] = _powmod(_fact[_N], mod - 2);
        foreach_reverse (i ; 0 .. _N) {
            _factinv[i] = (_factinv[i+1] * (i+1)) % mod;
        }
    }

    long c(int n, int k) {
        if (k < 0 || k > n) return 0;
        return f(n) * finv(n - k) % _mod * finv(k) % _mod;
    }

    long p(int n, int r) {
        if (r < 0 || r > n) return 0;
        return f(n) * finv(n - r) % _mod;
    }

    long f(int n) {
        return _fact[n];
    }

    long finv(int n) {
        return _factinv[n];
    }

    long _powmod(long x, long y) {
        return y > 0 ? _powmod(x, y>>1)^^2 % _mod * x^^(y & 1) % _mod : 1;
    }
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 18812
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <array>

using namespace std;
#define C 100

int main(){
  int N, M, num[C]={0}, i, a[C], b[C];
  cin >> N >> M;
  for (i = 0; i < M; i++){
    cin >> a[i] >> b[i];
    num[a[i] - 1] ++;
    num[b[i] - 1] ++;
  }
  for (i = 0; i < N; i++)
    cout << num[i] << endl;
  return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;
using T = std::tuple<int,int,int>;

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

int H, W;
std::string S;
bool used[1100][1100];
std::queue<T> que;

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

    std::cin >> H >> W;

    int rest = H * W;

    for(int i=0;i<H;++i){
        std::cin >> S;

        for(int j=0;j<W;++j){
            if(S[j] == '#'){
                used[i][j] = 1;
                rest -= 1;
                que.emplace(i, j, 1);
            }
        }
    }

    if(rest == 0){
        std::cout << 0 << std::endl;
        return 0;
    }

    int res;

    until(que.empty()){
        int r, c, t;
        std::tie(r, c, t) = que.front();
        que.pop();

        for(int i=0;i<4;++i){
            int nr = r + dx[i], nc = c + dy[i];

            if(0 <= nr && nr < H &&
               0 <= nc && nc < W &&
               !used[nr][nc]){
                used[nr][nc] = 1;
                rest -= 1;
                que.emplace(nr, nc, t + 1);
            }
        }

        if(rest == 0){
            res = t;
            break;
        }
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 13456