akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int par[100001];
int length[100001];
void init(int n){
  for(int i=1;i<=n;i++){
    par[i]=i;
    length[i]=1;
  }
  return;
}
int root(int n){
  if(par[n]==n)return n;
  return root(par[n]);
}
void unit(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y)return;
  if(length[x]>length[y]){
    par[y]=x;
    length[x]++;
  }
  else{
    par[x]=y;
    length[y]++;
  }
  return;
}
int main(){
  int n,m;cin>>n>>m;
  int p[n];for(int i=0;i<n;i++)cin>>p[i];
  int x[m],y[m];for(int i=0;i<m;i++)cin>>x[i]>>y[i];
  init(n);
  for(int i=0;i<m;i++){
    unit(x[i],y[i]);
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(root(p[i])==root(i+1))sum++;
  }
  cout<<sum<<endl;
}
  

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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 H,W;

bool input() {
  cin >>H >>W;
  if (H == 0 && W == 0) return false;
  return true;
}

void solve() {
  rep(i, H){
    rep(j, W){
      cout <<"#";
    }
    cout <<endl;
  }
  cout <<endl;
}

int main() {
  while (input()){
    solve();
  }
}



Measured memory_bytes: 3120
#include "bits/stdc++.h"
#include <cmath>

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) cin >> F[i][j];
    }
    vector<vector<ll>> P(N, vector<ll>(11));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) cin >> P[i][j];
    }
    ll max_sum = -10000000000;
    for (int bit = 1; bit < (1 << 10); bit++) {
        ll sum = 0;
        for (int i = 0; i < N; i++) {
            int cnt = 0;
            for (int j = 0; j < 10; j++) {
                if (bit & (1 << j)) {
                    if (F[i][j]) cnt++;
                }
            }
            sum += P[i][cnt];
        }
        max_sum = max(sum, max_sum);
    }
    cout << max_sum << endl;
}

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

