akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

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

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

    cout << max({dp[n][0],dp[n][1],dp[n][2]});

    return 0;
}

Measured memory_bytes: 3712
n = gets.to_i
s = []
n.times do
  s << gets.chop
end
s.sort!

alpha = {}
"MARCH".chars do |c|
  alpha[c] = 0
end

s.map do |x|
  alpha[x[0]] += 1 if x =~ /^[MARCH]/
end

count = []
"MARCH".chars do |c|
  count << alpha[c]
end

ans = 0
count.combination(3).map  do |c|
  ans += c.inject(:*)
end
p ans


Measured memory_bytes: 10856
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
#define MAX 100000

int main()
{
    string ss;
    getline(cin,ss);
    char temp;
    for(int i= 0;i<ss.length();++i)
    {
        temp = ss[i];
        if('a'<=temp&&temp<='z') temp += ('A'-'a');
        cout << temp;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin>>x;
  bool tf=false;
  while(1){
  	for(int i=2;i<pow(x,0.5);i++){
  		if(x%i==0){
      		tf=true;
      		break;
    	}
  	}
  	if(tf==true){
    	x++;
      	tf=false;
  	}else{
    	cout<<x<<endl;
    	return 0;
  	}
  }
}

Measured memory_bytes: 4064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  if(A+B <= 2 * C){
    cout << X * A + Y * B << endl;
  }else{
    if(X == Y){
      cout << 2 * X * C << endl;
    }else if(X > Y){
      cout << Y * 2 * C + (X-Y)*min(A,2*C) << endl;
    }else{
      cout << X * 2 * C + (Y-X)*min(B,2*C) << endl;
    }
  }
}


Measured memory_bytes: 256
n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
INF = 10**9 + 1
dp = [[INF]*n for _ in range(n)]

# コスト登録
for i, line in enumerate(A):
    for j, a in enumerate(line):
        dp[i][j] = a

for k in range(n):
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        d = dp[i][j]
        if d < A[i][j]:
            ans = -1
            break
        else:
            for k in range(n):
                if k == i or k == j:
                    continue
                if dp[i][k] + dp[k][j] == d:
                    break
            else:
                ans += d
    if ans == -1:
        break
print(ans)


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

int main(void){
  string vec1;
  string vec2;
  cin >> vec1;
  cin >> vec2;
  int N = vec1.size();
  for(int i = 0;i < N;i ++ ){
    int count = 0;
      for(int j = 0;j < N;j++){
        int a;
        if (i + j >= N){
        	a = i + j - N;
        }else{
          a = i + j;
        }
        if(vec1.at(a)==vec2.at(j)){
            count++;
        }else{
            break;
        }
      }
    if(count == N){
      cout << "Yes" <<endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  Sort(a);
  ll ans = 0;
  rep(i,k) {
    ans += a[i];
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3660
#!/usr/bin/env python3
import sys

def s_bannme(i,s):
    ans = [d for d in str(i)]
    if len(ans)>s:
        return int(ans[s])


def solve(N: int, M: int, S: "List[int]", C: "List[int]"):
            
    for i in range(1000):
        exist = True
        if M == 0:
            digits = len(str(i))
            if digits == N:
                pass
            else:
                exist = False
        else:
            for s, c in zip(S, C):
                digits = len(str(i))
                cons = s_bannme(i,s-1)
                if digits == N and cons == c:
                    pass
                else:
                    exist = False

        if exist:
            print(i)
            return
                
    print(-1)



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


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


int min(int a ,int b){
  if(a<b){
    return a;
  }
  return b;
}



int main(){
  int n,i,power;
  int dp[100003]={};
  scanf("%d",&n);
  for (i = 0; i < 6; i++) {
    dp[i]=i;
  }
  for (i = 1; i < 100002; i++) {
    dp[i]=100000;
    power=1;
    while (power<=i){
      dp[i]=min(dp[i],dp[i-power]+1);
      power*=6;
    }
    power=1;
    while (power<=i){
      dp[i]=min(dp[i],dp[i-power]+1);
      power*=9;
    }
  }
  printf("%d",dp[n]);
  return 0;
}


Measured memory_bytes: 512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#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)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	string s, t; cin >> s >> t;
	bool f = true;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i])f = false;
	}

	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
import Foundation

func main(){
   let n = Int(readLine()!)!
   let array = readLine()!.split(separator: " ")

   var j = 1
   var answer = 0
   for i in 0..<n {
      let curInt = Int(array[i])!
      if curInt == j {
         j += 1
      } else {
         answer += 1
      }
   }
   print(answer == n ? -1 :answer)
}
main()

Measured memory_bytes: 23712
ls = []
while 1:
    ls1 = list(map(int,input().split()))
    if ls1[0] == 0 and ls1[1] == 0:
        break
    else:
        ls.append(list(ls1))
        ls1.clear()
for i in range(len(ls)):
    for j in range(ls[i][0]):
        for k in range(ls[i][1]):
            print("#",end="")
        print()
    print()



Measured memory_bytes: 7004
#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;

ll min_times(ll x, ll y)
{
	ll base = x;
	while(x%y!=0){
		x+=base;
	}
	return x;
}

int main()
{
	int a, b;
	
	cin>>a>>b;

	cout<< min_times(a,b) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        int a;
        int b;
        int c;
        int temp;
        Scanner input = new Scanner(System.in);
        a = input.nextInt();
            //Scanner op = new Scanner(System.in);
        b = input.nextInt();
        c = input.nextInt();
        if (a > b) {
            temp = a;
            a = b;
            b = temp;
        }
        if (b > c) {
            temp = b;
            b = c;
            c = temp;
        }
        if (a > b) {
            temp = a;
            a = b;
            b = temp;
        }
        System.out.println(a + " " + b + " " + c);
    }

}


