akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int w, h;
int ans;
priority_queue<P>que;
signed main() {
	cin >> w >> h;
	rep(i, w) {
		int a; cin >> a;
		que.push({ a,0 });
		ans += a * (h + 1);
	}
	rep(i, h) {
		int a; cin >> a;
		que.push({ a,1 });
		ans += a * (w + 1);
	}
	while (1) {
		P p = que.top(); que.pop();
		if (p.second == 0) {
			if (!h)break;
			ans -= p.first * h; w--;
		}
		else {
			if (!w)break;
			ans -= p.first * w; h--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6256
N=int(input())
s=[int(input()) for i in range(N)]
if sum(s)%10 != 0:
    print(sum(s))
else:
    outs=[i for i in s if i%10!=0]
    if len(outs) == 0:
        print(0)
    else:
        print(sum(s)-min(outs))


Measured memory_bytes: 3060
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

grid = [[0] * W for _ in range(H)]

i, j, k = 0, 0, 0
while i < H:
    step = 1 if i % 2 == 0 else -1
    grid[i][j] = k + 1
    A[k] -= 1
    if A[k] == 0:
        k += 1
    if j + step in (-1, W):
        i += 1
    else:
        j += step

for row in grid:
    print(*row)


Measured memory_bytes: 3920
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("\\n|\\s");
        while(true) {
            int a;
            try{
                a = sc.nextInt();
            } catch(Exception e) {
                break;
            }
            int b = sc.nextInt();
            System.out.println(a + b);
        }
    }
}

Measured memory_bytes: 26168
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;


const double EPS = 1e-9;
int main() {
    int n, m; cin >> n >> m;
    priority_queue<LL> que;
    rep(i, n) {
        LL a;
        cin >> a;
        que.push(a);
    }
    rep(i, m) if (not que.empty()){

        auto x = que.top(); que.pop();
        x /= 2;

        if (x < 0.9) {
            n--;
            continue;
        }

        que.push(x);
    }
    LL ans = 0;
    rep(i, n) {
        auto x = que.top(); que.pop();
        ans += x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
// atc.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <string>
#include    <algorithm>
using namespace std;

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

	int out=1,tmp;

	for (int i = 2;i<40; i++) {
		tmp = i;
		for (int j=0;; j++) {
			tmp = tmp*i;

			if (tmp == x) {
				out = tmp;
				break;
			}
			else if (tmp > x) {
				break;
			}

			if (tmp > out) {
				out = tmp;
			}

		}

	}
	cout << out;

	return 0;

}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int n, a[100010]={0};
int main() {
    cin >> n;
    int f = 0;
    for(int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        if(a[i] < a[i-1]) a[i]++;
        if(a[i] < a[i-1]) f = 1;
    }
    if(f) cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
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++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//

int main(){
   ll n;cin>>n;
   ll a=sqrt(n)-1;
   
   FOR(t,1,n){
   ll ans=0;   
   FOR(i,1,a){
      FOR(j,1,i){
         FOR(k,1,j){
            if(i*i+j*j+k*k+i*j+j*k+k*i==t){
               if(i==j&&j==k&&k==i)ans++;
               else if(i==j||j==k||k==i)ans+=3;
               else ans+=6;
            }
         }
      }
   }
   cout<<ans<<endl;
 }
}

Measured memory_bytes: 3672
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def z_algorithm(S):
    l = len(S)
    A = [0] * l
    i = 1; j = 0
    while i < l:
        while i + j < l and S[j] == S[i + j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l - i > k < j - A[k]:
            A[i + k] = A[k]
            k += 1
        i += k; j -= k
    return A

n = I()
A = LI()
B = LI()
ax = [A[i%n] ^ A[(i+1)%n] for i in range(2 * n)]
bx = [B[i%n] ^ B[(i+1)%n] for i in range(n)]
z_box = z_algorithm(bx + ax)
for j in range(n, 2 * n):
    if z_box[j] >= n:
        print(j - n, B[0] ^ A[j - n])




Measured memory_bytes: 106120
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

n, k = list(map(int, input().split()))
h = [0] + list(map(int, input().split()))

INF = 10**10
dp = [INF]*(n+5)
dp[1] = 0

for i in range(2,n+1):
    temp = [dp[j] + abs(h[i] - h[j]) for j in range(i-1, max(0,i-k-1), -1)]
    dp[i] = min(temp)

print(dp[n])



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




int main() {
	int N,divNum=0,ans=1;
	cin >> N;
	for (int i = 1; i <= N ; i++)
	{
		if (i % 2 != 0)continue;
		int tmp = i;
		int count = 0;
		while (true)
		{
			if (tmp%2!=0)
			{
				break;
			}
			tmp /= 2;
			count++;
		}
		if (count>divNum)
		{
			divNum = count;
			ans = i;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3560
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
const int INT_LARGE = 1.0e+9 + 7;

template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}

int main() {
  // Input
  int numArray;
  std::cin >> numArray;
  assert(2 <= numArray and numArray <= 1.0e+5);
  std::vector<int> height(1 + numArray + 2);
  for (int i = 1; i <= numArray; ++i) {
    std::cin >> height[i];
    assert(height[i] <= 1.0e+4);
  }

  // Init
  std::vector<int> dp(1 + numArray + 2);
  for (int i = 1; i <= numArray + 2; ++i)
    dp[i] = INT_LARGE;
  dp[1] = 0;

  // DP main
  for (int i = 1; i <= numArray; ++i) {
    chmin<int>(dp[i + 1], dp[i] + abs(height[i + 1] - height[i]));
    chmin<int>(dp[i + 2], dp[i] + abs(height[i + 2] - height[i]));
  }

  // Output
  std::cout << dp[numArray] << std::endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    int n, a[200001];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    int Xor = a[0];
    for (int i = 1; i < n; ++i) Xor = Xor ^ a[i];
    for (int i = 0; i < n; ++i) cout << (Xor ^ a[i]) << " ";
    return 0;
}

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

 int main (void) {
    int a,b,c;
    char dummy;
    int d;
    
    rewind(stdin);
    d = scanf("%d %d %d",&a,&b,&c);
    
    if(a,b,c<1 || a,b,c>100){
      printf("1~100以外の整数は入力しないでください\n");
      exit(0);
      }
      
    if(b-a==c-b){
    printf("YES\n");
    return 0;
    }else{
    printf("NO\n");
    return 0;
    }
   }
    
    
     
      
      
     

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

int main() {
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(), a.end());
  for(int i=0;i<k;i++){
    a.at(n-1-i)=0;
    if(n-1-i==0){
      break;
    }
  }
  long long sum=0;
  for(int i=0;i<n;i++){
    sum=sum+a.at(i);
  }
  cout<<sum;
}

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

using namespace std;
#define ll long long
const long double EPS = 1e-8;
const long double PI = acos(-1);
const int N = 1e5 + 9;
ll arr[109][2];
ll mem[N];
int n, k;

const ll inf = 1e14 + 7LL;

ll solve() {
    for (int i = 0; i < N; i++)mem[i] = inf;
    mem[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = N - 1; j > -1; j--) {
            if (j - arr[i][1] > -1)
                mem[j] = min(mem[j], mem[j - arr[i][1]] + arr[i][0]);
        }
    }
    for (ll i = N - 1; i > -1; i--)
        if (mem[i] <= k)return i;
}

int main() {

    scanf("%d%d", &n, &k);

    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &arr[i][0], &arr[i][1]);
    }

    printf("%lld\n", solve());
}


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

long long cum[100010],cum_p[100010];
int main(void){
	int n,k; scanf("%d%d",&n,&k);
	vector<long long> a(n);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<n;i++){
		cum[i+1] = cum[i]+a[i];
		cum_p[i+1] = cum_p[i] + max(0LL,a[i]);
	}
	long long ans = -(long long)1e15;
	for(int i=0;i<=n-k;i++){
		long long res = (cum_p[i]-cum_p[0])+max(0LL,cum[i+k]-cum[i])+(cum_p[n]-cum_p[i+k]);
	 	ans = max(ans,res);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
ll n,c=0;
cin>>n;
ll a[n];
for(int i=0;i<n;i++)
{
  cin>>a[i];
}
for(int i=1;i<n;i++)
{
  if(a[i]>a[i-1])
  {  c++;

    for(int j=i+1;j<n;j++)
    {
      if(a[j]>=a[j-1])
        {i=j;
        continue;
      }
      else
      {
        //c++;
        i=j;
        if(i==n-1)
        {  //cerr<<"ajit"<<endl;
            c++;
        }
        break;
      }
      i=j;
      if(i==n-1)
      {
        //cerr<<"dollar"<<endl;
        c++;
      }
    }
    //cerr<<"IF = "<<i<<" "<<c<<endl;

  }
  else if(a[i]<a[i-1])
  {  c++;
    
    for(int j=i+1;j<n;j++)
    {
      if(a[j]<=a[j-1])
       {i=j;
        
        continue;
       }
      else
      {
        
        i=j;
        if(i==n-1)
         {//cerr<<"trivedi"<<endl;
              c++;
         }
        break;
      }
      i=j;
      if(i==n-1)
      {//cerr<<"paisa"<<endl;
        c++;
      }
    }
   // cerr<<i<<" "<<c<<endl;
  }

}
cout<<max(1ll,c)<<endl;
}
return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

void a();
void b();

int main()
{
	b();
    return 0;
}

void a()
{
	int A, B;
	cin >> A >> B;
	if (A + B >= 10)
	{
		cout << "error" << endl;
	}
	else {
		cout << A + B << endl;
	}
	return;
}

void b()
{
	string S;
	cin >> S;
	for (int i = 0; i < S.size() - 1; i++)
	{
		for (int j = i + 1; j < S.size(); j++)
		{
			if (S[i] == S[j])
			{
				cout << "no" << endl;
				return;
			}
		}
	}
	cout << "yes" << endl;
	return;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

        int n = Integer.parseInt(s.next());
        int k = Integer.parseInt(s.next());

        int[] h = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(s.next());
        }

        int[] sored = Arrays.stream(h).sorted().toArray();

        int min = 999999999;

        for (int i = 0; i < n - k + 1; i++) {
            int tmp = Math.abs(sored[i] - sored[i + k - 1]);
            if (min > tmp) {
                min = tmp;
            }
        }

        System.out.println(min);
    }
}

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