int main()
{
	char s[5];
	while(cin>>s){
	//	int len = strlen(s);
		int ans=700;
		for(int i=0;i<3;++i){
			if(s[i]=='o'){
				ans+=100;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
main = do
    xs <- getLine :: IO String
    let ys = reverse xs
    print $ min  (solve 0 (head xs) (tail xs)) (solve 0 (head ys) (tail ys))

solve :: Int -> Char -> String -> Int
solve n c [] =  n
solve n c (x:xs) = if c == x then solve (n+1) ops xs else solve n x xs
    where
        ops = if c == '0' then '1' else '0'

Measured memory_bytes: 8572
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
struct Side
{
	int a, b, c, d;
	Side(){}
	Side(int _a, int _b, int _c, int _d)
	{
		a = _a;
		b = _b;
		c = _c;
		d = _d;
	}
	pair<pair<int, int>, pair<int, int> > get() const
	{
		return make_pair(make_pair(a, b), make_pair(c, d));
	}
};
Side shift(Side s)
{
	return Side(s.b, s.c, s.d, s.a);
}
Side makeMin(Side s)
{
	Side res = s;
	for (int i = 0; i < 4; i++)
	{
		s = shift(s);
		if (s.get() < res.get())
                {
                      res = s;
                }
	}
	return res;
}
bool operator<(const Side x, const Side y)
{
	return x.get() < y.get();
}
bool operator==(const Side x, const Side y)
{
	return x.get() == y.get();
}
const int MAXN = 407;
Side s[MAXN];
map<Side, int> have;
int cnt(Side s)
{
	Side ss = s;
	int res = 0;
	for (int i = 0; i < 4; i++)
	{
		if (ss == s) res++;
		ss = shift(ss);
	}
	return res;
}
Side mirror(Side s)
{
	return Side(s.d, s.c, s.b, s.a);
}
vector<Side> dels;
int go(Side s)
{
	s = mirror(s);
	s = makeMin(s);
	int res = have[s];
	dels.push_back(s);
	have[s]--;
	return res * cnt(s);
}
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d %d %d", &s[i].a, &s[i].b, &s[i].c, &s[i].d);
		s[i] = makeMin(s[i]);
	}
	ll res = 0;
	for (int i = n; i >= 1; i--)
	{
		Side down = s[i];
		for (int j = i + 1; j <= n; j++)
		{
			Side up = mirror(s[j]);
			for (int rot = 0; rot < 4; rot++)
			{
				//map<Side, int> tmp = have;
				dels.push_back(s[j]);
				have[s[j]]--;
				ll curRes = 1;
				curRes *= go(Side(down.a, down.b, up.b, up.a));
				curRes *= go(Side(down.b, down.c, up.c, up.b));
				curRes *= go(Side(down.c, down.d, up.d, up.c));
				curRes *= go(Side(down.d, down.a, up.a, up.d));
				up = shift(up);
				//have = tmp;
				res += curRes;
				for (int k = 0; k < (int)dels.size(); k++)
				{
					have[dels[k]]++;
				}
				dels.clear();
			}
		}
		have[s[i]]++;
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 80128
from sys import stdin


def main():
    k = next_int()
    s = next_int()
    ans = 0
    for x in range(k + 1):
        for y in range(k + 1):
            z = s - x - y
            if 0 <= z <= k:
                ans += 1
    print(ans)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int x,y,z; cin >> x >> y >> z;
    int ans = 0;
    x-=z;
    while (x >= y+z) {
        ans++;
        x -= y+z;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int mod=1000000009;
int deg[110000];
pair<int,int>edge[210000];
int c[110000];
int d[110000];
int UF[110000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;
	UF[a]+=UF[b];
	UF[b]=a;
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		edge[i]=make_pair(p,q);
		deg[p]++;deg[q]++;
	}
	long long ret=1;
	for(int i=0;i<b;i++){
		if(deg[edge[i].first]>deg[edge[i].second])c[edge[i].first]=1;
		if(deg[edge[i].first]<deg[edge[i].second])c[edge[i].second]=1;
		if(deg[edge[i].first]==deg[edge[i].second])d[min(edge[i].first,edge[i].second)]=1;
	}
	for(int i=0;i<a;i++)if(c[i])d[i]=1;
	int num=0;
	for(int i=0;i<a;i++)if(!d[i])num++;
	for(int i=0;i<a;i++)UF[i]=-1;
	for(int i=0;i<b;i++){
		if(!c[edge[i].first]&&!c[edge[i].second])UNION(edge[i].first,edge[i].second);
	}
	for(int i=0;i<a;i++){
		if(!c[i]&&UF[i]<0)ret=ret*(-UF[i])%mod;
	}
	printf("%d\n%lld\n",num,ret);
}

Measured memory_bytes: 4232
def solution(r):
    #todo: check if r is valid
    if r < 1200:
        return 'ABC'
    elif r < 2800:
        return 'ARC'
    else:
        return 'AGC'

def main():
    r = int(raw_input().strip())
    print solution(r)

if __name__ == '__main__':
    main()

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

typedef long long ll;

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

    int x,y,ans=0;
    cin >> x >> y;
    int money[210];
    money[0] = 300000; money[1] = 200000; money[2] = 100000;
    for(int i=3;i<210;i++) money[i] = 0;
    if(x==1 && y==1) ans = 1000000;
    else{
        ans += money[x-1] + money[y-1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int T = Integer.parseInt(sc.next());

		int min= Integer.MAX_VALUE;
		for(int i=0; i<N; i++){
			int a=Integer.parseInt(sc.next());
			int b=Integer.parseInt(sc.next());
			if(b <= T){
				min = Math.min(min, a);
			}
		}
		if(min==Integer.MAX_VALUE){
			System.out.println("TLE");
		} else {
			System.out.println(min);
		}
	}
}


Measured memory_bytes: 26752
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int a,b;

int main(){
	while (~scanf("%d%d", &a,&b)){
		if (a == b){ printf("Draw\n"); }
		else{
			if (a == 1){
				printf("Alice\n");
			}
			else if (b == 1){ printf("Bob\n"); }
			else{
				if (a > b){ printf("Alice\n"); }
				else{ printf("Bob\n"); }
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout << a[0] << b[1] << c[2] << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

#define MOD 2019

int main(){
  long long int L = 0,R = 0;
  cin >> L >> R;
  if(L + MOD <= R){
    cout << 0 << endl;
  }else{
  L = L % MOD;
  R = R % MOD;
  int answer = 100000000;
  for(int i = L;i < R;i++){
    for(int j = i + 1;j <= R;j++){
      answer = min(answer,((i*j)%2019));
    }
  }
  cout << answer << endl;
}
}


Measured memory_bytes: 3612
//mangesh2102000

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000007

void print_mat(int m[][55],int n)
{
	cout << "START \n";

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout << m[i][j] << " ";
		}
		cout << endl;
	}

	cout << " END \n";
}

void matrix_multiply(int A[][55],int B[][55],int C[][55],int n)
{
	//print_mat(A,n);
	//print_mat(B,n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int l=1;l<=n;l++)
			{
				C[i][j] += (A[i][l]*B[l][j]);
				C[i][j] %= mod; 
			}
		}
	}
	//print_mat(C,n);
}

void assign_mat(int a[][55],int b[][55],int n)
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			a[i][j] = b[i][j];
		}
	}
}

void matrix_expo(int a[][55],int b[][55],int n,int k)
{

	while(k>0)
	{
		if(k%2 == 1)
		{
			int tmp[55][55];
			memset(tmp,0,sizeof(tmp));
			matrix_multiply(b,a,tmp,n);
			assign_mat(b,tmp,n);
		}
		int tmp[55][55];
		memset(tmp,0,sizeof(tmp));
		matrix_multiply(a,a,tmp,n);
		assign_mat(a,tmp,n);
		k/=2;
	}
}

void solve(int t)
{
	int n,k;
	int a[55][55];
	int b[55][55];
	cin >> n >> k;

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin >> a[i][j];
			if(i==j) b[i][j]=1;
			else b[i][j]=0;
		}
	}

	int ans = 0;

	matrix_expo(a,b,n,k);

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			ans += b[i][j];
			ans %= mod;
		}
	}

	cout << ans;
    //cout << "Case #" << t << ": ";    
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 512
# 部分木の解を 1 次元で持つように変更