Measured memory_bytes: 26192
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a, b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k, num[10][10], dp[105][10];
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> h >> w >> k;
    for (int bit = 0; bit < (1 << ((w - 1))); bit++)
    {
        ll dat[10] = {};
        cnt = 0;
        rep(i, w)
        {
            if (bit & (1 << i))
                dat[i] = 1;
        }
        ll ok = 1;
        rep(i, w)
        {
            if (dat[i] == 1 && dat[i + 1] == 1)
                ok = 0;
        }
        if (!ok)
            continue;
        rep(from, w)
        {
            ll now = from;
            rrep(to, from, w - 1)
            {
                if (dat[to] == 1)
                    now++;
                else
                    break;
            }
            a = 0;
            if (from == now)
                a = 1;
            else
                (num[from][now] += 1) %= MOD;
            now = from;
            rrrep(to, from - 1, 0)
            {
                if (dat[to] == 1)
                {
                    now--;
                }
                else
                    break;
            }
            if ((from == now && a) || from != now)
                (num[from][now] += 1) %= MOD;
        }
    }
    rep(i, w)
    {
        dp[0][i] = num[0][i];
    }
    rrep(i, 1, h)
    {
        rep(j, w)
        {
            rep(z, w)
            {
                (dp[i][j] += dp[i - 1][z] * num[z][j]) %= MOD;
            }
        }
    }
    Cout((dp[h - 1][k - 1]) % MOD);
    return 0;
}


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

#define int long long

const int N = 200005;
const long long INF = 1e18;

int n, m;
vector<pair<int,int>> add[N];
vector<pair<int,int>> del[N];
long long T[N << 2], lz[N << 2];

void push(int v,int l,int r) {
	if (lz[v]) {
		T[v] += lz[v];
		if (l < r) {
			lz[v << 1] += lz[v];
			lz[v << 1 | 1] += lz[v]; 
		}
		lz[v] = 0;
	}
}

void upd(int v,int l,int r,int L,int R,int x) {
	push(v, l, r);
	if (L > r || R < l) {
		return;
	}
	if (L <= l && R >= r) {
		lz[v] = 1LL * x; 
		push(v, l, r);
		return;
	}
	int mid = (l + r) >> 1;
	upd(v << 1, l, mid, L, R, x);
	upd(v << 1 | 1, mid + 1, r, L, R, x);
	T[v] = max(T[v << 1], T[v << 1 | 1]);
}

