akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
INF = (1<<31)
from bisect import bisect_left

class LazySegmentTree():

    def __init__(self,Q):
        self.N = Q
        self.tree = [INF]*(2*self.N)
        self.lazy = [INF]*(2*self.N)
   
    def _evaluate(self,K):#Kの上の遅延配列を評価する
        H = K.bit_length() - 1
        for i in range(H,0,-1):
            h = K >> i
            if self.lazy[h] == INF:
                continue
            self.tree[h] = min(self.tree[h],self.lazy[h])
            self.lazy[h << 1] = min(self.lazy[h << 1],self.lazy[h])
            self.lazy[h << 1|1] = min(self.lazy[h << 1|1],self.lazy[h])
            self.lazy[h] = INF
    
    def _caluculate(self,K):#Kより上を計算する
        while K > 1:
            K >>= 1
            self.tree[K] = min(self.tree[K],self.tree[K<<1],self.lazy[K<<1],self.tree[K<<1|1],self.lazy[K<<1|1])

    def range_update(self,L,R,M):#[L,R)にMを作用
        L += self.N
        R += self.N
        L0 = L//(L & -L)
        R0 = R//(R & -R) - 1
        #self._evaluate(L0)
        #self._evaluate(R0)
        while L < R:
            if L&1:
                self.lazy[L] = min(self.lazy[L],M)
                L += 1
            if R&1:
                R -= 1
                self.lazy[R] = min(self.lazy[R],M)
            L >>= 1
            R >>= 1
        #print("L0 R0 {} {}\n".format(L0,R0))
        self._caluculate(L0)
        self._caluculate(R0)
    
    def range_query(self,L,R):#[L,R)を計算する
        L += self.N
        R += self.N
        L0 = L//(L & -L)
        R0 = R//(R & -R) - 1
        self._evaluate(L0)
        self._evaluate(R0)
        v = INF
        while L < R:
            if L&1:
                v = min(v,self.tree[L],self.lazy[L])
                L += 1
            if R&1:
                R -= 1
                v = min(self.tree[R],self.lazy[R],v)
            L >>= 1
            R >>= 1
        return v
    '''
    def __str__(self):
        return '\n'.join(' '.join(str(v) for v in self.tree[1<<i:1<<(i + 1)]) for i in range((2*self.N).bit_length()))
    '''
    def debug(self):
        print(self.lazy)
        print(self.tree)
    
    def __str__(self):
        for i in range(self.N):
            self.tree[i] = min(self.tree[i],self.lazy[i])
            self.lazy[i << 1] = min(self.lazy[i << 1],self.lazy[i])
            self.lazy[i << 1|1] = min(self.lazy[i << 1|1],self.lazy[i])
            self.lazy[i] = INF
        for i in range(self.N,self.N*2):
            self.tree[i] = min(self.tree[i],self.lazy[i])
        return '\n'.join(map(str,[k if k < INF else -1 for k in self.tree[self.N:]]))


