akhauriyash/Code-Regression huggingface dataset:
/*
  
                                _oo0oo_
                               088888880
                               88" . "88
                               (| -_- |)
                                0\ = /0
                             ___/'---'\___
                          .' \\\\|     |// '.
                         / \\\\|||  :  |||// \\
                        /_ ||||| -:- |||||-  \\
                        |   | \\\\\\  -  /// ||
                        | \_|  ''\---/''  |_/ |
                        \  .-\__  '-'  __/-.  /
                      ___'. .'  /--.--\  '. .'___
                   ."" '<  '.___\_<|>_/___.' >'  "".
                  | | : '-  \'.;'\ _ /';.'/ - ' : | |
                  \  \ '_.   \_ __\ /__ _/   .-' /  /
              ====='-.____'.___ \_____/___.-'____.-'=====
                                '=---='

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             AC  AC  AC  AC  AC  AC  AC  AC  AC  AC  AC  AC
     
*/
#define OJ
#include <bits/stdc++.h>
#define pb push_back
#define _1 first
#define _2 second
#define FOR(i,a,b) for(int i=a;i<(b);i++)
#define FORN(i,b) for(int i=0;i<(b);i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define MAX(a,b)  a>b?a:b
#define MIN(a,b)  a>b?b:a
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;

int main()
{
	#ifndef OJ
	freopen("abc.in","r",stdin);
	freopen("abc.out","w",stdout);
	#endif
  int n,a,i,j,k;
  set<int> s1;
  int s2=0;
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>a;
    if(a>3199)  {s2++;  continue;}
    if(a>=1&&a<=399)  {s1.insert(1);  continue;}
    if(a>=400&&a<=799) {s1.insert(2); continue;}
    if(a>=800&&a<=1199){s1.insert(3); continue;}
    if(a>=1200&&a<=1599){s1.insert(4);continue;}
    if(a>=1600&&a<=1999){s1.insert(5);continue;}
    if(a>=2000&&a<=2399){s1.insert(6);continue;}
    if(a>=2400&&a<=2799){s1.insert(7);continue;}
    if(a>=2800&&a<=3199){s1.insert(8);continue;}
  }
  j=s1.size();
  if(j>0) cout<<j<<" ";
  else cout<<"1"<<" ";
  cout<<j+s2;
	#ifndef OJ
	fclose(stdin);
	fclose(stdout);
	#endif
}

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

template<typename T>
vector<T> convert_base(T x, T base) {
    if (x == 0) return {0};
    vector<T> ret;
    while (x) {
        T r = x % base;
        if (r < 0) r -= base;
        x = (x - r) / base;
        ret.emplace_back(r);
    }
    reverse(ret.begin(), ret.end());
    return ret;
}

int main() {
    int n; cin >> n;
    for (auto x: convert_base(n, -2)) cout << x;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100],b[100],c[100];
	scanf("%s%s%s",a,b,c);
	printf("%c",toupper(a[0]));
	printf("%c",toupper(b[0]));
	printf("%c",toupper(c[0]));
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cmath>

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

#define INF 10000007

typedef  long long ll;

using namespace std;

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

ll deg(int i){
  ll ret = 1;
  while(i != 0){
    if(i/10 == 0){
      break;
    }
    i/=10;
  }
  return i;
}

void solve(){
  int n;
  cin >> n;
  string p;
  cin >> p;
  char s[n+1];
  for(int i = 1;i < n+1;i++)
    s[i] = p[i-1];

  ll r=0,g=0,b=0;
  for(int i = 1;i < n+1;i++){
    if(s[i]=='R')r++;
    if(s[i]=='G')g++;
    if(s[i]=='B')b++;
  }
  ll ans = r*g*b;
  map<char,bool> f;
  for(int i = 1;i < n+1;i++){
    if(s[i]=='R'){
      f['R'] = true;
      f['G']=false;
      f['B']=false;
    }
    if(s[i]=='G'){
      f['R'] = false;
      f['G']=true;
      f['B']=false;
    }
    if(s[i]=='B'){
      f['R'] = false;
      f['G']=false;
      f['B']=true;
    }
    for(int j = i+1;j*2-i < n+1;j++){
      if((!f[s[j]]&&!f[s[j*2-i]])&&(s[j]!=s[j*2-i]))
        ans--;
    }
  }
  cout << ans << endl;
}


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


Measured memory_bytes: 3660
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    W, H, x, y = map(int, input().split())
    if W == 2 * x and H == 2 * y:
        print(W * H / 2, 1)
    else:
        print(W * H / 2, 0)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}
