akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Stack;
import java.util.Scanner;
import java.util.Queue;

/**
 * @author yoshikyoto
 */
class Main{
	static final boolean DEBUG = false;
	static Scanner sc = new Scanner(new InputStreamReader(System.in));
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static void main(String args[]) throws Exception{
		int n = readInt();
		int res = 100;
		for(int i = 0; i < n; i++){
			double res_d = res * 1.05;
			res = (int)Math.ceil(res_d);
		}
		p(res * 1000);
	}

	public static String readLine() throws IOException{return br.readLine();}
	public static int readInt(){return sc.nextInt();}
	public static void pa(Object[] arr){System.out.println(Arrays.toString(arr));}
	public static void pa(int[] arr){System.out.println(Arrays.toString(arr));}
	public static void pa(double[] arr){System.out.println(Arrays.toString(arr));}
	public static void pa(boolean[] arr){System.out.println(Arrays.toString(arr));}
	public static void p(Object o){System.out.println(o.toString());}
	public static void d(Object o){if(DEBUG)System.out.println(o.toString());}
	public static void da(int[] arr){if(DEBUG)System.out.println(Arrays.toString(arr));}
	public static void sort(int[] a){Arrays.sort(a);}
	public static int[] parseInt(String[] arr){
		int[] res = new int[arr.length];
		for(int i = 0; i < arr.length; i++)res[i] = Integer.parseInt(arr[i]);
		return res;
	}
	public static int parseInt(Object o){return Integer.parseInt(o.toString());}
	public static int digit(int n){return String.valueOf(n).length();}
	public static String reverse(String s){
		StringBuffer sb = new StringBuffer(s);
		return sb.reverse().toString();
	}
}

class MyHashMap<E> extends HashMap<E, Integer>{
	ArrayList<E> keyArray = new ArrayList<E>();
	public void add(E key){add(key, 1);}
	public void add(E key, Integer value){
		if(containsKey(key)){
			value += get(key);
		}else{
			keyArray.add(key);
		}
		put(key, value);
	}
}

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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}


vector<pair<int, int>> queries;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    /*
     * REMOVE ME PLS
     */

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

    int n, m;

    cin >> n >> m;

    priority_queue<int> q;

    for(int i = 0; i < n; ++i){
        int j;
        cin >> j;
        q.push(-j);
    }

    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        queries.push_back(make_pair(-b, -a));
    }

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

    for(auto i : queries){
        i.first = -i.first;
        i.second = -i.second;
        for(int j = 0; j < i.second; ++j){
            if(-q.top() >= i.first)
                break;
            //cout << "SWAP " << -q.top() << " " << i.first << endl;
            q.pop();
            q.push(-i.first);
        }
    }

    long long tot = 0;
    while(!q.empty()){
        tot -= q.top();
        q.pop();
    }

    cout << tot;


    return 0;
}


Measured memory_bytes: 1912
N=gets.to_i
wrray=gets.split.map(&:to_i)
sum = wrray.inject(:+)
m=1000000007
i=0
while i < N
  s=0
  j=0
  while j < i+1
    s += wrray[j]
    j += 1
  end
  l= sum-s*2
  if l < 0
    l=-l
  end
  if m > l
    m=l
  end
  i+=1
end
puts m

Measured memory_bytes: 1788
n = gets.chomp.to_i
a1 = gets.chomp.split(" ").map(&:to_i)
a2 = gets.chomp.split(" ").map(&:to_i)

max = 0
for i in 0..(n-1) do
  sum = 0
  for j in 0..(n-1) do
    if j < i then
      sum = sum + a1[j]
    elsif j > i then
      sum = sum + a2[j]
    else
      sum = sum + a1[j] + a2[j]
    end
  end 
  if sum > max then
    max = sum
  end
end

puts max


Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>
#include <string.h>

using namespace std;

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

    int n = s.size();
    long long ans = 0;
    long long time = 1;
    long long sum = 0;
    int a[2020];
    memset(a, 0, sizeof(a));

    for (int i = n - 1; i >= 0; i--) {
        sum = sum + (s[i] - '0') * time;
        sum = sum % 2019;
        time = time * 10;
        time = time % 2019;
        a[sum] += 1;
    }

    ans += a[0];

    for (int i = 0; i < 2019; i++) {
        ans += (a[i] * (a[i] - 1)) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3764
io = STDIN
s=io.gets.chomp
size=s.size
#sizeがnの時、同一文字がn/2+1以上
hash=Hash.new{|h,k|h[k]=0}

if size>=3
  s.split(//).each_cons(3).with_index do |x,i|
    a,b,c,d,e=x
    if a==b
      puts "#{i+1} #{i+2}"
      exit
    end
    if a==c
      puts "#{i+1} #{i+3}"
      exit
    end
  end
else
  if s[0]==s[1]
    puts "1 2"
    exit
  end
end
puts "-1 -1"

Measured memory_bytes: 9468
n,m,q = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(m)]
query = [list(map(int,input().split())) for _ in range(q)]
s = [[0]*(n+1) for _ in range(n+1)]

for i in range(m):
    l,r = lst[i]
    s[l][r] += 1

for i in range(1,n+1):
    for j in range(1,n+1):
        s[i][j] += s[i][j-1]

for i in range(q):
    l,r = query[i]
    ans = 0
    for j in range(l,r+1):
        ans += s[j][r] - s[j][l-1]
    print(ans)

Measured memory_bytes: 125556
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define vvll vecror<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
 
 


void solve()
{
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k,abs(k-n%k));
    /*if(n%k==0)
    {
    	cout<<0;
    	return;
    }
    if(n<k)
    {
    	cout<<min(n,k-n);
    	return;
    }
    n=n-k;
    if(ceil1(k,2)>n)
    	cout<<n;
    else
    	cout<<1;*/
    return;
}

