akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;

fn partition_point<Pred>(s: &[i32], pred: Pred) -> usize
        where Pred: Fn(i32) -> bool {
    let mut left = 0;
    let mut right = s.len();
    while right - left > 0 {
        let mid = (left + right) / 2;
        if pred(s[mid]) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    right
}

fn solve(_n: usize, a: &mut [i32], b: &mut [i32], c: &mut [i32]) -> usize {
    a.sort();
    b.sort();
    c.sort();
    b.iter()
        .map(|&x| partition_point(a, |y| y < x) * (c.len() - partition_point(c, |y| y <= x)))
        .sum::<usize>()
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut a = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect::<Vec<_>>();
    let mut b = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect::<Vec<_>>();
    let mut c = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect::<Vec<_>>();
    let r = solve(n, &mut a, &mut b, &mut c);
    println!("{}", r);
}


Measured memory_bytes: 6552
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for i in range(0, N - 1):
    if t[i + 1] - t[i] >= T:
        ans += T
    else:
        ans += t[i + 1] - t[i]
ans += T

print(ans)


Measured memory_bytes: 25196
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    int a[200005], b[200005];
    scanf("%d", &n);
    int i;
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        b[i] = a[i];
    }
    sort(b, b + n);
    for (i = 0; i < n; i++)
    {
        if (b[n - 1] != a[i])
            printf("%d\n", b[n - 1]);
        else
            printf("%d\n", b[n - 2]);
    }
    return 0;
}

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

bool cmp(const pair<int,int> a, const pair<int,int> b) {
    return a.first < b.first;
}

