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

typedef long long int llint;

int bisect(llint* a, int size, llint value)
{
  int left,right,mid;
  
  left = 0;
  right = size -1;
    while(left <= right) {
        mid = (left + right) / 2; /* calc of middle key */
        if (a[mid] == value) {
            return mid;
        } else if (a[mid] < value) {
	  if (a[mid+1] > value) {
	    return mid+1;
	  } else {
            left = mid + 1; /* adjustment of left(start) key */
	  }
        } else {
	  if (a[mid-1] < value) {
	    return mid;
	  } else {
            right = mid - 1; /* adjustment of right(end) key */
	  }
	}
    }
    return -1;
}

llint llint_min(int len, ...) {
    int i;
    llint _min, num;
    va_list ap;
    va_start(ap, len);

    _min = va_arg(ap, llint);
    for (i = 1; i < len; i++) {
      num = va_arg(ap, llint);
      if (num < _min)
        _min = num;
    }
    va_end(ap);
    return _min;
}

llint mmax(llint a, llint b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

int main(void)
{
  int A, B, Q;
  llint inf = 1000000000000;
  llint *s, *t, x, ans;
  int i, p, q;

  scanf("%d%d%d",&A,&B,&Q);
  s = malloc(sizeof(llint)*(A+2));
  t = malloc(sizeof(llint)*(B+2));
  s[0] = t[0] = -inf;
  s[A+1] = t[B+1] = inf;
  for(i=1;i<=A;i++) {
    scanf("%lld", &(s[i]));
  }
  for(i=1;i<=B;i++) {
    scanf("%lld", &(t[i]));
  }
  for(i=1;i<=Q;i++) {
    scanf("%lld", &x);
    p = bisect(s,A+2,x);
    q = bisect(t,B+2,x);
    ans = llint_min(6,
		  mmax(s[p]-x,t[q]-x),
		  mmax(x-s[p-1],x-t[q-1]),
		  (s[p]-x)*2 + (x-t[q-1]),
		  (s[p]-x) + (x-t[q-1])*2,
		  (t[q]-x)*2 + (x-s[p-1]),
		  (t[q]-x) + (x-s[p-1])*2);
    printf("%lld\n",ans);
  }

  return 0;
}

Measured memory_bytes: 2816
# Hanafuda Shuffle

while true
  n, r = gets.split(' ').map(&:to_i)
  break if n == 0 && r == 0

  cards = (1..n).to_a.reverse

  r.times do
    p, c = gets.split(' ').map(&:to_i)

    taken = cards.slice!(p-1, c)
    cards.unshift(*taken)
  end

  puts cards.first
end

Measured memory_bytes: 6120
mask = {'N':(1, 5, 2, 3, 0, 4), 'E':(3, 1, 0, 5, 4, 2), 'S':(4, 0, 2, 3, 5, 1), 'W':(2, 1, 5, 0, 4,3)}

dice = input().split()

for c in input():
    dice = [dice[i] for i in mask[c]]

print(dice[0])



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

bool is753(int i) {
    bool c3, c5, c7;
    c3 = c5 = c7 = false;

    do {
        int num = i % 10;
        switch (num) {
            case 3:
                c3 = true;
                break;
            case 5:
                c5 = true;
                break;
            case 7:
                c7 = true;
                break;
            default:
                return false;
        }

    } while (i /= 10);

    return (c3 && c5 && c7);
}

int n;
int ans = 0;

void dfs(long i) {
    if (i > n) return;

    if (is753(i)) ans++;
    dfs(10 * i + 3);
    dfs(10 * i + 5);
    dfs(10 * i + 7);
}

int main() {
    cin >> n;

    dfs(0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (a, b, c) = readIntList()
    val k = readInt()

    repeat(k) {
        if (a >= b) {
            b *= 2
        } else if (b >= c) {
            c *= 2
        }
    }
    if (a < b && b < c) {
        println("Yes")
    } else {
        println("No")
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)

Measured memory_bytes: 36452
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;

char s[N];

int main(){
	int n, m = 0;
	scanf("%d%s", &n, s);
	for (int i = 0; i < n; i++) if (s[i] == 'R') m ++;

	if (m > n - m) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
 
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))

cnt = 0

for i in range(2 ** N):
    flag = True
    for j in range(M):
        if not([(i >> k-1) & 1  for k in s[j]].count(1) % 2 == p[j]):
            flag = False
    if flag:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        long num = sc.nextLong();
        long move = (num / 11) * 2;
        if (num % 11 == 0) {
        } else if (num % 11 <= 6) {
            move++;
        } else {
            move += 2;
        }
        System.out.println(move);
        bw.flush();
    }
}


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

