akhauriyash/Code-Regression huggingface dataset:
use std::cmp;

fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { reader: sc.lock() };

    let n = sc.read();
    let mut abc: Vec<Vec<u32>> = vec![vec![0; 3]; n];
    for i in 0..n {
        for w in 0..3 {
            abc[i][w] = sc.read();
        }
    }

    let mut dp = vec![vec![0; 3]; n + 1];
    for i in 0..n {
        for prev in 0..3 {
            for next in 0..3 {
                if prev == next {
                    continue;
                }
                dp[i + 1][next] = cmp::max(dp[i + 1][next], dp[i][prev] + abc[i][next]);
            }
        }
    }

    let mut ans = 0;
    for i in 0..3 {
        ans = cmp::max(ans, dp[n][i]);
    }
    println!("{}", ans);
}

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

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


Measured memory_bytes: 14588
//   PIGMEISTER™   //

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

#define ll long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define MAX 100005

int main()
{
    jaldi;
    
    ll n, k;
    cin >> n >> k;
    ll a[n+1];
    sidha (i, 1, n+1) cin >> a[i];

    ll vis[n+1] = {0};
    ll cur = 1;
    vector<ll> v;
    while (!vis[cur]) {
        vis[cur] = 1;
        v.push_back(cur);
        cur = a[cur];
    }
    ll pos = 0;
    for (auto i : v) {
        if (i == cur) {
            break; 
        }
        ++pos;
    }

    ll loop = v.size()-pos;
    if (k < pos) {
        cout << v[k];
    }
    else {
        k -= pos;
        k %= loop;
        cout << v[pos+k];
    }
    
    return 0;
}


Measured memory_bytes: 8424
#include <cstdio>

using ll = long long;

const ll mod = 1e9+7;

ll N, M;
ll x[100001], y[100001], yy;

ll ans = 0;

int main () {
    scanf("%lld %lld", &N, &M);

    for(int n = 0; n < N; n++)
        scanf("%lld", x + n);
    for(int m = 0; m < M; m++)
        scanf("%lld", y + m);
    N--, M--;
    for(int m = 0; m < M; m++)
        (yy += (y[m+1] - y[m]) * (m+1) % mod * (M-m) % mod) %= mod;
    for(int n = 0; n < N; n++)
        (ans += (x[n+1] - x[n]) * (n+1) % mod * (N-n) % mod * yy % mod) %= mod;

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(10**8)
def f(v,p,G,T):
    global ans
    INF = 10**10
    for C in G[v]:
        c,d = C[0],C[1]
        if T[c]==INF:
            T[c] = T[v]+d
            f(c,v,G,T)
        elif T[c]!=T[v]+d:
            ans = "No"
def main():
    global ans
    N,M = map(int,input().split())
    G = [[] for i in range(N+1)]
    for i in range(M):
        L,R,D = map(int,input().split())
        G[L].append([R,D])
        G[R].append([L,-D])
    INF = 10**10
    T = [INF]*(N+1)
    while T.count(INF)!=0:
        for i in range(N+1):
            if T[i] == INF:
                T[i]=0
                f(i,-1,G,T)
        if ans=="No":break
ans = "Yes"
main()
print(ans)

Measured memory_bytes: 136616
n = int(input())
moneys = []
for i in range(n):
    x, y = input().split()
    x = float(x)
    if y == "JPY":
        y = 1.0
    else:
        y = 380000.0
    money = x*y
    moneys.append(money)
print(sum(moneys))

Measured memory_bytes: 38256
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);


int main()
{
    IOS();
    ll n,a,b;
    cin>>n>>a>>b;
    if(abs(a-b)%2==0)cout<<"Alice"<<endl;
    else cout<<"Borys"<<endl;
}


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