int main() {
    int n,m;
    ll x,y,cans;
    ll money;
    vector< pair<ll,ll> > vec;

    cin >> n >> m;
    for (int i=0; i<n; i++) {
        cin >> x >> y;
        vec.push_back(make_pair(x,y));
    }
    sort(vec.begin(),vec.end(),cmp);
    
    money=0; cans=0;
    for (int i=0; i<n; i++) {
        cans += vec[i].second;
        if (cans <= m)
            money += vec[i].second * vec[i].first;
        else {
            cans -= vec[i].second;
            money += (m-cans) * vec[i].first;
            break;
        }
    }
    cout << money << '\n';
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
int main(){ 
  int n, u, v;
  cin >> n >> u >> v;
  u--; v--;
  vector<vector<int>> g(n);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  auto dijkstra = [&](int s) {
    vector<int> d(n,INF);
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(make_pair(0, s));
    d[s] = 0;

    while (!que.empty()) {
      auto p = que.top(); que.pop();
      int u = p.second;
      if (d[u] < p.first) continue;
      for (auto v : g[u]) {
        if (d[v] > d[u] + 1) {
          d[v] = d[u] + 1;
          que.push(make_pair(d[v], v));
        }
      }
    }
    return d;
  };

  auto du = dijkstra(u);
  auto dv = dijkstra(v);
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (dv[i] < du[i]) continue;
    res = max(res, dv[i] - 1);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 7052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,S;
  cin >> K >> S;
  int c=0;
  for(int x=0; x<=K; x++){
  	for(int y=0; y<=K; y++){
    	if(x+y+K>=S && x+y<=S)c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

//////////////////////////////////////

//////////////////////////////////////

int main() {
    
    string S;
    ll K;
    cin >> S >> K;
    
    ll cnt = 0;
    char b = S[0];
    ll n = S.length();
    for (int i = 1; i < n; i++) {
        if (b == S[i]) {
            cnt += 1;
            b = '!';
        } else {
            b = S[i];
        }
    }
    bool f1 = false;
    if (b == S[0]) {
        f1 = true;
    }
    ll cnt2 = 0;
    for (int i = 0; i < n; i++) {
        if (b == S[i]) {
            cnt2 += 1;
            b = '!';
        } else {
            b = S[i];
        }
    }
    bool f2 = false;
    if (b == S[0]) {
        f2 = true;
    }
    //cerr << cnt << endl;
    //cerr << cnt2 << endl;
    ll ans = 0;
    if (f1 && f2) {
        ans = cnt + cnt2*(K-1);
    } else if (f1 && !f2) {
        ans = (cnt + cnt2)*(K/2) + cnt*(K%2);
    } else if (!f1 && f2) {
        ans = cnt + (2*cnt2)*((K-1)/2);
    } else {
        ans = (cnt + cnt2)*(K/2) + cnt*(K%2);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
s = str(input())
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
tmp = 0

for i in range(len(s)):
    if i%2==0 and s[i] in odd:
        tmp += 1
    elif i%2!=0 and s[i] in even:
        tmp += 1

print('Yes' if tmp==len(s) else 'No')

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

using namespace std;

int main(){

	long a,b,c,d,e;
    cin >> a >> b >> c >> d >> e ;
    if(a==0){
        cout << 1 << endl; 
    }else if(b==0){
        cout << 2 << endl; 
    }else if(c==0){
        cout << 3 << endl; 
    }else if(d==0){
        cout << 4 << endl; 
    }else if(e==0){
        cout << 5 << endl; 
    }
}


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


int main() {
	int x, y;
	int s;
	int cnt = 1;
	int val1, val2;
	while (true) {
		int max = 0;
		cin >> x >> y >> s;
		if (x == 0 && y == 0 && s == 0) break;

		for (int i = 1; i < 1000; i++) {
			for (int j = 1; j < 1000; j++) {
				val1 = i*(100 + x) / 100;
				val2 = j*(100 + x) / 100;
				if (val1 + val2 == s) {
					val1 = i*(100 + y) / 100;
					val2 = j*(100 + y) / 100;
					if (max < val1 + val2) max = val1 + val2;
				}
			}
		}
		cout << max << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: u64,
        b: u64,
        x: [u64;n]
    }
    let mut res = 0;
    for i in 0..n-1 {
        let d = x[i+1] - x[i];
        res += std::cmp::min(d*a, b);
    }
    println!("{}", res);
}


Measured memory_bytes: 6396
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        sc.close();

        // 主処理
        boolean judge = a.equals(b);
        String result = judge ? "H" : "D";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = in.readLine().split(" ");
      int[] arr = new int[lines.length];
      int k=0;
      for (String s : lines) {
        arr[k++] = Integer.parseInt(s); 
      }
      Arrays.sort(arr);
      int step=0;
      if(arr[2] - arr[1] > 10) {
        for(; arr[1]+10 < arr[2]; step++) {
          arr[1] += 2;
        }
      }
      if(arr[1] - arr[0] > 10) {
        for(; arr[0]+10 < arr[1]; step++) {
          arr[0] += 2;
        }
      }

      Tuple3 t = new Tuple3(arr[0], arr[1], arr[2]);
      t.step = step;

      bfs(t);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private void bfs(Tuple3 t) {
    Deque<Tuple3> que = new ArrayDeque<>();

    que.offer(t);

    Tuple3 cur;
    while(!que.isEmpty()) {
      cur = que.poll();

      if(cur.isEq()) {
        System.out.println(cur.step);
        return;
      }

      if(cur.e[0] < cur.e[1] && cur.e[0] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0]+2, cur.e[1], cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else if(cur.e[1] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0], cur.e[1]+2, cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else {
        que.offer(new Tuple3(cur.e[0], cur.e[1], cur.e[2]+2));
        que.peekLast().step = cur.step + 1;
      }

      if(cur.e[0] < cur.e[2] && cur.e[1] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0]+1, cur.e[1]+1, cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else if(cur.e[1] < cur.e[0] && cur.e[2] < cur.e[0]) {
        que.offer(new Tuple3(cur.e[0], cur.e[1]+1, cur.e[2]+1));
        que.peekLast().step = cur.step + 1;
      } else {
        que.offer(new Tuple3(cur.e[0]+1, cur.e[1], cur.e[2]+1));
        que.peekLast().step = cur.step + 1;
      }
      
    }
  }

  class Tuple3 {
    int[] e;
    int state;
    int step;

    public Tuple3(int a, int b, int c) {
      e = new int[3];
      e[0] = a;
      e[1] = b;
      e[2] = c;
      state = (a*10000) + (b*100) + c;
      step = 0;
    }

    @Override
    public boolean equals(Object obj) {
      if(obj == this) return true;
      if(obj == null) return false;
      if(!(obj instanceof Tuple3)) return false;

      Tuple3 ref = (Tuple3) obj;

      return this.state == ref.state ? true : false;
    }

    public boolean isEq() {
      return (e[0] == e[1]) && (e[1] == e[2]);
    }
  }
}

Measured memory_bytes: 29268
/*
AOJ: Rummy
https://onlinejudge.u-aizu.ac.jp/problems/2102
着席位置 教卓から見て左中央
*/

#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
using namespace std;

const double pi = acos(-1);

#define nyan cout<<"(=^•ω•^=)"<<endl;
#define int long long

pair<int, char> card[10];
//第一要素がランク，第二要素がスート

bool setting(int a, int b, int c){
    if(a==b&&b==c)return true;
    if(b==a+1&&c==b+1)return true;
    return false;
}

signed main(){
    int Query;cin>>Query;
    for(int q=0;q<Query;q++){
        for(int i=0;i<9;i++)cin>>card[i].first;
        for(int i=0;i<9;i++)cin>>card[i].second;
        sort(card,card+9);
        bool ans=false;
        do{
            bool flag=false;
            for(int i=0;i<3;i++){
                if(card[3*i].second!=card[3*i+1].second)flag=true;
                if(card[3*i+1].second!=card[3*i+2].second)flag=true;
                if(!setting(card[3*i].first,card[3*i+1].first,card[3*i+2].first))flag=true;
            }
            if(flag)continue;
            ans=true;
        }while(next_permutation(card,card+9));
        cout<<(ans?"1":"0")<<endl;
    }
    return 0;
}

/* 同じ方法だと麻雀の判定は厳しそう (14! = 87,178,291,200) */
/* sortしてからwhile(next_permutation)をすることで */
/* 全部の順列をまわることができるというのは新しい発見だった！ */


Measured memory_bytes: 3084
#include <iostream>
#include <string>
using namespace std;
void a()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (b / a >= c)
    cout << c;
  else
  {
    cout << b / a;
  }
}
void b()
{
  int a, b, k;
  cin >> a >> b >> k;
  int itr = 0;
  int ans = a;
  if (b < a)
    ans = b;
  ans++;
  while (itr != k)
  {
    ans--;
    if (a % ans == 0 && b % ans == 0)
      itr++;
  }
  cout << ans;
}
void c()
{
  string a;
  cin >> a;
  int p = 0;
  int q = 0;
  for (int i = 0; i < a.size(); i++)
  {
    if (a[i] == '0')
      p++;
    else
      q++;
  }
  int ans = 2 * p;
  if (q < p)
    ans = 2 * q;
  cout << ans;
}
int main(void)
{
  //b();
  //a();
  c();
}


Measured memory_bytes: 512
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	// 入力
	int N;
	cin >> N;
	
	set<int> mp;

	ll ans = 0;
	REP(i, N) {
		int a;
		cin >> a;

		if (mp.find(a) == mp.end()) {
			mp.insert(a);
		} else {
			mp.erase(a);
		}
	}

	cout << mp.size() << endl;
	return 0;
}


Measured memory_bytes: 4864
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
inf = float("inf")

n_item, w_volume = map(int, input().split())
weight, value = [], []
for _ in range(n_item):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)
# print(n_item, w_volume, weight, value)

# dp[i + 1][w]: i番目までの商品から重さがwを超えないよういくつか選んだときの価値の最大値
# 商品iを選ぶことができるとき (w - weight[i] >= 0 のとき)
# dp[i + 1][w] = max(dp[i + 1][w], dp[i][w - weight[i]] + value[i])
# 商品iを選ぶことができないとき
# dp[i + 1][w] = max(dp[i + 1][w], dp[i][w])

dp = [[0 for w in range(w_volume + 1)] for i in range(n_item + 1)]

for i in range(n_item):
    for w in range(w_volume + 1):
        if w - weight[i] >= 0:
            dp[i + 1][w] = max(dp[i + 1][w], dp[i][w - weight[i]] + value[i])
        dp[i + 1][w] = max(dp[i + 1][w], dp[i][w])

print(dp[n_item][w_volume])


Measured memory_bytes: 171016
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
#define endl '\n'

ll CountGreater(ll x, vector<ll>& A, bool is_sum, vector<ll>& P) {
  int n = A.size();
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    int l = -1, r = n;
    while (r-l > 1) {
      ll m = l + (r-l)/2;
      if (A[m]+A[i] > x) {
        l = m;
      } else {
        r = m;
      }
    }
    if (is_sum) {
      ans += P[r] + r*A[i];
    } else {
      ans += r;
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n,k;
  cin >> n >> k;
  vector<ll> A(n);
  for (auto& _a : A) cin >> _a;
  sort(A.rbegin(),A.rend());
  vector<ll> P(n+1);
  for (int i = 0; i < n; ++i) P[i+1] = P[i]+A[i];
  ll l = -1, r = 1e18;
  while (r-l > 1) {
    ll mid = l + (r-l)/2;
    ll cnt = CountGreater(mid,A,false,P);

    if (cnt < k) {
      r = mid;
    } else {
      l = mid;
    }
  }
  ll c2 = CountGreater(r, A, false, P);
  ll ans = CountGreater(r, A, true, P);
  ans += (k-c2)*r;
  cout << ans << endl;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef pair<ll,pl> pp;
const ll MOD = 1e9+7;
const ll MAX = 1e18*2;

ll dp[111][111111];

int main(){
  ll n,k;
  cin>>n>>k;
  ll w[111111],v[111111];
  for(int i=0;i<n;i++)cin>>w[i]>>v[i];
  fill_n(*dp,111*111111,MAX);
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<111111;j++){
	 if(dp[i][j]==MAX)continue;
	 dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
	 dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
    }
  }
  ll ans=0;
  for(int i=0;i<111111;i++)
    if(dp[n][i]<=k)ans=i;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 96640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

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







int main(){
 
int n,m;
map <string,int> cnt;
cin >> n;
string s[n+1],t;

rep (i,n){
  cin >> s[i];
  cnt[s[i]]++;
}

cin >> m;
rep (i,m){
  cin >> t;
  cnt[t]--;
}

int ma = 0;

for (auto x : cnt){
  ma = max(ma,x.second);
}
cout << ma << endl;

}


Measured memory_bytes: 256
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readUint() = readString() |> uint64
let readIntArray() = readStringArray() |> Array.map(fun x -> int x)
let char2String(value) = List.ofSeq value |> List.toArray |> System.String

let n = readUint() |> decimal
let minute = List.min [for _ in [1..5] -> readUint() |> decimal]
ceil (n / minute)
|> uint64 
|> fun x -> x + 4UL
|> printfn "%d"

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

using namespace std;

using int64 = long long;

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

  int n, k;
  cin >> n >> k;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) cin >> xs[i];

  vector<int> dp(k + 1);
  dp[0] = -1;
  for (int i = 1; i <= k; i++) {
    bool is_win = false;
    for (int x : xs) {
      if (i - x >= 0 && dp[i - x] < 0) {
        is_win = true;
      }
    }
    dp[i] = is_win ? 1 : -1;
  }
  cout << ((dp[k] > 0) ? "First" : "Second") << endl;
}


Measured memory_bytes: 640
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    int n;
    cin>>n;

    ll arr[n][3];

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


    for(int i=1; i<n; i++){
        arr[i][0] += max(arr[i-1][1], arr[i-1][2]);
        arr[i][1] += max(arr[i-1][0], arr[i-1][2]);
        arr[i][2] += max(arr[i-1][0], arr[i-1][1]);
    }

    cout<<max(arr[n-1][0], max(arr[n-1][1], arr[n-1][2]))<<endl;

    return 0;
}


