akhauriyash/Code-Regression huggingface dataset:
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

class Radix {
private:
    const char* s;
    int a[128];
public:
    Radix(const char* s = "abcdefghijklmnopqrstuvwxyz") : s(s) {
        int i;
        for(i = 0; s[i]; ++i)
            a[(int)s[i]] = i;
    }
    std::string to(long long p, int q) {
        int i;
        if(!p)
            return "0";
        char t[64] = { };
        for(i = 62; p; --i) {
            t[i] = s[p % q];
            p /= q;
        }
        return std::string(t + i + 1);
    }
    std::string to(const std::string& t, int p, int q) {
        return to(to(t, p), q);
    }
    long long to(const std::string& t, int p) {
        int i;
        long long sm = a[(int)t[0]];
        for(i = 1; i < (int)t.length(); ++i)
            sm = sm * p + a[(int)t[i]];
        return sm;
    }
};

signed main () {
    int n,k;cin >>n>>k;
    vector<int> a(n);
    rep(i,n)cin >>a[i];
    int sum=0;
    sort(all(a));
    rep(i,k)sum+=a[i];
    cout <<sum<<endl;
}

Measured memory_bytes: 3600
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	int N;
	cin >> N;
	if (N % 2) {
		cout << N * 2 << endl;
	}
	else {
		cout << N << endl;
	}
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b, h, m) = readLine()!!.split(' ').map { it.toInt() }
    val degA = 360.0 / 12 * h + (360 / 12) * (m / 60.0)
    val degB = 360.0 / 60 * m
    val degDiff = Math.abs(degA - degB)
    val th = Math.min(degDiff, 360 - degDiff)
    if (th == 0.0) {
        println(Math.abs(a - b))
    } else if (th == 180.0) {
        println(a + b)
    } else {
        println(Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(th * Math.PI / 180.0)))
    }
}


Measured memory_bytes: 36608
#include <bits/stdc++.h>
using namespace std;
long long N, K, start, End, rm;
long long visits[200005] = {0}, arr[200005];
deque<long long> vec, rm_vec;
int main()
{
    scanf("%lld %lld", &N, &K);
    for (int i = 1; i <= N; i++)
    {
        scanf("%lld", &arr[i]);
    }
    start = 1;
    while (visits[start] == 0)
    {
        vec.push_back(start);
        visits[start] += 1;
        start = arr[start];
    }
    End = arr[vec.back()];
    // for (int i = 0; i < N; i++)
    // {
    //     printf("%lld ", visit[i]);
    // }
    // printf("\n");
    rm = 0;
    while (!vec.empty() && vec.front() != End)
    {
        rm_vec.push_back(vec.front());
        vec.pop_front();
        rm++;
    }
    // for (auto p : vec)
    //     printf("%lld ", p);
    // printf("end %lld\n", End);
    // for (auto p : rm_vec)
    //     printf("%lld ", p);
    // printf("end %lld\n", End);
    if (K - rm < 0)
    {
        printf("%lld\n", rm_vec[K]);
    }
    else
    {
        int ans = (K - rm) % vec.size();
        printf("%lld\n", vec[ans]);
    }
}

Measured memory_bytes: 8424
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

bool isprime(int x) {
  if (x == 2) return true;
  else if (x < 2 || x % 2 == 0) return false;
  int i = 3;
  while (i * i <= x) {
    if (x % i == 0) return false;
    i += 2;
  }
  return true;
}

int main(){
  int a;
  cin >> a;
  int x = a;
  while (1) {
    if (isprime(x)) break;
    else x++;
  }
  cout << x;
  return 0;
}


Measured memory_bytes: 256
import itertools
import math

N = int(input())
x = []
y = []
for i in range(N):
    X,Y = map(int,input().split())
    
    x.append(X)
    y.append(Y)
n = math.factorial(N)
c = list(zip(x,y))
cnt = 0
x_list = []
y_list = []
for i in itertools.permutations(c):
    mm = i
    for k in range(N):
        x_list.append(mm[k][0])
        y_list.append(mm[k][1])
    for f in range(N-1):
        cnt += math.sqrt((x_list[f+1]  - x_list[f])**2 + (y_list[f+1] - y_list[f] ) ** 2)
    x_list = []
    y_list = []
print(cnt / n)
        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
  ll n;
  cin >> n;
  for (ll i = sqrt(n); i >= 1; i--) {
    if (n%i == 0) {
      cout << i + n/i - 2 << endl;
      break;
    }
  }
}

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

