akhauriyash/Code-Regression huggingface dataset:
class RSQ:
    def __init__(self, length, ini_num = float("inf")):
        self.length = 1
        self.ini_num = ini_num
        if length == 1:
            length = 2
        while self.length < length:
            self.length <<= 1
        self.segtree = [ini_num] * (2 * self.length - 1)

    def update(self, index, num):
        leaf_index = index + self.length - 1
        self.segtree[leaf_index] = num
        while leaf_index > 0:
            leaf_index = (leaf_index - 1) // 2
            self.segtree[leaf_index] = self.segtree[2 * leaf_index + 1] + self.segtree[2 * leaf_index + 2]

    def add(self, index, num):
        leaf_index = index + self.length - 1
        self.segtree[leaf_index] += num
        while leaf_index > 0:
            leaf_index = (leaf_index - 1) // 2
            self.segtree[leaf_index] = self.segtree[2 * leaf_index + 1] + self.segtree[2 * leaf_index + 2]

    def call_search(self, a, b):
        return self.search(a, b, index = 0, l = 0, r = self.length - 1)

    def search(self, a, b, index, l, r):
        if a <= l <= r <= b:
            return self.segtree[index]
        elif r < a or b < l:
            return self.ini_num
        else:
            return self.search(a, b, index * 2 + 1, l, (l + r) // 2) + self.search(a, b, index * 2 + 2, (l + r) // 2 + 1, r)

v_num, query = map(int, input().split(" "))
rsq = RSQ(v_num, 0)
for _ in range(query):
    comm, index, num = map(int, input().split(" "))
    if comm == 0:
        rsq.add(index - 1, num)
    else:
        print(rsq.call_search(index - 1, num - 1))

Measured memory_bytes: 12944
s = list(input())
ab = int(s[0]+s[1])
cd = int(s[2]+s[3])
ans = ""
if 1 <= ab <= 12 and (cd == 0 or 13 <= cd):
    ans = "MMYY"
elif 1 <= cd <= 12 and (ab == 0 or 13 <= ab):
    ans = "YYMM"
elif 1 <= ab <= 12 and 1 <= cd <= 12:
    ans = "AMBIGUOUS"
else:
    ans = "NA"
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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



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

	vector<string> s(N + 1);
	repn(i, N) cin >> s[i];
	
	vector<vector<ll>> g;
	g.push_back({});

	vector<ll> col;
	col.push_back(-1);
	vector<ll> dep;
	dep.push_back(0);
	
	ll c = 1;
	repn(i, N) {
		ll v = 0;
		rep(j, s[i].size()) {

			ll b = 0;
			for (ll w : g[v]) {
				if (col[w] == s[i][j]) { v = w; b = 1; }
			}
			if (b == 1) { continue; }

			g[v].push_back(c);
			g.push_back({});
			col.push_back(s[i][j]);
			dep.push_back(j + 1);
			v = c;
			c++;

		}
	}

	ll M = g.size();
	
	vector<ll> game;
	rep(i, M) {
		if (g[i].size() == 1) { game.push_back(L - dep[i]); }
	}

	ll G = game.size();
	rep(i, G) {
		ll c = 0;
		while (game[i] % 2 == 0) {
			c++;
			game[i] /= 2;
		}
		game[i] = (1 << c);
	}

	ll ans = 0;
	rep(i, G) { ans = ans ^ game[i]; }

	if (ans == 0) { cout << "Bob"; }
	else { cout << "Alice"; }

	system("PAUSE");
}


Measured memory_bytes: 10032
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

string s;

int main() {

	cin>>s;
	int ans=0;
	int a0,a1,a2,a3;

	for(a0=0; a0<s.size(); a0=a3){
		for(a1=a0; s[a1]=='J'; a1++);
		for(a2=a1; s[a2]=='O'; a2++);
		for(a3=a2; s[a3]=='I'; a3++);
		if(a1-a0>=a2-a1 && a2-a1<=a3-a2)ans=max(ans,a2-a1);
	}


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

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
int cheng(int x)
{
	int res = 1;
	for(int i = 0 ; i < x ; i ++)
		res *= 10 ;
	return res;
}
int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int n,i;
	cin >> n;
	int m = n;
	for(i = 1 ; m/10 > 0 ;i ++ )
		m = m/10;
	int res = 0;
	for(int j = 0; j < i - 1 ; j += 2)
		res += 9*cheng(j);
	if(i % 2 == 1)
		cout << res + n- cheng(i - 1) + 1;
	else
		cout << res;
	return 0;
 } 

