akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

struct D {
  pii seg;
  set<pii> st[2];
};

int N;
int P[214514];
int belong[214514];
vector<D> ds;
vector<int> ans;
priority_queue<pii, vector<pii>, greater<pii>> que;

pii Split(int k, int idx) {
  auto &d = ds[k];

  rep(i, 2) d.st[i].erase(pii(P[idx], idx));

  int l, r;
  tie(l, r) = d.seg;
  pii as(l, idx);
  pii bs(idx+1, r);
  pii ss = as;
  bool rev = false;
  if (as.Y - as.X > bs.Y - bs.X) {
    ss = bs;
    rev = true;
  }

  int nk = ds.size();
  D nd;
  reps(i, ss.X, ss.Y) {
    rep(j, 2) d.st[j].erase(pii(P[i], i));
    nd.st[(i-ss.X)%2].insert(pii(P[i], i));
    belong[i] = nk;
  }

  pii ret;
  if (!rev) {
    nd.seg = as;
    d.seg = bs;
    swap(d.st[0], d.st[1]);
    ret = pii(nk, k);
  } else {
    nd.seg = bs;
    d.seg = as;
    ret = pii(k, nk);
  }
  ds.eb(nd);
  return ret;
}

void Show() {
  /*puts("=======");
  rep(j, (int)ds.size()) {
    auto &d = ds[j];
    printf("%d=[%d, %d):\n", j, d.seg.X, d.seg.Y);
    rep(i, 2) {
      printf("%d: ", i);
      for (auto &p : d.st[i]) {
        printf("(%d, %d) ", p.X, p.Y);
      }
      puts("");
    }
  }
  puts("=======");
  */
}

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

  ds.resize(1);
  ds[0].seg = pii(0, N);
  rep(i, N) {
    scanf("%d", &P[i]);
    --P[i];
    ds[0].st[i%2].insert(pii(P[i], i));
  }

  que.push(pii(*ds[0].st[0].begin()));
  while (!que.empty()) {
    auto pa = que.top(); que.pop();
    //printf("pa: %d, %d\n", pa.X, pa.Y);
    ans.eb(pa.X);
    int idx = pa.Y;
    int b = belong[idx];
    int c[3];
    tie(c[0], c[1]) = Split(b, idx);
    Show();
    assert(!ds[c[1]].st[0].empty());
    auto &qa = *ds[c[1]].st[0].begin();
    ans.eb(qa.X);
    tie(c[1], c[2]) = Split(c[1], qa.Y);
    Show();

    rep(i, 3) {
      //printf("c[%d]=%d ", i, c[i]);
      if (ds[c[i]].st[0].empty()) {
        assert(ds[c[i]].st[1].empty());
        continue;
      }

      //printf("pushed: %d, %d\n", ds[c[i]].st[0].begin()->X, ds[c[i]].st[0].begin()->Y);
      que.push(pii(*ds[c[i]].st[0].begin()));
    }
    //puts("");
  }

  assert(ans.size() == N);
  rep(i, N) {
    printf("%d%c", 1+ans[i], " \n"[i == N-1]);
  }
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    cin>>N;
    vi count(10001);
    REP(x, 1, 101){
        REP(y, 1, 101){
            REP(z, 1, 101){
                int n = x*x + y*y + z*z + x*y + y*z + z*x;
                if(n > 10000) continue;
                count[n]++;
            }
        }
    }
    REP(i, 1, N+1) cout << count[i] << endl;
    return 0;
}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
#define INF 1LL<<30
#define MAXN 1000003
#define pb push_back
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
#define fst first
#define snd second
#define B 127
#define endl '\n'
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
const int  ALF = 5;
struct nodo{
    int termina;
    int hijos[ALF];
    nodo(){
        termina = -1;
        for(int i = 0; i < ALF; i++){
            hijos[i] = -1;
        }
    }
};
nodo Trie[MAXN];