int main ()
{
 	int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  bool flag = true;
  
  while (a > 0 && c > 0){
    if (flag) {
    	c -= b;
    }
    else {
     	a -= d; 
    }
      flag=!flag;
  }
  
  if (a <= 0) cout << "No" << endl;
  else cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 3604
object Main {
  def main(args: Array[String]) {
    val stdLineInputAry = io.StdIn.readLine().split(" ")

    val tate = stdLineInputAry(0).toInt
    val yoko = stdLineInputAry(1).toInt
    val menseki = tate * yoko
    val syuu = (tate * 2) + (yoko * 2)
    println(menseki + " " + syuu)
  }
}

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

#define long long ll;

bool compare(pair<int,int> a, pair<int,int> b)
{
    return a.first<b.first;
}
int main()
{
    
    int a,b;
    cin>>a>>b;
    
    if(a>=13)
    cout<<b<<endl;
    else if(a>5)
    cout<<b/2<<endl;
    else
    cout<<0<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
//agc004_a.cpp
//Sat Nov  3 10:04:31 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll a,b,c;
	cin >> a >> b >> c;

	if (a%2==0 || b%2==0 || c%2==0){
		cout << 0 << endl;
	}else{
		ll ans = a*b;
		if (b*c < ans){
			ans = b*c;
		}
		if (c*a < ans){
			ans = c*a;
		}
		cout << ans << endl;
	}


}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }

    println!("{}", min(a,b)+min(c,d));

}


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

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

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


int main(){
	int N; cin >> N;
	vector<int> A(N),B(N);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	vector<int> C(N);
	rep(i,N) C[i] = A[i]-B[i];
	sort(C.begin(),C.end(),greater<int>());
	ll cnt = 0;
	int ans = 0;
	rep(i,N){
		if(A[i] < B[i]) cnt += B[i]-A[i],ans++;
	}
	if(cnt == 0){
		cout << 0 << endl;
		return 0;
	}
	ll sum = 0;
	rep(i,N){
		sum += C[i];
		ans++;
		if(sum >= cnt){
			cout << ans << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}



Measured memory_bytes: 1408
# ABC-141-D
# https://qiita.com/ellio08/items/fe52a9eb9499b7060ed6
import heapq

N, M = map(int, input().split())
A = [i * (-1) for i in list(map(int, input().split()))]
heapq.heapify(A)

for _ in range(M):
    tmp = heapq.heappop(A) * (-1)
    heapq.heappush(A, (tmp//2)*-1)

# これだとTLEになる。
# for _ in range(M):
#     A[A.index(max(A))] //= 2

print(sum(A)*-1)

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

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);

    int w,h,n;
    cin>>w>>h>>n;
    int mi_x =0 , mi_y =0 , ma_x =w , ma_y=h;
    while(n--)
    {
        int x,y,a;
        cin>>x>>y>>a;

        if(a==1) mi_x=max(mi_x,x);

        if(a==2) ma_x=min(ma_x,x);

        if(a==3) mi_y=max(mi_y,y);

        if(a==4) ma_y=min(ma_y,y);

    }

    if(ma_x <= mi_x || ma_y <= mi_y) cout<<0;
    else cout<<(ma_x - mi_x)*(ma_y - mi_y);

    return 0;
}




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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        int _h;
        cin >> _h;
        h[i] = _h;
    }

    vector<int> dp(n);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        if (i < 2)
        {
            dp[i] = dp[i - 1] + abs(h[i - 1] - h[i]);
        }
        else
        {
            dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
        }
    }
    cout << dp.back() << endl;
}

int main(void)
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}


Measured memory_bytes: 4032
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    int n=0;
    scanf("%d",&n);
    int a[n+1];
    int b[n+1];
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[i]=i;
    }
   vector<pair<int,int>> p(n);
   for(int i=0;i<n;i++){
       p[i]=make_pair(a[i+1],b[i+1]);
   }
    sort(p.begin(),p.end());


    for(int k=0;k<n;k++){
        printf("%d\n",p[k].second);
    }
}