int main(int argc, char const *argv[])
{
    long n;
    cin >> n;
    int t;

    vector<long long> vec(n, 0);
    for (int i = 1; i < n; i++)
    {
        cin >> t;
        vec.at(t - 1)++;
    }
    for (int i = 0; i < n; i++)
    {
        cout << vec.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << min(a,b) + min(c,d) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) cin >> S[i];

    int cnt = 0;
    vector<int> A(5);
    vector<bool> B(5, false);
    REP(i, N) {
        if (S[i][0] == 'M') {
            A[0]++;
            B[0] = true;
        }
        if (S[i][0] == 'A') {
            A[1]++;
            B[1] = true;
        }
        if (S[i][0] == 'R') {
            A[2]++;
            B[2] = true;
        }
        if (S[i][0] == 'C') {
            A[3]++;
            B[3] = true;
        }
        if (S[i][0] == 'H') {
            A[4]++;
            B[4] = true;
        }
    }

    REP(i, 5) if (B[i]) cnt++;

    ll ans = 0;
    if (cnt == 3) {
        ans = 1;
        REP(i, 5) if (A[i] > 0) ans *= (ll)A[i];
    } else if (cnt > 3) {
        REP(bit, (1 << 5)) {
            int a  = 0;
            ll sum = 1;
            REP(i, 5) {
                if (bit & (1 << i)) {
                    a++;
                    sum *= (ll)A[i];
                }
            }
            if (a == 3)
                ans += sum;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
import numpy as np

N, T = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
# dp は0からT-1まで
dp = np.zeros(T, dtype=np.int32)
temp_ans = 0
for a, b in AB:
    temp_ans = max(temp_ans, dp.max() + b)
    dp[a:] = np.maximum(dp[a:], dp[:-a]+b)
print(temp_ans) 


Measured memory_bytes: 14564
def croad():
    n,k = map(int,input().split())
    x = list(map(int,input().split()))
    y = []
    for i in range(n-1):
        y.append(x[i+1]-x[i])
    y.sort()
    y.reverse()
    while k>1 and len(y)>0:
        y.pop(0)
        k -= 1
    print(sum(y))

a = int(input())
for i in range(a):
    croad()


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

int main() 
{ 
	int n;
	cin >> n;
	int arr[n];
	for(int i=0; i<n; i++)
		cin >> arr[i];
	int c1=0; int c2=0;
	for(int i=0; i<n; i++) {
		if(arr[i]%2==0) {
			if(arr[i]%3==0)
				c2++;
			else if(arr[i]%5==0)
				c2++;
			c1++;
		}
	}
	if(c1!=c2)
		cout << "DENIED\n";
	else
		cout << "APPROVED\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<int>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define mem(a) memset((a),0,sizeof(a))
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
int a,b,c,d;
int main(){
	int T=read();
	while(T--){
		cin>>a>>b>>c>>d;
		int n=a+b,l=0,r=n,k=(max(a,b)+min(a,b))/(min(a,b)+1); //cout<<k<<endl;
		while(l<r){
			int mid=(l+r)>>1; mid++; if(mid%(k+1)==0)mid--;
			int ya=mid/(k+1)*k+mid%(k+1),yb=mid/(k+1);
			if((b-yb)<=(ll)k*(a-ya+1)){l=mid; if((l+1)%(k+1)==0)l++;} else r=mid-1;
			
		}
		int sa=a-l/(k+1)*k-l%(k+1),sb=b-l/(k+1);
		int MID=l+sb-sa*k; //cout<<l<<" "<<MID<<" "<<sb<<" "<<sa<<endl;
		For(i,c,min(d,l))putchar(i%(k+1)?'A':'B');
		For(i,max(c,l+1),min(d,MID))putchar('B');
		For(i,max(MID+1,c),d)putchar((i-MID-1)%(k+1)?'B':'A'); puts("");
	}
}

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

enum SegtreeType{
	CUSTOM,
	RAQ_RMQ,
	RAQ_RSQ,
	RUQ_RMQ,
	RUQ_RSQ,
};
template<SegtreeType ty,class T>
class LazySegtree{
	int n;
	vector<T>dat,lazy;
	T INIT;
	T E0,E1;
	function<T(T,T,int)>F0;
	function<T(T,T)>F1,F2;
public:
	LazySegtree(int n_,T INIT,T E0,T E1
	,function<T(T,T,int)>F0,function<T(T,T)>F1,function<T(T,T)>F2):
		INIT(INIT),E0(E0),E1(E1),F0(F0),F1(F1),F2(F2){
		n=1;while(n<n_)n<<=1;
		dat=lazy=vector<T>(2*n);
		for(int i=0;i<2*n-1;i++){
			dat[i]=INIT;
			lazy[i]=E1;
		}
	}
	LazySegtree(int n_){
		switch(ty){
		case RAQ_RMQ:
			INIT=0;
			E0=numeric_limits<T>::max();
			E1=0;
			F0=[](T a,T b,int s){return a+b;};
			F1=[](T a,T b){return a+b;};
			F2=[](T a,T b){return min(a,b);};
			break;
		}
		n=1;while(n<n_)n<<=1;
		dat=lazy=vector<T>(2*n);
		for(int i=0;i<2*n-1;i++){
			dat[i]=INIT;
			lazy[i]=E1;
		}
	}
	inline void push(int k,int s){
		if(lazy[k]==E1)return;
		dat[k]=F0(dat[k],lazy[k],s);
		if(k<n-1){
			lazy[k*2+1]=F1(lazy[k*2+1],lazy[k]);
			lazy[k*2+2]=F1(lazy[k*2+2],lazy[k]);
		}
		lazy[k]=E1;
	}
	inline void upnode(int k){
		dat[k]=F2(dat[k*2+1],dat[k*2+2]);
	}
	inline void update(int a,int b,T x,int k,int l,int r){
		push(k,r-l);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]=F1(lazy[k],x);
			push(k,r-l);
			return;
		}
		update(a,b,x,k*2+1,l,(l+r)/2);
		update(a,b,x,k*2+2,(l+r)/2,r);
		upnode(k);
	}
	inline T query(int a,int b,int k,int l,int r){
		push(k,r-l);
		if(b<=l||r<=a)return E0;
		if(a<=l&&r<=b)return dat[k];
		T lb=query(a,b,k*2+1,l,(l+r)/2);
		T rb=query(a,b,k*2+2,(l+r)/2,r);
		upnode(k);
		return F2(lb,rb);
	}
	inline void update(int a,int b,T x){
		update(a,b,x,0,0,n);
	}
	inline void update(int a,T x){
		update(a,a+1,x);
	}
	inline T query(int a,int b){
		return query(a,b,0,0,n);
	}
	inline T query(int a){
		return query(a,a+1);
	}
};

int main(){
	int n,q;cin>>n>>q;
	LazySegtree<RAQ_RMQ,int>seg(n);
	rep(i,q){
		int ty;scanf("%d",&ty);
		if(ty==0){
			int l,r,x;scanf("%d%d%d",&l,&r,&x);r++;
			seg.update(l,r,x);
		}
		else{
			int l,r;scanf("%d%d",&l,&r);r++;
			printf("%d\n",seg.query(l,r));
		}
	}
}


Measured memory_bytes: 4996
import java.util.*;

public class Main{
    
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int inf = (int)1e9;
        
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        
        int[] w = new int[n+1];
        int[] e = new int[n+1];
        for(int i=0; i<n; i++){
            w[i+1] = w[i];
            e[i+1] = e[i];
            char c = s.charAt(i);
            if(c=='W'){
                w[i+1]++;
            }else{
                e[i+1]++;
            }
        }
        
        int wal = w[n];
        int eal = e[n];
        int min = (int)1e9;
        for(int i=0; i<n; i++){
            //System.out.println(w[i+1] + ":" + e[i+1]);
            if(s.charAt(i)=='W'){
                int tmp = eal-e[i] + w[i];
                //System.out.println(tmp);
                min = Math.min(min, tmp);
            }else{
                int tmp = eal-e[i+1] + w[i+1];
                //System.out.println(tmp);
                min = Math.min(min, tmp);
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 31648
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int g = sc.nextInt();
    int b = sc.nextInt();
    System.out.println((r*100+g*10+b)%4==0 ? "YES" : "NO");
  }
}


Measured memory_bytes: 35828
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

string l;
ll MOD = 1e9+7;

int main(){
	cin >> l;
	ll n = l.size();

	ll dp[n];
	ll powpow = 1;
	for(ll i = n-1; i >= 0; i--){
		if(i == n-1){
			if(l[i] == '0'){dp[i] = 1;}
			else{dp[i] = 3;}
		}
		else{
			if(l[i] == '0'){dp[i] = dp[i+1];}
			else{
				dp[i] = 2*dp[i+1];
				dp[i] %= MOD;
				dp[i] += powpow;
				dp[i] %= MOD;
			}
		}
		powpow *= 3;
		powpow %= MOD;
	}
	cout << dp[0] << endl;
	return 0;
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

	int ans = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			for(int k = 1;k <= n;k++){
				ans += __gcd(i, __gcd(j, k));
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

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

	long long v1 = b / x + 1;
	long long v2 = 0;
	if (a > 0) {
		v2 = (a - 1) / x + 1;
	}

	long long result = v1 - v2;
	cout << result << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
#define ll long long
using namespace std;

ll a,b;

ll GEt_ans(ll a)
{
	if(a<0)
	return 0;
    if(a%4==1)
        return 1;
    else if(a%4==2)
        return a+1;
    else if(a%4==3||a==0)
        return 0;
    else 
        return a;
}

int main()
{
	scanf("%lld%lld",&a,&b);
	printf("%lld\n",GEt_ans(b) xor GEt_ans(a-1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    cout << v[n-1] - v[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const int MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}


int main(){
    cin >> N >>M;
    set<int> ng;
    REP(i,M){int a; cin >> a; ng.insert(a);}
    vector<ll> dp(N+5);
    dp[0] = 1;
    for(int i = 0; i <= N-1; ++i){
        if(ng.find(i) != ng.end()) continue;
        dp[i+1] += dp[i];
        dp[i+1] %= MOD;
        dp[i+2] += dp[i];
        dp[i+2] %= MOD;
    }
    cout << dp[N];
    return 0;
    
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <long long int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    long long int ans = 0, mn = abs(a[0]), odd = 0;
    for (int i=0; i<n; i++){
        ans += abs(a[i]);
        if (a[i] < 0) odd ++;
        mn = min(mn, abs(a[i]));
    }
    if (odd & 1) ans -= 2*mn;
    cout << ans;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  if(s =="Sunny")cout << "Cloudy" << endl;
  else if(s == "Cloudy")cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	for(;;){
	int n,temp;
	double m=0;
	double alphasqured=0;
	vector<int> s;
	cin >> n;			//母体数の取得
	if(n==0)break;
	s.clear();
	s.reserve(n);		//確保
	for(int i=0;i<n;i++){
		cin >> temp;	//各得点の読み込み
		s.push_back(temp);//コンテナへの書き込み
		m+=(double)temp/n;//平均への追加
	}
	for(int i=0;i<n;i++){	alphasqured+=pow((s.at(i)-m),2)/n;}
	printf("%.4f\n",sqrt(alphasqured));
	}
	return 0;
}

Measured memory_bytes: 1224
f=lambda:map(int,input().split())
A,B,m=f()
a=list(f())
b=list(f())
ans=min(a)+min(b)
for _ in range(m):
    x,y,c=f()
    ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)    

Measured memory_bytes: 24692
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int h = n/3600;
		int m = (n - h*3600)/60;
		int s = (n - h*3600)-m*60;
		
		System.out.println(h+":"+m+":"+s);


		
      
	}
}



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

int main(){
  int N; cin >> N;
  vector<double> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  double up=1;
  double down=0;
  for(int i=0;i<N;i++){
    up*=A[i];
  }
  for(int i=0;i<N;i++){
    down+=up/A[i];
  }
  cout << fixed << setprecision(10);
  cout << up/down << endl;
}
   
    
    
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
struct RMQ{
private:
    int n;
    vector<pair<int,int>> node;
public:
    void rebulid(vector<int> &v){
        int sz=(int)v.size();
        n=1; while(n<sz)n*=2;
        node.resize(2*n-1);
        for(int i=0;i<sz;i++) node[i+n-1]={v[i],i};
        for(int i=n-2;i>=0;i--) node[i]=min(node[2*i+1],node[2*i+2]);
    }
    pair<int,int> query(int a,int b,int idx=0,int l=0,int r=-1){ /* get [a,b) */
        if(r<0) r=n;
        if(r<=a||b<=l) return {1e9,-1};
        if(a<=l&&r<=b) return node[idx];
        pair<int,int> vl=query(a,b,2*idx+1,l,(l+r)/2);
        pair<int,int> vr=query(a,b,2*idx+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

struct LCA{
private:
    int n;
    vector<int> EulerTour,depth,id;
    vector<vector<int>> G;
    RMQ rmq;
    void dfs(int v,int pre,int d){
        id[v]=(int)EulerTour.size();
        EulerTour.push_back(v);
        depth[v]=d;
        for(int u:G[v]){
            if(u!=pre){
                dfs(u,v,d+1);
                EulerTour.push_back(v);
            }
        }
    }
public:
    LCA(int node_size) : n(node_size),G(n), depth(n), id(n, -1){}
    void add(int from,int to){
        G[from].push_back(to);
        G[to].push_back(from);
    }
    void build(){
        EulerTour.reserve(2*n-2);
        for(int i=0;i<n;i++){
            if(id[i]<0){
                dfs(i,-1,0);
            }
        }
        vector<int> vec(2*n-2);
        for(int i=0;i<2*n-2;i++){
            vec[i]=depth[EulerTour[i]];
        }
        rmq.rebulid(vec);
    }
    int lca(int u,int v){
        return EulerTour[rmq.query(min(id[u],id[v]),max(id[u],id[v])+1).second];
    }
    int dist(int u,int v){
        int lc=lca(u,v);
        return depth[u]+depth[v]-2*depth[lc];
    }
};
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    LCA hoge(n);
    rep(i,n){
        int k; cin >> k;
        rep(j,k){
            int a; cin >> a;
            hoge.add(i,a);
        }
    }
    hoge.build();
    int q; cin >> q;
    rep(i,q){
        int a,b; cin >> a >> b;
        cout <<  hoge.lca(a,b) << endl;
    }
}



Measured memory_bytes: 17668
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


ll N;
ll A[300000];
pair<ll, ll> B[300000];
pair<ll, ll> update(pair<ll, ll> p, pair<ll, ll> q){
  vector<ll> x = {p.f, p.s, q.f, q.s};
  sort(x.begin(), x.end());
  return {x[2], x[3]};
}
void solve(){
  cin >> N;
  rep(i, 1<<N) cin >> A[i];
  rep(i, 1<<N) B[i] = {-1, A[i]};
  rep(i, N){
    rep(j, 1<<N)if((j>>i)&1){
      B[j] = update(B[j], B[j - (1<<i)]);
    }
  }
  ll now = -1;
  rep(i, 1<<N){
    if(i == 0) continue;
    now = max(now, B[i].f + B[i].s);
    cout << now << endl;
  }
}


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


Measured memory_bytes: 11264
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N,K = I()
p = l()
p.sort()
print(sum(p[:K]))

Measured memory_bytes: 72668
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, z, w;
int a[2010];

int dpx[2010], dpy[2010];
int calcX(int k);
int calcY(int k);

int calcY(int k) {
    if (dpy[k] < 0) {
        int res = abs(a[k] - a[n]);
        for (int i = k+1; i < n; i++) {
            res = min(res, calcX(i));
        }
        dpy[k] = res;
    }
    return dpy[k];
}


int calcX(int k) {
    if (dpx[k] < 0) {
        int res;
        res = (k == 0 ? abs(w - a[n]): abs(a[k] - a[n]));
        for (int i = k+1; i < n; i++) {
            res = max(res, calcY(i));
        }
        dpx[k] = res;
    }
    return dpx[k];
}

int solve() {
    memset(dpx, -1, sizeof(dpx));
    memset(dpy, -1, sizeof(dpy));
    return calcX(0);
}

void input() {
    cin >> n >> z >> w;
    for (int i = 1; i <= n; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 384
def gcd(a, b):
  while b > 0:
    a, b = b, a % b
  return a

T = int(input())
for _ in range(T):
  A, B, C, D = map(int, input().split())
  if B > D or B > A:
    print('No')
    continue
  if C >= B - 1:
    print('Yes')
    continue
  a = A % B
  step = gcd(B, D)
  k = (B - a + step - 1) // step - 1
  if C - a < k * step:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 3064
# coding: utf-8


def fib(p):
    lst = [1, 2]
    if p >= 1:
        for i in range(p - 2):
            lst.append(lst[i + 1] + lst[i])
        return lst[p - 1]
    elif p == 0:
        return 1
    else:
        print(0)
        exit()


n, m = map(int, input().split())
broken = [int(input()) for i in range(m)]
broken.insert(0, -1)
broken.append(n + 1)
ans = 1
for i in range(1, m + 2):
    ans *= fib(broken[i] - broken[i - 1] - 2)
    ans %= 1000000007


print(ans)


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

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int L=0;
  int D=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='('){
      L++;
    }
    else L--;
    D=min(D,L);
  }
  for(int i=D;i<0;i++){
    cout<<"(";
  }
  cout<<S;
  for(int i=0;i<L-D;i++){
    cout<<")";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N; cin >> N;
 vector<pair<int,int>> to;
  int cnt = 0;
 for(int a = 1; a <= N - 1; a++){
   for(int b = a+1; b <= N; b++){
     if( N % 2 ){ //Nが奇数の時、足してNになるノード同士を結んではならない
       if( a+b != N){ to.push_back(make_pair(a,b)); cnt++;}}
     else{//Nが偶数の時は、足してN+1になるノード同士を結んではならない
       if( a+b != N+1){ to.push_back(make_pair(a,b)); cnt++;}}
   }}
     
     cout << cnt << endl;
     for(int i = 0; i < (int)to.size(); i++){
       cout << to[i].first << " " << to[i].second << endl;}
     
     return 0;}
     
     

Measured memory_bytes: 384
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            long N = in.nextLong();
            long P = in.nextLong();
            long max = 1;
            Map<Long, Integer> divisorToCount = primeFactor(P);
            for (Long divisor : divisorToCount.keySet()) {
                int count = divisorToCount.get(divisor).intValue();
                while (count >= N) {
                    max *= divisor;
                    count -= N;
                }
            }
            System.out.println(max);
        }
    }

    public static final Map<Long, Integer> primeFactor(long n) {
        HashMap<Long, Integer> res = new HashMap<>();
        for (long i = 2; i * i <= n; i++) {
            while (n % i == 0) {
                int count = res.get(i) == null ? 0 : res.get(i).intValue();
                res.put(i, count + 1);
                n /= i;
            }
        }
        if (n != 1) {
            int count = res.get(n) == null ? 0 : res.get(n).intValue();
            res.put(n, count + 1);
        }
        return res;
    }
}


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

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

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

    int h[n];
    rep(i, n) cin >> h[i];

    sort(h, h+n);

    int res = 1e9;
    rep(i, n-k+1){
        res = min(res, h[i+k-1]-h[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 640
def charSort(chr)
  retStr = ""
  chr.each_char { |c|
    if retStr.empty? then
      retStr = c
      next
    end
    for i in 0..(retStr.length - 1) do
      if retStr[i] > c then
        if i == 0 then
          retStr = c + retStr
        else
          retStr = retStr[0..(i-1)] + c + retStr[i..-1]
        end
        break
      else 
        if (i == retStr.length - 1) then
          retStr += c
        end
      end
    end
  }
  return retStr
end

N = STDIN.gets
S = STDIN.gets.chomp
count = 0

for i in 0..(S.length - 1) do
  tmpCount = 0
  a = charSort(S[0..i]).squeeze
  b = charSort(S[i+1..-1]).squeeze
  a.each_char { |ac|
    b.each_char { |bc|
      if ac == bc then
        tmpCount += 1
      end
    }
  }
  tmpCount
  if count < tmpCount then
    count = tmpCount
  end
end

p count


Measured memory_bytes: 1788
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
struct edge{
  int from,to,cost;
};
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
edge es[100001];
int E,V;
ll kruskal(){
  sort(es,es+E,comp);
  init(V);
  ll res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    cout << es[i].cost << endl;
    if(!same(e.to,e.from)){
      unite(e.to,e.from);
      res += e.cost;
    }
  }
  return res;
}

int main()
{
  ll mod,kazu,K,arr[51];
  cin >> K;
  kazu = K/50;
  mod = K%50;
  REP(i,50){
    arr[i] = i+kazu;
  }
  REP(j,mod){
    REP(i,50){
      if(i == j)
        arr[i] += 50;
      else
        arr[i] += -1;
    }
  }
  cout << 50 << endl;
  REP(i,50)
    cout << arr[i] << " ";
  cout << endl;
  
  
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int,string> pairq;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	queue<pairq> que;
	ll n,q,t=0;
	cin >> n >> q;
	for(int i=0;i<n;i++){
		string name;
		ll time;
		cin >> name >> time;
		que.push(pair<int,string>(time,name));
	}

	while(!que.empty()){
		string name = que.front().second;
		ll time = que.front().first;

		time -= q;

		if(time<=0){
			t += que.front().first;
			cout << name << " " << t << endl;
			que.pop();
		}else{
			t += q;
			que.pop();
			que.push(pair<int,string>(time,name));
		}
	}
	return 0;
}

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

    #define ll long long

    using namespace std;


    int e[111], f[111];
    int main(){

   int a, b, c, d = 0, g = 1, h = 0;
   cin >> a >> b >> c;
   for(int i = 1; i <= b; ++i){
    cin >> f[i];
   }
   for(int i = 1; i <= a; ++i){
    for(int j = 1; j <= b; ++j){
        cin >> e[j];
        d = d + (e[j] *  f[g]);
        g++;
    }
    if(d + c > 0){
        h++;
    }
    d = 0;
    g = 1;

   }
   cout << h;
    return 0;


    }



Measured memory_bytes: 256
# coding: utf-8
import queue

class Node:
    def __init__(self, myNum, childNums):
        self.myNum = myNum
        self.parentNum = -1
        self.childNums = childNums
        self.nodeType = ""
        self.depth = -1
        
n = int(input().rstrip())
nodes = []
# 入力を使ってクラスに放り込む
for i in range(n):
    line = [int(i) for i in input().rstrip().split()]
    childNums = [i for i in line[2:]]
    nodes.append(Node(line[0],childNums))
# nodesを節点順にソートする
nodes = sorted(nodes,key=lambda x: x.myNum)
# 親を計算する
for node in nodes:
    for num in node.childNums:
        nodes[num].parentNum = node.myNum

# type を求める
for node in nodes:
    if node.parentNum == -1:
        node.nodeType = "root"
        rootNum = node.myNum
    elif not node.childNums:
        node.nodeType = "leaf"
    else:
        node.nodeType = "internal node"
        
# depth を計算する
q = queue.Queue()
q.put(nodes[rootNum])
nodes[rootNum].depth=0
while not q.empty():
    nd = q.get()
    for c in nd.childNums:
        nodes[c].depth = nd.depth + 1
        q.put(nodes[c])

#アウトプット
for node in nodes:
    print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(node.myNum,node.parentNum,node.depth,node.nodeType,node.childNums))


Measured memory_bytes: 40024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define double long double
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;
const double EPS = 1e-9;

int m, n;
double p[17][17];
double memo[1LL << 16][17];

double rec(int mask, int id){
    if(id == n){
        // cout << mask << ' ' << id << ' ' << 1.0 << endl;
        return 1.0;
    }
    if(mask == 0){
        // cout << mask << ' ' << id << ' ' << 0.0 << endl;
        return 0.0;
    }
    if(memo[mask][id] > -EPS) return memo[mask][id];
    double res = 0.0;
    rep(i, 0, m){
        if(!(mask & (1LL << i))) continue;
        double tmp = 0.0, now = 1.0;
        rep(j, id, n){
            // j番目に負けた場合
            tmp += now * (1 - p[i][j]) * rec(mask - (1LL << i), j);
            now *= p[i][j];
        }
        tmp += now;
        // tmp = p[i][id] *  rec(mask - (1LL << now), i, id);
        res = max(res, tmp);
    }
    // res = p[now][id] * rec(mask, now, id + 1) + (1 - p[now][id]) * res;
    // cout << mask << ' ' << id << ' ' << res << endl;
    return memo[mask][id] = res;
}

int main(){
    cin >> m >> n;
    rep(i, 0, m){
        rep(j, 0, n){
            cin >> p[i][j];
        }
    }
    rep(i, 0, 1 << m) rep(k, 0, n + 1) memo[i][k] = -1.0;
    double ans = 0.0;
    ans = rec((1LL << m) - 1, 0);
    printf("%.20Lf\n", ans);
}


Measured memory_bytes: 20700