#define NUM_MAX 100000

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX+2];
    int i;
    fget_array(&arr[1], num);
    arr[0] = arr[num+1] = 0;

    int64_t sum = 0;
    for(i = 1; i < num+2; i++) {
        sum += abs(arr[i] - arr[i-1]);
    }

    int64_t ans[NUM_MAX+1];
    for(i = 1; i <= num; i++) {
        ans[i] = sum - abs(arr[i+1] - arr[i]) - abs(arr[i] - arr[i-1]) + abs(arr[i+1] - arr[i-1]);
    }

    // presentation
    for(i = 1; i <= num; i++) {
        printf("%lld\n", ans[i]);
    }

    return 0;
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll H, N; cin >> H >> N;
  ll tot = 0;
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    tot += a;
  }
  cout << (tot >= H ? "Yes" : "No") << endl;

  return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[]
for i in range(n):
    abi=list(map(int,input().split()))
    ab.append(abi)
ab.sort()
msum=0
asum=0
for i in range(n):
    ai,bi=ab[i]
    asum=asum+ai*bi
    msum=msum+bi  
    if msum>=m:
        break
asum=asum-ai*(msum-m)
print(asum)

Measured memory_bytes: 27760
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>

struct RangeAddQuery{
    int n;
    std::vector<int> dat;

    void init(int n_){
        n = 1;
        while(n < n_) n *= 2;
        dat.resize(2 * n - 1, 0);
    }

    void add(int a, int b, int k, int l, int r, int x){
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            dat[k] += x;
        }
        else{
            add(a, b, k * 2 + 1, l, (l + r) / 2, x);
            add(a, b, k * 2 + 2, (l + r) / 2, r, x);
        }
    }

    void add(int a, int b, int x){
        add(a, b, 0, 0, n, x);
    }

    int query(int k){
        k += n - 1;
        int res = dat[k];
        while(k > 0) {
            k = (k - 1) / 2;
            res += dat[k];
        }
        return res;
    }
};

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    RangeAddQuery raq;
    raq.init(n);
    while(q--){
        int com;
        cin >> com;
        if(com){
            int i;
            cin >> i;
            cout << raq.query(i - 1) << "\n";
        }else{
            int s, t, x;
            cin >> s >> t >> x;
            raq.add(s - 1, t, x);
        }
    }
}


Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
#define mpi map<ll,ll>
#define  si set<ll>
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define reP(i,a,n) for(ll i=a;i<=n;i++)
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define st string
#define sz size()
#define case(i,n) Case<<" "<<i<<": "<<n<<endl;
#define tc ll t;cin>>t;while(t--)
int main()
{
    ll n,cnt=0;
    cin>>n;
    ll ara[n];
    for(ll i=0; i<n; i++)
       {
            cin>>ara[i];
            if((i+1)%2 and ara[i]%2)
                cnt++;
       }
       cout<<cnt<<endl;
}


Measured memory_bytes: 3588
import java.util.*;

public class Main {
    public static void main(String[] args)   {
        
        Scanner sc = new Scanner(System.in);
        
        double res = 0;
        
        int line = 1;
        
        while(sc.hasNextLine()){
            String input = sc.nextLine();

            if(line != 1){
                if(input.contains("BTC")){
                    double btc = Double.parseDouble(input.replace(" BTC", ""));
                    
                    res+=btc*380000.0d;
                }else{
                    double jpy = Double.parseDouble(input.replace(" JPY", ""));
                    
                    res+=jpy;
                }
            }
            
            line++;
        }
        
        System.out.println(res);
        sc.close();
    }
}

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

#define MAXN 100010
#define ll long long
#define mod 1000000007

using namespace std;

int n, cnt;
ll ans;

ll Dec(ll a, ll b) {return (a -= b) < 0 ? a + mod : a;}

int qp(int x, int y) {
	ll res = 1, base = x;
	while (y) {
		if (y & 1) {
			res = (res * base) % mod;
		}
		base = (base * base) % mod;
		y >>= 1;
	}
	return res;
}

ll F(ll x) {
	ll ans1 = 1, ans2 = 1;
	for(ll i = 1;i <= x; ++i) 
        ans1 = (ans1 * i) % mod;
	for(ll i = n - x + 1; i <= n; ++i) 
        ans2 = (ans2 * i) % mod;
	ans2 = (ans2 * qp(ans1, mod - 2)) % mod;
	return ans2;
}

int a[MAXN];

int main() {
	int x, y;
	scanf("%d%d%d", &n, &x, &y);
	ll ans = qp(2, n);
//	cout << F(x) << " " << F(y) << endl;
	ll tmp = F(x) + F(y);
	if (ans - tmp < 0) {
		ans = (ans - tmp + mod + mod) % mod;
	}
	else ans -= tmp;
	cout << ans - 1 << endl;
	return 0;
} 

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

