akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N, AC, WA, TLE, RE;
	AC = 0; WA = 0; TLE = 0; RE = 0;
	cin >> N;
	for ( int i = 0; i < N; i++){
		string str;
		cin >> str;
		if (str == "AC"){
			AC++;
		}else if (str == "WA"){
			WA++;
		}else if (str == "TLE"){
			TLE++;
		}else if (str == "RE"){
			RE++;
		}else cout << "error";
	}
	cout << "AC x " << AC << endl;
	cout << "WA x " << WA << endl;
	cout << "TLE x " << TLE << endl;
	cout << "RE x " << RE << endl;
}


Measured memory_bytes: 3628
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut scan = Scanner::new(cin);

    let n = scan.read::<i64>();
    let h = scan.read::<i64>();
    let w = scan.read::<i64>();
    println!("{}", (n - h + 1) * (n - w + 1));
}

// region template
#[allow(dead_code)]
fn uz(i: i32) -> usize { i as usize }

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: i32) -> Vec<T> {
        let mut ret = vec![];
        for _ in 0..n { ret.push(self.read::<T>()) }
        ret
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
// Welcome to my source code!

#define MAX 10000
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL)
        h1 = setHeight(T[u].left)+1;
    if (T[u].right != NIL)
        h2 = setHeight(T[u].right)+1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if (T[u].parent == NIL) {
        printf("root\n");
    } else if (T[u].left == NIL && T[u].right == NIL) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int main() {
    int v, l, r, root = 0;
    cin >> n;

    rep(i,n) T[i].parent = NIL;

    rep(i,n) {
        cin >> v >> l >> r;
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }

    rep(i,n) if (T[i].parent == NIL) root = i;

    setDepth(root,0);
    setHeight(root);

    rep(i,n) print(i);
}


Measured memory_bytes: 3228
n=int(input())
t,a=map(int,input().split())
h=map(int,input().split())
*x,=map(lambda x:t-x*0.006,h)

df=float("inf")
ans=0

for i,j in enumerate(x):
  if df>abs(a-j):
    df=abs(a-j)
    ans=i+1

print(ans)

Measured memory_bytes: 3064
import java.util.*;

class Main {
	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		
		//情報が何件入力されるかnで受け取る
		String s1 = sc.next();
		int n = Integer.parseInt(s1);
		
		//3次元配列で1フロア10部屋3階建ての公舎4棟のそれぞれの入居状況を格納する（初期値は０にする）
		int A[][][] = new int[10][3][4];
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					A[k][j][i] = 0;
				}
			}
		}
		
		//入力された情報を受け取り入居状況を更新する
		for(int i = 0; i < n; i++){
			String s2 = sc.next();
			int b = Integer.parseInt(s2);
			String s3 = sc.next();
			int f = Integer.parseInt(s3);
			String s4 = sc.next();
			int r = Integer.parseInt(s4);
			String s5 = sc.next();
			int v = Integer.parseInt(s5);
			A[r-1][f-1][b-1] += v;
		}
		
		//更新した入居状況を表示する
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					System.out.print(" " + A[k][j][i]);
				}
				System.out.println("");
			}
			if(i != 3){
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 20396
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn bfs(edges : Vec<Vec<usize>>, stt : usize) -> Vec<i32> {
    let mut v : Vec<i32> = vec!(-1;edges.len());
    let mut que = std::collections::VecDeque::new();
    que.push_back(stt);
    v[stt] = 0;
    while !que.is_empty() {
        let x : usize = que.pop_front().unwrap();
        for next in edges[x].iter() {
            if v[*next] == -1 {
                v[*next] = v[x] + 1;
                que.push_back(*next);
            }
        }
    }
    return v;
}

fn main() {
    let nm : Vec<usize> = get_vec();
    let n = nm[0];
    let m = nm[1];

    let mut edges : Vec<Vec<usize>> = vec!(Vec::new();n);
    for _i in 0..m {
        let ab : Vec<usize> = get_vec();
        edges[ab[0]-1].push(ab[1]-1);
        edges[ab[1]-1].push(ab[0]-1);
    }
    let ans : Vec<i32> = bfs(edges, 0);
    println!("{}", if ans[n-1] != -1 && ans[n-1] <= 2 {"POSSIBLE"} else {"IMPOSSIBLE"});
}


Measured memory_bytes: 22780
#include"bits/stdc++.h"
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int count = 1;
	if (b != a && b != c)
		count++;
	if (c != a && c != b)
		count++;
	if (c == b && c != a)
		count++;
	cout << count << endl;
}

Measured memory_bytes: 256
// Jigsaw
// * frank_c1
// * 2017 / 11/ 07

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