int main()
{
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
  
int main(int argc, const char * argv[]) {
  int w, h, x, y, r;
  scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
  if(x + r <= w)
    if(r <= x)
      if(y + r <= h)
        if(r <= y){
          printf("Yes\n");
          return 0;
        }
  printf("No\n");
  return 0;
}

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

int main(){
	int N,M;
	cin>>N>>M;
	int P[M],Y[M];
	vector<int> V[N];
	for(int i=0;i<M;++i){
		cin>>P[i]>>Y[i];
		V[P[i]-1].push_back(Y[i]);
	}
	for(int i=0;i<N;++i){
		sort(V[i].begin(),V[i].end());
	}
	for(int i=0;i<M;++i){
		int left=0,right=V[P[i]-1].size()-1;
		int mid;
		while(left<=right){
			mid=(left+right)/2;
			if(V[P[i]-1][mid]==Y[i]){
				cout<<setw(6)<<setfill('0')<<P[i];
				cout<<setw(6)<<setfill('0')<<mid+1<<endl;				
				break;
			}
			if(V[P[i]-1][mid]<Y[i]){
				left=mid+1;
			}
			if(V[P[i]-1][mid]>Y[i]){
				right=mid;
			}
		}
	}
}


Measured memory_bytes: 7808
import java.util.Scanner;

//AtCoder Beginner Contest 147
//A	Blackjack
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A1 = Integer.parseInt(sc.next());
		int A2 = Integer.parseInt(sc.next());
		int A3 = Integer.parseInt(sc.next());
		sc.close();

		if ((A1+A2+A3) >= 22) {
			System.out.println("bust");
		} else {
			System.out.println("win");
		}
	}
}


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

using namespace std;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    if(n % x == 0)
        cout << (n / x) * t;
    else
        cout << ((n / x) + 1) * t;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void){
	int n,ai,i,min,max;
	long sum=0;
	min = 1000000; max = -1000000;
	
	scanf("%d",&n);
	
	for(i = 0;i < n;i++){
		scanf("%d",&ai);
		
		if(ai < min){
			min = ai;
		}if(ai > max){
			max = ai;
		}
		sum = sum + ai;
	}
	printf("%d %d %ld\n",min,max,sum);
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
 
 
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto &x:A)cin>>x;
    
    map<int, lint> cnt;
    for (auto x : A) cnt[x]++;
    lint ret = 0;
    //求出从N个球中找到整数相等的不同的两个球(在code里意思是index一样的value有多大)
    for (auto p : cnt) ret += (p.second - 1) * p.second / 2; //n*n-1/2
     
    for(int i=0;i<N;i++) {
        lint n = cnt[A[i]];
        lint tmp = ret - (n-1);//由于题目是要求去掉第k个球之后找相同整数,所以最后答案减去n-1
        cout << tmp << "\n";
    }
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H, vector<char>(W));
    vector<vector<char>> tmp(H, vector<char>(W));
    vector<vector<char>> ans(H, vector<char>(W));
    rep(i, H) {
        rep(j, W) {
            cin >> a[i][j];
        }
    }
    int cnt = 0;
    rep(i, H) {
        bool flag = false;
        rep(j, W) {
            if (a[i][j] == '#') {
                flag = true;
                break;
            }
        }
        if (flag) {
            rep(j, W) {
                tmp[cnt][j] = a[i][j];
            }
            cnt += 1;
        }
    }
    cnt = 0;
    rep(j, W) {
        bool flag = false;
        rep(i, H) {
            if (tmp[i][j] == '#') {
                flag = true;
                break;
            }
        }
        if (flag) {
            rep(i, H) {
                ans[i][cnt] = tmp[i][j];
            }
            cnt += 1;
        }
    }
    rep(i, H) {
        rep(j, W) {
            if (ans[i][j] == '#' | ans[i][j] == '.') cout << ans[i][j];
        }
        cout << '\n';
    }
    return 0;
}

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

nums = list(map(int, input().split()))
q = int(input())
target_nums = list(map(int, input().split()))
score_list = []

for i in range(1 << n):
    ans = 0
    for j in range(n):
        if i >> j & 1:
            ans += nums[j]
    score_list.append(ans)