int main(){
  int a,b;
  char op;
  cin>>a>>op>>b;
  if(op=='+')cout<<a+b<<endl;
  if(op=='-')cout<<a-b<<endl;

  return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <utility>
using std::pair;
using std::map;
#define mp std::make_pair
#define inf 200005
const int maxn = 4e5+5;
int n;
int a[maxn];
int st[2][maxn][20];
map<pair<int, int>, pair<int, int> >son[3];
int  value[maxn], cnt;
struct cmp{
    bool operator () (pair<int, int> x, pair<int, int> y) const {
	if(a[x.first] == a[y.first]) return a[x.second] > a[y.second];
	return a[x.first] > a[y.first];
    }
};

std::priority_queue<pair<int, int>, std::vector<pair<int, int> >, cmp> pq;
int rmq(int k, int l, int r) {
    if(l > r) return 0;
    int len = floor(log(r - l + 1) / (log(2)));
    if(a[st[k][l][len]] < a[st[k][r-(1 << len)+1][len]]) return st[k][l][len];
    else return st[k][r-(1 << len)+1][len];
}
void set(pair<int, int>& a, pair<int, int> b) {
    a.first = b.first;
    a.second = b.second;
}
pair<int, int> divide(int k, int l, int r) {
    if(l > r) return mp(-1, -1);
    int pos1 = rmq(k, l, r);
    int pos2 = rmq(k ^ 1, pos1+1, r);
    set(son[0][mp(pos1, pos2)] , divide(l & 1 ? 0 : 1, l, pos1-1));
    set(son[1][mp(pos1, pos2)] , divide((pos1 + 1) & 1?0:1, pos1+1, pos2-1));
    set(son[2][mp(pos1, pos2)] , divide((pos2+1) & 1?0:1, pos2+1, r));
    return mp(pos1, pos2);
} 
void dfs(int x, int y) {
    pq.pop();
    printf("%d %d ", a[x], a[y]);
    for(int i = 0; i < 3; i++) if(son[i][mp(x,y)].first != -1)pq.push(son[i][mp(x,y)]);
    if(!pq.empty()) dfs(pq.top().first, pq.top().second);
}
int main() {
#ifdef orz
    freopen("input", "r", stdin);
#endif
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    a[0] = inf;
    for(int i = 1; i <= n; i+=2) st[0][i][0] = i, st[1][i][0] = st[0][i+1][0] = 0, st[1][i+1][0] = i+1;
    for(int j = 1; j <= 17; j++) {
	for(int i = 1; i <= n; i++) {
	    if(a[st[0][i][j-1]] < a[st[0][i+(1<<(j-1))][j-1]]) st[0][i][j] = st[0][i][j-1];
	    else st[0][i][j] = st[0][i + (1<<(j-1))][j-1];
	if(a[st[1][i][j-1]] < a[st[1][i+(1<<(j-1))][j-1]]) st[1][i][j] = st[1][i][j-1];
	else st[1][i][j] = st[1][i + (1<<(j-1))][j-1];
	}
    }
    pair<int, int> rt = divide(0, 1, n);
    pq.push(rt);
    dfs(rt.first, rt.second);
}


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

int main() {
int y, x;
cin >> y >> x;
int map[110][110];
for(int i = 0; i < y+1; i++){
for(int j = 0; j < x+1; j++){
map[y][x] = 0;
}
}
for(int i = 0; i < y; i++){
for(int j = 0; j < x; j++){
cin >> map[i][j];
}
}
int sum = 0;
for(int i = 0; i < y+1; i++){

for(int j = 0; j < x+1; j++){
sum += map[i][j];
if(j == x){
map[i][x] = sum;
sum = 0;
}
}
}

for(int i = 0; i < x+1; i++){

for(int j = 0; j < y+1; j++){
sum += map[j][i];
if(j == y){
map[y][i] = sum;
sum = 0;
}
}
}
for(int i = 0; i < y+1; i++){
for(int j = 0; j < x+1; j++){
cout << map[i][j];
if(j == x){
cout << endl;
}
else{
 cout << " ";   
}
}
}
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 100;
int a[maxn];
int main(){
	ll n, m;
	cin >> n >> m;
	if (n%m == 0) cout << "0" << endl, exit(0);
	ll p = n / m;
	n = n - p*m;
	cout << min(n, m - n) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <ext/pb_ds/priority_queue.hpp>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair <ll, int > pii;
typedef __gnu_pbds :: priority_queue <pii,  greater<pii >, pairing_heap_tag > heap;

const int N = 200010;
const int mod = 1e9 + 7;
const ll inf = 1LL << 60;

heap::point_iterator id[N];
struct edge{int to, next; ll v;} e[N << 1];
ll f[2][N], dis[2][N], len, ans;
int head[N], n, m, x, y, z, cnt, s, t;

void ins(int x, int y, int z)
{
    e[++cnt].to = y; e[cnt].next = head[x]; e[cnt].v = z; head[x] = cnt;
}

int dijkstra(int S, int fl)
{
    heap q;
    FOR(i, 1, n) dis[fl][i] = inf, id[i] = 0;
    id[S] = q.push(make_pair(0, S)); dis[fl][S] = 0; f[fl][S] = 1;
    while (!q.empty())
    {
        int x = q.top().second; q.pop();
        for(int i = head[x]; i; i = e[i].next)
        {
            int y = e[i].to;
            if (dis[fl][x] + e[i].v < dis[fl][y])
            {
                dis[fl][y] = dis[fl][x] + e[i].v;
                f[fl][y] = f[fl][x];
                if (id[y] != 0) q.modify(id[y], make_pair(dis[fl][y], y));
                else id[y] = q.push(make_pair(dis[fl][y], y));
            }
            else if (dis[fl][x] + e[i].v == dis[fl][y])
                f[fl][y] = (f[fl][y] + f[fl][x]) % mod;
        }
    }
}

int main()
{
    scanf("%d%d%d%d", &n, &m, &s, &t);
    FOR(i, 1, m)
    {
        scanf("%d%d%d", &x, &y, &z);
        ins(x, y, z); ins(y, x, z);
    }

    dijkstra(s, 0); dijkstra(t, 1);
    len = dis[0][t];

    FOR(i, 1, n) if (dis[0][i] + dis[1][i] == len && dis[0][i] == dis[1][i])
        ans = (ans + f[0][i] * f[0][i] % mod * f[1][i] % mod * f[1][i]) % mod;

    FOR(x, 1, n) for(int i = head[x]; i; i = e[i].next)
        if (dis[0][x] + e[i].v + dis[1][e[i].to] == len && dis[0][x] < dis[1][x] && dis[1][e[i].to] < dis[0][e[i].to])
            ans = (ans + f[0][x] * f[0][x] % mod * f[1][e[i].to] % mod * f[1][e[i].to]) % mod;
    printf("%lld\n", (f[0][t] * f[0][t] - ans + mod) % mod);

    return 0;
}


Measured memory_bytes: 18944
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii()-1;
    string ret;
    while(true){
        ret+=(char)(N%26)+'a';
        if(N<26){
            break;
        }
        N/=26;
        N-=1;
    }
    reverse(ret.begin(), ret.end());
    ose(ret);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);

  vector<long long> map(n + 1);
  vector<long long> cmbi(n + 1);

  for (int i = 0; i < n; i++)
    map.at(a.at(i))++;

  long long sum = 0;
  for (int i = 0; i < n + 1; i++) {
    cmbi.at(i) = map.at(i) * (map.at(i) - 1) / 2;
    sum += cmbi.at(i);
  }

  for (int i = 0; i < n; i++) {
    cout << (map.at(a.at(i)) - 1) * (map.at(a.at(i)) - 2) / 2 + sum - cmbi.at(a.at(i)) << endl;
  }
}

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

int main()
{
	int x[5];
    for(int i=0;i<5;i++)
    {
        cin>>x[i];
        if(x[i]==0)
        {
            cout<<i+1;
            break;
        }
    }
}

Measured memory_bytes: 3588
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
     N, D = map(int, sys.stdin.readline().split())
     L = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]  # 二次元配列入力　二次元マップみたいな入力のとき
     cnt = 0
     for i in range(N):
          l1 = L[i]
          for j in range(i + 1, N):
               l2 = L[j]
               tmp = 0.0
               for v1, v2 in zip(l1, l2):
                    tmp += (v1 - v2) ** 2
               root_tmp = math.sqrt(tmp)
               if root_tmp == int(root_tmp):
                    cnt += 1
     print(cnt)