long long get(int v,int l,int r,int L,int R) {
	push(v, l, r);
	if (L > r || R < l) {
		return -INF;
	}
	if (L <= l && R >= r) {
		return T[v];
	}
	int mid = (l + r) >> 1;
	return max(get(v << 1, l, mid, L, R), get(v << 1 | 1, mid + 1, r, L, R));
}

int32_t main() {
	scanf("%lld %lld", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int l, r, x; 
		scanf("%lld %lld %lld", &l, &r, &x);
		add[l].push_back(make_pair(l - 1, x));
		del[r].push_back(make_pair(l - 1, x));
	}
	long long ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (auto q : add[i]) {
			upd(1, 0, n, 0, q.first, q.second);
		}
		long long now = get(1, 0, n, 0, i - 1);
		ans = max(ans, now);
		upd(1, 0, n, i, i, now);
		for (auto q : del[i]) {
			upd(1, 0, n, 0, q.first, -q.second);
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 34560
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}

use std::cmp::Ordering;
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl<T: Copy> Copy for Rev<T> {}

fn main() {
    input! {
        n: i64
    }
    let ans = (1..n).into_iter().sum::<i64>();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool a = true;
  string t="";
  for(char c:s){
    if(c=='A' && a){
      t+='A';
      a=false;
    }
    else if(c=='Z' && !a){
      t+='Z';
      a=true;
    }
  }
  if(t[t.length()-1]=='A')
    t=t.substr(0,t.length()-1);
  if(t.length()==0) t="-1";
  cout << t << endl;
  return 0;
}

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

int main()
{
  int N;
  int a[110];
  int res=0;
  cin >> N;
  rep(i,N) cin >> a[i];

  sort(a,a+N);

  res = a[N-1]-a[0];

  cout << res << endl;
}


Measured memory_bytes: 256
#pragma GCC diagnostic ignored "-Wunused-result"
#define NDEBUG

#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cstdio>
#include <tuple>
#include <vector>

#ifdef NDEBUG
#  define debug(...)
#else
#  define debug(...)                                \
  do {                                              \
    fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
    fprintf(stderr, __VA_ARGS__);                   \
    fputc('\n', stderr);                            \
  } while (false)
#endif

using namespace std;
using tii = tuple<int, int>;

int H, W, a[501][501];
vector<tuple<tii, tii>> ans;

int main() {
  scanf("%d %d", &H, &W);
  vector<tii> cur;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) scanf("%d", &a[i][j]);
  }
  for (int i = 1; i <= H; i++) {
    int s = i % 2 != 0 ? 1 : W, t = W + 1 - s, dj = i % 2 != 0 ? 1 : -1;
    for (int j = s; j != t+dj; j += dj) {
      debug("i=%d j=%d", i, j);
      if (cur.empty()) {
        if (a[i][j] % 2 != 0) cur.emplace_back(i, j);
      } else {
        cur.emplace_back(i, j);
        if (a[i][j] % 2 != 0) {
          for (int i = 1; i < (int)cur.size(); i++) {
            ans.emplace_back(cur[i-1], cur[i]);
          }
          debug("clear");
          cur.clear();
        }
      }
    }
  }
  printf("%lu\n", ans.size());
  for (auto & row: ans) {
    tii s, t;
    tie(s, t) = row;
    int i1, j1, i2, j2;
    tie(i1, j1) = s, tie(i2, j2) = t;
    printf("%d %d %d %d\n", i1, j1, i2, j2);
  }
  return 0;
}


Measured memory_bytes: 5104
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

def f(a,b):
    a = list(set(a))
    b = list(set(b))
    cnt = 0
    for i in a:
        for j in b:
            if i == j:cnt += 1
    return cnt

if __name__ == "__main__":
    n = I()
    s = L()
    ans = 0
    for i in range(n):
        #print(s[:n-i],s[n-i:])
        ans = max(ans,f(s[:n-i],s[n-i:]))
    print(ans)

Measured memory_bytes: 9256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string s;
	cin >> s;
	
	ll ret = 0;
	ll cnt = 0;
	for(int i = 0 ; i < s.size() ; i ++){
		if(s[i] == 'B')cnt ++;
		else ret += cnt;
	}
	cout << ret << endl;
}


Measured memory_bytes: 640
N = int(input())
S = input()

result_dic = {}

