akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}
  
signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  lol a[n + 5];
  rep(i, n){
    cin >> a[i];
  }
  sort(a, a + n);
  lol ans = 0;
  rep(i, n){
    for(int j = i + 1;j < n;j ++){
      for(int k = j + 1;k < n;k ++){
	if(a[i] != a[j] && a[j] != a[k] && a[k] != a[i]){
	  if(a[i] + a[j] > a[k]){
	    //cout << a[i] << " " << a[j] << " " << a[k] << '\n';
	    ans ++;
	  }
	}
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3584
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

S = list(input())
K = int(input())
i = 0
ans = 0

if len(S) == 1 and K>1:
    print(K//2)
    exit()

while i+1 < len(S):
    tempc= 1
    while S[i] == S[i+1]:
        tempc += 1
        if tempc == len(S):
            print(tempc * K // 2)
            exit()
        if i+2 < len(S):
            i += 1
        else:
            break

    ans += tempc //2
    if i+2 >= len(S):
        break
    i += 1

j=2
frag = 0
if S[0] == S[-1] and K >1:


    last_num = 1
    while S[-1] == S[-j]:
        last_num += 1
        if (j+1) <= len(S):
            j += 1
        else:
            break
    i=0
    first_num = 1
    while S[i] == S[i+1]:
        first_num += 1
        if i+2 < len(S):
            i += 1
        else:
            break

    if last_num%2 + first_num%2 == 2:
        frag = 1


print((ans+frag)*K-frag)






Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<int> vec;
int gcd(int a,int b);
#define ll long long
int main()
{
  ll a,b,l;
  ll ans;
  cin>>a>>b;
  l=gcd(a,b);

  ans=a*b/l;

  cout<<ans<<'\n';

  return 0;
}
int gcd(int a,int b){
  int r;
  if(b<a)swap(b,a);
  
  r=a%b;
  while(r){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}


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

int main()
{	
	int N,M = 0;
  	cin >> N >> M;
	vector<int> vec(M,1);
	for (int i=0; i<N; i++){
      	int K=0;
      	cin  >> K;
      	vector<int> foods(M,0);
    	for (int j=0; j<K; j++){  
          int num=0;
          cin >> num;
          foods.at(num-1) = 1;
        }
      	for (int a=0; a<M; a++){
        	if(vec.at(a) == 1 && vec.at(a) == foods.at(a)){
              vec.at(a) = 1;
            }else{
              vec.at(a) = 0;
            }
        }
    }
  	int kind_of_foods = accumulate(vec.begin(),vec.end(),0);
  	cout << kind_of_foods << endl;
}

Measured memory_bytes: 384
n = int(input())
h = [int(i) for i in input().split()]
ans = 0
for i in range(1, 101):
    co = 0
    f = 0
    for j in range(n):
        if f == 1:
            if h[j] < i:
                f = 0
        else:
            if h[j] >= i:
                f = 1
                co += 1
    ans += co
print(ans)

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

double a, b, x, theta, ans;

int main() {
  cin >> a >> b >> x;
  if (x <= a * a * b / 2.0) {
    theta = atan( 2.0 * x / (a * b * b));
  } else {
    theta = atan( (a * a * a) / (2.0 * (a * a * b - x)));
  }
  ans = 90.0 - theta * 180.0 / M_PI;
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 256
s=input()

for i in range(len(s)):
    if i%2==0 and s[i] == 'h':
        continue
    elif i%2==1 and s[i] == 'i':
        continue
    else:
        print('No')
        exit()
if s[-1] == 'i':
    print('Yes')
else:
    print('No')

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

using namespace std;

using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18, MOD = 1e15 + 37;
const ld PI = acos(-1);

ll cnt[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

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

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

    int q;
    cin >> q;
    while (q--) {
        int b, c;
        cin >> b >> c;
        sum -= cnt[b] * b;
        sum += cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << "\n";
    }
}


Measured memory_bytes: 4424
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	int b;

	std::cin >> b;

	std::cout << (b + 1) / 2 << std::endl;

	return 0;
}


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

int cnt, h, w, xy[110][110]={-1};
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
pair<int,int> p;
char c[110][110];
queue<pair<int,int>> q;

int bfs(int x,int y){
	for(int i =0; i < h; i++){
		for(int j =0; j < w; j++){
			xy[i][j]=-1;
		}
	}
	q.push(pair<int,int>(x, y));
	xy[x][y]=0;
	while(q.size()){
		p=q.front();
		q.pop();
		for(int i = 0; i < 4; i ++){
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if(0 <= nx && nx <h  && 0 <= ny && ny < w && c[nx][ny] != '#' && xy[nx][ny]==-1){
				q.push(pair<int, int>(nx, ny));
				xy[nx][ny] = xy[p.first][p.second]+1;
			}
		}
	}
	return xy[p.first][p.second];
}
int32_t main()
{
	cin>>h>>w;
	for(int i =0; i<h; i++)
		for(int j =0; j<w; j++)
			cin>>c[i][j];
	for(int i =0; i<h; i++)
		for(int j =0; j<w; j++)
			if(c[i][j]=='.')
				cnt = max(cnt, bfs(i,j));
	cout<<cnt;
	return 0;
}

// 3 3
// ...
// ...
// ...


Measured memory_bytes: 256
N=int(input())
t0=0
x0=0
y0=0
 
for i in range(N):
  t1,x1,y1=map(int,input().split())
  AbsT=t1-t0
  AbsX=abs(x1-x0)
  AbsY=abs(y1-y0)
  if AbsX+AbsY>AbsT or (AbsX+AbsY-AbsT)%2!=0:
    print("No")
    break
  else:
      x0=x1
      y0=y1
      t0=t1

else:
  print("Yes")

Measured memory_bytes: 9212
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int m,n,b;
	cin>>m>>n>>b;
	{
		if(m*n>b)
			printf("%d",b);
		else
			printf("%d",m*n);
		
	}
	
	
	
	
	return 0;
}

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

int main(){
  int N, M, X, Y; cin >> N >> M >> X >> Y;
  vector<int> x(N,0), y(M,0);
  for(int i = 0; i < N; i++){
      cin >> x.at(i);
  }
  for(int i = 0; i < M; i++){
      cin >> y.at(i);
  }
  
  bool War = true;
  for(int Z = X+1; Z <= Y; Z++){
      bool peace = true;
      for(int i = 0; i < N; i++){
          if(x.at(i) < Z);
          else peace = false;
      }
      for(int i = 0; i < M; i++){
          if(y.at(i) >= Z);
          else peace = false;
      }
      if(peace){
          War = false;
          break;
      }
  }
  if(War) cout << "War" << endl;
  else cout << "No War" << endl;
}



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

int main() {
	int num;
  	int thousand_rem, hundred_rem, ten_rem, one_rem;

  	cin >> num;
  	thousand_rem = num / 1000;
  	hundred_rem = (num - 1000 * thousand_rem) / 100;
  	ten_rem = (num - 1000 * thousand_rem - 100 * hundred_rem) / 10;
  	one_rem = (num - 1000 * thousand_rem - 100 * hundred_rem - 10 * ten_rem) ;
  	
  	if(thousand_rem == hundred_rem && hundred_rem == ten_rem){
    	cout << "Yes" << endl;
    } else if(hundred_rem == ten_rem && ten_rem == one_rem){
    	cout << "Yes" << endl;
    } else {
    	cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	int n;
	cin >> n;
	vector<int>v(n);
	int sv = 0;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		if (i % 2 == 0 && i > 1)
			sv -= v[i];
		else
			sv += v[i];
	}
	vector<int>ans(n);
	ans[0] = v[0] * 2 - sv;
	for (int i = n - 1; i >= 1; --i)
		ans[i] = v[i] * 2 - ans[(i + 1) % n];
	for (auto i : ans)
		cout << i << ' ';
}

Measured memory_bytes: 2176
#include <stdio.h>
 
int main(void)
{
  int N;
  
  scanf("%d", &N);
  
  if(N <= 3) {
    printf("No");
  } else if(N == 5) {
    printf("No");
  } else if(N == 6) {
    printf("No");
  } else if(N == 9) {
    printf("No");
  } else if(N == 10) {
    printf("No");
  } else if(N == 13) {
    printf("No");
  } else if(N == 17) {
    printf("No");
  } else {
    printf("Yes");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int num_counts(const vector<int>& d_list, int thres) {
    int res = 0;
    for (const int d : d_list){
        if (d < thres) res += 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> d_list(N);
    range(i, 0, N) cin >> d_list.at(i);
    sort(d_list.begin(), d_list.end());
    int num_problems = N / 2;
    int ans = d_list.at(num_problems) - d_list.at(num_problems - 1);
    cout << ans << "\n";
}


Measured memory_bytes: 640
s =list(input())
N = len(s)
mod = pow(10,9)+7
dp = [[0]*13 for i in range(N)]
if s[0] == '?':
        dp[0][0:9] = [1 for i in range(10)]
else:
    dp[0][int(s[0])] = 1
for i in range(1,N):
    if s[i] == '?':
        for j in range(10):
            for m in range (13):
                 dp[i][(m*10+j)%13] += dp[i-1][m]%mod
    else:
        for m in range(13):
            dp[i][(m*10+int(s[i]))%13] += dp[i-1][m]%mod
print(dp[-1][5]% mod)

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

int main(){
  int N;
  cin >> N;
  
  vector<int> A(N), B(N), C(N);
  
  for(int i=0; i<N; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> B[i];
  for(int i=0; i<N; i++) cin >> C[i];
  
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());

  long long ans = 0;
  
  for(int i=0; i<N; i++){
    auto index = lower_bound(A.begin(), A.end(), B[i]);
    long long indexA = index - A.begin();
    auto index2 = upper_bound(C.begin(), C.end(), B[i]);
    long long indexC = C.end()-index2;
  	ans += indexA*indexC;
  }
  
  cout << ans << endl;

  return 0;
}

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

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

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

const int maxn = 1010;
mint dp[maxn][maxn];

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    combination nck(n);
    dp[0][0] = 1;

    for (ll i = 0; i <= n; i++) {
        for (ll j = 0; j <= b - a + 1; j++) {
            ll num = a + j;
            // F_{num} == 0
            dp[i][j + 1] += dp[i][j];

            // C <= F_{num} <= D
            for (ll k = c; k <= d; k++) {
                ll all = i + num * k;
                if (all > n) break;
                mint divide = nck.fact[num * k] * modpow(nck.ifact[num].x, k);
                mint disregard = nck.ifact[k];
                dp[all][j + 1] += dp[i][j] * nck(n - i, num * k) * divide * disregard;
            }
        }
    }
    cout << dp[n][b - a + 1].x << endl;
}

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

using namespace std;

void solve(string S) {
  bool a1, a2, a3;
  a1 = (S[0] == 'A');
  int N = S.length();
  a2 = false;
  for (int i = 2; i < N - 1; i++) {
    if (S[i] == 'C') {
      a2 = true;
    }
  }
  int nupper = 0;
  for (int i = 0; i < N; i++) {
    if (isupper(S[i])) {
      nupper += 1;
    }
  }
  a3 = (nupper == 2);
  if (a1 && a2 && a3) {
    printf("AC\n");
  } else {
    printf("WA\n");
  }
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let count a b c k =
        (if a = k then 1 else 0) + (if b = k then 1 else 0) + (if c = k then 1 else 0)
    in
    let m = 1000000007 in
    let ( *@) a b = ((a mod m) * (b mod m)) mod m in
    let main () =
        let n = int_of_string (read_line ()) in
        let rec loop r g b acc = function
            | [] -> acc
            | hd :: tl ->
                    let acc = acc *@ count r g b hd in
                    let r, g, b = if r = hd then r + 1, g, b else
                                  if g = hd then r, g + 1, b else
                                                 r, g, b + 1
                    in
                    loop r g b acc tl
        in
        let a = split (read_line ()) in
        let q = loop 0 0 0 1 a in
        Printf.printf "%d\n" q
    in
    main ()

Measured memory_bytes: 14720
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int a = Integer.parseInt(str[1]);
    int b = Integer.parseInt(str[2]);
    System.out.println(n*a<b?n*a:b);
  }
}

Measured memory_bytes: 22100
# -*- coding: utf-8 -*-

# 整数の入力
# スペース区切りの整数の入力
a, b, k = map(int, raw_input().split())

m = max(a,b)
count = 0
array = []
for i in range(1, m+1):

    if a%i==0 and b%i==0:
        count += 1
        array.append(i)

print array[-k]


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod =  998244353;
const long long INF = 1e15;

struct Fenwick {
    int N;
    vector<ll> seg;
    Fenwick(int N) : N(N) {
        seg.resize(N+1);
        fill_n(begin(seg), N+1, 0);
    }
    void add(int i, ll x) {
        i++;
        while (i <= N) {
            seg[i] += x;
            seg[i] %= mod;
            i += i & -i;
        }
    }
    ll sum(int i) {
        ll s{0};
        while (i > 0) {
            s += seg[i];
            s %= mod;
            i -= i & -i;
        }
        return s%mod;
    }
    ll sum(int a, int b) {
        return (sum(b) - sum(a))%mod;
    }
};

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

    int n,k;
    cin >> n >> k;
    vector<pair<ll,ll>> inter(k);
    for(int i = 0; i < k; i++){
        int l,r;
        cin >> l >> r;
        inter[i] = make_pair(l,r);
    }

    Fenwick tree(n);
    tree.add(0,1);

    for(ll i = 0; i < n; i++){
        ll plus = 0;
        for(ll j = 0; j < k; j++){
            if(i-inter[j].first >= 0){
                plus += tree.sum(max(0ll,i-inter[j].second),i-inter[j].first+1);
                plus %= mod;
            }
        }
        tree.add(i,plus);
    }

    cout << (tree.sum(n-1,n)+mod)%mod << endl;

    return 0;
}

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

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template <class Z> Z getint() {
  char c = getchar();
  bool neg = c == '-';
  Z res = neg ? 0 : c - '0';
  while (isdigit(c = getchar())) res = res * 10 + (c - '0');
  return neg ? -res : res;
}
template <class Z> void putint(Z a, char c = '\n') {
  if (a < 0) putchar('-'), a = -a;
  int d[40], i = 0;
  do d[i++] = a % 10; while (a /= 10);
  while (i--) putchar('0' + d[i]);
  putchar(c);
}

template <class T> struct assign_segtree {
  const int n;
  vector<pair<int, T>> t;
  assign_segtree(int _n, T a) : n(_n), t(2 * n, {0, a}) {}
  void assign(int l, int r, T a) {
    static int time = 0;
    ++time;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) t[l++] = {time, a};
      if (r & 1) t[--r] = {time, a};
    }
  }
  T get(int i) const {
    auto res = t[i += n];
    while (i >>= 1) if (t[i].first > res.first) res = t[i];
    return res.second;
  }
};

int main() {
  int n = getint<int>();
  int q = getint<int>();
  assign_segtree<int> st(n, 0x7fffffff);
  while (q--) {
    if (getint<int>() == 0) {
      int l = getint<int>();
      int r = getint<int>() + 1;
      int a = getint<int>();
      st.assign(l, r, a);
    } else {
      putint(st.get(getint<int>()));
    }
  }
}



Measured memory_bytes: 4356
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    string s; cin >> s;
    int n = s.length();

    int zeros = 0;
    for (int i = 0; i < n; i++) {
        if(s[i] == '0') {
            zeros += 1;
        } 
    }

    int res = min(zeros, n-zeros)*2;

    cout << res << endl;
    
    return 0;
}



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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout<<a[k-1]<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {

	int x, y, min, max, i;

	cin >> x >> y;

	if (x < y){
		min = x;
		max = y;
	}
	else if (x > y) {
		min = y;
		max = x;
	}
	while (1)
	{
		i = 1;
		i = max % min;

		if (i == 0)
			break;
		max = min;
		min = i;

	}

	cout << min << endl;


	return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<math.h>
int main()
{
    int x,a,b;
    while(scanf("%d%d%d",&x,&a,&b)!=EOF)
    {
        if(fabs(x-a)<fabs(x-b))
            printf("A\n");
        else
            printf("B\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

struct Point{
  double x,y;
  Point(){}
  Point(double x,double y):x(x),y(y){}
 
  Point operator+(Point p){return Point(x+p.x,y+p.y);}
  Point operator-(Point p){return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
  
  double norm(){return x*x+y*y;}
  double abs(){return sqrt(norm());}

  bool operator<(const Point &p) const{
    return x!=p.x? x< p.x : y < p.y;
  }

  bool operator==(const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS ;
  }
};

typedef Point Vector;

double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}
int ccw(Point p0,Point p1,Point p2){
  Vector a = p1-p0;
  Vector b = p2-p0;
  if(cross(a,b) > EPS) return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS) return CLOCKWISE;
  if(dot(a,b) < -EPS) return ONLINE_BACK;
  if(a.norm()<b.norm()) return ONLINE_FRONT;
  return ON_SEGMENT;
}
typedef vector<Point> Polygon;

int andrewScan(Polygon s){
  Polygon u,l;
  if(s.size()<3) return s.size();
  sort(s.begin(),s.end());
  u.push_back(s[0]);
  u.push_back(s[1]);
  l.push_back(s[s.size()-1]);
  l.push_back(s[s.size()-2]);

  for(int i=2;i<s.size();i++){
    for(int n=u.size();n>=2&&ccw(u[n-2],u[n-1],s[i]) != CLOCKWISE;n--){
      u.pop_back();
    }
    u.push_back(s[i]);
  } 
  for(int i=s.size()-3;i>=0;i--){
    for(int n=l.size();n>=2&&ccw(l[n-2],l[n-1],s[i]) != CLOCKWISE;n--){
      l.pop_back();
    }
    l.push_back(s[i]);
  }

  reverse(l.begin(),l.end());
  for(int i=u.size()-2;i>=1;i--) l.push_back(u[i]);
  return l.size();
} 
int main(){
  int n;
  while(cin>>n,n){
    Polygon p;
    p.clear();
    double x,y;
    for(int i=0;i<n;i++){
      //cin >> x >> y;
      scanf("%lf,%lf",&x,&y);
      //cout << x << ":" << y << endl;
      p.push_back(Point(x,y));
    }
    cout << n-andrewScan(p) << endl;
  }
  
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;

const int M = 1000000007, BIG = 0x3f3f3f3f;

int n;
ll k;
vi p;
vector<ll> a, c; 

ll Kad(int mxlen) {
  if (mxlen == 0)
    return 0;
  int len = 1;
  ll cur = a[0], ans = a[0];
  for (int i = 1; i < a.size(); i++) {
    if (a[i] >= cur + a[i]) {
      len = 1;
      cur = a[i];
    }
    else {
      if (len == mxlen) 
        cur += a[i] - a[i - len];
      else {
        len++;
        cur += a[i];
      }
    }
    ans = max(ans, cur);
  }
  return ans;
}

ll Solve(const vector<ll>& v) {
  a.resize(4 * v.size());
  for (int i = 0; i < v.size(); i++)
    a[i] = a[i + v.size()] = a[i + 2 * v.size()] = a[i + 3 * v.size()] = v[i];
  if (k <= 3 * v.size())
    return Kad(k);
  ll sum = 0;
  for (int i = 0; i < v.size(); i++)
    sum += v[i];
  if (sum < 0)
    return Kad(k);
  int q = k / v.size();
  int r = k % v.size();
  while (q > 0 && r < 2 * v.size()) {
    q--;
    r += v.size();
  }
  return sum * q + Kad(r);
}

ll Process() {
  ll ans = -8e18;
  vector<bool> vis(n, 0);
  for (int i = 0; i < n; i++) {
    int idx = p[i] - 1;
    if (vis[idx])
      continue;
    vector<ll> cur;
    while (vis[idx] == 0) {
      vis[idx] = 1;
      cur.push_back(c[idx]);
      idx = p[idx] - 1;
    }
    ans = max(ans, Solve(cur));
  }
  return ans;
}

void Output() { cout << Process() << "\n"; }

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

  while (cin >> n) {
    cin >> k;
    p.resize(n);
    for (int i = 0; i < n; i++)
      cin >> p[i];
    c.resize(n);
    for (int i = 0; i < n; i++)
      cin >> c[i];

    Output();
  }

  return 0;
}

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

int main() {
    string s;
    cin >> s;
    vector<string> S;
    string tmp = "";
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == 'A') {
            tmp += 'A';
        } else if(s[i] == 'B') {
            if(i + 1 < s.size() && s[i + 1] == 'C') {
                tmp += 'D';
                ++i;
            } else if(tmp.size() > 0) {
                S.push_back(tmp);
                tmp = "";
            } 
        } else {
            if(tmp.size() > 0) {
                S.push_back(tmp);
                tmp = "";
            }
        }
        if(i + 1 == s.size() && tmp.size() > 0) S.push_back(tmp);
    }

    long long res = 0;
    for(string str : S) {
        int cnt = 0;
        for(char c : str) {
            if(c == 'A') ++cnt;
            else res += cnt;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3196
use std::cmp::max;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let v: Vec<i32> = (0..n).map(|_| read()).collect();
    let c: Vec<i32> = (0..n).map(|_| read()).collect();

    let ans: i32 = v.iter().zip(c.iter()).map(|(v, c)| max(v - c, 0)).sum();

    println!("{}", ans)
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }

        static void Solve()
        {
            var Q = Sarray()[0];
            for (var i = 0; i < Q; ++i)
            {
                var (A, B) = Slice2<long>();
                WriteLine(check(A, B));
            }
        }
        // n人いて、使える順番を昇順に並べた場合(1,2,3,･･･,n
        // a_1-b_n,a_2-b_{n-1}...a_{(n+1)/2}-b{n/2+1}
        // b_1-a_n,･･･
        // とするのが最適
        // x*(x-i)と上に凸な関数になるため(n+1)/2*(n/2+1)がA*B未満であれば良い
        // A,Bは使えないため答えから1減らす
        static long check(long a, long b)
        {
            if (a == b) return 2 * (a - 1);
            var lim = a * b;
            var low = 1L;
            var high = 1L << 31;
            while (1 < high - low)
            {
                var mid = (low + high) / 2;
                var mul = (mid + 1) / 2 * (mid / 2 + 1);
                if (mul < lim) low = mid;
                else high = mid;
            }
            return low - 1;
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28332
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

const double PI = 3.141592;

int main() {
    double R;
    double two = 2;
    cin >> R;
    cout << (R * PI * two) << endl;
}


Measured memory_bytes: 3800
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int l = stdIn.nextInt();
		
		String[] s = new String[n];
		
		for(int i = 0; i < n; i++) {
			s[i] = stdIn.next();
		}
		
		Arrays.sort(s);
		
		for(int i = 0; i < n; i++) {
			System.out.print(s[i]);
		}
		
	}

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b,int c){
	return __gcd(a,__gcd(b,c));
}
int k;
long long ans;
int main(){
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
		for(int j=1;j<=k;j++)
			for(int l=1;l<=k;l++)
				ans+=gcd(i,j,l);
	printf("%lld\n",ans);
}

Measured memory_bytes: 3828
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int G[105][105];

int main()
{
    int h,w;
    while(scanf("%d%d",&h,&w)!=EOF)
    {
        int n;
       cin>>n;
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int k=1;k<=h;++k)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[k][j]);
                else printf("%d\n",G[k][j]);
            }
        }
    }
    return 0;
}


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

