akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll mod=1e9+7;
int main()
{
IOS
int n,cnt=0;
cin>>n;
vector<int> vis(1000003),v(n);
for(int i=0;i<n;i++)
{
    cin>>v[i];
    vis[v[i]]++;
}
for(int i=0;i<n;i++)
{
    ll f=1;
    for(int j=1;j<=sqrt(v[i]);j++)
    {
        if(v[i]%j==0)
        {
            if((j!=v[i] && vis[j]>=1) || (j==v[i] && vis[i]>1))
            {
                f=0;
                break;
            }
            int p=v[i]/j;
            if((p!=v[i] && vis[p]>=1) || (p==v[i] && vis[p]>1))
            {
                f=0;
                break;
            }
        }
    }
    if(f==1)
        cnt++;
}
cout<<cnt;
return 0;
}


Measured memory_bytes: 7960
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(i) i.begin(),i.end()

using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		vector<int> p;
		rep(i,n){
			int tmp;
			cin>>tmp;
			p.push_back(tmp);
		}
		sort(all(p));
		ll sum=0;
		for(int i=1;i<n-1;i++){
			sum+=p[i];
		}
		cout<<sum/(n-2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

#DIV = (10**9) + 7
DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    a = iRaw()
    ans = a + a**2 + a**3
    print(ans)




main()


Measured memory_bytes: 67432
import Control.Applicative
import Control.Monad

solver :: Int -> Int -> [String]
solver h w = replicate h $ concat $ replicate w "#"


main :: IO()
main = do
  (h:w:_) <- map (read :: String -> Int) . words <$> getLine
  unless (h == 0 && w == 0) $ do
    mapM_ putStrLn $ solver h w
    putStrLn ""
    main

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N);
  uint64_t ans=1;
  bool f=false;
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i=0;i<N;i++){
    uint64_t b = A[i];
    uint64_t before = ans;
    ans*=b;
    if(ans<0 || ans > 1000000000000000000 || ans<before){
      f=true;
      break;
    }
    
  }
   if(f)
     cout << -1 << endl;
  else
    cout << ans << endl;
}


Measured memory_bytes: 4000
#include<stdio.h>
int main()
{
    int w,i,x;
    char S[1005];
    gets(S);
    scanf("%d",&w);
    x = strlen(S);
    for(i=0;i<x;i++){


        if(i%w==0){

            printf("%c",S[i]);
        }


    }
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include <vector>
#include <set>
using namespace std;
int main(){
	int n;
	cin>>n;
	int p[n];
	for(int i=0;i<n;i++)cin>>p[i];
	int ans=0;
	for(int i=0;i<n-2;i++){
	 if(p[i]>p[i+1] && p[i+1]>p[i+2])ans++;
	 
	 if(p[i]<p[i+1] && p[i+1]<p[i+2])ans++;
	}
	cout<<ans;
	
	
	
	
		
}


Measured memory_bytes: 256
S = input()
N = len(S)
x = 0
if S[0] == 'A':
    if S[1] == 'C' or S[-1] == 'C':
        print('WA')
    else:
        if S.count('C') == 1:
            S.replace('A', '')
            S.replace('C', '')
            N = len(S)
            for i in range(N):
                if 97 <= ord(S[i]) <= 122:
                    x += 1
            if x == N - 2:
                print('AC')
            else:
                print('WA')
        else:
            print('WA')
else:
    print('WA')

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define cu continue
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf LLONG_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define f first
#define s second
#define vll vector <ll>
#define dbg(n) cout<<#n<<' '<<n<<endl;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cout<<fixed<<setprecision(8);
 	ll l;
 	cin>>l;
 	double x;
 	x=1.0*l/3;
 	cout<<x*x*x<<'\n';
}       


Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_057_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 i      PIC 9(2).
    01 j      PIC 9(2).

    01 INP    PIC X(5).
    01 INP2   PIC X(21).

    01 N      PIC 9(2).
    01 M      PIC 9(2).

    01 st1.
        03 st11 OCCURS 50.
            05 stx PIC S9(9).
            05 sty PIC S9(9).

    01 pt1.
        03 pt11 OCCURS 50.
            05 ptx PIC S9(9).
            05 pty PIC S9(9).

    01 dt     PIC 9(9).
    01 dtx    PIC 9(9).
    01 dty    PIC 9(9).

    01 mn     PIC 9(9).
    01 p      PIC 9(2).

    01 ans    PIC X(2).

    01 ZS     PIC Z(2)9.
    01 DUMMY  PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO N M.

    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
        ACCEPT INP2

        UNSTRING INP2
        DELIMITED BY SPACE
        INTO stx(i) sty(i)
    END-PERFORM.

    PERFORM VARYING i FROM 1 BY 1 UNTIL M < i
        ACCEPT INP2

        UNSTRING INP2
        DELIMITED BY SPACE
        INTO ptx(i) pty(i)
    END-PERFORM.

    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i

        MOVE 400000001 TO mn

        PERFORM VARYING j FROM 1 BY 1 UNTIL M < j
            SUBTRACT ptx(j) FROM stx(i) GIVING dtx
            SUBTRACT pty(j) FROM sty(i) GIVING dty
            ADD dtx TO dty GIVING dt
            IF dt < mn THEN
                MOVE dt TO mn
                MOVE j TO p
            END-IF
        END-PERFORM

        MOVE p TO ZS

        PERFORM UNANS

        DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans))

    END-PERFORM.

    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 384