# print(score_list)
for num in target_nums:
    if num in score_list:
        print("yes")
    else:
        print("no")



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


void solve(long long A, long long B){
    cout << A*B << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

A = [input() for _ in range(H)]

confilm = [[False] * W for _ in range(H)]
confilm[0][0] = True

nH, nW = 0, 0
while True:
    isMoved = False
    while nW < W - 1 and A[nH][nW + 1] == '#':
        nW += 1
        confilm[nH][nW] = True
        isMoved = True
    while nH < H - 1 and A[nH + 1][nW] == '#':
        nH += 1
        confilm[nH][nW] = True
        isMoved = True

    if not isMoved:
        break

for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            if confilm[h][w]:
                continue
            else:
                print('Impossible')
                exit()
        else:
            if confilm[h][w]:
                print('Impossible')
                exit()
            else:
                continue

print('Possible')




Measured memory_bytes: 3064
using System;
using System.Linq;
 
namespace cPOPAS
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(a.Max() * 2 > x[0] + 1 ? a.Max() * 2 - 1 - x[0] : 0);
        }
    }
}

Measured memory_bytes: 13396
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = int.Parse(line[0]);
        var y = int.Parse(line[1]);
        Console.WriteLine(getN(x) == getN(y) ? "Yes" : "No");
    }
    public static int getN(int x)
    {
        int ret;
        var a = new int[] { 4, 6, 9, 11 };
        if (x == 2) ret = 1;
        else if (a.Contains(x)) ret = 2;
        else ret = 3;
        return ret;
    }
}

Measured memory_bytes: 11220
import heapq


INFINITY = 10 ** 10
WHITE = 0
GRAY = 1
BLACK = 2


n = int(input())
dict_adjacency = {}

for _ in range(n):
    u, k, *list_num = map(int, input().split())

    list_temp = []

    dict_adjacency[str(u)] = {}

    for i in range(0, k * 2, 2):
        dict_adjacency[str(u)][str(list_num[i])] = list_num[i + 1]


d = [INFINITY] * n

def dijkstra(top_start):
    color = [WHITE] * n

    d[top_start] = 0
    h = []

    heapq.heappush(h, (d[top_start], top_start))

    while len(h) >= 1:
        cost_now, top_now = heapq.heappop(h)

        color[top_now] = BLACK

        if d[top_now] < cost_now:
            continue

        for top_next in dict_adjacency[str(top_now)].keys():
            top_next = int(top_next)
            if color[top_next] == BLACK:
                continue


            cost_next = d[top_now] + dict_adjacency[str(top_now)][str(top_next)]
            if cost_next < d[top_next]:
                d[top_next] = cost_next
                color[top_next] = GRAY
                heapq.heappush(h, (d[top_next], top_next))


dijkstra(top_start = 0)

for i, cost in enumerate(d):
    print(i, cost)


Measured memory_bytes: 66292
#include <iostream>

using namespace std;

int table[501][501];

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

  int N, M, Q;
  cin >> N >> M >> Q;

  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    table[l][r]++;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      table[i][j] += table[i - 1][j] + table[i][j - 1] - table[i - 1][j - 1];
    }
  }
  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;

    const int ans =
        table[q][q] - table[p - 1][q] - table[q][p - 1] + table[p - 1][p - 1];
    cout << ans << endl;
  }

  return 0;
}


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

const long long INF = (long long) 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector< map<int, long long> > dp(n + 1);
  dp[1][1] = a[1];
  vector<long long> mx(n + 1, -INF);
  mx[0] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = i / 2; j <= (i + 1) / 2; j++) {
      dp[i][j] = mx[j - 1] + a[i];
    }
    for (auto& p : dp[i - 1]) {
      mx[p.first] = max(mx[p.first], p.second);
    }
  }
  for (auto& p : dp[n]) {
    mx[p.first] = max(mx[p.first], p.second);
  }
  cout << mx[n / 2] << '\n';
  return 0;
}

Measured memory_bytes: 34620
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int gcd(int x,int y){
	
	if(y==0)
		return x;
	else
		return gcd(y,x%y);
	
	
}
int main(){
	
	int x,y;
	cin>>x>>y;
	cout<<gcd(x,y)<<endl;
	
	
}

Measured memory_bytes: 1160
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    counter = 0
    for a in A:
        if a == counter + 1:
            counter += 1
    if counter == 0:
        ans = -1
    else:
        ans = N - counter
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 26268
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う

int main(){
  int A,B;
  cin >> A >> B ;

  if(A*B % 2 == 0){
  	cout << "Even" << endl;
  }
  else{
  	cout << "Odd" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
// hmmmm ...coool
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int ok[N+2];
int done[N+10];
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n;
		map<int,int>mp;
		fn{
			cin >> ar[i];
			mp[ar[i]]++;
		}
		int ans =0;
		fn{
			int x = ar[i];
			if(ok[ar[i]])continue;
			ok[ar[i]]=1;
			if(mp[x]>=2)done[x]=1;
			for(int j=2*x;j<=N;j+=x)done[j] =1;
		}
		fn{
			ans+=(!done[ar[i]]);
		}
		cout<<ans;
	
	}
	return 0;
}

