akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n) upper_bound(v.begin(),v.end(),n)-v.begin()
#define mod 1000000007
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
/*bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}*/
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a);
		}
		b>>=1;
		a=(a*a);
	}
	return ans;
}//prefixsums
void frooty()
{
	l n;
	cin>>n;
	string s;
	l ac=0,wa=0,tle=0,re=0;
	for(l i=0;i<n;i++)
	{
		cin>>s;
		if(s=="AC")
		{
			ac++;
		}
		else if(s=="WA")
		{
			wa++;
		}
		else if(s=="TLE")
		{
			tle++;
		}
		else
			re++;
	}
	cout<<"AC x "<<ac<<"\n";
	cout<<"WA x "<<wa<<"\n";
	cout<<"TLE x "<<tle<<"\n";
	cout<<"RE x "<<re<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
//	cin>>q;
	while(q--)
	{
		frooty();
	}
}

Measured memory_bytes: 3668
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int dp[1<<12];
int main(){
	int N,M; cin >> N >> M;
	vector<int> a(M);
	vector<int> bc(M);
	rep(i,M){
		cin >> a[i];
		int b; cin >> b;
		rep(j,b){
			int c; cin >> c;
			c--;
			bc[i] |= 1<<c;
		}
	}
	rep(i,1<<12) dp[i] = INF;
	dp[0] = 0;
	rep(i,M){
		rep(j,1<<N){
			dp[j|bc[i]] = min(dp[j|bc[i]],dp[j]+a[i]);
		}
	}
	if(dp[(1<<N)-1] == INF){
		cout << -1 << endl;
		return 0;
	}
	cout << dp[(1<<N)-1] << endl;
}
   


Measured memory_bytes: 256
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    character(100):: s
    integer(int32):: ans,i,si,osi,dst,inf=1000000000

    read*, s
    ans=inf
    do i=ichar('a'),ichar('z')
        ! print*, '--',char(i)
        dst=0
        osi=0
        do si=1,len_trim(s)
            if (s(si:si) == char(i)) then
                dst=max(dst,si-osi-1)
                osi=si
            end if
        end do
        ! print*, dst,len_trim(s)-osi-1
        dst=max(dst,len_trim(s)-osi)
        osi=inf
        do si=1,len_trim(s)
            if (s(si:si)==char(i)) then
                osi=si
                exit
            end if
        end do
        ! print*, osi-1,dst
        ans=min(ans, max(osi-1,dst))
    end do
    print'(i0)', ans
end program name

Measured memory_bytes: 256
module Program =
  open System

  [<EntryPoint>]
  let main argv = 
    let [| n; x |] = Console.ReadLine().Split([|' '|]) |> Array.map int64

    let rec calc x y =
      if y = 0L then
        0L
      else
        let l1 = (x / y) * y * 3L
        let l2 = calc y (x % y)
        in l1 + l2

    printfn "%d" (calc (n - x) x)

    // exit code
    0


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

long long SUM[1000001];
long long N, M, a[300000], b[300000];
int main() {
	long long c;

	scanf("%d", &N);

	for(int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}

	sort(a, a+N);

	SUM[0] = 0;
	int ai = 0;
	for(int i = 0; i < 1000001; i++) {
		if(i > 0) SUM[i] = SUM[i - 1];
		while(ai < N && i == a[ai])
		{
			SUM[i] += a[ai];
			ai++;
		}
	}

/*
	for(int i = 0; i < 10; i++) {
		printf("%lld ", SUM[i]);
	}
	printf("\n");
*/
	scanf("%d", &M);

	for(int i = 0; i < M; i++) {
		scanf("%d",&b[i]);
	}
	
	for(int i = 0; i < M; i++) {
		cin >> c;
		printf(SUM[b[i]]>=c?"Yes\n":"No\n");
	}

	return 0;
}

Measured memory_bytes: 13728
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))

if __name__ == "__main__":
    n = int(input())
    k = int(input())
    x = int(input())
    y = int(input())

    print(min(k,n)*x + max(0,n-k)*y)
    


Measured memory_bytes: 9144
def merge(a, left, mid, right):
    global count
    l = a[left:mid] + [sentinel]
    r = a[mid:right] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
    count += right - left


def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

sentinel = 1000000001