def main():
    n = int(input())
    a = list(map(int,input().split()))
    temp = 1
    if 0 in a:
        temp = 0

    for n in a:
        if temp == -1:
            break
        temp *= n
        if temp > 10 ** 18:
            temp = -1
            break
    print(temp)

if __name__ == '__main__':
    main()


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

int main() {
    int N, s=0, x;
    cin >> N;
    x = N;
    while(1) {
        s += N%10;
        N /= 10;
        if (N==0) break;
    }
    if ( x%s ) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 3612
MOD = 10**9 + 7
def MOD_pow(a, n):
    res = 1
    while n > 0:
        if (n & 1):
            res = res * a % MOD
        a = a * a % MOD
        n = n // 2
    return res
def MOD_perm(n, r):
    rtn = 1
    for _ in range(r):
        rtn *= n
        rtn %= MOD
        n -= 1
    return rtn
def MOD_inv(a):
    b = MOD
    u = 1
    v = 0
    while b > 0:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u = u % MOD
    if u < 0:
        u += MOD
    return u
def cmb(n, r):
    return MOD_perm(n, r) * MOD_inv(MOD_perm(r, r)) % MOD

def main():
    n, a, b = map(int, input().split())
    ans = MOD_pow(2, n) - cmb(n, a) - cmb(n, b) - 1
    while ans < 0:
        ans += MOD
    print(ans)

if __name__ == "__main__":
    main()

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

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

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

    ll a,b;
    cin >> a >> b;
    ll c = gcd(a,b);
    ll cou = 1;
    for(ll i=2;i*i<=c;i++){
        if(c%i==0){
            cou++;
            while(c%i==0){
                c/=i;
            }
        }
    }
    if(c!=1)cou++;

    cout << cou << endl;
}


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

signed ans(string s,int a);

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    string s,t;
    cin >> s >> t;
    int a = s.size();
    int b = t.size();

    for(int i = 0;i < a-b+1;i ++){
        if(t == s.substr(i,b)){
        ans(s,a);
        return 0;
        }
    }

    for(int i =a-b;i >= 0;i --){
        for(int j = 0;j < b;j ++){

            if(s.at(i+j) != t.at(j) && s.at(i+j) != '?') break;

            if(j == b-1){
                for(int k = 0;k < b;k ++){
                    s.at(i+k) = t.at(k);
                }
                ans(s,a);
                return 0;
            }
        }
    }

    cout << "UNRESTORABLE" << endl;
}

signed ans(string s,int a){
    for(int i = 0;i < a;i ++){
        if(s.at(i) == '?') s.at(i) = 'a';
    }

    cout << s << endl;
}

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

using namespace std;

int main(){
  long long n, a[200009];
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  long long all=0;
  for(int i=0;i<n;i++)all^=a[i];
  for(int i=0;i<n;i++){
    cout << (all^a[i]) << (i==n-1?'\n': ' ');
  }
}


Measured memory_bytes: 5160
from math import *
PI = 3.1415926535898
while True:
	try:
		a = map(int, raw_input().strip().split(' '))
		b = map(int, raw_input().strip().split(' '))
		hit = 0
		blow = 0
		for i in range(len(a)):
			if a[i] == b[i]:
				hit += 1
			elif b.count(a[i]) > 0:
				blow += 1
		print "%d %d" % (hit, blow)
	except EOFError:
		break

Measured memory_bytes: 6384
n = int(input())
l = [[] for _ in range(n)]

for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,(input().split()))
        l[i].append([x-1,y])

ans = 0
for i in range(1 << n):
    h = []
    for j in range(n):
        h.append(i & 1 << j != 0)
    b = True
    for j in range(n):
        if i & 1 << j:
            for k in l[j]:
                if (k[1] == 1) != h[k[0]]:
                    b = False
                    break
        if not b:
            break
    if b:
        ans = max(ans,h.count(True))

print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n;
    cin >> n;

    vector<LL> a(n+1);

    for(int i = 1; i < n+1; i++){
        cin >> a[i];
    }

    sort(a.begin()+1,a.end(),greater<LL>());

    vector<LL> sum(n+1,0);

    sum[n] = a[n];

    for(int i = n-1; i > 0; i--){
        sum[i] = sum[i+1] + a[i];
    }

    LL result = 1;

    auto solve = [&](int k)->bool{
        if(a[k-1] <= sum[k]*2 ){
            result++;
            return true;
        }else{
            return false;
        }
    };

    int i = 2;

    while(i < n+1 && solve(i)){
        i++;
    }

    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 1792
def solve():
  n, m = map(int,input().split())
  plst = list(map(int,input().split()))
  pare_inds = [i for i in range(n)]
  belongs = [[] for i in range(n)]
  
  def get_root(x):
    p = pare_inds[x]
    if p == x:
      return x
    a = get_root(p)
    pare_inds[x] = a
    return a
  
  for i in range(m):
    x, y = map(int,input().split())
    x, y = x - 1, y - 1
    r_x, r_y  = get_root(x), get_root(y)
    if r_x < r_y:
      pare_inds[y] = r_x
      pare_inds[r_y] = r_x
    else:
      pare_inds[x] = r_y
      pare_inds[r_x] = r_y
  
  for i in range(n):
    belongs[get_root(i)].append(i)

  ans = 0

  for lst in belongs:
    lst2 = [plst[i] - 1 for i in lst]
    set1 = set(lst)
    set2 = set(lst2)
    ans += len(set1 & set2)