int main(){
  int N;
  cin>>N;
  vector<pair<string,int>> A(N);
  for(pair<string,int> &i:A)
    cin>>i.first>>i.second;
  string X;
  cin>>X;
  bool bo=false;
  int j=0;
  for(pair<string,int> &i:A){
    if(bo)
      j+=i.second;
    else if(i.first==X)
      bo=true;
  }
  cout<<j<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,X,T,p,ans;
    scanf("%d %d %d",&N,&X,&T);
   if(N%X==0){
    ans=N/X;
    ans=ans*T;
   }
   else {
       ans=N/X;
    ans=ans*T;
   ans=ans+T;


   }
   printf("%d",ans);
   return 0;


}


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

int main(){
    int N, time{}, muri{};
    cin >> N;
    vector<int> A(N);
    for(int i{}; i < N; i ++){
        cin >> A.at(i);
    }
    while(muri == 0){
        for(int i{}; i < N; i ++){
            muri += A.at(i) % 2;
            A.at(i) /= 2;
            time += (i+1)/N;
        }
    }
    cout << time-1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

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

  rep(i, N) {
    if (S[i] == 'Y') {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,p1,p2,p3,col[100001];
vector<pair<int,int> > arr[100001];
void dfs(int cur,int pre,int c) {
    col[cur]=c;
    for (int i=0; i<arr[cur].size(); i++) {
        if (arr[cur][i].first==pre) continue;
        if (arr[cur][i].second%2==0) dfs(arr[cur][i].first,cur,c);
        else dfs(arr[cur][i].first,cur,!c);
    }
}
int main() {
    cin>>n;
    for (int i=0; i<n-1; i++) {
        cin>>p1>>p2>>p3; p1--; p2--;
        arr[p1].push_back({p2,p3});
      	arr[p2].push_back({p1,p3});
    }
    dfs(0,-1,0);
    for (int i=0; i<n; i++) cout<<col[i]<<'\n';
}

Measured memory_bytes: 11436
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display,
{
    for (i, e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}


#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, BTreeMap, HashMap, HashSet};
#[allow(unused_imports)]
// use std::collections::btree_map::Entry::*;
#[allow(unused_imports)]
use std::collections::hash_map::Entry::*;

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! print { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! println { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }

    let s = readl!(String).into_bytes();
    let k = readl!(usize);
    // let mut dp = vec![vec![vec![None; k+1]; s.len()]; s.len()];
    let mut dp = HashMap::new();
    struct Env<'a> {dp: &'a mut HashMap<(isize, isize, usize), i32>, s: &'a Vec<u8>, }
    fn rec(env: &mut Env, l: isize, r: isize, k: usize) -> i32 {
        if let Some(&v) = env.dp.get(&(l, r, k)) {
            v
        } else {
            if l >= r {
                if l == r {
                    1
                } else {
                    0
                }
            } else {
                let mut res = 0;
                res = max(rec(env, l+1, r, k), res);
                res = max(rec(env, l, r-1, k), res);
                if env.s[l as usize] == env.s[r as usize] {
                    res = max(rec(env, l+1, r-1, k)+2, res);
                } else if k != 0 {
                    res = max(rec(env, l+1, r-1, k-1)+2, res);
                }
                env.dp.insert((l, r, k), res);
                // env.dp[l as usize][r as usize][k] = Some(res);
                res
            }
        }
    }
    println!("{}", rec(&mut Env{dp: &mut dp, s: &s}, 0, s.len() as isize-1, k));
}


Measured memory_bytes: 249740
import time
import random

def calc(D, C, S, T):
    s = 0
    l = [-1] * len(C)
    for d, t in enumerate(T):
        t -= 1
        s += S[d][t]
        s -= C[t] * (d - l[t]) * (d - l[t] - 1) // 2
        l[t] = d
    s -= sum(c * (d - l[i]) * (d - l[i] + 1) // 2 for i, c in enumerate(C))
    return s

def main():
    start = time.time()
    D = int(input())
    C = list(map(int, input().split()))
    S = [list(map(int, input().split())) for _ in range(D)]
    
    M = [0] * 26

    P = []
    
    for d in range(D):
        for i in range(26):
            M[i] += C[i]
        T = [m + s for m, s in zip(M, S[d])]
        i = T.index(max(T))
        M[i] = 0
        P.append(i)

    Sc = calc(D, C, S, P)
    while time.time() - start <= 1.8:
        d = random.choice(range(D))
        q = random.choice(range(26))
        if P[d] == q:
            continue
        old = P[d]
        P[d] = q
        Sn = calc(D, C, S, P)
        if Sn <= Sc:
            P[d] = old
        else:
            Sc = Sn
    return P

p = main()
print('\n'.join(str(i + 1) for i in p))


Measured memory_bytes: 9808
#include<stdio.h>
#include<string.h>

#define ll long long

ll min(ll x, ll y){
  if(x>y){
    return y;
  }else{
    return x;
  }
}

ll max(ll x, ll y){
  if(x<y){
    return y;
  }else{
    return x;
  }
}


int main(void){
  ll X,t;
  scanf("%lld%lld",&X,&t);

  printf("%lld\n",max(0,X-t));


  return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 6)


MOD = 10 ** 9 + 7


def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


def dfs(v):
    global MOD
    childs = 0
    var = 1
    for e in edge[v]:
        if path[e] == 0:
            path[e] = 1
            nc, nvar = dfs(e)
            childs += nc
            V[v][e] = (nc, nvar)
            var *= nvar
            var %= MOD
            var *= invs[nc]
            var %= MOD
    var *= modFacts[childs]
    var %= MOD
    return childs + 1, var


def dfs2(v):
    global MOD
    tNodes = 0
    tVar = 1
    for n, var in V[v].values():
        tNodes += n
        tVar *= var
        tVar %= MOD
        tVar *= invs[n]
        tVar %= MOD
    tVar *= modFacts[tNodes]
    tVar %= MOD
    dp[v] = tVar

    for e in edge[v]:
        if dp[e] == 0:
            eNodes, eVar = V[v][e]
            nVar = (tVar * invs[tNodes] * modFacts[eNodes] * modFacts[tNodes - eNodes]) % MOD
            nVar *= pow(eVar, MOD - 2, MOD)
            nVar %= MOD
            V[e][v] = (tNodes - eNodes + 1, nVar)
            dfs2(e)


N = int(input())
edge = [[] for _ in range(N)]
for s in sys.stdin.readlines():
    a, b = map(int, s.split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

modFacts, invs = prepare(N)

V = [{} for _ in range(N)]
path = [0] * N
dp = [0] * N
path[0] = 1
dfs(0)
dfs2(0)


print(*dp, sep='\n')


Measured memory_bytes: 183028
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct FenwickTree{
	vector<ll> data;
	FenwickTree(int n):data(n+1){}
	void AddRange(int i,int x){
		for(;i;i-=(i&-i))
			data[i]+=x;
	}
	void AddRange(int i,int j,int x){
		AddRange(i,-x);
		AddRange(j,x);
	}
	int Get(int i){
		ll res=0;
		for(i++;i<data.size();i+=(i&-i))
			res+=data[i];
		return res;
	}
};

int get()
{
	int i,d; scanf("%d.%d",&i,&d);
	return i*1000+(i<0?-d:d);
}

struct Event{
	int x,y;
	int kind; // 0:in, 1:out
	Event(){}
	Event(int x,int y,int k):x(x),y(y),kind(k){}
	bool operator>(const Event& e)const{
		return mp(x,kind)>mp(e.x,e.kind);
	}
};

int main()
{
	for(int n;~scanf("%d",&n);){
		int r=get();
		vector<pii> ps(n);
		rep(i,n) ps[i].first=get(),ps[i].second=get();
		
		vi ys;
		rep(i,n){
			ys.push_back(ps[i].second-r);
			ys.push_back(ps[i].second);
			ys.push_back(ps[i].second+r);
		}
		sort(all(ys));
		ys.erase(unique(all(ys)),ys.end());
		
		priority_queue<Event,vector<Event>,greater<Event>> pq;
		rep(i,n){
			pq.emplace(ps[i].first,ps[i].second,0);
			pq.emplace(ps[i].first+r,ps[i].second,1);
		}
		
		FenwickTree ft(ys.size());
		int res=0;
		while(pq.size()){
			Event e=pq.top(); pq.pop();
			int btm=lower_bound(all(ys),e.y-r)-ys.begin();
			int top=upper_bound(all(ys),e.y+r)-ys.begin();
			if(e.kind==0){	// in
				int y=lower_bound(all(ys),e.y)-ys.begin();
				res+=ft.Get(y)==0;
				ft.AddRange(btm,top,1);
			}
			else			// out
				ft.AddRange(btm,top,-1);
		}
		
		printf("%d\n",res);
	}
	
	return 0;
}

Measured memory_bytes: 19420
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _n = stdin.split('\n')[0]
const n = Number(_n)

const a1 = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)
const a2 = stdin
  .split('\n')[2]
  .split(' ')
  .map(Number)

const a1Total = i => {
  let sum = 0
  for (let j = 0; j <= i; j++) {
    sum += a1[j]
  }
  return sum
}

const a2Total = i => {
  let sum = 0
  for (let j = i; j < a2.length; j++) {
    sum += a2[j]
  }
  return sum
}

const res = _ => {
  let max = 0
  for (let i = 0; i < n; i++) {
    const sum = a1Total(i) + a2Total(i)
    max = sum > max ? sum : max
  }
  return max
}

console.log(res())


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1e9+1;

/*
dp[i][j]:i+1行j+1列までの経路の総数。
a[i-1][j], a[i][j-1]が共に.なら、それらの総和のmod

*/

void solve(){
    int h,w;
    cin >> h >> w;
    char a[h+5][w+5];
    rep(i,h){
        string s;
        cin >> s;
        rep(j,w){
            a[i][j] = s[j];
        }
    }
    int dp[h+5][w+5];
    int tmp=1;
    rep(i,h){
        if(a[i][0]=='#') tmp=0;
        dp[i][0] = tmp;
    }
    tmp = 1;
    rep(i,w){
        if(a[0][i]=='#') tmp=0;
        dp[0][i] = tmp;
    }

    for(int i=1; i<h; i++){
        for(int j=1; j<w; j++){
            if(a[i-1][j]=='.' && a[i][j-1]=='.') dp[i][j]=(dp[i-1][j]+dp[i][j-1]) % MOD;
            else if (a[i-1][j]=='.') dp[i][j]=dp[i-1][j];
            else if (a[i][j-1]=='.') dp[i][j]=dp[i][j-1];
            else dp[i][j]=0;
        }
    }

    cout << dp[h-1][w-1] << endl;
    
}

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


Measured memory_bytes: 5120
n,k = map(int,input().split())
s = list(map(int,input().split()))
s.insert(0,0)

visited = [0]*(n+1)
visited[1] = 1
q = [1]

def dp(town):
    if visited[town] == 1:
        ans = k%(len(q))
        print(q[ans])
        exit()
    else:
        visited[town] += 1
        q.append(town)

i = 1
next_town = s[1]
while True:
    if i == k:
        print(next_town)
        exit()
    if visited[next_town] == 1:
        break
    else:
        visited[next_town] += 1
        q.append(next_town)
        next_town = s[next_town]
        i += 1
    
index = q.index(next_town)
q = q[index:]
ans = (k-i)%len(q)
print(q[ans])



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

void greatFirst(int& a, int& b)
{
  if(a < b)
  {
    int tmp = a;
    a = b;
    b = tmp;
  }
}

int main()
{
  ll n, x, y;
  cin >> n ;
  ll a[n];
  ll b[n];
  rep(i,n)
    b[i] = 0;
  rep(i,n)
  {
    cin >> a[i];
    b[a[i]-1]++;
  }
  
  ll sum = 0;
  rep(i, n)
  {
    sum += (b[i]*(b[i]-1)/2);
  }

  rep(i,n)
  {
    cout << fixed << (sum - (b[a[i]-1]) + 1) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<deque>
#include<cstring>

int main()
{
	int n;
	std::cin >> n;
	
	while( n-- )
	{
		std::string s;
		std::cin >> s;

		std::deque<char> deq;
		deq.push_back( s[0] );
		
		int p = 0;
		bool used[53];
		memset( used, false, sizeof( used ) );
		used[26] = true;

		for( int i = 1; i < s.size(); i += 3 )
		{
			if( s[i] == '<' && !used[--p + 26] )
				deq.push_front( s[i+2] );
			else if( s[i+1] == '>' && !used[++p + 26] )
				deq.push_back( s[i+2] );

			used[p + 26] = true;
		}

		for( auto it = deq.begin(); it != deq.end(); ++it )
			std::cout << *it;

		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n; cin>>n;
  vector<int> dp(n+1,INF);
  dp[0]=0;
  for(int i=1;i<n+1;i++){
    dp[i]=min(dp[i],dp[i-1]+1);
    int k=6;
    while(i-k>=0){
      dp[i]=min(dp[i],dp[i-k]+1);
      k*=6;
    }
    k=9;
    while(i-k>=0){
      dp[i]=min(dp[i],dp[i-k]+1);
      k*=9;
    }
  }
  cout<<dp[n]<<endl;

  return 0;
}


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


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

    int n;
    cin>>n;
    int a[n];
    int m=0;
    int m2=0;
    set<int> st;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i] == 2) st.insert(i);
        if(a[i] == -1) m++;
        if(a[i] == -2) m2++;
    }
    if(m2){
        if(m2%2 && m){
            bool used = false;
            for(int i=0;i<n;i++){
                if(a[i] == -1 && !used){
                    st.insert(i);
                    used = 1;
                }
                if(a[i] == -2) st.insert(i);
            }
        }
        if(m2%2){
            for(int i=0;i<n;i++){
                if(m2==1) break;
                if(a[i] == -2){
                    st.insert(i);
                    m2--;
                }
            }
        }
        if(m2 %2 == 0){
            for(int i=0;i<n;i++){
                if(a[i] == -2) st.insert(i);
            }
        }
    }

    cout << st.size() << endl;
    for(auto i:st){
        cout << i+1 << endl;
    }

    
}


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

int main() {
  int N;
  cin >> N;
  int c = 0;
  int M = N;
  
  while(M > 0){
    M /= 10;
    c++;
  }
  
  if(c == 1){
    M = N;
  }
  else if(c == 2){
    M = 9;
  }
  else if(c == 3){
    M = N - 99 + 9;
  }
  else if(c == 4){
    M = 909;
  }
  else if(c == 5){
    M = N - 9999 + 909;
  }
  else{
    M = 90909;
  }
  cout << M << endl;
}

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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<char> v;
  rep(i,n) v.push_back(s[i]);
  for (int i = n; i > 0; --i) {
    if (v[i] == v[i - 1]) v.pop_back();
  }

  cout << v.size();

  return 0;
}

Measured memory_bytes: 640
import math


K = int(input())

sum = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        sum += math.gcd(i, j)
        if j == K:
            break
        else:
            for k in range(j + 1, K + 1):
                sum += math.gcd(i, math.gcd(j, k)) * 2

print(sum)



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

int main() {
    int N;
    cin >> N;
    int cnt[100001], a;
    ll sum = 0;
    rep(i,100001) cnt[i] = 0;
    rep(i,N) {
        cin >> a;
        cnt[a]++;
        sum += a;
    }

    int Q;
    cin >> Q;
    int B, C;
    rep(i,Q) {
        cin >> B >> C;
        sum += (C - B) * cnt[B];
        cout << sum << endl;
        cnt[C] += cnt[B];
        cnt[B] = 0;
    }
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 200005;
int n, a[mx], l, r = mx;

int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d", a+i);
	while(l+1 < r){
		int mid = (l+r) / 2, hi = 0;
		bool ok = true;
		map<int, int> mp;
		rep(i,n){
			bool t = hi >= a[i];
			hi = a[i];
			if(t && mid == 1) t = ok = false;
			if(t) while(++mp[hi] >= mid) hi--;
			if(!hi) ok = false;
			mp.erase(mp.upper_bound(hi), mp.end());
		}
		(ok ? r : l) = mid;
	}
	printf("%d\n", r);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  int n;
  cin >> n;
  vector<int> v(n),w(n),x(n);
  for(int i=0;i<n;i++) cin >> v[i];
  for(int i=0;i<n;i++) cin >> w[i];

  for(int i=0;i<n;i++) x[i] = i+1;

  int cnt = 1;
  while(x != v)
  {
    next_permutation(x.begin(),x.end());
    cnt++;
  }

  int a = cnt;

  cnt = 1;
  for(int i=0;i<n;i++) x[i] = i+1;
  while(x != w)
  {
    next_permutation(x.begin(),x.end());
    cnt++;
  }

  int b = cnt;

  cout << abs(a-b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n,k;
    cin >> n >>k;
    vector<int> x(n),y(n);
    vector<int> xx, yy;
    rep(i, n)
    {
        cin >> x[i] >> y[i];
        xx.push_back(x[i]);
        yy.push_back(y[i]);
    }
    sort(xx.begin(),xx.end());
    sort(yy.begin(), yy.end());
    ll ans = 1LL * (xx[n - 1] - xx[0]) * (yy[n - 1] - yy[0]);
    rep(xi,n){
        for (int xj = xi + 1; xj < n; xj++){
            rep(yi,n){
                for (int yj = yi + 1; yj < n;yj++){
                    int num = 0;
                    ll lx = xx[xi],rx = xx[xj];
                    ll ly = yy[yi],ry = yy[yj];
                    for (int i = 0; i < n;i++){
                        if(lx <= x[i] && x[i] <= rx && ly <= y[i] && y[i] <= ry){
                            num++;
                        }
                    }

                    if(num >= k)
                        ans = min(ans, 1LL * (rx - lx) * (ry - ly));
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
int32_t main(){
    fast;
    string s,t;
    cin>>s>>t;
    int n=s.length(),m=t.length();
    vector<vector<int> > dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
    int i=n,j=m;
    vector<char> c;
    while(i && j){
        if(s[i-1]==t[j-1]){
            c.pb(s[i-1]);
            i--,j--;
        }
        else if(dp[i][j-1]<dp[i-1][j])
            i--;
        else
            j--;
    }
    reverse(c.begin(),c.end());
    for(auto p:c)
        cout<<p;
    return 0;
}

Measured memory_bytes: 73608
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 300100;
ll dp[3][2][3][N];

void add(ll &x, ll y) {
  x = (x + y) % mod;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  s += '1';
  dp[0][0][0][0] = 1;
  REP(i, 0, s.length()) {
    REP(a, 0, 3) {
      REP(b, 0, 2) {
	REP(c, 0, 3) {
	  if (s[i] != '0') { // 1
	    int nb = c % 2 == 1 ? b : (b + 1) % 2;
	    int na = a + (c == 0 && a == b ? 1 : 0);
	    add(dp[na][nb][0][i + 1], dp[a][b][c][i]);
	  }
	  if (s[i] != '1') {
	    int nc = c + 1;
	    if (nc >= 3) nc = 1;
	    add(dp[a][b][nc][i + 1], dp[a][b][c][i]);
	  }
	}
      }
    }
  }
  ll tot = 0;
  REP(b, 0, 2) {
    REP(c, 0, 3) {
      add(tot, dp[2][b][c][s.length()]);
    }
  }
  cout << tot << endl;
}


Measured memory_bytes: 42900
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
int main(void) {
    vector<int> vc(3);
    rep(i, 3) cin >> vc[i];
    sort(vc.begin(), vc.end());
    cout << vc[0] + vc[1];
}


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

typedef long long ll;

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

    int A, B, M;

    cin >> A >> B >> M;

    ll am = 100000;
    ll bm = 100000;

    vector<ll> a(A);
    vector<ll> b(B);


    for(int i = 0; i < A; i++) {
        cin >> a[i];
        if(a[i] < am) {
            am = a[i];
        }
    }

    for(int i = 0; i < B; i++) {
        cin >> b[i];
        if(b[i] < bm) {
            bm = b[i];
        }
    }

    ll min = am + bm;


    for(int i = 0; i < M; i++) {
        ll x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        if(a[x] + b[y] - c < min) {
            min = a[x] + b[y] - c;
        }
    }

    cout << min << endl;
}

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

int main(){
  string s;
  cin >> s;
  int Q;
  cin >> Q;
  int count = 0;
  s.reserve(300010);

  rep(k,0,Q){
    int act;
    cin >> act;
    if(act==1) count++;
    else if(act==2){
      int f;
      string c;
      cin >> f >> c;
      if(f==1 && count%2==0) s.insert(0,c);
      else if(f==1) s.append(c);
      else if(f==2 && count%2==0) s.append(c);
      else if(f==2) s.insert(0,c);
    }
  }
  if(count%2==1) reverse(s.begin(),s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 924
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>


int main() {
	int n; std::cin >> n;
	std::vector<int> bars(n); for (auto& b : bars) std::cin >> b;
	std::sort(bars.begin(), bars.end());
	const auto sum = std::accumulate(bars.begin(), bars.end(), 0);
	std::vector<bool> can_make(sum, false);
	int min_diff = INT_MAX;
	for (auto second = 0; second < n - 1; ++second) {
		auto for_first = 0;
		for (auto i = second + 1; i < n - 1; ++i) for_first += bars[i];
		auto for_free = 0;
		for (auto i = 0; i < second; ++i) for_free += bars[i];
		std::fill(can_make.begin(), can_make.end(), false);
		can_make[0] = true;
		for (auto i = 0; i < second; ++i) {
			for (int j = can_make.size() - bars[i] - 1; j >= 0; --j) if (can_make[j]){
				can_make[j + bars[i]] = true;
			}
		}
		for (auto i = 0; i < can_make.size(); ++i) if (can_make[i]) {
			if (i > bars[second] && for_free - i + for_first > bars.back()) {
				min_diff = std::min(min_diff, std::abs(i + bars[second] - (for_free - i + for_first + bars.back())));
			}
			if (for_free - i > bars[second] && i + for_first > bars.back()) {
				min_diff = std::min(min_diff, std::abs(for_free - i + bars[second] - (i + for_first + bars.back())));
			}
		}
	}
	std::cout << ((min_diff == INT_MAX) ? -1 : min_diff) << '\n';
}


Measured memory_bytes: 3152
N,M = map(int,input().split())

cards = [x for x in range(N)]

tmp = cards
Ls = []
Rs = []
for i in range(M):
    L,R = map(int,input().split())
    Ls.append(L - 1)
    Rs.append(R - 1)

print(max(min(Rs) - max(Ls) + 1,0))


Measured memory_bytes: 14972
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    int i;
    int num_div = 0;
    cin >> a >> b >> c;
    for (i = a ; i <= b ; ++i){
        if(c%i==0){
            num_div++;
        }
    }
    cout << num_div << endl;
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  vector<int> c(2);
  rep(i, 2) cin >> c[i];

  rep(i, 2) {
    if (c[i] == 1) c[i] += 13;
  }
  if (c[0] > c[1]) cout << "Alice" << endl;
  else if (c[0] < c[1]) cout << "Bob" << endl;
  else cout << "Draw" << endl;


  
  return 0;
}

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

int main()
{
    string S;
    cin >> S;
    long ans = 0;
    int while_cnt = 0;
    rep(i, S.size())
    {
        if (S.at(i) == 'W')
        {
            ans += i - while_cnt;
            while_cnt++;
        }
    }

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

Measured memory_bytes: 3752
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;
#define int __int128
const int N = (int) 20, mod = (int) 0;
int sum[N], p10[N], val[N];

int go(int dig, int pos, int d) {
	if (sum[pos] * 9 < d) return 0;
	if (sum[pos] * -9 > d) return 0;
	if (pos == (dig + 1) / 2) {
		return d == 0;
	}
	int res = 0;
	for (int diff = -9; diff <= 9; ++diff) {
		if (dig - 1 - pos == pos && diff) {
			continue;
		}
		int ways = 0;
		for (int j = (pos == 0); j <= 9; ++j) {
			int i = j + diff;
			if (i >= 0 && i <= 9) {
				++ways;	
			}
		}
		if (ways) res += ways * go(dig, pos + 1, d - diff * val[pos]);
	}
	return res;
	
}

int32_t main() {
	int32_t tt;
	int td;
	cin >> tt;
	td = tt;
	p10[0] = 1;
	int res = 0;
	for (int j = 1; j < N; ++j) p10[j] = p10[j - 1] * 10;
	for (int dig = 1; dig <= 18; ++dig) {
		int half = (dig + 1) / 2;
		memset(sum, 0, sizeof sum);
		memset(val, 0, sizeof val);
		for (int j = half - 1; j >= 0; --j) {
			sum[j] = sum[j + 1];
			val[j] = p10[dig - 1 - j] - p10[j];
			sum[j] += val[j];
		}
		res += go(dig, 0, td);
	/*	
		for (int mask = 0; mask < (1 << half); ++mask) {
			for (int sub = 0; sub < (1 << half); ++sub)  {
				for (int jsub = 0; jsub < (1 << half); ++jsub) if ((mask & jsub) == jsub && (sub & jsub) == jsub) {
				int d = td;
				int cur = 1;
				for (int j = 0; j < half; ++j) {
					int diff = 0;
					while (val[j] && diff < 20 && d > 9 * sum[j + 1]) {
						d -= val[j];
						++diff;
					}
					while (val[j] && diff > -20 && d < -9 * sum[j + 1]) {
						d += val[j];
						--diff;
					}
					int cur_m = (mask >> j & 1) + (sub >> j & 1) * 2 - 2 + (jsub >> j & 1);
					int cur_mul = 0;
					d += cur_m * val[j];
					diff -= cur_m;
					for (int p = (j == 0); p <= 9; ++p) {
						int ot = p + diff;
						if (ot >= 0 && ot <= 9) {
							if (!val[j] && ot != p) continue;
							++cur_mul;	
						}
							
					}
					cur *= cur_mul;
				}
				if (d == 0) {
					res += cur * ((dig & 1) ? 1 : 1);
				}
			}
			}
		} 
	*/
	}
	cout << (long long) res << endl;
}





Measured memory_bytes: 256
# 入力は以下の形式で標準入力から与えられる。
# N
# A1 A2 ... AN
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

flg, num = true, 0
while true
  a.each do |e|
    if (e % 2) != 0
      flg = false
      break
    end
  end
  
  if flg
    a.map! {|e| e/2 }
	num += 1
  else
    break
  end
end

# 黒板に N 個の正の整数 A1,...,AN が書かれています．
# すぬけ君は，黒板に書かれている整数がすべて偶数であるとき，
# 次の操作を行うことができます．
# 黒板に書かれている整数すべてを， 2 で割ったものに置き換える．
# すぬけ君は最大で何回操作を行うことができるかを出力せよ．
p num

Measured memory_bytes: 1788
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        while(true) {
            int a = scn.nextInt();
            String str = scn.next();
            int b = scn.nextInt();

            if(str.equals("?")) break;

            switch(str){
                case "+":
                    System.out.println(a + b);
                    break;
                case "-":
                    System.out.println(a - b);
                    break;
                case "*" :
                    System.out.println(a * b);
                    break;
                case "/" :
                    System.out.println(a / b);
                    break;
            }
        }
    }
}


Measured memory_bytes: 26292
read n a b
ans=0
for (( k = 1; k <= n; k++ )); do
    dsum=0 value=$k
    while (( value > 0 )); do
        dsum=$(( dsum + value % 10 )) value=$(( value / 10 ))
    done
    (( dsum >= a && dsum <= b )) && (( ans += k ))
done
echo ${ans}


Measured memory_bytes: 376
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();

		int s[] = new int [n * 2];
		int c[] = new int [m * 2];

		for (int i = 0; i < n; ++i)
		{
			s[i * 2] = sc.nextInt();
			s[i * 2 + 1] = sc.nextInt();

			//System.out.print(s[i * 2] + " ");
			//System.out.println(s[i * 2 + 1]);
		}

		//System.out.println();

		for (int i = 0; i < m; ++i)
		{
			c[i * 2] = sc.nextInt();
			c[i * 2 + 1] = sc.nextInt();

			//System.out.print(c[i * 2] + " ");
			//System.out.println(c[i * 2 + 1]);
		}

		//System.out.println();

		sc.close();

		for (int i = 0; i < n; ++i)
		{
			int dist = Integer.MAX_VALUE, index = -1;

			//System.out.println(index + " " + dist);

			for (int j = 0; j < m; ++j)
			{
				int tmp = Math.abs(s[i * 2] - c[j * 2]) + Math.abs(s[i * 2 + 1] - c[j * 2 + 1]);

				if (tmp < dist)
				{
					dist = tmp;
					index = j + 1;

					//System.out.println("D:" + tmp + " " + dist + " " + index);
				}
			}

			System.out.println(index);
		}
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
struct custom {
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e19;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=(y>>1);
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j;
    cin>>n;
    ll arr[n+1],dp[n+1];
    for(i=1;i<=n;i++)cin>>arr[i];
    dp[1]=0;
    dp[2]=abs(arr[2]-arr[1]);
    for(i=3;i<=n;i++)dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
    cout<<dp[n]<<endl;
}


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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;

int main()
{
	scanf("%d",&N);
	set<int> st;
	FOR(i,0,N){
		int a;
		scanf("%d",&a);
		if(st.count(a) == 0){
			st.insert(a);
		}
		else{
			st.erase(a);
		}
	}
	printf("%lu\n",st.size());

	return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
int main()
{
	IOS();
	
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	cout<<'x';
	
	
	
	
	
	
	
	
	
	

	
	
	return 0;
}



Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = Counter(A)
C = {key:(B[key]*(B[key]-1)//2) for key in B}
ans = sum(C.values())
#print(C,ans)
#print(C[3])
for i in A:
    if C[i] < 1:
        print(ans)
    else:
        print(ans - C[i] + (B[i]-1)*(B[i]-2)//2)

Measured memory_bytes: 32020
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
pii cord[1000005],quer[1000005];
int main(){
	ll s,w;
	cin>>s>>w;
	if(w>=s)cout<<"unsafe";
	else cout<<"safe";
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int to_i(string s){
    int res=0;
    for(int i=0;i<s.size();i++){
        res*=10;
        res+=s[i]-'0';
    }
    return res;
}
int main(){
    stack<int> v;
    int ans,a,b;
    string c;
    while(cin>>c){
        if(c=="+"||c=="-"||c=="*"){
            b=v.top();v.pop();
            a=v.top();v.pop();
            if(c=="+"){
                ans=a+b;
                v.push(a+b);
            }else if(c=="-"){
                ans=a-b;
                v.push(a-b);
            }else{
                ans=a*b;
                v.push(a*b);
            }
        }else{
            v.push(to_i(c));
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long int;

#define INF 1000000000000000000

int main(void){

    ll n, k;
    cin >> n >> k;

    ll mod = n % k;

    ll minValue = INF;

    while(1){
        if(minValue >= abs(mod - k)) {
            minValue = abs(mod - k);
            mod = minValue;
        }else{
            break;
        }
    }

    cout << minValue << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int syogen[15][15];
  r(i,15)r(j,15)syogen[i][j]=-1;
  r(i,n){
    int a;
    cin >> a;
    r(j,a){
      int x,y;
      cin >> x >> y;
      x--;
      syogen[i][x]=y;
    }
  }
  int ans=0;
  r(i,1<<n){
    vector<int> v(n,0);
    r(j,n)if(i>>j&1)v[j]++;
    bool flag=true;
    r(j,n){
      if(v[j]==1){
        r(k,n){
          if(syogen[j][k]==-1)continue;
          if(syogen[j][k]!=v[k])flag=false;
        }
      }
    }
    if(flag)ans=max(ans,__builtin_popcount(i));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256