def rerooting(n, edges, identity, merge, add_node):
    # 全方位木 dp
    # 参考1: https://qiita.com/keymoon/items/2a52f1b0fb7ef67fb89e
    # 参考2: https://atcoder.jp/contests/abc160/submissions/15255726
    from functools import reduce
    G = [[] for _ in range(n)]
    for a, b in edges:
        G[a].append(b)
        G[b].append(a)
    # step 1
    parents = [0] * n
    order = []  # 行きがけ順
    stack = [0]
    parents[0] = -1
    while stack:
        v = stack.pop()
        p = parents[v]
        order.append(v)
        for u in G[v]:
            if p != u:
                stack.append(u)
                parents[u] = v
    # 下から登る
    dp_down = [0]*n  # 自身とその下
    for v in order[:0:-1]:
        p = parents[v]
        result = identity
        for u in G[v]:
            if p != u:
                result = merge(result, dp_down[u])
        dp_down[v] = add_node(result, v)
    # step 2
    # 上から降りる
    dp_up = [identity] * n  # 親とその先
    for v in order:
        Gv = G[v]
        if len(Gv) == 1 and v != 0:
            continue
        p = parents[v]
        cum = identity
        right = [identity]
        for u in Gv[::-1]:
            if u != p:
                cum = merge(dp_down[u], cum)
                right.append(cum)
        cum = dp_up[v]
        idx_right = -2
        for u in Gv:
            if u != p:
                dp_up[u] = add_node(merge(cum, right[idx_right]), v)
                idx_right -= 1
                cum = merge(cum, dp_down[u])
    results = [add_node(
        merge(
            reduce(merge, (dp_down[u] for u in Gv if u != parents[v]), identity),
            dp_up[v]
        ), v
    ) for v, Gv in enumerate(G)]
    return results

class Combination:
    def __init__(self, n_max, mod=10**9+7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod-2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

def main():
    N = int(input())
    AB = [list(map(lambda x: int(x)-1, input().split())) for _ in range(N-1)]
    mod = 10**9 + 7
    comb = Combination(202020)
    identity = (1, 0)
    fac, facinv = comb.fac, comb.facinv
    def merge(a, b):
        a0, a1 = a
        b0, b1 = b
        return a0*b0*fac[a1+b1]*facinv[a1]*facinv[b1]%mod, a1+b1
    def add_node(a, idx):
        a0, a1 = a
        return a0, a1+1
    Ans = rerooting(N, AB, identity, merge, add_node)
    print("\n".join(str(ans) for ans, _ in Ans))

main()


Measured memory_bytes: 183640
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP=pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

signed main() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 1) cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 256
S = input()
N = len(S)
if  N ==1:
    print(0)
    exit()
a = S[0:N:2].count("0")
b = S[1:N:2].count("1")
c = S[0:N:2].count("1")
d = S[1:N:2].count("0")

print(min(a+b,c+d))

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

constexpr int INF = 3000;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, aij, mincost, minu, sum=0;
    std::cin >> n;
    std::vector<std::vector<int>> a(n);
    std::vector<int> d(n), p(n), color(n); // white:0, gray:1, black:2
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            std::cin >> aij;
            a[i].push_back(aij);
        }
        d[i] = INF;
    }
    d[0]=0;
    p[0]=-1;
    while (true) {
        mincost = INF;
        for (int i=0; i<n; i++) {
            if (color[i] < 2 and d[i] < mincost) {
                mincost = d[i];
                minu = i;
            }
        }
        if (mincost == INF) {
            break;
        }
        color[minu] = 2;
        for (int v=0; v<n; v++) {
            if (color[v] < 2 and a[minu][v] >= 0 and d[v] > a[minu][v]) {
                d[v] = a[minu][v];
                p[v] = minu;
                color[v] = 1;
            }
        }
    }

    for (int i=0; i<n; i++) {
        sum += d[i];
    }
    std::cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 3280
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