before_words = {i:0 for i in range(10)}
after_words = {i:0 for i in range(10)}
for s in S:
    after_words[int(s)] += 1

for  i, s in enumerate(S[:-1]):
    if i == 0:
        before_words[int(s)] += 1
        after_words[int(s)] -= 1
        continue
    after_words[int(s)] -= 1

    before =  [x for x, y in before_words.items() if y > 0]
    after =  [x for x, y in after_words.items() if y > 0]
    for b in before:
        for a in after:
            result_dic[str(b) + s + str(a)] = 1

    before_words[int(s)] += 1

print(len(result_dic))

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

#define int long long

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

int N, x;
list<int> ans;

signed main() {
    cin >> N >> x;
    if (x == 1 || x == 2 * N - 1) {
        cout << "No" << endl;
        return 0;
    }
    ans.push_back(x);
    for (int i = 1; i < N; i++) {
        if (i % 2 == 0) {
            ans.push_back((x + 2 * N - 2 + i) % (2 * N - 1) + 1);
            ans.push_front((x + 2 * N - 2 - i) % (2 * N - 1) + 1);
        } else {
            ans.push_back((x + 2 * N - 2 - i) % (2 * N - 1) + 1);
            ans.push_front((x + 2 * N - 2 + i) % (2 * N - 1) + 1);
        }
    }
    cout << "Yes" << endl;
    for (auto it = ans.begin(); it != ans.end(); ++it) {
        cout << *it << endl;
    }
    return 0;
}


Measured memory_bytes: 7808
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def score(t):
        n = 26
        v = 0
        minus = sum_ = sum(c)
        last = [0]*n
        for i in range(d):
            ti = t[i]-1
            minus -= (i+1-last[ti])*c[ti]
            v += s[i][ti]-minus
            minus += sum_
            last[ti] = i+1
        return v
    d = I()
    c = LI()
    s = LIR(d)
    t = IR(d)
    m = I()
    for _ in range(m):
        i,q = LI()
        t[i-1] = q
        print(score(t))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 72504
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 1e5 + 10;
const int M = (int) 101;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int INF1 = (int) 1e9 + 3;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;

int n;
vector<int> a;

int calc(vector<int> v) {
  bool ok = 1;
  for (auto it : v) {
    ok &= it == 1;
  }
  if (ok) {
    return 0;
  }
  int cnt_even = 0;
  for (auto it : v) {
    cnt_even += 1 - it % 2;
  }
  if (cnt_even % 2) {
    return 1;
  } 
  if (sz(v) - cnt_even > 1) {
    return 0;
  }
  int gcd = 0;
  vector<int> g = v;
  for (auto &it : g) {
    it -= it % 2;
    if (!it)
      return 0;
    gcd = __gcd(gcd, it);
  }
  for (auto &it : g) {
    it /= gcd;
  }
  return !calc(g);
} 