Measured memory_bytes: 5064
/*
	Created by Faisal Ahmed
*/

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n;
	
	cin >> n;
	
	cout << n * n << endl;
	
	return 0;
} 

Measured memory_bytes: 256
import scala.io.StdIn.readLine
import scala.collection.immutable.Queue
import scala.annotation.tailrec

object Main {
  @tailrec
  def loop(n:Int,q:Queue[(String,Int)]):Queue[(String,Int)] = {
    if(n==0) q
    else {
      val m = readLine.split(" ")
      loop(n-1,q.enqueue((m(0),m(1).toInt)))
    }
  }

  @tailrec
  def rrobin(q:Queue[(String,Int)],total:Int,qt:Int):Unit = {
    if(q.isEmpty) return
    else {
      val ((p,t),r) = q.dequeue
      val (newQ,newT) =
          if(t>qt) (r.enqueue((p,t-qt)),qt)
          else {
            println(p + " " + (t+total))
            (r,t)
          }
      rrobin(newQ,total+newT,qt)
    }
  }

  def main(args:Array[String]) = {
    val l = readLine.split(" ").map(_.toInt)
    val q = loop(l(0),Queue[(String,Int)]())

    rrobin(q,0,l(1))
  }
}

Measured memory_bytes: 127060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

string yes = "Yes";
string no = "No";