int main(){
  int i,n,m,p,x[1001],total;


  while(1){
         
    total = 0;
    cin >> n >> m >> p;
    if(n==0 && m==0 && p==0)break;

    for( i = 1; i <=1000; i++){
      x[i]=0;
    }

    for( i = 1; i <= n; i++){
      cin >> x[i];
      total += x[i]*100;
    }
      
    if(x[m]>0){
      total = total * (100- p) /100;
      total /= x[m];
      cout << total << endl;
    }else if(x[m]==0){
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
n=int(input())
z=list(map(int,input().split()))
print(' '.join(list(map(str,z))))
for i in range(1,n):
    v=z[i]
    j=i-1
    while j>=0 and z[j]>v:
        z[j+1]=z[j]

        j-=1
        z[j+1]=v
    print(' '.join(list(map(str, z))))

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

int main() {
int n;
cin >> n;
int k;
cin >> k;
long ans = 0;
for (int a, i = 0; i < n; ++i) {
cin >> a;
ans += min(a, k - a) * 2;
}

cout << ans << endl;
return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\b\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N;
  IN(N);
  cout << N*(N+1)/2 << endl;
  return 0;
}



Measured memory_bytes: 256
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

n,m = map(int,input().split())

#根なら-size,子なら親の頂点
par = [-1]*n
lan = [[] for _ in [0]*m]
for pt in range(n):
    l = tuple(map(int,input().split()))
    for i in range(1,len(l)):
        lan[l[i]-1].append(pt)

for i in range(m):
    for j in range(1,len(lan[i])):
        unite(lan[i][0],lan[i][j])

cnt = 0
for e in par:
    if e < 0:
        cnt += 1

if cnt == 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 70816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
  ll N;
  cin>>N;
  ll C[N-1],S[N-1],F[N-1];
  for(ll i=0;i<N-1;i++){
    cin>>C[i]>>S[i]>>F[i];
  }
    ll ans=0;  
  for(ll i=0;i<N-1;i++){
	ans=0;
    for(ll j=i;j<N-1;j++){
      if(ans<=S[j]){ans=S[j];}
      else {ll start=(ans+F[j]-1)/F[j];
           ans=start*F[j];
            //cout<<"start"<<start;
           }
      //cout<<"j"<<j<<"ans"<<ans<<" "<<C[j]<<endl;
      ans=ans+C[j];
      //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    
  }
  cout<<0<<endl;
  
}


Measured memory_bytes: 3484
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define forup(i,a,b) for(int i=a; i<b; ++i)
#define fordn(i,a,b) for(int i=a; i>b; --i)
#define rep(i,a) for(int i=0; i<a; ++i)
#define dforup(i,a,b) for(i=a; i<b; ++i)
#define dfordn(i,a,b) for(i=a; i>b; --i)
#define drep(i,a) for(i=0; i<a; ++i)
#define ll long long
#define ull unsigned long long
#define gi(x) scanf("%d",&x)
#define gl(x) scanf("%lld",&x)
#define gd(x) scanf("%lf",&x)
#define gs(x) scanf("%s",x)
#define pis(x) printf("%d ",x)
#define pin(x) printf("%d\n",x)
#define pls(x) printf("%lld ",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)
#define pss(x) printf("%s ",x)
#define pds(x) printf("%.12f ",x)
#define pdn(x) printf("%.12f\n",x)
#define pnl() printf("\n")
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define m_p make_pair
#define fs first
#define sc second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
#define MOD 100000000000000007
#define limit 10000005
const int N = 5e5 + 7;

void solve()
{
	ll n,x;
	cin>>n;
	vector<ll> v;
	vector<ll> dp(n+2, 0);
	rep(i, n){cin>>x; v.pb(x); }	
	dp[0] = 0;
	forup(i, 1 , n)
	{
		if(i==1)
		{
			dp[i+1] = dp[i]+ abs(v[i]-v[i-1]);
		}
		else
			dp[i+1] = min(dp[i] + abs(v[i-1] - v[i]), dp[i-1]+ abs( v[i-2]-v[i]));		
	}
	//rep(i, n+1){ pin(dp[i]); }
	//pnl();
	cout<<dp[n]<<endl;
}

int main()
{
	int t;
	t =1;
//	gi(t);
	
  	while(t--)
  	{
	  solve();
  	}
}
	
ull mod_pow(ull num, ull pow, ull mod)
{
		ull test,n = num;
		for(test = 1; pow; pow >>= 1)
		{
				if (pow & 1)
						test = ((test % mod) * (n % mod)) % mod;
				n = ((n % mod) * (n % mod)) % mod;
		}
		return test; /* note this is potentially lossy */
}
ll gcd(ll a,ll b)
{	ll r;
	while(b)
	{	r= a%b;a = b; b = r;
	}
	return a;
}

int mpow(int base, int exp) {
	base %= MOD;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % MOD;
		base = ((ll)base * base) % MOD;
		exp >>= 1;
	}
	return result;
}




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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	char conv[8]={'0','1','2','3','5','7','8','9'};
	while(true){
		int X=in();
		if(!X) break;
		vector<int> V;
		while(X){
			V.push_back(X%8);
			X/=8;
		}
		reverse(ALL(V));
		for(auto& x:V) cout<<conv[x];
		out();
	}

	return 0;
}



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

#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi (3.14159265358979323846264338327950288419716939937510)
#define fo(i, n) for(int i = 0; i < n; ++i)
#define ro(i, n) for(int i = n - 1; i >= 0; --i)
#define fill(x, y) memset(x, y, sizeof(x))


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef double D;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

const int maxn = (int) 1e5;
vi g[maxn];
bool was[maxn];
int cost[maxn];
int q = 0;
vi d[maxn];
int num[maxn];

bool sorting (int v1, int v2) {
    if (cost[v1] != cost[v2]) re cost[v1] < cost[v2];
    re v1 < v2;
}
set <int, bool (*)(int, int)> s1(sorting);
set <int, bool (*)(int, int)> s2(sorting);

bool f(vi &v1, vi &v2) {
    if (v1.size() != v2.size()) re v1.size() > v2.size();
    re v1[0] < v2[0];
}

ii dfs (int v) {
    was[v] = true;
    d[q].pb(v);
    for (auto j : g[v]) if (!was[j]) dfs (j);
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    fo(i, n) scanf("%d", cost + i);
    int x, y;
    fo(i, m) {
        scanf("%d %d", &x, &y);
        g[x].pb(y);
        g[y].pb(x);
    }
    fo(i, n) {
        if (!was[i]) {
            dfs(i);
            ++q;
        }
    }
    if (n < (q - 1) * 2) {
        cout << "Impossible\n";
        re 0;
    }
    sort(d, d + q, f);
    for (auto j : d[0]) s1.insert(j), num[j] = 0;
    for (int i = 1; i < q; ++i) for (auto j : d[i]) s2.insert(j), num[j] = i;
    ll ans = 0;
    while (!s2.empty()) {
        int v = *s2.begin();
        ans += cost[*s1.begin()];
        s1.erase(s1.begin());
        ans += cost[v];
        for (auto j : d[num[v]]) s1.insert(j), s2.erase(j);
        s1.erase(v);
    }
    cout << ans << endl;
    re 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int x, a, b;
  cin >> x >> a >> b;
  
  co((x-a)%b);
  return 0;
}


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

using namespace std;

#define int long long

vector<int> neg,pos;

int lessthan(int val){
	int ret=0;
	if(val<0){
		for(int i=0;i<neg.size();i++){
			int l=0,r=pos.size()-1,c=pos.size();
			while(l<=r){
				int m=(l+r)/2;
				if(neg[i]*pos[m]<=val){
					c=m;
					r=m-1;
				}
				else
					l=m+1;
			}
			ret+=pos.size()-c;
		}
	}
	else{
		for(int i=0;i<neg.size();i++){
			int l=i+1,r=neg.size()-1,c=neg.size();
			while(l<=r){
				int m=(l+r)/2;
				if(neg[i]*neg[m]<=val){
					c=m;
					r=m-1;
				}
				else
					l=m+1;
			}
			ret+=neg.size()-c;
		}
		
		for(int i=0;i<pos.size();i++){
			int l=i+1,r=pos.size()-1,c=0;
			while(l<=r){
				int m=(l+r)/2;
				if(pos[i]*pos[m]<=val){
					c=m;
					l=m+1;
				}
				else
					r=m-1;
			}
			//cout<<"c :"<<c<<"\n";
			ret+=(c>=i?c-i:0);
		}
		//cout<<ret<<"\n";
		ret+=(pos.size()*neg.size());
	}
	return ret;
}

signed main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(x<0)
			neg.push_back(x);
		else
			pos.push_back(x);
	}
	sort(neg.begin(),neg.end());
	sort(pos.begin(),pos.end());
	int l=-1e18,r=1e18,res=0;
	while(l<=r){
		int m=(l+r)/2;
		int less=lessthan(m);
		//cout<<l<<" "<<r<<" "<<m<<" "<<less<<"\n";
		if(less<k){
			l=m+1;
		}
		else{
			res=m;
			r=m-1;
		}
	}
	cout<<res;
}


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