const int maxn = (int)(1e5) + 5;
int ai[maxn], bi[maxn], ci[maxn], di[maxn];
int in[maxn], ou[maxn], vi[maxn];
vector<int> nxt[maxn];
int H, cnt, sgn;

void dfs(int x) {
	vi[x] = 1; if (in[x] != ou[x]) sgn = 1; cnt += ou[x] - in[x];
	for (int i = 0; i < (int)nxt[x].size(); ++i) if (!vi[nxt[x][i]]) dfs(nxt[x][i]);
}

int main() {
	int n;
	scanf("%d%d", &n, &H);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d%d%d", &ai[i], &bi[i], &ci[i], &di[i]);
		int u = 0, v = 0;
		if (!ci[i]) u = ai[i]; else u = ci[i] + H;
		if (!di[i]) v = bi[i] + H; else v = di[i];
		++ou[u]; ++in[v]; nxt[u].push_back(v); nxt[v].push_back(u);
	} int cnt = 0, e = 0;
	for (int i = 1; i <= H; ++i) if (in[i] > ou[i]) return printf("NO\n"), 0; 
	for (int i = H + 1; i <= H + H; ++i) if (in[i] < ou[i]) return printf("NO\n"), 0;
	for (int i = 1; i <= H + H; ++i) if (!vi[i] && in[i] + ou[i]) {
		cnt = sgn = 0; dfs(i); if (cnt || !sgn) return printf("NO\n"), 0;
	}
	return printf("YES\n"), 0;
}

Measured memory_bytes: 6784
program main;
var
    i : integer;
    ans : boolean;
    s : string;
begin
    readln(s);

    ans := false;
    for i := 1 to 3 do 
        if (s[i] = '7') then
            ans := true;

    if (ans) then
        writeln('Yes')
    else 
        writeln('No');
end.

Measured memory_bytes: 1388
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>

using namespace std;

int main(void){
    int A,B,Q;
    cin>>A>>B>>Q;
    vector<long long> s(A);
    vector<long long> t(B);
    vector<long long> x(Q);

    for(int i=0;i<A;i++){
        cin>>s[i];
    }
    for(int i=0;i<B;i++){
        cin>>t[i];
    }
    for(int i=0;i<Q;i++){
        cin>>x[i];
    }

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());

    for(int i=0;i<Q;i++){
        long long ans=INT64_MAX;

        vector<long long>::iterator it_s=upper_bound(s.begin(),s.end(),x[i]);
        int index_s=it_s-s.begin();

        for(int k=-1;k<1;k++){
            if(index_s+k<=-1||index_s+k>=A){continue;}

            long long point_s=s[index_s+k];
            vector<long long>::iterator it_st=upper_bound(t.begin(),t.end(),point_s);
            int index_st=it_st-t.begin();

            for(int l=-1;l<1;l++){
                if(index_st+l<=-1||index_st+l>=B){continue;}
                long long point_st=t[index_st+l];
                ans=min(ans, abs(x[i]-point_s)+abs(point_s-point_st) );
            }
        }

        vector<long long>::iterator it_t=upper_bound(t.begin(),t.end(),x[i]);
        int index_t=it_t-t.begin();

        for(int k=-1;k<1;k++){
            if(index_t+k<=-1||index_t+k>=B){continue;}

            long long point_t=t[index_t+k];
            vector<long long>::iterator it_ts=upper_bound(s.begin(),s.end(),point_t);
            int index_ts=it_ts-s.begin();

            for(int l=-1;l<1;l++){
                if(index_ts+l<=-1||index_ts+l>=A){continue;}
                long long point_ts=s[index_ts+l];
                ans=min(ans, abs(x[i]-point_t)+abs(point_t-point_ts) );
            }
        }

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

Measured memory_bytes: 3712
N,X = list(map(int, input().split()))
L = list(map(int, input().split()))
L.insert(0,0)
cou = 0
BP = 0
for i in range(N + 1):
    BP += L[i]
    if BP <= X:
        cou += 1
    else:
        print(cou)
        exit()
print(cou)

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

int main(){
int n,c,k;
  cin >> n >> c >> k;
int t[n];
  for(int i=0;i<n;i++) cin >> t[i];
sort(t,t+n);
  int bus=0;
  
  for(int i=0;i<n;){
  bus++;  
  int j=i;
    while(i-j<c && t[i]-t[j]<=k && i<n)i++;
  
  }
 cout << bus << endl;
}

Measured memory_bytes: 4008
#include<iostream>


int main(){
    int n;
    std::cin >> n;
    int a[n];
    for (int i=0;i<n;i++){
        std::cin >> a[i];
    }
    int height=a[0];
    long long sum=0;

    for(int i=1;i<n;i++){
        if (height <= a[i]){
            height =a[i];
        }
        else{
            sum= sum+ height-a[i];            
        }
    }

    std::cout <<sum << std::endl;
    
    return 0;


}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	vll ans(n);
	rep(i,n-1){
		ll m;
		cin >> m;
		m--;
		ans[m]++;
	}
	for(auto&& e:ans) cout << e << endl;
	return 0;
}