Measured memory_bytes: 5944
import java.util.*;

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

		int S = in.nextInt();
		int h = S / 60 / 60;
		int m = (S / 60) % 60;
		int s = S % 60;

		System.out.println(String.format("%d:%d:%d", h, m, s));
	}
}

Measured memory_bytes: 17168
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
#define rep(i,n) for(int i=0;i<(n);i++)
 
 
int main(){
  string t;
  cin>>t;
  rep(i,t.size()){
    if(t[i]=='?')t[i]='D';
  }
  cout<<t<<endl;
}

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

/* Segment Tree -----------*/
template <typename M>
class SegmentTree {
    using F = std::function< M(M, M) >;
private:
    int n;
    F func;
    M M_init;
    std::vector<M> t;
public:
    // constructor
    SegmentTree(int &n, F func, const M &M_init): n(n), func(func), M_init(M_init) { t.assign(2*n, M_init); }
    SegmentTree(std::vector<M> &vec, F func, const M &M_init): n(vec.size()), func(func), M_init(M_init) {
        t.assign(2*vec.size(), M_init);
        for(int i = 0; i < vec.size(); ++i) t[i+vec.size()] = vec[i];
    }

    void build() {  // build segment tree
        for(int i = n-1; i > 1; --i) t[i] = func(t[i<<1], t[i<<1|1]);
    }
    void modify(int p, M val) {  // update value at position p
        for(t[p += n] = val; p > 1; p >>= 1) t[p>>1] = func(t[p], t[p^1]);
    }
    M query(int l, int r) {  // reply to query [l, r)
        M resl = M_init, resr = M_init;
        for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if(l & 1) resl = func(resl, t[l++]);
            if(r & 1) resr = func(t[--r], resr);
        }
        return func(resl, resr);
    }
    M operator[](const int &k) const {return t[k+n];}  // mustn't use to input
};

