akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if((to_string(i).size())%2==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

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

int main() {
    ll x;
    cin >> x;
    cout << lcm(x, 360LL) / x << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;
int Pow_mod(int x, int pow){
    if(pow==0) return 1;
    int a=Pow_mod(x, pow/2);
    a=a*a;
    if(pow%2==1) a*=x;
    return a;
}
signed main(){
    int n,p; cin>>n>>p;
    vector<int> a(n);
    bool b=false;
    rep(i,n){
        cin>>a.at(i);
        if(a.at(i)%2==1) b=true;
    }
    if(!b){
        if(p==0){
            cout<<Pow_mod(2, n)<<endl;
        }else{
            cout<<0<<endl;
        }
    }else{
        cout<<Pow_mod(2, n-1)<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#define C(x,y) (fct[x]*ufct[y]%TT*ufct[(x)-(y)]%TT)
using namespace std;
const int m=2001,M=4001,MM=8000,TT=1000000007;
int n,cnt[m+5][m+5],F[M+5][M+5];
long long fct[MM+5],ufct[MM+5],ans;
inline char nc(){
	static char buf[100000],*p1,*p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
inline void add(int&x,int y){if((x+=y)>=TT) x-=TT;}
inline long long pow(int x,int y){
	long long ret=1,w=x;
	while(y){
		if(y&1) ret=ret*w%TT;
		if(!(y>>=1)) return ret;
		w=w*w%TT;
	}
}
int main(){
	n=read();
	for (int i=fct[0]=1;i<=MM;i++) fct[i]=fct[i-1]*i%TT;
	ufct[MM]=pow(fct[MM],TT-2);
	for (int i=MM;i;i--) ufct[i-1]=ufct[i]*i%TT;
	for (int i=1;i<=n;i++){
		int x=read(),y=read();
		cnt[x][y]++;F[m-x][m-y]++;
		ans-=C(x+y<<1,x<<1);
	}
	for (int i=1;i<=M;i++)
	for (int j=1;j<=M;j++)
	add(F[i][j],F[i-1][j]),add(F[i][j],F[i][j-1]);
	for (int i=1;i<=m;i++)
	for (int j=1;j<=m;j++) if(cnt[i][j])
	ans+=1ll*cnt[i][j]*F[m+i][m+j]%TT;
	printf("%lld\n",(ans%TT+TT)*(TT+1>>1)%TT);
	return 0;
}

Measured memory_bytes: 78720
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES

#include <cmath>
using namespace std;
#define pi 3.14159265359
int main()
{
    double a,b,x,ha,h,y;
    double unghi;
    cin>>a>>b>>x;
    ha=x/(a*a);
    if(ha>=b/2)
    {
        h=b-ha;
        unghi=90-((180 * atan2(a/2,h)) / acos(-1));
        cout<<fixed<<setprecision(10)<<unghi;
    }
    else
    {
        y=(2*x)/(b*a);
        unghi=(180 * atan2(b,y))    / acos(-1) ;
        cout<<fixed<<setprecision(10)<<unghi;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,count=0;
  scanf("%d",&n);
  int x[101],d;
  for(i=1;i<=100;i++)
    x[i]=0;
  for(i=0;i<n;i++){
    scanf("%d",&d);
    if(x[d]==0){
      count++;
      x[d]=1;
    }
  }
  printf("%d\n",count);
}


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

int main()
{
	long long n,i,sum=0;
	cin>>n;
	long long ar[n];
	for(i=0;i<n;i++)
		cin>>ar[i];
	for(i=1;i<n;i++)
		if(ar[i]<ar[i-1])
		{
		  sum+=ar[i-1]-ar[i];
		  ar[i]=ar[i-1];
		}
	cout<<sum;
  return 0;
}

Measured memory_bytes: 5156
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	char s[1010];
	int n, a, b;
	string str[3] = {"replace", "reverse", "print"};
	cin >> s >> n;
	string s0 = s;
	rep(i,n) {
		char p[110];
		cin >> p >> a >> b;	
		string s1 = p;
		if(!s1.compare(str[0])) {
			char q[1010];
			cin >> q;
			s0.replace(a, b - a + 1, q);
		} else if(!s1.compare(str[1])) {
			string s2 = s0.substr(0, a);
			string s3 = s0.substr(a, b - a + 1);
			string s4 = s0.substr(b + 1);
			string s5;
			for(int j = 0; j < b - a + 1; ++j) {
				s5 += s3.at(b - a - j);
			}
			s0 = s2 + s5 + s4;
		} else if(!s1.compare(str[2])){
			rep2(j, a, b + 1) {
				cout << s0.at(j);
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int> Q;
int a[10010],n;

int P(int x,int y){
	int r=10;
	while(x>=r)r*=10;
	return r*y+x;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<i;j++){
			Q.push(P(a[i],a[j]));
			Q.push(P(a[j],a[i]));
		}
		while(Q.size()>3)Q.pop();
	}
	cout<<Q.top()<<endl;
	return 0;
}

Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

ll dp[5000*5000+1];

int main(){
    int n;
    cin>>n;
    int ga,sa,ba,gb,sb,bb;
    cin>>ga>>sa>>ba>>gb>>sb>>bb;
    int g=gb-ga,s=sb-sa,b=bb-ba;
    for(int i=1;i<=n;i++){
        if(g>0&&ga<=i){
            dp[i]=max(dp[i],dp[i-ga]+g);
        }
        if(s>0&&sa<=i){
            dp[i]=max(dp[i],dp[i-sa]+s);
        }
        if(b>0&&ba<=i){
            dp[i]=max(dp[i],dp[i-ba]+b);
        }
    }
    int m=n+dp[n];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=m;i++){
        if(g<0&&gb<=i){
            dp[i]=max(dp[i],dp[i-gb]-g);
        }
        if(s<0&&sb<=i){
            dp[i]=max(dp[i],dp[i-sb]-s);
        }
        if(b<0&&bb<=i){
            dp[i]=max(dp[i],dp[i-bb]-b);
        }
    }
    cout<<m+dp[m]<<endl;
}

Measured memory_bytes: 195584
class SegmentTree():
    def __init__(self, n):
        self.n = n
        self.dp = [0 for _ in range(2 * n)]
        
    def update(self, k, a):
        k += self.n
        self.dp[k] = a
        while (k > 1):
            self.dp[k >> 1] = max(self.dp[k], self.dp[k ^ 1])
            k >>= 1
        
    def query(self, l, r):
        res = 0
        l, r = l + self.n, r + self.n
        while l < r:
            if l & 1:
                res = max(res, self.dp[l])
                l += 1
            if r & 1:
                res = max(res, self.dp[r - 1])
            l, r = l >> 1, r >> 1
        return res
    
    
n, k = map(int, input().split())
A = []
for _ in range(n):
    a = int(input())
    A.append(a)
num = max(A) + k + 1

st = SegmentTree(num)
for i in range(n):
    x = A[i]
    l = max(x - k, 0)
    r = min(x + k + 1, num)
    now = st.query(l, r) + 1
    st.update(x, now)
print(max(st.dp))    

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

int N;
int A[200];

void solve() {
  int ans = 0;
  bool ng = false;
  while (1) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2) {
        ng = true;
      } else {
        A[i] /= 2;
      }
    }
    if (ng) break;
    ans++;
  }
  cout << ans << endl;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  solve();
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let mut xy = vec![];
    for _ in 0..n {
        let x: i64 = sc.read();
        let y: i64 = sc.read();
        xy.push((x, y));
    }

    if xy.iter().any(|&(x, y)| (x + y).abs() % 2 == 0)
        && xy.iter().any(|&(x, y)| (x + y).abs() % 2 == 1)
    {
        println!("-1");
        return;
    }

    let mut arms: Vec<i64> = (0..31).rev().map(|i| 1 << i).collect::<Vec<_>>();
    if (xy[0].0 + xy[0].1).abs() % 2 == 0 {
        arms.push(1);
    }

    let arms_sum = arms.iter().sum::<i64>();

    println!("{}", arms.len());
    for (i, &arm) in arms.iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", arm);
    }
    println!();

    for &(x, y) in xy.iter() {
        let p = x + y;
        let mut cur_sum = arms_sum;
        let mut x_dir = vec![];
        for &arm in arms.iter() {
            if cur_sum - 2 * arm >= p {
                cur_sum -= 2 * arm;
                x_dir.push(-1);
            } else {
                x_dir.push(1);
            }
        }

        let q = x - y;
        let mut cur_sum = arms_sum;
        let mut y_dir = vec![];
        for &arm in arms.iter() {
            if cur_sum - 2 * arm >= q {
                cur_sum -= 2 * arm;
                y_dir.push(-1);
            } else {
                y_dir.push(1);
            }
        }

        let n = x_dir.len();
        for i in 0..n {
            match (x_dir[i], y_dir[i]) {
                (1, 1) => print!("R"),
                (1, -1) => print!("U"),
                (-1, 1) => print!("D"),
                (-1, -1) => print!("L"),
                _ => unreachable!(),
            }
        }
        println!();
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
int main()
{
  int n;
  cin>>n;
  int k;
  cin>>k;
  int h[n];
  int i=0;
   int dp[n];
  while(i<n)
  {
    cin>>h[i];
    dp[i]=INF;
    i++;
  }
  i=0;
  dp[0]=0;
  for(;i<n;i++)
  {
    int j=1;
    while(j<=k && i+j<n)
    {
      dp[i+j]=min(dp[i+j],abs(h[i]-h[i+j])+dp[i]);
      j++;
    }
    //cout<<dp[i]<<" ";
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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(){
    int a,b,c;
    cin >> a >> b >> c;
    string ans = "No";
    if(a == b){
        if(a != c){
            ans = "Yes";
        }
    }
    if(c == b){
        if(a != c){
            ans = "Yes";
        }
    }
    if(a == c){
        if(a != b){
            ans = "Yes";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m,k=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
mnt=0
i=1
mb=0
j=1
while mnt<=k and 0<i<n+1:
    mnt+=a[i-1]
    i+=1
if mnt>k:
    i-=2
    mnt-=a[i]
else:
    i-=1

while i>=0:

    while mnt<=k and j<m+1:
        if j==0:
            j=1
        mnt+=b[j-1]
        j+=1
    if mnt>k:
        j-=1
        mnt-=b[j-1]
    
        
    if i+j-1>mb:
        mb=i+j-1
    
    mnt-=a[i-1]
    i-=1            
            
            
print(mb)


Measured memory_bytes: 40772
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);  cin.tie(0) ; cout.tie(0);
#define debug(x) cout << #x << " : " << x << endl;
#define pi 3.14159265359
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
using ll = long long int;
using db = double;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
const int MOD = 1e9+9;
const ll M = 1000000000000001;
vl range;


void solve()
{
    ll n, start , end;
     cin >> n;
     
     string s;
    ll dup = n;
     while(dup > 0)
     {
         int r = dup % 26;
         if (r == 0)
         {
            s = 'z' + s;
            dup = (dup / 26) -1;
         }
         else
         {
             s = char(96 + r) + s;
             dup = dup / 26;
         }
     }
     cout << s<< endl;
}

int main()
{
//  #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout);
//  #endif
    fastio;
    int t = 1;
    while(t--)
       solve();
    return 0;
}

Measured memory_bytes: 3652
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	[h, a] <- readToListN 2 <$> BS.getLine
	print $ (h + a - 1) `div` a


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

using namespace std;

int main() {
  int a, b, c, x, y, p1, p2, p3;
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

  int mi = min(x, y), ma = max(x, y);
  p1 = a * x + b * y;
  p2 = mi * 2 * c + (ma - mi) * (ma == x ? a : b);
  p3 = ma * 2 * c;
  printf("%d\n", min(p1, min(p2, p3)));
  return 0;
}


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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(b<=x){
    cout << "delicious" << endl;
    return 0;
  }
  else if(-a+b <= x){
    cout << "safe" << endl;
  }
  else{
    cout << "dangerous" << endl;
  }
}

Measured memory_bytes: 3620
# Author: cr4zjh0bp
# Created: Sat Mar 28 10:36:41 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b, c = na()

print("YES" if b - a == c - b else "NO")

Measured memory_bytes: 3064
X,Y,A,B,C=list(map(int,input().split()))
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)

pqr=sorted(p[:X]+q[:Y]+r,reverse=True)

print(sum(pqr[:(X+Y)]))

Measured memory_bytes: 106000
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;#include <stdio.h>
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int N;
	cin >> N;


	cout << (N - 2) * 180;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e5;
const char newl = '\n';

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

  ll n, q, b, c, num, sum=0;
  vl cnt(MAX+1);
  cin >> n;
  while(n --> 0) {cin >> num; cnt[num]++; sum+=num;}
  
  cin >> q;
  while(q --> 0) {
    cin >> b >> c;
    sum += cnt[b]*(c-b);
    cout << sum << newl;
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;


int n;
string s, t;


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

    cin>>s>>t;
    n = s.size();
    vector<vector<int>> ms(26), mt(26);
    for (int i=0; i<n; i++) {
	ms[s[i]-'a'].push_back(i);
	mt[t[i]-'a'].push_back(i);
    }

    // Each char will be of form:
    // 1. A->X
    // 2. B->Y and Y->B (cycle)

    // AABYAY
    // XXYBXB

    sort(ms.begin(),ms.end());
    sort(mt.begin(),mt.end());

    cout<<(ms==mt ? "Yes\n" : "No\n");
    
    return 0;
}


Measured memory_bytes: 6000
n, a, b = map(int, input().split())
dp = [0] + [2 ** 60] * n
p = list(map(int, input().split()))
for i in range(n):
	dp[i + 1] = dp[0]
	dp[0] += a
	for j in range(i):
		if p[j] < p[i]: dp[i + 1] = min(dp[i + 1], dp[j + 1])
		dp[j + 1] += [b, a][p[j] < p[i]]
print(min(dp))

Measured memory_bytes: 42476
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void inline swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void inline swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class B {
	string s;
public:
	B()
	{
		cin >> s;
	}
	void solve()
	{
		for (int i = 0; i < SZ(s); i += 2)
			cout << s[i];
		cout << endl;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  bool flag=false;
  rep(i,n+1){
    if(n-4*i<0) break;
    flag|=((n-4*i)%7==0);
  }

  Yes(flag);


}

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

using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b==c)cout<<"Yes"<<endl;
  else if(a+c==b)cout<<"Yes"<<endl;
  else if(c+b==a)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
  }


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

/**
 * \\///\_/\/\\\\/_/\\///
 * 26
 * 4 4 2 1 19
 * 
 * \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\
 * 35
 * 5 4 2 1 19 9
 *
 */

int main(int argc, char **argv){

    std::vector<char> C;
    char buf;
    while(std::cin >> buf){
	C.push_back(buf);
    }


    std::stack<int> L;
    std::stack<std::pair<int,int>> D;
    int all_sum = 0;
    for(int i = 0; i < C.size(); i++){
	char c = C.at(i);
	if(c == '\\'){
	    L.push(i);
	}else if(c == '/' && L.empty() == false){
	    int left = L.top(); L.pop();
	    int s = i - left;
	    all_sum += s;

	    while(D.empty() == false && D.top().first > left){
		s += D.top().second;
		D.pop();
	    }
	    D.push(std::make_pair(left, s));
	}
    }

    std::stack<std::pair<int,int>> D2;
    while(D.empty() == false){
	D2.push(D.top());
	D.pop();
    }
    
    std::cout << all_sum << std::endl;
    std::cout << D2.size();
    while(D2.empty() == false){
	std::cout << " " << D2.top().second;
	D2.pop();
    }
    std::cout << std::endl;
    
}



Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 1000000007
#define PI 3.1415926535897932384
#define F first
#define S second
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair

void tree(ll t[],ll s, ll e, ll a[], ll node){
    if(s==e){
        t[node]=a[s];
    }
    else{
        ll mid=(s+e)/2;
        tree(t,s,mid,a,2*node);
        tree(t,mid+1,e,a,2*node+1);
        t[node]=t[2*node]+t[2*node+1];
    }
    return;
    
}

int query(ll t[],ll s, ll e,ll l, ll r,ll node){
    
    if(l>e || r<s) return 0;
    if(l<=s and e<=r) return t[node];
    
        ll mid=(s+e)/2;
        return query(t,s,mid,l,r,2*node)+
        query(t,mid+1,e,l,r,2*node+1);

}

void update(ll tree[],int node, int start, int end, int idx, int val,ll A[])
{
    if(start == end)
    {
        A[idx] += val;
        tree[node] += val;
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx and idx <= mid) update(tree,2*node, start, mid, idx, val,A);
        else update(tree,2*node+1, mid+1, end, idx, val,A);
        tree[node] = tree[2*node] + tree[2*node+1];
    }
}


void solve(){ 
    ll n;
    cin>>n;
    ll a[n+1];
    fr(n+1) a[i]=0;
    rep(i,1,101){
        rep(j,1,101){
            rep(k,1,101){
                ll g=(i+j)*(i+j)+(i+k)*(i+k)+(k+j)*(k+j);
                g/=2;

                if(g<=n){
                    //cout<<g<<" "<<i<<" "<<j<<" "<<k<<endl;;
                    a[g]++;
                }
            }
        }
    }
    rep(i,1,n+1) cout<<a[i]<<endl;

}
int main()
{   FAST;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout); 
#endif
   
    ll test;
    test=1;
   
    //cin>>test;
    while(test--)
    {
        solve();
    }
     cerr<<endl<<"maut : "<<elasped_time<<endl;
    return 0;
}
 
    



Measured memory_bytes: 3864
from collections import *

N=int(input())
S=input()
c=Counter(S)

ans=c['R']*c['G']*c['B']

for i in range(N):
  for j in range(i+1,N):
    if S[i]==S[j]:
      continue
    k=j*2-i
    if k>=N or S[k]==S[i] or S[k]==S[j]:
      continue
    ans-=1

print(ans)


Measured memory_bytes: 74004
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 512;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int N;
char maze[MAX][MAX], nmaze[MAX][MAX];
bool match[MAX][MAX];

void solve(void){
    cin >> N;
    rep(N, i) scanf("%s\n", maze[i]);
    ll ans = 0LL;
    rep (N, A) {
        bool f = true;
        rep(N, y) {
            rep(N, x) {
                f = f && (maze[x][y] == maze[y][x]);
                nmaze[(x+1)%N][y] = maze[x][y];
            }
        }
        rep(N, y) {
            rep(N, x) {
                maze[x][y] = nmaze[x][y];
            }
        }
        if (f) ans ++;
    }
    cout << ans * N << endl;
}

int main(void){
  solve();
  return 0;
}


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

int main() {
  uint64_t N;
  cin >> N;
  if(N % 2 == 1){
    cout << 0 << endl;
    return 0;
  }

  // 5で割れる回数
  N /= 2;
  uint64_t ans = 0;
  while(0 != N){
    N /= 5;
    ans += N;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <map>
#include <vector>
#include <climits>
#include <cmath>
#include <stdlib.h>


using namespace std;

long long p = 1e9 + 7;
long long const max_n = 10001;
long long fact[max_n];
long long ifact[max_n];

long long mod(long long x)
{
    x %= p; 
    if (x < 0) x += p; 
    return x;
}

long long inverse(long long x)
{
    x = mod(x);
    if (x == 1) return x;
    return mod(1LL * (-p/x) * inverse(p%x));
}

long long ncr(long n, long r)
{
    long long ret = (ifact[n - r] * ifact[r]) % p;
    ret = (ret * fact[n]) % p;
    return ret;
}


int main()
{
    int s; cin >> s;
    fact[0] = 1;
    for (int i = 1; i < max_n; i++)
    {
        fact[i] = mod(fact[i - 1] * i); 
    }
    ifact[0] = 1;
    for (int i = 1; i < max_n; i++)
    {
        ifact[i] = mod(ifact[i - 1] * inverse(i)); 
    }
    long long ans = 0; 
    for (int i = 1; 3 * i <= s; i++)
    {
        ans = mod(ans + ncr(s - 2 * i - 1, i - 1)); 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3784
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)

int a[101010];

int n;

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

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[a[i] - 1] == i + 1)ans++;
	}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

#define YES printf("Yes\n")
#define NO printf("No\n")

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    char s[105][105];
    ll h,w;
    scanf("%lld%lld",&h,&w);
    ll cnt[26]={};
    rep(i,0,h){
        scanf("%s",s[i]);
        rep(j,0,w){
            cnt[(ll)s[i][j]-97]++;
        }
    }

    ll a=0,b=0,c=0;
    rep(i,0,26){
        if(cnt[i]%4==1){a++;}
        if(cnt[i]%4==2){b++;}
        if(cnt[i]%4==3){c++;}
    }
    
    if(h%2==0&&w%2==0){
        if(a==0&&b==0&&c==0){
            YES;
        }else{
            NO;
        }
    }


    if(h*w%2==1){
        
        if(a==1){
            if(c!=0){
                NO;
            }else{
                if( b <= h/2+w/2 ){
                    YES;
                }else{
                    NO;
                }
            }
        }else{
            if(c!=1){
                NO;
            }else{
                if( b-1 > h/2+w/2 ){
                    YES;
                }else{
                    NO;
                }
            }
        }
    }


    if( h*w%2==0  && (h+w)%2==1 ){
        // printf("b%lld\n",b);
        if(a!=0 || c!=0){
            NO;
        }else{
            if(b > ( (h%2) ? (w/2) : (h/2) ) ){
                NO;
            }else{
                YES;
            }
        }
    }
    // rep(i,0,26){
    //     printf("%c%lld ",(char)i+97,cnt[i]);
    // }
    // printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,m;
	cin>>n>>m;
	if(n==1||m==1) cout<<1<<endl;
	else{
		ll ans=(n*m+1)/2;
	    cout<<ans<<endl;
	}
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

P ass[200009]; // first : 締め切り時刻
			   // second : かかる時間

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

	int N; cin >> N;
	for (int i = 0; i < N; i++) cin >> ass[i].second >> ass[i].first;
	sort(ass, ass + N);

	ll now = 0;
	bool flag = true;
	for (int i = 0; i < N && flag; i++) {
		now += ass[i].second;
		if (now > ass[i].first) flag = false;
	}

	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1792
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N,W = map(int,input().split())
    wv = [list(map(int,input().split())) for _ in range(N)]
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    
    for w in range(1,W+1):
        for i in range(1,N+1):
            if w - wv[i-1][0] >= 0:
                dp[i][w] = max(dp[i-1][w],dp[i-1][w-wv[i-1][0]] + wv[i-1][1])
            else:
                dp[i][w] = dp[i-1][w]
    print(dp[-1][-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 152380
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;
using ll = long long int;
int main() {
	ll N;
	array<ll, 100001> A;
	cin >> N;
	for (ll i = 0; i < N; i++) cin >> A[i];
	A[N] = 0;
	sort(A.begin(), A.begin() + N + 1);
	ll sum = 0;
	for (ll i = 1; i <= N; i++) {
		if (A[i] != A[i - 1]) {
			cerr << N + 1 - i << " ga " << A[i] - A[i - 1] << " ko" << endl;
			if ((A[i] - A[i - 1]) % 2 == 1) sum ^= (N + 1 - i);
		}
	}
	cout << (sum != 0 ? "first" : "second") << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <set>

int main(void)
{
	int ans = 0;
	int n, q;
	std::cin >> n;
	std::vector<int> arr(n);
	for (auto & a : arr)
		std::cin >> a;
	std::cin >> q;
	for (size_t i = 0; i < q; i++)
	{
		int in = 0;
		std::cin >> in;
		int left = 0, mid = n / 2, right = n;
		while (left != right)
		{
			if (arr[mid] == in) {
				ans++;
				break;
			}
			if (in < arr[mid])	right = mid;
			else				left = mid+1;

			mid = (right + left) / 2;
		}
	}

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

Measured memory_bytes: 3056
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
i = 0
count = 0
while i <= a
  j = 0
  while j <= b
    k = 0
    while k <= c
      if i * 500 + j * 100 + k * 50 == x
        count += 1
      end
      k += 1
    end
    j += 1
  end
  i += 1
end
puts count

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

typedef long long ll;

const int maxn = 1e5;
int val[maxn];
int main(){
	std::ios::sync_with_stdio(false);

	ll n;
	std::cin >> n;

	for(ll i = 0; i < n; i++){
		std::cin >> val[i];
	}
	std::sort(val, val + n);

	ll a = 0;
	ll b = 0;

	for(ll i = n - 1; i >= 0; i--){
		if(val[i] == val[i - 1]){
			if(val[i] > a){
				b = a;
				a = val[i];
			} else if(val[i] > b){
				b = val[i];
			}

			i--;
		}
	}

	std::cout << a * b << '\n';
}

Measured memory_bytes: 640
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

int n,x,y;
int dist[2005];
int ans[2005];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>n>>x>>y;
    REP(i,1,n){
    	REP(j,1,n)dist[j] = OO;
    	dist[i] = 0;
    	REP(j,2,n)dist[j] = min(dist[j], dist[j-1]+1);
    	REV(j,n-1,1)dist[j] = min(dist[j], dist[j+1]+1);
    	dist[x] = min(dist[x], dist[y]+1);
    	dist[y] = min(dist[y], dist[x]+1);
    	REP(j,2,n)dist[j] = min(dist[j], dist[j-1]+1);
    	REV(j,n-1,1)dist[j] = min(dist[j], dist[j+1]+1);
    	REP(j,1,n){
    		ans[dist[j]]++;
    	}
    }

    REP(i,1,n-1)cout << ans[i]/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let ps: Vec<_> = (0..n).map(|_| {
        let x: f64 = sc.cin();
        let y: f64 = sc.cin();
        (x, y)
    }).collect();

    let mut x = ps[0].0;
    let mut y = ps[0].1;

    let mut r = 0.0;
    let mut eps = 1.0;
    for _ in 0..100000 {
        r = 0.0;
        let mut the_index = 0;
        for i in 0..n {
            let d = (ps[i].0 - x).powi(2) + (ps[i].1 - y).powi(2);
            if d > r {
                r = d;
                the_index = i;
            }
        }
        x += (ps[the_index].0 - x) * eps;
        y += (ps[the_index].1 - y) * eps;
        eps *= 0.999;
    }
    put!(r.sqrt());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


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

int main()
{
    int n,k,q,a;
    cin>>n>>k>>q;

    vector<int> v(n+1,k);
    for(int i=1;i<=q;i++)
    {
        cin>>a;
        v[a]++;
    }
    for(int i=1;i<=n;i++)
    {

        if(v[i]<=q)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    lint a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int result =0;
		int A[] = new int[3];
		for (int i=0;i<3;i++) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		result +=Math.abs(A[1]-A[0]);
		result +=Math.abs(A[1]-A[2]);
		System.out.println(result);
	}
}

Measured memory_bytes: 23124
import keyword
from collections import deque

N, M = map(int, input().split())

G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

visited = [False] * N
par = [0] * N
visited[0] = True
d = deque(G[0])
for i in G[0]:
    visited[i] = True
    par[i] = 0
cur = 0
while d:
    cur = d.popleft()
    for i in G[cur]:
        if not visited[i]:
            visited[i] = True
            par[i] = cur
            d.append(i)

print('Yes')
for i in range(1, N):
    print(par[i] + 1)


Measured memory_bytes: 34908
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <random>
#include <chrono>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<ll> v = {1,255,43435,6347715,866251507,114429029715,14877590196755,1919209135381395,246614610741341843};

int main() {
    string X = "FESTIVAL";
    ll k;
    cin >> k;
    string s;
    vector<ll> ans(9);
    for (int i = 8; i >= 0; --i) {
        ans[i] = k/v[i];
        k %= v[i];
    }
    for (int i = 0; i < 9; ++i) {
        for (int j = 0; j < 7; ++j) {
            s += string(1<<i, X[j]);
        }
        s += string(ans[i], 'L');
        if(accumulate(ans.begin()+i+1,ans.end(), 0LL) == 0) break;
    }
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 256
//Solution by Zhusupov Nurlan
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef map<string , int> MSI;
typedef vector<int> VI;
typedef pair<int, int> PII;

#define endl '\n'
#define pb(x) push_back(x)
#define sqr(x) ((x) * (x))
#define F first
#define S second
#define SZ(t) ((int) t.size())
#define len(t) ((int) t.length())
#define base LL(1e9 + 7)
#define fname ""
#define sz 1000 * 1000
#define EPS (1e-8)
#define INF ((int)1e9 + 9)
#define mp make_pair

LL n, a[sz];

LL sign(LL x) {
  if (x < 0) return -1;
  if (x > 0) return 1;
  return 0;
}

LL calc() {
  LL res = 0, last = 0, s = 0;

  for (int i = 1; i <= n; i++) {
    s += a[i];
    if (sign(s) != sign(last) && sign(s) != 0) {
      last = s;
    } else {
      res += abs(s) + 1;
      last = -sign(last);
      s = last;
    }
  }

  return res;
}

int main()
{
//    freopen(fname"in", "r", stdin);
//    freopen(fname"out", "w", stdout);

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  LL x, y;
  cin >> x >> y;
  if (abs(x - y) > 1) cout << "Alice";
  else
      cout << "Brown";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

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

Int n, k, a[100001], b[100001];
P p[100001];

int main(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		p[i] = (P(a[i], b[i]));
	}
	sort(p, p+n);
	for(int i = 0; i < n; i++){
		k -= p[i].second;
		if(k <= 0){
			cout << p[i].first << endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3328