akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = a; i <= b; ++ i)
#define SZ(x) int(x.size())

using namespace std;

const int maxn = 100 + 4, maxm = 1e7 + 10;
int P[maxn], C[maxn], n, vis[maxm];
int notprim[maxm], S[maxm];
vector<int> num, prime;

void Get_prime(int m)
{
	notprim[0] = notprim[1] = 1;
	For(i, 2, m)
	{
		if(!notprim[i])
			prime.push_back(i);
		int len = prime.size();
		For(j, 0, len - 1)
		{
			if(prime[j] * i > m)
				break;
			notprim[prime[j] * i] = 1;
			if(i % prime[j] == 0)
				break;
		}
	}
}

namespace Match
{
	const int N = 1e7 + 10;
	int to[N], head[N], nxt[N], e;
	int pre[N], vis[N], G[N], O[N], now, sum;
	void add(int x, int y)
	{
		to[++ e] = y;
		nxt[e] = head[x];
		head[x] = e;
	}
	bool dfs(int x)
	{
		go(x, i)
		{
			if(vis[to[i]] != now)
			{
				vis[to[i]] = now;
				if(!pre[to[i]] || dfs(pre[to[i]]))
				{
					pre[to[i]] = x;
					return 1;
				}
			}
		}
		return 0;
	}
	int match()
	{
		int res = 0;
		for(now = 1; now <= G[0]; ++ now)
			res += dfs(now);
		return res;
	}
	void solve()
	{
		int res = 0;
		For(i, 0, SZ(num) - 1)
			if(num[i] & 1)
				G[++ G[0]] = num[i];
			else
				O[++ O[0]] = num[i];
		For(i, 1, G[0])
			For(j, 1, O[0])
				if(!notprim[abs(G[i] - O[j])])
					add(i, j);
		res += match();
		memset(vis, 0, sizeof(vis));
		G[0] -= res, O[0] -= res;
		res += G[0] / 2 * 2, G[0] %= 2;
		res += O[0] / 2 * 2, O[0] %= 2;
		if(G[0] * O[0])
			res += 3;
		cout << res << endl;
	}
}

int main()
{
	Get_prime(1e7 + 5);
	scanf("%d", &n);
	For(i, 1, n)
		scanf("%d", &P[i]), vis[P[i]] ^= 1;
	For(i, 1, maxm - 1)
		if(vis[i] != vis[i - 1])
			num.push_back(i);
	memset(vis, 0, sizeof(vis));
	Match::solve();
	return 0;
}


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