long long GCD(long long a, long long b){
    return (b ? GCD(b, a%b) : a);
}

signed main(){
    using namespace std;

    // input
    int n; cin >> n;
    vector<long long> aa(n);
    for (int i = 0; i < n; ++i) cin >> aa[i];

    // build
    SegmentTree<long long> a(aa, [](long long p, long long q){ return GCD(p,q);}, 0LL);
    a.build();

    // solve
    long long ans = -1, pp;

    for(int i = 0; i < n; ++i) {
        if(i==0) pp = a.query(1, n);
        else if(i==n-1) pp =a.query(0, n-1);
        else pp = GCD(a.query(0,i), a.query(i+1, n));
        ans = max(ans, pp);
    }
    // output
    cout << ans << '\n';
}

Measured memory_bytes: 2560
main(){int n,a,b,c,x,i,t,y[101];for(;scanf("%d%d%d%d%d",&n,&a,&b,&c,&x),n;printf("%d\n",t>10000?-1:t)){for(i=0;i<n;)scanf("%d",y+i++);for(t=i=0;t<10001&i<n;x=(a*x+b)%c,t++)if(y[i]==x&&++i==n)break;}return 0;}

Measured memory_bytes: 0
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System;

class Prog
{
    public static void Main(string[] args)
    {
        new Prog().Solve();
    }