Measured memory_bytes: 384
N = int(input())
A = input().split()
judge = 1
count = 0

while(judge):
  for i in range(N):
    A[i] = int(A[i])
    if(A[i]%2 == 0):
      count += 1
      A[i] = A[i]/2
    else:
      judge = 0
      break
      
print(count//N)

Measured memory_bytes: 3060
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -10**10
for i in range(1, 2**10):
    tmp = i
    b = []
    while tmp:
        b.append(tmp % 2)
        tmp //= 2
    while len(b) != 10:
        b.append(0)

    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if b[k] == 1 and F[j][k] == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int v[N];
    for(int i=0;i<N;i++){
        cin >> v[i];
    }
    long long int sum=0;
    int min=v[0];
    int max=v[0];
    for(int i=0;i<N;i++){
        sum = sum + v[i];
        if(v[i]<min){
            min = v[i];
        }
        if(v[i]>max){
            max = v[i];
        }
    }
    printf("%d %d %lld\n",min,max,sum);
    
    return 0;
}


Measured memory_bytes: 3180
# SPDX-License-Identifier: X11
# 2020-08-31
# Tsundoku (300pt)

function main()
  N, M, K = parse.(Int, split(readline(), " "))
  A = parse.(Int, split(readline(), " "))
  B = parse.(Int, split(readline(), " "))
  As = runsum(A)
  Bs = runsum(B)

  j = M
  ans = 0
  for i ∈ 0:N
    As[i + 1] > K && break

    while j > 0 && As[i + 1] + Bs[j + 1] > K
      j -= 1
    end

    ans = max(ans, i + j)
  end

  println(ans)
end

function runsum(A)
  As = Vector{Int}(undef, 1 + lastindex(A))
  As[1] = 0
  for i ∈ 1:lastindex(A)
    As[i + 1] = As[i] + A[i]
  end
  return As
end

main()