int ultimo = 1;
int valor(char c){
    if(c == 'A') return 1;
    if(c == 'C') return 2;
    if(c == 'G') return 3;
    if(c == 'T') return 4;
}

void Agregar(string &s, int idx){
    int pos = 0;

    for(int i = 0; i<s.size(); i++){
        if(Trie[pos].hijos[valor(s[i])] == -1){
            ultimo++;
            Trie[pos].hijos[valor(s[i])] = ultimo;
        }
        pos = Trie[pos].hijos[valor(s[i])];

    }
    if(Trie[pos].termina == -1){
        Trie[pos].termina = idx;
    }

}

bool Busca(string &s){
    int pos = 0;
    for(int i = 0; i<s.size(); i++){
        pos = Trie[pos].hijos[valor(s[i])];
        if(pos == -1) return false;
    }
    if(Trie[pos].termina == -1) return false;
    return true;
}



int main(){
    int n;

    cin >> n;
    cin.ignore();
    int diff = 1;
    for(int t = 1; t<=n; t++){
        string q,p;
        cin >> q >> p;
        if(q == "insert"){

            Agregar(p,diff);
            diff++;
        }else{
            if(Busca(p)){
                cout << "yes";
            }else{
                cout << "no";
            }
            cout << endl;
        }
    }

    return 0;

}



Measured memory_bytes: 26632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdio>

using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<int> P(N),Q(N);
  vector<int> v(N);
  for(int i=0;i<N;i++){
    cin >> P[i];
  }
  for(int i=0;i<N;i++){
    cin >> Q[i];
    v[i]=i+1;
  }
  int j=1;
  int a,b;
  do{
    if(P==v) a=j;
    if(Q==v) b=j;
    j++;
  }while(next_permutation(v.begin(),v.end()));
  cout << abs(a-b) << endl;
}



Measured memory_bytes: 3140
#include <iostream>
#include <string>
using namespace std;
int a[893];
int main()
{
    int n,m,x,iwa=0;
    cin>>n>>m>>x;
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    for(int i=0;i<m;i++){
        if(a[i]>x){break;}
        iwa++;
    }
    int ta=m-iwa;
    if(iwa<ta){cout<<iwa<<endl;}
    else{cout<<ta<<endl;}
}



Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    val (h,w) = readLine()!!.split(" ").map{it.toInt()}
    val s = Array(h){CharArray(w)}
    for(i in 0 until h){
        val t = readLine()!!
        s[i] = t.toCharArray()
    }
    val dx = intArrayOf(0,1,0,-1)
    val dy = intArrayOf(1,0,-1,0)
    val inf = 10000000
    fun calc(y : Int, x : Int) : Int{
        val q = ArrayDeque<Pair<Int,Int>>()
        var dist = Array(h) {IntArray(w){inf} }
        dist[y][x] = 0
        q.push(Pair(y,x))
        while(q.isNotEmpty()){
            val cury = q.first.first
            val curx = q.first.second
            q.removeFirst()
            for(i in 0 .. 3){
                val nexty = cury + dy[i]
                val nextx = curx + dx[i]
                if(nextx >= 0 && nextx < w && nexty >= 0 && nexty < h && dist[nexty][nextx] == inf && s[nexty][nextx] == '.'){
                    dist[nexty][nextx] = dist[cury][curx] + 1
                    q.addLast(Pair(nexty, nextx))
                }
            }
        }
        var ret = 0
        for(i in 0 until h){
            for(j in 0 until w){
                if(dist[i][j] != inf) ret = Math.max(ret, dist[i][j])
            }
        }
        return ret
    }
    var ans = 0
    for(i in 0 until h){
        for(j in 0 until w){
            if(s[i][j] == '.') ans = Math.max(calc(i, j), ans)
        }
    }
    println(ans)
}