    public void Solve()
    {
        int[] nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        N = nk[0];K = nk[1];
        hs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        int[] dp = new int[N];
        dp[0] = 0;

        for (int i = 1; i < N; i++)
        {
            List<int> candidates = new List<int>();

            for (int j = Math.Max(0,i - K); j < i;j++){
                candidates.Add(dp[j] + Math.Abs(hs[i] - hs[j]));
            }

            dp[i] = candidates.Min();
        }

        Console.WriteLine(dp[N - 1]);

        Console.ReadKey();
    }

    int N, K;
    int[] hs;
}

public struct Vector2
{
    public Vector2(double x, double y)
    {
        this.@this = new double[] { x, y };
    }


    public double[] @this;

    public double x
    {
        get
        {
            return @this[0];
        }
        set
        {
            @this[0] = value;
        }
    }

    public double y
    {
        get
        {
            return @this[1];
        }
        set
        {
            @this[1] = value;
        }
    }

    public double magnitude { get { return Math.Pow(sqrMagnitude, 1 / 2); } }

    public double sqrMagnitude { get { return Math.Pow(x, 2) + Math.Pow(y, 2); } }

    public Vector2 normalized { get { return this * (1 / this.magnitude); } }

    public static Vector2 operator +(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x + b.x, a.y + b.y);
    }

    public static Vector2 operator -(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x - b.x, a.y - b.y);
    }

    public static Vector2 operator *(Vector2 a, double b)
    {
        return new Vector2(a.x * b, a.y * b);
    }


    public static Vector2 operator /(Vector2 a, double b)
    {
        if (b == 0)
        {
            throw new DivideByZeroException();
        }
        else return new Vector2(a.x / b, a.y / b);
    }

    public bool Equals(Vector2 other)
    {
        return (@this[0] == other.@this[0] && @this[1] == other.@this[1]);
    }

}

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

int main() {
  string S;
  cin >> S;
  char c = S.at(0);
  bool can = true;
  if (c == S.at(1) && c == S.at(2)) can = false;
  
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

const int MAXN = 11;

const int di[12] = {-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
const int dj[12] = {2,2,2,1,0,-1,-2,-2,-2,-1,0,1};
const int H = 10;
const int W = 10;
int si, sj;
int n;
int ti[MAXN], tj[MAXN];

bool dfs(int step, int pi, int pj) {
  if(step == n) return true;
  for(int k = 0; k < 12; ++k) {
    int ni = pi + di[k];
    int nj = pj + dj[k];
    if(ni < 0 || ni >= H) continue;
    if(nj < 0 || nj >= W) continue;
    if(max(abs(ti[step]-ni),abs(tj[step]-nj)) >= 2) continue;
    if(dfs(step+1, ni, nj)) return true;
  }
  return false;
}

int main() {
  while(cin >> sj >> si && (si|sj)) {
    cin >> n;
    for(int i = 0; i < n; ++i) {
      cin >> tj[i] >> ti[i];
    }
    if(dfs(0, si, sj)) {
      cout << "OK" << endl;
    } else {
      cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6+10;
int n,m=1003;
int b[1010];
int deg[maxn];
int ct[1010];
vector<int> a[maxn],all;
bool vis[maxn],d[maxn],ok;
void topsort(int nod){
    vis[nod]=true;
    d[nod]=true;
    for(int i:a[nod]){
        if(!vis[i]){
            topsort(i);
        }
        else if(d[i]){
            ok=false;
        }
    }
    d[nod]=false;
//    topo.push_back(nod);
}


int main(){
    int x,y;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<n;j++){
            scanf("%d",&b[j]);
            x=i,y=b[j];
            if(x>y)swap(x,y);
            b[j]=(n+1)*x + y;
            all.push_back(b[j]);
        }
        for(int j=1;j+1<n;j++){
            a[b[j]].push_back(b[j+1]);
            deg[b[j+1]]++;
        }
    }
    vector<int> cur;
    for(int i=1;i<maxn;i++){
        if(deg[i]==0){
            cur.push_back(i);
        }
    }
    ok=true;
    for(int i:all)
    if(!vis[i]){
        topsort(i);
        if(!ok)return !printf("-1");
    }
    int ans=0;
    while(!cur.empty()){
        ans++;
        vector<int> nxt;
        for(int i:cur){
            for(int j:a[i]){
                deg[j]--;
                if(deg[j]==0)
                    nxt.push_back(j);
            }
        }
        cur=nxt;
    }
    printf("%d\n",ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 82796
import math

def getN():
    return int(input())

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

def solve(n):
    cnt = 0
    while(True):
        n = math.ceil(n / 3)
        cnt += 1
        if n == 1:
            return cnt

n = getN()
print(solve(n))


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

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];
#define vvint(v, w, n) vector<int> v(n); vector<int> w(n); REP(i,n) cin >> v[i] >> w[i];
#define vlint(v, n) vector<ll int> v(n); REP(i,n) cin >> v[i];
#define vdouble(v, n) vector<double> v(n); REP(i,n) cin >> v[i];
#define vvdoube(v, n1, n2) vector<vector<double> > v(n1, vector<double>(n2, 0)); REP(i,n1) REP(j,n1) cin >> v[i][j];
#define string(x) string x; cin >> x;
#define vstring(v, n) vector<string> v(n); REP(i,n){string a; std::cin >> a; v.push_back(a); }

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).begin(), (v).end(), std::greater<int>()
#define len(v) (v).length()
#define FIND(s, n) (s.find(n) != s.end())
#define SORT(a) sort(all(a))

static const string abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
static const long long MOD = 1000000007;
static const double PI=3.1415926535897932;
static const int INF = 0x3f3f3f3f;
static const int INFTY = (1 << 29);
static const long long LINFTY = (1LL << 32);

static const int dy4[]={0, 0, 1, -1};
static const int dx4[]={1, -1, 0, 0};
static const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
static const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};


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

  int A, B;
  cin >> A >> B;

  if(A==B) cout << "Draw" << endl;
  else if((A > B && B != 1) || A == 1) cout << "Alice" << endl;
  else if((A < B && A != 1) || B == 1) cout << "Bob" << endl;
  
  return 0;
}


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

int main(){
	while(1){
		int n,m,p;
		cin>>n>>m>>p;
		if(n==0&&m==0&&p==0) break;
		int count=0,ans,a;
		lp(i,n){
			cin>>a;
			count+=a;
			if(i==m-1) ans=a;
		}
		count*=100;
		count*=(100-p);
		if(ans!=0)cout<<count/ans/100<<endl;
		else cout<<"0"<<endl;
	}		
	return 0;
}


Measured memory_bytes: 2956
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  vector<int> a,b;
  cin>>n;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    a.push_back(x);
  }
  cin>>m;
  for(int i=0;i<m;i++){
    int x;
    cin>>x;
    b.push_back(x);
  }
  if(includes(a.begin(),a.end(),b.begin(),b.end())) cout<<"1"<<endl;
  else cout<<"0"<<endl;
  return 0;
}



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