Measured memory_bytes: 39952
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[100000],n;
ll h[100000]={0};

ll solve(int num)
{
  if(num==n-1)
    return 0;
  if(num>=n)
    return 1000000;
  if(dp[num]!=-1)
    return dp[num];
  int ans=0;
  ans=min(abs(h[num+1]-h[num])+solve(num+1),abs(h[num+2]-h[num])+solve(num+2));
  return dp[num]=ans;
}
int main()
{
for(ll i=0;i<100000;i++)
dp[i]=-1;
ll i;
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>h[i];
  }
 ll a = solve(0);
  cout<<dp[0];
}
 

Measured memory_bytes: 3328
#include<bits/stdc++.h>
typedef long long i64;
int n,k;
i64 sa=0;
void mins(i64&a,i64 b){if(a>b)a=b;}
struct node{
	node*lc,*rc;
	int D,sz,rnd;
	i64 vl,vr;
	void sp(node*&,node*&,int);
	i64 gl(){return lc?lc->gl():vl;}
	i64 gmn(){
		i64 mn=vr;
		if(lc)mins(mn,lc->gmn());
		if(rc)mins(mn,rc->gmn());
		return mn;
	}
}ns[1000007],*np=ns,*rt,*p1,*p2,*p3,*p4;
node*mg(node*a,node*b){
	if(!a)return b;
	if(!b)return a;
	if(a->rnd>b->rnd){
		a->sz+=b->sz;
		a->rc=mg(a->rc,b);
		return a;
	}
	b->sz+=a->sz;
	b->lc=mg(a,b->lc);
	return b;
}
void node::sp(node*&l,node*&r,int k){
	if(!this){l=r=0;return;}
	int ls=lc?lc->sz:0;
	if(k<=ls)return r=this,sz-=k,lc->sp(l,lc,k);
	if(k>=ls+D)return l=this,sz=k,rc->sp(rc,r,k-ls-D);
	k-=ls;
	node*a=np++,*b=np++;
	*a=(node){0,0,k,k,rand(),vl,vl};
	*b=(node){0,0,D-k,D-k,rand(),vr,vr};
	if(vl>vr){
		a->vr=vl-k+1;
		b->vl=vl-k;
	}
	l=mg(lc,a);
	r=mg(b,rc);
}
char buf[2000007],*ptr=buf;
int _(){
	int x=0;
	while(*ptr<48)++ptr;
	while(*ptr>47)x=x*10+*ptr++-48;
	return x;
}
int main(){
	fread(buf,1,sizeof(buf),stdin);
	n=_(),k=_();
	srand(time(0));
	*(rt=np++)=(node){0,0,k,k,rand(),0,0};
	for(int i=1,a,b;i<=n;++i){
		a=_(),b=_();
		sa+=a;
		if(b==1){
			if(a*2>k)return puts("-1"),0;
			rt->sp(p1,p2,1);
			p2->sp(p2,p3,a*2-1);
			p3=mg(p3,p1);
			i64 y=p3->gl();
			*(p4=np++)=(node){0,0,a*2-1,a*2-1,rand(),y+a*2-1,y+1};
			rt=mg(p3,p4);
		}else{
			rt->sp(p1,p2,a*2%k);
			rt=mg(p2,p1);
		}
	}
	printf("%lld\n",sa*2+rt->gmn());
	return 0;
}

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

works = list()
for num in range(n):
    a = list(map(int, input().split()))
    works.append(a)

works.sort(key = lambda x :x[1])

time = 0
limit = 0

for row in works:
    time += row[0]
    limit = row[1]
    if time > limit:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 53656
// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl
 
const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
 
 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
 
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;
struct comp{
    bool operator() (pll a, pll b){
        return a.ff+a.ss <  b.ff+b.ss;
    }
};
struct comp1{
    bool operator() (pll a, pll b){
        return a.ff-a.ss <  b.ff-b.ss;
    }
};
struct comp2{
    bool operator() (pll a, pll b){
        return a.ss-a.ff <  b.ss-b.ff;
    }
};
void solve(){
    int n; cin>>n;
    set <pll,comp> s1;
    set <pll,comp1> s2;
    set <pll,comp2> s3;
    for(int i=0;i<n;i++){
        ll a,b; cin>>a>>b;
        s1.insert(mp(a,b));
        s2.insert(mp(a,b));
        s3.insert(mp(a,b));
    }
    auto it=s1.begin();
    auto it1=s1.end();
    auto it2=s2.begin();
    auto it3=s2.end();
    auto it4=s3.begin();
    auto it5=s3.end();
    it1--;
    it3--;
    it5--;
    ll ans1=abs((it1->first+it1->second)-(it->first+it->second));
    ll ans2=abs((it2->first-it2->second)-(it3->first-it3->second));
    ll ans3=abs((it4->second-it4->first)-(it5->second-it5->first));
    cout<<max(ans1,max(ans2,ans3))<<endl;
    
}
int main(){
    fastio();
    //write code
    int t; t=1;
    while(t--){
        solve();
    }
    return 0;
}

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