Measured memory_bytes: 41952
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static class Tuple implements Comparable<Tuple> {
		int s, t, c;

		Tuple(String[] tokens) {
			this.s = Integer.parseInt(tokens[0]) - 1;
			this.t = Integer.parseInt(tokens[1]) - 1;
			this.c = Integer.parseInt(tokens[2]) - 1;
		}

		Tuple(int s, int t, int c) {
			this.s = s;
			this.t = t;
			this.c = c;
		}

		@Override
		public int compareTo(Tuple o) {
			// 開始時刻でソート
			return Integer.compare(this.s, o.s);
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int C = Integer.parseInt(tokens[1]);
		List<Tuple> programs = new ArrayList<>(N);
		Map<Integer, List<Tuple>> map = new HashMap<>();
		for (int i = 0; i < C; ++i) {
			map.put(i, new ArrayList<Tuple>());
		}
		for (int i = 0; i < N; ++i) {
			tokens = in.readLine().split(" ");
			Tuple tuple = new Tuple(tokens);
			map.get(tuple.c).add(tuple);
		}
		// チャンネルごとに連続する番組を1つとして扱う
		for (int i = 0; i < C; ++i) {
			Collections.sort(map.get(i));
			Deque<Tuple> deque = new ArrayDeque<>(map.get(i).size());
			deque.addAll(map.get(i));
			while (!deque.isEmpty()) {
				if (deque.size() == 1) {
					// のこり1つの要素をprogramsに入れる
					programs.add(deque.poll());
				} else {
					Tuple elem = deque.poll();
					if (elem.t == deque.peek().s) {
						// 要素をつなげる
						Tuple newElem = new Tuple(elem.s, deque.poll().t, elem.c);
						deque.addFirst(newElem);
					} else {
						programs.add(elem);
					}
				}
			}
		}
		Collections.sort(programs);
		// 先頭から順に取り出し，queueに入れていく．
		// queueは終了時刻に基づくpriority queueとし，その最大要素数を解とする
		Queue<Tuple> queue = new PriorityQueue<>(new Comparator<Tuple>() {
			@Override
			public int compare(Tuple o1, Tuple o2) {
				// 終了時刻でソート
				return Integer.compare(o1.t, o2.t);
			}
		});
		int maxSize = 1;
		queue.add(programs.get(0));
		for (int i = 1; i < programs.size(); ++i) {
			Tuple program = programs.get(i);
			// 終了している番組を除去
			while (!queue.isEmpty()) {
				if (queue.peek().t < program.s) {
					queue.poll();
				} else {
					break;
				}
			}
			queue.add(program);
			maxSize = Math.max(maxSize, queue.size());
		}
		System.out.println(maxSize);
	}
}


Measured memory_bytes: 48504
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a=n/100;
	if(a*111>=n){
		cout<<a*111<<endl;
	}else{
		cout<<(a+1)*111<<endl;
	}
	return 0;
}

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

int main() {
    string S;
    cin >> S;
    string ans;
    if (S == "Sunny") ans = "Cloudy";
    else if (S == "Cloudy") ans = "Rainy";
    else ans = "Sunny";
    cout << ans << endl;
}

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

int selectionSort(int A[],int N){
    int minj,cnt=0;
    for(int i=0;i<N;i++){
        minj=i;
        for(int j=i;j<N;j++){
            if(A[minj]>A[j]){
                minj=j;
            }
        }
      	if(A[i] != A[minj]){
        	swap(A[i],A[minj]);
          	cnt++;
        }
    }
    return cnt;
}

int main() 
{
    int n,res;
    cin >> n;
    int A[n];
    rep(i,n){
        cin >> A[i];
    }

    res = selectionSort(A,n);

    rep(i,n){
        if(i){
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl << res << endl;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

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

    string S, T; cin >> S >> T;
    T.pop_back();
    if(S == T) cout << "Yes" << endl;
    else cout << "No" << endl;    

    return 0;
}



Measured memory_bytes: 3648
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        long ans = 0;
        for(int i = 0; i < n-1; i++) {
            long diff = a[i] + a[i+1] - x;
            if(diff <= 0) continue;
            ans += diff;
            if(a[i+1] >= diff) {
                a[i+1] -= diff;
            } else {
                diff -= a[i+1];
                a[i+1] = 0;
                a[i] -= diff;
            }
        }
        System.out.println(ans);
    }
}


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

