akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque


while True:
    w,h=map(int,input().split())
    if w==h==0:
        sys.exit()
    
    #Vert[i][j]=i行目に関して、j列目とj+1列目の間の情報
    #Hori[i][j]=i行目とi+1行目の間に関して、j列目の情報
    Vert=[]
    Hori=[]
    for i in range(2*h-1):
        #縦棒に関する情報
        if i%2==0:
            Vert.append(list(map(int,input().split())))
        #横棒に関する情報
        else:
            Hori.append(list(map(int,input().split())))
    
    #移動可能マスを出力
    def sur(v): #v:tuple
        vx=v[0]
        vy=v[1]
        preE=[(vx-1,vy),(vx+1,vy),(vx,vy-1),(vx,vy+1)]
        E=[]
        if 0<vx:
            if Hori[vx-1][vy]==0:
                E.append((vx-1,vy))
        if vx<h-1:
            if Hori[vx][vy]==0:
                E.append((vx+1,vy))
        if 0<vy:
            if Vert[vx][vy-1]==0:
                E.append((vx,vy-1))
        if vy<w-1:
            if Vert[vx][vy]==0:
                E.append((vx,vy+1))
        return E

    #bfs
    dist=[[0]*w for i in range(h)]
    q=deque()

    dist[0][0]=1
    q.append((0,0))
    while q:
        now=q.popleft()
        for next in sur(now):
            if dist[next[0]][next[1]]>0:
                continue
            q.append(next)
            dist[next[0]][next[1]]=dist[now[0]][now[1]]+1

            if next==(h-1,w-1):
                print(dist[h-1][w-1])
                break
        else:
            continue
        break
    else:
        print(0)


    



Measured memory_bytes: 6016
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, m: usize, k: usize);
    if m == 1 {
        if k == 0 {
            println!("0 0 1 1");
        } else {
            println!("{}", -1);
        }
        return;
    }
    let n = 2usize.pow(m as u32) - 1;
    if k > n {
        println!("{}", -1);
        return;
    }
    for i in 0..=n {
        if i != k {
            print!("{} ", i)
        }
    }
    print!("{} ", k);
    for i in (0..=n).rev() {
        if i != k {
            print!("{} ", i)
        }
    }
    print!("{}", k);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2124
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