public class ABC167B {
	private static void Main(string[] args) {
		var inputs = ReadIntsAsArray();
		var a = inputs[0];
		var b = inputs[1];
		var c = inputs[2];
		var k = inputs[3];

		var answer = Math.Min(a, k) - Math.Min(c, Math.Max(0, k - a - b));
		Console.WriteLine(answer);
	}

	private static int[] ReadIntsAsArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
}

Measured memory_bytes: 28260
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{

    class Program
    {
        public static (long m, long s)[,] dp;
        public static long mod;


        static void Main(string[] args)
        {
            checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                var vals = Console.ReadLine().Split(' ')
                    .Select(x => int.Parse(x)).ToList();


                var N = vals[0];

                var F = primehurui(N + 2);
                long ans = 0;
                
                for (int i = 1; i < N; i++)
                {
                    var pp = new Dictionary<int,int>();
                    var Nc = N-i;
                    while (F[Nc] != 0)
                    {
                        int a;
                        if (pp.TryGetValue(F[Nc],out  a))
                        {
                            pp[F[Nc]] = a + 1;
                        }
                        else
                        {
                            pp[F[Nc]] = 1;
                        }
                        Nc = Nc / F[Nc];
                    }
                    long subans = 1;
                    foreach(var pm in pp)
                    {
                        subans *= (pm.Value+1);
                    }
                    ans += subans;
                }
                

                Console.WriteLine(ans);

                Console.Out.Flush();
            }//cheked

        }
        static public int[] primehurui(int N)
        {
            var result = new int[N];
            for (int p = 2; p < N; p++)
            {
                if (result[p] != 0)
                {
                    continue;
                }
                for (int k = 0; p*k < N; k++)
                {
                    if(result[p*k]==0)
                    result[p * k] = p;
                }
            }
            return result;
        }
    }

}




Measured memory_bytes: 45380
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
ans = 0

for _ in range(N):
    x, u = readline().decode('utf8').split()
    if u == 'JPY':
        ans += int(x)
    else:
        ans += float(x) * 380000

print(ans)