#define INF 1000000000;
#define NODE 10000;

using namespace std;
int A,B;
string S;
int abs(int x){
	if(x<0){
		return -x;
	}
	return x;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}
int max(int x,int y){
	if(x>y)return x;
	
	return y;
}

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

	if(S[0]=='+'){
		cout<<A+B<<endl;
	}else{
		cout<<A-B<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a,b,c,d;int l;
	cin >>l; a=l/1000;b=(l%1000)/100;c=(l%100)/10;d=(l%10);
	if((a+b+c+d)==7) cout << a<<"+" <<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
	else if((a+b+c-d)==7) cout << a<<"+" <<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
	else if((a+b-c+d)==7) cout << a<<"+" <<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
  else if((a+b-c-d)==7) cout << a<<"+" <<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
	else if((a-b+c+d)==7) cout << a<<"-" <<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
	else if((a-b+c-d)==7) cout << a<<"-" <<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
	else if((a-b-c+d)==7) cout << a<<"-" <<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
	else if((a-b-c-d)==7) cout << a<<"-" <<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>

#define HANDS 15

using namespace std;

map<string,int> HSP;
const char *str[]={"Rock","Fire","Scissors","Snake","Human","Tree","Wolf","Sponge","Paper","Air","Water","Dragon","Devil","Lightning","Gun"}; 

int main()
{
  int N;
  for(int i=0;i<HANDS;++i)
    HSP[str[i]]=i;

  while(cin>>N&&N){
    bool exist[HANDS]={false,};
    int in[HANDS]={0,},out[HANDS]={0,};
    int hands[N];

    for(int i=0;i<N;++i){
      string s;cin>>s;hands[i]=HSP[s];
      exist[hands[i]]=true;
    }

    for(int i=0;i<N;++i)
      for(int j=1;j<=7;++j)
	if(exist[(hands[i]+j)%HANDS])
	  ++in[(hands[i]+j)%HANDS],++out[hands[i]];

    int win=-1;
    for(int i=0;i<HANDS;++i)
      if(exist[i]&&in[i]==0&&out[i]>0)
	if(win>=0){win=-1;break;}
	else win=i;

    if(win<0||N==1)
      cout<<"Draw"<<endl;
    else
      cout<<str[win]<<endl;
  }
  return 0;
}

Measured memory_bytes: 920
#include<iostream>

using namespace std;

int main() {
	int ki = 0, guu = 0;
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a % 2 == 0)guu++;
		else ki++;
	}
	if (ki % 2 == 1)cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256