int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << (calc(a) ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 19072
h, w = list(map(int, input().split()))
if h == 1:
    print(1)
else:
    if w == 1:
        print(1)
    else:
        x = h * w
        if x%2 == 0:
            print(x // 2)
        else:
            print((x + 1)//2)


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

int n;
int buf[101];

int main(){
    cin >> n;
    int count = 0;
    int input;
    for(int i = 0; i < 101; i++) buf[i] = 0;
    for(int i = 0; i < n; i++){
        cin >> input;
        if(buf[input] == 1){
            continue;
        }else{
            buf[input] = 1;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

int main()
{
    string t;
    stack<int> s;
    cin>>t;
    int ans = 0;
    for(int i = 0;i < t.size(); ++i){
        int v = t[i] - '0';
        if(s.empty()) s.push(v);
        else if(s.top() + v == 1){
            ans += 2;
            s.pop();
        }
        else s.push(v);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
int main(void){
    int a,b,c,i;int A[2]={0},B[2]={0},C[2]={0};
    while(1){
        scanf("%d %d %d",&a,&b,&c);
        if(a==-1&&b==-1&&c==-1)break;
        b=b+a*60;
        C[0]=7200-(c+b*60);
        C[1]=C[0]*3;
        for(i=0;i<2;i++){
            B[i]=C[i]/60;
            C[i]=C[i]%60;
            A[i]=B[i]/60;
            B[i]=B[i]%60;
            printf("%02d:%02d:%02d\n",A[i],B[i],C[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 612
#n=int(input())
#n,m=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())
n=len(s)
mx=0
temp=0
l=['A','C','G','T']

for i in range(n):
    for j in range(i,n):
        st=s[i:j+1]
        if all([c in l for c in st]):
            mx=max(mx,j-i+1)
print(mx)


Measured memory_bytes: 9120
#include<iostream>
#include<algorithm>
using namespace std;
int n;
const int maxn = 205;
int a[maxn];
int b[maxn];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]&1)b[i]=0;
        else
        {
            int k = 0;
            while(a[i]%2==0)
            {
                a[i]/=2;
                k++;
            }
            b[i]=k;
        }
    }
    sort(b+1,b+1+n);
    cout<<b[1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::input;

// B - FizzBuzz Sum
fn main() {
    input! {
        n: i64,
    }
    let mut sum = 0;
    for i in 1..=n {
        if i % 3 == 0 {continue;}
        if i % 5 == 0 {continue;}
        sum += i;
    }
    println!("{}", sum);
}

Measured memory_bytes: 2080
import sys
from collections import Counter

n, *s = sys.stdin.read().split()
n = int(n)

def comb_2(n):
    return n * (n - 1) // 2

def main():
    t = [''.join(sorted(t)) for t in s]

    c = Counter(t)
    pairs_cnt = 0
    for v in c.values():
        pairs_cnt += comb_2(v)
    
    return pairs_cnt
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 28288
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 998244353;

ll pow(ll a, ll b){
    ll ret=1;
    while(b>0){
        ret*=a;
        ret%=MOD;
        b--;
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<ll> cnt(N,0);
    int max_=0;
    for(int i=0; i<N; i++){
        int d;
        cin >> d;
        max_=max(max_,d);
        if(i==0 && d!=0){
            cout << 0 << endl;
            return 0;
        }else if(i!=0 && d==0){
            cout << 0 << endl;
            return 0;
        }

        cnt[d]++;
    }

    ll ans=1;
    for(int i=0; i<max_; i++){
        ans*=pow(cnt[i],cnt[i+1]);
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
# abc160_b.py
# https://atcoder.jp/contests/abc160/tasks/abc160_b

# B - Golden Coins /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 高橋君は金色の硬貨が好きです。自分が持っている 500円硬貨 1 枚につき 1000、5 円硬貨 1 枚につき 5の 嬉しさ を得ます。
# 高橋君は X円を持っています。これを高橋君の嬉しさが最大になるように両替したとき、高橋君の嬉しさはいくらになりますか？
# (なお、利用できる硬貨は 500円玉、100 円玉、50 円玉、10 円玉、5 円玉、1 円玉の 6種類とします。)

# 制約
#     0≤X≤109
#     Xは整数

# 入力
# 入力は以下の形式で標準入力から与えられる。
# X

# 出力
# 嬉しさの最大値を出力せよ。

# 入力例 1
# 1024

# 出力例 1
# 2020

# 500円硬貨 2 枚、5 円硬貨 4 枚を含むように両替することで 2020の嬉しさを得ます。これが嬉しさの最大です。

# 入力例 2
# 0

# 出力例 2
# 0

# 高橋君は一文無しです。

# 入力例 3
# 1000000000

# 出力例 3
# 2000000000

# 高橋君は大富豪です。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    X = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    q1, mod1 = divmod(X, 500)
    q2, mod2 = divmod(mod1, 5)

    result = q1*1000 + q2*5

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['1024']
        lines_export = [2020]
    if pattern == 2:
        lines_input = ['0']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['1000000000']
        lines_export = [2000000000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9240
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        n: i64,
        l: i64,
    }
    let mut ans = 0;
    let mut close0 = std::i64::MAX;

    for i in l..l + n {
        ans += i;
        if close0.abs() > i.abs() {
            close0 = i;
        }
    }
    // println!("close0: {}", close0);
    println!("{}", ans - close0);
}


Measured memory_bytes: 2096
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    rep(i, 1<<3) {
        int num = s[0] - '0';
        string ans = "";
        ans += s[0];
        rep(j, 3) {
            if ((i>>j) & 1) {
                //cout << s[j+1] - '0' << endl;
                num += (s[j+1] - '0');
                ans += '+';
                ans += s[j+1];
            }
            else {
                //cout << s[j+1] - '0' << endl;
                num -= (s[j+1] - '0');
                ans += '-';
                ans += s[j+1];
            }
            //cout << num << endl;
            //cout << ans << endl;
        }
        if (num == 7) {
            cout << ans << "=7" << endl;
            return 0;
        }
    }
    return 0;
}


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

const int MAX = 86400;
int A[MAX*2+5];

int main(){
	int n,a,b,t=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		t+=a;
		t%=MAX;
		A[t]++;
		t+=b;
		t%=MAX;
	}
	
	for(int i=0;i<MAX;i++){
		A[i+MAX] = A[i];
	}
	for(int i=1;i<MAX*2;i++){
		A[i] += A[i-1];
	}
	
	int pos = 10800;
	int ans = A[pos];
	for(int i=pos+1;i<MAX*2;i++){
		ans = max(ans,A[i]-A[i-(pos+1)]);
	}
	
	cout << ans << endl;
	return 0;
}

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

public class ABC
{




    public static void Main()
    {
        int[] read = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int K = read[0];
        int A = read[1];
        int B = read[2];
        long output = 1;
        if (A + 2 >= B) Console.WriteLine(output+K);

        else
        {
            K = K - A + 1;
            output += A - 1;
            if (K % 2 != 0)
            {
                K = K - 1;
                output++;
            }
            
            long k2 = K / 2;
            long ba = B - A;
            long seki = k2 * ba;
            output += seki;

            Console.WriteLine(output);
        }

    }
}



Measured memory_bytes: 11348
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int a, b; cin >> a >> b;
  if (a + b == 15) outl("+");
  else if (a * b == 15) outl("*");
  else outl("x");
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val prices = (1..n).map { readLine()!!.toInt() }
    val max = prices.max()
    val ret = prices.toMutableList()
    val maxIdx = prices.indexOfFirst { it == max }
    ret[maxIdx] /= 2
    println(ret.sum())
}

Measured memory_bytes: 33736
import java.util.*;
fun main(args: Array<String>){
  val sc = Scanner(System.`in`)
  val a = sc.nextInt()
  val b = sc.nextInt()
  val c = sc.nextInt()
  val d = sc.nextInt()
  val e = sc.nextInt()
  val k = sc.nextInt()
  if(e-a>k){
    println(":(")
  }
  else{
    println("Yay!")
  }
}

Measured memory_bytes: 31268
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<cstdio>
#include<algorithm>
using namespace std;
int n,f[100005],a[100005],ans=0;
inline int read(){
	char ch=getchar();
	int x=0,f=1;
	while(ch<'0' || ch>'9')	{if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main(){
    n=read();
    for(int i=1;i<=n;i++){
		a[i]=read();
    }
    for(int i=1;i<=n;i++){
        if(a[i]<=a[i-1]){
        	f[i]+=f[i-1]+1;
		}
		else{
			f[i]=0;
		}
    }
    for(int i=1;i<=n;i++){
    	ans=max(ans,f[i]);
	}
    printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 896
N,K=[int(c) for c in input().split()]
D=0
for c in input().split():
  D|=(1<<int(c))
while(1):
  d=0;
  for c in str(N):
    d|=1<<int(c)
  if(d&D==0):
    print(N)
    exit()
  N+=1;

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

int n;
vector<int> v;
int dp[100001];

int main(){
	cin >> n;
	memset(dp,INF,sizeof(dp));
	dp[0] = 0;
	v.push_back(1);
	for(int i = 9; i <= n; i*=9){
		v.push_back(i);
	}
	for(int i = 6; i <= n; i*=6){
		v.push_back(i);
	}

	dp[0] = 0;
	for(int i = 0; i < v.size(); i++){
		for(int j = v[i]; j <= n; j++){
			dp[j] = min(dp[j], dp[j-v[i]]+1);
		}
	}
	
	cout << dp[n] << endl;
	
	return 0;
}

Measured memory_bytes: 640
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int w, h, n; in(w),in(h),in(n);
  vector<int> X(n),Y(n),A(n);
  loop(i,0,n) in(X[i]),in(Y[i]),in(A[i]);
  int min_x = 0, max_x = w, min_y = 0, max_y = h;
  loop(i,0,n) {
    int a = A[i];
    if (a==1) min_x = max(min_x, X[i]);
    if (a==2) max_x = min(max_x, X[i]);
    if (a==3) min_y = max(min_y, Y[i]);
    if (a==4) max_y = min(max_y, Y[i]);
  }
  print(max(0, max_x-min_x) * max(0, max_y-min_y));
  return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

//#define MyPrint fprintf
#define MyPrint


int get_int2(int *in1, int *in2)
{
    char ch;

    if ((in1 == NULL) || (in2 == NULL))
        return -1;

    while (scanf("%d %d", in1, in2) != 2) {
        while ((ch = getchar()) != '\n')
            putchar(ch);        // dispose of bad input
        MyPrint(stderr, " is not an integer.\nPlease enter an integer value.\n");
    }

    while (getchar() != '\n')   // discard rest of line
        continue;
    return 0;
}

int main(int argc, char *argv[])
{
    int val1, val2;
    int vmul;

    MyPrint(stdout, "Please input integer value.\n");
    
    get_int2(&val1, &val2); 
    if ((val1 < 1) || (val1 > 10000)) {
        MyPrint(stdout, "your input number is error.\n", val1);
        return -1;
    }
    val1 = (int)val1;

    if ((val2 < 1) || (val2 > 10000)) {
        MyPrint(stdout, "your input number is error.\n", val2);
        return -1;
    }
    val2 = (int)val2;

    MyPrint(stdout, "Your input value is %d %d\n", val1, val2);

    MyPrint(stdout, "Your input result : ");

    vmul = val1 * val2;
    MyPrint(stdout, "%d\n", vmul);

    if (vmul % 2 == 0) {
        //fprintf(stdout, "Odd\n");
        fprintf(stdout, "Even\n");
    }
    else {
        //fprintf(stdout, "Even\n");
        fprintf(stdout, "Odd\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

void max_select(ll &a, ll b){
    a = max(a,b);
}


int main(){
    
    int n, w;
    scanf("%d%d", &n, &w);
    vector<ll> dp(w+1); // 0 ... W
    //dp[i] - the maximum total value of item with total weight exactly i

    for(int item = 0; item < n; ++item){
        int weight, value;
        scanf("%d%d", &weight, &value);
        for(int weight_already = w - weight; weight_already >= 0; --weight_already){
            max_select(dp[weight_already + weight], dp[weight_already] + value);
        }        
    }
    ll answer = 0;
    for(int i = 0; i <= w; ++i){
        max_select(answer, dp[i]);
    }
    printf("%lld\n", answer);


    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n, k; cin >> n >> k;
    vector<int> num(200000);
    REP(i, n){
        int tmp; cin >> tmp;
        num[tmp - 1]++;
    }
    ll cnt = 0;
    whole(sort, num, greater<>());
    FOR(i, k, num.size()){
        cnt += num[i];
    }
    cout << cnt << endl;
}

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

def main():
    N = int(input())
    a = [int(s) for s in input().split(' ')]

    result = []

    max_a = max(a)
    min_a = min(a)

    if 0 <= max_a + min_a:
        k = a.index(max_a)
        sk = str(k + 1) + ' '
        for i in range(N):
            if a[i] < 0:
                result.append(sk + str(i + 1))
        for i in range(1, N):
            result.append(str(i) + ' ' + str(i + 1))
    else:
        k = a.index(min_a)
        sk = str(k + 1) + ' '
        for i in range(N):
            if a[i] > 0:
                result.append(sk + str(i + 1))
        for i in range(N - 1, 0, -1):
            result.append(str(i + 1) + ' ' + str(i))

    print(len(result))
    for s in result:
        print(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import heapq
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n = int(input())
    xy = [list(map(int, input().split())) + [i] for i in range(n)]
    xy.sort()
    UF = UnionFind(n)
    lst = [[xy[0][1], xy[0][2]]]
    
    for _, y, i in xy[1:]:
        flg = False
        tmp = lst[0]
        while lst and lst[0][0] < y:
            flg = True
            pos = lst[0][1]
            UF.union(i, pos)
            heapq.heappop(lst)
        if flg:
            heapq.heappush(lst, tmp)
        else:
            heapq.heappush(lst, [y, i])
    for i in range(n):
        print(UF.size(i))
    
main()

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

#define ll long long 

using namespace std;

int a,b;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>a>>b;
    if(a==1 && b==2) cout<<3;
    else if (a==1 && b==3) cout <<2;
    else if (a==2 && b==1) cout<<3;
    else if (a==2 && b==3) cout<<1;
    else if (a==3 && b==1) cout<<2;
    else if (a==3 && b==2) cout<<1;
    
    
    
    return 0;
}

Measured memory_bytes: 256
from heapq import heappop,heappush
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort(reverse=1)
q=list(map(int,input().split()))
q.sort(reverse=1)
r=list(map(int,input().split()))+[0]
r.sort(reverse=1)
h=[]
m=p[0]
for i in range(x):
  heappush(h,p[i])
  m=min(m,p[i])
for i in range(y):
  heappush(h,q[i])
  m=min(m,q[i])
i=0
while m<r[i]:
  _=heappop(h)
  heappush(h,r[i])
  m=heappop(h)
  heappush(h,m)
  i+=1
print(sum(h))

Measured memory_bytes: 111272
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int x;
    cin >> x;
    long long a, b;
    for(a = 0; ; a++){
        long long a5 = a*a*a*a*a;
        if(a5 < x){
            for(b = 0; ; b--){
                long long b5 = b*b*b*b*b;
                if(a5 > x + b5) break;
                else if(a5 == x + b5){
                    cout << a << " " << b;
                    return 0;
                }
            }
        }
        else if(a5 > x){
            for(b = 0; ; b++){
                long long b5 = b*b*b*b*b;
                if(a5 < x + b5) break;
                else if(a5 == x + b5){
                    cout << a << " " << b;
                    return 0;
                }
            }
        }
        else{
            b = 0;
            cout << a << " " << b;
            return 0;
        }
    }
    return 0;
}

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

int main(){
	int n,pos;
	string s;
	while(cin>>n&&n){
		getline(cin,s);
		while(n--){
			getline(cin,s);
			while((pos=s.find("Hoshino",0))!=string::npos)
				s.replace(pos,7,"Hoshina");
			cout<<s<<endl;
		}
	}
	return 0;
}

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



int main(){
    int n=0,m=0,ans=0;
    cin >> n >> m;
    // int a[m+10]={},b[m+10]={};
    vector<pair<int,int>> order(m);
    bool bris[n+10]={};
    ans =0;
    for(int i =0;i<m;i++){
        cin >>order[i].second>>order[i].first;
    }

    sort(order.begin(),order.end());
    int index=0;
    for(int i=0;i<m;i++){
        if(index >= order[i].second){
            continue;
        }
        else{
            index = order[i].first-1;
            ans++;
        }
    }

    
    cout << ans<<endl;
}


Measured memory_bytes: 1152
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

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

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val H = IntArray(N) { sc.next().toInt() }
        val d = IntArray(N) { Int.MAX_VALUE }
        d[0] = 0
        for (i in 0 until N - 1) {
            d[i + 1] = arrayOf(d[i + 1], d[i] + Math.abs(H[i] - H[i + 1])).min()!!
            if (i + 2 < N) d[i + 2] = arrayOf(d[i + 2], d[i] + Math.abs(H[i] - H[i + 2])).min()!!
        }
        pw.println(d[N - 1])
    }
}


Measured memory_bytes: 41724
import fractions

a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=list(set(b))
d = [n//2 for n in c]
e=d[0]
for i in range(1, len(d)):
    e = e * d[i] // fractions.gcd(e, d[i])

odd=0
even=0
while odd != len(d) and even==0 or even==len(d):
    odd=0
    even=0
    for i in range(len(d)):
        if d[i]%2==0:
            d[i]=d[i]//2
            even+=1
        else:
            odd+=1

if even>0:
    print(0)            
else:
    if a[1]//e%2==0:
        print(a[1]//e//2)
    else:    
        print(a[1]//e//2 + 1)

Measured memory_bytes: 16320