Measured memory_bytes: 12508
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char x,y;
    cin >> x >> y;
    int a = x - 'a';
    int b = y - 'a';
    if(a>b){
        puts(">");
    }else if(a<b){
        puts("<");
    }else{
        puts("=");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, m, pre[N], suf[N];
char s[N];
vector <int> tp;
int calcu()
{
	int cur = 0, cnt = 0;
	while(cur<n)
	{
		int nxt = min(cur+m,n) - pre[min(cur+m,n)];
		if(nxt<=cur) return -1;
		cur = nxt;	
		cnt++;
	}
	return cnt;
}
void solve()
{
	int cur = n;
	while(cur>0)
	{
		int nxt = max(cur-m,0) + suf[max(cur-m,0)];
		tp.pb(nxt-cur);
		cur = nxt;
	}
	reverse(tp.begin(),tp.end());
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> m >> s;
 	pre[0] = 0;
 	for(int i=1;i<=n;i++)
 	{
 		if(s[i]=='0') pre[i] = 0;
 		else pre[i] = pre[i-1] + 1;
 	}
 	suf[n] = 0;
 	for(int i=n-1;i>=0;i--)
 	{
 		if(s[i]=='0') suf[i] = 0;
 		else suf[i] = suf[i+1] + 1;
 	}
 	int step = calcu();
 	if(step==-1) 
 		return cout << -1, 0;
 	solve();
 	for(int x : tp) cout << -x << ' ';
	return 0;
}


Measured memory_bytes: 1912
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
 
n = int(input())
A = [int(input()) for i in range(n)]
 
cnt = 0
G = [1]
for i in range(99):
    if n < 1 + 3*G[-1]:
        break
    G.append(1 + 3*G[-1])
m = len(G)
G.reverse()
for i in range(m):
    insertionSort(A, n, G[i])
 
print(m)
print(*G)
print(cnt)
print(*A, sep='\n')


Measured memory_bytes: 53288
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define int __int128
#define min(a,b) a<b?a:b 
template<class T>inline void read(T& x) {
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+(s&15);s=getchar();}
	x*=f;
}
inline void print(int x,char s) {
    if(x>=10) { print(x/10,'S'); }
    putchar(x%10+'0');
    if(s!='S') putchar(s);
}
inline void print(int x) {
    if(x>=10) { print(x/10); }
    putchar(x%10+'0');
}
template<class T>inline T fabs(T a) { return a>0?a:-a; }
char s[102];
int n,num[102],x,f[102][4];
inline int dfs(int k,int sx,int cnt) {
	if(k>n) return (cnt==x);
	if(cnt>x) return 0;
	if(!sx&&f[k][cnt]) return f[k][cnt];
	int mx,ans=0;
	if(sx) mx=num[k];
	else mx=9;
	rep(i,0,mx) {
		if(i==0) ans+=dfs(k+1,(sx&&(i==mx)),cnt);
		else ans+=dfs(k+1,(sx&&(i==mx)),cnt+1);
	}
	return f[k][cnt]=ans;
}
signed main() {
	scanf("%s",s+1);
	n=strlen(s+1);
	rep(i,1,n) num[i]=s[i]-'0';
	read(x);
	print(dfs(1,1,0));
}


Measured memory_bytes: 384
s = list(input())
a = len(s)

def f(b):
    count = 0
    for i in range(a):
        if s[i] != b:
            count += 1

        if b == '0':
            b = '1'
        else:
            b = '0'
    return count