n = int(input())
a = list(map(int, input().split()))
count = 0
merge_sort(a, 0, len(a))
print(*a)
print(count)

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

int main(){
    int N;cin>>N;
    vector<double> array(N);
    for(int i=0;i<N;i++)cin>>array[i];
    sort(array.begin(),array.end());
    double ans=array[0];
    for(int i=0;i<N;i++){
        ans=(ans+array[i])/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
list = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
	a,b,c,d = [int(j) for j in input().split()]
	list[a-1][b-1][c-1] += d
for i in range(4):
	for j in range(3):
		for k in range(10):
			print(" {0}".format(list[i][j][k]),end='')
		print()
	if i != 3:
		print("####################")

Measured memory_bytes: 7556
#[derive(Default)]
//NOTE
//declare variables to reduce the number of parameters for dp and dfs etc.
struct Solver {}

impl Solver {
    fn solve(&mut self) {
        let stdin = std::io::stdin();
        let mut scn = Scanner {
            stdin: stdin.lock(),
        };
        let mut n: usize = scn.read();
        
        let mut div = 2;
        let mut result = 0;
        loop {
            let mut cnt = 0;
            while n % div == 0 {
                cnt += 1;
                n /= div;
            }

            let mut m = 1;
            while m * (m + 1) <= 2 * cnt {
                m += 1;
            }
            result += (m -1);
            div += 1;
            if div * div > n {
                break;
            }
        }
        if n != 1 {
            result += 1;
        }
        println!("{}", result);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| {
            let mut solver = Solver::default();
            solver.solve()
        })
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: 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
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn 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: 2212
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> R, G, B;
	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		if (c == 'R') R.push_back(i);
		if (c == 'G') G.push_back(i);
		if (c == 'B') B.push_back(i);
	}
	long long ans = 0;
	for (int r : R) {
		for (int g : G) {
			int i = min(r, g);
			int j = max(r, g);
			int k1 = i - (j - i);
			int k2 = j + (j - i);
			int k3 = ((i + j) % 2 == 0 ? (i + j) / 2 : -1);
			ans += B.size();
			if (binary_search(B.begin(), B.end(), k1)) ans--;
			if (binary_search(B.begin(), B.end(), k2)) ans--;
			if (binary_search(B.begin(), B.end(), k3)) ans--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  string s;
  cin >> s;
  if(s=="ABC") cout << "ARC" << endl;
  if(s=="ARC") cout << "ABC" << endl;
}


Measured memory_bytes: 3628
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def main():
    n,m = na()
    if n > m:
        print("safe")
    else:
        print("unsafe")
    return

if __name__ == '__main__':
  main()

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  int n,a,b;
  cin >>n>>a>>b;
  cout << min(a*n,b) << endl;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

char pattern[8][8];

void inline rotate90() {
  char o[8][8];
  for (int j = 0; j < 8; j++)
    for (int i = 0; i < 8; i++)
      o[j][i] = pattern[j][i];
  for (int j = 0; j < 8; j++)
    for (int i = 0; i < 8; i++)
      pattern[j][i] = o[7-i][j];
}

void inline print_pattern() {
  for (int j = 0; j < 8; j++) {
    for (int i = 0; i < 8; i++)
      cout << pattern[j][i];
    cout << endl;
  }
}

int main() {
  for (int j = 0; j < 8; j++)
    for (int i = 0; i < 8; i++)
      cin >> pattern[j][i];
  for (int i = 1; i <= 3; i++) {
    cout << i * 90 << endl;
    rotate90();
    print_pattern();
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
using namespace std;

int main(){
  long long n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  s[k-1] = tolower(s[k-1]);
  cout << s << endl;
  return 0;
}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define line puts("-------");
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int main()
{
    ll n;
    sl(n);
    ll m=1,cnt=1;
    while(m*2<=n)
    {
        cnt++;
        m*=2;
    }
    ll ans=1;
    while(cnt--)
        ans*=2;
    cout<<ans-1;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    while (H != 0 || W !=0) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
}


Measured memory_bytes: 3092
import numpy as np

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

A=[]
for i in range(N):
    A.append(list(input()))

B=[]
for j in range(M):
    B.append(list(input()))

A=np.asarray(A)
B=np.asarray(B)
flg=False

  
for x in range(N-M):
    for y in range(N-M):
        if (A[x:x+M,y:y+M] == B).all():
            flg=True
if flg:
    print("Yes")
else:
    try:
        if (A == B).all():
            print("Yes")
        else:
            print("No")
    except:
        print("No")

Measured memory_bytes: 13044
import sys
input = sys.stdin.buffer.readline

N = int(input())
XY = [list(map(int, input().split())) + [i + 1] for i in range(N)]

dist = []

XY.sort()
for i in range(N - 1):
  dist.append((abs(XY[i][0] - XY[i + 1][0]), (XY[i][2], XY[i + 1][2])))
XY.sort(key = lambda x: x[1])
for i in range(N - 1):
  dist.append((abs(XY[i][1] - XY[i + 1][1]), (XY[i][2], XY[i + 1][2])))
dist.sort()

root = [i for i in range(N + 1)]
comp_size = [1] * (N+1)
 
def root_find(x):
  if x == root[x]:
    return x
  else:
    z = root_find(root[x])
    root[x] = z
    return z

def merge(x, y):
  rx = root_find(x)
  ry = root_find(y)
  sx = comp_size[rx]
  sy = comp_size[ry]
  if rx != ry:
    if sx >= sy:
      root[ry] = rx
      comp_size[rx] = sx + sy
    else:
      root[rx] = ry
      comp_size[ry] = sx + sy
      
answer = 0
for d, (a, b) in dist:
  if root_find(a) != root_find(b):
    merge(a, b)
    answer += d

print(answer)


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

static const int INF = 1e9+7;

int grid[1005][1005];
vector<vector<bool>> visited(1005, vector<bool> (1005, false));
vector<int> dis(1005 * 1005, INF);
int H, W, N;
int dx[4] = { 0, 1, 0, -1 }; // N, E, S, W
int dy[4] = { -1, 0, 1, 0 }; // N, E, S, W

int bfs(int s, int e) {
  // visited, dis 初期化
  rep(i, 0, H) {
    rep(j, 0, W) {
      visited[i][j] = false;
      dis[i * W + j] = INF;
    }
  }

  queue<int> q;
  q.push(s);
  dis[s] = 0;
  while (!q.empty()) {
    int u = q.front(); q.pop();
    int uy = u / W;
    int ux = u % W;
    if (visited[uy][ux]) continue;
    if (u == e) {
      break;
    }
    visited[uy][ux] = true;
    rep(i, 0, 4) {
      int vy = u / W + dy[i];
      int vx = u % W + dx[i];
      int v = vy * W + vx;
      if (0 <= vx && vx < W && 0 <= vy && vy < H) {
        if (grid[vy][vx] != -1 && !visited[vy][vx]) {
          q.push(v);
          dis[v] = min(dis[v], dis[u] + 1);
        }
      }
    }
  }

  return dis[e];
};

int main() {
  cin >> H >> W >> N;
  vector<int> points(N+1, 0);

  char ch;
  int s;
  rep(i, 0, H) {
    rep(j, 0, W) {
      cin >> ch;
      if (ch == 'S') {
        s = i * W + j;
        grid[i][j] = 0;
        points[0] = i * W + j;
      } else if (ch == 'X') {
        grid[i][j] = -1;
      } else if (ch == '.') {
        grid[i][j] = 0;
      } else {
        grid[i][j] = (int) ch - 48;
        points[grid[i][j]] = i * W + j;
      }
    }
  }

  int ans = 0;
  rep(i, 0, N) {
    ans += bfs(points[i], points[i+1]);
  }
  cout << ans << endl;
};



Measured memory_bytes: 10972
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<int> b(n);
   f(i,1,n){
      cin >> b[i];
   }
   vector<int> a(n+10,1e9);
   f(i,1,n){
      a[i] = min(a[i],b[i]);
      a[i+1] = min(a[i+1],b[i]);
   }
   int ans = 0;
   f(i,1,n+1){
      ans += a[i];
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 256
import math
A, B, H, M = map(int, input().split())

th1 = (H + M / 60) / 12 * 2 * math.pi
th2 = M / 60 * 2 * math.pi
x1 = [A * math.cos(th1), A * math.sin(th1)]
x2 = [B * math.cos(th2), B * math.sin(th2)]
d = ((x1[0] - x2[0]) ** 2 + (x1[1] - x2[1]) ** 2) ** 0.5
print(d)

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

const int mod=1000000007;
ll dp[110][10];
int h,w,k;

bool ok(int X) {
  bool tmp=false;
  for (int i=0; i<w-2; i++) {
    int a=(X>>i)&1;
    int b=(X>>(i+1))&1;
    if (a&b) tmp=true;
  }
  return tmp;
}

int main() {
  cin>>h>>w>>k;
  dp[0][0]=1;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      dp[i][j]%=mod;
      for (int bit=0; bit<(1<<(w-1)); bit++) {
        if (ok(bit)) continue;
        if (bit&(1<<j)) dp[i+1][j+1]+=dp[i][j];
        else if ((j>=1)&&(bit&(1<<(j-1)))) dp[i+1][j-1]+=dp[i][j];
        else dp[i+1][j]+=dp[i][j];
      }
    }
  }
  cout<<dp[h][k-1]%mod<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

bool dfs(int from,int now,const vector<vector<int>>&edges, vector<int>&pais) {
	assert(pais[now]==-1);
	for (auto e : edges[now]) {
		if(e==from)continue;
		if (pais[e] == -1) {
			pais[e]=now;
			pais[now]=e;
			return true;
		}
		else {
			int next=pais[e];
			pais[e]=now;
			pais[now]=e;
			pais[next]=-1;
			bool ok=dfs(e,next,edges,pais);
			if(ok)return true;
			else {
				pais[e]=next;
				pais[now]=-1;
				pais[next]=e;
			}
		}
	}
	return false;
}


int main() {
	int N;cin>>N;
	vector<vector<int>>edges(N+1);
	vector<int>pais(N+1,-1);
	int ans=0;
	for (int i = 0; i < N; ++i) {
		int a;cin>>a;
		edges[i+1].push_back(a);
		edges[a].push_back(i+1);
		bool ok=dfs(-1,i+1,edges,pais);
		if(ok)ans++;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3288
#include "bits/stdc++.h"
using namespace std;
int main() {
	string S;
	bool used[26];
	while (cin >> S, S != "#") {
		int N = S.size();
		int bit = 0;
		for (int i = 0; i < N; i++) if (S[i] == 'z') bit |= (1 << i);
		vector<string> ans;
		for (int i = 0; i < (1 << N); i++) {
			if (i&bit) continue;
			memset(used, 0, sizeof(used));
			used[0] = 1;
			bool invalid = 0;
			for (int j = 0; j < N; j++) {
				char ch = S[j];
				if (i&(1 << j)) ch++;
				if (!used[ch - 'a']) {
					used[ch - 'a'] = 1;
					ch--;
				}
				if (ch != S[j]) {
					invalid = 1;
					break;
				}
			}
			if (invalid) continue;
			string T = S;
			for (int j = 0; j < N; j++) {
				if (i&(1 << j)) T[j]++;
			}
			ans.push_back(T);
		}
		sort(ans.begin(), ans.end());
		cout << ans.size() << endl;
		if (ans.size() <= 10) {
			for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
		}
		else {
			for (int i = 0; i < 5; i++) cout << ans[i] << endl;
			for (int i = 0; i < 5; i++) cout << ans[ans.size() - 5 + i] << endl;
		}
	}
}


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

int main() {
    long long N, A, B;
    cin >> N >> A >> B;

    long long ans = N / (A+B) * A;
    long long rem = N % (A+B);

    if (rem > A) cout << ans+A << endl;
    else cout << ans+rem << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void)
{
  long long a,b,c,d,ac,ad,bc,bd,ans;
  cin >> a >> b >> c >> d;
  ac = a * c;
  ad = a * d;
  bc = b * c;
  bd = b * d;
  ans = max({ac,ad,bc,bd});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


lli n,m;
vector<int> vs[100005];


int gone[100005];

void dfs(int no,int &p,int& q,int c){
	gone[no] = c;
	int tc=3-c;
	rep(i,vs[no].size()){
		int to = vs[no][i];
		if(gone[to]){
			if(gone[to]!=tc){
				puts("-1");
				exit(0);
			}
			continue;
		}
		dfs(to,p,q,tc);
	}
	if(c==1)p++;
	else q++;
}


int tn[100005]={};


int dpn=1;
int dp[2][100005]={};

int main(void){
	scanf("%lld%lld",&n,&m);
	rep(i,m){
		int a,b;
		scanf("%d%d",&a,&b); a--; b--;
		vs[a].push_back(b);
		vs[b].push_back(a);
	}
	
	lli ds = 0;
	rep(i,n){
		if(gone[i])continue;
		int p=0,q=0;
		dfs(i,p,q,1);
		ds += abs(p-q);
		tn[abs(p-q)]++;
	}
	
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	rep(i,n+1){
		if(!tn[i])continue;
		//printf("%d : %d\n",i,tn[i]);
		rep(j,n+3){
			if(dp[1 - dpn][j]>=0)dp[dpn][j]=tn[i];
			else if(j<i || dp[dpn][j-i]<=0);
			else{
				dp[dpn][j] = dp[dpn][j-i]-1;
			}
			//printf("dp[%d][%d] :: %d ,, %d %d\n",dpn,j,dp[dpn][j],dp[dpn-1][j],dp[dpn][j-i]);
		}
		dpn = 1 - dpn;
	}
	
	
	lli mt = IINF;
	rep(i,n+3){
		if(dp[1-dpn][i]>=0)mt = min(mt,abs(i-(ds-i)));
	}
	
	//printf("mt %lld\n",mt);
	
	printf("%lld\n",((n+mt)/2)*((n+mt)/2-mt)-m);
	
	
	
		
	return 0;
}

Measured memory_bytes: 10384
#include <iostream>
#include <stdio.h>

#define rep(i,min,sup) for(int i=min;i<sup;i++)
#define per(i,min,sup) for(int i=(sup-1);i>=min;i--)
#define swap(a,b) {a+=b;b=a-b;a-=b;}
#define ll long long

using namespace std;

main(){
  char c[3];
  scanf("%c%c%c",&c[0],&c[1],&c[2]);
  if(c[0]==c[1]&&c[1]==c[2])printf("No");
  else printf("Yes");
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

//typedef uint64_t hash_t;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int HASH_COUNT = 2;
//const hash_t HASH_P = (uint32_t)-13337;
//uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);
//const hash_t HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)};

int main(){
  int n, k;
  fastScan(n);
  fastScan(k);
  vector < int > vec(n + 5, 0);
  for(int i = 1; i <= n + 1; i++){
    vec[i] += vec[i - 1] + i;
    vec[i] %= mod;
  }
  int ans = 0;
  for(int i = k; i <= n + 1; i++){
    int l = vec[i - 1] % mod;
    int r = vec[n] - vec[n - i];
    r %= mod; r += mod; r %= mod;
    int tmp = (r - l + 1) % mod;
    tmp += mod; tmp %= mod;
    ans += tmp; ans %= mod;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 3920
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String agrs[]) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	while(true){
	    int n=Integer.parseInt(br.readLine());

	    if(n==0)
		break;

	    ArrayList<String> list=new ArrayList<>();

	    int max=0;

	    for(int i=0;i<n;i++){
		String str[]=br.readLine().split("");

		StringBuilder sb=new StringBuilder(str[0]);
		for(int j=0;j<str.length;j++){
		    if((str[j].equals("a")||str[j].equals("e")||str[j].equals("i")||str[j].equals("o")||str[j].equals("u"))&&j!=str.length-1){
		        sb.append(str[j+1]);
		    }
		}
		list.add(sb.toString());
		//System.out.println(sb.toString());
		max=Math.max(max,sb.toString().length());
	    }

	    HashSet<String> set=new HashSet<>();
	    int k=1;
	    boolean flag=false;

	    for(;k<=max;k++){
		flag=false;
		
		for(int i=0;i<list.size();i++){
		    String s= (list.get(i).length()<k) ? list.get(i) : list.get(i).substring(0,k);

		    if(set.contains(s)){
			flag=true;
			break;
		    }
		    set.add(s);
		}

		if(!flag){
		    break;
		}
		set.clear();
	    }

	    if(flag)
		System.out.println("-1");
	    else
		System.out.println(k);
	}
    }
}
    



Measured memory_bytes: 36476
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		if(i && s[i]!=s[i-1])
		ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    int r;
    scanf("%d\n",&r);
    if (r<1200){
        printf("ABC\n");
    }
    else{
        if(r<2800){
            printf("ARC\n");
        }
        else{
            printf("AGC\n");
        }
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

int main(){
	int N;
    std::cin >> N;
    int L[11] = {0};
    for(int i=0;i<N;i++){
        std::cin >> L[i+1];
    }
    int m = 0;
    int sum = 0;
    for(int i=1;i<=N;i++){
        if(m<L[i]){
            m = L[i];
        }
        sum += L[i];
    }
    std::cerr << m << "  " << sum << std::endl;
    if(sum-m>m){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

ll a[100000];
ll b[100001]={1};
int n,p;
ll ans;

int main(){
  cin>>n>>p;
  rep(i,n) cin>>a[i];

  rep(i,n)
    for(int j=100000;j-a[i]>=0;j--)
      b[j]+=b[j-a[i]];

  rep(i,100000)
    if(i%2==p) ans+=b[i];

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>   
using namespace std;   
#define nl cout<<"\n";

int main() {   
    ios::sync_with_stdio(0);   
    cin.tie(0);   
   
    #ifndef ONLINE_JUDGE   
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);   
    #endif   
    
	int t;cin>>t;
	std::vector<int> v(4,0);
	while(t--){
		string s1;
		cin>>s1;
		if(s1 == "AC"){v[0]++;}
		if(s1 == "WA"){v[1]++;}
		if(s1 == "TLE"){v[2]++;}
		if(s1 == "RE"){v[3]++;}
	} 
	cout<<"AC x "<<v[0];nl
	cout<<"WA x "<<v[1];nl
	cout<<"TLE x "<<v[2];nl
	cout<<"RE x "<<v[3];



}   
        

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	long double L ;
	cin >> L;
	L=(long double)L;
    long double solution;
	solution = (long double)L*L*L/(long double)27;
	cout << setprecision(20) << solution << endl;;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string n;
	int moto;
	int sum = 0;
	cin >> n;
	moto = atoi(n.c_str());
	for (int i = 0; i < n.size(); ++i)
	{
		sum += n[i] - '0';
	}
	cout << ((moto % sum == 0)?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(1e9 + 7)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

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

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
	
    int n;
    cin >> n;

    vector<int> arr(n);
    rep(i,n) cin >> arr[i];

    // minimum no of increasing sub-sequences
    multiset<int> M;
    rep(i,n) {
    	auto it = M.lower_bound(arr[i]);

    	if(it == M.begin())
    		M.insert(arr[i]);
    	else {
    		it--;
    		M.erase(it);
    		M.insert(arr[i]);
    	}
    }

    cout << sz(M) << '\n';
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  cout<<fixed<<setprecision(10);
  int N;
  cin >> N;
  vector<llong> H(N);
  for(int i=0; i<N; ++i) cin >> H[i];
  string flg="Yes";
  if(N>1){
    for(int i=N-1; i>0; --i){
      if(H[i-1]==H[i]+1) H[i-1] -= 1;
      else if(H[i-1] > H[i]+1){
        flg = "No";
        break;
      }
    }
  }
  cout << flg << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    int n,x;cin>>n;
    vector<pair<int,int>> a;
    for(int i=1;i<=n;i++){
        cin>>x;
        a.pb(mp(x,i));
    }
    sort(all(a));
    for(int i=0;i<n;i++){
        cout<<a[i].ss<<" "/*<<a[i].ff<<"\n"*/;
    }
    return 0;
}

Measured memory_bytes: 1780
use proconio::{input, fastout};
// use proconio::marker::{Chars};
// use proconio::marker::Usize1;
#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        k: usize,
        a: [usize;n],
        b: [usize;m],
    }

    let mut t_a:Vec<usize> = vec![0;n+1];
    let mut t_b:Vec<usize> = vec![0;m+1];
    t_a[1] = a[0];
    t_b[1] = b[0];
    for i in 1..n {
        t_a[i+1] = t_a[i] + a[i];
    }

    for i in 1..m {
        t_b[i+1] = t_b[i] + b[i];
    }

    let mut ans: Vec<usize> = vec![0;1];
    let mut bestj = m;

    for i in 0..n+1 {
        if t_a[i] > k {
            break;
        }
        for j in (0..bestj+1).rev() {
            // println!("i={}", i);
            // println!("j={}", j);
            // println!("t_a[i]+t_b[j]={}", t_a[i]+t_b[j]);
            if t_a[i] + t_b[j] <= k {
                bestj = j;
                ans.push(i+j);    
                break;
            }
        }
    }

    

    let mut max_ans = 0;
    for i in ans {
        max_ans = std::cmp::max(max_ans, i);
        // println!("{}", i);
    }
    
    println!("{}", max_ans);

}


Measured memory_bytes: 12476
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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; }

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
int MAX_N=100000;
int MAX_M=100000;
int MAX_H=1000000000;
int main(){
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    int x,y;
    set<int> s;
    int h[MAX_N],a[MAX_M+5],b[MAX_M+5],save[MAX_N+5]={},compare[MAX_N+5]={};
    rep(i,n){
        cin >> h[i];
    }
    rep(i,m){
        cin >> x >> y;
        if(h[x-1]>h[y-1]) s.insert(y);
        else if(h[x-1]<h[y-1]) s.insert(x);
        else if(h[x-1]==h[y-1]){
            s.insert(x);
            s.insert(y);
        }
    }

    cout << n-s.size() << endl;
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    bool u, l;
    // 上2桁判定
    int twoDigit = (S[0] - '0') * 10 + (S[1] - '0');
    //cout << twoDigit << endl;
    if (twoDigit > 12 || twoDigit == 0) {
        u = false;
    }
    else {
        u = true;
    }
    // 下2桁判定
    int lastTwoDigit = (S[2] - '0') * 10 - (S[3] - '0');
    if (lastTwoDigit > 12 || lastTwoDigit == 0) {
        l = false;
    }
    else {
        l = true;
    }

    if (!u && !l) {
        cout << "NA" << endl;
    }
    // YYMM
    else if (!u && l) {
        cout << "YYMM" << endl;
    }
    // MMYY
    else if (u && !l) {
        cout << "MMYY" << endl;
    }
    // AMBIGUOUS
    else {
        cout << "AMBIGUOUS" << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  fast_io
  int a,b;
  cin>>a>>b;
  cout<<6-(a+b)<<endl;
  return 0;
}

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

int main() {
    vector<int> a(3);
    rep(i,3){
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
    
   
}



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

int main() {
  long k;
  cin >> k;
  long d = 100;
  for (int i = 1; i < 1000000000; i++) {
    d = d * 1.01;
    if (k <= d) {
      cout << i;
      break;
    }
  }
}


Measured memory_bytes: 3636
import itertools


def roll(dice, commands):
    for command in commands:
        if command == 'N':
            dice[0], dice[1], dice[5], dice[4] = dice[1], dice[5], dice[4], dice[0]
        elif command == 'S':
            dice[0], dice[1], dice[5], dice[4] = dice[4], dice[0], dice[1], dice[5]
        elif command == 'W':
            dice[0], dice[3], dice[5], dice[2] = dice[2], dice[0], dice[3], dice[5]
        elif command == 'E':
            dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2], dice[0]

A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(4):
    for j in range(4):
        for commands in itertools.permutations('S' * i + 'W' * j):
            a = A[::]
            roll(a, commands)
            if B == a:
                print('Yes')
                exit()
print('No')

Measured memory_bytes: 6764
import java.io.*;
import java.util.*;


/**
 * AIZU ONLINE JUDGE
 * 0653
 *  2020/5/5
 */
public class Main {


    boolean main() throws IOException {

        Scanner sc = new Scanner(systemin);

        int[] masu = new int[2019 + 1];
        int N = sc.nextInt();
        int[] X = new int[N + 1];
        for(int n = 1; n <= N; n++) {
            X[n] = sc.nextInt();
            masu[X[n]] = 1;
        }
        int M = sc.nextInt();
        for(int m = 0; m < M; m++) {
            int A = sc.nextInt();
            if (X[A] < 2019 && masu[X[A] + 1] == 0) {
                masu[X[A]]--;
                X[A]++;
                masu[X[A]]++;
            }
        }

        for(int n = 1; n <= N; n++) {
            result.printf("%d\n", X[n]);
        }

        sc.close();
        return false;
    }



    PrintStream log;
    PrintStream result = System.out;
    BufferedReader systemin;

    static Main instance = new Main();

    Main() {
        systemin = new BufferedReader(new InputStreamReader(System.in));
        log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    }

    public static void main(String[] args) throws IOException {

        instance.main();
        instance.systemin.close();
    }


}




Measured memory_bytes: 26752
#include <iostream>
using namespace std;
int main(){
  int A,B,C;
  cin>>A;
  if(A>=22){
    cout<<"bust"<<endl;
  }
  else{
    cin>>B;
    A+=B;
    if(A>=22){
      cout<<"bust"<<endl;
    }
    else{
      cin>>C;
      A+=C;
      if(A>=22){
        cout<<"bust"<<endl;
      }
      else cout<<"win"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define FLOOR(x) ((int)floor(((double)x)))
#define CEIL(x) ((int)ceil(((double)x)))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int N;
int B[200010];


int solve(){
	int ans1 = 0, ans2 = 0;
	int b1 = B[N/2], b2 = B[N/2-1];
	rep(i, 0, N) ans1 += abs(B[i]-b1), ans2 += abs(B[i]-b2);
	return min(ans1, ans2);
}


signed main(){
	cin >> N;
	rep(i, 0, N) cin >> B[i], B[i] -= (i+1);

	sort(RNG(B, N));

	cout << solve() << endl;

	return 0;
}

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

int ac[100005];
int main() {
    int n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            ac[i + 1]++;
        }
    }
    for (int i = 1; i < 100005; i++) ac[i] += ac[i - 1];
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << ac[r] - ac[l] << endl;
    }
    return 0;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

using namespace std;

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

	int n, m, x, y;
	cin >> n >> m >> x >> y;

	vector<int> x_v(n);
	rep (i, 0, n)
		cin >> x_v[i];

	vector<int> y_v(m);
	rep (i, 0, m)
		cin >> y_v[i];

	int x_max = *max_element(x_v.begin(), x_v.end());
	int y_min = *min_element(y_v.begin(), y_v.end());

	if (x < y && x_max < y_min && x_max < y && x < y_min)
		cout << "No War" << endl;
	else
		cout << "War" << endl;

	return 0;
}



Measured memory_bytes: 256
import numpy as np
from collections import defaultdict
from math import sqrt


def sieve(x):
    primes = []
    is_prime = np.ones(x + 1, bool)
    is_prime[0] = is_prime[1] = False
    for i in range(x + 1):
        if is_prime[i]:
            primes.append(i)
            is_prime[2*i::i] = False

    return primes


def prime_fact(x):
    mx = int(sqrt(x)) + 5
    primes = sieve(mx)
    pf = defaultdict(int)
    for e in primes:
        while x % e == 0:
            x //= e
            pf[e] += 1

    if x != 1:
        pf[x] += 1

    return pf


n, p = map(int, input().split())

pf = prime_fact(p)
ans = 1
for k, v in pf.items():
    ans *= pow(k, v // n)

print(ans)


Measured memory_bytes: 31012
from sys import stdin

h, n = (int(v) for v in stdin.readline().split())
spells = [tuple(int(v) for v in stdin.readline().split()) for i in range(n)]

# ~ print(spells)

costs = [0]
for i in range(1, h + 1):
    lowest_cost = None
    for damage, cost in spells:
        if damage < i:
            total_cost = cost + costs[i - damage]
        else:
            total_cost = cost
        if lowest_cost is None or total_cost < lowest_cost:
            lowest_cost = total_cost
    costs.append(lowest_cost)

print(costs[h])


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

const int N = 100 + 10;
int n, m, x;
vector<int> v;
set<int> st;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    
     
    cin >> n >> m >> x;
    for (int i = 0; i < m; i++){
      int x;
      cin >> x;
      v.push_back(x);
    }
    int left = 0;
    int right = 0;
    for (int i = 0; i < v.size(); i++)
      left += v[i] < x;
    for (int i = 0; i < v.size(); i++)
      right += v[i] > x;

    cout << min(left, right) << endl;
}

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

signed main() {
  int N,moto=1,hiku=1;
  cin >> N;
  vector<int>vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
    moto *= 3;
    if(vec[i]%2 == 0){
      hiku *= 2;
    }
  }
  cout << moto-hiku << endl;
}


Measured memory_bytes: 3624
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
counter = Counter(a)
sum_res = sum(a)
for _ in range(q):
    before, after = map(int, input().split())
    sum_res -= before * counter[before]
    sum_res += after * counter[before]
    counter[after] += counter[before]
    counter[before] = 0
    print(sum_res)

Measured memory_bytes: 24016