Measured memory_bytes: 204132
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int z[300005];
int main()
{
//    freopen("in.txt", "r", stdin);
    int n,k;
    scanf("%d%d", &k, &n);
    if (k % 2 == 0)
    {
        printf("%d", k / 2);
        for (int i = 1; i < n; i++)
            printf(" %d", k);
        printf("\n");
    }
    else
    {
        int tmp = (k + 1) / 2;
        for (int i = 1; i <= n; i++)
            z[i] = tmp;
        int cnt = n / 2;
        int p = n - 1;
        while (cnt)
        {
            if (z[n])
            {
                if (cnt > z[n])
                {
                    cnt -= z[n];
                    z[n] = 0;
                    continue;
                }
                else
                {
                    z[n] -= cnt;
                    break;
                }
            }
            z[p]--;
            cnt--;
            if (!z[p])
            {
                p--;
                continue;
            }
            for (int l = p + 1; l <= n; l++)
                z[l] = k;
            p = n - 1;
        }
        printf("%d", z[1]);
        for (int i = 2; i <= n; i++)
        {
            if (z[i])
                printf(" %d", z[i]);
            else
                break;
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

bool f(int n) {
    string s = to_string(n);
    return s.size() % 2;
}

signed main() {
    int N, ans = 0;
    cin >> N;
    FOR(i, 1, N + 1) {
        ans += f(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string divide[4]={"dream","dreamer","erase","eraser"};

int main() {
    string S;
    cin >> S;
    
    reverse(S.begin(),S.end());
    for (int i = 0; i < 4; i++)
    {
        reverse(divide[i].begin(),divide[i].end());
    }
    bool can =true;
    for (int i = 0; i < S.size();)
    {
        bool can2=false;
        for (int j = 0; j < 4; j++)
        {
            string d = divide[j];
            if (S.substr(i,d.size())==d)
            {
                can2 =true;
                i+=d.size();
            }
            
        }
        if (!can2)
        {
            can = false;
            break;
        }
    }
    if (can)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint pow(const modint x, ll r) {
        return x^r;
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) {
            int size = factorial.size();
            factorial.resize(n+1);
            for (int i = size; i <= n; i++) {
                factorial[i] = fact(i-1) * modint(i);
            }
        }
        return factorial[n];
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial = {1};
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)

int main(void){
    ll n,k;
    cin >> n >> k;
    modint res = 0;
    vector<vector<ll>> divs(k+1);
    rep1(i,k){
        rep1(j,k){
            if (i*j > k) break;
            divs[i*j].push_back(i);
        }
    }

    vector<modint> cnt(k+1);
    rep(i,k){
        ll x = k-i;
        modint c = modint::pow(k/x, n) - cnt[x];
        res += modint(x) * c;
        for (ll d : divs[x]) {
            cnt[d] += c;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 19848
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[] judge = new boolean[n];
        if(n > 1000) n = 1000;
        for(int i = 0;i < n;i++){
            int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt();
            judge[i] = (a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a);
        }
        for(int i = 0;i < n;i++){
            System.out.println(judge[i] ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 33588
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main() {
    int N;
    cin >> N;
    int mark = 0;
    int prev;
    int ans = 1;
    cin >> prev;
    for (int i = 1; i < N; i++) {
        int now;
        cin >> now;
        if (now > prev) {
            if (mark == 0) {
                mark = 1;
            } else if (mark == -1) {
                ans++;
                mark = 0;
            }
        } else if (now < prev) {
            if (mark == 0) {
                mark = -1;
            } else if (mark == 1) {
                ans++;
                mark = 0;
            }
        }
        prev = now;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

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

		int x=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(Math.abs(x-a)>Math.abs(x-b)){
			System.out.println("B");
		}else{
			System.out.println("A");
		}


  }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};


PI V[30][30];
int Vs[30];
bool vis[1<<8][30];
int ti[30];

main(){
  int n,m,p,a,b;
  while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b),n){
    --a,--b;
    rep(i,n)scanf("%d",ti+i);

    memset(Vs,0,sizeof(Vs));

    rep(i,p){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      --x,--y;
      V[x][Vs[x]++]=mp(y,z);
      V[y][Vs[y]++]=mp(x,z);
    }

    priority_queue<pair<double,PI> > Q;
    Q.push(mp(0,mp(a,0)));
    memset(vis,0,sizeof(vis));
    double ans=-1;

    while(!Q.empty()){
      int v=Q.top().S.F,cst=Q.top().S.S;
      double cc=-Q.top().F;
      Q.pop();
      if(vis[cst][v])continue;
      vis[cst][v]=true;
      if(v==b){
        ans=cc;
        break;
      }

      rep(i,n){
        if(cst>>i&1)continue;
        rep(j,Vs[v]){
          int nv=V[v][j].first;
          int tc=V[v][j].second;
          int nst=cst|(1<<i);
          if(vis[nst][nv])continue;
          double nc=cc+1.0*tc/ti[i];
          Q.push(mp(-nc,mp(nv,nst)));
        }
      }
    }
    if(ans<0)puts("Impossible");
    else printf("%f\n",ans);
  }
}

Measured memory_bytes: 5564
#include<bits/stdc++.h>
using namespace std;
/*void copy(string a, char b[]){
    for(int i=0;i<a.size();i++){
        b.push_back(i);
        b.at(i)=a.at(i);
    }
}*/
int main(){
    string a;
    cin>>a;
    string b;
    b=a;
    int flag;
    for(int i=0;i<a.size();i++){
        flag=0;
        for(int j=0;j<a.size();j++){
            if(i==j)continue;
            if(a.at(i)==b.at(j)){
                flag=1;
                break;
            }
        }
        if(flag) break;
    }
    if(flag==1) cout<<"no"<<endl;
    else cout<<"yes"<<endl;
    
}

Measured memory_bytes: 3596
a, b, c, d = map(int, list(input()))
abcd = [a, b, c, d]
anss = []
import copy
def dfs(add_list, index):
    value = abcd[0]
    if index == 2:
        for add_index in range(len(add_list)):
            if add_list[add_index]:
                value += abcd[add_index+1]
            else:
                value -= abcd[add_index+1]

        if value == 7:
            anss.append(add_list)

    else:
        new_index = index + 1
        new_add_list = copy.copy(add_list)
        new_add_list[new_index] = False
        dfs(new_add_list, new_index)

        new_add_list = copy.copy(add_list)
        new_add_list[new_index] = True
        dfs(new_add_list, new_index)


def main():
    dfs([True,True,True], 0)
    dfs([False,True,True], 0)

    ans = anss[0]
    ans_str = []
    for op in ans:
        if op:
            ans_str.append("+")
        else:
            ans_str.append("-")
    ret_str = ""
    for index in range(len(ans_str)):
        ret_str += str(abcd[index])
        ret_str += ans_str[index]
    ret_str += str(abcd[-1])
    ret_str += "=7"
    print(ret_str)
if __name__ == "__main__":
    main()

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

using namespace std;

int main(){
    int n,i,A,B,d,flag=0;
    cin>>n>>A>>B;
    for(i=1;i<=1000;i++){
        if(n>0){d=i%n;}
        if(d==0){
            if(i>=A && i<=B){
                    flag=1;

            }
        }
    }
    if(flag==1){cout<<"OK"<<endl;}
    if(flag==0){cout<<"NG"<<endl;}

    return 0;
}

Measured memory_bytes: 3612
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0

n,k = map(int,input().split())
n = n%k
if abs(n-k) >= n:
    print(n)
else:
    print(abs(n-k))

Measured memory_bytes: 3060
n = gets.to_i
a = gets.split.map(&:to_i).sort!

a_max = a.max
dp = Array.new(a_max+1, true)

b = Hash.new
a.each do |aa|
  next if dp[aa] == false

  b[aa] = b[aa].to_i + 1
  next if b[aa] > 1
  start = aa * 2
  start.step(a_max, aa) do |i|
    dp[i] = false
  end
end
ans = b.count{|_, v| v == 1}

p ans

Measured memory_bytes: 47572
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
//#define M 998244353
const int inf=4e18;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int a,b,n;cin>>a>>b>>n;
	int x=min(n,b-1);
	cout<<(a*x)/b-a*(x/b)<<endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
int main(){     
    int n;
    cin >> n;
    vector<int> a(n);
    int s = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        s += a[i];
    }


    int ans = 0;
    int mindiff = 100000000;
    for(int i = 0;i<n;i++){
        if (abs(s-n*a[i]) < mindiff){
            mindiff = abs(s-n*a[i]);
            ans = i;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 3608
#include <stdio.h>
#include <math.h>
int tre[1000][2];
int mem[2][1001];
int main(void){
	int w,n,aw,av,k=0,m,i,j;
	while(scanf("%d",&w)*w){
		scanf("%d",&n);
		for(i=0;i<2;i++){for(j=0;j<=w;j++){mem[i][j]=0;}}
		for(i=0;i<n;i++){scanf("%d,%d",&tre[i][0],&tre[i][1]);}
		mem[0][tre[0][1]-1]=tre[0][0];

		for(m=1;m<n;m++){
			aw=tre[m][1];mem[1][aw-1]=tre[m][0];
			for(i=0;i<w;i++){
				av=mem[0][i];
				if(av>0){
					if(mem[1][i]<av)mem[1][i]=av;
					if(i+aw<=w && mem[1][i+aw]<av+tre[m][0])mem[1][i+aw]=av+tre[m][0];
				}
			}
			av=0;aw=0;
			for(i=0;i<w;i++){
				if(mem[1][i]<=av)mem[0][i]=0;
				else{mem[0][i]=mem[1][i];av=mem[1][i];aw=i+1;}
			}
		}

		if(n==1)printf("Case %d:\n%d\n%d\n",++k,tre[0][0],tre[0][1]);
		else printf("Case %d:\n%d\n%d\n",++k,av,aw);
	}
	return 0;
}

Measured memory_bytes: 616
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
pll papa[12],haha[12];
ll a[212345],pre[212345];
pll searchmin(int l,int r){
	int low=l;
	int high=r-1;
	int mid,ans=l;
	while(low<=high){
		mid=(low+high)/2;
		if(pre[mid]-pre[l-1]<=pre[r]-pre[mid]){
			ans=mid;
			low=mid+1;
		}
		else{
			high=mid-1;
		}
	}
	
	ll mini=min(pre[ans]-pre[l-1],pre[r]-pre[ans]);
	ll maxi = max(pre[ans]-pre[l-1],pre[r]-pre[ans]);
	return mp(mini,maxi);
}
pll searchmax(int l,int r){
	int low=l;
	int high=r-1;
	int mid,ans=r-1;
	while(low<=high){
		mid=(low+high)/2;
		if(pre[mid]-pre[l-1]>=pre[r]-pre[mid]){
			ans=mid;
			high=mid-1;
		}
		else{
			low=mid+1;
		}
	}
	ll mini=min(pre[ans]-pre[l-1],pre[r]-pre[ans]);
	ll maxi = max(pre[ans]-pre[l-1],pre[r]-pre[ans]);
	return mp(mini,maxi);
}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int i;
    f(i,1,n+1){
    	cin>>a[i];
    	pre[i]=pre[i-1]+a[i];
    }
    int j,k;
    ll wow,maxi,mini;
    wow=inf;
    wow*=wow;
    f(i,2,n-1){
    	papa[0] = searchmin(1,i);
    	papa[1] = searchmax(1,i);
    	haha[0] = searchmax(i+1,n);
    	haha[1] = searchmin(i+1,n);
    	rep(j,2){
    		rep(k,2){
    			mini=min(papa[j].ff,haha[k].ff);
    			maxi=max(papa[j].ss,haha[k].ss);
    			wow=min(wow,maxi-mini);
    		}
    	}
    }
    cout<<wow<<endl;

    return 0;  
    
}



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

int main()
{
	vector<int> v;
	int n;
	for (int i = 0; i < 10; i++) {
		cin >> n;
		v.push_back(n);
	}
	sort(v.begin(), v.end());

	for (int i = 0; i < 3; i++) {
		cout << v.back() << endl;
		v.pop_back();
	}
	return 0;
}

Measured memory_bytes: 3124
package main

import (
	"fmt"
	"log"
	"strings"
)

func main() {

	var N, K int //
	var S, s string

	_, err := fmt.Scan(&N, &K, &S)
	if err != nil {
		log.Fatal(err)
		}

	s = S[K - 1 : K]
	s = strings.ToLower(s)

	fmt.Println(S[0:K-1] + s + S[K:N])
}


Measured memory_bytes: 640
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
using mat = vector<vector<ll>>;
using vec = vector<ll>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main(){
int A,B;
cin>>A>>B;
if(A+B>=10){
    cout<<"error"<<endl;
}
else{
    cout<<A+B<<endl;
}





return 0;
}

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

using namespace std;

int n, k;
int a[212345];
int cnt[212345];
int l[212345], r[212345];

int main() {
                                               

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

	for(int i = 1; i <= n; i++) {
		while(q.size() && a[q.top()] > a[i]) q.pop();
		if(q.empty()) l[i] = 1;
		else l[i] = q.top() + 1;
		q.push(i); 
	}
	while(q.size())q.pop();

	for(int i = n; i >= 1; i--) {
		while(q.size()&&a[q.top()]>a[i])q.pop();
		if(q.empty()) r[i]=n;
		else r[i]=q.top()-1;
		q.push(i);
	}

	long long ans = 0;
	for(int i = 1; i <= n; i++)
		ans += (r[i] - i + 1) * 1LL * (i - l[i] + 1) * 1LL * a[i];
	cout << ans;	
}




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

int main(){
  int n,q,i,num,j,ans,y;
     int count = 0;
  cin >> n >>q;
  vector<int> l(q);
  vector<int> r(q);
  vector<int> ac(n);
  string s,t,u;
  int sum=0;
  cin >>s;
  for(i = 0;i<q;i++){
    cin >> l[i] >> r[i];
  }
  ac[0] = 0;
  for(i = 1;i<n;i++){
      if(s[i-1] =='A' && s[i] == 'C'){
        sum += 1;
      }
    ac[i] = sum;
  }
  for(i = 0;i<q;i++){
    j = ac[r[i]-1] - ac[l[i]-1];
    cout << j <<endl;
  }
}

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

int h,w,c,ans;
int dw[4]={1,0,-1,0},dh[4]={0,1,0,-1};

void dfs(int cell[8][8],int rank){
	rank++;
	if(rank==5){
		if(cell[0][0]!=c){
			int tmp=cell[0][0];
			queue<P> que;
			que.push(P(0,0));
			cell[0][0]=c;
			while(que.size()){
				int ph=que.front().first,pw=que.front().second;que.pop();
				rep(j,4){
					if(0<=ph+dh[j]&&ph+dh[j]<h&&0<=pw+dw[j]&&pw+dw[j]<w&&cell[ph+dh[j]][pw+dw[j]]==tmp){
						cell[ph+dh[j]][pw+dw[j]]=c;
						que.push(P(ph+dh[j],pw+dw[j]));
					}
				}
			}
		}
		int cnt=1;
		queue<P> que;
		que.push(P(0,0));
		cell[0][0]=-1;
		while(que.size()){
			int ph=que.front().first,pw=que.front().second;que.pop();
			rep(j,4){
				if(0<=ph+dh[j]&&ph+dh[j]<h&&0<=pw+dw[j]&&pw+dw[j]<w&&cell[ph+dh[j]][pw+dw[j]]==c){
					cell[ph+dh[j]][pw+dw[j]]=-1;
					cnt++;
					que.push(P(ph+dh[j],pw+dw[j]));
				}
			}
		}
		ans=max(ans,cnt);
		return;
	}
	rep(i,6){
		int z[8][8];
		rep(j,8)rep(k,8)z[j][k]=cell[j][k];
		if(cell[0][0]==i)continue;
		queue<P> que;
		que.push(P(0,0));
		int tmp=cell[0][0];
		cell[0][0]=i;
		while(que.size()){
			int ph=que.front().first,pw=que.front().second;que.pop();
			rep(j,4){
				if(0<=ph+dh[j]&&ph+dh[j]<h&&0<=pw+dw[j]&&pw+dw[j]<w&&cell[ph+dh[j]][pw+dw[j]]==tmp){
					cell[ph+dh[j]][pw+dw[j]]=i;
					que.push(P(ph+dh[j],pw+dw[j]));
				}
			}
		}
		dfs(cell,rank);
		rep(j,8)rep(k,8)cell[j][k]=z[j][k];
	}
}

int main(){
	int cell[8][8];
	while(cin>>h>>w>>c,h||w||c){
		ans=0;
		c--;
		rep(i,h)rep(j,w)cin>>cell[i][j];
		rep(i,h)rep(j,w)cell[i][j]--;
		dfs(cell,0);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int d;
  cin>>d;

  vector<ll> p(26);
  rep(i,26) {
    cin>>p[i];
  }


  vector<vector<ll>> q(d,vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin>>q[i][j];
    }
  }

  ll pre=0;
  vector<int> r(26,0);
  rep(i,d-5){
    ll ans=-INF;
    ll memo;
    rep(j,26){
      ll sum=pre;
      auto last=r;
      sum+=q[i][j];
      last[j]=i+1;
      rep(k,26){
        sum-=7*p[k]*(i+1-last[k]);
      }
      if(sum>ans) {
        memo=j;
        chmax(ans,sum);
      }
    }
    cout << memo+1 << endl;
    pre=ans;
    r[memo]=i+1;
  }

  ll answer=-INF;
  ll A,B,C,D,E;
  vector<int> zen(5);
  rep(i,26){
    rep(j,26){
      rep(k,26){
        rep(l,26){
          rep(m,26){
            zen[0]=i;
            zen[1]=j;
            zen[2]=k;
            zen[3]=l;
            zen[4]=m;

            ll sum=0;
            auto last=r;
            rep(n,5){
              sum+=q[d-5+n][zen[n]];
              last[zen[n]]=d-5+n+1;
              rep(o,26){
                sum-=p[o]*(d-5+n+1-last[o]);
              }
            }

            if(sum>answer) {
              A=zen[0];
              B=zen[1];
              C=zen[2];
              D=zen[3];
              E=zen[4];
            }
            chmax(answer,sum);

          }
        }
      }
    }
  }

  cout << A+1 << endl;
  cout << B+1 << endl;
  cout << C+1 << endl;
  cout << D+1 << endl;
  cout << E+1 << endl;
  
}

Measured memory_bytes: 3756
N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
PX = [list(map(int,input().split())) for _ in [0]*Q]

E = [[] for _ in [0]*N]
for a,b in AB:
    a-=1
    b-=1
    E[a].append(b)
    E[b].append(a)

P = [-1]*N
P[0] = 0
q = [0]
while q:
    i = q.pop()
    for j in E[i]:
        if P[j]!=-1: continue
        P[j] = i
        q.append(j)
P[0] = -1

V = [0]*N
for p,x in PX:
    p-=1
    V[p] += x

q = [0]
done = [False]*N
while q:
    i = q.pop()
    done[i] = True
    for j in E[i]:
        if done[j] : continue
        V[j] += V[i]
        q.append(j)

print(*V)

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

int main(){
    int n,m;
    cin >>n>>m;
    int h[n],situ[n];
    fill(situ,situ+n,1);
    rep(i,n){
        cin >>h[i];
    }
    int a[m],b[m];
    rep(i,m){
        cin >>a[i]>>b[i];
        if(h[a[i]-1]>h[b[i]-1]){
            situ[b[i]-1]=-1;
        }else if(h[a[i]-1]<h[b[i]-1]){
            situ[a[i]-1]=-1;
        }else{
            situ[a[i]-1]=-1;
            situ[b[i]-1]=-1;
        }
    }
    int ans=0;
    rep(i,n){
        if(situ[i]==1) ans++;
    }
    cout << ans <<endl;
    
    return 0;
}

Measured memory_bytes: 5144
N = int(input())
As = list(map(int, input().split()))

L = sum(As)
L2 = L * 2
acc = 0
minD = float('inf')
for a in As:
    acc += a * 2
    d = abs(acc - L)
    minD = minD if minD < d else d
print(minD)

Measured memory_bytes: 26764
import java.util.*;
import java.io.*;
import java.math.*;

public class Main 

{ 
static int mod=1000000007;

	 static FastReader sc=new FastReader(); 
	 
		  public static void main(String[] args) 
    {
			  int n=i();
			  int max=0;
			  int c=0;
			  for(int i=0;i<n;i++) {
				  int a=i();
				  int b=i();
				  if(a==b) {
					  c++;
				  }
				  else {
					  if(c>max)
						  max=c;
					  c=0;
				  }
			  }
			  if(c>max)
				  max=c;
			  if(max>=3)
				  System.out.println("Yes");
			  else
				  System.out.println("No");
			  
			  
			  
    }

		  
		  
		  
static int[] input(int n) {
	int A[]=new int[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.nextInt();
	   }
	   return A;
   }
static long[] inputL(int n) {
	long A[]=new long[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.nextLong();
	   }
	   return A;
   }
static String[] inputS(int n) {
	String A[]=new String[n];
	   for(int i=0;i<n;i++) {
		   A[i]=sc.next();
	   }
	   return A;
   }


static void input(int A[],int B[]) {
	   for(int i=0;i<A.length;i++) {
		   A[i]=sc.nextInt();
		   B[i]=sc.nextInt();
	   }
}
static long mod(long x) {
	  return ((x%mod + mod)%mod);
}

     static int i() {
    	 return sc.nextInt();
     }
     static String s() {
    	 return sc.next();
     }
     static long l() {
    	 return sc.nextLong();
     }  
     static void sort(int[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
        Arrays.sort(arr);
     }
  
        
        
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
} 





Measured memory_bytes: 32784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iomanip>

using namespace std;

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

	vector<int> ls(2 * n);
	for(auto& l : ls) {
		cin >> l;
	}

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

	int ans = 0;
	for(int i = 0; i < n; ++i) {
		ans += ls[2 * i];
	}	

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    string ans = "";

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

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

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

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int a[3][2];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 2; j++) a[i][j] = 0;
		}
		int b, c, d;
		for (int i = 0; i < n; i++) {
			scanf("%d:%d %d", &b, &c, &d);
			if (b < 11) b += 24;
			if (d < c) d += 60;
			int f = d - c;
			int e = b * 60 + c;
			if (e >= 11 * 60 && e < 15 * 60) {
				a[0][0]++;
				if (f <= 8) a[0][1]++;
			}
			if (e >= 18 * 60 && e < 21 * 60) {
				a[1][0]++;
				if (f <= 8) a[1][1]++;
			}
			if (e >= 21 * 60) {
				a[2][0]++;
				if (f <= 8) a[2][1]++;
			}
		}
		if (a[0][0] == 0) {
			cout << "lunch no guest" << endl;
		}
		else {
			cout << "lunch " << (a[0][1] * 100) / a[0][0] << endl;
		}
		if (a[1][0] == 0) {
			cout << "dinner no guest" << endl;
		}
		else {
			cout << "dinner " << (a[1][1] * 100) / a[1][0] << endl;
		}
		if (a[2][0] == 0) {
			cout << "midnight no guest" << endl;
		}
		else {
			cout << "midnight " << (a[2][1] * 100) / a[2][0] << endl;
		}
	}
}

Measured memory_bytes: 3108
// 各番号間の最短距離をBFSで算出して合計する

#include <bits/stdc++.h>

using namespace std;

struct P
{
  int x;
  int y;
};

int const INF = 1000000;

int N, M, L;

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

// 分かりにくいけど破壊的に現在を変更していく
// 順々にチーズを食べてくいくことを表現するため
int bfs(vector<vector<char>> field, P &current, char end)
{
  vector<vector<int>> d(N, vector<int>(M, INF));

  queue<P> q;
  q.push(current);

  d.at(current.x).at(current.y) = 0;

  while (q.size())
  {
    P p = q.front();
    q.pop();

    // 現在位置の更新
    current.x = p.x;
    current.y = p.y;

    if (field.at(p.x).at(p.y) == end)
      break;

    // 四方を探索
    for (int i = 0; i < 4; i++)
    {
      int nx = p.x + dx.at(i);
      int ny = p.y + dy.at(i);      

      // 範囲内
      if (0 <= nx && nx < N && 0 <= ny && ny < M)
      {        
        // 障害物でない、かつ未訪問
        if (field.at(nx).at(ny) != 'X' && d.at(nx).at(ny) == INF)
        {          
          d.at(nx).at(ny) = d.at(p.x).at(p.y) + 1;
          q.push(P{nx, ny});
        }
      }
    }
  }

  return d.at(current.x).at(current.y);
}

string cheese = "123456789";

int main()
{
  P start = P{0, 0};

  cin >> N >> M >> L;

  vector<vector<char>> field(N, vector<char>(M));

  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      cin >> field.at(i).at(j);

      if (field.at(i).at(j) == 'S')
        start = P{i, j};
    }
  }

  int count = 0;

  for (int i = 0; i < L; i++)
  {
    count += bfs(field, start, cheese.at(i));
  }
  cout << count << endl;
}



Measured memory_bytes: 8860
n, k  = map(int, input().split())
an = list(map(int, input().split()))
bn = [-1]*(n+1)

now=1
bn[1]=0
for i in range(1, k+1):
 #   print(bn)
    now = an[now-1]
    if bn[now] >0:
        rp =i-bn[now]
        p= (k-i)%rp
        for j in range(p):
            now = an[now-1]
        print(now)
        exit(0)
    bn[now]=i
print(now)

Measured memory_bytes: 92220
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		for(int i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 24288
#include<iostream>
#include<algorithm>
#define F 114514
using namespace std;
int s[F],e[F],q;bool c[F];void a(bool t,bool r){if(t){if(c[q-1]!=r){if(q==1)e[0]++,c[0]=r;else{e[q-2]=e[q-1]+1;q--;}}else e[q-1]++;return;}if(c[q-1]!=r)s[q]=e[q-1],e[q]=s[q]+1,c[q]=r,q++;else e[q-1]++;return;}int main(){int n,t;while(true){cin>>n;if(!n)break;cin>>t;s[0]=0,e[0]=1,c[0]=t,q=1;for(int i=1;i<n;i++){cin>>t;a(i%2,t);}int o=0;for(int i=0;i<q;i++)if(!c[i])o+=e[i]-s[i];cout<<o<<endl;}return 0;}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int a[3];
	for (int i = 0; i < 3; i++) cin >> a[i];

	if (a[0] == a[1] && a[1] == a[2])  cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

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

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

    li pay = A * N;
    if (pay < B) {
        cout << pay;
    } else {
        cout << B;
    }
    cout << endl;
    return 0;
}


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

int main(){
  int d,ans = 0;
  cin>>d;
  int x,y;
  cin>>x;
  vector<int> X,Y;
  for(int i = 0;i < x;i++){
    int p;
    char a;cin>>a>>p;
    if(a!='D')continue;
    X.push_back(p);
  }
  cin>>y;
  for(int i = 0;i < y;i++){
    int q;
    string s;cin>>s>>q;
    if(s[0]!='D'||s[1]!='D')continue;
    Y.push_back(q);
  }
  sort(X.begin(),X.end(),greater<int> ());
  sort(Y.begin(),Y.end(),greater<int> ());

  for(int i = 0;i <= Y.size();i++){
    int res = 0,td = d;
    
    for(int j = 0;j <i;j++){
      if(2 <= td){
        td-=2;
        res += Y[j];
      }      
    }    

    for(int j = 0;j < X.size();j++){
      if(1 <= td){
        td--;
        res += X[j];
      }
    }
    ans = max(ans,res);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-10, PI = acos(-1);
const int N = 2e5 + 9, M = 1e5 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<int> adj[N];
bool vis[N];
ll Xs, Ys;

void dfs(int node) {
  if(node > 1e5)
    ++Ys;
  else
    ++Xs;
  vis[node] = 1;
  for(int it: adj[node]) {
    if(vis[it]) continue;
    dfs(it);
  }
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, x, y;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x >> y;
    y += 1e5;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  ll total = 0;
  for (int i = 0; i < N; ++i) {
    if(!vis[i]) {
      Xs = Ys = 0;
      dfs(i);
      total += (Xs * Ys);
    }
  }
  cout << total - n;
}


Measured memory_bytes: 10240
s = list(input())
t = list(input())

#sを可能な限り一番小さい文字列,tを可能な限り一番大きな文字列にする
s.sort()
t.sort(reverse=True)
s_ = "".join(s)
t_ = "".join(t)

if s_ < t_:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(abs(b-a) <= d && abs(c-b) <= d || abs(a-c) <= d){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256