Measured memory_bytes: 4792
#include <iostream>
#define ABS(X) ((X) < 0 ? -1 * (X) : (X))

using namespace std;

int main()
{
    int sx, sy;
    int tx, ty;

    cin >> sx >> sy;
    cin >> tx >> ty;

    for(int i = 0; i < tx - sx; i++) {
        printf("R");
    }
    for(int i = 0; i < ty - sy; i++) {
        printf("U");
    }
    for(int i = 0; i < tx - sx; i++) {
        printf("L");
    }
    for(int i = 0; i < ty - sy; i++) {
        printf("D");
    }

    printf("D");
    for(int i = 0; i < tx - sx + 1; i++) {
        printf("R");
    }
    for(int i = 0; i < ty - sy + 1; i++) {
        printf("U");
    }
    printf("L");

    printf("U");
    for(int i = 0; i < tx - sx + 1; i++) {
        printf("L");
    }
    for(int i = 0; i < ty - sy + 1; i++) {
        printf("D");
    }
    printf("R");

    printf("\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,N); for (int i = 0; i<N; i++)
#define in(N); cin >> N
#define out(ans); cout << ans << endl;
 
int main() {
  int N;
  string N1;
  in(N);
  N1=to_string(N);
  if (N1.at(0)=='7' || N1.at(1)=='7' || N1.at(2)=='7') cout << "Yes" << endl;
  else cout << "No" << endl;
 
}


Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;
const ll mmod = 998244353;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<string> g;
vector<vector<ll>> dp;

int main() {
    
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    
    ll ret = 0;
    if (p == 2 || p == 5)
    {
        for (int i = 0; i < n; ++i)
        {
            if ((s[i] - '0') % p == 0)
            {
                ret += (i + 1ll);
            }
        }
    }
    else
    {
        map<ll, ll> m;
        ll c = 1;
        ll now = 0;
        m[0]++;
        for (int i = n - 1; i >= 0; --i)
        {
            now += (s[i] - '0') * c;
            now %= p;
            c *= 10;
            c %= p;
            ret += m[now % p];
            m[now % p]++;
        }
        
    }
    
    cout << ret << endl;
    
    return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << char(s1.at(0) - 32) << char(s2.at(0) - 32) << char(s3.at(0) - 32)
       << endl;

  return 0;
}


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

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

    long double a, b, h, m; cin >> a >> b >> h >> m;

    long double theta = abs((h*30.0+m*0.5)- m*6.0) * M_PI / 180;
    //cout << theta << "\n";

    long double ans = pow(a,2.0) + pow(b,2.0) - 2*a*b*cos(theta);

    cout << setprecision(20)<< sqrt(ans) << "\n";

    

    return 0;
}

Measured memory_bytes: 4184
def main():
  n = int(input())
  v = list(map(int, input().split()))

  if 0 in v:
    print(0)
    return
  
  prod = 1
  for i in v:
    prod *= i
    if(prod > 1000000000000000000):
      print(-1)
      return
  print(prod)

main()

Measured memory_bytes: 21464
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}