print(min(f('0'), f('1')))

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    ll x, y, z;
}a[1055];
int n, m;
int i, j, k;
bool cmp(node a, node b){
    return 1ll*i*a.x + 1ll*j*a.y + 1ll*k*a.z > 1ll*i*b.x + 1ll*j*b.y + 1ll*k*b.z;
}
int main(){
    scanf("%d%d", &n, &m);
    ll ans = 0;
    for(i = 1; i <= n; ++i) scanf("%lld%lld%lld", &a[i].x, &a[i].y, &a[i].z);
    for(i = -1; i <= 1; i += 2){
        for(j = -1; j <= 1; j += 2){
            for(k = -1; k <= 1; k += 2){
                sort(a+1, a+n+1, cmp);
                ll tmp = 0;
                for(int _ = 1; _ <= m; ++_){
                    tmp += 1ll*i*a[_].x+ 1ll*j*a[_].y+ 1ll*k*a[_].z;
                }
                ans = max(ans, tmp);
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main(void){
    long long n,x,y,z;
    scanf("%lld",&n);
    long long a[n],b[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        b[i]=a[i];
    }
    sort(a,a+n);
    y=a[(n/2)-1];
    z=a[n/2];
    for(int i=0;i<n;i++){
        if(b[i]<=y){
            printf("%lld\n",z);
        }else{
            printf("%lld\n",y);
        }
    }
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
typedef long long ll;
#define rep(i, n) for (int (i) = 0; i < (n);++i)
using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    for (int i = A;i <= A * B;i += A){
        if (i % B == C) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    queue<int> v[n+1];
    rep(i,n){
        rep(j,n-1){
            int a;
            cin>>a;
            v[i+1].push(a);
        }
    }

    int day=0;
    vector<int> c(n+1);
    ll sum=0;
    ll suma = n*(n-1)/2;
    ll g=0;
    while(true) {

        day++;

        bool t=false;

        for (int i = 1; i < n + 1; i++) {
            g++;
            if(!v[i].empty()) {

                int aite = v[i].front();
                if (!v[aite].empty()&& c[aite] != day && c[i]!=day && v[aite].front() == i) {
                    v[aite].pop();
                    v[i].pop();
                    c[i] = day;
                    c[aite] = day;
                    sum++;
                    t = true;
                }
            }
        }


        if(t==false){break;}
        if(g>1000000){
            cout<<suma<<endl;
            return 0;
        }

    }

    for(int i=1;i<=n;i++){
        if(v[i].size()>=1){
            cout<<-1<<endl;
            return 0;
        }
    }
    day--;

    cout<<day<<endl;







    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;


int main(){
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    ll t,i,q,j,x,y,k,temp,temp2,z,l,tt,n,m,sum=0;
    cin >> n >> k;
    vector <ll> a(n);
    for(ll &x : a){
        cin >> x;
    }
    ll prod=1;
    for(i=k;i<n;i++){
        if(a[i]<=a[i-k]){
            cout << "No\n";
        }
        else cout << "Yes\n";
    }
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
#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 pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const int vx[]={1,0,-1,0}, vy[]={0,1,0,-1};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int main(){
	ll n,a,b,c,d; cin >> n >> a >> b >> c >> d;
	
	REP(i,0,n){
		if(c * (n - 1 - i) - d * i <= b - a){
			if(b - a <= (n - 1 - i) * d - c * i){
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	
	cout << "NO" << endl;
	return 0;
}


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

long Gcd(int a,int b){
    if(b == 0) return a;
    Gcd(b,a%b);
}

long Lcm(long m, long n)
{
	return m * n / Gcd(m,n); 
}

int main(){
    int a,b;
    cin >> a >> b;
    cout << Lcm(a,b) << endl;
    return 0;
}

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

#define int long long

int32_t main(){

      int n,k;
      cin>>n>>k;

      vector<pair<int,int>> v(n+1);
      for(int i=1;i<=n;i++){
         cin>>v[i].first>>v[i].second;
      }

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

      int dp[n+1][k+1];

      for(int i=0;i<=n;i++){
         for(int j=0;j<=k;j++){
            if(j==0||i==0)
               dp[i][j]=0;
            else if(j>=v[i].first)
               dp[i][j]=max(dp[i-1][j],v[i].second+dp[i-1][j-v[i].first]);
            else
               dp[i][j]=dp[i-1][j];
         }
      }

      cout<<dp[n][k];
   
}


Measured memory_bytes: 79104
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi
all=0
a.each do |aa|
  all=(all^aa)
end
ans=[]
a.each do |aa|
  ans<<(all^aa)
end
puts ans.join(" ")

Measured memory_bytes: 39560
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
    string input;
    const int alph_lim = 26;
 
    while (getline(cin, input, '\n')) {
        for (int i = 0; i < alph_lim; i++) {
            for (int j = 0; j < input.size(); j++) {
                if (islower(input[j])) {
                    input[j]++;
                    if (input[j] > 'z') 
                        input[j] -= alph_lim;
                }
            }
 
            if (input.find("the") != string::npos ||
                input.find("this") != string::npos ||
                input.find("that") != string::npos) {
                cout << input << endl;
                break;
            }
        }
    }
 
    return 0;
}

Measured memory_bytes: 1180
X = int(input())

if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
else:
    print(1)


Measured memory_bytes: 9172
s = input()

while True:
    s = s[:-1]
    if len(s) % 2 == 1:
        continue

    s1 = s[0:int(len(s) / 2)]
    s2 = s[int(len(s) / 2):]
    if s1 == s2:
        print(len(s))
        exit()


Measured memory_bytes: 38256
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int n;
vector<ll> a;
vector<ll> b;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    a.assign(n, 0);
    b.assign(n, 0);
    F0R(i, n) cin >> a[i];
    F0R(i, n) cin >> b[i];
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>> pq;
    ll res = 0;
    F0R(i, n)
    {
        if(b[i] > a[i]) pq.push({b[i], i});
        if(b[i] < a[i])
        {
            cout << "-1";
            return 0;
        }
    }
    while(!pq.empty())
    {
        ll cur = pq.top().s;
        pq.pop();
        ll adj = b[(cur - 1 + n)%n] + b[(cur + 1)%n];
        ll mv = (b[cur] - a[cur])/adj;
        b[cur] -= mv * adj;
        res += mv;
        if(b[cur] > a[cur]) pq.push({b[cur], cur});
        if(b[cur] < a[cur] || mv == 0)
        {
            cout << "-1";
            return 0;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 9456