string S;
int ctr[3] = {};
int ex[3] = {};
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> S;
  int N = S.length();
  for (char c:S) if (c == 'a') ctr[0]++; else if (c == 'b') ctr[1]++; else ctr[2]++;
  sort(ctr, ctr+3);
  rep(i, 3) ex[i] = N/3;
  rep(i, N%3) ex[i]++;
  sort(ex, ex+3);
  rep(i, 3) if (ctr[i] != ex[i]) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n, 0);
    map<ll,ll> M;
    for (ll i = 0; i < n; ++i) {
        cin >> A[i];
        auto a = A[i];
        if (M.find(a) == M.end()) {
            M.insert(make_pair(a, 1));
        } else {
            M[a] = M[a] + 1;
        }
    }
    ll sum = 0;
    for (auto iter = M.begin(); iter != M.end(); ++iter) {
        if (iter->second > 1) {
            auto p = iter->second;
            sum += (p * (p - 1)) / 2;
        }
    }
    for (ll i = 0; i < n; ++i) {
        auto a = A[i];
        auto res = sum;
        auto p = M[a];
        if (p > 1) {
            res = res - ((p * (p-1)) /2) + (((p-1) * (p-2)) / 2);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define int long long 
using namespace std;

int dp[3001][3001];

int solve(int a[],int i, int j){
	if (i==j){
		dp[i][j] = a[i];
		return a[i];
	}
	if  (dp[i][j]!=1e15){
		return dp[i][j];
	}
	dp[i][j] = max(a[i]-solve(a,i+1,j),a[j]-solve(a,i,j-1));
	return dp[i][j];
}

signed main(){

	//freopen("input.txt","r",stdin);
	int n;
	cin >> n;
	int a[10000];
	for (int i=0; i<3001;  i++){
		for (int j=0; j<3001;  j++){
			dp[i][j] = 1e15;
		}
	}
	for (int i=0; i<n; i++){
		cin >> a[i];
	}
	cout << solve(a,0,n-1);
 	cout << endl;
}

Measured memory_bytes: 70784
n = int(input())
a = dict()
for _ in range(n):
    s = input()
    if s in a:
        a[s] += 1
    else:
        a[s] = 1

M = max(a.values())
ans = []
for s in a:
    if a[s] == M:
        ans.append(s)
ans.sort()
for s in ans:
    print(s)


Measured memory_bytes: 32096
#include <bits/stdc++.h>
using namespace std;
static const int INFH = (1<<30)-1;
static const int INFL = -INFH;
 
vector<pair<char, int>> runLength(string x)
{
	char now = x[0];
	int count = 1;
	vector<pair<char, int>> ret;
	for (int i = 1; i < x.size(); ++i)
	{
		if(x[i] != now)
		{
			ret.push_back(make_pair(now, count));
			now = x[i];
			count = 1;
		}
		else
		{
			++count;
		}
	}
	ret.push_back(make_pair(now, count));
	return ret;
}
 
long long int wa(int x)
{
	long long int ret = 0;
	for (int i = 1; i <= x; ++i)
	{
		ret += i;
	}
	return ret;
}
 
int main()
{
	string in;
	cin >> in;
	vector<pair<char, int>> r = runLength(in);
	long long int ans = 0;
	if(r.size() == 1)
	{
		cout << wa(r[0].second) << endl;
		return 0;
	}
	for (int i = 0; i < r.size(); ++i)
	{
		if(i == 0 && r[i].first == '>')
		{
			ans += wa(r[i].second);
		}
		else if (i == r.size() - 1 && r[i].first == '<')
		{
			ans += wa(r[i].second);
		}
		else
		{
			ans += wa(max(r[i].second, r[i + 1].second)) + wa(min(r[i].second, r[i + 1].second)-1);
			++i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>

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

  int s = 0;

  for (int n = N; n > 0; n /= 10) {
    s += n % 10;
  }

  std::cout << (N % s == 0 ? "Yes" : "No") << std::endl;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#define ll long long int
#define MOD 1000000007LL
using namespace std; 
int main() {
    int n;
    cin>>n;
    ll a[114514]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,greater<int>());
    int c=1;
    ll ans=0;
    int f=0;
    for(int i=1;i<=n;i++){
        if(a[i]==a[i-1]){
            c++;
        }else{
            if(c>=4){
                if(ans==0){
                    ans=a[i-1]*a[i-1];
                    f=1;
                    break;
                }else{
                    ans*=a[i-1];
                    f=1;
                    break;
                }
            }else if(c>=2){
                if(ans>0){
                    ans*=a[i-1];
                    f=1;
                    break;
                }else{
                    ans=a[i-1];
                    c=1;
                }
               
            }else{
                c=1;
            }
        }
    }
    if(f==0){
        cout<<0<<endl;
    }else{
       cout<<ans<<endl;
    }
}

Measured memory_bytes: 1152
#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() {
   int a,b;cin>>a>>b;
   int ans=max(a+b,a*b);
   ans=max(ans,a-b);
   cout<<ans<<endl;
   }

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

int main()
{
    int n;
    cin >> n;
    map<string, int> a;
    rep(i,n) {
        string s;
        cin >> s;
        a[s]++;
    }
    int maxv = 0;
    for (const auto& x : a) {
        maxv = max(maxv, x.second);
    }
    for (auto i = a.begin(); i != a.end(); i++) {
        if (i->second == maxv)
            cout << i->first << endl;
    }
    return 0;
}


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

int main() {
	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	vector<int> tmp(N);
	for (int i = 1; i < N; ++i) {
		if (S[i - 1] == 'A' && S[i] == 'C') tmp[i] = tmp[i - 1] + 1;
		else tmp[i] = tmp[i - 1];
	}
	for (int i = 0; i < Q; ++i) {
		int l, r;
		cin >> l >> r;
		cout << tmp[r - 1] - tmp[l - 1] << endl;
	}
}

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

bool disliked[10]{};

bool good(int n) {
	while (n) {
		if (disliked[n % 10])
			return false;
		
		n /= 10;
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, k, tmp; cin >> n >> k;
	for (int i = 0; i < k; ++i) {
		cin >> tmp;
		disliked[tmp] = 1;
	}
	
	while (!good(n)) ++n;
	
	cout << n;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int W=sc.nextInt();
	int a=sc.nextInt();
	int b=sc.nextInt();
	if((a<=b&&b<=a+W)||(b<=a&&a<b+W))System.out.println("0");
	else if(b>=a+W)System.out.println(b-a-W);
	else System.out.println(a-b-W);
}}


Measured memory_bytes: 23892
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,k= map(int, sys.stdin.readline().split(' '))
    ans=0
    for i in range(k,n+2):
        x=(i*(i-1))//2
        y=n*i
        y-=(i*(i-1))//2
        ans+=(y-x+1)
        ans%=mod

        #print(x,y)
    print(ans)
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
int n;
double arr[3001], rra[3001];
double dp[3001][3001];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> arr[i];
		rra[i]=1-arr[i];
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			if(j==0){
				dp[i][j]=rra[i]*dp[i-1][j];
			}
			else{
				dp[i][j]=rra[i]*dp[i-1][j]+arr[i]*dp[i-1][j-1];
			}
		}
	}
	double total=0;
	for(int i=(n/2)+1;i<=n;i++){
		total+=dp[n][i];
	}
	cout << fixed << setprecision(10) << total << endl; 
}