string solve() {
    int N;
    cin >> N;

    vector<int> a;
    inputVector(a, N);

    map<int, int> m;
    for (auto num : a) {
        m[num]++;
    }

    if (m.size() == 1) {
        if (m.begin()->first == 0) {
            return yes;
        }
        return no;
    }

    if (N % 3 != 0) return no;

    if (m.size() == 3) {
        int num[3];
        int cnt = 0;
        for (auto &pr : m) {
            num[cnt] = pr.first;
            if (pr.second != N / 3) return no;
            cnt++;
        }

        if ((num[0] ^ num[1]) != num[2]) return no;
        if ((num[1] ^ num[2]) != num[0]) return no;
        if ((num[2] ^ num[0]) != num[1]) return no;
        return yes;
    } else if (m.size() == 2) {
        int num[2];
        for (auto &pr : m) {
            if (pr.second == N / 3) num[0] = pr.first;
            else if (pr.second == 2 * N / 3) num[1] = pr.first;
            else return no;
        }
        return num[0] == 0 ? yes : no;
    } else return no;
}

signed main() {
    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 5632
// -*- coding:utf-8-unix -*-

use std::cmp::*;
use std::collections::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::vec;

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
const MOD: usize = 1000000007;
use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(unused_macros)]
macro_rules! p {
    ([$($x:expr), *]) => {{
        let mut f = true;
        $(
            print!("{}{}", if f {""} else {" "}, $x);
            f = false;
        )*
78786    print!("\n");
    }};
    ($x:expr) => {{
        let mut f = true;
        for a in $x.iter() {
            print!("{}{}", if f {""} else {" "}, a);
            f = false;
        }
        print!("\n");
    }};
}
#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

fn solve() {
    let mut x: usize = read();
    println!("{:?}", x ^ 1);

    return;
}
fn main() {
    solve()
}


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

const long long MOD = 1000000007;