int main(){
  fastIO();
  int k,a,b;
  cin>>k>>a>>b;
  bool yes=false;
  for(int i=a;i<=b;i++){
    if(i%k==0)yes=true;
  }
  if(yes){
    cout<<"OK"<<endl;
  }else{
    cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main(void) {
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if(x + r <= W && y + r <= H && x - r >= 0 && y - r >= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3104
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a=I()
print(a+a**2+a**3)

    
    
    

    
    


    
    

        
        
    


    

Measured memory_bytes: 65384
#include<stdio.h>

int main() {

	int W, H,i,j;

	while (1) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) break;

		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}


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

int N;
vector<int> edges[100000];

bool check2(const vector<int>& v, int omit, int K){
    int sz = v.size();
    int i = 0, j = sz-1;
    while(true){
        if(i == omit) i++;
        if(j == omit) j--;
        if(i >= j) return true;
        if(v[i] + v[j] > K) return false;
        i++; j--;
    }
}

int find_opt(const vector<int>& v, int K){
    int sz = v.size();
    int ng = -1, ok = sz;
    while(ok-ng>1){
        int mid = (ng+ok)/2;
        (check2(v, mid, K) ? ok : ng) = mid;
    }
    return (ok == sz ? -1 : v[ok]);
}

int dfs(int i, int par, int K){
    vector<int> v;
    for(auto j : edges[i]){
        if(j == par) continue;
        int ret = dfs(j, i, K);
        if(ret == -1 || ret+1 > K) return -1;
        v.push_back(ret+1);
    }
    if(v.size() % 2 == 0) v.push_back(0);
    sort(v.begin(), v.end());

    return find_opt(v, K);
}

bool check(int K){
    int result = dfs(0, -1, K);
    if(edges[0].size() % 2 == 1){
        return (result != -1);
    }else{
        return (result == 0);
    }
}

int main(){
    cin >> N;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    int A = 0;
    for(int i=0; i<N; i++){
        if(edges[i].size() % 2 == 1) A++;
    }
    A /= 2;

    int ng = 0, ok = N;
    while(ok-ng>1){
        int mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    int B = ok;

    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 13696
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    dic = {}
    tmp = 0
    for num in a:
        if num in dic:
            dic[num] += 1
            tmp += 1
        else:
            dic[num] = 1
    # print(dic)
    print(N - tmp - int(tmp&1))

if __name__ == "__main__":
    main()

Measured memory_bytes: 18336
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int x;
  cin >> x;
  if(x == 7 || x == 5 || x == 3) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,i,t,j;
  cin>>n;
  long long int a[n],d[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  d[0]=0;
  for(i=1;i<n;i++)
    d[i]=1e9+5;
  for(i=0;i<n-1;i++)
  {
    if(i+1<n)
    {
      d[i+1]=min(d[i+1],d[i]+abs(a[i+1]-a[i]));
    }
    if(i+2<n)
    {
      d[i+2]=min(d[i+2],d[i]+abs(a[i+2]-a[i]));
    }
  }
  cout<<d[n-1];
}


Measured memory_bytes: 1792
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
 
using namespace std;
 
int n;
long long a, b, c, ans = 0;
vector<long long> h;
 
bool f(long long aa) {
	long long an= 0;
	for (int i = 0; i < n; i++) {
		long long d = h[i] - aa*b;
		if (d > 0) {
			an += ceil(double(d) / c);
		}
	}
	return an <= aa;
}
 
int main() {
	cin >> n >> a >> b;
	c = a - b;
	h.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	long long mm = 1, ma = 17179869185;
	long long now = (mm + ma)/2;
	while (ma - mm > 2) {
	//	cout << mm << " " << now <<  " " <<  ma <<endl;
		if (f(now)) {
			ma = now + 1;
		}
		else {
			mm = now;
		}
		now = (mm + ma) / 2;
	}
if(f(mm)) cout << mm << endl;
else cout << mm + 1 << endl;
//	cin >> n;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define nl '\n'
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

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

  int n;
  cin >> n;
  pair<int,int> a[1+n];
  for(int i=1; i<=n; i++)
    cin >> a[i].ff, a[i].ss=i;
  sort(a+1, a+1+n);
  int ans[1+n];
  for(int i=1; i<=n; i++) {
    int lx = i-1, mid = n / 2;
    if( mid <= lx ) {
      ans[a[i].ss] = a[mid].ff;
    } else {
      ans[a[i].ss] = a[mid+1].ff;
    }
  }
  for(int i=1; i<=n; i++) cout << ans[i] << nl;

  return 0;
}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
int dp[100005][105], prefix[100005][105];
int segtree[400005][105];
const int MOD = 1e9+7;
int n, k;
void update(int v, int l, int r, int pos, int val, int child){
    if(l==r){
        segtree[v][child] = val;
        return;
    }
    int m = (l+r)/2;
    if(pos <= m)
        update(2*v, l, m, pos, val, child);
    else
        update(2*v+1, m+1, r, pos, val, child);
    segtree[v][child] = (segtree[2*v][child]+segtree[2*v+1][child])%MOD;
}
int sum(int v, int l, int r, int ql, int qr, int child){
    if(l > qr || r < ql)
        return 0;
    if(ql <= l && r <= qr)
        return segtree[v][child];
    return sum(2*v, l, (l+r)/2, ql, qr, child) + sum(2*v+1, (l+r)/2+1, r, ql, qr, child);
}
int main() {
    IO;
    cin >> n >> k;
    dp[0][0] = 1;
    prefix[0][0] = 1;
    for(int i = 1; i <= k; i++)
        prefix[i][0]+=prefix[i-1][0];
    for(int child = 1; child<=n; child++){
        dp[0][child] = 1;
        prefix[0][child] = 1;
        int mx;
        cin >> mx;
        for(int candle = 1; candle <= k; ++candle){
            dp[candle][child] = prefix[candle][child-1];
            if(candle-mx-1 >= 0)
                dp[candle][child]= (dp[candle][child]-prefix[candle-mx-1][child-1]+MOD)%MOD;;
            prefix[candle][child] = (prefix[candle-1][child]+dp[candle][child])%MOD;
        }
    }
    cout << dp[k][n];
}


Measured memory_bytes: 82560
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

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

    if(n == 1){
        if(d.at(0) == 0)cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    if(d.at(0) > 0){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1;i < n;i ++){
        if(d.at(i) == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    int m = 0;
    for(int i = 0;i < n;i ++) m = max(m,d.at(i));
    vector<int> kazoe(m+1);
    for(int i = 0;i < n;i ++){
        kazoe.at(d.at(i)) ++;
    }

    int ans = 1;
    for(int i = 1;i < m+1;i ++){
        for(int j = 0;j < kazoe.at(i);j ++){
            ans *= kazoe.at(i-1);
            ans %= 998244353;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4712
N, Y = map(int, input().split())

flg = -1
for i in range(N+1):
  for j in range(N+1):
    goke = 9000*i + 4000*j
    if (goke == Y - 1000*N) and (i + j <= N):
      A = i
      B = j
      flg = 1
      break

if flg == 1:
  C = N - A -B
  print('{} {} {}'.format(A, B, C))
else:
  print('-1 -1 -1')


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

int main() {
  int w,n;
  cin >> w >> n;
  int array[w];
  for (int i = 0; i < w; i++) array[i] = i+1;
  for (int i = 0; i < n; i++) {
    int a,b,tmp;
    char c;
    cin >> a >> c >> b;
    tmp = array[a-1];
    array[a-1] = array[b-1];
    array[b-1] = tmp;
  }
  for (int i = 0; i < w; i++) cout << array[i] << endl;
  return 0;
}



Measured memory_bytes: 3116
'use strict'

const main = (input) => {
    input = input.split('\n').map(i => parseInt(i))
    const N = input[0]
    const ds = input.slice(1, N + 1)
    console.log(new Set(ds).size)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

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

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

int tr = 0;
int pok = 0;
int best = 0;
int n, k;
string s;

void pomeri()
{
    best = max(best, tr);
    if(s[pok] == '1') while(pok < n && s[pok] == '1') pok++, tr--;
    while(pok < n && s[pok] == '0') pok++, tr--;
}

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

    cin >> n >> k;
    cin >> s;
    int d = 0;
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        if(i == 0) d++;
        else if(s[i] != s[i-1])
        {
            if(s[i-1] == '1')
                tr += d;
            else
            {
                cnt++;
                if(cnt > k) pomeri();
                tr += d;
            }
            d = 1;
        }
        else d++;
    }
    if(s[n-1] == '1') tr += d, best = max(best, tr);
    else
    {
        cnt++;
        if(cnt > k) pomeri();
        tr += d;
        best = max(best, tr);
    }
    cout << best;

    return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python
# coding: utf-8

def main():
    n, z, w = list(map(int, input().split()))
    As = list(map(int, input().split()))
    if len(As) > 1:
        answer = max(abs(w - As[-1]), abs(As[-1] - As[-2]))
    else:
        answer = abs(w-As[-1])
    print(answer)


if __name__ == '__main__':
    main()


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

class UnionFind {
public:
    vector<int> par;
    UnionFind(int n) {
        par.resize(n);
        REP(i, 0, n) {
            par[i] = i;
        }
    }
    int Find(int n) {
        return (n == par[n] ? n : par[n] = Find(par[n]));
    }
    bool Union(int a, int b) {
        a = Find(a);
        b = Find(b);
        if (a == b) return false;
        par[a] = b;
        return true;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    REP(i, 0, N) {
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf(N);
    REP(i, 0, M) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.Union(x, y);
    }
    int cnt = 0;
    REP(i, 0, N) {
        if (uf.Find(p[i]) == uf.Find(i)) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
import copy
n = int(input())

# nの約数を全て求める
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def hantei(i):
    global n
    n1 = copy.copy(n)
    while n1 % i == 0:
        n1 //= i
    if n1 % i == 1:
        return True
    else:
        return False

li = divisor(n)
li2 = divisor(n-1)
ans = 0

for i in li:
    if i != 1:
        if hantei(i):
            ans += 1

for i in li2:
    if n % i != 0:
        ans += 1

print(ans)


Measured memory_bytes: 39916
n = int(input())
a = [int(input()) for i in range(n)]
MAX = max(a)
MAX_num = a.count(MAX)
if MAX_num == 1:
  MAX_index = a.index(MAX)
  a.sort()
  for i in range(n):
    if i == MAX_index:
      print(a[-2])
    else:
      print(MAX)
else:
  for i in range(n):
    print(MAX)
  

Measured memory_bytes: 12532
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define INF 1e12
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int power(int b,int p)
{
	if(p==0) return 1;
	if(p==1) return b;
	int tmp=power(b,p/2);
	if(p%2) return tmp*tmp*b;
	return tmp*tmp;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c; cin>>a>>b>>c;
	cout<<min(b/a,c);
	return 0;
}











Measured memory_bytes: 256
#include<set>
#include <unordered_set>
#include <unordered_map>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <string.h>
#include <strings.h>


#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define clr(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define mod 1000000007ll
#define eps 1e-10
#define infi  1000000000ll
#define infll 1000000000000000000ll


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef unordered_map<ll,ll> umll;


const int N = 100005;
int n,r;
ll a,b,c;
set<pair<pii, int>> taken;
int main(){
    scanf("%lld%lld%lld" ,&a,&b,&c);
    int ans = 0;
    while (!(a&1) && !(b&1) && !(c&1)) {
        if(taken.count({mp(a,b),c})) {
            printf("-1\n");
            return 0;
        }
        taken.insert({mp(a,b),c});
        taken.insert({mp(b,a),c});

        taken.insert({mp(a,c),b});
        taken.insert({mp(c,a),b});

        taken.insert({mp(b,c),a});
        taken.insert({mp(c,b),a});

        ++ ans;
        a >>= 1 , b >>= 1 , c >>= 1;
        ll t1 = a , t2 = b, t3 = c;
        a += t2 , b += t3 , c += t1;
    }
    
    printf("%d\n",ans);
}


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

using namespace std;

int main(){

    string S, T;
    vector<int> S_count(26, 0), T_count(26, 0);
    cin >> S;
    for(int i = 0; i < S.length(); i++) S_count[S[i] - 'a']++;
    cin >> T;
    for(int i = 0; i < T.length(); i++) T_count[T[i] - 'a']++;
    sort(S_count.begin(), S_count.end());
    sort(T_count.begin(), T_count.end());
    for(int i = 0; i < 26; i++){
        if(S_count[i] != T_count[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 776
def insertsort(a,n):
    for i in range(1,n):
        v=a[i]
        j=i-1
        while j>=0 and a[j]>v:
            a[j+1]=a[j]
            j-=1
        a[j+1]=v
        print(*a)

N=int(input())
A=list(map(int,input().split()))
print(*A)

insertsort(A,N)


Measured memory_bytes: 5980
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main(){
	ll x;
	cin>>x;
	cout<<((x<1200)?"ABC":"ARC")<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
N = [input() for i in range(n)]
m = int(input())
M = [input() for i in range(m)]

nc = Counter(N)
mc = Counter(M)

a = set(list(nc.keys())+list(mc.keys()))
ans = 0

for i in a:
    b = nc[i]-mc[i]
    if ans < b:
        ans = b
        
print(ans)

Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d; cin >> n >> d;
  vector<vector<int>> a(n,vector<int>(d));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> a.at(i).at(j);
    }
  }
  int cnt = 0;
  double distance = 0;
  for(int i = 0;i < n - 1; i++){
    for(int j = i +1; j < n; j++){
      for(int k = 0; k < d; k++){
        //printf("%d %d\n",a.at(i).at(k),a.at(j).at(k));
      	distance += (a.at(i).at(k) - a.at(j).at(k)) * (a.at(i).at(k) - a.at(j).at(k));
      }
    distance = sqrt(distance);
   // cout << distance << endl;;
    if(ceil(distance) == floor(distance)) cnt++;
    distance = 0;
    }

  }
  
  cout << cnt;      
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main (){
  int n,a[100],i,j,minj,v,count=0;

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

  //sorting
  for(i=1;i<=n;i++){
    minj=i;
    for(j=i+1;j<=n;j++){
      if(a[j]<a[minj]){
	minj=j;

      }
    
    }
	v=a[i];
	a[i]=a[minj];
	a[minj]=v;
	if(i!=minj){
	  count++;
	}
  }

  //output answer
    for(i=1;i<=n;i++){
      if(i==n){
	cout<<a[i]<<endl;
      }else{
	cout<<a[i]<<" ";
      }
    }
    cout<<count<<endl;

  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define MOD 100000
using namespace std;

int ind[1 << 19];

int main(){
	int h,w,tmp = 0,now = 0,nxt = 1,all = 1;
	vector<int> num;
	vector<int> dp[2][2];
	char s[20][20];
	scanf("%d %d",&h,&w);
	for(int i = 0;i < h;i++){
		getchar();
		for(int j = 0;j < w;j++) s[i][j] = getchar();
	}
	for(int i = 0;i < (1 << 19);i++) ind[i] = -1;
	for(int i = 0;i < (1 << (w - 1));i++){
		bool flag = true;
		for(int j = 0;j < w - 2;j++){
			if(((i >> j) & 1) && ((i >> (j + 1)) & 1)) flag = false;
		}
		if(flag){
			ind[i] = num.size();
			num.push_back(i);
		}
	}
	for(int i = 0;i < 2;i++){
		for(int j = 0;j < 2;j++) dp[i][j].resize(num.size());
	}
	dp[now][0][0] = 1;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			for(int k = 0;k < num.size();k++){
				dp[nxt][0][k] = 0;
				dp[nxt][1][k] = 0;
			}
			bool a = true,b = true,c = true;
			if(s[i][j] == '?') all = (all * 3) % MOD;
			else{
				if(s[i][j] != 'J') a = false;
				if(s[i][j] != 'O') b = false;
				if(s[i][j] != 'I') c = false;
			}
			for(int k = 0;k < num.size();k++){
				int n = (num[k] & ~(1 << j));
				if(!j){
					if(a) (dp[nxt][1][ind[n]] += dp[now][0][k] + dp[now][1][k]) %= MOD;
					if(b) (dp[nxt][0][ind[n]] += dp[now][0][k] + dp[now][1][k]) %= MOD;
					if(c && !((num[k] >> j) & 1)) (dp[nxt][0][ind[n]] += dp[now][0][k] + dp[now][1][k]) %= MOD; 
				}else{
					if(a) (dp[nxt][1][ind[n]] += dp[now][0][k] + dp[now][1][k]) %= MOD;
					if(b){
						(dp[nxt][0][ind[n | (1 << (j - 1))]] += dp[now][1][k]) %= MOD;
						(dp[nxt][0][ind[n]] += dp[now][0][k]) %= MOD;
					}
					if(c && !((num[k] >> j) & 1)) (dp[nxt][0][ind[n]] += dp[now][0][k] + dp[now][1][k]) %= MOD;
				}
			}
			swap(now,nxt);
		}
	}
	int ans = 0;
	for(int i = 0;i < 2;i++){
		for(int v : dp[now][i]) ans = (ans + v) % MOD;
	}
	cout << (all - ans + MOD) % MOD << endl;
	return 0;
}

Measured memory_bytes: 5380
from heapq import heappop, heappush
N = int(input())
A = []
memo = {}
count = 0
for i in range(N):
  a = int(input())
  if i%2 == 1:
    memo[a] = 1
  else:
    memo[a] = 0
  heappush(A,a)

for i in range(N):
  x = heappop(A)
  if i%2 != memo[x]:
    count += 1
print(count//2)

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

int main(){
    const long int mod = pow(10,9)+7;
    long int N;
    cin >> N;

    long long int ans=0;

    long long int s1,s2,s3;
    s1 = 1;
    s2 = 1;
    s3 = 1;

    rep(i,N) {
        s1 *= 10;
        s1 %= mod;
    }
    rep(i,N) {
        s2 *= 9;
        s2 %= mod;
    }
    rep(i,N) {
        s3 *= 8;
        s3 %= mod;
    }

    ans += s1;
    ans %= mod;

    ans -= s2;
    ans %= mod;
    if(ans<0) ans+=mod;

    ans -= s2;
    ans %= mod;
    if(ans<0) ans+=mod;

    ans += s3;
    ans %=mod;

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int a,b,c,k,sa1,sa2,sum;
	scanf("%d %d %d %d",&a,&b,&c,&k);
	sa1=k-a;
	if(sa1<0){
		sa1=0;
	}
	sum=0;
	sum+=k-sa1;
	if(sa1>=1){
	   sa2=sa1-b;
	   if(sa2>=1){
		   sum-=sa2;
	   }
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1700
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<String>().chars().collect::<Vec<_>>();
    for i in 1..n.len() {
        if n[i - 1] == n[i] {
            println!("Bad");
            return;
        }
    }
    println!("Good");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <functional>
#include <stack>
using namespace std;

string s, t;

signed main() {
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLOutput;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        String S = sc.next();
        if (S.charAt(0)==S.charAt(1) && S.charAt(0)==S.charAt(2)) System.out.println("No");
        else if (S.charAt(0)==S.charAt(1) && S.charAt(2)==S.charAt(3)) System.out.println("Yes");
        else if (S.charAt(0)==S.charAt(2) && S.charAt(1)==S.charAt(3)) System.out.println("Yes");
        else if (S.charAt(0)==S.charAt(3) && S.charAt(1)==S.charAt(2)) System.out.println("Yes");
        else System.out.println("No");
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 22484
import java.util.*;

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

    int n = s.nextInt();
    int[] p = new int[n];
    for (int i = 0; i < n; i++) {
      p[i] = s.nextInt();
    }

    int[] count = new int[n+1];
    Arrays.fill(count, 0);
    for (int i = 0; i < n; i++) {
      count[p[i]] = count[p[i]-1]+1;
    }

    int maxCount = 0;
    for (int i = 1; i <= n; i++) {
      maxCount = Math.max(maxCount, count[i]);
    }
    System.out.println(n - maxCount);
  }
}


Measured memory_bytes: 66760
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(int& val: arr) {
        cin >> val;
    }
    int m = INT_MAX, M = INT_MIN;
    int m_idx = -1, M_idx = -1;
    for(int i = 0; i < n; i++) {
        if (arr[i] > M) {
            M = arr[i];
            M_idx = i+1;
        }
        if (arr[i] < m) {
            m = arr[i];
            m_idx = i+1;
        }
    }
    cout << (n-1)*2 << endl;
    if (abs(M) > abs(m)) {
        for(int i = 1; i <= n; i++) {
            if (i == M_idx) continue;
            cout << M_idx << " " << i << endl;
        }
        for(int i = 1; i < n; i++) {
            cout << i << " " << i+1 << endl;
        }
    } else {
        for(int i = 1; i <= n; i++) {
            if (i == m_idx) continue;
            cout << m_idx << " " << i << endl;
        }
        for(int i = n; i >= 2; i--) {
            cout << i << " " << i-1 << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >> n;
  vector <vector <ll>> f(n, vector <ll> (10));
  rep(i, n) {
    rep(j, 10) {
      cin >> f.at(i).at(j);
    }
  }
  vector <vector <ll>> p(n, vector <ll> (11));
  rep(i, n) {
    rep(j, 11) {
      cin >> p.at(i).at(j);
    }
  }
  ll res = -INF;
  for (int tmp = 0; tmp < (1 << 10); tmp++) {
    bitset <10> s(tmp);
    vector <ll> c(n, 0);
    bool flag = 1;
    rep(i, 10) {
      if (s.test(i)) {
        flag = 0;
        rep(j, n) {
          if (f.at(j).at(i)) c.at(j)++;
        }
      }
    }
    if (flag) continue;
    ll profit = 0;
    rep(i, n) {
      profit += p.at(i).at(c.at(i));
    }
    res = max(res, profit);
  }
  cout << res << endl;
}

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

int main(){
  map<int,int> data;
  int a,b,c,d;
  cin>>a>>b;
  for(int i=0;i<b;i++){
    cin>>c>>d;
    data[c]+=1;
    data[d]+=1;
  }
  for(int i=1;i<=a;i++){
    cout<<data[i]<<endl;
  }
}

Measured memory_bytes: 256
while(True):
    a,b=list(map(int,input().split()))
    if a==0 and b==0:
        break
        
    n=int(input())
    x=[0]*n
    y=[0]*n
    e=[[0]*b for i in range(a)]
    
    for i in range(n):
        x[i],y[i]=list(map(int,input().split()))
        e[x[i]-1][y[i]-1]=1
    p=[[0]*b for i in range(a)]
    p[0][0]=1
    for i in range(a):
        if e[i][0]==0 and p[i-1][0]==1:
            p[i][0]=1 
    for i in range(b):
        if e[0][i]==0 and p[0][i-1]==1:
            p[0][i]=1
    
    for i in range(1,a):
        for j in range(1,b):
            if e[i-1][j]==1:
                u=0
            else:
                u=p[i-1][j]
            if e[i][j-1]==1:
                v=0
            else:
                v=p[i][j-1]
            p[i][j]=u+v
    
    print(p[a-1][b-1])
    



Measured memory_bytes: 5612
import scala.io.StdIn

object Main extends App {
  val s = StdIn.readLine().sorted
  val t = StdIn.readLine().sortBy(f => -1*f)
  
  def loop(sl: String, tl: String): Boolean = {
    if(sl.nonEmpty && tl.isEmpty) false
    else if(sl.isEmpty && tl.nonEmpty) true
    else if(sl.isEmpty && tl.isEmpty) false
    else if(sl.head > tl.head) false
    else if(sl.head < tl.head) true
    else loop(sl.tail, tl.tail)
  }
  
  println(if(loop(s, t)) "Yes" else "No")
}


Measured memory_bytes: 25540
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  string S;
  cin >> S;
  int ans = 0;
  rep(i, S.size())
  {
    if (S[i] == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256