Measured memory_bytes: 68992
#include <iostream>
using namespace std;
int main(void) {
  int n;
  float x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> n;
  while (n--) {
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
    if ((y1 - y2) / (x1 - x2) == (y3 - y4) / (x3 - x4)) {
      cout << "YES";
    } else {
      cout << "NO";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,a[111111],x,y;
int main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	if(a[n-1]-a[0]>=2){
		puts("No");
		return 0;
	}
	if(a[n-1]-a[0]==0){
		if(a[0]==n-1||a[0]*2<=n)puts("Yes");
		else puts("No");
	}
	else{
		rep(i,n){
			if(a[i]==a[n-1])y++;
			else x++;
		}
		if(x<a[n-1]&&2*(a[n-1]-x)<=y)puts("Yes");
		else puts("No");
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi					3.14159265359
ll INF=1e18+10;
ll MOD=1000000007;

ll expo(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
int main()
{
    map<ll,ll> m;
    rep(i,1,50002)
    {
        int j=i*1.08;
        m[j]=i;
    }
    int nn;cin>>nn;
    if(m[nn]==0)
        cout<<":(";
    else
        cout<<m[nn];
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int a[n],sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	cin>>n;
	while(n--){
		int p,q;
		cin>>p>>q;
		p--;
		int ans=sum-a[p]+q;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int find(int x,vector<int>&root){
    if(root[x]==x)return x;
    else return find(root[x],root);
}
int main(){
    int n,m;
    cin>>n>>m;
    int p[n];
    vector<int>root(n);
    vector<int>rank(n,0);
    for(int i=0;i<n;i++){
        cin>>p[i];
        p[i]--;
        root[i]=i;
    }
    int x[m],y[m];
    for(int i=0;i<m;i++){
        cin>>x[i]>>y[i];
        int X=find(x[i]-1,root),Y=find(y[i]-1,root);
        if(X==Y)continue;
        if(rank[X]<rank[Y])root[X]=Y;
        else{
            root[Y]=X;
            if(rank[X]==rank[Y])rank[X]++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)if(find(i,root)==find(p[i],root))ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,m;
ll a[110000];
ll b[110000];
map<ll,ll> mp;

int main(){
  cin>>n>>m;
  rep(i,n){
    cin>>a[i];
    if(i) b[i]+=b[i-1];
    b[i]+=a[i];
  }

  rep(i,n){
    mp[b[i]%m]++;
  }

  ll ans=0;
  for(auto m:mp){
//    cout<<m.F<<' '<<m.S<<endl;
    ans+= m.S*(m.S-1)/2;
  }

  cout<<ans+mp[0]<<endl;
}


Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<climits>
 
using namespace std;
 
const int INF=(1LL<<31)-1;
int N,K;
//const int sqrtN=512;
int sqrtN;
vector<int> data;
vector<int> bucketmin;
vector<int> lazyflag;
vector<int> lazyupdate;
 
void init(){
    K=(N+sqrtN-1)/sqrtN;
    data.assign(K*sqrtN,INF);
    bucketmin.assign(K,INF);
    lazyflag.assign(K,false);
    lazyupdate.assign(K,0);
}
 
void eval(int k){
    if(lazyflag[k]){
        lazyflag[k]=false;
        for(int i=k*sqrtN;i<(k+1)*sqrtN;i++){
            data[i]=lazyupdate[k];
        }
    }
}
 
void update(int s,int t, int x){
    for(int k=0;k<K;k++){
        int l=k*sqrtN;
        int r=(k+1)*sqrtN;
        if(r<=s || t<=l) continue;
        if(s<=l && r<=t){
            bucketmin[k]=x;
            lazyflag[k]=true;
            lazyupdate[k]=x;
        }
        else{
            eval(k);
            for(int i=max(s,l);i<min(t,r);i++){
                data[i]=x;
            }
            int &minval=bucketmin[k]=INF;
            for(int i=l;i<r;i++){
                minval=min(minval,data[i]);
            }
        }
    }
}
 
void find_min(int s,int t){
    int minval=INF;
    for(int k=0;k<K;k++){
        int l=k*sqrtN;
        int r=(k+1)*sqrtN;
        if(r<=s || t<=l) continue;
        if(s<=l && r<=t){
            minval=min(minval,bucketmin[k]);
        }
        else{
            eval(k);
            for(int i=max(s,l);i<min(t,r);i++){
                minval=min(minval,data[i]);
            }
        }
    }
    printf("%d\n",minval);
}
 
int main(){
    int q,com;
    int s,t,x;
    scanf("%d %d",&N,&q);
    sqrtN = (int)sqrt(N);
    //printf("sqrt(N)=%lld\n",sqrtN);
    init();
    for(int i=0;i<q;i++){
        scanf("%d",&com);
        if(com==0){
            scanf("%d %d %d",&s,&t,&x);
            update(s,t+1,x);//[s,t)
        }
        else{
            scanf("%d %d",&s,&t);
            find_min(s,t+1);
        }
    }
}


Measured memory_bytes: 3384
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない




int main() {

	vector<ll> u, m, b;
	int n, k;
	cin >> n;

	rep(i, 0, n) {
		cin >> k; u.push_back(k);
	}

	rep(i, 0, n) {
		cin >> k; m.push_back(k);
	}

	rep(i, 0, n) {
		cin >> k; b.push_back(k);
	}

	sort(u.begin(), u.end());
	sort(b.begin(), b.end());

	ull ans = 0;

	rep(i, 0, n) {
		ll ud = lower_bound(u.begin(), u.end(), m[i]) - u.begin();
		ll bd = b.end() - upper_bound(b.begin(), b.end(), m[i]);
		ans += ud * bd;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3316
import java.util.Scanner;
class Main {
	int a,b,i;
	String op;
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		op = sc.next();
		b = sc.nextInt();
		while(!op.equals("?")){
			if(op.equals("+")){
				i = a + b;
				System.out.println(i);
			}else if(op.equals("-")){
				i = a - b;
				System.out.println(i);
			}else if(op.equals("*")){
				i = a * b;
				System.out.println(i);
			}else if(op.equals("/")){
				i = a / b;
				System.out.println(i);
			}
			a = sc.nextInt();
			op = sc.next();
			b = sc.nextInt();
		}
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
}

Measured memory_bytes: 18036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int w = A / K;
  if(A % K != 0) {
    if(A <= (w + 1) * K && (w + 1) * K <= B) {
      cout << "OK" << endl;
    }
    else {
      cout << "NG" << endl;
    }
  }
  else {
    cout << "OK" << endl;
  }
}

Measured memory_bytes: 3672
n = gets.to_i
inputs = gets.chomp.split(" ").map(&:to_i).sort!
if n == 1 and inputs[0] == 0
	puts 1
	exit
end

if n == 2 and (inputs[0] !=1 or inputs[1] !=1)
	puts 0
	exit
end

if n%2 == 1 and inputs[0] != 0
	puts 0
	exit
end

(n % 2).step(n-1,2) { |i|
	# print "i=", i+1, "\n"
	# p inputs[i+1]
	if inputs[i] != inputs[i+1] or inputs[i] != i+1
		puts 0
		exit
	end
}

puts 2**(n/2) % (10**9+7)

Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

const int N = int(1e5) + 7;

typedef pair<int, int> pii;
struct TVal {
    int x, y, z;
    bool operator<(const TVal& o)const& {
        if(x - y != o.x - o.y) return x - y > o.x - o.y;
        return x < o.x;
    }
} a[N];
set<pii, greater<pii>> sy;
set<pii> sx;
int n, x, y, z, choose[N];
ll Sx = 0, Sy = 0, S = 0, _S = 0;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> x >> y >> z; n = x + y + z;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i].x >> a[i].y >> a[i].z;
        a[i].x -= a[i].z;
        a[i].y -= a[i].z;
        _S += a[i].z;
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= x; ++i) {
       sx.insert(mp(a[i].x, i));
       Sx += a[i].x;
    }
    for(int i = x + 1; i <= n; ++i) sy.insert(mp(a[i].y, i));
    for(int i = 1; i <= y; ++i) {
        Sy += (*sy.begin()).fi;
        choose[(*sy.begin()).se] = 1;
        sy.erase(sy.begin());
    }
    S = Sx + Sy;
    for(int i = x + 1; i <= n - y; ++i) {
        sy.erase(mp(a[i].y, i));
        if(choose[i]) {
            Sy -= a[i].y;
            Sy += (*sy.begin()).fi;
            choose[(*sy.begin()).se] = 1;
            sy.erase(sy.begin());
        }
        if((*sx.begin()).fi < a[i].x) {
            Sx -= (*sx.begin()).fi;
            Sx += a[i].x;
            sx.erase(sx.begin());
            sx.insert(mp(a[i].x, i));
        }
        S = max(S, Sx + Sy);
    }
    cout << S + _S;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	double r;
	cin >> r;
	cout << fixed << setprecision(10);
	cout << 2 * M_PI * r << endl;
    
    return 0;
}



Measured memory_bytes: 3784
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n;
  cin >> n;
  cout << n / 3 << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

const int inf = 99999;

class St{
public:
  int c, x, y;
  St() {}
  St(int _c, int _x, int _y): c(_c), x(_x), y(_y) {}

  bool operator>(const St &st) const{
    return st.c < c;
  }
};

int h, w, a[51][51];
int bfs()
{
  priority_queue<St, vector<St>, greater<St> > que;
  int vis[51][51];
  fill(&vis[0][0], &vis[h][w], inf);
  que.push(St(a[0][0], 0, 0));

  while(!que.empty()){
    St st = que.top();
    que.pop();
    
    if(st.x == w-1 && st.y == h-1) return st.c;

    int dx = st.x+1, dy = st.y+1;
    if(dx < w && vis[st.y][dx] > st.c+a[st.y][dx]){
      vis[st.y][dx] = st.c+a[st.y][dx];
      que.push(St(vis[st.y][dx], dx, st.y));
    }
    if(dy < h && vis[dy][st.x] > st.c+a[dy][st.x]){
      vis[dy][st.x] = st.c+a[dy][st.x];
      que.push(St(vis[dy][st.x], st.x, dy));
    }
  }

  return -1;
}

int main()
{
  while(cin>>h>>w && (h+w)){
    for(int i = 0; i < h; i++)
      for(int j = 0; j < w; j++) scanf("%1d", &a[i][j]);

    cout << bfs() << endl;
  }

  return 0;
}

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

using namespace std;

int string_to_sum(string S)
{
  int sum = 0;
  for (auto var : S)
  {
    sum += var - '0';
  }
  return sum;
}

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for (auto i = 1; i <= N; i++)
  {
    int s = string_to_sum(to_string(i));
    if (A <= s && s <= B)
    {
      ans += i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[][] map = { { 0, 300, 500, 600, 700, 1350, 1650 },
				{ 6, 0, 350, 450, 600, 1150, 1500 },
				{ 13, 7, 0, 250, 400, 1000, 1350 },
				{ 18, 12, 5, 0, 250, 850, 1300 },
				{ 23, 17, 10, 5, 0, 600, 1150 },
				{ 43, 37, 30, 25, 20, 0, 500 }, { 58, 52, 45, 40, 35, 15, 0 } };
		while (true) {
			int n = scanner.nextInt() - 1;
			if (n == -1)
				break;
			int a = scanner.nextInt() * 100 + scanner.nextInt();
			int m = scanner.nextInt() - 1;
			int b = scanner.nextInt() * 100 + scanner.nextInt();
			int ans = map[n][m];
			if (map[m][n] <= 40) {
				if ((1730 <= a && a <= 1930) || (1730 <= b && b <= 1930)) {
					if (map[n][m] % 20 == 0) {
						ans = map[n][m] / 2;
					} else {
						ans = (map[n][m] - 50) / 2 + 50;
					}

				}
			}
			System.out.println(ans);
		}
	}
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> t(n), a(n);
  for(int i = 0; i < n; i++) cin >> t.at(i) >> a.at(i);
  
  ll nowt = 1, nowa = 1;
  for(int i = 0; i < n; i++){
    ll t1, a1, t2, a2;
    if(nowt % t.at(i) == 0){
      t1 = nowt;
      a1 = a.at(i) * (t1 / t.at(i));
    }
    else{
      t1 = (nowt / t.at(i) + 1) * t.at(i);
      a1 = a.at(i) * (t1 / t.at(i));
    }
    if(nowa % a.at(i) == 0){
      a2 = nowa;
      t2 = t.at(i) * (a2 / a.at(i));
    }
    else{
      a2 = (nowa / a.at(i) + 1) * a.at(i);
      t2 = t.at(i) * (a2 / a.at(i));
    }
    
    if(a1 < nowa){
      nowt = t2;
      nowa = a2;
    }
    else if(t2 < nowt){
      nowt = t1;
      nowa = a1;
    }
    else{
      if(t1 + a1 < t2 + a2){
        nowt = t1;
        nowa = a1;
      }
      else{
        nowt = t2;
        nowa = a2;
      }
    }
  }
  
  cout << nowt + nowa << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main { 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true) {

				//中間テストm,期末テストf,再テストrの点数をげっと
				int m=sc.nextInt();
				int f=sc.nextInt();
				int r=sc.nextInt();
				//ここから条件分岐
				if(m==-1 && f==-1 && r==-1) break;
				if(m==-1 || f==-1) System.out.println('F');
				else if((m+f)>=80) System.out.println('A');
				else if((m+f)>=65 && (m+f)<80) System.out.println('B');
				else if((m+f)>=50 && (m+f)<65) System.out.println('C');
				else if((m+f)>=30 && (m+f)<50) {
					
					if(r>=50 ) System.out.println('C');
					else System.out.println('D');
				}
				else if((m+f)<30 || m==-1 || f==-1) System.out.println('F');
			}
		}
	}






Measured memory_bytes: 26156
n=int(input())

xy=[]
answer=0

for i in range(n):
    xy.append(list(map(float,input().split())))

for i in range(0,n):
    answer+=(xy[i][0]-xy[i-1][0])*(xy[i][1]+xy[i-1][1])

print(abs(answer)/2)


Measured memory_bytes: 5620
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int a[100];
	int n;
	cin >> n;
	REP(i,n) cin >> a[i];
	for(int i=n-1;i>-1;i--){
		if(i!=0) cout << a[i] << " ";
		else cout << a[i];
	}
	cout << endl;
}

Measured memory_bytes: 1164
from operator import itemgetter
import bisect
from itertools import accumulate
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
WV.sort(key=itemgetter(0, 1))
w, v = zip(*WV)
w0 = w[0]
w1 = w0 + 1
w2 = w1 + 1
w3 = w2 + 1
i0 = bisect.bisect_left(w, w0)
i1 = bisect.bisect_left(w, w1)
i2 = bisect.bisect_left(w, w2)
i3 = bisect.bisect_left(w, w3)
v0 = sorted(v[i0:i1], reverse=True)
v1 = sorted(v[i1:i2], reverse=True)
v2 = sorted(v[i2:i3], reverse=True)
v3 = sorted(v[i3:], reverse=True)
a0 = list(accumulate(v0)) + [0]
a1 = list(accumulate(v1)) + [0]
a2 = list(accumulate(v2)) + [0]
a3 = list(accumulate(v3)) + [0]
n0 = 1 + len(v0)
n1 = 1 + len(v1)
n2 = 1 + len(v2)
n3 = 1 + len(v3)

ans = 0
for i0 in range(n0):
    for i1 in range(n1):
        for i2 in range(n2):
            for i3 in range(n3):
                if i0*w0 + i1*w1 + i2*w2 + i3*w3 <= W:
                    ans = max(ans, a0[i0-1]+a1[i1-1]+a2[i2-1]+a3[i3-1])
print(ans)



Measured memory_bytes: 3316
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        
        int x = scanner.nextInt();
        int i = 0;
        int X;
        int hantei = 0;
        int ans = 0;
        
        while(hantei == 0){
            
            X = x+i;
            
            for(int j=2; j<=X; j++){
                
                if(X%j==0){
                    if(j==X){
                        hantei = 1;
                        ans = X;
                    }else{
                        break;
                    }
                }
                
            }
            
            i++;
            
        }
        
        
        System.out.println(ans);
        
        
    }
}


Measured memory_bytes: 21716