int main() {
  vector<int> a(13);
  cin>>a.at(0)>>a.at(1)>>a.at(2);
  for(int i=3;i<13;i++){
    a.at(i)=a.at(0)*a.at(i-1)-a.at(1);
    cout<<a.at(i)<<endl;
  }
}

Measured memory_bytes: 256
def f(n):
  if n % 2 == 0:
    return n//2
  else:
    return 3*n + 1


s = int(input())
a = [s]
i = 0
while True:
  s = f(a[i])
  if s in a:
    print(i+2)
    break
  else:
    a.append(s)
    i += 1



Measured memory_bytes: 2940
#include <stdio.h>
int main(void){
    
    
    
        double mt;
        double high=0;
        double low=100000;
        while(scanf("%lf",&mt)!=EOF){
            
            if(mt>high){
                high=mt;
            }   
            
            if(mt<low){
                low=mt;
            }   
    
            
        }
        
        
        printf("%.1f\n",high-low);
}



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

int main(void){
    string s[3];
    rep(i,3)cin>>s[i];
    cout<<"A"<<s[1][0]<<"C"<<endl;
    return 0;
}


Measured memory_bytes: 256
t1,t2,r1,r2 = map(int,input().split())
if r1 == -1 or r2 == -1:
    if t1 < t2:
        print('Alice')
    elif t1 > t2:
        print('Bob')
    else:
        print('Draw')
elif r1 > r2:
    print('Alice')
elif r1 < r2:
    print('Bob')
else:
    print('Draw')


Measured memory_bytes: 5596
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

    vector<int> t(1'000'001);
    sort(a.begin(), a.end());

    for (int i : a) {
        t[i]++;
        if (t[i] > 1)
            continue;

        for (int j = i * 2; j < t.size(); j += i) {
            t[j]++;
        }
    }

    int ans = 0;
    for (int i : a) {
        if (t[i] == 1)
            ans++;
    }
    cout << ans << endl;

    return 0;
}


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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define se second
#define fi first
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef vector<int>  vi;
typedef pair<ii, ll>  iii;
typedef pair<double, double>  iidb;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const double PI = acos(-1);
#define initseg ll new_nodo=(nodo*2)+1,mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define offset 9000

const ll MOD=1e9+7;

#define cmplog 20
#define tam 600000


using namespace std;

int main()
{	
	ios::sync_with_stdio(false);cin.tie(0);
	string txt;
	cin>>txt;
	if (txt.back()=='s')
		cout<<txt+"es";
	else
		cout<<txt+"s";
}


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

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i < x; ++i) 
		if (x % i == 0) return false;
	return true;
}

int main() {
	int x;
	cin >> x;
	
	int p = x;
	while (!is_prime(p)) ++p;
	
	cout << p << endl;
}


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