int main(){
	int tmp;
	stack<int> st;
	while(cin>>tmp){
		if(tmp){
			st.push(tmp);
		}else{
			cout << st.top() << endl;
			st.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
int main(void)
{
	int a,b,c,d,y,x,n;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	n=a+b+c+d;
	x=n/60;
	y=n-60*x;
	printf("%d\n",x);
	printf("%d\n",y);
	
	return 0;
}



Measured memory_bytes: 2716
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

using mint=modint998244353;

struct S{
	mint a;
	mint p;
	int s;
};

struct F{
	mint d;
	int i;
};

S op(S l, S r){
	mint k=10; k=k.pow(r.s);
	return S{l.a*k+r.a,l.p*k+r.p,l.s+r.s};
}

S e(){
	return S{0,0};
}

S mapping(F l, S r){
	if(l.d==0) return r;
	return S{l.d*r.p,r.p,r.s};
}

F composition(F l, F r){
	if(l.i<r.i)
		return r;
	else
		return l;
}

F id(){
	return F{0,-1};
}

int main(){
	int n, q; cin >> n >> q;
	vector<S> A(n,S{1,1,1});
	lazy_segtree<S, op, e, F, mapping, composition, id> seg(A);
	int l, r, d;
	REP(i,q){
		cin >> l >> r >> d;
		l--;
		seg.apply(l,r,{d,i});
		S ans=seg.all_prod();
		cout << ans.a.val() << endl;
	}
	return 0;
}

Measured memory_bytes: 13828
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int INF = INT_MAX / 2;

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

	while ( true )
	{
		int n, m;
		cin >> n >> m;

		if ( !( n | m ) )
		{
			break;
		}

		VI as( n ), bs( m );
		FOR( a, as )
		{
			cin >> a;
		}
		FOR( b, bs )
		{
			cin >> b;
		}

		int tota = accumulate( ALL( as ), 0 ), totb = accumulate( ALL( bs ), 0 );

		int res1 = INF, res2 = INF;
		REP( i, 0, n )
		{
			REP( j, 0, m )
			{
				int a = tota - as[i] + bs[j];
				int b = totb + as[i] - bs[j];

				if ( a == b && as[i] + bs[j] < res1 + res2 )
				{
					res1 = as[i];
					res2 = bs[j];
				}
			}
		}

		if ( res1 != INF )
		{
			cout << res1 << ' ' << res2 << endl;
		}
		else
		{
			cout << -1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1196
/*author : Yashvardhan
Thursday, May 09, 2019
6:00 PM
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define endl '\n'

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,m;
	cin>>n>>m;

	vector<pi> arr;

	for(int i = 0; i < n ; i++){
		int a,b;
		cin>>a>>b;
		arr.pb(make_pair(a,b));
	}

	sort(arr.begin(),arr.end());
	int i = 0;
	int ans = 0;
	while(m > 0){
		int qnt = arr[i].ss;
		int cost = arr[i].ff;
		if(qnt >= m){
			ans += cost*m;
			break;
		}
		else{
			ans += cost*qnt;
			m -= qnt;
		}
		i++;
	}

	cout<<ans<<endl;
	

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// GCD,LCMを求める関数
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}

signed main(){
	ll k; cin>>k;
	ll ans = 0;

	for(ll a=1; a<=k; a++){
		for(ll b=1; b<=k; b++){
			ll g = gcd(a,b);
			for(ll c=1; c<=k; c++){
				ans += gcd(c,g);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        new Program().SolveB();
        Console.ReadKey();
    }

    Scanner sc = new Scanner();
    void Solve()
    {
        long a = sc.NextLong();
        string op = sc.Next();
        long b = sc.NextLong();
        if (op == "+")
            Console.WriteLine(a + b);
        else
            Console.WriteLine(a - b);
    }
    void SolveB()
    {
        int N = sc.NextInt();
        int[] T = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++)
        {
            T[i] = sc.NextInt();
            sum += T[i];
        }
        int M = sc.NextInt();
        for (int i = 0; i < M; i++)
        {
            int P = sc.NextInt();
            int X = sc.NextInt();
            Console.WriteLine(sum - T[P - 1] + X);
        }
    }
    // ------------------------------------- //
    int Max(int v1, int v2) { return Math.Max(v1, v2); }
    int Min(int v1, int v2) { return Math.Min(v1, v2); }
    int[][] CreateArray2D(int n1, int n2)
    {
        int[][] ary = new int[n1][];
        for (int i = 0; i < n1; i++) ary[i] = new int[n2];
        return ary;
    }
}
class Scanner
{
    public Scanner() { }
    private string[] buff = null;
    private int bIndex = 0;
    public string Next()
    {
        if (buff == null || bIndex >= buff.Length)
        {
            buff = Console.ReadLine().Split(' ');
            bIndex = 0;
        }
        return buff[bIndex++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
class Pair<T, K>
{
    public Pair() { }
    public Pair(T f, K s)
    {
        first = f;
        second = s;
    }
    public T first {get; set;}
    public K second {get; set;}
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double v[] = new double[n], sum;
		for (int i = 0; i < n; i++) {
			v[i] = sc.nextInt();
		}
		Arrays.sort(v);
		sum = v[0];
		for (int i = 1; i < n; i++) {
			sum = (sum + v[i]) / 2;
		}
		System.out.println(sum);

	}
}

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

using namespace std;

#define MAX_H 50
#define MAX_W 50
#define MAX_S 10

struct State{
  int d,x,y,s,f;
  State(int d,int x,int y,int s,int f) :
    d(d),x(x),y(y),s(s),f(f) {}
};

char M[MAX_H][MAX_W];
bool visited[MAX_H][MAX_W][1<<MAX_S][2];

int getFloor(int x,int y,int f){
  if(M[y][x] == '|'){ return f; }
  if(M[y][x] == '_' || islower(M[y][x])){
    return 0;
  }
  return 1;
}

int main(){
  int H,W,sx,sy,gx,gy,S;
  char MS[MAX_H][MAX_W][MAX_S];
  cin >> W >> H;
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cin >> M[i][j];
      if(M[i][j] == '%'){
        M[i][j] = '_';
        sx = j; sy = i;
      }
      if(M[i][j] == '&'){
        M[i][j] = '_';
        gx = j; gy = i;
      }
    }
  }
  cin >> S;
  for(int i = 0 ; i < S ; i++){
    for(int j = 0 ; j < H ; j++){
      for(int k = 0 ; k < W ; k++){
        cin >> MS[j][k][i];
      }
    }
  }
  int ans = -1;
  memset(visited,false,sizeof(visited));
  visited[sy][sx][0][0] = true;
  const int dx[] = {-1,0,1,0};
  const int dy[] = {0,-1,0,1};
  queue<State> Q;
  Q.push(State(0,sx,sy,0,0));
  while(!Q.empty()){
    State s = Q.front(); Q.pop();
    int x = s.x, y = s.y;
    if(x == gx && y == gy){
      ans = s.d;
      break;
    }
    if(islower(M[y][x])){
      int sw = M[y][x] - 'a';
      int next = s.s ^ (1<<sw);
      int nf = s.f;
      if(MS[y][x][sw] == '*'){
        nf = 1-nf;
      }
      if(!visited[y][x][next][nf]){
        visited[y][x][next][nf] = true;
        Q.push(State(s.d+1,x,y,next,nf));
      }
    }
    if(isupper(M[y][x])){
      int sw = M[y][x] - 'A';
      int next = s.s ^ (1<<sw);
      int nf = s.f;
      if(MS[y][x][sw] == '*'){
        nf = 1-nf;
      }
      if(!visited[y][x][next][nf]){
        visited[y][x][next][nf] = true;
        Q.push(State(s.d+1,x,y,next,nf));
      }
    }
    if(M[y][x] == '|'){
      int next = 1-s.f;
      if(!visited[y][x][s.s][next]){
        visited[y][x][s.s][next] = true;
        Q.push(State(s.d+1,x,y,s.s,next));
      }
    }
    for(int i = 0 ; i < 4 ; i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
      int f = s.f;
      if(0 > nx || W <= nx || 0 > ny || H <= ny){
        continue;
      }
      if(M[ny][nx] == '#'){ continue; }
      int nf = getFloor(nx,ny,f);
      for(int j = 0 ; j < S ; j++){
        if((s.s >> j) & 1){
          if(MS[ny][nx][j] == '*'){
            nf = 1 - nf;
          }
        }
      }
      if(f == nf && !visited[ny][nx][s.s][nf]){
        visited[ny][nx][s.s][nf] = true;
        Q.push(State(s.d+1,nx,ny,s.s,nf));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int c0=0,c1=0;
    string s;
    cin>>s;
    rep(i,s.size())
    {
        if(s[i]=='0')c0++;
        else c1++;
    }

    cout<<2*min(c0,c1)<<endl;
    return 0;
}

Measured memory_bytes: 512
import numpy as	np

n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))

x = np.array(x)

count =	0
for i in range(n):
    for j in range(i+1, n):
        dist = np.linalg.norm(x[i] - x[j])
        if dist == int(dist):
            count += 1

print(count)

Measured memory_bytes: 13416
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

struct Unionfind {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // constructor
  Unionfind(int n = 1) { stree(n + 1); }
  // make and initialization
  void stree(int n = 1) {
    par.resize(n);
    treerank.resize(n);
    for(int i = 0; i < n; ++i) {
      par[i] = i;
      treerank[i] = 0;
    }
  }
  // search root
  int root(int x) {
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] < treerank[y])
      par[x] = y;
    else if(treerank[y] < treerank[x])
      par[y] = x;
    else {
      par[y] = x;
      ++treerank[x];
    }
    return 1;
  }
};

long long n, m;
long long cnt[100005] = {0};
vector<pair<int, int>> v;
Unionfind uf;
vector<long long> ans;

void solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    v.push_back(make_pair(a, b));
  }
  reverse(v.begin(), v.end());
  ans.assign(m, 0);
  solve();
  for(int i = 0; i < m; ++i) cout << ans[m - 1 - i] << endl;
  return 0;
}

void solve() {
  ans[0] = n * (n - 1) / 2;
  uf = Unionfind(n + 1);
  for(int i = 0; i < n; ++i) cnt[i] = 1;
  for(int i = 0; i < m - 1; ++i) {
    long long now = 0, sum = 0;
    if(uf.issame(v[i].fi, v[i].se)) {
      ans[i + 1] = ans[i];
      continue;
    }
    now = sum = cnt[uf.root(v[i].fi)];
    cnt[uf.root(v[i].fi)] = 0;
    now *= cnt[uf.root(v[i].se)];
    sum += cnt[uf.root(v[i].se)];
    cnt[uf.root(v[i].se)] = 0;
    uf.uni(v[i].fi, v[i].se);
    cnt[uf.root(v[i].fi)] = sum;
    ans[i + 1] = ans[i] - now;
  }
}

Measured memory_bytes: 4468
while True:
    h, w = map(int, input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for j in range(w):
            if (i+j)%2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print('')
    print('')


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

int main(){
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int x[N], y[M];
	for(int i = 0; i < N; i++) cin >> x[i];
	for(int i = 0; i < M; i++) cin >> y[i];
	sort(x, x+N);
	sort(y, y+M);
	if(x[N-1] < y[0] && x[N-1] < Y && X < y[0]) cout << "No War" << endl;
	else cout << "War" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int NM = 1e5+10;
vector<ll> a(NM), b(NM), c(NM);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    rep(i, n){
        ll x = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll y = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += x*y;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3840
def read():
    N = int(input())
    S = input()
    return N, S

def solve(N, S, NMAX=4000):
    bucket = [0, 0, 0]
    for i in range(N):
        if S[i] == 'R':
            bucket[0] += 1
        elif S[i] == 'G':
            bucket[1] += 1
        elif S[i] == 'B':
            bucket[2] += 1
    ans = bucket[0] * bucket[1] * bucket[2]
    for i in range(N-2):
        for j in range(i+1, N-1):
            k = j + j - i
            if k >= N:
                continue
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    return ans

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 9240
#include<stdio.h>

int main(void){

        int is_prime[10010], i, j;
        for(i=0; i<10010; i++) is_prime[i] = 1;
        for(i=2; i<10010; i++){
                if(is_prime[i]){
                        for(j=2; i*j<10010; j++) is_prime[i*j] = 0;
                }
        }

        int n;
        while(scanf("%d", &n)!=EOF){
                for(; n>0; n--){
                        if(is_prime[n-2] && is_prime[n]){
                                printf("%d %d\n", n-2, n);
                                break;
                        }
                }
        }
        return 0;
}


Measured memory_bytes: 2044
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        k: i64,
        a: [i64; n],
    }
    const B: usize = 40;
    let mut ch = vec![[0, 0]; B];
    for i in 0..B {
        let mut cnt = 0;
        for j in 0..n {
            if (a[j] & 1 << i) != 0 { cnt += 1; }
        }
        ch[i] = [cnt as i64, (n - cnt) as i64];
    }
    let mut ma = 0;
    let mut k = k + 1;
    while k > 0 {
        let lsb = k & (-k);
        let mut tot = 0;
        for i in 0..B {
            tot += ch[i][(k >> i & 1) as usize] << i;
        }
        let mut u = 1;
        let mut pos = 0;
        while u < lsb {
            if ch[pos][0] < ch[pos][1] {
                tot += (ch[pos][1] - ch[pos][0]) << pos;
            }
            u *= 2;
            pos += 1;
        }
        tot += (ch[pos][0] - ch[pos][1]) << pos;
        ma = max(ma, tot);
        k &= k - 1;
    }
    puts!("{}\n", ma);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 110;

int n, m;
int a, b, c;
int p[N], q[N], r[N];
priority_queue<int, vector<int>, greater<int>> heap;

int main()
{
	scanf("%d%d", &n, &m);
	scanf("%d%d%d", &a, &b, &c);
	for (int i = 0; i < a; i ++ ) scanf("%d", &p[i]);
	for (int i = 0; i < b; i ++ ) scanf("%d", &q[i]);
	for (int i = 0; i < c; i ++ ) scanf("%d", &r[i]);
	sort(p, p + a);
	sort(q, q + b);
	sort(r, r + c);
	
	for (int i = a - 1; i >= a - n; i -- ) heap.push(p[i]);
	for (int i = b - 1; i >= b - m; i -- ) heap.push(q[i]);
	
	for (int i = c - 1; i >= 0; i -- )
		if (r[i] > heap.top())
		{
			heap.pop();
			heap.push(r[i]);
		}
		
	LL res = 0;
	while (heap.size())
	{
		res += heap.top();
		heap.pop();
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 2552
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long long int> VLL;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    io;
    int n;
    cin >> n;
    VI v(n+1), w(n+1);
    FOR (i, 1, n+1) {
        cin >> v[i] >> w[i];
    }

    int nv = min((1<<9)+1, n+1);
    vector<VI> dp(nv, VI(100001));
    FOR (j, 0, 100001) {
        if (j >= w[1])
            dp[1][j] = v[1];
    }
    FOR (i, 2, nv) {
        FOR (j, 0, 100001) {
            if (j >= w[i]) {
                dp[i][j] = max(dp[i/2][j], dp[i/2][j-w[i]] + v[i]);
            } else {
                dp[i][j] = dp[i/2][j];
            }
        }
    }

    int q;
    cin >> q;
    int ver, l;

    FOR (i, 0, q) {
        cin >> ver >> l;
        VI rem;
        while (ver >= nv) {
            rem.pb(ver);
            ver /= 2;
        }
        if (SZ(rem) == 0) {
            cout << dp[ver][l] << "\n";
        } else {
            int msk = (1<<SZ(rem));
            int ans = 0;
            FOR (j, 0, msk) {
                int we = 0, val = 0;
                FOR (k, 0, SZ(rem)) {
                    if (j&(1<<k)) {
                        we += w[rem[k]];
                        val += v[rem[k]];
                    }
                }
                if (we > l)
                    continue;
                else {
                    ans = max(ans, val + dp[ver][l-we]);
                }
            }
            cout << ans << "\n";
        }

    }
}
//check for edge cases in limits
//printing double may print 1.223232e9 like values, beware of that


Measured memory_bytes: 206692
list_NM = list(map(int, input().split())) #0:N,1:M
list_A = list(map(int, input().split())) 
i = 0
number_all = 0
N = list_NM[0]
M = list_NM[1]
while all:
    number_all += list_A[i]
    i += 1
    if(i==N):
        break
i = 0
kijun = number_all/(4*M)
flag = 0
while all:
    if(kijun<=list_A[i]):
        flag +=1
    i += 1

    if(i==N):
        break

if(flag>=M):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import heapq

n, k = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for i in range(min(n, k)+1):  # a+b
    for a in range(i+1):  # 操作A
        b = i - a  # 操作B
        L = V[:a] + V[n-b:]
        heapq.heapify(L)
        total = sum(L)
        for j in range(k-i):
            if not L:
                break
            if L[0] >= 0:
                break
            total -= heapq.heappop(L)
        ans = max(ans, total)

print(ans)

Measured memory_bytes: 75284
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <utility>

using die = std::pair<char, std::string>;

die get_die() {
  char a, b, c, d, e, f;
  scanf(" %c%*s %c%*s %c%*s %c%*s %c%*s %c%*s",
        &a, &b, &c, &d, &e, &f);

  char bot;
  std::string side;
  if (a == 'R') {
    bot = f;
    side += b;
    side += c;
    side += e;
    side += d;
  } else if (b == 'R') {
    bot = e;
    side += c;
    side += a;
    side += d;
    side += f;
  } else if (c == 'R') {
    bot = d;
    side += f;
    side += e;
    side += a;
    side += b;
  } else if (d == 'R') {
    bot = c;
    side += a;
    side += e;
    side += f;
    side += b;
  } else if (e == 'R') {
    bot = b;
    side += d;
    side += a;
    side += c;
    side += f;
  } else if (f == 'R') {
    bot = a;
    side += b;
    side += d;
    side += e;
    side += c;
  }

  std::string mside = side;
  for (int i = 1; i < 4; ++i) {
    std::rotate(side.begin(), side.begin()+1, side.end());
    mside = std::min(mside, side);
  }

  return {bot, mside};
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::set<die> d;
  for (size_t i = 0; i < n; ++i) {
    d.insert(get_die());
  }
  printf("%zu\n", n-d.size());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2792
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
    int n;
    cin >> n;
    rep(i,50000) {
        int r = (i+1)*1.08;
        if (r == n) {
            cout << i+1 << "\n";
            return 0;
        }
    }
    cout << ":(" << "\n";
}


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

using namespace std;


int main() {
	int N, limit;
	cin >> N >> limit;
	int min = 0,cost = 1001;
	int c,t;
	for (int i = 0; i < N; i++) {
		cin >> c>>t;
		
		if (t <= limit && c < cost) {
			min = c;
			cost = c;
		}
	}
	if (cost == 1001) cout << "TLE" << endl;else cout << min;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  string w;
  cin >> w;
  bool ans = true;
  for (char i = 'a'; i <= 'z';i++){
    ll x = count(all(w), i);
    if(x%2!=0){
      ans = false;
    }
  }
  if(ans){
    print("Yes");
  }
  else{
    print("No");
  }
}

Measured memory_bytes: 256
/*input
6 3 4
3
1
3
2


*/
#include <bits/stdc++.h>
using namespace std;
#define int long long int
// int dp[5003][5003];
#define maxl( X, Y) ((X) > (Y))? X : Y
// const int nax =100;
const int maxn = 2e5 +5;
#define bug(x) cout << #x << " " << x << "\n";
#define max( x, y) ( (x) > (y) ? (x ) : (y))
#define min( x, y) ( (x) > (y) ? (y ) : (x))
int exp(int a, int n)
{
	if ( n==0)
		return 1;
	if ( n==1 )
		return a;
	if ( n & 1)
		return (a * exp((a*a), n/2));
	else
		return exp((a*a), n/2);
}
int freq[maxn];
signed main(){
	int n;
	int k , q;
	cin >> n >> k >> q;

	for ( int i =0; i < q;  i++)
	{
		int x;
		cin >> x;
		freq[x]++;
	}
	// ans =k -q + freq
	for ( int i =0; i <= n; i++)
	{
		freq[i] = k - q + freq[i];
	} 
	for ( int i =1; i <= n; i++)
	{
		if ( freq[i] > 0)
			cout << "Yes\n";
		else
			cout <<"No\n";
	}


}

Measured memory_bytes: 1408
import heapq
import math
INF=math.inf
V, E, r = map(int, input().split())
edges = [[] for i in range(V)]
dist = [INF] * V
visited = [0] * V
node_heap=[]
for i in range(E):
    lst = list(map(int, input().strip().split()))
    edges[lst[0]].append([lst[0],lst[1],lst[2]])

dist[r] = 0
cur_node=r     #current_node
visited[r] = 1
#始点ノードから伸びているものに関して追加
for cur_edges in edges[cur_node]:
    heapq.heappush(node_heap,[dist[r]+cur_edges[2],cur_edges[1]]) #(到着ノードまでの総距離,到着のーど)
while node_heap:
    shortest_route = heapq.heappop(node_heap)
    if visited[shortest_route[1]]:
        continue
    cur_node = shortest_route[1]
    dist[cur_node]=shortest_route[0]
    for cur_edges in edges[cur_node]:
        if visited[cur_edges[1]]==0:
            heapq.heappush(node_heap, [dist[cur_node] + cur_edges[2], cur_edges[1]])
    visited[cur_node]=1

for i in range(V):
    if dist[i] == INF:
        print("{}".format("INF"))
    else:
        print("{}".format(dist[i]))






Measured memory_bytes: 126268
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>
#include <chrono>
#include <cmath>

#define int long long

using namespace std;


const int INF = 1e15;

signed main() {
  int n, m, x;
  cin >> n >> m >> x;

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

  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      int t;
      cin >> t;
      a[i].push_back(t);
    }
  }

  int cost_min = INF;

  for (int bits = 0; bits < (1LL << n); bits++) {
    int cost = 0;
    vector<int> ability(m);

    for (int j = 0; j < n; j++) {
      if ((bits & (1 << j)) != 0) {
        cost += c[j];
        for (int k = 0; k < m; k++) {
          ability[k] += a[j][k];
        }
      }
    }

    bool flag = true;
    for (int j = 0; j < m; j++) {
      if (ability[j] < x) {
        flag = false;
        break;
      }
    }

    if (flag) {
      if (cost < cost_min) {
        cost_min = cost;
      }
    }

  }

  if (cost_min == INF) {
    cost_min = -1;
  }

  cout << cost_min << endl;

  return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmax(T& ref, const T value) {
	if (ref < value) ref = value;
}

const ll mod = 1000000007;

class modint {
	static constexpr std::int_fast64_t Modulus = 1e9 + 7;
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
};

ostream& operator<<(ostream& stream, const modint& data) {
	stream << data.a;
	return stream;
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> as(n);
	rep(i, n) cin >> as[i];

	vector<vector<modint>> dp(n + 1, vector<modint>(k + 2, 0));
	vector<vector<modint>> sums(n + 1, vector<modint>(k + 2, 0));
	//dp[i][j]...i番目までの人でj-1個をわける組み合わせ
	//dp[i][0]...dp[i-1][0];
	//dp[i][1]...dp[i-1][1] + dp[i-1][0];
	//dp[i][2]...dp[i-1][2] + dp[i-1][1] + dp[i-1][0];
	//dp[i][j]...dp[i-1][j] + dp[i-1][j-1] + dp[i-1][j-as[i]];
	for (int i = 0; i <= as[0]; i++) {
		dp[0][i+1] = 1;
	}
	rep(i, k+1) {
		sums[0][i + 1] = sums[0][i] + dp[0][i + 1];
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= k; j++) {
			dp[i][j + 1] = sums[i - 1][j + 1] - sums[i - 1][max(0LL, j + 1 - as[i] - 1)];
		}
		rep(j, k + 1) {
			sums[i][j + 1] = sums[i][j] + dp[i][j + 1];
		}
	}
	cout << dp[n - 1][k+1] << endl;
    return 0;
}


Measured memory_bytes: 161888
/*  
    tanuj_johal :: gla_clg_sync_with_CSE(true);
    bonding.tie(true);
    hardwork.tie(true);
    
    ::::::::--------------------::::::::
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define f(i,a,b)    for(ll i=a;i<b;i++)
#define f0(i,n)     f(i,0,n)
#define arr(a,n)    int a[n];f0(i, n) cin >> a[i];
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,vi> g;
unordered_map<ll,ll> vis;

const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 1e5+10;


bool imp = false;
void solve()
{
    ll k;cin>>k;
    string s;cin>>s;
    string temp = "";
    k = min(k,(ll)s.size());
    for(ll i=0;i<k;i++)
        temp+=s[i];
    cout<<temp;
    
    if(k != s.size())
        cout<<"...";
}

int main()
{
    fio
    int t=1;
    if(imp) cin>>t;
    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }
    
}


Measured memory_bytes: 3656
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (a > b)
        a = b;
    if (c > d)
        c = d;
    a += c;
    printf("%d", a);
    return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

int N, M;
int A[100100];
int B[100100];

signed main() {
    cin >> N >> M;
    rep(i, N) {
        cin >> A[i];
    }
    sort(A, A + N);

    int can = 0;//Ai+Aj>=canとなる(i,j)がM通り以上ある
    int cant = 100000 * 2 * N + 1;//Ai+Aj>=cantとなる(i,j)はM通り未満
    while (cant - can > 1) {
        int m = (can + cant) / 2;
        int num = 0;
        for (int i = N - 1; i >= 0; --i) {
            num += A + N - lower_bound(A, A + N, m - A[i]);
            if (num >= M)break;
        }
        if (num >= M)can = m;
        else cant = m;
    }
    rep(i, N) {
        B[i + 1] = B[i] + A[i];
    }
    int ans = 0;
    int num = 0;
    rep(i, N) {
        //Ai+Aj>canのものを足す
        int idx = upper_bound(A, A + N, can - A[i]) - A;
        //A[idx],A[idx+1],...,A[N-1]
        num += N - idx;
        ans += A[i] * (N - idx) + B[N] - B[idx];
    }
    ans += (M - num) * can;
    cout << ans << endl;
    return 0;
}


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

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

    int res = 0; // a>b : 1   a=b : 0 a<b : -1
    
    if(a.size()>b.size())
        res = 1;
    if(a.size()<b.size())
        res = -1;
    if(a.size() == b.size()){
        for(int i=0; i<a.size(); i++){
            if(a.at(i)>b.at(i)){
                res = 1; break;
            }else if(a.at(i) < b.at(i)){
                res = -1; break;
            }
        }
    }
        
    if(res == 1)
        cout << "GREATER" << endl;
    else if(res == -1)
        cout << "LESS" << endl;
    else if(res == 0)
        cout << "EQUAL" << endl;

    return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int count = 0;
            for(int i = 0; i < N - 2; i++)
            {
                string ABC = S.Substring(i, 3);
                if(ABC == "ABC")
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);
const ll MOD = (ll)(1e9 + 7);

int n;
ll t[MAX_N];
ll a[MAX_N];

bool et[MAX_N];

int main(void) {
  // Here your code !
  scanf("%d", &n);

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

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

  if (t[n - 1] != a[0]) {
    printf("%d\n", 0);
    return 0;
  }

  et[0] = true;

  for (int i = 1; i < n; ++i) {
    if (t[i] > t[i - 1]) {
      et[i] = true;
    } else {  // t[i] == t[i - 1]
      et[i] = false;
    }
  }

  // for (int i = 0; i < n; ++i) {
  //   printf("%d", et[i]);
  // }
  // printf("\n");

  ll ans = 1LL;

  for (int i = n - 2; i >= 0; --i) {
    if (a[i] > a[i + 1]) {  // i-th height must be exact from a's sight
      if (et[i]) {          // both are exact
        if (a[i] != t[i]) {
          ans = 0LL;
          break;
        } else {
          ans *= 1LL;
          ans %= MOD;
        }
      } else {              // a is exact, t is not exact
        if (a[i] > t[i]) {  // since a is exact, t must be bigger than a
          ans = 0LL;
          break;
        } else {
          ans *= 1LL;
          ans %= MOD;
        }
      }
    } else {                // a[i] == a[i + 1]
      if (et[i]) {          // t is exact, a is not exact
        if (a[i] < t[i]) {  // since t is exact, a must be bigger than t
          ans = 0LL;
          break;
        } else {
          ans *= 1LL;
          ans %= MOD;
        }
      } else {  // t is not exact
        ans *= min(a[i], t[i]);
        ans %= MOD;
      }
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string rank[6];
	cin>>n;
	while(n--){
		double input;
		cin>>input;
		if(input<165.0)rank[0]+='*';
		else if(165.0<=input&&input<170.0)rank[1]+='*';
		else if(170.0<=input&&input<175.0)rank[2]+='*';
		else if(175.0<=input&&input<180.0)rank[3]+='*';
		else if(180.0<=input&&input<185.0)rank[4]+='*';
		else if(185.0<=input)rank[5]+='*';
	}
	for(int i=0;i<6;i++){
		cout<<i+1<<':'<<rank[i]<<endl;
	}
}

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

int main() {
    int n;
    cin >> n;
    int *a = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int temp, mini, cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        mini = i + 1;
        //cout << "i: " << i <<endl;
        for (int j = i + 1; j < n; j++) {
            //cout << "j: " << j << endl;
            if (a[mini] > a[j]) {
                mini = j;
            }
            //cout << "mini: " << mini << endl;
        }
        if (a[mini] < a[i]) {
            temp = a[i];
            a[i] = a[mini];
            a[mini] = temp;
            ++cnt;
            /*for (int k = 0; k < n; k++) {
                cout << a[k] << " ";
            }
            cout << endl;*/
        }
    }
    for (int i = 0; i < n - 1; i++) {
        cout << a[i] << " ";
    }
    cout << a[n - 1] << endl;
    cout << cnt << endl;
    delete [] a;
    return 0;
}

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

int main() {
    int A, B, C, X;
    scanf("%d%d%d%d", &A, &B, &C, &X);

    int count = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                int amount = 500 * i + 100 * j + 50 * k;
                if (amount == X) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int a[N], b[N];
int main() {
    int n;
    cin >> n;
    ll s = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(i == 0) {
            s = a[i];
        } else {
            if(i & 1) {
                s -= a[i];
            } else {
                s += a[i];
            }
        }
    }
    b[0] = s;
    for(int i = 0; i < n; i++) {
        b[i+1] = a[i]*2 - b[i];
    }
    for(int i = 0; i < n; i++) {
        cout << b[i] << " \n"[i == n - 1];
    }
    return 0;
}

Measured memory_bytes: 2048
#TLE
# 0と1を数えて少ないほうの2倍を取れば勝ち
S = list(input())
count0 = 0
count1 = 0
for i in range(len(S)):
    if S[i]=='0':
        count0 += 1
    else:
        count1 += 1
print(2*min(count0,count1))


Measured memory_bytes: 3956