N,Q = map(int,input().split())
roadwork = [tuple(map(int,input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
st = LazySegmentTree(Q)

for s,t,x in roadwork:
    l = bisect_left(D,s - x)
    r = bisect_left(D,t - x)
    st.range_update(l,r,x)
print(str(st))

Measured memory_bytes: 132552
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t x;

    std::cin >> x;

    std::cout << (x == 0 ? 1 : 0) << std::endl;

    return 0;
}

Measured memory_bytes: 3632
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり整数
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''

N, A, B, C = map(int, input().split())
L = []
for i in range(N):
    x1 = int(input())
    L.append(x1)



ans = INF
for use in range(4**N):  # 4進法　1:A 2:B 3:C 0:unused
    a = 0
    b = 0
    c = 0
    d = 0
    local = 0
    unuse = 0
    for i in range(N):
        where = use%(4**(i+1))//(4**i)
        if where == 1:
            a+=L[i]
        elif where == 2:
            b+= L[i]
        elif where == 3:
            c+=L[i]
        else :
            d+=L[i]
            unuse+=1

    if a*b*c == 0:
        continue

    local = abs(A-a) + abs(B-b) + abs(C-c) + (N-unuse-3)*10
    ans = min(ans, local)


print(ans)
    

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define read cin >>
#define echo cout <<
#define fin << '\n'
#define _ << ' ' <<
#define in :
#define var auto&&
#define let const auto

int a[1010], b[1010];
int h, n;
int dp[10100][1010];

int min ( int a, int b, int c ) {
    return min(a, min(b, c));
}

int dfs ( int left, int pos ) {
    if ( left <= 0 ) return 0;
    if ( pos == n ) return 0x3f3f3f3f;
    if ( ~dp[left][pos] ) return dp[left][pos];
    return dp[left][pos] =
        min ( dfs ( left-a[pos], pos ) + b[pos],
            dfs ( left-a[pos], pos+1 ) + b[pos],
            dfs ( left, pos+1 ));
}

signed main ( ) {

    read h >> n;

    for ( int i = 0; i < n; i++ ) {
        read a[i] >> b[i];
    }

    memset(dp, -1, sizeof(dp));

    echo dfs ( h, 0 ) fin;



    return 0;
}

Measured memory_bytes: 80512
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x.sort()
ans = 0
for i in range(n):
    if m - x[i][1] < 0:
        print(ans + m * x[i][0])
        exit()
    ans += x[i][0] * x[i][1]
    m -= x[i][1]
print(ans)

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

int main() {
	int n, k;
	string s;
	while ( cin >> n >> k >> s ) {
		vector<int> diff;
		diff.push_back(0);
		diff.push_back(0);
		
		int last = 0;
		for (int i = 0; i < n; ++i) {
			if ( s[i] != s[last] ) {
				diff.push_back(i);
				last = i;
			}
		}
		
		for (int i = 0; i < 2*k+1; ++i) diff.push_back(n);
		
		int ans = 0, ds = diff.size();
		
		if ( s[0] == '0' ) {
			for (int i = 0; i+2*k+1 < ds; i += 2 ) ans = max( ans, diff[ i+2*k+1 ]-diff[i] );
		}
		else {
			for (int i = 1; i+2*k+1 < ds; i += 2 ) ans = max( ans, diff[ i+2*k+1 ]-diff[i] );
		}
		
//		for (auto x : diff) cout << x << ' '; cout << '\n';
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int ans=INF;
    for(int i=0;i<=2*max(X,Y);i+=2){
        ans=min(ans,A*max(X-i/2,0)+B*max(Y-i/2,0)+C*i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define PI 3.14159265358979
using namespace std;

int main()
{
  ll N, M; cin >> N >> M;
  vector<vector<ll>> G(N + 1, vector<ll>(0));
  vector<ll> dist(N + 1, -1), shirube(N + 1);
  queue<ll> Q;
  rep(i, 0, M) {
   	ll A, B; cin >> A >> B;
    G[A].push_back(B); G[B].push_back(A);
  }
  dist[0] = 0; dist[1] = 0; Q.push(1);
  while (!Q.empty()) {
  	ll v = Q.front(); Q.pop();
    for (ll nv : G[v]) {
    	if (dist[nv] != -1) continue;     
      dist[nv] = dist[v] + 1;
      shirube[nv] = v;
      Q.push(nv);
    }
  }
  if (!notFound(dist, -1)) {
  	cout << "No" << endl;
  } else {
  	cout << "Yes" << endl;
    rep(i, 2, N + 1) {
    	cout << shirube[i] << endl;
    }
  }
}

Measured memory_bytes: 13596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> ary(3);
int ct = 0;

void add(int a, int b, int c);

int main() {

	//int count = 0;
	for (int i = 0; i < 3; i++) {
		cin >> ary[i];
	}
	sort(ary.begin(), ary.end());

	int d1 = abs(ary[0] - ary[1]);
	int d2 = abs(ary[2] - ary[1]);
	
	while (ary[0] != ary[1] || ary[2] != ary[1]) {
		if (d1 >= 3) {
			add(2, 0, 0);
		} else if (d2 >= 3) {
			add(0, 2, 0);
		} else if (abs(d2 - d1) == 2) {
			add(2, 0, 0);
		} else if (d1 == d2 && d1 == 2) {
			add(2, 0, 0);
		} else if (d1 == d2 && d1 == 1) {
			add(0, 1, 1);
		} else {
			add(1, 1, 0);
		}

		d1 = abs(ary[0] - ary[1]);
		d2 = abs(ary[2] - ary[1]);
	}

	cout << ct << endl;

}

void add(int a, int b, int c) {
	ct++;
	ary[0] += a;
	ary[1] += b;
	ary[2] += c;

	sort(ary.begin(), ary.end());
}

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

int main(){

    int n;
    cin >> n;
    vector<int> a(n);

    rep(i,n){
        cin >> a[i];
    }
    bool f=true;
    rep(i,n){
        if(a[i]%2==0){
            if(a[i]%3!=0&&a[i]%5!=0){
                f=false;
                break;
            }
        }
    }

    if(f){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vll;
void Mini(ll &a,ll b){
  a=min(a,b);
}
const ll INF=(1LL<<60);
struct edge{
  ll to,cost;
  edge(int a,int b):to(a),cost(b){}
};
int N,M,S,T,U,V;
vector< vector<edge> > G;
void dijkstra(int from,vll &dist,vll &minU,vll &distU,vll &minV,vll &distV){
  for(int i=0;i<N;i++){
    dist[i]=INF;
    minU[i]=distU[i];
    minV[i]=distV[i];
  }
  dist[from]=0;
  priority_queue< P , vector<P> , greater<P> > Q;
  Q.push(P(0,from));
  while(!Q.empty()){
    P p=Q.top();
    Q.pop();
    ll pos=p.second;
    ll cost=p.first;
    if(cost>dist[pos])continue;
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(cost+e.cost<dist[e.to]){
        dist[e.to]=cost+e.cost;
        minU[e.to]=min(distU[e.to],minU[pos]);
        minV[e.to]=min(distV[e.to],minV[pos]);
        Q.push(P(dist[e.to],e.to));
      }else if(cost+e.cost==dist[e.to]){
        Mini(minU[e.to],minU[pos]);
        Mini(minV[e.to],minV[pos]);
      }
    }
  }
}
int main(){
  scanf("%d %d %d %d %d %d",&N,&M,&S,&T,&U,&V);
  S--;T--;U--;V--;
  G.resize(N);
  for(int i=0;i<M;i++){
    int from,to,cost;
    scanf("%d %d %d",&from,&to,&cost);
    from--;to--;
    G[from].push_back( edge(to,cost) );
    G[to].push_back( edge(from,cost) );
  }
  vll distS(N),distT(N),distU(N),distV(N);
  vll minSU(N),minSV(N),minTU(N),minTV(N),tmp(N);
  dijkstra(U,distU,tmp,tmp,tmp,tmp);
  dijkstra(V,distV,tmp,tmp,tmp,tmp);
  dijkstra(S,distS,minSU,distU,minSV,distV);
  dijkstra(T,distT,minTU,distU,minTV,distV);
  ll ans=distU[V];
  for(int i=0;i<N;i++){
    if(distS[i]+distT[i]!=distS[T])continue;
    Mini(ans,minSU[i]+minTV[i]);
    Mini(ans,minSV[i]+minTU[i]);
  }
  printf("%lld\n",ans);
  return 0;
}



Measured memory_bytes: 25672
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

fn main() {
    scan!(n, k; usize);
    scan!(h_array; Vec<usize>);

    let mut h_array = h_array;
    h_array.sort();

    let ans: usize = if n > k {
        h_array[..(n-k)].into_iter().sum()
    } else {
        0
    };

    println!("{}", ans);
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> fields(h);
  REP(i, h) {
    cin >> fields[i];
  }

  int dp[110][110];
  REP(i, 110) {
    REP(j, 110) {
      dp[i][j] = 1000;
    }
  }
  int count = 0;
  if (fields[0][0] == '#') {
    count++;
  }
  dp[0][0] = count;

  REP(i, w) {
    if (i == 0) continue;
    if (fields[0][i] == '#') {
      if (fields[0][i - 1] == '.') {
        count++;
      }
    }
    dp[0][i] = count;
  }

  count = 0;
  if (fields[0][0] == '#') {
    count++;
  }
  dp[0][0] = count;

  REP(i, h) {
    if (i == 0) continue;
    if (fields[i][0] == '#') {
      if (fields[i - 1][0] == '.') {
        count++;
      }
    }
    dp[i][0] = count;
  }

  REP(i, h) {
    if (i == 0) continue;
    REP(j, w) {
      if (j == 0) continue;
      if (fields[i][j] == '#') {
        if (fields[i - 1][j] == '.' && fields[i][j - 1] == '.') {
          dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1;
          continue;
        }
        if (fields[i][j - 1] == '#') {
          dp[i][j] = min(dp[i][j], dp[i][j - 1]);
        }
        if (fields[i - 1][j] == '#') {
          dp[i][j] = min(dp[i][j], dp[i - 1][j]);
        }
      } else {
        dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }

  // REP(i, h) {
  //   REP(j, w) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  cout << dp[h - 1][w - 1] << endl;

  return 0;
}



Measured memory_bytes: 256
S = input()

if S == 'SUN':
    print("7")

elif S == 'MON':
    print("6")

elif S == 'TUE':
    print("5")

elif S == 'WED':
    print("4")

elif S == 'THU':
    print("3")

elif S == 'FRI':
    print("2")

elif S == 'SAT':
    print("1")

Measured memory_bytes: 8880
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
int main() {
    IO;
    string s;
    cin >> s;
    int n = s.length();
    s = "#" + s;
    if (s[1] != 'A') {
        cout << "WA";
        return 0;
    }
    int cnt = 0;
    for (int i = 3; i < n; i++)
        if (s[i] == 'C') {
            cnt++;
        }
    if (cnt != 1) {
        cout << "WA";
        return 0;
    }
    for (int i = 2; i <= n; i++)
        if (s[i] != 'C')
            if (s[i] >= 'A' && s[i] <= 'Z') {
                cout << "WA";
                return 0;
            } 
    cout << "AC";
    return 0;
}


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

int main()
{
    while (1) {
        int x,y;
        cin>>x>>y;
        if(x==0&&y==0)
            break;
        else{
            if(x<y)
                cout<<x<<" "<<y<<endl;
            else
                cout<<y<<" "<<x<<endl;

        }
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    ll X, N;
    cin >> X >> N;


    set<ll> P;
    REP(i,N){
        ll p;
        cin >> p;
        P.insert(p);
    }

    ll sum = 1e15;
    ll ans;

    for(int val = 500; val >= -500; val--){
        if(P.find(val) != P.end()) continue;
        ll diff = abs(val - X);
        if(diff <= sum){
            ans = val;
            sum = diff;
        }
    }

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


Measured memory_bytes: 3632
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    String s = sc.next();

    if (s.equals("ABC")){
      out.println("ARC");
    }else {
      out.println("ABC");
    }
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 33816
#include<iostream>
#include<string>
#include<algorithm>
#include<map>

using namespace std;

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

    map<string, int> votes;

    for(int i = 0; i < N; i++) {
        string name;
        cin >> name;
        if(votes.find(name) != votes.end()) {
            votes[name]++;
        } else {
            votes.insert(make_pair(name, 1));
        }
    }

    int max = 0;
    for(auto i = votes.begin(); i != votes.end(); ++i) {
        if(max < i->second) {
            max = i->second;
        }
    }

    for(auto i = votes.begin(); i != votes.end(); ++i) {
        if(max == i->second) {
            cout << i->first << endl;
        }
    }

    return 0;
}


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

vector<pair<int, int> > e;
int n, k, cnt;

int main() {
	cin >> n >> k;
	for (int i = 2; i <= n; i++)
		e.push_back({ 1, i });
	if (k > (n - 1) * (n - 2) / 2)
		return cout << -1, 0;
	cnt = (n - 1) * (n - 2) / 2;
	int U = 2, V = 3;
	while (k < cnt) {
		e.push_back({ U, V });
		cnt--;
		V++;
		if (V == n + 1)
			U++, V = U + 1;
	}
	cout << e.size() << '\n';
	for (int i = 0; i < e.size(); i++)
		cout << e[i].first << ' ' << e[i].second << '\n';
}

Measured memory_bytes: 384
N=int(input())
L=[str(i) for i in [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381, 1451, 1471, 1481, 1511, 1531, 1571, 1601, 1621, 1721, 1741, 1801, 1811, 1831, 1861, 1871, 1901, 1931, 1951, 2011, 2081, 2111, 2131, 2141, 2161, 2221, 2251, 2281, 2311, 2341, 2351, 2371, 2381, 2411, 2441]]
print(" ".join(L[:N]))


Measured memory_bytes: 3064
W,H,N = map(int,input().split())

x1 = 0
x2 = W
y1 = 0
y2 = H
rectangle_S = W*H
black_S = 0
judge = 1 #1:黒部分全部でない,0:黒部分全部

for i in range(N):
  x,y,a = map(int,input().split())
  if(a == 1):
    if(x < x1):
     black_S += 0
     x1 = x1
    elif(x1 <= x <= x2):
     black_S += (x-x1)*(y2-y1)
     x1 = x
    elif(x2 < x):
     black_S = W*H
     break      
  elif(a == 2):
    if(x < x1):
     black_S = W*H
     judge = 0 #黒全部
    elif(x1 <= x <= x2):
     black_S += (x2-x)*(y2-y1)
     x2 = x
    elif(x2 < x):
     black_S += 0
     #x2 = x2   
  elif(a == 3):
    if(y < y1):
     black_S += 0
     y1 = y1
    elif(y1 <= y <= y2):
     black_S += (y-y1)*(x2-x1)
     y1 = y
    elif(y2 < y):
     black_S = W*H
     judge = 0   
  elif(a == 4):
    if(y < y1):
     black_S = W*H
     judge = 0 #黒全部
    elif(y1 <= y <= y2):
     black_S += (y2-y)*(x2-x1)
     y2 = y
    elif(y2 < y):
     black_S += 0
     #y2 = y2

if(judge == 0):
  print(0)
else:
  print(rectangle_S - black_S)


Measured memory_bytes: 3064
S = input() # S_i = B(lack) or W(hite)
N = len(S)

"""
    最終的には W..W...B...B のような並びになる。
    元の状態から B がどれだけ右に進んだかの総和が答え。
"""

def sum_contin_int(l, r):
    return (r * (r + 1) - l * (l - 1)) // 2

cnt_initial = 0
cnt_b = 0
for i in range(N):
    if S[i] == 'B':
        cnt_initial += i
        cnt_b += 1

cnt_final = sum_contin_int(N - cnt_b, N - 1)

ans = cnt_final - cnt_initial
print(ans)

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

using namespace std;

int main()
{
    int i=0, sum=0;
    char x;
    vector <char> A;
    while(true)
    {
        char ch=getchar();
        if(ch=='\n')
        {
            break;
        }
        else if(ch=='B' && !A.empty())
        {
            A.pop_back();
        }
        else if(ch!='B')
        {
            A.push_back(ch);
        }
    }
    for(int i=0; i<A.size(); i++)
    {
        cout<<A[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
n,m=gets.split.map &:to_i
s={}
par=[*0...n]
fr=->x{
  u=par[x]
  return u==x ? x : par[x]=fr[u]
}
fu=->x,y{
  x=fr[x]
  y=fr[y]
  par[y]=x if x!=y
}
m.times{
  a,b=gets.split.map{|e| e.to_i-1 }.minmax
  r=s[a]||={}
  next if r[b]
  r[b]=true
  fu[a,b]
}
c={}
n.times{|e|
  r=fr[e]
  c[r]=1+(c[r]||0)
}
puts c.values.max

Measured memory_bytes: 68520
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	var sa, sb string
	for i := 0; i < a; i++ {
		sb += strconv.Itoa(b)
	}
	for i := 0; i < b; i++ {
		sa += strconv.Itoa(a)
	}
	// fmt.Println("sa", sa, "sb", sb)
	if sa == sb {
		fmt.Println(sa)
	} else if sa > sb {
		fmt.Println(sb)
	} else {
		fmt.Println(sa)
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 0;

V<V<bool> > adj;
V<int> color;
int n;

bool dfs(int u, bool c, V<int> &occ) {
    if (color[u] == !c) return false;
    else if (color[u] == c) return true;
    color[u] = c;
    occ[c]++;
    F(v,n) if (adj[u][v])
        if (!dfs(v, !c, occ))
            return false;
    return true;
}

int roads(int x) {
    return x*(x-1)/2;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int m; cin>>n>>m;
    adj.assign(n, V<bool>(n, true));
    F(i,n) adj[i][i] = false;
    F(i,m) {
        int a,b; cin>>a>>b;
        a--,b--;
        adj[a][b] = adj[b][a] = false;
    }
    color.assign(n, -1);
    int off = 0;
    V<bool> knap(n+1, false);
    knap[0] = true;
    bool poss = true;
    F(u,n) if (color[u] == -1) {
        V<int> occ;
        occ.push_back(0);
        occ.push_back(0);
        if (!dfs(u, 0, occ))
            poss = false;
        if (occ[1] < occ[0])
            swap(occ[0], occ[1]);
        H(occ)
        off += occ[0];
        int diff = occ[1]-occ[0];
   //     cout<<"K: ";
        DR(i,diff,n+1){
 //       	cout<<i<<' ';
        	if (knap[i-diff]) {
            knap[i] = true;
        }
		}
     //   cout<<endl;
    }
//    for(int i=1;i<=n;i++) cout<<knap[i]<<' ';
//    cout<<endl;
    H(off)
    H(knap)
    int best = n*n;
    F(i,n+1) if (knap[i]) {
        int sa = off + i, sb = n - sa;
        H(sa) H(sb)
        MI(best, roads(sa) + roads(sb));
    }
    cout<<(poss ? best : -1)<<"\n";
}


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

int main() {
  int N, K, sum;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    if ((K - x) > x) {
      sum += 2 * x;
    }
    else {
      sum += 2 * (K - x);
    }
  }
  cout << sum << endl;
}

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

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		Arrays.sort(nums);

		if(n%2==1) {
			if(nums[0]==0) {
			} else {
				System.out.println(0);
				return;
			}
		}
		for(int i = n-1; i > 0; i-=2) {
			if(nums[i]!=nums[i-1]) {
				System.out.println(0);
				return;
			}
		}
		long ans = 1L;
		int time = n/2;
		for(int i = 0; i < time; i++) {
			ans = (ans * 2L) % 1000000007;
		}
		System.out.println(ans%1000000007);
	}
}

Measured memory_bytes: 50384
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  string s;
  string t;
  cin >> s >> t;
  cout << t+s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    double xs,ys,xt,yt;
    cin>>xs>>ys>>xt>>yt;
    double dx=xs-xt,dy=ys-yt;
    cout<<fixed<<setprecision(10);
    cout<<sqrt(dx*dx+dy*dy)<<endl;
     
}


Measured memory_bytes: 3236
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    sort(as.rbegin(), as.rend());
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += as[i] * (i & 1 ? -1 : 1);
    }
    cout << ans << '\n';
}


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

using namespace std;

int intersection(int cx1, int cy1, int r1, int cx2, int cy2, int r2);

int main(){
  int cx1, cy1, r1;
  int cx2, cy2, r2;

  cin >> cx1 >> cy1 >> r1;
  cin >> cx2 >> cy2 >> r2;

  cout << intersection(cx1, cy1, r1, cx2, cy2, r2) << endl;


  return 0;
}

int intersection(int cx1, int cy1, int r1, int cx2, int cy2, int r2){
  float d = 0.0;

  d = (cx2 - cx1) * (cx2 - cx1) + (cy2 - cy1) * (cy2 - cy1);
  d = sqrt(d);

  if(d > (r1 + r2)){
    return 4;
  }
  else if(d == (r1 + r2)){
    return 3;
  }
  else if(d < (r1 + r2) && d > abs(r1 - r2)){
    return 2;
  }
  else if(d == abs(r1 - r2)){
    return 1;
  }
  else return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(5e5) + 7;
const int maxm = 300;

int n, m;
ll a[maxn], b[maxn];
ll C(ll n, ll m) { return a[n] * b[n - m] % mod * b[m] % mod; }
ll A(ll n, ll m) { return a[n] * b[n - m] % mod; }

int main() {

	// freopen("in.in", "r", stdin);
	scanf("%d%d", &n, &m);
	a[0] = b[0] = a[1] = b[1] = 1;
	for (ll i = 2; i <= m; i++) b[i] = (mod - mod / i) * b[mod % i] % mod;
	for (ll i = 2; i <= m; i++) {
		a[i] = a[i - 1] * i % mod;
		b[i] = b[i - 1] * b[i] % mod;
	}
	ll al = 0;
	for (ll i = 0; i <= n; i++) {// 枚举至少有i个元素与A序列对应相同(容斥定理)
		ll x = (i % 2 ? -1 : 1);
		al = (al + x * C(n, i) * A(m - i, n - i) % mod + mod) % mod;
	}
	printf("%lld\n", A(m, n) * al % mod);

	return 0;
}

Measured memory_bytes: 11492
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    N = ii()
    import math
    for i in range(N+1):
        if math.floor(i*1.08) == N:
            print(i)
            return
    print(':(')




main()


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

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int k = stdIn.nextInt();
        int q = stdIn.nextInt();
        int num[] = new int[n + 1];
        
        for(int i = 1; i <= n; i++){
            num[i] = k - q;
        }
        
        for(int i = 0; i < q; i++){
            int ans = stdIn.nextInt();
            num[ans]++;
        }
        
        for(int i = 1; i <= n; i++){
            if(num[i] > 0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
        //int c = stdIn.nextInt();
        //String s = stdIn.next();
        //char c[] = s.toCharArray();
        //String ss[] = new int[s.length()];
        
        //boolean flag = true;
        
       //for(int i = 0; i < s.length(); i++){
        //     if(i % 2 == 0){
        //         if(c[i] == 'L'){
        //             flag = false;
        //             break;
        //         }
        //     }else{
        //         if(c[i] == 'R'){
        //             flag = false;
        //             break;
        //         }
        //     }
        // }
        
        // if(flag){
        //     System.out.println("Yes");
        // }else{
        //     System.out.println("No");
        // }
        
        
        // if(s.equals("Sunny")){
        //     System.out.println("Cloudy");
        // }else if(s.equals("Cloudy")){
        //     System.out.println("Rainy");
        // }else{
        //     System.out.println("Sunny");
        // }
        
        //int count = 0;
        
        //for(int i = 0; i < s.length(); i++){
            //ss[i] = c
        //}
        
        //System.out.println();
    }
    
}


Measured memory_bytes: 58324
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
a,b,c,d,e,f = LI()
a *= 100
b *= 100
ans = [a,0]
for i in range(f//a+1):
    for j in range((f-a*i)//b+1):
        for k in range((f-a*i-b*j)//c+1):
            for l in range((f-a*i-b*j-c*k)//d+1):
                if i or j or k or l:
                    s = c*k+d*l
                    w = a*i+b*j
                    q = w*e//100
                    if s <= q:
                        if w+s <= f:
                            if ans[1]/ans[0] < s/(s+w):
                                ans = [w+s,s]
print(*ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 42844
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	k := nextInt()
	al := make([]int, n)
	for i := 0; i < n; i++ {
		al[i] = nextInt()
		if i < k {
			continue
		}
		//fmt.Println(al[i], al[i-k])
		if al[i] > al[i-k] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}

	}

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 6220
def getGcd(num1, num2):
    while True:
        tmp = num1
        num1 = num2 % num1
        num2 = tmp
        if(num1 == 0):
            return tmp

[n, x] = map(int, input().split(" "))
xs = list(map(int, input().split(" ")))

xs.append(x)
xs.sort()

gc = xs[1] - xs[0]

for i in range(1, n + 1):
    gc = getGcd(gc,  xs[i] - xs[i - 1])

print(gc)

Measured memory_bytes: 14228
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int x,y,z,n,m,ans1[200005],ans2[200005],order[200005];

int main() {
	cin >> x;
	for (int i = 1; i <= x; i++) {
		cin >> y;
		order[y] = i;
	}
	ans1[1] = ans2[1] = 500000000;
	for (int i = 2; i <= x; i++) {
		int tmp = order[i] - order[i-1];
		if (tmp < 0) {
			ans1[i] = ans1[i-1]+1;
			ans2[i] = ans2[i-1]-1+tmp;
		} else {
			ans1[i] = ans1[i-1]+1+tmp;
			ans2[i] = ans2[i-1]-1;			
		}
	}
	for (int i = 1; i <= x; i++) {
		cout << ans1[i] << " ";
	}
	cout << "\n";
	for (int i = 1; i <= x; i++) {
		cout << ans2[i] << " ";
	}
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
using namespace std;
int const MAX = 100003;
volatile bool not_prime[MAX + 1];

int main(){
  int x;
  cin >> x;
  
  vector<int> unko;
  for (int i = 2; i <= MAX; ++i) {
    if (!not_prime[i]) {
      unko.push_back(i);
      for (int j = 1; j <= MAX / i; ++j) not_prime[i * j] = true;
    }
  }
  cout << *lower_bound(unko.begin(), unko.end(), x);
  return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;


int main(void)
{
    string s;
    cin >> s;

    string out = "";
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i] == '0'){
            out.push_back('0');
        } else if(s[i] == '1'){
            out.push_back('1');
        } else {
            if(s.size() > 0){
                out = out.substr(0, out.size() - 1);
            }
        }
    }

    cout << out << endl;
    
    return 0;
}


Measured memory_bytes: 3632
n, m, q = map(int, input().split())
qry = [list(map(int, input().split())) for _ in range(q)]

ans = 0


def dfs(A):
    global ans
    if len(A) == n:
        score = 0
        for a, b, c, d in qry:
            if A[b - 1] - A[a - 1] == c:
                score += d
        ans = max(ans, score)
        return
    elif len(A) == 0:
        for nx in range(1, m + 1):
            dfs(A + [nx])
    else:
        for nx in range(A[-1], m + 1):
            dfs(A + [nx])


dfs([])
print(ans)


Measured memory_bytes: 71852
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define ff(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b) 
int ans = 0;
ll k;
bool f(ll x){
    int cur = 0;
    while(x){
        x /= 10;
        cur++;
    }
    return (cur & 1);
}
void dfs(ll u){
    if(u <= k && f(u))
        ans++;
    fore(i, 0, 10){
        ll num = u * 10 + i;
        if(num <= k && num > 0)
            dfs(num);
    }
}
int main(){
    //FL;
    fin;
    cin >> k;
    dfs(0LL);
    cout << ans << '\n';
    time;
    return 0;
}   

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

int main() {
  int x;
  cin>>x;
  if(x==6){cout<<2<<endl;}
  else if(x==4){cout<<2<<endl;}
  else if(x==9){cout<<2<<endl;}
  else if(x==10){cout<<2<<endl;}
  else if(x==14){cout<<2<<endl;}
  else if(x==21){cout<<2<<endl;}
  else if(x==22){cout<<2<<endl;}
   else if(x==25){cout<<2<<endl;}
   else if(x==26){cout<<2<<endl;}
   else if(x==8){cout<<5<<endl;}
   else if(x==12){cout<<5<<endl;}
  else if(x==18){cout<<5<<endl;}
  else if(x==20){cout<<5<<endl;}
  else if(x==27){cout<<5<<endl;}
  else if(x==16){cout<<14<<endl;}
  else if(x==24){cout<<15<<endl;}
  else if(x==28){cout<<4<<endl;}
   else if(x==30){cout<<4<<endl;}
   else if(x==32){cout<<51<<endl;}
  else {cout<<1<<endl;}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cctype>
#include <stdio.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    int res=99999999;
    int B[N];
    for (int i = 0;i <N;i++){
        B[i]=0;
        cin >> A[i];
        while (A[i]%2!=1){
            A[i] = A[i] / 2;
            B[i]++;
        }
        res = min(B[i],res);
    }



    cout << res << endl;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = double;
using ii = pair <int, int>;

#define int long long
#define FOR(a, b, c) for(int a = b, _c = c; a <= _c; ++a)
#define FORD(a, b, c) for(int a = b, _c = c; a >= _c; --a)
#define REP(a, b, c) for(int a = b, _ = c; a < _; ++a)
#define ALL(a, b) for(auto &a : b)
#define pb push_back
#define mp make_pair
#define all(a) begin(a), end(a)
#define reset(f, x) memset(f, x, sizeof(f))
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll

template <class T> void Max(T &x, T y) { x = (x > y) ? x : y;}

const int N = 1e4 + 5;
const ll mod = 1e9 + 7;
string k;
int a[N], d;
ll f[N][105][2];

void add(ll &x, ll y) {
  x = (x + y) % mod;
}

ll F(int i, int r, int o) {
  if(i > sz(k)) return !r;
  if(f[i][r][o] != -1) return f[i][r][o];
  ll ans = 0;
  FOR(j, 0, (o ? 9 : a[i])) add(ans, F(i + 1, (r + j) % d, j < a[i] || o));
  return f[i][r][o] = ans;
}

main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> k >> d;
  reset(f, -1);
  REP(i, 0, sz(k)) a[i + 1] = k[i] - '0';
  cout << (F(1, 0, 0) - 1 + mod) % mod;
}


Measured memory_bytes: 17536
#include <stdio.h>

int main(void)
{
	int x, n, i, j, k;
	
	while(scanf("%d %d", &n, &x) != EOF)
	{
		int count = 0;
		if(n == 0 && x == 0) break;
		
		for(i = 1;i < n-1; i++)
		{
			for(j = i + 1;j < n; j++)
			{
				for(k = j + 1;k <= n; k++)
				{
					if(i + j + k == x) count++;
				}
			}
		}
		
		printf("%d\n", count);
	}
	
	return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int A, B, C;
	long K;
	cin >>A >>B >>C >>K;
	K %=2;
	cout <<(A-B)*(1-2*K) <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e5 + 7;

map <string, int> ma;
int main()
{
    int n;
    cin>>n;
    string s;
    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin>>s;
        sort(s.begin(), s.end());
        if(ma[s]) ma[s]++;
        else ma[s] = 1;
    }
    map <string, int> :: iterator it;
    for(it = ma.begin(); it != ma.end(); it++)
    {
        ll x = it->second;
        ans += x*(x-1)/2;
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#define rep(i, a, b) for(lli i = a; i < (b); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) lli((x).size())
#define wis cout<<endl<<"I already speak english, bitch"<<endl<<endl;
 
typedef long long int lli;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef pair<ii,lli> iii;
 
#define trace(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cout <<  *it  << " : " << a << endl;
    err(++it, args...);
}

int main(){
	//vi v;
	int n; cin>>n;
	vector<pair<int,int> > v;
	rep(i,0,n){
		int foo; cin>>foo;
		v.pb({foo,i});
	}
	sort(all(v));
	for(auto x : v){
		cout<<x.ss+1<<" ";
	}
	return 0;
}

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

int main(){
	int n,c,now;
	bool f;
	while(cin >> n , n){
		vector<int> card(n*2);
		vector<int> taro(n);
		vector<int> hanako(n);
		
		for(int i=0;i<n*2;i++)card[i]=i+1;
		
		for(int i=0;i<n;i++){
			cin >> taro[i];
			card[taro[i]-1]=0;
		}
		c = 0;
		for(int i=0;i<n*2;i++){
			if(card[i])hanako[c++]=card[i];
		}
		now = 0;
		while(1){
			sort(taro.begin(),taro.end());
			sort(hanako.begin(),hanako.end());
			f=1;
			for(int i=0;i<taro.size();i++)
				if(taro[i]>now){
					now=taro[i];
					taro.erase(taro.begin()+i);
					f=0;
					break;
				}
			if(f)now=0;
			if(taro.empty())break;
			f=1;
			for(int i=0;i<hanako.size();i++)
				if(hanako[i]>now){
					now=hanako[i];
					hanako.erase(hanako.begin()+i);
					f=0;
					break;
				}
			if(f)now=0;
			if(hanako.empty())break;
		}
		cout << hanako.size() << endl << taro.size() << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll nck(int n, int k) { ll ret = 1; rep(i, k) {ret *= n - i; ret /= i + 1; } return ret; } // n <= 60
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


ll n, s;

ll dig(int i) {
    vector<int> v;
    ll n2 = n;
    while (n2) {
        v.eb(n2 % i);
        n2 /= i;
    }
    
    ll sum = 0;
    // for (int i = SZ(v) - 1; i >= 0; --i) cout << v[i] << " "; cout << endl;
    rep(i, SZ(v)) sum += v[i];
    return sum;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    
    cin >> n >> s;
    
    if (n == s) { out(n + 1); return 0; }
    for (int i = 2; (ll)i * i <= n; ++i) {
        ll sum = dig(i);
        
        
        if (sum == s) {
            out(i);
            return 0;
        }
    }
    
    vector<ll> v;
    for (int i = 1; (ll)i * i <= n - s; ++i) {
        if ((n - s) % i == 0) {
            v.eb(i + 1);
            v.eb((n - s) / i + 1);
        }
    }
    sort(all(v));
    
    // for (auto vi : v) cout << vi << " "; cout << endl;
    // bの候補が絞れた
    for (auto b : v) {
        if (n / b + n % b == s) {
            if (n / b >= b) continue;
            // out(n / b << " " << n % b);
            out(b);
            return 0;
        }
    }
    out(-1);
}



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

int main( int argc, char *argv[] )
{
int i;
int N;
long long iF;
const int iMod = 1000000007;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;

	iF = 1;
	for( i = 2; i <= N; i++ )
	{
		iF *= i;
		iF %= iMod;
	}

	cout << iF << endl;

	return 0;
}




Measured memory_bytes: 256