#    lst.sort()
#    lst2.sort()
#    ind1 = 0
#    ind2 = 0
#    end = len(lst)
#    while ind1 < end and ind2 < end:
#      if lst[ind1] == lst2[ind2]:
#        ans += 1
#        ind1 += 1
#        ind2 += 1
#      elif lst[ind1] < lst2[ind2]:
#        ind1 += 1
#      else:
#        ind2 += 1
  
  print(ans)
solve()

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

using namespace std;

#define ll  long long
#define ld  double

#define all(x)  x.begin(),x.end()
#define sz(x)   (int)x.size()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 1e6 + 5;
const int   mod = 1e9 + 7;

void add(int &a,int b)  {
    a += b;
    if (a >= mod)
        a -= mod;
}
void sub(int &a,int b)  {
    a -= b;
    if (a <  0)
        a += mod;
}
int mul(int a,int b)    {
    return  1ll * a * b % mod;
}
int Pow(int a,int b)    {
    int ans = 1;
    while (b)   {
        if(b & 1)   ans = mul(ans,a);
        a = mul(a,a);   b >>= 1;
    }
    return  ans;
}
int inv(int a,int p)    {
    return  a == 1 ? 1 : p - 1ll * p * inv(p % a,a) / a;
}

typedef pair<int,int>   ii;

int f[N];

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

    int n;  cin >> n;

    f[0] = 1;
    f[1] = 1;

    int S = 2;

    for(int i = 2 ; i < n ; ++i)    {
        add(f[i],S);
        sub(f[i],f[i - 2]);

        add(S,f[i]);
    }
    sub(S,f[n - 1]);

    int ans = 1;

    add(ans,mul(S,n - 1));
    add(ans,mul(f[n - 1],n - 1));

    for(int i = 0 ; i < n - 1 ; ++i)    {
        int C = f[i];
        C = mul(C,n - 1);
        C = mul(C,n - 1);

        add(ans,C);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4224
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int calc(int n, int m) {
    int f(int k) {
        return k * (k - 1) / 2;
    }
    return f(n) + f(m);
}

void main() {
    int n, m; scan(n, m);
    writeln(calc(n, m));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 256
import Foundation
var X = Int(readLine()!) ?? 0
var moneyArray = [0,0]

moneyArray[0] = (X/500)*1000
X = X%500 
moneyArray[1] = (X/5)*5
X = X%5

let happiness =  moneyArray.reduce(0){(num1: Int, num2: Int)  -> Int in
  return num1 + num2
}
print(happiness)

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 m, nm, nM;
  while(cin >> m >> nm >> nM, m) {
    vector<i64> P(m);
    rep(i,0,m) cin >> P[i];
    sort(all(P));
    reverse(all(P));
    i64 ans = -1e18;
    i64 res = 0;
    rep(i,nm,nM + 1) {
      i64 tmp = ans;
      ans = max(ans, P[i - 1] - P[i]);
      if(tmp <= P[i - 1] - P[i]) {
        res = i;
      }
    }
    cout << res << endl;
  }
}



Measured memory_bytes: 3092
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    print('ABC'+input())

if __name__ == '__main__':
    main()


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

int main() {
	string one, two, three = "";
	cin >> one >> two;

	for (int i = 0; i < two.size() - 1; i++) {
		three += two[i];
	}
	bool notEqual = false;

	for (int i = 0; i < one.size(); i++) {
		if(one[i] != three[i]) {
			notEqual = true;
			break;
		}
	}

	if(notEqual) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
}

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

int main(){
	int n, d;
	cin >> n >> d;
	int a[n][d], ans = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < d; j++){
			cin >> a[i][j];
		}
	}
	
	for(int i = 0; i < n-1; i++){
		for(int j = i+1; j < n; j++){
			int dist = 0;
			for(int k = 0; k < d; k++){
				dist += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
			}
			int sq;
			for(int k = (sq = (int)sqrt(dist)) - 1; k < sq + 1; k++){
				if(k * k == dist) ans++;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n , x , a[200001] = {0};
  std::cin >> n ;
  for(int i=1; i < n; i++) {
    std::cin >> x;
    a[x] += 1 ;
  }
  for(int i=1; i <= n; i++){
    cout << a[i] << endl;
  }
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int n,a,b,cnt=0;
    cin >> n;
    rep(i,n){
        cin >> a >> b;
        if(a==b and cnt!=3)cnt++;
        else if (a!=b and cnt!=3)cnt=0;
    }
    cout << (cnt==3?"Yes":"No");

    return 0;
}

Measured memory_bytes: 3648
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      count=0
      if i>0 and S[i-1][j]=='#': count+=1
      if (i>0 and j>0)and S[i-1][j-1]=='#': count+=1
      if (i>0 and j<W-1)and S[i-1][j+1]=='#': count+=1
      if i<H-1 and S[i+1][j]=='#': count+=1
      if (i<H-1 and j>0)and S[i+1][j-1]=='#': count+=1
      if (i<H-1 and j<W-1)and S[i+1][j+1]=='#': count+=1
      if j>0 and S[i][j-1]=='#': count+=1
      if j<W-1 and S[i][j+1]=='#': count+=1
      S[i][j]=str(count)
for i in range(H):
  for j in range(W):
    if j<W-1: print(S[i][j],end='')
    else: print(S[i][j])

Measured memory_bytes: 43372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

VI adj[212345];
int cnt[212345] = {};
LL ans[212345] = {};

void dfs(LL acc, int idx, int par){
    ans[idx] = acc + cnt[idx];
    for(auto i : adj[idx]){
        if(i != par){
            dfs(acc+cnt[idx],i,idx);
        }
    }
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin >> N >> Q;
    REP(i,N-1){
        int a,b; cin >>a>> b;
        a--; b--;
        adj[a].eb(b);
        adj[b].eb(a);
    }
    REP(i,Q){
        int p,x; cin>> p >> x;
        p--;
        cnt[p] += x;
    }
    dfs(0,0,-1);
    REP(i,N){
        cout << ans[i] << " ";
    }
    cout << endl;


}


Measured memory_bytes: 28288
#include <cstdio>
#include <cstring>

bool mp[16][16];
int dp[16][16];

int main() {
	int a,b,n;
	while(scanf("%d %d",&a,&b),a||b) {
		scanf("%d",&n);
		memset(mp,0,sizeof(mp));
		for(int i=0;i<n;i++) {
			int x,y;
			scanf("%d %d",&x,&y);
			mp[x-1][y-1]=true;
		}
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(int i=0;i<a;i++) {
			for(int j=0;j<b;j++) {
				if(mp[i][j]) continue;
				dp[i][j]+=!mp[i][j]&&(i-1)>=0?dp[i-1][j]:0;
				dp[i][j]+=!mp[i][j]&&(j-1)>=0?dp[i][j-1]:0;
			}
		}
		printf("%d\n",dp[a-1][b-1]);
	}
}

Measured memory_bytes: 1028
using System;
using System.Collections.Generic;

    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            
            List<string> input = new List<string>();
            List<double> iList=new List<double>();
            int count=0;
            input.AddRange(Console.ReadLine().Split(' '));
            double answer =0;

            foreach(var s in input)
            {
                iList.Add(double.Parse(s));
                iList.Sort();
            }

            count=iList.Count;
            
            for(int i=0;i<count-1 ; i++)
            {
                answer = (iList[0]+iList[1])/2;
                iList.RemoveAt(0);
                iList.RemoveAt(0);
                iList.Insert(0,answer);
            }

            foreach(var i in iList)
            {
                Console.WriteLine(i);
            }
        }

}


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