long long mod_pow(long long x, long long n, long long mod){
	long long res = 1;
	while(n > 0){
		if(n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long n; cin >> n;
	long long x[n];
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	long long ans = 0, factor = 0;
	for(int i = 1; i < n; i++){
		factor += mod_pow(i, MOD-2, MOD);
		factor %= MOD;
		ans += factor * (x[i] - x[i-1]);
		ans %= MOD;
	}
	for(int i = 1; i <= n-1; i++){
		ans = ans * i % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define rg register
#define ll long long 
#define inf 0x3f3f3f3f
#define PA pair<int,int>
inline int read()
{
    int 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*10+c-'0',c=getchar();
    return x*f;
}
int g[10]={0,2,5,5,4,5,6,3,7,6};
int n,m;
int used[10005],vis[10];
PA f[10005];
int main(){

    n=read(),m=read();
    for(int i=1;i<=m;i++) vis[read()]=1;used[0]=1;
    for(int i=0;i<n;i++)
        for(int j=1;j<=9;j++)
        {
            if(!used[i]||!vis[j]) continue;
            int t=i+g[j];
            if(t>n) continue;
            PA c(f[i].first+1,j);used[t]=1;
            f[t]=max(f[t],c);
        }
    while(n>0)
    {
        printf("%d",f[n].second);
        n-=g[f[n].second];
    }
    return 0;
}

Measured memory_bytes: 384
import Control.Monad
main = do
  n <- readLn :: IO Int
  xs <- replicateM n getLine :: IO [String]
  putStrLn $ solve xs ['a'..'z']

solve :: [String] -> String -> String
solve xs [] = []
solve xs (c:cs) = 
  (replicate l c) ++ solve xs cs
  where l = foldl1 (\a b -> min a b) $ map (length . filter(==c)) xs

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main() {
  char a; cin >> a;
  if (a == 'A') cout << 'T' << endl;
  else if (a == 'T') cout << 'A' << endl;
  else if (a == 'G') cout << 'C' << endl;
  else cout << 'G' << endl;
  return 0;
}


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

#define ld long double
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define nl '\n'
#define pii pair <ll, ll>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846264
#define y1 abacaba
#define fn "abc"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define pcnt(i) __builtin_popcount(i)
#define lcm(a,b) (a * b) / __gcd(a, b)
#define chill_wave ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pressF freopen("lepus.in", "r", stdin); freopen("lepus.out", "w", stdout);

using namespace std;

const long long MXN = 1e6 + 3;
const long long MAXN = 2e3 + 7;
const long long MOD = 1e9;
const long long INF = 1e18;

inline void f_math(bool ok = 0) { chill_wave if(ok) { pressF; } }

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

ll n, dp[MXN], a[MXN];

int main() {

    f_math();

    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        dp[i] = INF;
    }
    dp[1] = 0;
    for(int i = 2; i <= n; i++) {
        if(i != 2) {
            dp[i] = min(dp[i], abs(a[i] - a[i - 2]) + dp[i - 2]);
        }
        dp[i] = min(dp[i], abs(a[i] - a[i - 1]) + dp[i - 1]);
    }
    cout << dp[n];
    return 0;
}


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

long long power(long long x, long long n){
	long long ans = 1;
	while(n){
		if(n&1) ans *= x;
		n >>= 1;
		x *= x;
	}
	return ans;
}

signed main(){
	int N, n, count = 1;
	
	cin>>n;
	
	N = n;
	
	for(int i = 2; i * i <= n; i++){
		int con = 0;
		while(n%i==0){//cout<<i<<endl;
			n/= i;
			con++;
		}
		if(con){//cout<<power(i,con)<<" "<<power(i,con-1)<<endl;;
			count *= (power(i,con)-power(i,con-1));
		}
		
	}
	if(n != 1)count *= (power(n,1)-power(n,0));
	
	// if(N==1)count = 0;
	cout<<count<<endl;
	
	return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(void)
{
    int a, b;
    int c;
    
    scanf("%d %d", &a, &b);
    if ((a + b) > (a - b)) {
        c = a + b;
    } else {
        c = a - b;
    }
    if ((a * b) > c) {
        c = a * b;
    }
    
    printf("%d\n", c);
    return 0;
}


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

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

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

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

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

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

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

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


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

struct cod {
	ll ind;
	ll x;
	ll y;
};

bool cmpx(cod t, cod u) {
	return t.x < u.x;
}

bool cmpy(cod t, cod u) {
	return t.y < u.y;
}

struct unionfind {
	ll N;
	vector<ll> par;
	vector<ll> sz;//根の場合、その木のサイズ

	unionfind(ll N0) {
		N = N0;
		par.assign(N + 1, -1);
		sz.assign(N + 1, 1);

	}

	ll root(ll x) {
		if (par[x] == -1) { return x; }
		par[x] = root(par[x]);
		return par[x];
	}

	bool same(ll x, ll y) {
		return root(x) == root(y);
	}

	void unite(ll x, ll y) {
		ll a = root(x);
		ll b = root(y);
		if (a != b) { par[a] = b; }
		sz[b] += sz[a];
	}

	ll size(ll x) {
		ll r = root(x);
		return sz[r];
	}
};

//頂点数n 辺集合e(0-index)の無向グラフに対し、最小全域木を構成、disは長さの和
//unionfindを利用

struct Kruskal {
	ll N;
	vector<edge> e;
	vector<vector<edge>> g;
	ll dis;

	

	Kruskal(ll N0, vector<edge> e0) {
		N = N0;
		e = e0;

		g.resize(N + 1);

		unionfind uf(N);

		sort(e.begin(), e.end(), [](edge x, edge y) {return x.d < y.d; });

		dis = 0;

		rep(i,e.size()){
			ll a = e[i].fr;
			ll b = e[i].to;
			if (uf.same(a, b)) { continue; }
			g[a].push_back({ e[i].ind,a,b,e[i].d });
			g[b].push_back({ e[i].ind,b,a,e[i].d });
			dis += e[i].d;
			uf.unite(a, b);
		}

	}

	
};



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

	vector<cod> t(N + 1);

	repn(i, N) {
		t[i].ind = i;
		cin >> t[i].x >> t[i].y;

	}

	vector<edge> e;

	sort(++t.begin(), t.end(), cmpx);

	repn(i, N - 1) {
		e.push_back({ 0,t[i].ind,t[i + 1].ind, t[i + 1].x - t[i].x});
	}

	sort(++t.begin(), t.end(), cmpy);

	repn(i, N - 1) {
		e.push_back({ 0,t[i].ind,t[i + 1].ind, t[i + 1].y - t[i].y });
	}

	Kruskal k(N,e);
	cout << k.dis;


	

	system("PAUSE");
}

Measured memory_bytes: 35688
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

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

    ll ans = 0;
    ll gohyaku = (X / 500);
    ans += gohyaku * 1000;

    ll go = (X - (gohyaku * 500)) / 5;

    ans += go * 5;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
 
   char s[10];
   scanf("%s",s);
   sort(s,s+4);
   printf((s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) ? "Yes\n" : "No\n");

   return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())

# user_dic = {user_id:{user_id: user_condition}}
user_dic = {}
for i in range(1, n+1):
    words_num = int(input())
    words_dic = {}
    for t in range(words_num):
        word = list(map(int, input().split()))
        words_dic[word[0]] = word[1]
    user_dic[i] = words_dic

max_num = 0

# 全てのパターンについて探索
for i in range(2 ** n):
    # 矛盾があるならFalseにする
    flag = True

    # パターンを2進数化
    bin_num = str(bin(i))[2:].zfill(n)

    # ユーザーごとの証言を考える
    for member, words in user_dic.items():
        # 正しい人か否か判断

        # 正しいなら
        if int(bin_num[-1 * member]) == 1:
            # 証言1つずつに対して考える
            for idx, cond in words.items():
                if  int(bin_num[-1 * idx]) != cond:
                    flag = False
                    break
 

        # 正しくないなら
        # else:
        #     # 証言1つずつに対して考える
        #     for idx, cond in words.items():
        #         if  int(bin_num[-1 * idx]) == cond:
        #             flag = False 
    
    # 矛盾がない場合
    if flag:
        # 正直者をカウントし, 結果を比較し更新
        true_num = bin(i).count("1")
        if max_num < true_num:
            max_num = true_num

print(max_num)

sys.exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    vector<ll> h(n,0);
    vector<vector<ll>> edge(n,vector<ll>());
    rep(i,n) {
        cin>>h[i];
    }
    rep(i,m) {
        ll a,b;
        cin>>a>>b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    ll res = 0;
    rep(i,n) {
        bool flg = true;
        rep(j,edge[i].size()) {
            flg &= h[i] > h[edge[i][j]];
        }
        res += flg;
    }
    cout << res << endl;
    return 0;
}


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

int main(void) {
  int N;
  string out = "No";
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i * 4 + 7 * j > N) {
        break;
      }
      if (i * 4 + 7 * j == N) {
        out = "Yes";
        break;
      }
    }
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
K, N = map(int, input().split())
#L = [int(input()) for i in range(N)]
A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]