int main()
{
    int a,b;
    cin >> a >> b;
    int digit;
    int n = 1;
    int sum;
    digit = log10(b) + 1;

    for(int i = 0; i < digit; i++){
        n *= 10;
    }
    
    sum = a * n + b;

    for(int i = 1; i * i <= sum; i++){
        if(i == sqrt(sum)){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,M; cin >> N >> M;
	vector<LL> x(N),y(M);
	repp(i,0,N) cin >> x[i];
	repp(i,0,M) cin >> y[i];
	LL sx = 0, sy = 0;
	const LL mod = 1e9+7;
	repp(i,1,N) (sx += (x[i]-x[i-1])*i%mod*(N-i)) %= mod;
	repp(i,1,M) (sy += (y[i]-y[i-1])*i%mod*(M-i)) %= mod;
	cout << sx*sy%mod << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c + 9 * max({ a,b,c });
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    #define fi first
    #define se second
    #define sz(v) (int)((v).size())
    #define pb push_back
     
    typedef long long ll;
     
    int main()
    {
    	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
     
    	int n, k; cin >> n >> k;
    	vector<double> p(n);
    	for (int i=0; i<n; i++) cin >> p[i];
    	double exp = 0;
    	for (int i=0; i<k; i++) exp += (p[i]+1)/2;
    	double ans = exp;
    	for (int i = k; i < n; i++) {
    		exp += (p[i]+1)/2;
    		exp -= (p[i-k]+1)/2;
    		ans = max(ans, exp);
    	}
    	cout << fixed << setprecision(6) << ans << "\n";
    }

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


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

    printf("%d %d\n",min(A,B),max(A+B-N,0));

    return 0;
}

Measured memory_bytes: 256
import sys, math, re
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = input()
    k = 0
    for i in N:
        k += int(i)
        k %= 9

    if k == 0:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

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


int c(char c){
	return c=='I'? 1:
		c=='V'? 5:
		c=='X'? 10:
		c=='L'? 50:
		c=='C'? 100:
		c=='D'? 500: 1000;
}


int main(){
	string s;
	while(cin>>s){
		int sum=0, i=0;
		for(; i<s.size()-1; i++){
			if(c(s[i])>=c(s[i+1]))sum+=c(s[i]);
			else
				sum+=c(s[i+1])-c(s[i]), i++;
		}
		if(i<s.size())sum+=c(s[i]);
		cout<<sum<<"\n";
		s.clear();
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll p=1000000007;
ll bin(ll x,ll po)
{
    ll ans=1;
    if(po==0)
        return ans;
    if(po%2==1)
    {
        ans=ans*x%p;
        po--;
    }
    ll p1=bin(x,po/2);
    ans=ans*p1%p;
    ans=ans*p1%p;
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll n=s.length();
    ll ans=0;
    ll cur=1;
    for(ll i=0;i<s.length();i++)
    {
        if(s[i]=='1')
        {
            ans=(ans+cur*(bin(3,n-1-i))%p)%p;
            cur=cur*2%p;
        }
    }
    ans=(ans+cur)%p;
    cout<<ans;
}

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

int func(int x) {
    if(x % 100 != 0)
        return 0;

    return func(x / 100) + 1;
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int d,n,cnt=0;
    cin >>d>>n;
    int i = 1;
    while(true){
        if(func(i)==d){
            cnt++;
        }
        if(cnt == n){
            cout << i <<endl;
            return 0;
        }
        i++;
    }
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main(){
    //freopen("5.in","r",stdin);
    //freopen("5.out","w",stdout);
    int n,m;
    cin>>n>>m;
    for(int i=m-n+1;i<m+n;i++){
        cout<<i<<" ";
    }
    return 0;
}


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

int main()
{
    int count[1001] = {0};
    int n;
    long long ans = 1;
    const long long m = pow(10, 9) + 7;
    cin >> n;
    for(int i = 2; i <= n; i++){
        int k = i;
        for(int j = 2; j <= i; j++){
            while(k % j == 0){
                count[j] += 1;
                k /= j;
            }
        }
    }
    for(int i = 1; i <= n; i++){
       ans = (ans * (count[i] + 1)) % m;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 2:
    x, y = A[1], A[0]
    print(x-y)
    print(x, y)
    exit()
idx = bisect.bisect_left(A, 0)
if idx:
    if idx < N:
        Q = A[:idx]
        P = A[idx:]
    else:
        Q = A[:-1]
        P = [A[-1]]
else:
    Q = [A[0]]
    P = A[1:]


XY = []
LP = len(P)
for i in range(LP-1):
    XY.append((Q[0], P[i]))
    Q[0] -= P[i]
LQ = len(Q)
for i in range(LQ):
    XY.append((P[-1], Q[i]))
    P[-1] = P[-1] - Q[i]
ans = P[-1]
print(ans)
for x, y in XY:
    print(x, y)





Measured memory_bytes: 64396
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define TR(it,c) for( typeof(c.begin()) it = c.begin(); it != c.end(); ++it )
#define TRR(it,c) for( typeof(c.rbegin()) it = c.rbegin(); it != c.rend(); ++it
#define REP(i,a) for (int i = 0; i < (a); i++)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)

#define DRI(a) int a; scanf("%d", &a);
#define DRII(a, b) int a, b; scanf("%d %d", &a, &b);
#define DRIII(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c);
#define RI(a) scanf("%d", &a);
#define RII(a, b) scanf("%d %d", &a, &b);
#define RIII(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define MM(arr, num) memset((arr), (num), sizeof((arr)))
#define DEB(x) cerr << ">>> " << (#x) << " -> " << (x) << endl;
#define DEBA(x,n) cerr << (#x) << " "; deba((x),(n));
void deba(int * a, int n){ cerr << "| "; REP(i,n) cerr << a[i] << " "; cerr << "|" << endl;}


inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

const int INF = 1<<30;
typedef long long ll;
typedef unsigned long long ull;
/*******************************************************/

char s[123456];

int main() {

  scanf("%s",s);
  int len = strlen(s);
  int sc = 0;

  REP(i,len){
    if(i%2){
      if( s[i] != 'p' )sc+= 1;
    }
    else{
      if(s[i] == 'p') sc-=1;
    }
  }

  cout << sc << endl;

  return 0;
}


Measured memory_bytes: 384
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	string s;
	cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}


Measured memory_bytes: 256
n = gets.to_i
a = readlines.map(&:to_i)
sa = 0
soko = 0;
for i in 0..n-1 do
  if sa <= a[i] 
    sa = a[i]
    soko = i
  end
end
a[soko] = 0
ni = 0
for i in 0..n-1 do
  if ni <= a[i]
    ni = a[i]
  end
end
for i in 0..n-1 do
  if i != soko
    puts sa
  else
    puts ni
  end
end
  

Measured memory_bytes: 20860
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	str <- getLine
	let
		n = 'N' `elem` str
		w = 'W' `elem` str
		e = 'E' `elem` str
		s = 'S' `elem` str
	putStrLn $ which "Yes" "No" $ n == s && e == w

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    vector<long long> H(5);
    for(long long i = 0; i < 5; i++) cin >> H[i];
    sort(H.begin(),H.end());
    cout << 5 + (N - 1) / H[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;
ll gcd(ll x, ll y){
  if(y==0)return x;
  else return gcd(y,x%y);
}
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a<b && b<c ) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 3116
function Main(arg) 
{
  var S = arg.split("\n")[0].split("");

  var ans = [0 , 0, 0];
  for (var i = 0; i < S.length; i++){
    ans[S[i].charCodeAt() - 'a'.charCodeAt()]++;
  }

  if (Math.abs(ans[0] - ans[1]) > 1 ||
    Math.abs(ans[1] - ans[2]) > 1 ||
    Math.abs(ans[2] - ans[0]) > 1) {
    console.log("NO");
    return;
  }
  console.log("YES");
  return;
}

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

Measured memory_bytes: 8524
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';
const int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };

int N, M, res, res2, a[100001];

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int p;
		string s;
		cin >> p >> s;
		if (a[p] == -1)continue;
		if (s == "AC") {
			res += a[p];
			a[p] = -1;
			res2++;
		}
		else {
			a[p]++;
		}
	}
	cout << res2 << sp << res << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
	int N, min, max, a;
	cin >> N;

	cin >> a;
	min = max = a;
	for (int i = 1; i < N; i++)
	{
		cin >> a;
		if (min > a)
			min = a;

		if (max < a)
			max = a;
	}

	cout << max - min << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (a-c)* (b-d) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll digsum(ll n) {
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 1LL<<60;
    for (ll i = 1; i <= n-1; i++) {
        ll tmp = digsum(i) + digsum(n-i);
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())

num = {}

for i in range(n):
    seq = input()
    seq = ''.join(sorted(seq))
    if seq in num:
        num[seq] += 1
    else:
        num[seq] = 1

ans = 0
for s in num:
    k = num[s]
    if k > 1:
        ans += k * (k-1) // 2

print(ans)

Measured memory_bytes: 17804
A = input()
if (A.count("N") > 0 and A.count("S") == 0) or (A.count("N") == 0 and A.count("S") > 0):
    print("No")
elif (A.count("W") > 0 and A.count("E") == 0) or (A.count("W") == 0 and A.count("E") > 0):
    print("No") 
else:
    print("Yes")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

void solve()
{
	for(int i = 1; i < 10; ++i)
	{
		for(int j = 1; j < 10; ++j)
		{
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1112
class RollingHash():
    def __init__(self, s):
        self.length = len(s)
        self.base = 1009
        self.mod = (1 << 127) - 1
        self.hash = [0] * (self.length + 1)
        self.pow = [1] * (self.length + 1)
 
        for i in range(self.length):
            self.hash[i+1] = (self.hash[i] + ord(s[i])) * self.base % self.mod
            self.pow[i+1] = self.pow[i] * self.base % self.mod
 
    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        t = (t + self.mod) % self.mod
        return t

N = int(input())
S = input()

RH = RollingHash(S)

from collections import defaultdict

def check(length):
    if length==0:
        return True
    dd = defaultdict(int)
    flag = False
    for i in range(N-length+1):
        rh = RH.get(i,i+length)
        if dd[rh]==0:
            dd[rh] = i+1
        else:
            if dd[rh]+length<=i+1:
                flag=True
                break
    return flag

l = 0
r = N

while r-l>1:
    if check((l+r)//2):
        l = (l+r)//2
    else:
        r = (l+r)//2

print(l)

Measured memory_bytes: 46444
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let mut S = rl().chars().collect::<VecDeque<_>>();
    let Q = read!(usize);

    let mut rev = false;
    for _ in 0..Q {
        let query = rl();
        let mut w = query.split_whitespace();
        let t = w.next().unwrap().parse::<i32>().unwrap();
        if t == 1 {
            rev = !rev;
        } else {
            let F = w.next().unwrap().parse::<i32>().unwrap();
            let C = w.next().unwrap().chars().next().unwrap();

            match (F, rev) {
                (1, false) | (2, true) => S.push_front(C),
                (1, true) | (2, false) => S.push_back(C),
                _ => unreachable!(),
            }
        }
    }

    let S = if rev {
        S.into_iter().rev().collect::<String>()
    } else {
        S.into_iter().collect()
    };

    println!("{}", S)
}


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

const int N = 500009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

int n;
string s;

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin>>n>>s;
	if(n%2)
		cout<<"No\n";
	else
	{
		string see;
		for(int i=0;i<(n/2);i++)
		{
			see +=s[i];
		}
		see = see + see;
		if(see == s)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
		
	}
}	

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

int main(){
  int N,Y,Z,X;
  cin >> N >> Y;
  bool flag=false;
  for(int i=0;i<=N;i++){
    if((Y-1000*i==0)&&(i==N)){
      cout << 0 << " " << 0 << " " << i << endl;
      flag=true;
      break;
    }else{
      Z=Y-1000*i;
      for(int j=0;j<=N-i;j++){
        if((Z-5000*j==0)&&(j+i==N)){
          cout << 0 << " " << j << " " << i << endl;
          flag=true;
          break;
        }else{
          X=Z-5000*j;
          for(int k=0;k<=N-i-j;k++){
            if((X-10000*k==0)&&(i+j+k==N)){
              cout << k << " " << j << " " << i << endl;
              flag=true;
              break;
            }
          }
          if(flag){
            break;
          }
        }
      }
      if(flag){
        break;
      }
    }
  }
  if(!flag){
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

long long int gcd(long long int a, long long int b){
    long long int tmp;
    while(1){
        if(a%b == 0){
            return b;
            break;
        }else{
            a = a%b;
            tmp = a;
            a = b;
            b = tmp;
        }
    }
}

int main(void){
    long long int n, i, j, ans;
    scanf("%lld", &n);
    int a[n];
    for(i=0; i<n; i++) scanf("%lld", &a[i]);

    ans = a[0];
    for(i=0; i<n; i++) ans = gcd(ans, a[i]);
    printf("%lld", ans);
}

Measured memory_bytes: 512
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
need = 0
can = 0
for i in range(n):
    if a[i] > b[i]:
        need += a[i] - b[i]
    else:
        can += (b[i] - a[i]) // 2
if need <= can:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;

int dp[10][270];

struct State {
    int v, x, d;
    State(int v, int x, int d): v(v), x(x), d(d) {}
};

int main(){
    int n, m, R;
    cin >> n >> m >> R;
    vector<int> r(R);
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }
    vector<vector<int>> dist(n, vector<int>(n, INF));
    rep(i, n) dist[i][i] = 0;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    rep(k, n) rep(i, n) rep(j, n) {
        chmin(dist[i][j], dist[i][k]+dist[k][j]);
    }
    rep(i, 10) rep(j, 270) dp[i][j] = INF;
    rep(i, R) dp[i][1<<i] = 0;
    auto comp = [](State a, State b) {
        return a.d>b.d;
    };
    priority_queue<State, vector<State>, decltype(comp)> q{comp};
    rep(i, R) q.emplace(i, 1<<i, 0);
    while (!q.empty()) {
        State now = q.top();
        q.pop();
        int nv = now.v;
        int nx = now.x;
        int nd = now.d;
        if (nd>dp[nv][nx]) continue;
        rep(i, R) {
            if (i==nv) continue;
            int iv = i;
            int ix = nx | (1<<i);
            int id = nd + dist[r[nv]][r[i]];
            if (id>=dp[iv][ix]) continue;
            dp[iv][ix] = id;
            q.emplace(iv, ix, id);
        }
    }
    int ans = INF;
    rep(i, R) {
        chmin(ans, dp[i][(1<<R)-1]);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <cstdint>
#include <functional>
#if _WIN32
#include <locale>
#endif

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;

template <class T>
inline void rep(T max, std::function<void(T)> f) {
  for(T i = 0; i < max; ++i) f(i);
}


int main() {
  using namespace std;
  #if _WIN32
  locale::global(locale(""));
  #endif
  u32 s, w;
  cin >> s >> w;
  cout << (s <= w ? "unsafe" :  "safe") << '\n';
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int t,x;
  double ans = 0;

  cin >> t >> x;
  ans = (double)t/x;

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


Measured memory_bytes: 256
#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)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  string s, t;
  int a, b;
  string u;
  cin >> s >> t >> a >> b >> u;
  if (u == s) a--;
  else b--;
  cout << a SP b << endl;
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 10 ** 9 + 7

count = [pow(k // max(i, 1), n, mod) for i in range(k + 1)]

for i in range(k, 0, -1):
  for j in range(2 * i, k + 1, i):
    count[i] -= count[j]

sum_ = 0
for i in range(k + 1):
  sum_ = (sum_ + i * count[i]) % mod

print(sum_)

Measured memory_bytes: 11664
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && k == 0 && m == 0)break;
			else calc(n, k, m);
			
		}
	}
	public void calc(int n, int k, int m){
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = m+1; i < n+1; i++){
			list.add(i);
		}
		for(int i = 1; i < m; i++){
			list.add(i);
		}
		int t = k;
		while(list.size()!=1){
			if(t <= list.size()){
				list.remove(t-1);
				t = t + k - 1;
			}
			else{
				while(t > list.size()){
					t = t - list.size();
				}
				list.remove(t-1);
				t = t + k - 1;
			}
		}
		System.out.println(list.get(0));
	}

	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 38052