using namespace std;

int n, v[20], c[20], f[20];

void input() {
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> v[i];
	for (int i = 0; i < n; ++i) cin >> c[i];
}

void genInput() {
	n = 4;
	for (int i = 0; i < n; ++i) {
		v[i] = rand() % 5 + 1;
		c[i] = rand() % 5 + 1;
	}
}

int bruteForce() {
	int res = 0;
	for (int state = 0; state < (1 << n); ++state) {
		int tmp = 0;
		for (int j = 0; j < n; ++j)
			if (state & (1 << j))
				tmp += v[j] - c[j];
		res = max(res, tmp);
	}
	return res;
}

int dp() {
	f[0] = max(0, v[0] - c[0]);
	for (int i = 1; i < n; ++i)
		f[i] = max(f[i - 1], f[i - 1] + v[i] - c[i]);
	return f[n - 1];
}

int main() {
	/*
	int Case = 0;
	while (true) {
		genInput();
		int res1 = bruteForce();
		int res2 = dp();
		if (res1 != res2) {
			printf("FAIL\n");
			for (int i = 0; i < n; ++i)
				printf("%d: [v = %d, c = %d]\n", i, v[i], c[i]);
			break;
		}
		printf("Passed case %d\n", ++Case);
	}
	*/
	input();
	cout << dp();
	return 0;
}


Measured memory_bytes: 256
n = int(input())
for i in range(1, 3501):
  for j in range(1, 3501):
    seed = 4 * i * j - n * (i + j) 
    if seed > 0:
      k, mod = divmod(n * i * j, seed) 
      if mod == 0:
        print(i, j, k)
        exit()


Measured memory_bytes: 2940
#include <stdio.h>

int		main()
{
	int		N;
	int		i;
	long	sum;

	i = 1;
	sum = 0;
	scanf("%d\n", &N);
	while (i <= N)
	{
		if (i % 3 && i % 5)
			sum += (long)i;
		i++;
	}
	printf("%ld\n", sum);
	return (0);
}


Measured memory_bytes: 1732
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let r:f64 = read();
    println!("{}",2.0*r*std::f64::consts::PI);
}


Measured memory_bytes: 2188
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		
		for( int A = (-120); A < (120); A++){
			for( int B = (-120); B < (120); B++){
			if(Math.pow(A,5)-Math.pow(B,5) == X)
			{System.out.println(A+" "+B); return;}
		}
		}
	}
}

Measured memory_bytes: 38660
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;
const double INF = 1e8;

struct Edge{
    int from,to;
    double dist;
    Edge(int from,int to,double dist) : from(from),to(to),dist(dist) {};
};

int main(){
    cout << fixed << setprecision(10);
    while(true){
        // 券,都市,道,from,to
        int n,m,p,a,b;
        cin >> n >> m >> p >> a >> b;
        if(n == 0 and m == 0 and p == 0 and a == 0 and b == 0) break;
        a--,b--;
        vector<int> uma(n);
        for(int i=0;i<n;i++) {
            cin >> uma[i];
        }
        vector<vector<Edge> > edge(m);
        for(int i=0;i<p;i++){
            int x,y,z;
            cin >> x >> y >> z;
            x--,y--;
            edge[x].push_back(Edge(x,y,z));
            edge[y].push_back(Edge(y,x,z));
        }

        vector<vector<double> > DP(1 << n,vector<double>(m,INF));
        DP[0][a] = 0;

        for(int s=0;s<(1 << n);s++){
            for(int t=0;t<m;t++){
                if(DP[s][t] >= INF) continue;
                for(int k=0;k<n;k++){
                    if(s & (1 << k)) continue;
                    for(int e=0;e<edge[t].size();e++){
                        DP[s | (1 << k)][edge[t][e].to] = min(DP[s | (1 << k)][edge[t][e].to],
                                                              DP[s][t] + edge[t][e].dist/uma[k]);

                    }
                }
            }
        }
        // cerr << b << endl;
        // for(int i=0;i<(1 << n);i++){
        //     for(int j=0;j<m;j++){
        //         cerr << DP[i][j] << " ";
        //     }
        //     cerr << endl;
        // }
        // for(int i=0;i<(1 << n);i++){
        //     for(int j=0;j<m;j++){
        //         cerr << DP[i][j] << " ";
        //     }
        //     cerr << endl;
        // }
        double minii = INF+EPS;
        for(int i=0;i<(1 << n);i++){
            minii = min(minii,DP[i][b]);
        }
        if(minii >= INF){
            cout << "Impossible" << endl;
        }else{
            cout << minii << endl;
        }
    }
    return 0;
}

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