ls=[K-A[-1]+A[0]]
for i in range(1,N):
    ls.append(A[i]-A[i-1])

print(K-max(ls))

Measured memory_bytes: 80252
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007
 
typedef long long ll;
 

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

    int a;
    string s;
    cin >> s;

    repr(i,s.size()){
        if(s[i] == 'Z'){
            a = i + 1;
            break;
        }
    }

    cout << a - s.find('A') << endl;

	return 0;
}

Measured memory_bytes: 720
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]

pred = fetch_one_line()
fact = fetch_one_line()

print(sum([p == f for p, f in zip(pred, fact)]))



Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int T = sc.nextInt();
		for (int i = 0; i < T; ++i) {
			int N = sc.nextInt();
			int D = sc.nextInt();
			int ans = (N - 1) * 127 + (N % 2 == 0 ? (D ^ 127) : D);
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 14412
#include <stdio.h>
#include <string.h>

int ans[1000000];

void mkPrime(){
  int i,j;

  for(i=2;i<1000000;i++){
    ans[i] = 1;
  }
  ans[0] = ans[1] = 0;

  for(i=2;i<1000000;i++){
    if(ans[i]){
      for(j=i+i;j<1000000;j+=i){
        ans[j] = 0;
      }
    }
  }

  for(i=1;i<1000000;i++){
    ans[i] += ans[i-1];
  }
}

int main(void){
  int n;

  mkPrime();
  while(scanf("%d",&n) != EOF){
    printf("%d\n",ans[n]);
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
const ll maxint=2e18;
const ll minint =-2e18;
/*******\
(͡ ° ͜ʖ ͡ °) : Hello there, relax.
\*     */

int main(){
    int n;
    cin>>n;
    ll res = 0;
    for(int a=1;a<n;a++){
        //cout<<a<<" "<<((n-1)/a)<<endl;
        res += ((n-1)/a);
    }
    cout<<res<<'\n';
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>

#define rep(i, n) for (int i = 0; i < n; i++) 
#define rrep(i, n) for(int i = n-1; i>=0; i--)
#define range(i, n, m) for (int i = n; i < m; i++) 
#define rrange(i, n, m) for (int i = n - 1; i => m; i--) 
#define MOD 1000000007

typedef long long int ll;
typedef unsigned long long int ull;


using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

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

	ll N, M;
	ll A, B, C;
	string S, T;

	vector<ll> in(5);


	rep(i, 5) {
		cin >> in[i];
	}
	cin >> A;
	bool flg = false;

	rep(i, 5) {
		rep(k, 5) {
			if (abs(in[i] - in[k]) > A) {
				flg = true;
			}
		}
	}


	if (flg) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}





	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
  int a, b;
  cin >> a >> b;
  int ans;
  if(a + b == 3) {
    ans = 3;
  } else if(a + b == 4) {
    ans = 2;
  } else if(a + b == 5) {
    ans = 1;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n,k; cin>>n>>k;
  string s; cin>>s;
  int ans=0,change=0;
  char now=s[0];
  bool flag = false;
  for(int i=0;i<n;i++){
    if(now==s[i]){
      if(flag){
        ans++;
      }else flag=true;
    }else{
      now=s[i];
      change++;
      flag=true;
    }
  }
  if(k<(change+1)/2){
    ans+=2*k;
  }else{
    ans+=2*((change+1)/2);
    if(s[0]!=s[n-1]) ans--;
  }
  cout<<ans<<endl;
}

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

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1) {
  for(int u : to[v]) {
    if(u == p) continue; //親だったらスルー
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  // 双方向の辺作成
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  dfs(0);

  rep(i, n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 23680
def main():
  k, n = map(int, input().split())
  max_range = 0
  first = True
  first_range = 0
  pre_range = 0
  for i in [int(i) for i in input().split()]:
    if first:
      first = False
      first_range = i
      pre_range = i
      continue
    
    if max_range < i - pre_range:
      max_range = i - pre_range
    
    pre_range = i
  
  if max_range < first_range + (k - pre_range):
    max_range = first_range + (k - pre_range)
  
  return k - max_range

print(main())

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

  int main() {
    string S;
    int K;
    int count = 0;
    cin >> S >> K;


    for (int i = 0; i < S.length(); i++) {
      if (S[i] != '1')
        break;
      count += 1;
    }

    if (0 <= K && K <= count)
        cout << '1' << endl;
    else
        cout << S[count] << endl;

    return 0;
  }


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a, b,c,d;
    string S;
    //cin >> S;
    cin >> a>>b>>c>>d;
    if (a+b<c+d) cout << "Right"  << endl;
    else if (a+b>c+d) cout << "Left"  << endl;
    else cout << "Balanced"  << endl;

    return 0;
}


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

# define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
# define FORD(i, a, b) for(int i = (a); i >= (b); --i)
# define VAR(v, i) __typeof(i) v=(i)
# define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define ff first
# define ss second
# define mp make_pair
# define pb push_back
# define next ____next
# define prev ____prev
# define left ____left
# define hash ____hash

using namespace std;

typedef long long lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}

// ---------------------------------------------------------------------------------------------------------------------------------- //

int N;
lld total;
string s;
lld cnt[2][30];

int main(){
    cin >> s;
    
    N = s.length();
    
    // tekler icin
    FOR(i, 0, N-1)
        total += min(i+1, N - i);
    
    // ciftler icin
    FOR(i, 0, N-1)
        total += min(i+1, N-i-1);

    FOR(i, 0, N-1)
        cnt[i%2][s[i]-'a']++;

    // tekler icin
    FOR(i, 0, 1)
        FOR(j, 0, 25)
            total -= cnt[i][j] * (cnt[i][j]+1) / 2;

    //ciftler icin
    FOR(i, 0, 25)
        total -= cnt[0][i] * cnt[1][i];

    cout << total + 1;

}


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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define in(a, l, r) (l <= a && a < r)
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template<typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

int main() {
    int A, B; cin >> A >> B;
    out(max(A - B * 2, 0));
    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    while (1) {
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<int> p(n);
        for (int i=0; i<n; ++i) {
            cin >> p[i];
        }
        sort(p.begin(), p.end(), greater<int>());

        int sum = 0, minus = 0;
        for (int i=0; i<(int)p.size(); ++i) {
            sum += p[i];
            if ((i + 1) % m == 0) minus += p[i];
        }
        cout << sum - minus << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
 
int main(int argc, const char * argv[])
{
    int H,A,t;
     
    scanf("%d%d",&H,&A);
     
    if (H%A==0) {
        t=H/A;
    }
    else{
        if(A>H)
            t=1;
        else{t=H/A+1;}
    }
    printf("%d",t);
    
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();

		int n = 0;
		int e = 0;
		int w = 0;
		int s = 0;

		for(int i=0;i<S.length();i++) {
			switch(S.charAt(i)) {
			case 'N':
				n++;
				break;
			case 'E':
				e++;
				break;
			case 'W':
				w++;
				break;
			case 'S':
				s++;
				break;
			default:
				break;
			}
		}

		boolean ns = false;
		boolean ew = false;

		if((n==0 && s==0) || (n>=1 && s>=1)) ns = true;
		if((e==0 && w==0) || (e>=1 && w>=1)) ew = true;

		if(ns && ew) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


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

int n;
int a[2][101];
int ans;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<2; ++i)
		for(int j=0; j<n; ++j)
			cin >> a[i][j];
	for(int i=0; i<n-1; ++i){
		a[0][i+1] += a[0][i];
		a[1][n-2-i] += a[1][n-1-i];
	}
	for(int i=0; i<n; ++i)
		ans = max(ans, a[0][i] + a[1][i]);
	cout << ans << "\n";
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	//freopen("in.txt", "r", stdin);
  
	cin >> l >> r >> d;
	int c = 0;
	rep(i, l, r) if (i % d == 0) c++;
	cout << c;
}

Measured memory_bytes: 3628