int main()
{
	int r, d, x;
	cin >> r >> d >> x;

	for (int i = 0; i < 10; ++i) {
		x = r * x - d;
		cout << x << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    vector<int> v(3) ; 
    for(int i=0;i<3;i++){
    	cin >> v[i] ; 
    }
    sort(v.begin(),v.end()) ; 
    int ans = v[2] - v[1] ; 
    v[0] += ans ; 
    v[1] += ans ; 
    int dist = v[2] - v[0] ; 
    if ( dist & 1 ){
    	v[2]++;
    	ans++ ; 
    }
    ans += (v[2]-v[0])/2;
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define cs const
#define mid ((l+r)>>1)
#define ls (now<<1)
#define rs (now<<1|1)
#define pb push_back
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define cn(x) memset(x, 0, sizeof(x))
using namespace std;
cs int mod = 998244353;
cs int ff = 1e6+1;
int n, a, b;
signed main()
{
    cin >> n >> a >> b;
    if( a > b ) swap( a, b );
    if( ( b - a ) % 2 == 0 ) cout << ( b - a ) / 2 << endl;
    else cout << min( a - 1, n - b ) + ( b - a + 1 ) / 2 << endl; 
}
/* be careful:
1 if not solve after 20 min, read it again
2 before sumbit read things below:
int overflew
arrey bounds
memory
special cases
*/

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


int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    bool okemaru =false;
    int ans=0;   
    sort(l.begin(),l.end(),greater<>());
    for(int i=0;i<n-2;i++){
        
        //hazimeno henn
        for(int j=n-1;j>i+1;j--){
            //hutatume
            if(okemaru==true){
                ans+=(j-i)*(j-i-1)/2;
                //cout<<"(j-i)*(j-i-1)/2 "<<(j-i)*(j-i-1)/2<<endl;//memo
                okemaru = false;
                break;
            }
            for(int k=j-1;k>i;k--){
                //saigo
                if(l[i]<(l[j]+l[k])){
                    ans+=k-i;
                    //cout<<"k "<<k<<" i "<<i<<" k-i "<<k-i<<endl;//memo
                    if(j==k+1&&j!=i+2){
                        okemaru = true; 
                    }
                    break;
                }
            }
        
        }
    
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

struct node{int l,r,key;};
node t[500001];
int sz;
vector<int> preord,inord;
void dfs(int vi){
    preord.pb(t[vi].key);
    if(t[vi].l!=-1)dfs(t[vi].l);
    inord.pb(t[vi].key);
    if(t[vi].r!=-1)dfs(t[vi].r);
}
bool dfs2(int k,int vi){
    bool ret=false;
    if(t[vi].key==k) return true;
    else if(t[vi].key>k){
        if(t[vi].l!=-1) ret|=dfs2(k,t[vi].l);
        else return false;
    }
    else if(t[vi].key<k){
        if(t[vi].r!=-1) ret|=dfs2(k,t[vi].r);
        else return false;
    }
    return ret;
}
int main(){
    int n,k;
    cin>>n;
    string s;
    rep(i,n){
        cin>>s;
        if(s[0]=='i'){
            cin>>k;
            int cur=0;
            while(cur<sz){
                if(k>t[cur].key){
                    if(t[cur].r!=-1) cur=t[cur].r;
                    else{
                        t[cur].r=sz;break;
                    }
                }
                else{
                    if(t[cur].l!=-1) cur=t[cur].l;
                    else{
                        t[cur].l=sz;break;
                    }
                }
            }
            t[sz].l=t[sz].r=-1;
            t[sz].key=k;++sz;
        }
        else if(s[0]=='p'){
            preord.clear(),inord.clear();
            dfs(0);
            int m=inord.size();
            rep(i,m) cout<<" "<<inord[i];
            cout<<endl;
            rep(i,m) cout<<" "<<preord[i];
            cout<<endl;
        }
        else{
            cin>>k;
            if(dfs2(k,0)) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10768
package main
import (
  "fmt"
  "os"
  "text/scanner"
  "strconv"
)
func main(){
  var s scanner.Scanner
  s.Init(os.Stdin)
  var x [6]int
  for i:=0; i<6; i++{
    s.Scan()
    x[i], _ = strconv.Atoi(s.TokenText())
  }
  if(x[4]-x[0]<=x[5]){
    fmt.Printf("Yay!\n")
  }else{
    fmt.Printf(":(\n")
  }
}

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

long long h[200005] = { 0 };
long long z[200005] = { 0 };
int main()
{
	long long n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		
		cin >> z[i];
		h[z[i]]++;
	}
	long long sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += h[i] * (h[i] - 1) / 2;
	}
	//cout << sum << endl;
	for (int i = 1; i <= n; i++) {
		long long p = z[i];
		if(h[p] == 0||h[p]==1)cout <<sum << endl; 
		else cout<<sum -( h[p] * (h[p] - 1) / 2)+((h[p]-1)*(h[p]-2)/2)<<endl;
	}
}

Measured memory_bytes: 4736
import numpy as np
n,m = map(int,input().split())
A1 = np.zeros(n,dtype=bool)
Ai = np.zeros(n,dtype=bool)
for i in range(m):
    a,b = map(int,input().split())
    if a == 1:
        A1[b-1] = True
    if b == n:
        Ai[a-1] = True
if np.any(Ai[A1]):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 27292
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





int main()
{
   
    int n, w;
    cin >> n >> w;
    vector<int>a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<ll>x(w + 1009);
    for (int i = 1; i <= w+1005; i++)x[i] = -99999999999999;
    x[0] = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = w; j >= 0; j--) {
            x[j + b[i]] = max(x[j + b[i]], x[j] + a[i]);
            if (j + b[i] <= w)ans = max(x[j + b[i]],ans);
        }
    }

    cout << ans << endl;



    return 0;

}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  VI a(n); for (int i = 0; i < n; i++) cin >> a[i];

  int ima = max_element(a.begin(), a.end()) - a.begin();
  int imi = min_element(a.begin(), a.end()) - a.begin();
  cout << 2 * (n - 1) << '\n';
  if (a[ima] + a[imi] >= 0) {
    for (int i = 0; i < n; i++) {
      if (i == ima) continue;
      cout << ima + 1 << " " << i + 1 << '\n';
    }
    for (int i = 0; i < n - 1; i++) {
      cout << i + 1 << " " << i + 2 << '\n';
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i == imi) continue;
      cout << imi + 1 << " " << i + 1 << '\n';
    }
    for (int i = n - 1; i > 0; i--) {
      cout << i + 1 << " " << i << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 256
s=input()
t=input()
S=[]
T=[]
for i in range (len(s)):
    S.append(s[i])
for i in range (len(t)):
    T.append(t[i])
S.sort()
T.sort(reverse=True)
count=0
for i in range(min(len(s),len(t))):
    if S[i]<T[i]:
        print("Yes")
        count=1
        break
    if S[i]>T[i]:
        print("No")
        count=1
        break
if count==0:
    if len(s)<len(t):
        print("Yes") 
    else:
        print("No")   
        


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1), B(N);
    rep(i,N+1) cin >> A[i];
    rep(i,N) cin >> B[i];

    long long ans = 0;
    rep(i,N) {
        if (A[i] >= B[i]) ans += B[i];
        else {
            ans += A[i];
            B[i] -= A[i];
            if (A[i + 1] >= B[i]) {
                A[i + 1] -= B[i];
                ans += B[i];
            } else {
                ans += A[i + 1];
                A[i + 1] = 0;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
a,b,x = gets.chomp.split.collect{ |item| item.to_i}

h = (a*a*b).to_f/2.0
result = 90
if x > h
  result = Math.atan((4*h-2*x).to_f/(a*a*a).to_f) * 180.0 / Math::PI
else
  result = Math.atan((a*b*b).to_f/(2*x).to_f) * 180.0 / Math::PI
end

puts result

Measured memory_bytes: 1788
N,L=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

aji_sum=0
eat=99999

for i in range(1,N+1):
    
    aji_sum=aji_sum+i+L-1
    if abs(i+L-1) < abs(eat):
        eat = i+L-1

print(aji_sum-eat)

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

const int M = 1000005;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> q(M);
    for (int x : A)
    {
        if (q[x] != 0) {
            q[x] = 2;
            continue;
        }
        for (int j = x; j < M; j += x) q[j]++;
    }

    int ans = 0;
    rep(i, N)
    {
        if (q[A[i]] <= 1) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7904
#include <iostream>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    bool sunu[N];
    for(int i=0;i<N;i++){
        sunu[i]=false;
    }
    int count=0;
    for(int i=0;i<K;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int A;
            cin >> A;
            A--;
            if(sunu[A]==false){
                sunu[A]=true;
                count++;
            }
        }
    }
    int ans=N-count;
    cout << ans ;
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main()
{
	int N;
	int table[2][100];
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &table[0][i]);
	}
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &table[1][i]);
	}

	int max = 0;
	int point;

	for (int i = 0; i < N; i++)
	{
		point = 0;
		for (int j = 0; j <=i; j++)
		{
			point += table[0][j];
		}
		for (int j = i; j < N; j++)
		{
			point += table[1][j];
		}
		if (point > max)
			max = point;
	}
	printf("%d", max);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int N = in.nextInt();
		
		if(N%2==0) {
			System.out.print(N);
		} else {
			System.out.print(N*2);
		}
		in.close();
		
	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//add_edge:辺の追加, build:from→toへの経路探索+負の閉路検出
template<typename T>
struct BellmanFord {
	struct Edge {
		ll from, to; ll cost;
		Edge() {}
		Edge(ll from, ll to, ll cost) :from(from), to(to), cost(cost) {}
	};
	ll n; vll G; vl used, reach;
	BellmanFord(ll n) :n(n), G(n), used(n, 0), reach(n, 0) {}

	vector<Edge> es;
	void add_edge(ll from, ll to, ll cost) {
		es.push_back(Edge(from, to, cost));
		G[from].push_back(to);
	}
	void dfs(ll v) {
		if (used[v]) return;
		used[v] = 1;
		for (ll u : G[v]) dfs(u);
	}
	ll build(ll from, ll to, ll& neg_loop) {
		for (ll i = 0; i < n; i++) {
			fill(used.begin(), used.end(), 0);
			dfs(i);
			reach[i] = used[to];
		}
		vector<ll> ds(n, 1e18);
		ds[from] = 0;
		for (ll i = 0; i < n; i++) {
			bool update = 0;
			for (auto e : es) {
				if (!reach[e.from] || !reach[e.to] || ds[e.from] == 1e18) continue;
				if (ds[e.to] > ds[e.from] + e.cost) {
					ds[e.to] = ds[e.from] + e.cost;
					update = 1;
				}
			}
			if (!update)break;
			if (i == n - 1) {
				neg_loop = 1;
				return INF;
			}
		}
		neg_loop = 0;
		return ds[to];
	}
};
int main() {
	cin >> N >> M;
	BellmanFord<ll> G(N);
	for (i = 0; i < M; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--; c *= (-1);
		G.add_edge(a, b, c);
	}
	ll NL;
	ll res = G.build(0, N - 1, NL);
	if (NL) cout << "inf";
	else cout << -res;
}

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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
/* }}} */

int sumsum(int tmp)
{
    int sum=0;
    while(tmp>0)
    {
        sum+=tmp%10;
        tmp/=10;
    }
    return sum;
}

signed main() 
{
    int n,a,b;
    cin >> n >> a >> b;
    int ans=0;
    REP1(i,n)
    {
        int tmp=sumsum(i);
        if(tmp>=a&&tmp<=b) ans+=i;
    }
    print(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define mod 1000000007

using namespace std;
class CompareFirst
{
public:
  bool operator()(pair<int,int> n1,pair<int,int> n2) {
    return n1.first>n2.first; //>:desc <:asc
  }
};

int main(){
  string s,t,ss;
  int a,b,i,j,k,l,n,ans=0,m=0;
  vector<string> vs;
  vector<int> v[26];
  pair<int,int> pr;
  //unordered_map<string,int> mp;
  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst> pq

  cin >> a >> b;
  int kuchi = 1;

  //else if(b%(a-1) == 0)ans = b/(a-1);
  //else ans = (b/(a-1)) + 1;
  while(1){
    if(kuchi >= b)break;
    kuchi--;
    kuchi += a;
    ans++;
  }
  if(b == 1)ans = 0;
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

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

        for (int i = 0; i < o.length(); i++) {
            System.out.print(o.charAt(i));
            if (i < e.length()) {
                System.out.print(e.charAt(i));
            }
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define vi vector<ll>
#define all(v) v.begin(), v.end()

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

	ll n = 0, k = 0;
	cin >> n >> k;
	ll sol = pow((k - 1), (n - 1));
	sol *= k;
	cout << sol << endl;
	//cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B != C)
  {
    cout << "Yes" << endl;
    return 0;
  }
  else if (B == C && A != B)
  {
    cout << "Yes" << endl;
    return 0;
  }
  else if (A == C && C != B)
  {
    cout << "Yes" << endl;
    return 0;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
s=list(str(input()))
for i in range(len(s)):
    s[i]=int(s[i])
n=len(s)
mod=10**9+7
dp=[[0 for i in range(2)] for j in range(n+1)]
dp[0][0]=0
dp[0][1]=1
for i in range(n):
    if s[i]==1:
        dp[i+1][0]=(dp[i][0]*3+dp[i][1])%mod
        dp[i+1][1]=dp[i][1]*2%mod
    else:
        dp[i+1][0]=dp[i][0]*3%mod
        dp[i+1][1]=dp[i][1]%mod
print(sum(dp[n])%mod)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
inline void add(signed &a,signed b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=1111111;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    if(n<0|k<0||k>n)return 0;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*inv[n-k]%mod;
}

int N;
int A[444],B[444];
int posA[444],posB[444];

signed dp[410][410][140][3];

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

    dp[N][N][0][0]=1;
    for(int i=N;i>0;i--){
        for(int j=N;j>0;j--){
            for(int k=0;k<=N/3;k++){
                add(dp[i][j][k][1],dp[i][j][k][0]);
                if(i-1!=0){
                    if(posB[A[i]]>j)add(dp[i-1][j][k+1][0],dp[i][j][k][0]);
                    else add(dp[i-1][j][k][0],dp[i][j][k][0]);
                }

                add(dp[i][j][k][2],dp[i][j][k][1]);
                if(j-1!=0){
                    if(posA[B[j]]>i)add(dp[i][j-1][k+1][1],dp[i][j][k][1]);
                    else add(dp[i][j-1][k][1],dp[i][j][k][1]);
                }

                if(posB[A[i]]>j&&posA[B[j]]>i&&k)add(dp[i-1][j-1][k-1][0],(long long)dp[i][j][k][2]*k%mod);
            }
        }
    }

    int ans=dp[0][0][0][0];
    for(int i=0;i<N/3;i++){
        ans=ans*(3*i+1)%mod;
        ans=ans*(3*i+2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 289280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
    ll K, ans = 0;
    string S;
    cin >> K >> S;
    if (S.length() <= K) {
        cout << S << endl;
        return 0;
    }
    for (ll i = 0; i < K; i++) {
        cout << S[i];
    }
    cout << "..." << endl;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int num=0;
    for(int i=0;i<3;i++)
        if(s[i]=='R')
            num++;
    if(s[1]=='S'&&num)
        cout<<1<<endl;
    else
        cout<<num<<endl;
    return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll n, m;

  cin >> n >> m;

  ll l_max = 0;
  ll r_min = n;
  for(ll i=0; i<m; i++) {
    ll lt, rt;
    cin >> lt >> rt;
    if(lt > l_max) l_max = lt;
    if(rt < r_min) r_min = rt;
  }

  ll d = r_min - l_max;
  if(d < 0) {
    cout << 0 << endl;
  } else {
    cout << d+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 384
A, B, K = map(int, input().split())

a = max(0, A - K)
if A - K >= 0:
    a = A - K
    b = B
else:
    if A + B - K >= 0:
        a = 0
        b = A + B - K
    else:
        a = 0
        b = 0
print(a, b)

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<iomanip>
#include<string.h>
#include<cstdio>
#include<cstdlib>
#include<stack>

using namespace std;

int main(){

  int n, q;

  cin >> n;

  int s[n + 1];

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

  cin >> q;

  int sum = 0;

  for(int i = 0; i < q; i++){
    int t;
    cin >> t;

    int left = 0, right = n;

    while(left < right){
      int mid = (left + right) / 2;
      if(s[mid] == t){
        sum++;
        break;
      }
      else if(s[mid] > t) right = mid;
      else left = mid + 1;
    }
  }

  cout << sum << endl;


  return 0;

}


Measured memory_bytes: 3424
//https://gist.github.com/draftcode/1357281
#include <string>
#include <cctype>
#include <iostream>
typedef std::string::iterator State;
class ParseError {};

int number(State &begin);
int factor(State &begin);
int term(State &begin);
int expression(State &begin);
void consume(State &begin, char expected){
	if(*begin == expected){
		begin++;
	}else{
		std::cerr << "Expected '" << expected << "' but got '"<<*begin << "'"<<std::endl;
		std::cerr << "Rest string is '";
		while(*begin){
			std::cerr << *begin++;
		}
		std::cerr<<"'"<<std::endl;
		throw ParseError();
	}
}

int main(void){
	int N;
	std::cin >> N;
	std::cin.ignore();
	while(N--){
		std::string s;
		std::getline(std::cin, s);
		//std::cin>>s;
		State begin = s.begin();
		int ans = expression(begin);
		//consume(begin, '=');
		std::cout << ans << std::endl;
	}
	return 0;
}

int number(State &begin){
	int ret = 0;

	while(isdigit(*begin)){
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}

	return ret;
}

int factor(State &begin){
	int ret;
	if(*begin == '('){
		//consume(begin,'(');
		begin++;
		ret = expression(begin);
		//consume(begin,')');
		begin++;
	}else{
		return number(begin);
	}
	return ret;
}

int term(State &begin){
	int ret = factor(begin);

	for(;;){
		if(*begin == '*'){
			begin++;
			ret *= factor(begin);
		}else if(*begin == '/'){
			begin++;
			ret /= factor(begin);
		}else{
			break;
		}
	}
	return ret;
}

int expression(State &begin){
	int ret = term(begin);

	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		} else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}else {
			break;
		}
	}
	return ret;
}

Measured memory_bytes: 1212
#include <iostream>
#include <cstring>
#define N 10000
using namespace std;
void mpstr2num(int *num, char *str);
void mpadd(int* ret, int* a, int* b);
void mpnum2str(char* str, int* num);

char a[100], b[100];
int anum[25], bnum[25];
int resultnum[25];
char result[100];

void mpstr2num(int* num, char* str){
    char* ss;
    int* nn;
    while(*str == ' ' || *str == '\t') str++;
    while(*str == '0') str++;
    ss = str;
    while(*ss >= '0' && *ss <= '9') ss++;
    if(ss == str){
        *num = 0;
        return;
    }
    int x = 0;
    int k = 1;
    nn = num;
    do{
        x+=(*--ss - '0') * k;
        k *= 10;
        if(k == N || ss == str){
            *++nn = x;
            x = 0;
            k = 1;
        }
    }while(ss != str);

    *num = nn - num;
    return;
}

void mpadd(int* ret, int* a, int* b){
    int la = *a;
    int lb = *b;
    int lr = (la >= lb) ? la : lb;
    int* rr = ret;
    int x = 0;
    for(int i=1; i<= lr; i++){
        if(i <= la) x += *++a;
        if(i <= lb) x += *++b;
        if(x < N){
            *++rr = x;
            x = 0;
        }else{
            *++rr = x - N;
            x = 1;
        }
    }
    *++rr = x;
    *ret = lr + x;
    return;
}

void mpnum2str(char* str, int* num){
    if(*num == 0){
        *str++ = '0';
        *str = '\0';
        return;
    }
    char* ss = str - 1;
    int x;
    for(int i=*num; i>0; i--){
        x = *++num;
        for(int j=1; j<N; j*=10){
            *++ss = x%10 + '0';
            x /= 10;
        }
    }    while(*ss == '0') ss--;
    *(ss+1) = '\0';
    while(str < ss){
        x = *str;
        *str++ = *ss;
        *ss-- = x;
    }
    return;
}

int main(){
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a >> b;
        if(strlen(a) > 80 || strlen(b) > 80){
            cout << "overflow" << endl;
            continue;
        }
        mpstr2num(anum, a);
        mpstr2num(bnum, b);
        mpadd(resultnum, anum, bnum);
        mpnum2str(result, resultnum);
        if(strlen(result) > 80){
            cout << "overflow" << endl;
            continue;
        }else{
            cout << result << endl;
        }
    }
    return 0;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), pena(n);

  for (int i = 0; i < m; i++) {
    int p;
    string s;
    cin >> p >> s;
    --p;
    if (ac[p]) {
      continue;
    }
    if (s == "AC") {
      ac[p] = 1;
    } else {
      pena[p]++;
    }
  }
  int ans_ac = 0, ans_pena = 0;
  for (int i = 0; i < n; i++) {
    ans_ac += ac[i];
    if (ac[i]) {
      ans_pena += pena[i];
    }
  }
  cout << ans_ac << " " << ans_pena << endl;

  return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    vector<pair<ll, ll>> shop;
    REP(i, N) shop.push_back(make_pair(A[i], B[i]));
    sort(shop.begin(), shop.end());

    ll ans = 0;
    ll count = 0;
    for(auto iter = shop.begin(); iter != shop.end(); ++iter)
    {
        ll price = (*iter).first;
        ll stock = (*iter).second;
        if (count < M) 
        {
            if (count + stock <= M)
            {
                ans += price * stock;
                count += stock;
            }
            else 
            {
                ans += price * (M - count);
                count += M - count;
            }
        }
        else
        {
            break;
        }
        
    }

    cout << ans << endl;
}


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

int main()
{
  int N,X ;
  cin>>N>>X ;
  int L[N+1] ;
  for(int i=0;i<N+1;i++) cin>>L[i] ;
  
  int D[N] ;
  D[0]=0 ;
  int count=0 ;
  for(count=1;count<N+1;count++){
    D[count]=D[count-1]+L[count-1] ;
    if(D[count]>X) break ;
  }
  cout<<count<<endl ;
  return 0 ;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()

    table = [False]*n

    ans = 0
    for index, i in enumerate(t[:k]):

        if i == 'r':
            ans += p
            table[index] = True
        elif i == 'p':
            ans += s
            table[index] = True
        elif i == 's':
            ans += r
            table[index] = True

    for index, (i, j) in enumerate(zip(t[k:], t)):
        if i == j:
            if table[index]:
                table[index+k] = False
                continue
        if i == 'r':
            ans += p
            table[index+k] = True
        elif i == 'p':
            ans += s
            table[index+k] = True
        elif i == 's':
            ans += r
            table[index+k] = True
    print(ans)


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    reverse(all(s));
    if (p % 2 == 0 || p % 5 == 0) {
        ll ans = 0;
        rep(i, 0, n) {
            if ((s[i] - '0') % p == 0) {
                ans += n - i;
            }
        }
        cout << ans << endl;
        return 0;
    }
    int mod[n + 1] = {};
    mod[0] = 1;
    int pw = 1;
    rep(i, 0, n) {
        mod[i + 1] = (mod[i] + pw * (s[i] - '0')) % p;
        pw *= 10;
        pw %= p;
    }
    map<ll, ll> mp;
    rep(i, 0, n + 1) {
        mp[mod[i]]++;
    }
    ll ans = 0;
    for (auto i : mp) {
        ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1796
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){
        int L[3];
        for (int i = 0; i < 3; i++) {
                scanf("%d", &L[i]);
        }
        if (L[1]>L[2]) {
                int tmp;
                tmp=L[1];
                L[1]=L[2];
                L[2]=tmp;
        }
        if ( L[2] <= L[0]+L[1]) {
                printf("0\n");
                return 0;
        }else{
                printf("%d\n",L[2]-L[1]-L[0]);
                return 0;
        }
}

Measured memory_bytes: 128
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>


typedef long long llong;
using namespace std;
#define MAX 100010

int main() {
	string number_A;
	string number_B;
	string sum;
	int N;
	int sum_size;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> number_A;
		cin >> number_B;
		if (number_A.size() > 80 || number_B.size() > 80)cout << "overflow\n";
		else {
			sum_size = max(number_A.size(), number_B.size());
			sum.resize(sum_size);
			while (number_A.size() != sum_size) {
				number_A.insert(0, "0");
			}
			while (number_B.size() != sum_size) {
				number_B.insert(0, "0");
			}
			for (int j = 0; j < min(number_A.size(), number_B.size()); j++) {
				sum[j] = number_A[j]-48 + number_B[j];
			}
			for (int j = sum_size-1; j >=0; j--) {
				if (sum[j]>57) {
					sum[j] -= 10;
					if(j!=0) sum[j - 1] += 1;
					else sum.insert(0, "1");
				}
			}
			if (sum.size() > 80) cout << "overflow\n";
			else cout << sum << endl;


		}
	}

	return 0;
}
 


Measured memory_bytes: 3064
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

a = [v[i] for i in range(n) if i % 2]
b = [v[i] for i in range(n) if i % 2 == 0]
aa = Counter(a)
bb = Counter(b)
ans = 0

aas = sorted(aa.keys(), key=lambda key:aa[key], reverse=True)
bbs = sorted(bb.keys(), key=lambda key:bb[key], reverse=True)
if aas[0] != bbs[0]:
    ans += len(a) - aa[aas[0]]
    ans += len(b) - bb[bbs[0]]
else:
    if len(aa) == len(bb) and len(aa) == 1 and a[0] == b[0]:
        ans += min(len(a), len(b))
    else:
        s = len(a) - aa[aas[0]] + len(b) - bb[bbs[1]]
        t = len(a) - aa[aas[1]] + len(b) - bb[bbs[0]]
        ans = min(s,t)

print(ans)


Measured memory_bytes: 19040
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a) for(int i=lst[a];i;i=nxt[i])
using namespace std;

typedef long long ll;

const int N=2e3+10,M=2e4+10,inf=0x7fffffff;

int t[M],f[M],v[M],nxt[M],lst[N],l;

void add(int x,int y,int z,int c) {
	t[++l]=y;f[l]=z;v[l]=c;nxt[l]=lst[x];lst[x]=l;
	t[++l]=x;f[l]=0;v[l]=-c;nxt[l]=lst[y];lst[y]=l;
}

int n,S,T,t1,t2,t3,t4,x,y,c,q[M],pre[N];
ll dis[N],ans=0;
bool vis[N];

bool spfa() {
	fo(i,S,t4) dis[i]=-1e12;dis[S]=0;
	int i=0,j=1;q[1]=S;vis[S]=1;
	while (i<j) {
		rep(k,q[++i])
			if (f[k]&&dis[t[k]]<dis[q[i]]+v[k]) {
				dis[t[k]]=dis[q[i]]+v[k];pre[t[k]]=k;
				if (!vis[t[k]]) vis[t[k]]=1,q[++j]=t[k];
			}
		vis[q[i]]=0;
	}
	return dis[T]>-1e12;
}

void find() {
	int flow=inf;
	for(int x=T;x!=S;x=t[pre[x]^1]) flow=min(flow,f[pre[x]]);
	for(int x=T;x!=S;x=t[pre[x]^1]) {
		f[pre[x]]-=flow;f[pre[x]^1]+=flow;
		ans+=(ll)flow*v[pre[x]];
	}
}

int main() {
	scanf("%d",&n);l=1;
	S=0;T=(n<<1)+1;t1=T+1;t2=t1+1;t3=t2+1;t4=t3+1;
	fo(i,1,n) {
		scanf("%d%d%d",&x,&y,&c);
		add(S,i,c,0);
		add(i,t1,inf,x+y);
		add(i,t2,inf,x-y);
		add(i,t3,inf,-x+y);
		add(i,t4,inf,-x-y);
	}
	fo(i,1,n) {
		scanf("%d%d%d",&x,&y,&c);
		add(i+n,T,c,0);
		add(t1,i+n,inf,-x-y);
		add(t2,i+n,inf,-x+y);
		add(t3,i+n,inf,x-y);
		add(t4,i+n,inf,x+y);
	}
	while (spfa()) find();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
"use strict";
function Main(input) {
  // 最終的に回答を格納するための変数
  let sum = 0;
  // カウンター
  let i = 1;
  // inputをどんどん半分にしていき1になったら終了
  while(input != 1){
    // カウンターを足算していく
    sum += i;
    // inputを切り捨てで2分に1にする
    input = Math.floor(input/2);
    // カウンターを2倍にする
    i *= 2;
  }
  // sumを2倍にして最初の1回分足したものが答え
  console.log(sum * 2 + 1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 7372
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Main{
    static int grundy(int v, int pare){
        int res = 0;
        for(int u : Edge[v])if(u!=pare)res^=(1+grundy(u,v));
        return res;
    }

    static List<Integer> Edge[];
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        Edge = new ArrayList[N];
        for(int i=0;i<N;++i)Edge[i]=new ArrayList<>();
        for(int i=0;i<N-1;++i){
            int x = scan.nextInt()-1;
            int y= scan.nextInt()-1;
            Edge[x].add(y);
            Edge[y].add(x);
        }
        if(grundy(0,-1)==0){
            System.out.println("Bob");
        }else{
            System.out.println("Alice");
        }
    }
}

Measured memory_bytes: 112624
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<CityInfo>cityInfoList = new ArrayList<CityInfo>();

		for(int i =0;i < m;i++) {
			CityInfo cityInfo = new CityInfo(i,sc.nextInt(),sc.nextInt());
			cityInfoList.add(cityInfo);
		}
		cityInfoList.sort((a,b) ->{
			if(a.getKen() == b.getKen()) {
				return a.getYear() - b.getYear();
			}else {
				return a.getKen() - b.getKen();
			}
		});
		int number = 1;
		for(int i =0;i < cityInfoList.size();i++) {
			if(i ==0) {
				cityInfoList.get(i).setBirthNumber(number);
				continue;
			}
			if(cityInfoList.get(i).getKen() ==cityInfoList.get(i-1).getKen()) {
				number++;
				cityInfoList.get(i).setBirthNumber(number);
			}else {
				number = 1;
				cityInfoList.get(i).setBirthNumber(number);
			}
		}
		cityInfoList.sort((a,b) ->{
			return a.getId() - b.getId();
		});
		for(CityInfo cityInfo: cityInfoList) {
			StringBuilder answer = new StringBuilder();
			String ken = String.valueOf(cityInfo.getKen());
			for(int i = 0;i <6-ken.length();i++) {
				answer.append("0");
			}
			answer.append(ken);
			String birthNumber = String.valueOf(cityInfo.getBirthNumber());
			for(int i = 0;i <6-birthNumber.length();i++) {
				answer.append("0");
			}
			answer.append(birthNumber);
			System.out.println(answer);
		}
	}
	private static class CityInfo{
		private int id;
		private int ken;
		private int year;
		private int birthNumber;
		public CityInfo(int id,int ken,int year) {
			this.id = id;
			this.ken = ken;
			this.year = year;
		}
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public int getKen() {
			return ken;
		}
		public void setKen(int ken) {
			this.ken = ken;
		}
		public int getYear() {
			return year;
		}
		public void setYear(int year) {
			this.year = year;
		}
		public int getBirthNumber() {
			return birthNumber;
		}
		public void setBirthNumber(int birthNumber) {
			this.birthNumber = birthNumber;
		}

	}
}

Measured memory_bytes: 110060
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
int solve(int a[],int n){
	int dp[n+1];
  	dp[1]=0;
    for(int i=2;i<=n;i++){
      int option1=abs(a[i]-a[i-1])+dp[i-1];
      int option2=(i==2)?inf:abs(a[i]-a[i-2])+dp[i-2];
      dp[i]=min(option1,option2);
    }
    return dp[n];
}
int main(){
	int n;
  	cin>>n;
    int a[n+1];
  	for(int i=1;i<=n;i++)cin>>a[i];
  	cout<<solve(a,n)<<endl;
	return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	int x = n * 800;
	int y = (n / 15) * 200;
	cout << x - y << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();

        int res = 0;
        for (int i = 0; i <= n - 3; i++) {
            if("ABC".equals(s.substring(i, i + 3))){
                res++;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 23636
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 10**9 + 7
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    K = NI()
    S = SI()
    LS = len(S)

    f = [0] * (K+LS)
    r = [0] * (K+LS)
    f[0] = 1
    r[0] = 1
    c = 1
    for i in range(1, K + LS):
        c = (c * i) % MOD
        f[i] = c
        r[i] = pow(c, MOD - 2, MOD)

    def comb(n, k):
        return (f[n] * r[k] * r[n - k]) % MOD

    ans = 0
    for i in range(K+1):
        ans = (ans + pow(25,i,MOD) * pow(26,K-i,MOD) * comb(i+LS-1,LS-1)) % MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 109132
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

ll n,i,k;cin>>n>>k;
ll a[n];for(i=0;i<n;i++) cin>>a[i];
sort(a,a+n,greater<int>());
ll s=0;
for(i=k;i<n;i++) s+=a[i];
cout<<s;


return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
    int a[10000],min,max,n,i;
    long long sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    max=min=a[0];
    for(i=1;i<n;i++){
        if(a[i]>max)max=a[i];
        if(a[i]<min)min=a[i];
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}


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

public class Main{
	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//int n = Integer.parseInt(br.readLine());
		 Scanner scan = new Scanner(System.in);
	        int n = scan.nextInt();
		// 1オリジンの配列を用いる
		int []A = new int[n + 1];
		int []B = new int[n + 1];
		int max = 0;
		//Arrays.fill(A, 0);
		//String s = br.readLine();


		for(int i = 1; i <= n; i++) {
			int k = scan.nextInt();
			A[i] = k;
			max = Math.max(max, k);
		}
		scan.close();
		//br.close();
//		String []A1 = s.split(" ");
//		for(int i = 0; i < n; i++) {
//			//int k = Integer.parseInt(A1[i]);
//			int k = new Integer(A1[i]).intValue();
//			A[i + 1] = k;
////			if(max < k) {
////				max = k;
////			}
//			max = Math.max(max, k);
//		}

		CountingSort(A, B, max, n);
		StringBuilder sb = new StringBuilder();
		sb.append(B[1]);
		for(int i = 2; i <= n; i++) {
			sb.append(' ').append(B[i]);
		}
		System.out.println(sb);
	}
	public static void CountingSort(int[] A, int[] B, int k, int n) {
		int []C = new int[k + 1];
		Arrays.fill(C, 0);
		for(int j = 1; j <= n; j++) {
			C[A[j]] ++;
		}
		for(int i = 1; i <= k; i++) {
			C[i] = C[i] + C[i - 1];
		}
		for(int j = n; j >= 1; j--) {
			B[C[A[j]]] = A[j];
			C[A[j]] --;
		}
	}
}


Measured memory_bytes: 515132