int a[3001];
long long dp[3001][3001][2];

int main(){

	int n;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = n - 1; i >= 0; i--){
		for(int j = i; j < n; j++){
			for(int p = 0; p < 2; p++){
				if(i == j){
					dp[i][j][p] = a[i];
					continue;
				}
			
				dp[i][j][p] = max(-dp[i + 1][j][!p] + a[i], -dp[i][j - 1][!p] + a[j]);
			}
		}
	}
	cout << dp[0][n-1][0];

}





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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

class UnionFind
{
public:
    UnionFind(int n)
        : mN(n)
    {
        REP(i, n)
        {
            mNodeTbl.push_back(i);
            mRankTbl.push_back(0);
        }
    }

    int find(int x)
    {
        if (x == mNodeTbl[x])
            return x;
        return mNodeTbl[x] = find(mNodeTbl[x]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    void unit(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (mRankTbl[x] < mRankTbl[y])
        {
            mNodeTbl[x] = y;
        }
        else
        {
            mNodeTbl[y] = x;
            if (mRankTbl[x] == mRankTbl[y])
                mRankTbl[x]++;
        }
    }

private:
    int mN;
    vector<int> mNodeTbl;
    vector<int> mRankTbl;
};

struct Group
{
    vector<ll> v;
    ll g;
};

pll A[100005];

int main()
{
    ll N;
    cin >> N;
    vector<ll> X;
    REP(i, N)
    {
        cin >> A[i].first >> A[i].second;
        X.push_back(A[i].first);
    }
    sort(X.begin(), X.end());
    X.erase(unique(X.begin(), X.end()), X.end());

    sort(A, A + N, [](pll a, pll b) { return a.second < b.second; });
    vector<Group> G(X.size());
    REP(i, N)
    {
        ll x = lower_bound(X.begin(), X.end(), A[i].first) - X.begin();
        G[x].v.push_back(A[i].second);
    }

    UnionFind uf(X.size());
    REP(i, N - 1)
    {
        if (A[i].second == A[i + 1].second)
        {
            ll x0 = lower_bound(X.begin(), X.end(), A[i].first) - X.begin();
            ll x1 = lower_bound(X.begin(), X.end(), A[i + 1].first) - X.begin();
            uf.unit(x0, x1);
        }
    }

    REP(i, G.size())
    {
        G[i].g = uf.find(i);
    }
    sort(G.begin(), G.end(), [](Group a, Group b) { return a.g < b.g; });

    ll ans = 0;
    ll row = 0, col = 0;
    vector<ll> v;
    REP(i, G.size())
    {
        row++;
        col += G[i].v.size();
        REP(j, G[i].v.size())
        {
            v.push_back(G[i].v[j]);
        }

        if (i == G.size() - 1 || G[i].g != G[i + 1].g)
        {
            sort(v.begin(), v.end());
            v.erase(unique(v.begin(), v.end()), v.end());

            ans += std::max(0LL, static_cast<ll>(v.size() * row - col));
            v.clear();
            row = col = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

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

// #define int long long

/* short */
#define pb push_back
#define print(Target) cout << Target << '\n'

/* REPmacro */
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

/* const */
const int INF = INT_MAX;

signed main()
{
  //ios::sync_with_stdio(false);
  string s;
  vector<string> dic, ans;

  while (cin >> s){
    dic.pb(s);
    char c;
    scanf("%c", &c);
    if (c == '\n') break;
  }
  bool flg = false;
  REP(i, dic.size()){
    REP(j, dic[i].size()){
      if (dic[i][j] == ',' || dic[i][j] == '.'){
        dic[i].erase(dic[i].begin() + j);
      }
    }
    if (3 <= dic[i].size() && dic[i].size() <= 6){
      ans.pb(dic[i]);
    }
  }
  REP(i, ans.size() - 1){
    cout << ans[i] << " ";
  }
  print(ans[ans.size() - 1]);
  
  return (0);
}

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

const int NIL = -1;

template <typename T> struct Node {
  T parent = NIL;
  T left = NIL;
  T right = NIL;
};

template <typename T> int depth(int u, const std::vector<T> &t) {
  int d = -1;
  while (u != NIL) {
    ++d;
    u = t.at(u).parent;
  }
  return d;
}

template <typename T> void printNodeDesc(const std::vector<T> &t) {
  std::size_t n = t.size();

  for (std::size_t i = 0; i < n; ++i) {
    int parent = t.at(i).parent, left = t.at(i).left;
    std::cout << "node " << i << ": parent = " << parent
              << ", depth = " << depth(i, t) << ", ";

    if (parent == NIL)
      std::cout << "root, ";
    else if (left == NIL)
      std::cout << "leaf, ";
    else
      std::cout << "internal node, ";

    {
      int c = left;
      std::cout << '[';
      while (c != NIL) {
        std::cout << c;
        c = t.at(c).right;
        if (c != NIL)
          std::cout << ", ";
      }
      std::cout << ']';
    }

    std::cout << std::endl;
  }
}

int main() {
  int n;
  std::cin >> n;
  std::vector<Node<int>> t(n, Node<int>{});

  for (int i = 0; i < n; ++i) {
    int u, k, left;
    std::cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      int c;
      std::cin >> c;
      if (j == 0)
        t.at(u).left = c;
      else
        t.at(left).right = c;
      t.at(c).parent = u;
      left = c;
    }
  }

  printNodeDesc(t);
}



Measured memory_bytes: 3788
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

int main(void)
{
    string s;
    cin >>s;
    vector<int> ans(s.size(), 0);
    int r1 = 0;
    int r2 = 0;
    int contCount = 1;
    int rlIndex = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'R'){
            if(i > 0){
                if(s[i-1] == 'L'){
                    contCount = 1;
                    ans[rlIndex] = r1;
                    ans[rlIndex+1] = r2;
                    r1 = 0;
                    r2 = 0;
                }else{
                    contCount++;
                }
            }
            if(contCount % 2){
                r1++;
            }else{
                r2++;
            }
        }
        if(s[i] == 'L'){
            if(s[i-1] == 'R'){
                contCount = 1;
                rlIndex = i-1;
            }else{
                contCount++;
            }
            if(contCount % 2){
                r2++;

            }else{
                r1++;

            }

            if(i == s.size()-1){
                ans[rlIndex] = r1;
                ans[rlIndex+1] = r2;
            }
        }
    }

    bool first = true;
    for(int i = 0; i < ans.size(); i++){
        if(first){
            printf("%d", ans[i]);
            first = false;
        }else{
            printf(" %d", ans[i]);
        }
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

A, B = map(int, input().split())

# print(A)
# print(B)

# 紙に書かれたことを守って, E869120 君と square1001 君両方が, 
# 食べたい数のケーキを取ることができるならば Yay!, そうでなければ :( と出力しなさい.

if A <= 8 and B <= 8:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 2940
def bellman_ford(s, n, G):
    d = [float('inf')]*n
    d[s] = 0
    for i in range(n):
        update = False
        for x, y, z in G:
            if d[y] > d[x] + z:
                d[y] = d[x] + z
                update = True
        if not update:
            break
        if i == n - 1:
            return None
    return d

def main():
    n, m, p = map(int, input().split())
    G = []
    U = [[] for _ in range(n)]
    V = [[] for _ in range(n)]
    dic = {}
    for _ in range(m):
        a, b, c = map(int, input().split())
        if (a-1, b-1) in dic:
            if dic[(a-1, b-1)] > -c+p:
                dic[(a-1, b-1)] = -c+p
        else:
            dic[(a-1, b-1)] = -c+p
    for v in dic.keys():
        G.append([v[0], v[1], dic[v]])
        U[v[1]].append(v[0])
        V[v[0]].append(v[1])
    st1 = set()
    st1.add(n-1)
    q = [n-1]
    while len(q) > 0:
        t = q.pop(-1)
        for v in U[t]:
            if not v in st1:
                q.append(v)
                st1.add(v)
    st2 = set()
    st2.add(0)
    q = [0]
    while len(q) > 0:
        t = q.pop(-1)
        for v in V[t]:
            if not v in st2:
                q.append(v)
                st2.add(v)
    st = st1 & st2
    eg = []
    for v in G:
        if v[0] in st and v[1] in st:
            eg.append(v)
    ans = bellman_ford(0, n, eg)
    if ans is None:
        print(-1)
    else:
        print(max(0, -ans[n-1]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 5560
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+5;
int n;
int A[M],tmp[M];
int C[M];
void add(int x,int d){
	for(;x;x^=x&-x)C[x]=max(C[x],d);
}
int sum(int x){
	int ret=0;
	for(;x<=n;x+=x&-x)ret=max(ret,C[x]);
	return ret;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&A[i]);
		tmp[i]=A[i];
	}
	sort(tmp+1,tmp+1+n);
	int sz=unique(tmp+1,tmp+1+n)-tmp-1;
	for(int i=1;i<=n;i++)A[i]=lower_bound(tmp+1,tmp+1+sz,A[i])-tmp;
	int ans=0;
	for(int i=1;i<=n;i++){
		int ret=sum(A[i])+1;
		ans=max(ans,ret);
		add(A[i],ret);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string t;
int a[4005],s[5][4005],u[5];
 int main(){
 	int n;
 	cin>>n>>t;
 	for(int i=1;i<=n;i++)
 	{
 		if(t[i-1]=='R') a[i]=0;
 		if(t[i-1]=='G') a[i]=1;
 		if(t[i-1]=='B') a[i]=2;
	 }
	 for(int i=1;i<=n;i++)
	   {
	   	 for(int j=0;j<3;j++)s[j][i]=s[j][i-1];
	   	 s[a[i]][i]=s[a[i]][i-1]+1;
	   }
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]==a[j])continue;
			memset(u,0,sizeof(u));
			u[a[i]]=1;u[a[j]]=1;
			int x;
			for(int k=0;k<3;k++)
			   if(u[k]==0)x=k;
			ans+=s[x][n]-s[x][j];
			if(j-i+j<=n&&a[j-i+j]==x)ans--;
		}
	}
 cout<<ans;
return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <stack>
using namespace std;
typedef long long int ll;

int main(){
	int n,c,k; cin >> n >> c >> k;
	vector<int> t(n);
	for(int i=0;i<n;i++){
		cin >> t[i];
	}
	sort(t.begin(),t.end());
	int ans=0;
	for(int i=0;i<n;i++){
		int cp=t[i];
		int cnt=0;
		while(cp+k>=t[i]&&cnt<c&&i<n){
			cnt++;
			i++;
		}
		i--;
		ans++;
	}
	cout << ans << endl;
}

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


int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    vector<int> q(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n;i++){
        cin>>q[i];
    }
    vector<int> r(n);
    for(int i=0;i<n;i++){
        r[i]=i+1;
    }
    int a,b;
    int count=1;
    do{
        int ca=0,cb=0;
        for(int i=0;i<n;i++){
            if(p[i]==r[i])ca++;
            if(q[i]==r[i])cb++;
            else if(p[i]!=r[i] && q[i]!=r[i]) break;
        }
        if(ca==n) a=count;
        if(cb==n) b=count;
        count++;
    }while(next_permutation(r.begin(),r.end()));
    cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#create date: 2020-08-02 21:01

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, d = na()
    ans = 0
    for i in range(n):
        x, y = na()
        if x**2 + y**2 <= d**2:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 68436
// Aizu Vol-2 0278: Admission Fee
// 2017.8.6

#include <stdio.h>

int main()
{
	int N, x, y, b, p, k, sm;

	scanf("%d", &N);
	while (N-- > 0) {
		scanf("%d%d%d%d", &x, &y, &b, &p);
		if ((x % 50) || (y % 50)) while (1);
#if 0
		k = ((x*5 + y*2) * 4) / 5;
		if ((sm = x*b + y*p) > k) {
			sm = k, b -= 5, p -= 2;
			if (b > 0) sm += (x*b*4) / 5;
			if (p > 0) sm += (y*p*4) / 5;
		}
#else
		sm = x*b + y*p;
		if (b < 5) b = 5;
		if (p < 2) p = 2;
		k = ((x * b + y * p) * 4) / 5;
		if (sm > k) sm = k;
#endif
		printf("%d\n", sm);
	}
	return 0;
}

Measured memory_bytes: 600
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    h=list(map(int,readline().split()))
    ans=0
    while True:
        flag=True
        flag2=True
        for i in range(n):
            if h[i]>0:
                h[i]-=1
                flag=False
                flag2=False
                if i==n-1:
                    ans+=1
            else:
                if flag2==False:
                    flag2=True
                    ans+=1
        if flag: break

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
//template <typename... T> void read(T& ... t){ ((cin >> t), ...); }
//template <typename... T> void write(T ... t){ ((cout << t), ...); }
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define space ' '
using LL = long long;
using pii = pair<int,int>;
const int INF = 2e9;
const int NN = 2e3;
const int MOD = 998244353;
namespace Mm{
	inline int mul(const LL &x, const LL &y) { return (x*y)%MOD; }
	inline int add(const LL &x, const LL &y) { return (x+y)%MOD; }
	inline int power(const LL &x, const LL &n){ if(n == 0) return 1; int y=power(x, n>>1); y=mul(y,y); return (n&1)?mul(y,x):y; }
	inline int inv(const LL &x){ return power(x, MOD-2); }
	// int _fact[2*NN] = {0};
	// inline int fact(const int &x){ return (x==0 ? 1 : (_fact[x]!=0 ? _fact[x] : _fact[x]=mul(x, fact(x-1)))); }
	// inline int cnk(const int &n, const int &k){ return (n<k)?0:mul(fact(n),inv(mul(fact(k),fact(n-k)))); }
	int _cnk[2*NN+1][2*NN+1] = {0};
	inline int cnk(const int &n, const int &k){ return (n<k)?0:(k==0)?1:(_cnk[n][k]!=0?_cnk[n][k]:_cnk[n][k]=add(cnk(n-1,k),cnk(n-1,k-1))); }
} using namespace Mm;
int n,k;
int dp[NN+1][NN+1];
int nbPairs[2*NN+1];

#define read(a,b) cin>>a>>b
#define write(a,b) cout<<a<<b

int32_t main(){ FAST;
	read(k,n);
	dp[0][0] = 1;
	for(int i=1; i<=NN; ++i){ // #pairs
		int prefSum = 0;
		for(int j=0; j<=NN; ++j){ // #items to distribute on pairs
			dp[i][j] = add(dp[i-1][j], add(prefSum, prefSum)); // k € [1;j]
			prefSum = add(prefSum, dp[i-1][j]);
		}
	}

	for(int i=1; i<=k; ++i) for(int j=i+1; j<=k; ++j) ++nbPairs[i+j];

	for(int i=2; i<=2*k; ++i){
		int ans = 0;
		int others = k - 2*nbPairs[i];

		if(i&1){
			if(others == 0){
				ans = dp[nbPairs[i]][n];
				write(ans, ln);
				continue;
			}

			for(int giveOthers=0; giveOthers<=n; ++giveOthers){
				int givePairs = n-giveOthers;
				ans = add(ans, mul(dp[nbPairs[i]][givePairs], cnk(others+giveOthers-1, giveOthers)));
			}
		}
		else{
			--others;
			if(others == 0){
				ans = add(dp[nbPairs[i]][n], dp[nbPairs[i]][n-1]);
				write(ans, ln);
				continue;
			}
			
			for(int giveOthers=0; giveOthers<=n; ++giveOthers){
				int givePairs = n-giveOthers;
				ans = add(ans, mul(dp[nbPairs[i]][givePairs], cnk(others+giveOthers-1, giveOthers)));
			}
			for(int giveOthers=0; giveOthers<=n-1; ++giveOthers){
				int givePairs = n-1-giveOthers;
				ans = add(ans, mul(dp[nbPairs[i]][givePairs], cnk(others+giveOthers-1, giveOthers)));
			}
		}

		write(ans, ln);
	}
}

Measured memory_bytes: 78336
#include<iostream>
using namespace std;
int main()
{
    char x;
    cin >> x;
    if(x=='a'||x=='i'||x=='u'||x=='e'||x=='o')
    {
        cout << "vowel" << endl;
    }
    else
    {
        cout << "consonant" << endl;
    }

}


Measured memory_bytes: 256
N, M = [int(x) for x in input().split(' ')]
XP = [int(x) for x in input().split(' ')]
XP.sort()
D = [0] * (len(XP)-1)
for x in range(len(XP)-1):
    d = XP[x+1] - XP[x]
    D[x] = d
D.sort()
s = 0
for i in range(len(D) - N + 1):
    s += D[i]
print(s)

Measured memory_bytes: 13832
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	int ans = 0;
	if(c * 2 <= a + b) {
		ans += 2 * c * min(x,y);
		x -= ans / 2 / c;
		y -= ans / 2 / c;
	}
	if(c * 2 <= a) {
		int tmp = x;
		ans += 2 * c * tmp;
		x -= tmp;
		x = max(x,0);
		y -= tmp;
		y = max(y,0);
	}
	if(c * 2 <= b) {
		int tmp = y;
		ans += 2 * c * tmp;
		x -= tmp;
		x = max(x,0);
		y -= tmp;
		y = max(y,0);
	}

	ans += x * a;
	ans += y * b;

	cout << ans << endl;



}


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

#define  optimize   ios::sync_with_stdio(0); cin.tie(0);
#define PI  acos(-1.0)
#define RESET(a, b) memset(a, b, sizeof(a))
#define pb push_back
int main()
{
     optimize
     int n;
     cin>>n;
     ll a[n+2];
     set<ll>st;
     map<ll,ll>Map;
     for(int i=0;i<n;i++){
        cin>>a[i];
        Map[a[i]]++;
        st.insert(a[i]);
     }
     ll x=0,y=0;
     for(auto it=st.rbegin();it!=st.rend();++it){
          if(Map[*it]>=2){
            x=*it;
            break;
          }
     }
     for(auto it=st.rbegin();it!=st.rend();++it){
        if(*it!=x && Map[*it]>=2){
            y=*it;
            break;
        }
     }
     if(Map[x]>=4) cout<<x*x<<endl;
     else cout<<x*y<<endl;
}


Measured memory_bytes: 15284
#include <iostream>
#include <utility>
#include <string>
#include <map>

using namespace std;

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

  using Restaulants = map<short,short>;

  map<string, Restaulants*> cities;
  Restaulants restaulants;
  
  for (int n=1; n<=N; ++n) {
    string S;
    short P;
    cin >> S >> P;

    if (cities.count(S)==0)
      cities[S] = new Restaulants;
    cities[S]->emplace(P,n);
  }

  for (auto& city : cities) {
    for (auto itr = city.second->rbegin(); itr != city.second->rend(); ++itr) {
      cout << itr->second << endl;
    }
  }

  return 0;
}


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

int dfs(int y, int x, int dy, int dx, vector<vector<int>> const& v) {
    int n = v.size();
    if(y < 0 || n <= y || x < 0 || n <= x || v[y][x] == 0) {
        return 0;
    }
    return dfs(y+dy, x+dx, dy, dx, v) + 1;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<vector<int>> v(n, vector<int>(n));
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                char c; cin >> c;
                v[i][j] = c - '0';
            }
        }
        int res = 0;
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                if(v[i][j] == 1) {
                    res = max(res, dfs(i+1, j, 1, 0, v)+1);
                    res = max(res, dfs(i, j+1, 0, 1, v)+1);
                    res = max(res, dfs(i+1, j+1, 1, 1, v)+1);
                    res = max(res, dfs(i+1, j-1, 1, -1, v)+1);
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3112
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(scanner.nextInt());
        }
        System.out.println(set.size() == n ? "YES" : "NO");
    }
}

Measured memory_bytes: 102388
#include <stdio.h>

int main( void ) 
{
	int n,x;
	int i,j,k;
	int count;
	
	while( 1 ) {
		scanf( "%d%d", &n, &x );
		if( 0==n && 0==x ) { break; }

		count=0;
		for( i=1; i<=n; i++ ) {
			for( j=i+1; j<=n; j++ ) {
				for( k=j+1; k<=n; k++ ) {
					if( x==(i+j+k) ) {
						count++;
					}
				}
			}
		}
		printf( "%d\n", count );
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

constexpr int MAXN = 200000;

int A[MAXN + 2], cnt[MAXN + 2];

int main() {
	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> A[i];
		cnt[A[i]]++;
	}
	ll ans = 0;
	for(int i = 1; i <= N; i++)
		ans += (ll)cnt[i] * (cnt[i] - 1) / 2;
	for(int i = 0; i < N; i++) {
		ll res = ans - (ll)cnt[A[i]] * (cnt[A[i]] - 1) / 2;
		res += (ll)(cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2;
		cout << res << '\n';
	}
}


Measured memory_bytes: 3712