int main() {
	int ans = 0;

	int n, m, x, y;
	cin >> n >> m >> x >> y;

	int vx[100], vy[100], max=x, min=y;
	for (int i = 0; i < n; i++) {
		cin >> vx[i];
		if (max < vx[i]) max = vx[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> vy[i];
		if (min > vy[i]) min = vy[i];
	}

	if (max >= min) ans = 1;


	cout << ((ans) ? "War" : "No War") << endl;

	return 0;
}

Measured memory_bytes: 256
fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut ordered = v.clone();
    ordered.sort();

    let mut ret = 0;
    for i in 0..n {
        if v[i] != ordered[i] {
            ret += 1
        }
    }

    if ret == 0 || ret == 2 {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,a; cin>>n>>a;
	int l=a, r=a+n-1;
	int eat=0;
	if(r<=0) eat=r;
	else if(l>=0) eat=l;
	cout<<(r+l)*(r-l+1)/2-eat<<"\n";
	return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer(8) :: n, i, largest_smaller_dividor
  read (*, *) n
  do i = 1, int(sqrt(dble(n))) + 1
    if (i ** 2 > n) exit
    if (mod(n, i) == 0) largest_smaller_dividor = i
  end do
  write (*, "(i0)") (largest_smaller_dividor - 1) + (n / largest_smaller_dividor - 1)
end program main


Measured memory_bytes: 640
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int t;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> t;
    while (t-->0) {
        int n; cin >> n;
        vll a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
        string s; cin >> s;
        vll basis;
        int ans = -1;
        for (int i = n - 1; i >= 0; i--) {
            for (ll base: basis) chmin(a[i], a[i] ^ base);

            // もし a[i] があとで表される（a[i]==0）なら
            // どちらにせよ操作の必要なし？（打ち消せるので）
            // a[i] があとで表せられない（a[i]!=0）なら
            // 1 なら勝ち（0 に出来ないので）
            // 0 なら基底に加えてもっと前（<i）を見る
            if (a[i] != 0) {
                if (s[i] == '1') {
                    ans = 1;
                    break;
                } else basis.emplace_back(a[i]);
            }
        }
        if (ans == -1) ans = 0;
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define PB push_back

main(){
  int n,k;
  cin>>n>>k;
  while(k--){
    int a,b;
    cin>>a>>b;
    a=min(a,1+n-a);
    b=min(b,1+n-b);
    a=min(a,b);
    cout<<(a+2)%3+1<<endl;
  }
}

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

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

const ll mod = 1e9+7;
const ll INF = 2e9;
const double PI = 3.1415926535;

char s[100001];
ll hat[100001];
ll h[6] = {1, 10, 9, 12, 3, 4};
ll se[6][10] = {
    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
    {0, 1, 2, 4, 5, 7, 8, 10, 11, 12},
    {0, 1, 2, 3, 5, 6, 7, 9, 10, 11},
    {0, 4, 5, 6, 7, 8, 9, 10, 11, 12},
    {0, 1, 2, 3, 5, 6, 8, 9, 11, 12},
    {0, 2, 3, 4, 6, 7, 8, 10, 11, 12}
};
ll dp[100001][13];

int main(void){
    scanf("%s", &s);
    ll i = 0, j = 0;
    while(s[i] != '\0'){
        if(s[i] == '?'){hat[j] = i; j++;}
        i++;
    }
    ll ama = 0;
    for(ll k = 0;k < i;k++){
        if(s[k]!= '?')ama += (s[k] - '0') * h[(i-k-1)%6];
    }
    ama %= 13;
    for(int a = 0;a < j+1;a++)for(int b = 0;b < 13;b++)dp[a][b] = 0;
    dp[0][ama] = 1;
    for(ll k = 0;k < j;k++){
        for(ll m = 0;m < 13;m++)for(ll l = 0;l < 10;l++){
            dp[k+1][(13 + se[(i-hat[k]-1)%6][l] + m)%13] += dp[k][m]%mod;
        }
    }
    cout << dp[j][5]%mod << endl;
    /*for(int a = 0;a < j+1;a++){
        for(int b = 0;b < 13;b++)printf("%lld ", dp[a][b]);
        printf("\n");
    }*/
	return 0;
}

Measured memory_bytes: 11264
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline().rstrip()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N = iIn()
ans = -1 * N % 1000
print(ans)

Measured memory_bytes: 9276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll a[N],b[N],n,ans,s1,s2,s;
pair<ll,int> x1,x2,i1,i2;
vector<pair<ll,int> > h;
int cnt[N];
int main(){
	cin>>n;
	i1=i2=make_pair(2e9,0);
	for (int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
		s1+=a[i],s2+=b[i];
		s+=min(a[i],b[i]);
		pair<ll,int> z=make_pair(max(a[i],b[i]),i);
		if (z<i1)swap(z,i1);
		if (z<i2)i2=z;
		z=make_pair(min(a[i],b[i]),i);
		if (z>x1)swap(z,x1);
		if (z>x2)x2=z;
		h.push_back(make_pair(a[i],i));
		h.push_back(make_pair(b[i],i));
	}
	sort(h.begin(),h.end());
	int can=0;
	ll sum=0;
	for (int i=0;i<n;i++){
		cnt[h[i].second]++;
		if (cnt[h[i].second]==2)can=1;
		sum+=h[i].first;
	}
	if (can){
		cout<<sum<<endl;
		return 0;
	}
	ans=i1.second==x1.second?(min(i2.first-x1.first,i1.first-x2.first)):i1.first-x1.first;
	ans=min(min(s1,s2),ans+s);
	cout<<ans<<endl;
}

Measured memory_bytes: 7536
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define deb(x) cout<<#x<<" "<<endl;
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//-------------------------------------------------------------------------------





int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin>>n;
	int w;
	cin>>w;
	ll wt[n],c[n];
	for(int i=0;i<n;++i){
		cin>>wt[i]>>c[i];
	}
	ll dp[n+1][w+1];
	for(int i=0;i<=n;++i){
		for(int j=0;j<=w;++j){
			if(i==0||j==0){
				dp[i][j]=0;
			}
			else if(wt[i-1]<=j){//last weight is less than capacity j
				dp[i][j]=max(dp[i-1][j-wt[i-1]]+c[i-1],dp[i-1][j]);//include the item or exclude the current item

			}
			else{
				dp[i][j]=dp[i-1][j];//ignore the item if its weight is greater than the capacity of the knapsack
			}
		}
	}
	cout<<dp[n][w];

}
 

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    double limit = 1.0 / (4.0 * m);
    vector<double> v(n);
    double tot = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        tot += v[i];
    }
    for (int i = 0; i < n; i++) {
        if ((v[i] / tot) >= limit) cnt++;
    }
    cout << (cnt >= m ? "Yes" : "No") << "\n";

    return 0;
}


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