Measured memory_bytes: 2432
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000;

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) {
  if (a + b == a || a + b == b) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

int main(void) {
  ll a, b; cin >> a >> b;
  cout << a * b / gcd(a, b) << endl;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
a = list(map(int,input().split()))
s = np.zeros(n+1)
for i in a:
    s[i]+=1
al = sum((s*(s-1))/2)
for i in range(n):
    ans=al-(s[a[i]]-1)
    print(int(ans))

Measured memory_bytes: 51564
/* ***********************************************
Author        :Tisuama
Created Time  :2017年09月10日 星期日 14时41分46秒
File Name     :B.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
int n;
struct node{
    int l,r;
}A[1100];
int cmp(node a,node b)
{
    if(a.l==b.l)
        return a.r<b.r;
    return a.l<b.l;
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&A[i].l,&A[i].r);
        sort(A,A+n,cmp);
        int sum=0;
        int l=0,r=0;
        while(r<n)
        {
            int rmax=A[l].r;
            while(r<n&&A[l].r>=A[r].l)
            {
                rmax=max(rmax,A[r].r);
                r++;
            }
            sum+=rmax-A[l].l+1;
            if(r==n)
                break;
            l=r;

        }
        printf("%d\n",sum);
    }
}


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

using namespace std;

//#define FILE_IO

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    //freopen("1.out", "w", stdout);
    #endif

    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for(int r = 0; r * R <= N; r++)
        for(int g = 0; r * R + g * G <= N; g++)
        {
            int b = (N - r * R - g * G) / B;
            if( (r * R + g * G + b * B) ==  N ) ans++;
        }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n,a,b;
int main()
{
    scanf("%d",&n);
    for(int i = 1 ; i <= sqrt(n) ; i++)
	{
        a = i, b = n / i;
        if(a * b == n && a > 0 && a <= 9 && b > 0 && b <= 9)
		{
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
ll v[110],w[110];
ll dp[110][10010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,W;
  cin >> N >> W;
  rep(i,N){
    cin >> v[i] >> w[i];
  }
  rep(i,N){
    rep(j,W+1){
      if(j - w[i] >= 0){
        dp[i+1][j] = max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
      }
      else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  cout << dp[N][W]<<endl;
  return 0;
}

Measured memory_bytes: 11008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            char result = 'd';
            for (int i = 0; i < patterns.length; i++) {
                int[] pattern = patterns[i];
                char ch = line.charAt(pattern[0]);
                if (ch == 's') {
                    continue;
                }
                if (ch == line.charAt(pattern[1])
                        && ch == line.charAt(pattern[2])) {
                    result = ch;
                    break;
                }
            }
            out.println(result);
        }
    }

    private static final int[][] patterns = { { 0, 1, 2 }, { 3, 4, 5 },
            { 6, 7, 8 }, { 0, 3, 6 }, { 1, 4, 7 }, { 2, 5, 8 }, { 0, 4, 8 },
            { 2, 4, 6 } };
}

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

int main(){
    int n; cin >> n;
    vector<ll> A(n);
    ll ans=0;
    for (int i=0;i<n;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    for (int i=0;i<n-2;i++){
        ll a=A[i];
        for (int j=i+1;j<n-1;j++){
            if (A[i]==A[j]) continue;
            ll s=A[i]-A[j];
            for (int k=j+1;k<n;k++){
                if (A[j]==A[k]) continue;
                if (A[k]>s) ans++;
            }
        }
    }
    cout << ans << "\n";
}



Measured memory_bytes: 3556
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int ans=0;

void dfs(ll x,bool a,bool b,bool c,ll n){
  if(a&&b&&c){
    ans++;
  }
  if(x*10+3<=n)
  dfs(x*10+3,1,b,c,n);
  if(x*10+5<=n)
  dfs(x*10+5,a,1,c,n);
  if(x*10+7<=n)
  dfs(x*10+7,a,b,1,n);
}

int main(){
  ll n; cin>>n;
  dfs(0,0,0,0,n);
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

map <int,int> m;

int main()
{
    int n,l;
    cin >> n >> l;

    vector <string> v;
    string s;

    for(int i=0;i<n;i++)
    {
        cin >> s;
        v.push_back(s);
    }

    sort(v.begin(),v.end());

    for(int i=0;i<n;i++)
        cout << v[i];
    cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

typedef i32 deque_val;

typedef struct Deque {
  deque_val *array;
  size_t front;
  size_t last;
  size_t mask;
} deque;

deque* new_deque (void) {
  const size_t len = 2;
  deque *d = (deque *) calloc (len, sizeof (deque));
  d->array = (deque_val *) calloc (len, sizeof (deque_val));
  d->front = d->last = 0;
  d->mask = len - 1;
  return d;
}

void init_deque (deque * const d) {
  d->front = d->last = 0;
}

void free_deque (deque * const d) {
  free (d->array);
  free (d);
}

int is_empty (const deque *d) {
  return d->front == d->last;
}

size_t get_size (const deque *d) {
  return (d->last + (~d->front + 1)) & d->mask;
}

void deque_realloc (deque * const d) {
  deque_val *array = (deque_val *) calloc (2 * (d->mask + 1), sizeof (deque_val));
  size_t k = 0;
  for (size_t i = d->front; i != d->last; i = (i + 1) & d->mask) {
    array[k++] = d->array[i];
  }
  free (d->array);
  d->array = array;
  d->front = 0;
  d->last = k;
  d->mask = 2 * d->mask + 1;
}

deque_val pop_front (deque * const d) {
  deque_val res = d->array[d->front];
  d->front = (d->front + 1) & d->mask;
  return res;
}

deque_val pop_back (deque * const d) {
  d->last = (d->last + d->mask) & d->mask;
  return d->array[d->last];
}

deque_val get_front (const deque *d) {
  return d->array[d->front];
}

deque_val get_back (const deque *d) {
  return d->array[(d->last + d->mask) & d->mask];
}

void push_front (deque * const d, const deque_val v) {
  if(((d->last + 1) & d->mask) == d->front) {
    deque_realloc (d);
  }
  d->front = (d->front + d->mask) & d->mask;
  d->array[d->front] = v;
}

void push_back (deque * const d, const deque_val v) {
  if(((d->last + 1) & d->mask) == d->front) {
    deque_realloc (d);
  }
  d->array[d->last] = v;
  d->last = (d->last + 1) & d->mask;
}

void run (void) {
  i32 mod;
  scanf ("%" SCNi32, &mod);
  i32 *dp = (i32 *) calloc (mod, sizeof (i32));
  for (i32 i = 0; i < mod; ++i) {
    dp[i] = mod;
  }
  dp[1] = 1;
  deque *d = new_deque();
  push_back (d, 1);
  while (!is_empty (d)) {
    i32 v = pop_front (d);
    i32 u = 10 * v % mod;
    if (dp[u] > dp[v]) {
      dp[u] = dp[v];
      push_front (d, u);
    }
    u = (v + 1) % mod;
    if (dp[u] > dp[v] + 1) {
      dp[u] = dp[v] + 1;
      push_back (d, u);
    }
  }
  printf ("%" PRIi32 "\n", dp[0]);
}

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


Measured memory_bytes: 896
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int height[n];
	for(int i = 0; i<n;i++){
		cin>>height[i];
	}
	int cost[n];
	cost[0] = 0;
	cost[1] = abs(height[1] - height[0]);
	for(int i = 2;i<n;i++){
		cost[i] = min(cost[i-1] + abs(height[i]-height[i-1]) , cost[i-2] + abs(height[i] - height[i-2]));
	}
	cout<<cost[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
s = input()

def solve(s):
    while len(s) > 0:
        if s[-5:] == 'dream':
            s = s[:-5]
        elif s[-7:] == 'dreamer':
            s = s[:-7]
        elif s[-5:] == 'erase':
            s = s[:-5]
        elif s[-6:] == 'eraser':
            s = s[:-6]
        else:
            print('NO')
            return 
    print('YES')
    return

solve(s)


Measured memory_bytes: 3316
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int A,B;
	scanf("%d%d",&A,&B);
	if(B%A==0) printf("%d\n",A+B);
	else printf("%d\n",B-A);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
string ch;
int a;
while(1)
{a=0;
cin>>ch;
if(ch=="0") break;
int ren=ch.size();
for(int i=0;i<ren;i++)
	{
	a+=ch[i]-'0';
	}
cout<<a<<endl;
}
return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
int main()
{
	int n;
	cin >> n;
	int* d = new int[n];

	if (n % 2 == 1) {
		cout << 0;
		return 0;
	}
		

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

	std::sort(d, d + n);

	cout << d[n / 2] - d[n / 2 - 1];
	return 0;
}



Measured memory_bytes: 640
import math
A, B, H, M = map(int, input().split())
tyousin = M*360/60
tansin = (H*60+M)*360/(12*60)
deg = abs(tyousin-tansin)
if deg >= 180:
    deg = 360-deg

c2 = A*A+B*B-2*A*B*math.cos(math.radians(deg))
print(math.sqrt(c2))


Measured memory_bytes: 9440
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 210000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long dp[1100][21000];
struct wolf{
	int w,s,v;
	wolf(){w=s=v=0;}
	wolf(int W,int S,int V){w=W;s=S;v=V;}
};
inline bool operator<(const wolf&a,const wolf&b){
	return a.s+a.w<b.s+b.w;
}
wolf p[1100];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		int w,s,v;
		scanf("%d%d%d",&w,&s,&v);
		p[i]=wolf(w,s,v);
	}
	std::sort(p,p+a);
	for(int i=0;i<a;i++){
		for(int j=0;j<=p[i].s;j++){
			
			dp[i+1][j+p[i].w]=max(dp[i+1][j+p[i].w],dp[i][j]+p[i].v);
		}
		for(int j=0;j<21000;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
		}
	}
	long long ret=0;
	for(int i=0;i<21000;i++){
		ret=max(ret,dp[a][i]);
	}
	printf("%lld\n",ret);
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  int minv = 2000000000;
  int maxv = -2000000000;
  for (int x : v) {
    maxv = max(maxv, x - minv);
    minv = min(minv, x);
  }
  cout << maxv << endl;
  return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,a,b;cin>>n>>a>>b;
    ll ans =  ( n/(a+b) )*a;
    n%=(a+b);
    ans+=min(n,a);
    cout<<ans;
}






Measured memory_bytes: 256
def gcd(a, b):
  return gcd(b, a%b) if b else a

def lcm(a, b):
  return a*b//gcd(a, b)

a, b, c, d = list(map(int, input().split()))
ttt = lcm(c, d)
tt = b-a+1
ta = b//c - (a-1)//c
tb = b//d - (a-1)//d
tc = b//ttt - (a-1)//ttt
print(tt-ta-tb+tc)

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int w,h,n;
	cin >> w >> h >> n;
	int flag[h][w] = {};
	for(int k = 0; k < n; k++){
		int x,y,a;
		cin >> x >> y >> a;
		if(a == 1){
			for(int i = 0; i < h; i++){
				for(int j = 0; j < x; j++){
					flag[i][j] = 1;
				}
			}
		}else if(a == 2){
			for(int i = 0; i < h; i++){
				for(int j = x; j < w; j++){
					flag[i][j] = 1;
				}
			}
		}else if(a == 3){
			for(int i = 0; i < y; i++){
				for(int j = 0; j < w; j++){
					flag[i][j] = 1;
				}
			}
		}else{
			for(int i = y; i < h; i++){
				for(int j = 0; j < w; j++){
					flag[i][j] = 1;
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(!flag[i][j]) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    int c = b - a - 1;
    int s = 0;
    for (int i = 1; i <= c; ++i) {
        s += i;
    }
    cout << s - a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
template <typename T>
void ivec(vector<T> &v, ll N){
    REP(i,0,N){ T x; cin >> x; v.push_back(x); }
}


int main(){
    ll H, N;
    cin >> H >> N;

    vector<ll> dp(20202, 1E9);
    dp[0]=0;
    REP(i,0,N){
        ll a, b;
        cin >> a >> b;
        REP(j,0,H){
            dp[j+a]=min(dp[j+a], dp[j]+b);
        }
    }
    cout << *min_element(dp.begin() + H, dp.end()) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) {
        cin >> s.at(i);
    }
    FOR(h, 0, H) {
        FOR(w, 0, W) {
            if (s.at(h).at(w) == '.') { continue; }
            if ((0 <= h - 1) && (s.at(h - 1).at(w) == '#')) {
                continue;
            } else if ((0 <= w - 1) && (s.at(h).at(w - 1) == '#')) {
                continue;
            } else if ((w + 1 < W) && (s.at(h).at(w + 1) == '#')) {
                continue;
            } else if ((h + 1 < H) && (s.at(h + 1).at(w) == '#')) {
                continue;
            } else {
                cout << "No" << endl;
                exit(0);
            }
        }
    }
    cout << "Yes" << endl;
}


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

int main(){
    long long A,B,C;
    cin >> A >> B >> C;
    if(A%2==0||B%2==0||C%2==0){
        cout << 0 << endl;
    }else{
        long long ans1,ans2,ans3;
        ans1=abs((A/2)*B*C-(A-A/2)*B*C);
        ans2=abs((B/2)*A*C-(B-B/2)*A*C);
        ans3=abs((C/2)*B*A-(C-C/2)*B*A);
        cout << min(ans1,min(ans2,ans3)) << endl;
    }
}

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

typedef long long ll;
typedef long double ld;

#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)


int main(){  
  int N; cin >> N;
  
  vector<string> s(N);
  vector<int> P(N);
  rep(i, N) cin >> s.at(i) >> P.at(i);
  
  vector<int> q(N);
  rep(i, N) q.at(i) = i;
  
  int tempo_i;
  string tempo_s;
  
  if(N>=2){
    for(int i=0; i<=N-2; i++){
      for(int j = i+1; j<=N-1; j++){
        if((s.at(i) > s.at(j)) || (s.at(i) == s.at(j) && P.at(i) < P.at(j))){
          tempo_s = s.at(j); s.at(j) = s.at(i); s.at(i) = tempo_s;
          tempo_i = P.at(j); P.at(j) = P.at(i); P.at(i) = tempo_i;
          tempo_i = q.at(j); q.at(j) = q.at(i); q.at(i) = tempo_i;
        }
      }
    }
  }
  
  
  
  rep(i, N) cout << q.at(i) + 1 << endl;
      

  
  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define NMAX 110000
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

ll n,m;

vector<vector<int>> blist;
void dfs(int i, vector<int>& v){
    if(i<n){
        vector<int> v1(v.size());
        for(int j=0; j<v.size(); j++) v1[j] = v[j];
        dfs(i+1,v);
        v1.push_back(i);
        dfs(i+1,v1);
    }
    else{
        blist.push_back(v);
        v.clear();
    }
}

int main()
{	
    cin >> n >> m;
    vector<ll> k(m), p(m);
    vector<vector<ll>> s(m);
    for(int i=0; i<m; i++){
        cin >> k[i];
        s[i].resize(k[i]);
        for(int j=0; j<k[i]; j++) cin >> s[i][j];
    }
    for(int i=0; i<m; i++) cin >> p[i];

    vector<int> tmp;
    dfs(0,tmp);

    vector<vector<bool>> onoff(blist.size());
    vector<bool> v;
    for(int i=0; i<blist.size(); i++){
        v.assign(n,false);
        for(int j=0; j<blist[i].size(); j++){
            v[blist[i][j]] = true;
        }
        onoff[i] = v;
    }

    bool success;
    ll ans(0);
    for(int l=0; l<onoff.size(); l++){
        success = true;
        for(int i=0; i<m; i++){
            ll num(0);
            for(int j=0; j<k[i]; j++) if(onoff[l][s[i][j]-1]) num ++;
            if(num%2!=p[i]) success = false;
        }
        if(success) ans ++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;

struct UnionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
} uft(200000);

int main() {
    int n, m;
    cin >> n >> m;
    vi p(n);
    rep(i, n ) {
        cin >> p[i];
        --p[i];
    }
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        uft.unite(p[x], p[y]);
    }

    int ans = 0;
    rep(i, n) {
        ans += (uft.same(i, p[i]));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
ARC103 C
"""

n = int(input())
vli = list(map(int,input().split()))

evli = vli[::2]
ovli = vli[1::2]

from collections import Counter
Cevli = Counter(evli).most_common(2)
Covli = Counter(ovli).most_common(2)

vem,iem=Cevli[0]
vom,iom=Covli[0]

if vem!=vom:
    ans = n-iem-iom
elif iem == n//2 and iom == n//2:
    ans = n//2
elif iem == n//2:
    vom2,iom2=Covli[1]
    ans = n-n//2-iom2
elif iom == n//2:
    vem2,iem2=Cevli[1]
    ans = n-n//2-iem2
else:
    vem2,iem2=Cevli[1]
    vom2,iom2=Covli[1]
    ans1 = n-iem-iom2
    ans2 = n-iem2-iom
    ans = min(ans1,ans2)

print(ans)



Measured memory_bytes: 15860
#include <stdio.h>
int A[100];
int n;
 int solve(int i,int m){
   if(m==0)return 1;
   if(i>=n)return 0;
   int res = (solve(i+1,m) || solve(i+1, m-A[i]));
   return res;
 }
int main(){
  int i,q,M;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s,t;
    cin>>s>>t;
    int ans=0;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
    
    
    return 0;
}

Measured memory_bytes: 3916
a=int(input())
b=int(input())
c=int(input())
x=int(input())

count=0
for i in range(a+1):
    for j in range(b+1):
        for r in range(c+1):
            if 500*i+100*j+50*r==x:
                count+=1
                
print(count)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  ll N,K;cin>>N>>K;

  vl H(N);rep(i,N){
    cin>>H[i];
    
  }
  sort(all(H));
  reverse(all(H));
  ll ans =0;
  f(i,K,N){
    ans += H[i];
  }
  cout<<ans<<endl;

}





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

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

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int ans = 1, s = 0;
    for (int i = 0; i < n; ++i) {
        s += v[i];
        if(s <= x){
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


North  = 0
East   = 1
South  = 2
West   = 3

DICT = {"^":North,">":East,"v":South,"<":West}

while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break

    base_map = [input() for _ in range(H)]
    check = [[False]*W for row in range(H)]

    row = 0
    col = 0

    while True:
        if base_map[row][col] == '.':
            print("%d %d"%(col,row))
            break
        else:
            if check[row][col] == True:
                print("LOOP")
                break

            check[row][col] = True
            tmp_dir = DICT[base_map[row][col]]

            if tmp_dir == North:
                row -= 1
            elif tmp_dir == East:
                col += 1
            elif tmp_dir == South:
                row += 1
            else: #tmp_dir == West
                col -= 1


Measured memory_bytes: 6552
#include <iostream>
using namespace std;
int f(int x,int y){
	int u=x-y;
	if(u<0){
		u=u*-1;
	}
	return u;
}
int main(){
	long long c,a,b;
	cin>>c>>a>>b;
	if(f(a,c)<f(b,c)){
		cout<<"A";
	}
	else{
		cout<<"B";
	}
	return 0;
}

Measured memory_bytes: 256
import collections as co
n = int(input())
s = []
for i in range(n):
    s.append(input())
SS = co.Counter(s)
ma = max(SS.values())

ans = []
for i in SS.keys():
    if SS[i] == ma:
        ans.append(i)

ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 35572
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;
const int  maxn=1e4+10;
const int inf=0x3f3f3f3f;
int n,k;
int d[11];
bool vis[11];


bool judge(int x){
    bool flag=true;
    while(x>0){
        if(vis[x%10]){
            x/=10;
            continue;
        }
        else {
            flag=false;
            break;
        }
    }
    return flag;
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++)   scanf("%d",d+i);
    for(int i=0;i<10;i++)   vis[i]=true;
    for(int i=1;i<=k;i++){
        vis[d[i]]=false;
    }
    for(int i=n;i<=inf;i++){
        if(judge(i))    {
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#dice
D=[int(i) for i in input().split()]
Os=input()
for i in range(len(Os)):
    if Os[i]=="N":
        t=D[0]
        D[0]=D[1]
        D[1]=D[5]
        D[5]=D[4]
        D[4]=t
    elif Os[i]=="S":
        t=D[0]
        D[0]=D[4]
        D[4]=D[5]
        D[5]=D[1]
        D[1]=t        
    elif Os[i]=="E":
        t=D[0]
        D[0]=D[3]
        D[3]=D[5]
        D[5]=D[2]
        D[2]=t        
    elif Os[i]=="W":
        t=D[0]
        D[0]=D[2]
        D[2]=D[5]
        D[5]=D[3]
        D[3]=t        
print(D[0])

Measured memory_bytes: 7772
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

vector<int> a[110000];
int used[110000];
int mk[110000];

int main()
{
  int i,j,m,n,b1,x,y,cnt1,cnt2,k;
  vector<int> q;
  _int64 ans;
  scanf("%d%d",&n,&m);
  for (i=0;i<n;i++)
    a[i].clear();
  for (i=0;i<m;i++)
  {
    scanf("%d%d",&x,&y);
    x--;y--;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  memset(used,0,sizeof(used));
  memset(mk,-1,sizeof(mk));
  ans=0;
  for (i=0;i<n;i++)
    if (used[i]==0)
    {
      q.clear();
      q.push_back(i);
      used[i]=1;
      mk[i]=0;
      b1=0;
      cnt1=1;cnt2=0;
      for (j=0;j<q.size();j++)
      {
        x=q[j];
        for (k=0;k<a[x].size();k++)
        {
          y=a[x][k];
          if (used[y]==0)
          {
            used[y]=1;
            q.push_back(y);
            mk[y]=1-mk[x];
            if (mk[y]==0) cnt1++;
            else cnt2++;
          }
          else
          {
            if (mk[x]+mk[y]!=1)
            {
              b1=1;
            }
          }
        }
      }
      if (b1==1)
      {
        ans+=(_int64)q.size()*(q.size()-1)/2;
      }
      else
      {
        ans+=(_int64)cnt1*cnt2;
      }
    }
  ans-=m;
  printf("%lld\n",ans);
  return 0;
}

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

int main()
{
    int n;
    int alpha[26];

    while( cin >> n )
    {
        if( !n )
            break;
        
        for( int i = 0; i < 26; i++ )
            alpha[i] = 0;

        char c[n];
        int cnt = n, max = -1, maxi = 0;
        
        for( int i = 0; i < n; i++ )
            cin >> c[i];
        
        bool judge2 = true;
        for( int i = 0; i < n; i++ )
        {
            alpha[c[i]-'A']++;
            cnt--;
            for( int j = 0; j < 26; j++ )
                if( max < alpha[j] )
                {
                    max = alpha[j];
                    maxi = j;
                }

            if( max > n / 2 )
            {
                cout << (char)( maxi + 'A' ) << " " << i + 1 << endl;
                judge2 = false;
                break;
            }

            bool judge = true;
            for( int j = 0; j < 26; j++ )
            {
                if( j != maxi && max - cnt > alpha[j] );
                else if( j != maxi )
                    judge = false;
                else;
            }

            if( judge )
            {
                cout << (char)( maxi + 'A' ) << " " << i + 1 << endl;
                judge2 = false;
                break;
            }
        }
        if( judge2 )
            cout << "TIE" << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
# include <cstdio>
# include <cstdlib>
# include <iostream>
# include <algorithm>
# include <cstring>
using namespace std;

int len;
char ss[101], ans[101];

int main(void)
{
    scanf("%s", ss);
    for(int i=0, slen=strlen(ss); i<slen; ++i)
    {
        if(ss[i] == 'B')
        {
            if(len)
                --len;
        }

        else
        {
            ans[len]=ss[i];
            ++len;
        }
    }
    ans[len]='\0';
    printf("%s\n", ans);
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int s;
  cin >> s;

  unordered_map<int, int> ai;

  int i;
  for (i = 1; !ai.count(s); ++i) {
    ai[s];
    if (s % 2) {
      s = s * 3 + 1;
    } else {
      s /= 2;
    }
  }

  cout << i << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long
#define inf 1e9

using namespace std;
typedef pair<llint, llint> P;

llint n, k, q;
llint a[2005];
vector<P> vec;
bool used[2005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k >> q;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		vec.push_back(P(a[i], i));
	}
	sort(vec.begin(), vec.end());
	
	used[0] = used[n+1] = true;
	
	llint ans = inf;
	for(int t = 0; t < vec.size(); t++){
		
		llint l = 0;
		vector<llint> tmp, tmp2;
		for(int i = 1; i <= n+1; i++){
			if(used[i]){
				tmp2.clear();
				for(int j = l+1; j < i; j++) tmp2.push_back(a[j]);
				sort(tmp2.begin(), tmp2.end());
				if(tmp2.size() >= k){
					for(int j = 0; j < (int)tmp2.size()-k+1; j++) tmp.push_back(tmp2[j]);
				}
				l = i;
			}
		}
		sort(tmp.begin(), tmp.end());
		
		if(tmp.size() >= q){
			ans = min(ans, tmp[q-1] - tmp.front());
		}
		used[vec[t].second] = true;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 384
h,w,d=map(int,input().split())
basyo=[[]for i in range(h*w)]
hako=[]
a=[0 for i in range(h*w)]
for i in range(h):
    hako.append(list(map(int,input().split())))
for i in range(h):
    for j in range(w):
        basyo[hako[i][j]-1].append([i,j])

for i in range(d):
    a[i]=0
    tmp=0
    while i<h*w-d :
        ni=i+d
        t=abs(basyo[i][0][0]-basyo[ni][0][0])+abs(basyo[i][0][1]-basyo[ni][0][1])
        tmp+=t
        a[ni]=tmp
        i=ni
q=int(input())
for i in range(q):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    print(a[y]-a[x])

Measured memory_bytes: 95120
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
using namespace::std;
int main(){

int A;
  int B;
  cin>>A>>B;
  if((A-B)%2){
    cout<<"IMPOSSIBLE";
  }else{
    cout<<A-(A-B)/2;
  }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#define P pair<int,string>
using namespace std;

int main()
{
	int a, b; cin >> a >> b;
	P c[51];
	c[0] = P(0, "kogakubu10gokan");
	for (int d = 0; d < a; d++) {
		string e; int f;
		cin >> f >> e;
		c[d+1] = P(f, e);
	}
	for (int i = a; i >= 0;i--) {
		if (b >= c[i].first) { cout << c[i].second << endl; break; }
	}
}

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

int main() {
    int N;
  	cin >> N;
  	vector<int> h(N);
  
  	int v;
  	rep(i,N) {
      cin >> v;
      h[v-1] = i;
    }
  
  	rep(i,N) {
      cout << h[i]+1;
      if (i < N-1) cout << " ";
    }
  	cout << endl;
  	return 0;
}


Measured memory_bytes: 1152