akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct _n {
  int deg;
  int right;
  int left;
  int r;
  int parent;
  int sib;
  int depth;
  int height;
} node;

//接点を格納する配列
node tree[100000];
int n;
//関数のプロトタイプ宣言
void setDepth(int);
int setHeight(int);
int main() {
  int i, j, k, l, r;
  //nを受け取る
  scanf("%d", &n);
  //木構造の各接点の情報を初期化
  for(i = 0; i < n; i++) {
    tree[i].parent = -1;
    tree[i].sib = -1;
    tree[i].depth = 0;
    tree[i].height = 0;
    tree[i].deg = 0;
  }
  //n行の入力を処理する（kでループしているがkは使わない）
  for(k = 0; k < n; k++) {
    //何番めの接点かをiに格納
    scanf("%d", &i);
    //接点の配列に、子を格納
    scanf("%d %d", &tree[i].left, &tree[i].right);
    //子の兄弟を設定
    if(tree[i].left != -1) tree[tree[i].left].sib = tree[i].right;
    if(tree[i].right != -1) tree[tree[i].right].sib = tree[i].left;
    //子に親を設定
    if(tree[i].left != -1)tree[tree[i].left].parent = i;
    if(tree[i].right != -1) tree[tree[i].right].parent = i;
    //子の数を設定
    if(tree[i].left != -1) tree[i].deg++;
    if(tree[i].right != -1) tree[i].deg++;
  }
  //kにrootとなる接点が配列の何番目にあるかを代入
  for(i = 0; i < n; i++) {
    if(tree[i].parent == -1) k = i;
  }
  //再帰関数を呼び出す（この関数で全てのtree[x].depthを設定）
  setDepth(k);
  //heightを設定する関数を呼び出す
  setHeight(k);
  //出力
  for(i = 0; i < n; i++) {
    //共通部分
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
	   i, tree[i].parent, tree[i].sib, tree[i].deg, tree[i].depth, tree[i].height);
    
    //ここから接点の種類により分岐
    
    //接点の親が最初の-1から変わっていない場合それがrootとなる
    if(tree[i].parent == -1) {
      printf("root\n");
    }
    //子の数が0のときはleaf
    else if(tree[i].deg == 0) {
      printf("leaf\n");
    }
    /* leafでない場合internal nodeかrootになるが、
       rootの分岐は先に済ませたのでその他の場合　つまりinternal nodeの場合 
    */
    else {
      printf("internal node\n");
    }
  }
  return 0;
}

void setDepth(int r) {
  //引数は木構造のさくらんぼの繋がってる部分のイメージ（？）
  //tree[r]のそれぞれの子に、tree[r]の深さ+1をセット;
  if(tree[r].right != -1 )tree[tree[r].right].depth += 1 + tree[r].depth;
  if(tree[r].left != -1) tree[tree[r].left].depth += 1 + tree[r].depth;
  /* tree[r]のそれぞれの子から先の深さを決めるため、
     再帰的に関数を呼び出す
  */
  if(tree[r].left != -1) setDepth(tree[r].left);
  if(tree[r].right != -1) setDepth(tree[r].right);
}
int setHeight(int r) {
  int i, h=0, hl, hr, n;
  if(tree[r].deg == 0) {
    tree[r].height = 0;
    return 0;
  }
  if(tree[r].left != -1) hl = setHeight(tree[r].left);
  else hl = 0;
  if(tree[r].right != -1) hr = setHeight(tree[r].right);
  else hr = 0;
  h = (hl < hr)? hr: hl;
  h++;
  tree[r].height = h;
  return h;
}



Measured memory_bytes: 2756
A=int(input())
B=int(input())
C=int(input())
X=int(input())

ans=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                ans+=1
print(ans)            

Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

const int Maxn = 2e5 + 5;

int n;
int a[Maxn];
long long ans;