# 双対考える
# A1<=B1, A2<= min(B1,B2), A3<=min(B2,B3) ...
A = [B[0]]

for i in range(N-1):
    if i+1 != len(B):
        A.extend([min(B[i],B[i+1])])
    else:
        A.extend([B[i]])


print(sum(A))

Measured memory_bytes: 61936
#include <iostream>

using namespace std;
typedef long long ll;

ll a, b, c, k;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> a >> b >> c >> k;
	ll res = a-b;
	if (k%2 == 0) cout << res << "\n";
	else cout << -res << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define hello777 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <string>
#define pie 3.14159265358979323846
constexpr int MOD = 1e9+7;
const int MAX= 1e5+5;
using namespace std;


//ll gcd(int a, int b)
//{ 
//    if (a == 0) 
//        return b;  
//    return gcd(b % a, a);  
// } 
// 
//ll lcm(int a, int b)  
// {  
//    return a/gcd(a, b) *b;  
// }
//  
//int prime(int n)
//{
//	rep(i,2,n+1)
//	{
//		if(n%i==0)return i;
//	}
//	
//vector<unordered_set<int> > prime_factors(MAX,unordered_set<int>());
//int primes[MAX];
//int prefix[MAX][6];
//void sieve(){
//    //primes i stores the largest prime factor of a number....
//    for(int i=2;i<MAX;++i){
//        if(primes[i]!=0){
//            continue;
//        }
//        primes[i] = i;
//        for(int j=2*i;j<MAX;j+=i){
//            primes[j] = i;
//        }
//    }
//    
//    for(int i=2;i<MAX;++i){
//        int current = i;
//        
//        while(current!=1){
//            prime_factors[i].insert(primes[current]);
//            current = current/primes[current];
//        }
//    }
//    
//    for(int i=1;i<MAX;++i){
//        for(int k=1;k<=5;++k){
//            prefix[i][k] = prefix[i-1][k] + (prime_factors[i].size()==k);
//        }
//    }
//    
//}
void solve() 
{
	ll n,ans=0;cin>>n;
	vector<int> a(n);
	rep(i,0,n)
	{
		cin>>a[i];
	}
	sort(a.begin(),a.end(),greater<int>());
	rep(i,0,n)
	{
		ans+=a[i/2];
	}
	ans-=a[0];
	cout<<ans<<endl;
}



int main()
{
	hello777;

	int q=1;
	
//    cin>>q;
    while(q--)
    {   
      solve();
    }
}

 

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int main() {  
  int A, B;
  cin >> A >> B;
  int i = 0;
  while(i < 14*A){
    int a = i*0.08;
    int b = i*0.1;
    if(a == A && b == B){
      cout << i << endl;
      return 0;
    }
    i++;
  }
  cout << "-1" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt();
        int hap = 0;
        int fives = n % 500;
        int num500 =n  / 500;
        int num5 =  fives / 5;
        hap += (num500 * 1000) + (num5 * 5);
        System.out.println(hap);
    }
}