int main() {
    int k;
    cin >> k;
    vector<ll> a;
    for(int i = 1; i <= 9; ++i) a.push_back(i);
    while(1){
        if(k<=a.size()){
            cout << a[k-1] << endl;
            break;
        }
        else{
            k-=a.size();
            vector<ll> old;
            swap(a, old);
            for(ll x : old){
                for(int i = -1; i <= 1; ++i){
                    int d = x%10 + i;
                    if(d < 0 || d > 9) continue;
                    a.push_back(x*10 + d);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1712
"""
AtCoder
    :author: vierbein
"""
from __future__ import absolute_import, division, print_function

# import itertools as it
from collections import *
import sys
import functools


def pp(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

N = int(input().strip())
xs = ["".join(sorted(input())) for _ in range(N)]
res = sum(cnt * (cnt - 1) // 2 for cnt in Counter(xs).values())
print(res)


Measured memory_bytes: 19944
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repit(it,u) for(__typeof((u).begin())it=(u).begin();it!=(u).end();++it)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define uniq(u) (u).erase(unique(all(u)),(u).end())
#define ll long
#define long int64_t
#define mp make_pair
#define pb push_back

typedef double number;
typedef vector<vector<number> > matrix;

inline number my_hypot(number x, number y) { return sqrt(x * x + y * y); }
inline void givens_rotate(number& x, number& y, number c, number s) {
    number u = c * x + s * y, v = -s * x + c * y;
    x = u, y = v;
}
vector<number> givens(matrix A, vector<number> b) {
    const int n = b.size();
    rep(i, n) repi(j, i + 1, n) {
        const number r = my_hypot(A[i][i], A[j][i]);
        const number c = A[i][i] / r, s = A[j][i] / r;
        givens_rotate(b[i], b[j], c, s);
        repi(k, i, n) givens_rotate(A[i][k], A[j][k], c, s);
    }
    for (int i = n - 1; i >= 0; --i) {
        repi(j, i + 1, n) b[i] -= A[i][j] * b[j];
        b[i] /= A[i][i];
    }
    return b;
}

const double eps = 0.01;

int d;
vector<number> v;

vector<number> solve_eq(int m, int n){
    matrix A(d+1,vector<number>(d+1));
    vector<number> b(d+1);
    int cnt = 0;
    rep(i,d+3)if(i != m && i != n){
        b[cnt] = v[i];
        rep(j,d+1) A[cnt][j] = pow(1.0*i,1.0*j);
        cnt++;
    }
    return givens(A,b);
}

int main(){
    while(cin >> d, d){
        v.resize(d+3);
        int ans = -1;
        rep(i,d+3) cin >> v[i];
        rep(i,d+3){
            repi(j,i+1,d+3){
                vector<number> b = solve_eq(i,j);
                number e = 0, f = 0;
                rep(k,d+1) e += pow(1.0*i,1.0*k) * b[k];
                rep(k,d+1) f += pow(1.0*j,1.0*k) * b[k];
                if(abs(e-v[i]) > eps && abs(f-v[j]) < eps){
                    ans = i;
                    break;
                }
                if(abs(e-v[i]) < eps && abs(f-v[j]) > eps){
                    ans = j;
                    break;
                }
            }
            if(ans >= 0) break;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1320
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
void solve() {
	lli ret = 0;
	map <lli, lli> m;
	lli n;
	cin >> n;
	for (lli i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			m[i]++;
			n /= i;
		}
	}
	if (n > 1) m[n]++;
	for (auto& it : m) {
		lli low = 1;
		lli high = it.ss;
		lli cnt = 1;
		while (low <= high) {
			lli mid = low + (high - low) / 2;
			if (it.ss - (mid * (mid + 1)) / 2 >= 0) {
				cnt = mid;
				low = mid + 1;
			} else high = mid - 1;
		}
		ret += cnt;
	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 3664
a = 0
while a < 100:
    h, w = map(int, input().split())

    if h == 0 and w == 0:
        break
    elif h == 1 and w == 1:
        print("#")
    elif h % 2 == 0 and w % 2 == 0:
        b = 0
        while b <= (h - 2) / 2:
            for i in range(int(w/2)):
                print("#.", end = "")
            print()
            for j in range(int(w/2)):
                print(".#", end = "")
            print()
            b += 1
    elif h % 2 == 1 and w % 2 == 0:
        b = 0
        while b < (h - 2) / 2:
            for i in range(int(w/2)):
                print("#.", end = "")
            print()
            for j in range(int(w/2)):
                print(".#", end = "")
            print()
            b += 1
        for i in range(int(w/2)):
            print("#.", end = "")
        print()
    elif h % 2 == 0 and w % 2 == 1:
        b = 0
        while b <= (h - 2) / 2:
            for i in range(int(w/2)):
                print("#.", end = "")
            print("#")
            for j in range(int(w/2)):
                print(".#", end = "")
            print(".")
            b += 1
    elif h % 2 == 1 and w % 2 == 1:
        b = 0
        while b <= (h - 2) / 2:
            for i in range(int(w/2)):
                print("#.", end = "")
            print("#")
            for j in range(int(w/2)):
                print(".#", end = "")
            print(".")
            b += 1
        for i in range(int(w/2)):
            print("#.", end = "")
        print("#")
    print()
    a += 1


Measured memory_bytes: 6400
#include<bits/stdc++.h> 
#define ll long long
#define pb push_back
using namespace std;

const int mod = 1e9+7;
vector<int> dp(100005,-1);
vector<int> vis(1000005,false);
vector<int> adj[100005];

void dfs(int node,int pa){
  if(vis[node]){
  return ; 
  }
  if(adj[node].size()==0){
    vis[node]=true;
    dp[node]= 0;
    return ;
  }
  int ans=INT_MIN;
  for(auto i : adj[node]){
    if(i==pa)
      continue;
    if(dp[i]==-1)
      dfs(i,node);
    ans = max(ans, 1+ dp[i]);
  }
  dp[node] = ans;
  vis[node] = true;
  return;
}
int main(){
  int n,m;
  cin>>n>>m;
  
  for(int i=0;i<m;i++){
  int a,b;cin>>a>>b;
   adj[a].pb(b);
  }
  int ans=INT_MIN;
  for(int i=1;i<=n;i++){
    if(!vis[i])
      dfs(i,0);
  }
  for(int i=1;i<=n;i++)
    ans= max(ans,dp[i]);
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 16320
using System;

namespace ConsoleApp31
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] array = line.Split(' ');

            int x = int.Parse(array[0]);
            int y = int.Parse(array[1]);

            if (y % 2 == 0)
            {
                if (x*2 <= y  && x*4 >= y )
                {
                    Console.WriteLine("Yes");
                }
                else
                { Console.WriteLine("No"); }
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 27512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    for(int i=L;i<=R;i++)
    {
        if(i%d==0)
        {
            ans++;
        }
    }

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

Measured memory_bytes: 3604
#include <cstdio>
#include <iostream>
#include <string>


using namespace std;



int main() {
	string str;
	int i,j,max;

	cin >> str;

	for (i = str.size()-3; i > 0; --i) {
		for (j = 0, max = i / 2 + 1; j < max; ++j) {
			if (str[j] != str[j + max])
				break;
		}
		if (j == max)
			break;
	}
	cout << i+1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define mod 100000
int w,h,memo[101][101][5];
int solve(int y,int x,int shine){
  if(y<0 || y >= h || x < 0 || x >= w) return 0;
  if(memo[y][x][shine]) return memo[y][x][shine];
  if(y == h - 1 && x == w - 1) return 1;
  if(!shine) //生きてる☆
    return memo[y][x][shine] = solve(y+1,x,1) + solve(y,x+1,2) % mod;
  if(shine == 1) // 死にそう^v^
    return memo[y][x][shine] = solve(y+1,x,1) + solve(y,x+1,4) % mod;
  if(shine == 2) // 死にそう^v^
    return memo[y][x][shine] = solve(y+1,x,3) + solve(y,x+1,2) % mod;
  if(shine == 3) //死んでる(・^・)
    return memo[y][x][shine] = solve(y+1,x,1) % mod;
  if(shine == 4) //死んでる(・^・)
    return memo[y][x][shine] = solve(y,x+1,2) % mod;
}
int main(){
  while(cin >> w >> h , w){
    fill_n(memo[0][0],101*101*5,0);
    cout << solve(0,0,0) % mod <<endl;
  }
}

Measured memory_bytes: 1364
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/

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

    int k, n;
    cin>>k>>n;
    vector<int> a(n+1);
    for (int i = 0; i<n; i++) cin>>a[i];
    a[n] = k + a[0];
    int maxx = 0;
    for (int i = 0; i<n; i++) maxx = max(maxx, a[i+1] - a[i]);
    cout<<k - maxx;

}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    vector<int> cnt(N,0);
    REP(i,N){
        if(A[i]&1==N&1){
            cout<<0<<endl;
            return 0;
        }
        cnt[A[i]]++;
    }
    if(cnt[0]>1){
        cout<<0<<endl;
        return 0;
    }
    rep(i,1,N) if(cnt[i]!=0&&cnt[i]!=2){
        cout<<0<<endl;
        return 0;
    }
    N/=2;
    ll ans=1,mod=1e9+7;
    ll x=2;
    while(N){
        if(N&1) ans=ans*x%mod;
        x=x*x%mod;
        N>>=1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int dem=0,vt=-1,vt1=-1,vt2=-1;
    string s,c="abc";
    cin>>s;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<c.size();j++){
            if(s[i]==c[j]){
                dem++;
                c.erase(j,1);
            }
        }
    }
    (dem==3) ? cout<<"Yes" : cout<<"No";
    
    return 0;
}

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

vector<int> num;

int mochictrl(int x) {
  if(x == 0) return 0;
  if(num[x] == num[x - 1]) num.erase(num.begin() + x);
  return mochictrl(x - 1);
}

int main() {
  int temp, mochis;
  cin >> mochis;
  for(int i = 0; i < mochis; i++ ) {
    cin >> temp;
    num.push_back(temp);
  }
  sort(num.begin(),num.end());
  mochictrl(mochis);
  cout << num.size() << endl;
  //cout << "↓配列" << endl;
  //for(auto& x:num) {
  //  cout << x << endl;
  //}
}



Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	lint N,K;
	lint ans=0;
	
	cin >> N >> K;
	
	for(lint b=K+1;b<=N;b++)
	{
		lint p=N/b,r=N%b;
		ans+=p*max(b-K,0ll);
		ans+=max(r+1-K,0ll);
	}
	
	if(K==0)ans-=N;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef int LL;
const LL maxn=1e6+9,inf=0x3f3f3f3f;
inline LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
LL T,n;
int main(){
	n=Read();
	LL A(Read()),B(Read());
	printf("%d\n",std::min(n*A,B));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int A[100000],n;

int binarysearcch(int key){
    int left=0;
    int right=n;
    int mid;
    while(left<right){
        mid = (left+right)/2;
        if(key==A[mid])return 1;
        if(key>A[mid])left = mid +1;
        else if(key<A[mid])right=mid;
            }
    return 0;
}

int main(void){
    int i,q,k,sum =0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&k);
        if(binarysearcch(k))sum++;
    }
    printf("%d\n",sum);
    
    return 0;
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int minusmod(ll &n){
  // -2で割ったあまりを返す
  // 引数は-2で割る
  if (n > 0){
    ll res = n % 2;
    n /= -2;
    return (int)res;
  }else if (n % 2 == 0){
    n /= -2;
    return 0;
  }else{
    n = -n + 1;
    n /= 2;
    return 1;
  }
}

int main() {
  ll n; cin >>n;
  stack<int> S;
  if (n == 0) S.push(0);
  while (abs(n) > 0){
    S.push(minusmod(n));
  }
  while (!S.empty()){
    cout <<S.top(); S.pop();
  }
  cout <<endl;
}

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

using namespace std;


int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int &a:A) cin >> a;
    
    int ans = 0;
    int cnt = 1;
    for(int i=1; i<N; i++){
        if(A[i]==A[i-1]) cnt ++;
        else {
            ans += cnt/2;
            cnt = 1;
        }
    }
    ans += cnt/2;
    cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())

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

cnt = 0

for i in range(N):
    if D[i][0] == D[i][1]:
        cnt += 1
    elif cnt < 3:
        cnt = 0

if cnt >= 3:
    print('Yes')
else:
    print('No')

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

const int N = 2e3+5;
int h,w;
char a[N][N];
vector<int> p1[N], p2[N];

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

    cin >> h >> w;
    for(int i=1;i<=h;i++){
        p1[i].push_back(0);
        for(int j=1;j<=w;j++){
            cin >> a[i][j];
            if(a[i][j] == '#')p1[i].push_back(j);
        }
        p1[i].push_back(w+1);
    }

    for(int j=1;j<=w;j++){
        p2[j].push_back(0);
        for(int i=1;i<=h;i++){
            if(a[i][j] == '#')p2[j].push_back(i);
        }
        p2[j].push_back(h+1);
    }

    int ans = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(a[i][j] == '.'){
                int x = upper_bound(p1[i].begin(), p1[i].end(), j) - p1[i].begin();
                int left = p1[i][x-1], right = p1[i][x];
                int y = upper_bound(p2[j].begin(), p2[j].end(), i) - p2[j].begin();
                int up = p2[j][y-1], down = p2[j][y];
                int res = (right - left) + (down - up) - 3;
                ans = max(ans, res);
            }
        }
    }

    cout << ans << '\n';



    return 0;
}


Measured memory_bytes: 36352
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin >>a>>b>>c>>d;
    int R,L;
    R=c+d;
    L=a+b;
    if(R==L){
        cout <<"Balanced"<<endl;
    }else if(R<L){
        cout <<"Left"<<endl;
        
    }else if(L<R){
        cout <<"Right"<<endl;
    }
    
        
    
}


Measured memory_bytes: 256
# ２部マッチング
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]

def dfs(v, visited):
    for u in edge[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], visited):
            matched[u] = v
            return True
    return False

matched = [-1] * N
edge = [set() for _ in range(N)]
for i, a in enumerate(A):
    for j, b in enumerate(B):
        if a[0] < b[0] and a[1] < b[1]:
            edge[i].add(j)
print(sum(dfs(v, set()) for v in range(N)))

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

using namespace std;

using bellman_cost = long long;

template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};

template<class T>
struct Vertex_Cost
{
	T cost;
	bool valid = false;
	Vertex_Cost(T v1) : cost(v1) {}
	Vertex_Cost() {}
};
using vertex = Vertex_Cost<bellman_cost>;

template<class T>
struct Edge_Cost
{
	int to;
	T cost;
	Edge_Cost(int t, T c) : to(t), cost(c) {}
	Edge_Cost() {}
};
using edge = Edge_Cost<bellman_cost>;
using graph = Graph<vertex, edge>;

template<class T, class V, class E>
void Bellmanford(Graph<V, E>& G, int s, T INF_COST)
{
	auto &v = G.v;
	auto &e = G.e;
	for (auto& vv : v) vv.cost = INF_COST, vv.valid = false;
	v[s].cost = 0;
	v[s].valid = true;
	for (int i = 0; i + 1 < (int) v.size(); i++) {
		for (int j = 0; j < (int) v.size(); j++) {
			for (auto& x: e[j]) {
				if (v[j].cost == INF_COST) continue;
				v[x.to].cost = min(v[x.to].cost, v[j].cost + x.cost);
				v[x.to].valid = true;
			}
		}
	}
	auto valid_check = [&](auto f, int pos) {
		if (!v[pos].valid) return;
		v[pos].valid = false;
		for (auto& y: e[pos]) {
			f(f, y.to);
		}
	};
	for (int i = 0; i < (int) v.size(); i++) {
		for (auto& x: e[i]) {
			if (v[i].cost == INF_COST) continue;
			if (v[x.to].cost > v[i].cost + x.cost) {
				valid_check(valid_check, x.to);
			}
		}
	}
}

int main() {
	int N, M;
	cin >> N >> M;
	graph g(N);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		g.add_edge(a-1, b-1, -c);
	}
	Bellmanford(g, 0, LLONG_MAX);
	if (g.v[N-1].valid) cout << -g.v[N-1].cost << endl;
	else cout << "inf" << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;


int main() {
    long long int k,a,b;
    cin >> k >> a >> b;
    long long int ans = 1;
    long long int now = a;
    long long int kk = a - b;
    if(now >= k) {
        cout << ans << endl;
        return 0;
    }
    if(kk <= 0) {
        cout << -1 << endl;
        return 0;
    }
    ans +=  ((k - now) / kk + ((k - now) % kk != 0 ? 1: 0)) * 2;

    cout << ans << endl;
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int H = scan.nextInt();
			int W = scan.nextInt();
			if(H == 0 && W == 0)
				break;
			for(int i = 1;i <= H; i++){
				for(int j = 1; j <= W; j++){
					if(((i % 2 == 0) && (i != 0) && (j % 2 == 0) && (j != 0)) || (i % 2 != 0) && (j % 2 != 0)){
						System.out.print("#");
					}else{
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}

	}

}

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

int main(){
  int H,W;
  cin >> H >> W;
  char S[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> S[i][j];
    }
  }
  for(int i=-1;i<=H;i++){
    if(i==-1||i==H){
      for(int j=-1;j<=W;j++){
        cout << "#";
      }
      cout << endl;
    }
    else{
      for(int j=-1;j<=W;j++){
        if(j==-1||j==W){
          cout << "#";
        }
        else{
          cout << S[i][j];
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split(" ")))
ans = 1
for i in range(1,n):
    tmp = 1
    for j in range(i):
        if h[j] <= h[i]:
            continue
        else:
            tmp = 0
            break;
    if tmp == 1:
        ans += 1
print(ans)


Measured memory_bytes: 2940
#include<stdio.h>

int gcd(int x, int y);

int main(){
  int x, y, i, d;
  scanf("%d%d",&x,&y);

  d=gcd(x,y);
  
  printf("%d\n",d);

  return 0;
}


int gcd(int x,int y)
{
  int a,r;
if (x < y){
    a=y;
    y=x;
    x=a;
  }
while (y > 0){
  r = x % y;
  x = y;
  y = r;
	  }
 return x;
}



Measured memory_bytes: 2104
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n;
 cin>>n;
 ll k,t1,t2,tmp,ans=1e8;
 rep(i,1,n){
  t1=0;t2=0;
  tmp=i;
  while(tmp>0){
   t1+=tmp%10;
   tmp/=10;
  }
  tmp=n-i;
  while(tmp>0){
   t2+=tmp%10;
   tmp/=10;
  }
  ans=min(ans,t1+t2);
 }
 pr(ans);
return 0;}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = {1, 0, -1, 0}, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};

vector<long long>h;

int main() {
	long long n,k,ans=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        long long num;
        cin>>num;
        h.push_back(num);
    }
    sort(all(h));
    reverse(all(h));
    for(int i=k;i<n;i++){
        ans+=h[i];
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>

int main(void) {

  double x1,y1,x2,y2,x3,y3,xp,yp;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF) {

    double s,t;

    s=(double)((y3-y1)*(xp-x1)-(x3-x1)*(yp-y1))/(double)((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));

    t=(double)((x2-x1)*(yp-y1)-(xp-x1)*(y2-y1))/(double)((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));

    if(s>0 && t>0 && s+t<1) {
      //printf("%lf %lf",s,t);
      printf("YES\n");

    } else {
      //printf("%lf %lf",s,t);      
      printf("NO\n");

    }
       
  }
   
  return 0;

}

Measured memory_bytes: 0
from operator import itemgetter

N = int(input())
L = [[int(a) for a in input().split()] for _ in range(N)]

for i in range(N):
    L[i].append(L[i][0]+L[i][1])
    
L.sort(reverse=True, key=itemgetter(2))
a = 0
b = 0
for i in range(N):
    if i%2 == 0:
        a += L[i][0]
    else:
        b += L[i][1]
        
print(a-b)

Measured memory_bytes: 65268
N, M = map(int, input().split())
edges = [[] for _ in range(N + 1)]

from collections import deque

for i in range(M):
  a, b = map(int, input().split())
  edges[a].append(b)
  edges[b].append(a)

queue = deque()
queue.append(1)
colors = ["white"] * (N + 1)

u = queue.popleft()
colors[u] = "black"

for edge in edges[u]:
  if colors[edge] != "black":
    queue.append(edge)

for i in range(len(queue)):
  u = queue.popleft()
  colors[u] = "black"
  for edge in edges[u]:
    if colors[edge] != "black":
      queue.append(edge)

for q in queue:
  if q == N:
    print("POSSIBLE")
    exit()

print("IMPOSSIBLE")


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int b[100004];
    int n;cin>>n;
    rep(i,n-1)cin>>b[i];
    ll tot=b[0]+b[n-2];
    for(int i=1;i<n-1;i++)tot+=min(b[i],b[i-1]);
    cout<<tot<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define NMAX 15005
#define VMAX 200000
#define inf 2000000005

using namespace std;
ifstream f("date.in");
ofstream g("date.out");
long long int k,sum;
int gcd(int a,int b)
{
    int r;
    while(b)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int main()
{
    cin>>k;
for(int i=1;i<=k;i++)
{
    for(int j=1;j<=k;j++)
    {
        for(int d=1;d<=k;d++)
        {
            int p=gcd(i,j);
            sum=sum+gcd(p,d);
        }
    }
}
cout<<sum;


}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main()
{
    ll n,ans = 0,min = 20000000;
    cin >> n;
    vll a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i] <= min){
            ans++;
            min = a[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main(){
  long long n, c, s = 0, k = 0, a = 0;
  cin >> n >> c;
  s = n % c;
  k = -1 * (s - c);
  if(s > k){
    cout << k << "\n";
    return 0;
  }
  cout << s << "\n";
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		partB100();
	}
	
	public static void partB100() {
		Scanner scB = new Scanner(System.in);
		int D = scB.nextInt();
		int N = scB.nextInt();

		if(D == 0) {
			if(N == 100) {
				System.out.println(101);
			}else {
				System.out.println(N);
			}
		}else if(D == 1) {
			if(N == 100) {
				System.out.println(10100);
			}else {
				System.out.println(N * 100);
			}
		}else if(D == 2) {
			if(N == 100) {
				System.out.println(1010000);
			}else {
				System.out.println(N * 10000);
			}
		}
	}
}

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

int main() {
    int n;
    cin >> n;
    ll v[n], c[n];
    for(int i = 0; i < n; i++)
    cin >> v[i];
    for(int i = 0; i < n; i++)
    cin >> c[i];
    ll s = 0;
    for(int i = 0; i < n; i++){
        if(v[i] - c[i] > 0)
        s += v[i] - c[i];
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def bfs(N, v0, edge):

    search = [-1] * N
    search[v0] = 1
    q = deque()
    q.append(v0)

    while q:
        v = q.popleft()
        now_color = search[v]
        for nv in edge[v]:
            if search[nv] == -1:
                q.append(nv)
                search[nv] = now_color + 1
            elif search[nv] == now_color:
                return None

    return max(search)


def main():

    N = in_n()

    edge = [[] for _ in range(N)]
    for i in range(N):
        edge[i] = [j for j, n in enumerate(readline()) if n == ord('1')]

    ans = -1
    for i in range(N):
        color = bfs(N, i, edge)
        if color:
            ans = max(ans, color)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9768
S = []
for i in range(3):
    S.append(input())
#print(S)#
name = ['A', 'B', 'C']
inx = {'a':0, 'b':1, 'c':2}
n = 0 #A

while S[n]!='':
    #print(n, S[n])#
    next = S[n][0]
    S[n] = S[n][1:]
    n = inx[next]
    
print(name[n])

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

int main() {
    int n;
    cin >> n;
    int d[n];
    rep(i,n) cin >> d[i];
    sort(d, d+n);

    int ans = d[n/2] - d[n/2 -1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = []
ans = 0
for i in range(n):
    tmp_sum = 0
    tmp = list(map(int, input().split()))
    for j in range(m):
        tmp_sum += tmp[j] * b[j]
    if tmp_sum + c > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++) cin>>a[i];

  map<ll,int> mp;
  for(int i=0;i<n;i++){
    auto itr = mp.find(a[i]);
    if(itr == mp.end()){
      mp.insert(make_pair(a[i],1));
    }else{
      itr->second++;
    }
  }

  int ans=0;
  for(auto itr:mp){
    if(itr.first==1){
      ans+=itr.second-1;
    }else{
      ans+=itr.second % itr.first;
    }
  }

  cout << ans << endl;
}


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

int d[305][305],a[305][305];

int main()
{
	int n,m,l;
	scanf("%d %d %d",&n,&m,&l);
	for(int i=1; i<=n; i++)
	for(int j=1; j<=n; j++)
	if(i!=j)
			{
				d[i][j]=0x3f3f3f3f;
				a[i][j]=0x3f3f3f3f;
			}
	for(int i=0; i<m; i++)
	{
		int x,y,z;
		scanf("%d %d %d",&x,&y,&z);
		d[x][y]=z,d[y][x]=z;
	}
	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			if(i!=j&&d[i][j]<=l)
				a[i][j]=1;
	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
	int q;
	scanf("%d",&q);
	while(q--)
	{
		int s,t;
		scanf("%d %d",&s,&t);
		printf("%d\n",a[s][t]==0x3f3f3f3f?-1:a[s][t]-1);
	}
}


Measured memory_bytes: 1280
s = int(input())

def prime(R):
    s = 0
    prime_list = []
    while s==0:
        for i in range(2,R+1):
            if R%i==0:
                R=R//i
                if R==1:
                    s=1
                prime_list.append(i)
                break
    return prime_list
prime_list = []
for i in range(2,s+1):
    for p in prime(i):
        prime_list.append(p)
uniq = list(set(prime_list))
prime_counts = []
for u in uniq:
    if prime_list.count(u) != 1:
        prime_counts.append(prime_list.count(u))
c74 = 0
c24 = 0
c14 = 0
c4 = 0
for pc in prime_counts:
    if pc >= 74:
        c74 += 1
        c24 += 1
        c14 += 1
        c4 += 1
    elif pc >= 24:
        c24 += 1
        c14 += 1
        c4 += 1
    elif pc >= 14:
        c14 += 1
        c4 += 1
    elif pc >= 4:
        c4 += 1

ans = 0
ans += c74
ans += c24*(len(prime_counts)-1)
ans += c14*(c4-1)
ans += c4*(c4-1)*(len(prime_counts)-2)//2
print(ans)
            

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  cout << string(b - '0', a) << endl;
  return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0280
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                string s = RSt();

                int fieldBill = 0;
                int[] players = new int[n];

                for (int i = 0; i < s.Length; i++)
                {
                    int idx = i % n;
                    players[idx]++;

                    switch (s[i])
                    {
                        case 'S':
                            fieldBill += players[idx];
                            players[idx] = 0;
                            break;
                        case 'L':
                            players[idx] += fieldBill;
                            fieldBill = 0;
                            break;
                    }
                }
                Console.WriteLine("{0} {1}", WAr(players.OrderBy(x => x)), fieldBill);
            }

        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 18576
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <cstdio> 
#include <iostream> 
#include <cmath> 
#include <string> 
#include <list> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <utility> 
#include <set> 
#include <map> 
#include <complex> 
#include <queue> 
#include <stack> 
#include <cstdlib> 
#include <ctime> 
#include <cstring> 
#include <string.h> 
#include <unordered_set>
#include <unordered_map>
#include <cassert>

using namespace std; 

typedef unsigned int uint; 
typedef long long int64; 
typedef unsigned long long uint64; 
typedef unsigned short ushort; 
typedef unsigned char uchar; 
typedef pair<int,int> ipair; 
typedef vector<int> VI; 
typedef vector<string> VS; 
typedef vector<double> VD; 
#define SIZE(A) ((int)(A.size()))
#define LENGTH(A) ((int)(A.length()))
#define MP(A,B) make_pair(A,B)
const double pi=acos(-1.0); 
const double eps=1e-11; 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(a) (a).begin(),(a).end()

template<class T> T sqr(const T &x) { return x*x; } 
template<class T> T lowbit(const T &x) { return (x^(x-1))&x; } 
template<class T> int countbit(const T &n) { return (n==0)?0:(1+countbit(n&(n-1))); } 
template<class T> void ckmin(T &a,const T &b) { if (b<a) a=b; } 
template<class T> void ckmax(T &a,const T &b) { if (b>a) a=b; } 

const int maxn=200000+16;

int64 total;
int n;
int64 a[maxn];
int64 sa[maxn];
int64 st[maxn];
map<int64,int> wa;
int64 f1[maxn];
int64 f2[maxn];

int64 solve1(int pos,int64 t)
{
	int at=upper_bound(st,st+n,t)-st-1;
	int64 w;
	if (pos%2==1)
		w=f2[at];
	else
		w=f1[at];
	if (at%2==1)
		w+=(t-st[at]);
	else
		w-=(t-st[at]);
	w=max(w,0LL);
	w=min(w,total);
	return w;
}
void simulate(int64 f[],int64 x)
{
	REP(i,n)
	{
		f[i]=x;
		if (i%2==1) x=min(total,x+a[i]);
		else x=max(0LL,x-a[i]);
	}
}
int64 solve2(int64 a,int64 t)
{
	int at=upper_bound(st,st+n,t)-st-1;
	a+=sa[at];
	if (at%2==1) a+=(t-st[at]);
	else a-=(t-st[at]);
	a=max(a,0LL);
	a=min(a,total);
	return a;
}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios_base::sync_with_stdio(false);
	cin>>total>>n;
	REP(i,n) cin>>a[i];
	for (int i=n-1;i>0;i--) a[i]-=a[i-1];
	a[n++]=1000000009;
	int64 s=0;
	int64 ps=0,pt=total;
	REP(i,n)
	{
		sa[i]=s;
		if (i%2==1) 
			s+=a[i];
		else
			s-=a[i];
		if (ps<=pt)
		{
			if (pt+s>=total)
			{
				int64 e=max(ps,total-s);
				wa[e]=i;
				pt=e-1;
			}
			else if (ps+s<=0)
			{
				wa[ps]=i;
				ps=min(pt,-s)+1;
			}
		}
	}
	simulate(f1,0);
	simulate(f2,total);
	st[0]=0;
	REP(i,n) st[i+1]=st[i]+a[i];
	int nq;
	cin>>nq;
	REP(step,nq)
	{
		int64 a,t;
		cin>>t>>a;
		ckmin(t,st[n]-1);
		auto it=wa.upper_bound(a);
		--it;
		int pos=it->second;
		int64 ret;
		if (t>=st[pos+1])
			ret=solve1(pos,t);
		else
			ret=solve2(a,t);
		printf("%d\n",(int)ret);
	}
	return 0;
}

Measured memory_bytes: 7424
#include <stdio.h>

int main(void)
{
    int a11, a12, a13, a21, a22, a23, a31, a32, a33;
    int n, i, j;
    int p[100];

    scanf("%d%d%d", &a11, &a12, &a13);
    scanf("%d%d%d", &a21, &a22, &a23);
    scanf("%d%d%d", &a31, &a32, &a33);

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
    }

    for (j = 0; j < n; j++)
    {
        if(a11 == p[j]){
            a11 = 0;
        }

        if(a12 == p[j]){
            a12 = 0;
        }

        if(a13 == p[j]){
            a13 = 0;
        }

        if(a21 == p[j]){
            a21 = 0;
        }

        if(a22 == p[j]){
            a22 = 0;
        }

        if(a23 == p[j]){
            a23 = 0;
        }

        if(a31 == p[j]){
            a31 = 0;
        }

        if(a32 == p[j]){
            a32 = 0;
        }

        if(a33 == p[j]){
            a33 = 0;
        }
    }

    if((a11==a12&&a12==a13&&a13==0) || (a21==a22&&a22==a23&&a23==0) || (a31==a32&&a32==a33&&a33==0) || (a11==a21&&a21==a31&&a31==0) || (a12==a22&&a22==a32&&a32==0) || (a13==a23&&a23==a33&&a33==0) || (a11==a22&&a22==a33&&a33==0) || (a13==a22&&a22==a31&&a31==0)){
        printf("Yes");
    }

    else{
        printf("No");
    }
}

Measured memory_bytes: 128
n = int(input())
infos = [[int(i) for i in input().split()] for t in range(n)]

def calculate(infos,n):
    dp=[[0]*3 for i in range(n)]
    dp[0] = infos[0][:]
    for i in range(1,n):
        a,b,c = dp[i-1]
        dp[i] = [infos[i][0]+max(b,c),infos[i][1]+max(a,c),infos[i][2]+max(a,b)]
    return max(dp[-1])

print(calculate(infos,n))


Measured memory_bytes: 44020
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
vi a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<a[k-1]<<endl;
}

Measured memory_bytes: 256
S = input()
if S.count("S") >= 1 and S.count("W") >= 1 and S.count("E") >= 1 and S.count("N") >= 1:
  print("Yes")
elif S.count("S") >= 1 and S.count("W") == 0 and S.count("E") == 0 and S.count("N") >= 1:
  print("Yes")
elif S.count("S") == 0 and S.count("W") >= 1 and S.count("E") >= 1 and S.count("N") == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;
int main()
{
    int n;
    cin >> n;
  //  bool ok = false;
    for (int i = 0; i < 30; i++) {
        for (int j = 0; j < 20; j++) {
            if (4 * i + 7 * j == n) {
               // ok = true;
                cout << "Yes" << endl;
                return 0;
                break;
            }
        }

        //if (ok)break;
    }
    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    vector<int> L(N);

    rep(i, N) cin >> L[i];

    sort(all(L));

    ll ans = 0;

    rep(i, N - 2) {
        repd(j, i + 1, N - 1) {
            auto position = lower_bound(all(L), (L[i] + L[j]));
            int index = distance(L.begin(), position);
            index--;
            ans += (index - j);
        }
    }

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

Measured memory_bytes: 256