int main() {	
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	for (int i = 2; i <= n; i ++) {
		if (a[i] >= a[i - 1]) continue;
		ans += a[i - 1] - a[i];
		a[i] = a[i - 1];
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 2516
#include<stdio.h>
int main(void)
{
  int X;
  long long A,B;
  while(scanf("%d",&X)!=0)
  {
    for(A=0;!0;A++)for(B=0;B<A;B++)
    {
      if(A*A*A*A*A-B*B*B*B*B==X)return printf("%lld %lld\n",A,B),0;
      else if(A*A*A*A*A+B*B*B*B*B==X)return printf("%lld %lld\n",A,-B),0;
    }
  }
}

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

int main() {
    long long a, b, k;
    cin >> a >> b >> k;
    long long ans_a = max(0ll, a-k);
    long long ans_b = max(0ll, b - max(0ll, k-a));
    cout << ans_a << " " << ans_b << endl;
    return 0;
}

Measured memory_bytes: 256
k = int(input())
s = input()

mod = 10**9+7

def fpow(x, y):
  res = 1
  while y>0:
    if y%2 == 1:
      res = (res%mod * x%mod)%mod
    x = (x%mod * x%mod)%mod
    y = y//2
  return res
MAXN = 2000005
fact = [0]*MAXN
fact[0] = 1
for i in range(1, MAXN):
  fact[i] = (i%mod * fact[i-1]%mod)%mod
  
def inv(a):
  return fpow(a, mod-2)
  
n = len(s)
ans = fpow(26, n+k)
for m in range(n):
    ncm = (fact[n+k]%mod * inv(fact[m])%mod)%mod
    ncm = (ncm%mod * inv(fact[n+k-m])%mod)%mod
    
    p = fpow(25, n+k-m)
    
    val = (ncm%mod * p%mod)%mod
    
    ans = (ans%mod - val%mod + mod)%mod
print(ans%mod)

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

int top1 = 0, top2 = 0, S1[20000];
struct A{int first; int area;};
struct A S2[20000];
void push1(int x) {
        S1[top1] = x;
        top1++;
}
void push2(int x, int y) {
        S2[top2].first = x;
        S2[top2].area = y;
        top2++;
}
int pop1() {
        top1--;
        return S1[top1];
}
struct A pop2() {
        top2--;
        return S2[top2];
}


int main() {
        string str;
        int sum = 0, j;
        struct A temp;
        cin >> str;
        for(int a = 0; a < str.length(); a++) {
                char d = str.at(a);
                if(d == '\\') push1(a);
                else if(top1 == 0);
                else if(d == '/') {
                        j = pop1();
                        sum += (a - j);
                        temp.first = j; temp.area = a - j;
                        for(int b = top2 - 1; b >= 0; b--) {
                                if(S2[b].first < a && S2[b].first > j) {
                                        temp.area += pop2().area;
                                }
                        }
                        push2(temp.first, temp.area);
                }
        }
        cout << sum << endl;
        cout << top2;
        for(int c = 0; c < top2; c++) {
                cout << " " << S2[c].area;
        }
        cout << endl;
        return 0;
}


Measured memory_bytes: 3280
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long N;
    cin >> N;
    for(long long h = 1; h <= 3500; h++){
        for(long long n = 1; n <= 3500; n++){
            if((4 * h * n - (n + h) * N)> 0 && (h * n * N) % (4 * h * n - (n + h) * N) == 0){
                cout << h << " " << n << " " << (h * n * N) / (4 * h * n - (n + h) * N)<<endl;;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
if __name__ == "__main__":
    H,W = map(int,input().split())
    V = 10
    edges = []
    for i in range(10):
        c = list(map(int,input().split()))
        edges.append([(j,c[j]) for j in range(10)])
    INF = float("inf")
    dp = [[INF]*V for _ in range(V)]
    for i in range(V):
        for j, w in edges[i]:
            dp[i][j] = w

    for k in range(V):
        for i in range(V):
            for j in range(V):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    ans = 0
    for _ in range(H):
        for x in map(int,input().split()):
            if x >= 0:
                ans += dp[x][1]
    print(ans)

Measured memory_bytes: 9268
R, C = [int(i) for i in input().split()]

s = []

for r in range(R):
    s.extend([int(i) for i in input().split()])
    
for r in range(R):
    row = s[r*C:r*C+C]
    row.append(sum(row))
    print(*row)

footer = [sum(s[c::C]) for c in range(C)]
footer.append(sum(footer))
print(*footer)


Measured memory_bytes: 6280
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
const int mod = 1000000007;
int test[345678];
long long gcd(long long a, long long b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
signed main() {
	int n, m, k, a, cnt = 0; string s; cin >> n;
	for (int h = 1; h <= n; h++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				cnt += gcd(h, gcd(i, j));
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int vmin(vector<int> v){
  int ans=1000000;
  for(int i=0;i<v.size();i++){
    ans=min(ans,v.at(i));
  }
  return ans;
}
int main() {
  int A,B,M;
  cin >> A >> B >> M;
  vector<int> a(A),b(B),x(M),y(M),c(M);
  for(int i=0;i<A;i++)cin >> a.at(i);
  for(int i=0;i<B;i++)cin >> b.at(i);
  for(int i=0;i<M;i++){
    cin >> x.at(i) >> y.at(i) >> c.at(i);
  }
  int ans=vmin(a)+vmin(b);
  for(int i=0;i<M;i++){
    ans=min(ans,a.at(x.at(i)-1)+b.at(y.at(i)-1)-c.at(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll k;
string s;
 
int main() {
  cin>>k;
  cin>>s;
  int p=s.length();
  for (int i=0; i<p; i++) {
    if (i<k) cout<<s[i];
  }
  if (p>k) cout<<"...";
  cout<<endl;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    int n;
    std::cin >> n;

    int happiness = 0;
    happiness += n / 500 * 1000;
    n %= 500;
    happiness += n / 5 * 5;
    std::cout << happiness << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

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

		 String b = scan.next();

		 if(b.equals("A")) {
			 System.out.println("T");
		 }
		 if( b.equals("T")){
			 System.out.println("A");
		 }
		 if(b.equals("G")){
			 System.out.println("C");
		 }
		 if(b.equals("C")){
			 System.out.println("G");
		 }

	}

}

Measured memory_bytes: 23124
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
inline int  in(){int n;scanf("%lld",&n);return n;}
inline void out(int n){printf("%lld\n",n);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;
vi vec;
int mx=-1, mn=INF;

signed main(){
    io();
    cin>>n;
    vec.resize(n);
    rep(i,n) {
        cin>>vec[i];
        mx=max(mx,vec[i]);
        mn=min(mn,vec[i]);
    }
    cout<<mx-mn<<endl;

    return 0;
}


Measured memory_bytes: 888
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;


int N;

signed main()
{
	vector<int> v;

	cin >> N;
	REP(i, N)
	{
		int l;
		cin >> l;
		v.push_back(l);
	}

	RSORT(v);

	int sum = 0;
	for (int i = 1; i < N; i++)
	{
		sum += v[i];
	}

	if (v[0] < sum)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}









Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

string S;
char c;
inline void solve(){
  IN(S);
  for(c='a';c<='z';c++){
    if(!count(ALL(S),c)){
      OUT(c);
      return;
    }
  }
  OUT("None");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a,b,k;
  cin >> a >> b >> k;
  for(int i=0; i<k; i++) {
    if(i%2==0) {
      if(a%2==0) {
        b+=a/2;
        a/=2;
      }
      else {
        b+=(a-1)/2;
        a=(a-1)/2;
      }
    }
    else {
      if(b%2==0) {
        a+=b/2;
        b/=2;
      }
      else {
        a+=(b-1)/2;
        b=(b-1)/2;
      }
    }
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int N,i,ans;
	scanf("%d",&N);
	ans = N;
	for(i=0;i<=N;i++){
		int cc=0;
		int t=i;
		while(t>0){
			cc+=t%6;
			t/=6;
		}
		t=N-i;
		while(t>0){
			cc+=t%9;
			t/=9;
		}
		if( ans>cc){
			ans = cc;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
num_city, num_train, num_question = [int(i) for i in input().split()]

#電車の数
trains = [[0] * (num_city + 1) for i in range(0, num_city + 1)]
for i in range(0, num_train):
    start, arrive = [int(j) for j in input().split()]
    trains[start][arrive] += 1

#累積和表を作る
cumlative_sum = [[0] * (num_city + 1) for i in range(0, num_city  + 1)]
for start in range(0, num_city + 1):
    for arrive in range(0, num_city + 1):
        cumlative_sum[start][arrive] = cumlative_sum[start][arrive - 1] + trains[start][arrive]

for start in range(0, num_city + 1):
    for arrive in range(0, num_city + 1):
        cumlative_sum[start][arrive] += cumlative_sum[start - 1][arrive]

for i in range(0, num_question):
    start, arrive = [int(j) for j in input().split()]
    result = cumlative_sum[arrive][arrive] - cumlative_sum[start - 1][arrive] - cumlative_sum[arrive][start - 1] + cumlative_sum[start - 1][start - 1]
    print(result)


Measured memory_bytes: 15320
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int cnt = 0;
		for(int i =0;i<10;i++)
			for(int j=0;j<10;j++)
				for(int k=0;k<10;k++)
					for(int q=0;q<10;q++)
						if(i + j + k + q == n)
							cnt++;
							
						
		cout<<cnt<<endl;
	}
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
int n,a[100005],val[100005];
vector<int>edge[100005];
map<int,vector<int> >M;
int main(){
	cin>>n;
	repn(i,n){
		cin>>a[i];
		M[a[i]].pb(i);
	}
	rep(i,n-1){
		int x,y;cin>>x>>y;
		edge[x].pb(y);
		edge[y].pb(x);
	}
	for(map<int,vector<int> >::iterator it=M.begin();it!=M.end();++it){
		vector<int>&vi = it->sc;
		vector<P>zip;
		rep(i,vi.size()){
			int x = vi[i];
			bool ok = 0;
			rep(j,edge[x].size()){
				if(val[edge[x][j]] == -1) ok = 1;
			}
			if(ok) zip.pb(mp(x,1));
			else zip.pb(mp(x,-1));
		}
		rep(i,zip.size()){
			val[zip[i].fi] = zip[i].sc;
		}
	}
	repn(i,n) if(val[i] == 1) cout << i << " ";
	cout<<endl;
}

Measured memory_bytes: 3072
import java.util.*

fun main(args:Array<String>):Unit {
    while (true){
        val r = readLine()!!.trim().toInt()
        if (r == 0) return
        val (w1, h1, x1, y1) = readLine()!!.trim().split(' ').map(String::toInt)
        val office1 = Array(h1){readLine()!!.trim().split(' ').map(String::toInt).toIntArray()}
        val (w2, h2, x2, y2) = readLine()!!.trim().split(' ').map(String::toInt)
        val office2 = Array(h2){readLine()!!.trim().split(' ').map(String::toInt).toIntArray()}
        val office1Level = calRLevel(office1, Point(x1 - 1, y1 - 1))
        val office2Level = calRLevel(office2, Point(x2 - 1, y2 - 1))
        var minRLevel = Int.MAX_VALUE
        val maxSize = minOf(r, w1 * h1)
        val minSize = maxOf(0, r - w2 * h2)
        for (i in minSize .. maxSize){
            if (minRLevel > office1Level[i] + office2Level[r - i])
                minRLevel = office1Level[i] + office2Level[r - i]
        }
        println(minRLevel)
    }
}
data class Point(val x:Int, val y:Int) {
    operator fun plus(that:Point):Point = Point(x + that.x, y + that.y)
}
fun Point.neighbors():Iterable<Point> {
    return listOf(Point(1, 0), Point(0, 1), Point(-1, 0), Point(0, -1)).map{it + this}
}
fun calRLevel(securityLevels:Array<IntArray>, start:Point):IntArray{
    val height = securityLevels.size
    val width = securityLevels.first().size
    val res = IntArray(height * width + 1){0}
    val queue = PriorityQueue<Pair<Int, Point>>(compareBy(Pair<Int, Point>::first))
    val isSearched = Array(height){BooleanArray(width){false}}
    isSearched[start.y][start.x] = true
    queue.add(Pair(securityLevels[start.y][start.x], start))
    var max = 1
    var idx = 1
    while (queue.isNotEmpty()){
        val top = queue.remove()
        if (max < top.first)
            max = top.first
        res[idx++] = max
        top.second.neighbors().forEach {
            if (it.x in 0 until width && it.y in 0 until height && !isSearched[it.y][it.x]){
                isSearched[it.y][it.x] = true
                queue.add(Pair(securityLevels[it.y][it.x], it))
            }
        }
    }
    return res
}


Measured memory_bytes: 166340
/***************************************************************
	File name: F.cpp
	Author: huhao
	Create time: Mon 08 Jun 2020 02:46:44 PM CST
***************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=r*10+c-48;
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=1<<16|10,M=40,mod=1000000007;
i64 power(i64 a,i64 b,i64 p)
{
	i64 r=1;
	for(;b;b>>=1,a=a*a%p) if(b&1) r=r*a%p;
	return r;
}
i64 inv(i64 a){ return power(a,mod-2,mod); }
i64 n,m,a[N],ans,f[M][N];
namespace C
{
	i64 f[N],F[N];
	void init(int n)
	{
		f[0]=1; fr(i,1,n) f[i]=f[i-1]*i%mod;
		F[n]=inv(f[n]); fd(i,n,1) F[i-1]=F[i]*i%mod;
	}
	i64 C(i64 a,i64 b){ return a>=b&&b>=0?f[a]*F[b]%mod*F[a-b]%mod:0; }
}
i64 &Add(i64 &a,i64 b){ return a=(a+b)%mod; }
int main()
{
	n=read(); m=read(); C::init(1<<n);
	fr(i,0,m-1) a[m-i]=read();
	f[0][0]=1;
	fr(i,1,m) fr(j,0,(1<<n)-1)
	{
		Add(f[i][j],f[i-1][j]);
		fr(k,0,n-1) if(!((j>>k)&1)) Add(f[i][j|(1<<k)],-f[i-1][j]*C::C((1<<n)-j-a[i],(1<<k)-1)%mod*C::f[1<<k]);
	}
//	fr(i,0,(1<<n)-1) printf("%lld%c",f[m][i]*C::f[(1<<n)-1-i]%mod,i==end_i?'\n':' ');
	fr(i,0,(1<<n)-1) Add(ans,f[m][i]*C::f[(1<<n)-1-i]);
	printf("%lld\n",(ans*(1<<n)%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 9856
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
public class Main {
	static List<Long> a;
	static List<Long> b;
	static List<Long> c;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int k = sc.nextInt();
		a = new ArrayList<>();
		b = new ArrayList<>();
		c = new ArrayList<>();
		for(int i =0; i < x; i++)
			a.add(Long.parseLong(sc.next()));
		for(int i = 0; i < y; i++)
			b.add(Long.parseLong(sc.next()));
		for(int i = 0; i < z; i++)
			c.add(Long.parseLong(sc.next()));
		
		Collections.sort(a, Collections.reverseOrder());
		Collections.sort(b, Collections.reverseOrder());
		Collections.sort(c, Collections.reverseOrder());
		
		List<Long> ab = new ArrayList<>();
		for(int i = 0; i < x; i++)
			for(int j = 0; j < y; j++)
				ab.add(a.get(i) + b.get(j));
		Collections.sort(ab, Collections.reverseOrder());
		int size = Math.min(k, ab.size());
		List<Long> abc = new ArrayList<>();
		
		for(int i = 0; i < size; i++) 
			for(int j = 0; j < z; j++)
				abc.add(ab.get(i) + c.get(j));
		
		Collections.sort(abc, Collections.reverseOrder());

		for(int i = 0; i < k; i++)
			System.out.println(abc.get(i));
	}
}

class Scanner {
	private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	private static final int SPACE = (int)' ';
	private static final int LINE_END_0 = 13;
	private static final int LINE_END_1 = 10;
	private static final int BEFORE = -1;
	
	public boolean ready() {
		try {
			return br.ready();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	
	public String next(){
		StringBuilder sb = new StringBuilder();
		
		int length = BEFORE;
		readLoop: while(true) {
			try {
				int value = br.read();
				switch(value) {
				case LINE_END_1:
					if(length == BEFORE)
						break;
					
					if((int)sb.charAt(length) == LINE_END_0)
						sb.deleteCharAt(length);
				case SPACE:
					break readLoop;
				}
				sb.append((char)value);
				length++;

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
}

Measured memory_bytes: 189392
N, X = map(int, input().split())
Llist = [int(i) for i in input().split()] 
Dlist = []

for i in range(N+1):
  if i == 0:
    Dlist.append(0)
  else:
    Dlist.append(Dlist[i-1]+Llist[i-1])


print(len([i for i in Dlist if i <= X])) 

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  if(N <= 26) {
    cout << char('a'+N-1) << endl;
    return 0;
  }
  ll tmp = 0;
  ll pw = 1;
  int d = 0;
  while(N > tmp) {
    pw *= 26;
    tmp += pw;
    d++;
  }
  string ans(d, ' ');
  ll M = N-tmp/26;
  rep(i, d) {
    ans[i] = 'a' + M % 26;
    M /= 26;
  }
  reverse(all(ans));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
# coding: utf-8

n = int(input())
d = len(str(n))
ans = 0

if d == 1:
  print(n)
else:
  for i in range(1, d+1):
    if i % 2 == 0:
      continue

    if i == d:
      ans += n - (10**(i-1)) + 1
      break;

    if i == 1:
      ans += 9
    else:
      ans += (10**i) - (10**(i-1))

  print(ans)

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

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

using namespace std;

int main(){
  int h,w;cin>>h>>w;
  vector<string> ss;
  rep(i,h){
    string t;cin>>t;
    ss.push_back(t);
  }

  rep(i,h){
    rep(j,w){
      if(ss[i][j]=='#'){
        cout<<'#';
        continue;
      }
      int result=0;
      if(i-1>=0 && j-1>=0 && ss[i-1][j-1]=='#')result++;
      if(i-1>=0 && ss[i-1][j]=='#')result++;
      if(i-1>=0 && j+1<w && ss[i-1][j+1]=='#')result++;
      if(j+1<w && ss[i][j+1]=='#')result++;
      if(i+1<h && j+1<w && ss[i+1][j+1]=='#')result++;
      if(i+1<h && ss[i+1][j]=='#')result++;
      if(i+1<h && j-1>=0 && ss[i+1][j-1]=='#')result++;
      if(j-1>=0 && ss[i][j-1]=='#')result++;
      cout<<result;
    }
    cout<<endl;
  }
  

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

  int n;
  cin>>n;
  std::vector<int> a(n);
  std::vector<int> origin(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    origin[i]=a[i];
  }

  std::sort(a.begin(), a.end(), std::greater<int>());
  int max=a[0];

  for(int i=0;i<n;i++){
    if(max==origin[i]){
      cout<<a[1]<<endl;
    }else{
      cout<<max<<endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

constexpr lint INF = 1LL << 60;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<plint> LR(N);
    REP(i, N) cin >> LR[i].first >> LR[i].second;
    sort(LR.begin(), LR.end(), [](plint l, plint r) { return l.first + l.second > r.first + r.second; });

    vector<pint> w(N, pint(N / 2, N / 2));
    REP(i, N / 2)
    {
        w[i] = make_pair(i, i + 1);
        w[N - 1 - i] = make_pair(i + 1, i);
    }
    vector<lint> dp(N + 1, INF);
    dp[0] = 0;
    REP(i, N)
    {
        IREP(j, i + 1)
        {
            mmin(dp[j + 1], dp[j] + LR[i].first * w[j].first + LR[i].second * w[j].second);
            dp[j] += LR[i].first * w[N - 1 - i + j].first + LR[i].second * w[N - 1 - i + j].second;
        }
    }
    cout << *min_element(dp.begin(), dp.end()) << endl;
}


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

int main(){
    int count[5][4][11], n;
    
    for(int i = 1; i <= 4; i++){
        for(int j = 1; j <= 3; j++){
            for(int k = 1; k <= 10; k++){
                count[i][j][k] = 0;
            }
            
        }
    }
    
    cin >> n;
    for(int i = 0; i < n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        count[b][f][r] += v; 
    }

    for(int f = 1; f <=4; f++){
        if (f > 1) cout << "####################\n";
        for(int b = 1; b <= 3; b++){
            for(int r = 1; r <= 10; r++){
                cout << " " << count[f][b][r];
            }
            cout << endl;
        }
    }
    return 0;

}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;  

int main()
{
  fastio;
  string s;
  cin>>s;
  int n=s.length();
  ll sum=0;
  int i=0;
  while(i<n)
  {
    ll cnt1=0,cnt2=0;
    while(i<n&&s[i]=='<')
    {
      cnt1++;
      i++;
    }
    while(i<n&&s[i]=='>')
    {
      cnt2++;
      i++;
    }

    if(cnt1>cnt2)
    {
      cnt2--;
    }
    else
    {
      cnt1--;
    }
    sum+=(cnt2*(cnt2+1)/2);
    sum+=(cnt1*(cnt1+1)/2);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3900
use std::vec::Vec;
use std::cmp::*;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, k) = {
      let v: Vec<usize> =read_vec();
      (v[0], v[1])
    };

    let mut ans: u64 = 0;
    for b in 1..n+1 {
      let p = n / b;
      let r = n % b;
      ans += max(0, r as i64- k as i64 + 1) as u64 + p as u64 * max(0, b as i64 - k as i64) as u64;
    }
    if k == 0 {
      ans -= n as u64;
    }
    println!("{}", ans);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
		vector<pair<char,int>> vp(26);
	for(int i=0;i<26;i++)
	{
		vp[i].first = 'a'+i;
	}
	char s[1300];
	while(scanf("%s",s)!=EOF)
	{
		
		for(int i = 0;i<strlen(s);i++)
		{
			for(int j = 0;j<26;j++)
			{
				if(s[i]==vp[j].first||s[i]+32==vp[j].first)vp[j].second++;
			}
		}
	}

	for(int i = 0;i< 26;i++)
	{
		cout<<(char)('a'+i)<<" : "<<vp[i].second<<endl;
	}
	return 0;
}


Measured memory_bytes: 3244
#include<iostream>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
using namespace std;

#define LL long long int
#define uLL unsigned long long int

#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SLL(a) scanf("%lld",&a)
#define SLL2(a,b) scanf("%lld%lld",&a,&b)
#define SLL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define SC(a) scanf("%c",&a)
#define P(a) printf("%d",a)
#define PS(a) printf("%s",a)
#define PLL(a) printf("%lld",a)
#define PCASE(kk) printf("Case %d: ",kk++)
#define PCASENL(kk) printf("Case %d:\n",kk++)
#define NL puts("")

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pi (2.0*acos(0.0))
#define pii pair<int,int>

template<typename T>inline T POW(T B,T P)
{
    if(P==0) return 1;
    if(P&1) return B*POW(B,P-1);
    else return SQR(POW(B,P/2));
}
template <class T> inline T BMOD(T p,T e,T m)
{
    T ret=1;
    while(e)
    {
        if(e&1) ret=(ret*p)%m;
        p=(p*p)%m;
        e>>=1;
    }
    return (T)ret;
}
template <typename T>inline T ModInv (T b,T m)
{
    return BMOD(b,m-2,m);
}
template<typename T>inline T ABS(T a)
{
    if(a<0)return -a;
    else return a;
}
template<typename T>inline T gcd(T a,T b)
{
    if(a<0)return gcd(-a,b);
    if(b<0)return gcd(a,-b);
    return (b==0)?a:gcd(b,a%b);
}
template<typename T>inline T lcm(T a,T b)
{
    if(a<0)return lcm(-a,b);
    if(b<0)return lcm(a,-b);
    return a*(b/gcd(a,b));
}


//for(__typeof(pp.begin()) i=pp.begin(); i!=pp.end(); i++ )

//knight and king move....



//int Dx[]={-2,-1,1,2,1,2,-2,-1};
//int Dy[]={-1,-2,2,1,-2,-1,1,2};
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
//int dx[]= {-1,-1,0,0,1,1};
//int dy[]= {-1,0,-1,1,0,1};
/////////////

int arr[11],cs[11],n;

LL dp[12][12];

LL go(int mask)
{
    LL ret=0;

    for(int i=0;i<n;i++)
    {
        if(mask&(1<<i)){}
        else{

        }
    }

}

int main()
{
    string s;

    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        arr[i]=s[i]-'0';
    }

    for(int i=0;i<s.size();i++)
    {
        for(int j=i;j<s.size();j++)
        {
            LL sum=0;
            for(int k=i;k<=j;k++)
            {
                sum=sum*10+arr[k];
            }
            dp[i][j]=sum;
//            cout<<i<<" "<<j<<" "<<sum<<endl;
        }
    }



    n=s.size()-1;



    LL res=0;
    for(LL i=0;i<(1LL<<n);i++)
    {
//        cout<<i<<endl;
        int lst=0;
        for(LL j=0;j<n;j++)
        {
            if((i&(1LL<<j)))
            {
//                cout<<i<<" "<<j<<" "<<lst<<" "<<dp[lst][j]<<endl;
                res+=dp[lst][j];
                lst=j+1;
            }
        }
//        cout<<i<<" "<<n<<" "<<lst<<" "<<dp[lst][n]<<endl;
        res+=dp[lst][n];
    }
    PLL(res),NL;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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





int main() {

	ll H, W;
	cin >> H >> W;

	char c[200][200];

	repn(i, H)repn(j, W) { cin >> c[i][j]; }

	repn(i, 2 * H) {
		repn(j, W) {
			cout << c[(i + 1) / 2][j];
		}
		cout << endl;
	}

	system("PAUSE");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/agc018_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  vector<ll> c(N);
  set<ll> s;
  ll m = 0;
  rep(i, N) {
    ll x;
    cin >> x;
    c[i] = x;
    s.insert(x);
    m = max(m, x);
  }
  if (m < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(c.begin(), c.end());
  rep(i, N - 1) { s.insert(abs(c[i] - c[i + 1])); }

  bool ret = false;
  for (auto a : s) {
    if (a != 0 && K % a == 0) {
      ret = true;
      break;
    }
  }

  cout << (ret ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 7040
import java.util.*;
import java.io.*;
public class Main{
/// functions
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
// end
static long[] f;
// taking inputs
static BufferedReader s;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
// ends
//......................................@uthor_Alx..............................................

public static void main(String[] args) throws  IOException{
       assign();
       String s1=read();
       char[] arr=new char[900000];
       int j1=400000,i1=400000-1;
       for(int i=0;i<s1.length();i++){
       	arr[j1]=s1.charAt(i);
       	j1++;
       }

        int q=int_v(read()); int flag=0;
        while(q--!=0){
        	String[] z=read().split(" ");
        	if(int_v(z[0])==1){
        		flag=(1^flag);
        		//sb=sb.reverse();
        	}
        	else{
        		if(flag==0){
        			if(int_v(z[1])==1){arr[i1]=z[2].charAt(0);i1--;}//sb.insert(0,z[2]);
        		else{arr[j1]=z[2].charAt(0);j1++;}//sb.append(z[2]);
        		}
        		else{
        			if(int_v(z[1])==1){arr[j1]=z[2].charAt(0);j1++;}
        		else{arr[i1]=z[2].charAt(0);i1--;}
        		}
        		
        	}
        }
    if(flag==0){
    	for(int i=i1+1;i<j1;i++){
    		out.write(arr[i]+"");
    	}
    	out.write("\n");
    }
     if(flag==1){
     	for(int i=j1-1;i>i1;i--){
    		out.write(arr[i]+"");
    	}
    	out.write("\n");
     }
             
        out.flush();
  }
}


Measured memory_bytes: 64508
#include <bits/stdc++.h>
#define pp pair<int, int>
using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m, n){
        vector<pp> v;
        int d, p;
        for(int i = 0; i < n; i++){
            cin >> d >> p;
            v.push_back(pp(p, d));
        }
        sort(v.begin(), v.end(), greater<pp>());
        int res = 0;
        for(int i = 0; i < n; i++){
            if(v[i].second <= m){
                m -= v[i].second;
            }else if(m == 0){
                res += v[i].first * v[i].second;
            }else{
                res += v[i].first * (v[i].second - m);
                m = 0;
            }
        }
        cout << res << endl;
    }
    return 0;
}


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

ll solve() {
    ll N, K;
    cin >> N >> K;
    const ll MOD = 1e9 + 7;
    ll ans = 0;
    for ( ll k = K; k <= N+1; k++ ) {
        ans += (2*N+1-k)*k/2 - (k-1)*k/2 + 1;
        ans %= MOD;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuffer sb = new StringBuffer();
		for (int i=0;i<s.length();i++) {
			if (i%2==0) {
				sb.append('0');
			} else {
				sb.append('1');
			}
		}
		String zero = sb.toString();
		sb = new StringBuffer();
		for (int i=0;i<s.length();i++) {
			if (i%2==1) {
				sb.append('0');
			} else {
				sb.append('1');
			}
		}
		String one = sb.toString();
		int z =0;
		int o=0;
		for (int i=0;i<s.length();i++) {
			if (s.charAt(i)==zero.charAt(i)) {
				z++;
			} else {
				o++;
			}
		}
		System.out.println(Math.min(z, o));
	}
}

Measured memory_bytes: 39428
S = input()
N = int(S.split(" ")[0])
M = int(S.split(" ")[1])


lArr = []
rArr = []
for i in range(M):
    S = input()
    l1 = int(S.split(" ")[0])
    r1 = int(S.split(" ")[1])
    lArr.append(l1)
    rArr.append(r1)

lArr.sort()
rArr.sort()

l1 = max(lArr)
r1 = min(rArr)

if r1 < l1:
    print(0)
else:
    print(r1 - l1 + 1)


Measured memory_bytes: 11440
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int n, a;
  cin >> n >> a;
  cout << ((n%1000 <= a)?"Yes" :"No") << endl;
}


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


int main() {
    string S;
    cin >> S;
    if(S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int MAX = 1000010;
int N;
int d[1010101];

void solve() {
    int cnt[1010101] = {};
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        cnt[A]++;
    }

    int asn = 0;
    for (int i = 1; i <= MAX; i++) {
        if (cnt[i]) {
            if (d[i])
                continue;
            if (cnt[i] == 1)
                asn += cnt[i];
            for (int x = i; x < MAX; x += i) {
                d[x] = 1;
            }
        }
    }

    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;


    solve();
    return 0;
}


Measured memory_bytes: 19364
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> ds(n);
  for(Int i=0;i<n;i++) cin>>ds[i];
  Int ans=0;
  for(Int i=0;i<n;i++)
    for(Int j=0;j<i;j++)
      ans+=ds[i]*ds[j];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
bool vis[maxn];
int main(){
	int n , k;cin >> n >> k;
	int d , y;
	fo(i,1,k){
		cin >> d;
		fo(i,1,d){
			cin >> y;
			vis[y] = 1;
		}
	}
	int ans = 0;
	fo(i,1,n)if(!vis[i])ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
       int A,B,C;
        cin >> A >> B >> C;

       if(A<=B*C){

            cout <<  "Yes"<< endl;

       }else{
            cout <<  "No"<< endl;

       }
       
        return 0;
    }

Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>
#include <cassert>
#include<map>
#include<bitset>

using lli = long long int;
lli inf = 1000000007;
using namespace std;


void solve() {
	int N, X, Y;
	cin >> N >> X >> Y;
	// 直接行くか XY使うか YX使うか
	int ans[2010] = {};
	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			int cost = min(j - i,
				min(abs(X - i) + 1 + abs(Y - j), abs(Y - i) + 1 + abs(X - j))
			);
			ans[cost]++;
		}
	}
	for (int i = 1; i < N; i++) {
		cout << ans[i] << endl;
	}
}

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

Measured memory_bytes: 256