Measured memory_bytes: 21844
package main

import (
	"fmt"
	"sort"
)

func main() {
	var K int
	a := make([]int, 3)
	fmt.Scan(&a[0], &a[1], &a[2])
	fmt.Scan(&K)
	sort.Ints(a)
	for i := 0; i < K; i++ {
		a[2] = a[2] * 2
	}
	fmt.Println(a[0] + a[1] + a[2])
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}

ll r, s, p;

inline int fun(char c) {
    return c == 'r' ? 0 : c == 's' ? 1 : 2;
}

inline int rfun(char c) {
    return c == 'r' ?  2 : c == 's' ? 0: 1;
}

inline void f(vi & v, string const& t, int i, int k, ll & ans) {
    char c = t[i];
    int d = fun(c);
    if (i < k || v[i-k] != d) {
        ans += c == 'r' ? p : c == 's' ? r : s;
        v[i] = d;
    }
    else {
        if (i + k < (int)(t.size()) && t[i+k] != c) {
            v[i] = rfun(t[i+k]);
        }
        else
            v[i] = 5;
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n, k;
    cin >> n >> k;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll ans = 0;
    vi v(n+5, -1);
    rep(i, 0, (int)(t.size())) {
        f(v, t, i, k, ans);
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 848
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    long[] c = new long[n];
    long[] s = new long[n];
    long[] f = new long[n];

    for (int i = 0; i < n - 1; i++) {
      c[i] = sc.nextInt();
      s[i] = sc.nextInt();
      f[i] = sc.nextInt();
    }

    for (int start = 0; start < n; start++) {
      long t = 0;
      for (int i = start; i < n - 1; i++) {
        // ceil
        long k = Math.max(((t - s[i]) + (f[i] - 1)) / f[i], 0);
        t = s[i] + k * f[i] + c[i];
      }
      os.println(t);
    }
  }
}


Measured memory_bytes: 25980
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let ab: Vec<(i64, i64)> = (0..n).map(|_| (read::<i64>(), read::<i64>())).collect();

    let mut d: i64 = 0;
    for i in ab.iter().rev() {
        let a = i.0;
        let b = i.1;
        if (a + d) % b != 0 {
            d = ((a + d) / b + 1) * b - a;
        }
    }
    println!("{}", d);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
int main() {
	int m, d;
	cin >> m >> d;
	long long ans = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= d; j++) {
			if ((j % 10) * (j / 10) == i && j % 10 >= 2 && j / 10 >= 2) {
				//cout << i << ' ' << j << '\n';
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1000];
int b,c;

int main(){
    cin>>b>>c;
    for(int u=1;u<b+1;u++){
        cin>>a[u];
    }


    for(int f=1;f<c+1;f++){
        for(int i=1;i<b;i++){
            if(a[i]%f>a[i+1]%f){
                int e=a[i];
                a[i]=a[i+1];
                a[i+1]=e;
            }

        }
    }

    for(int op=1;op<b+1;op++){
        cout<<a[op]<<endl;
    }
    
}

Measured memory_bytes: 3084
#include <iostream>
using namespace std;
int main(){
  int flg=0;
  char str[100];
  cin >> str;
  for(int i=0; i<100; i++){
    if(i%2==0 && str[i]=='L'){
      flg=1;
      break;
    }else if(i%2==1 && str[i]=='R'){
      flg=1;
      break;
    }
  }
    if(flg){ cout << "No";}
    else{ cout << "Yes";}
    return 0;
}

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

int main(int argc, char **argv)
{
	int n, i, j, x, y, tmp, t = 1;
	int *array = (int *)calloc(100, sizeof(int));

	while(1){
		scanf("%d", &n);
		if(n == 0){
			break;
		}
		
		x = j = array[0] = 1;
		tmp = 2;
		y = 0;
		i = -1;
		while(tmp <= n*n){
			array[y*n+x] = tmp++;
			x += i;
			y += j;
			
			if(x < 0 || y < 0 || y >= n || x >= n){
				x -= i;
				y -= j;
				i = -i;
				j = -j;
				
				if((y == 0 || y == n-1)&& x < n-1){
					x++;
				} else {
					y++;
				}
			}
		}
		
		printf("Case %d:\n", t++);
		for(i = 0; i < n; i++){
			for(j = 0; j < n; j++){
				printf("%3d", array[i*n+j]);
			}
			printf("\n");
		}		
	}
	
	return 0;
}

Measured memory_bytes: 0
import math
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((math.atan2(x, y), x, y))

X = sorted(X) * 2
m = 0
for i in range(N):
    sx = sy = 0
    for j in range(i, i + N):
        sx += X[j][1]; sy += X[j][2]
        d = sx ** 2 + sy ** 2
        m = max(m, d)

print(m**0.5)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,m,i,j,pl[100005],pr[100005],sl[100005],sr[100005],ans;
struct rg{
	int l,r;
}a[100005];
bool cmp(rg x,rg y)
{
	return x.l<y.l;
}
int main(){
	cin>>n;
	rep(i,n){
		cin>>a[i].l>>a[i].r;
	}
	sort(a+1,a+n+1,cmp);
	pl[1]=a[1].l;pr[1]=a[1].r;
	for(i=2;i<=n;i++){
		pl[i]=max(a[i].l,pl[i-1]);
		pr[i]=min(a[i].r,pr[i-1]);
	}
	sl[n]=a[n].l;sr[n]=a[n].r;
	for(i=n-1;i;i--){
		sl[i]=max(a[i].l,sl[i+1]);
		sr[i]=min(a[i].r,sr[i+1]);
	}
	pr[0]=sr[n+1]=0x3f3f3f3f;
	rep(i,n){
		ans=max(ans,(a[i].r-a[i].l+1)+max(0,min(pr[i-1],sr[i+1])-max(pl[i-1],sl[i+1])+1));
	}
	rep(i,n-1){
		ans=max(ans,max(0,pr[i]-pl[i]+1)+max(0,sr[i+1]-sl[i+1]+1));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5996
/*
必要な文字の種類は最大でもN.最小で1(文字列の長さが狭義短調増加のとき).
文字の種類数を決めたときに辞書順が成り立つように文字列群を構成できるか
をO(N)で判定することが出来れば、log(N)*O(N)の二分探索で解けるはず.
*/
#include<iostream>
#include<map>
#include<vector>
using namespace std;

int n;
vector<int> v;

bool check(int mid){
    map<int,int> len;
    //int from = n+1;

    for(int i = 1; i < n; i++){
        if(v[i-1] < v[i])   continue;

        int b = v[i];
        // 最悪O(N)
        while(len.count(b) && len[b] == mid-1 && b >= 1)    b--;
        if(b == 0)  return false;

        len[b]++;
        
        // TLEしそう O(log(len.size()) + O(len.end()-it))
        auto it = len.upper_bound(b);
        if(it != len.end())   len.erase(it, len.end());
    }

    return true;
}

int main(){
    cin >> n;
    
    v.resize(n);
    for(int i = 0; i < n; i++)  cin >> v[i];

    bool asc = true;
    for(int i = 1; i < n; i++)  asc &= v[i-1] < v[i];
    if(asc){
        cout << 1 << endl;
        return 0;
    }

    // (l, r]
    int l = 1, r = n;
    while(r-l > 1){
        int mid = (l+r)/2;
        if(check(mid))  r = mid;
        else            l = mid+1;
    }

    if(l != 1 && check(l))  cout << l << endl;
    else                    cout << r << endl;

    return 0;
}

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

using namespace std;

int main(){
	long long ans, l, r, i;

	scanf("%lld%lld", &l, &r);

	ans = 0;

	for (i = l; i <= r; i *= 2){
		ans++;
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a, b, c;
    scanf("%d%d%d",&a,&b,&c);
    int f = 0;
    if(a == b && b != c)
        f = 1;
    if(b == c && c != a)
        f = 1;
    if(a == c && c != b)
        f = 1;
    if(f) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<bitset>
using namespace std;

typedef long long int ll;
const int N_MAX = 52;
const int M_MAX = 22;

vector<pair<int, int>> edge[N_MAX];
vector<pair<int, int>> Con;
ll root[M_MAX];

void dfs(int v, int p, int u, bool& ok, int k){
    if (v == u){
        ok = true;
        return;
    }
    for(auto e : edge[v]){
        if (e.first == p) continue;
        root[k] = root[k] | (ll)1 << e.second;
        dfs(e.first, v, u, ok, k);
        if (ok)return;
        root[k] = root[k] & ~((ll)1 << e.second);
    }
}

int main(){
    int n, m;
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        edge[a].emplace_back(b, i);
        edge[b].emplace_back(a, i);
    }
    cin >> m;
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        Con.emplace_back(u, v);
    }
    memset(root, 0, sizeof(root));
    for(int i = 0; i < m; i++){
        bool ok = false;
        dfs(Con[i].first, -1, Con[i].second, ok, i);
    }
    ll pat = 0;
    for(int S = 0; S != 1 << m; S++){
        ll ALL = 0;
        int num = 0;
        for(int i = 0; i < m; i++){
            if (S & 1 << i){
                num++;
                ALL |= root[i];
            }
        }
        ll tot = 0;
        while(ALL > 0){
            if (ALL & 1)tot++;
            ALL >>= 1;
        }
        ll Snum = (ll)1 << (n-1-tot);
        if (num % 2 == 0)pat += Snum;
        else pat -= Snum;
    }
    cout << pat << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "string"

using namespace std;

int main() {
	string s[3];
	for (int i = 0; i < 3; i++) {
		cin >> s[i];
	}
	bool flag = false;
	if (s[0][s[0].size() - 1] == s[1][0] && s[1][s[1].size() - 1] == s[2][0]) {
		flag = true;
	}

	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256