akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
G = [ set() for _ in range(n+1) ]
for  _ in range(m):
  a, b = map(int, input().split())
  G[a].add(b)
  G[b].add(a)
seen = [False]*(n+1)

def dfs(v, c):
  if c == n:
    return 1
  seen[v] = True
  temp = 0
  for nv in G[v]:
    if not seen[nv]:
      temp += dfs(nv, c+1)
  seen[v] = False
  return temp

print(dfs(1, 1))

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

int main() {
  int N,W;
  cin>>N>>W;
  vector<vector<int64_t>>p(N+1,vector<int64_t>(W+1,0));
  for(int i=1;i<=N;i++){
    int64_t w,v;
    cin>>w>>v;
    int a=0;
    while(w+a<=W){
      p.at(i).at(w+a)=max(p.at(i-1).at(w+a),p.at(i-1).at(a)+v);
      a++;
    }
    for(int j=0;j<=W;j++){
      p.at(i).at(j)=max(p.at(i).at(j),p.at(i-1).at(j));
  }
  }
  cout<<p.at(N).at(W)<<endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int A, B, S;
  cin >> A >> B;
  S = 0;
  for (int i = A; i <= B; i++) {
      if ( (i/10000 == i%10 ) && ( (i%10000)/1000 == (i%100)/10 ) ) {
          S ++;
      }
  } 
  cout << S << endl;
}

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

int h, w, k;
char s[51][51];
int dp[51][51][1 << 12][4], dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
bool used[51][51];
void mark(int x, int y, int t, int s) {
	used[x][y] = true;
	if (s == 0)return;
	int a = ((t >> 1 & 1) << 1) + (t & 1);
	x -= dx[a], y -= dy[a];
	t >>= 2;
	mark(x, y, t, s - 1);
}
int rec(int x, int y, int t, int a, int cnt) {
	if (dp[x][y][t][a] != -1)return dp[x][y][t][a];
	int res = -INF;
	rep(i, 4) {
		if (i % 2 && !a)continue;
		int nx = x + dx[i], ny = y + dy[i];
		if (nx < 0 || ny < 0 || nx >= h || ny >= w || s[nx][ny] == '#')continue;
		memset(used, 0, sizeof(used));
		mark(x, y, t, cnt);
		int v = ((!used[nx][ny] && '1' <= s[nx][ny] && s[nx][ny] <= '9') ? s[nx][ny] - '0' : 0);
		int p = (t >> (k * 4 - 2)) << (k * 4 - 2); p = t - p;
		p = (p << 2) + i; int b = cnt; if (b < 2 * k)b++;
		int o = rec(nx, ny, p, a - i % 2, b);
		if (o != -INF)res = max(res, o + v);
	}
	if (x == h - 1 && y == w - 1 && res == -INF) {
		return dp[x][y][t][a] = 0;
	}
	return dp[x][y][t][a] = res;
}
int main() {
	scanf("%d%d%d", &h, &w, &k);
	rep(i, h)scanf("%s", s[i]);
	memset(dp, -1, sizeof(dp));
	printf("%d\n", rec(0, 0, 0, k, 0));
}

Measured memory_bytes: 169644
import sys

input = sys.stdin.readline


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.height = [1] * n
        self.size = [1] * n

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.height[x] < self.height[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.height[x] == self.height[y]:
                    self.height[x] += 1

    def group_size(self, x):
        return self.size[self.find(x)]


N, M = map(int, input().split())

uf = UnionFind(M)
lang = set()
for _ in range(N):
    KL = tuple(map(int, input().split()))
    for i in range(1, KL[0]):
        uf.unite(KL[i] - 1, KL[i + 1] - 1)  # 0-indexed
    for i in range(KL[0]):
        lang.add(KL[i + 1] - 1)

lang = list(lang)
print('YES' if uf.group_size(lang[0]) == len(lang) else 'NO')


Measured memory_bytes: 65204
a, b, k = map(int, raw_input().split())

stop = 0

for i in range(k):
    if i % 2 == 0:
        a /= 2
        b += a
        if b == a * 2:
            stop = i + 1
            break
    if i % 2 == 1:
        b /= 2
        a += b
        if a == b * 2:
            stop = i + 1

if stop == 0 or (k - stop) % 2 == 0:
    print a, b
else:
    print b, a



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

using namespace std;
typedef long long ll;

ll H,N;
ll A[1000];
ll B[1000];
priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
ll cost[10001];

int main(){
    cin >> H >> N;
    for(int i=0;i<N;i++) cin >> A[i] >> B[i];
    for(int i=0;i<=H;i++) cost[i] = 1e15;
    pq.push(make_pair(0,0));
    while(true){
        pair<ll,ll> p = pq.top();
        pq.pop();
        ll c = p.first;
        ll d = p.second;
        if(d >= H){
            cout << c << endl;
            break;
        }
        if(cost[d] != 1e15) continue;
        cost[d] = c;
        for(int i=0;i<N;i++){
            if(d+B[i] <= H && cost[d+B[i]] != 1e15) continue;
            pq.push(make_pair(c + B[i],d + A[i]));
        }
    }
    return 0;
}

Measured memory_bytes: 67296
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n; cin >> n;
	REP(t, n) {
		int score = 0;
		int ace = 0;
		char c[2]; cin >> c[0] >> c[1];
		REP(i, 2) {
			if ('2' <= c[i] && c[i] <= '9') {
				score += c[i] - '0';
			} else if (c[i] == 'A') {
				ace++;
				score += 11;
			} else {
				score += 10;
			}
		}
		char stack[8]; REP(_i, 8) { cin >> stack[_i]; }
		if (score == 21) { printf("blackjack\n"); continue; }
		if (score > 21) {
			if (ace) {
				ace--;
				score -= 10;
			}
		}
		int i = -1;
		while (true) {
			if (score == 17) {
				if (ace) {
					goto HIT;
				}
			}
			if (score > 21) {
				printf("bust\n");
				break;
			}
			if (score > 16) {
				printf("%d\n", score);
				break;
			}
			
HIT:
			++i; // Stack position
			if ('2' <= stack[i] && stack[i] <= '9') {
				score += stack[i] - '0';
			} else if (stack[i] == 'A') {
				ace++;
				score += 11;
				if (score > 21) {
					ace--;
					score -= 10;
				}
			} else {
				score += 10;
			}
			if (score > 21) {
				if (ace) {
					ace--;
					score -= 10;
				}
			}
		}
	}
}

Measured memory_bytes: 1148
#include<iostream>
#include<vector>
#include<map>
#include<stack>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

// Recieve edge(=(int,int)) as an adj list.
vector<vector<int>> getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);

	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
// 	putv(graph[i]);
	return graph;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
using namespace std;
int main(){
	vector<int> vec;
	int x;
	rep(i,3){
		cin >> x;
		vec.emplace_back(x);
	}
	sort(vec.begin(),vec.end());
	cout << vec[0] + vec[1] << endl;
}

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

int main() {
    int N;
    cin >> N;
    int sum = 0;
    for (int x=0; x <= N/4; ++x) {
        if ((N - 4*x)%7==0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    stack<int>st;
    stack<pair<int,int> >area;
    char c;
    int sum=0;
    for(int i=0;cin>>c;i++){
        if(c=='\\') st.push(i);
        else if(c=='/'&&st.size()>0){
            int j=st.top();st.pop();
            sum+=(i-j);
            int a=i-j;
            while(area.size()>0&&area.top().first>j){
                a+=area.top().second;area.pop();
            }
            area.push(make_pair(j,a));
        }
    }
    vector<int>ans;
    while(!area.empty()){
        ans.push_back(area.top().second);
        area.pop();
    }
    reverse(ans.begin(),ans.end());
    cout<<sum<<"\n"<<ans.size();
    for(auto i:ans){
        cout<<" "<<i;
    }
    cout<<"\n";
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
ll const mod = 1e9+7;
 
#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<vector<P>> edges(100010),edges1(100010),edges2(100010);
 
void dijkstra(int s,vector<ll>& dist) {
	priority_queue<P,vector<P>,greater<P>> que;
	dist[s] = 0;
	que.push(P(0,s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v =  p.second;
		if (dist[v] < p.first) continue;
		for (int i = 0;i < edges[v].size();++i) {
			P e = edges[v][i];
			if (dist[e.first] > dist[v]+e.second) {
				dist[e.first] = dist[v]+e.second;
				que.push(P(dist[e.first],e.first));
			}
		}
	}
}

void fukugen(int s,vector<ll>& dist) {
	vector<bool> used(100010,false);
	stack<int> st;
	st.push(s);
	used[s] = true;
	while (!st.empty()) {
		int i = st.top();
		st.pop();
		for (P& e : edges[i]) if (dist[i] == dist[e.first]+e.second) {
			if (!used[e.first]) {
				used[e.first] = true;
				st.push(e.first);
			}
			edges1[i].push_back(e);
			edges2[e.first].push_back(P(i,e.second));
		}
	}
}

void dp(int s,vector<ll>& dist,vector<vector<P>>& edges,vector<ll>& dp) {
	priority_queue<P,vector<P>,greater<P>> que;
	vector<bool> used((int)dist.size(),false);
	dp[s] = 1;
	que.push(P(0,s));
	used[s] = true;
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		for (P& e : edges[p.second]) {
			(dp[e.first] += dp[p.second]) %= mod;
			if (!used[e.first]) {
				que.push(P(dist[e.first],e.first));
				used[e.first] = true;
			}
		}
	}
}

int main() {
	int n,m,s,t;
	cin >> n >> m >> s >> t;
	s--;t--;
	vector<ll> dist1(n,1LL<<60),dist2(n,1LL<<60);
	vector<ll> dp1(n,0),dp2(n,0);
	for (int i = 0;i < m;++i) {
		int u,v,w;
		cin >> u >> v >> w;
		u--;v--;
		edges[u].push_back(P(v,w));
		edges[v].push_back(P(u,w));
	}
	dijkstra(s,dist1);
	dijkstra(t,dist2);
	fukugen(s,dist2);
	dp(s,dist1,edges1,dp1);
	dp(t,dist2,edges2,dp2);
	ll ans = 0;
	ans = dp1[t]*dp2[s]%mod;
	for (int i = 0;i < n;++i) if (dist1[i]*2 == dist1[t] && dist2[i]*2 == dist1[t]) (ans -= dp1[i]*dp1[i]%mod*dp2[i]%mod*dp2[i]%mod) %= mod;
	for (int i = 0;i < n;++i) for (P& e : edges1[i]) if (dist1[i]*2 < dist1[t] && dist1[e.first]*2 > dist1[t]) (ans -= dp1[i]*dp1[i]%mod*dp2[e.first]%mod*dp2[e.first]%mod) %= mod;
	cout << (ans+mod)%mod << endl;
	return 0;
}

Measured memory_bytes: 29888
#include<stdio.h>
#include<math.h>
int main()
{
    long x;
    scanf("%ld",&x);
  long long i,j;
    for( i=-120;i<121;i++){
        for( j=-120;j<121;j++){
           if(pow(i,5)-pow(j,5)==x){
              printf("%lld %lld",i,j);
               return 0;
            }
        }
    }
   
}


Measured memory_bytes: 2452
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;


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

	ll L;
	cin >> L;

	vector<ll> dp(1, 1);
	vector<array<ll, 3>> edges;

	while (dp.back() < L) {
		const int j = dp.size();
		dp.push_back(0);
		for (int rep = 0; rep < (dp[j - 1] * 3 <= L ? 3 : 6); ++rep) {
			for (int i = j - 1; i >= 0; --i)
				if (dp[i] + dp[j] <= L) {
					edges.push_back({ i, j, dp[j] });
					dp[j] += dp[i];
					break;
				}
		}
	}

	const int N = dp.size();
	const int M = edges.size();
	assert(dp.back() == L);
	assert(N <= 20 && M <= 60);

	cout << N << ' ' << M << '\n';
	for (auto &&e : edges)
		cout << e[0] + 1 << ' ' << e[1] + 1 << ' ' << e[2] << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x,y,ans;
int main()
{    
    scanf("%lld%lld",&x,&y);
    for(long long i=x;i<=y;i*=2)
    {
    	ans++;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	
	// 花の高さのh[i]が全て0になるまで水やりを行う
	int answer = 0;
	// 花の配列の最大値を返す値が0になるまで、ループを処理する
	while (*max_element(h.begin(), h.end()) > 0)
	{
		int i = 0;
		while (i < N)
		{
			if (h[i] == 0)
			{
				// 次の花へ
				i++;
			}
			else {
				while (i < N && h[i] > 0)
				{
					// 花の水やりで高さ1減らす
					h[i]--;
					// 区間の終わりまで
					i++;
				}
				// 花の水やりの回数を1増やす
				answer++;
			}
		}
	}
	
	// 出力
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray();
            var a = array.First();
            var b = array.Last();

            var answer = new int[] { a + b, a - b, a * b }.Max();

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			int n = int.Parse(Console.ReadLine());
			string dirs = Console.ReadLine();

			int max = 0;

			for (int i = 1; i < dirs.Length - 1; ++i) {
				string a = dirs.Substring(0, i);
				a = new string(a.Distinct().ToArray());
				string b = dirs.Substring(i, dirs.Length - i);
				b = new string(b.Distinct().ToArray());

				int count = 0;
				for (int j = 0; j < a.Length; ++j) {
					if (b.Contains(a[j])) {
						++count;
					}
				}

				if (max < count) {
					max = count;
				}
			}

			Console.WriteLine($"{max}");
			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 13396
def main():
    N, K, C = map(int, input().split())
    S = input()
    ansL = [0] * K
    pos = 0
    idx = 0
    while idx < K:
        if S[pos] == "o":
            ansL[idx] = pos
            idx += 1
            pos += C + 1
        else:
            pos += 1
    ansR = [0] * K
    pos = N-1
    idx = K-1
    while idx >= 0:
        if S[pos] == "o":
            ansR[idx] = pos
            idx -= 1
            pos -= C + 1
        else:
            pos -= 1
    for i in range(K):
        if ansL[i] == ansR[i]:
            print(ansL[i] + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 50764
#include<stdio.h>
 
int main()
{
    int n;
    scanf("%d",&n);
     
    int f[50];
     
    f[0]=f[1]=1;
     
    int i;
    for(i=2;i<=n;i++)//iは2以上でそれ以下は1
    {
        f[i]=f[i-1]+f[i-2];
    }
     
    printf("%d\n",f[n]);
     
    return 0;
}


Measured memory_bytes: 2044
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[25100000] = {};

int main(){
    int N;
    cin >> N;
    long long int g1, s1, b1, g2, s2, b2;
    cin >> g1 >> s1 >> b1;
    cin >> g2 >> s2 >> b2;
    for(int i = 0; i <= N; i++){
        DP[i] = i;
    }
    for(int i = 0; i <= N; i++){
        DP[i + g1] = max(DP[i + g1], DP[i] + g2);
        DP[i + s1] = max(DP[i + s1], DP[i] + s2);
        DP[i + b1] = max(DP[i + b1], DP[i] + b2);
    }
    long long int S1 = DP[N];
    for(int i = 0; i <= S1; i++){
        DP[i] = i;
    }
    for(int i = 0; i <= S1; i++){
        DP[i + g2] = max(DP[i + g2], DP[i] + g1);
        DP[i + s2] = max(DP[i + s2], DP[i] + s1);
        DP[i + b2] = max(DP[i + b2], DP[i] + b1);
    }
    cout << DP[S1] << endl;
    return 0;
}

Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n; cin >> n;
  	long long ans = 0LL;
  	for (int i = 1; i <= n; i++) {
     	if (i % 3 && i % 5) ans += i; 
    }
  	cout << ans << endl;
}


Measured memory_bytes: 3560
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
//#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 3000;
int mod = 998244353;
int d[N][N], cnt[N];
void solve(vector < int > v, int lvl = 1){
    int n = v.size();
    if (n == 1) return;
    for (int i = 0; i < n / 2; i++){
        for (int j = n / 2; j < n; j++){
            int v1 = v[i];
            int v2 = v[j];
            d[v1][v2] = d[v2][v1] = lvl;
        }
    }
    vector < int > a1, a2;
    a1.clear();
    a2.clear();
    for (int i = 0; i < n / 2; i++) a1.pb(v[i]);
    for (int i = n / 2; i < n; i++) a2.pb(v[i]);
    solve(a1, lvl + 1);
    solve(a2, lvl + 1);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    vector < int > v;
    for (int i = 1; i <= n; i++) v.pb(i);
    solve(v);
    for (int i = 1; i <= n; i++){
        for (int j = i + 1; j <= n; j++) cout << d[i][j] << " ";
        cout << endl;
    }
}


Measured memory_bytes: 5632
#include<stdio.h>
int main(void)
{
    int n,k[1001],p[1001],x[1001],i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    scanf("%d %d",&k[i],&p[i]);
		x[i]=k[i]%p[i];
	}
	for(i=0;i<n;i++){
	    if(x[i]==0){
		    printf("%d\n",p[i]);
		}
		else if(x[i]==k[i]){
		    printf("%d\n",k[i]);
		}
		else {
		    printf("%d\n",x[i]);
		}
	}
	return 0;
}

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

#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

vector<int> a;

void factorize(int n) 
{ 
    int count = 0; 
    while (!(n % 2))
    { 
        n >>= 1;
        count++; 
    }
    if (count) a.push_back(2);
    for (int i = 3; i <= sqrt(n); i+=2)
    { 
        count = 0; 
        while (n % i == 0)
        { 
            count++; 
            n = n / i; 
        } 
        if (count) a.push_back(i);
    }
    if (n > 2)  a.push_back(n);
} 


int32_t main()
{
    IOS;
    int x,y,g;
    cin>>x>>y;
    g = __gcd(x,y);
    factorize(g);
    cout<<a.size() + 1<<"\n";
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

ll a[100001];
ll h[100001];
ll r[100001];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n;
	char a[100], b[100], c[100];
	scanf("%d", &n);
	scanf("%s%s%s", a,b,c);
	int ans = 0;
	REP(i, n) {
		int cnt = 2;
		if (a[i] == b[i])cnt--;
		if (b[i] == c[i])cnt--;
		if (c[i] == a[i])cnt--;
		ans += Max(0,cnt);
	}
	PRINTD(ans);

}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a = 0;
	REP(i, 4) {
		char s;
		cin >> s;
		if (s == '+')a++;
		else a--;

	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned int;
typedef pair<int,int> P;
int const MOD=1000000007;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    string s; cin>>s; int siz=s.size(),l[siz],r[siz],ans[siz]={}; fill(l,l+siz,100000); fill(r,r+siz,100000);
    r[1]=1; l[siz-2]=1;
    for (int i = 1; i < siz-1; i++){
        if(s[i]=='R'){r[i+1]=1;}
        else {l[i-1]=1;}
    }
    for (int i = 1; i < siz; i++){
        if(r[i]!=1)r[i]=min(r[i-1]+1,r[i]);
    }
    for (int i = siz-2; i >= 0; i--){
        if(l[i]!=1)l[i]=min(l[i+1]+1,l[i]);
    }
    for (int i = 0; i < siz; i++){
        if(s[i]=='R')ans[i+l[i]-(l[i]%2)]++;
        else ans[i-r[i]+(r[i]%2)]++;
    }
    for (int i = 0; i < siz-1; i++){
        cout<<ans[i]<<' ';
    }
    cout<<ans[siz-1]<<'\n';
}

Measured memory_bytes: 1872
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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 () {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  //vi to[200005];

  int N, Q; cin >> N >> Q;
  vvi to(N,vi());
  REP(i,N-1) {
    int a, b; cin >> a >> b;
    --a; --b;
    to[a].PB(b);
    to[b].PB(a);
  }

  vi ans(N);
  //ans.resize(N);
  REP(i,Q) {
    int p, x; cin >> p >> x;
    --p;
    ans[p] += x;
  }

  vector<bool> checked(N,false);
  queue<int> que;
  que.push(0);
  checked[0] = true;

  while (!que.empty()) {
    int node = que.front();
    que.pop();
    int point = ans[node];
    for (auto &next : to[node]) {
      if (!checked[next]) {
        ans[next] += point;
        que.push(next);
        checked[next] = true;
      }
    }
  }

  REP(i,N) {
    cout << ans[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 15604
from sys import stdin, stdout

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()
out = [0 for i in xrange(m)]

pos = {}
dos = [[] for i in xrange(n + 1)]
for i in xrange(m):
    p, y = map(int, inp[i].strip().split())
    pos[(p, y)] = i
    dos[p].append(y)

for i in xrange(n + 1):
    if dos[i]: dos[i].sort()

for i in xrange(n + 1):
    for j in xrange(len(dos[i])):
        pre = str(i).zfill(6)
        suf = str(j + 1).zfill(6)
        sad = pre + suf
        out[pos[(i, dos[i][j])]] = sad

stdout.write("\n".join(out))
        
        
        
    


Measured memory_bytes: 92940
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, q;
    cin >> n >> q;

    vector< int > a(n - 1), b(n - 1);
    vector< stack< int > > c(n);

    for (int i = 0; i < n - 1; i++) {
        cin >> a[i] >> b[i];
        c[a[i] - 1].push(b[i] - 1);
        c[b[i]-1].push(a[i]-1);
    }

    vector< int > p(q), x(q);
    vector< int > ans(n, 0);

    for (int i = 0; i < q; i++) {
        cin >> p[i] >> x[i];
        ans[p[i] - 1] += x[i];
    }

    queue< int > add;
    vector<bool> visited(n,false);
    add.push(0);
    int i = 0;
    while (add.size()) {
        i = add.front();
        add.pop();
        if(!visited[i]) visited[i]=true;
        while (c[i].size()) {
            if(!visited[c[i].top()]){
              ans[c[i].top()] += ans[i];
              add.push(c[i].top());
            }
            c[i].pop();
        }
     
          continue;
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 141440
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>

using namespace std;

const int mod = 1e9 + 7;
long long n, dp[2005];

int main() {
    cin >> n;
    dp[0] = 1;
    for (int i = 3; i <= n; i++) {
        for (int j = 3; j <= i; j++) dp[i] = (dp[i] + dp[i - j]) % mod;
    }
    cout << dp[n] << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl a(n);
	FOR(i,0,n) cin >> a[i];
	sort(all(a));

	ll res = 0;
	FOR(i,0,n) FOR(j,i+1,n) FOR(k,j+1,n) {
		res += a[i] < a[j] && a[j] < a[k] && a[i]+a[j] > a[k];
	}
	cout << res << endl;

}



Measured memory_bytes: 3660
import java.util.*;
import java.io.*;

public class Main {
	static final int like = 753;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int x = sc.nextInt();
		int max  = 1;
		List<Integer> list = new ArrayList<>();
		for(int i = 2; i <= 1000; i++) {
			int num = (int)Math.pow(i, 2);
			while (num <= 1000) {
				if(!list.contains(num)) list.add(num);
				num *= i;
			}
		}
		Collections.sort(list);
		for(int n: list) {
			if (n > x)break;
			max = n;
		}
		
		out.println(max);
		
		out.close();
	}
	


static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



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

using namespace std;

int main(){
       int s;
       cin>>s;
       int a=s/100;
       int b=s%100;
       if((a<=12&&b<=12)&&(a>=1&&b>=1)){
           cout<<"AMBIGUOUS"<<endl;
       }
       else if(a>12&&b<=12&&b>=1){
        cout<<"YYMM"<<endl;
       }
       else if(b>12&&a<=12&&a>=1){
        cout<<"MMYY"<<endl;
       }
       else if(a==0&&b>=1&&b<=12){
        cout<<"YYMM"<<endl;
       }
       else if(b==0&&a>=1&&a<=12){
        cout<<"MMYY"<<endl;
       }
       else{
        cout<<"NA"<<endl;
       }
       return 0;
}


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

int main() {
    long long n, a, b, ans;
    cin >> n >> a >> b;
    ans = ((b-a) % 2 == 0) ? (b-a)/2 : (a-1 < n-b) ? a + (b-a-1)/2 : n-b+1 + (b-a-1)/2;
    cout << ans << endl;
}

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

ll inf=9223372036854775806,mod=1000000007;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,k,i,ans=1;
	cin>>n>>k;
	for (i=0;i<n;i++){
		ans=min(ans*2,ans+k);
	}
	cout<<ans;
 	return 0;
}

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

struct Problem {

	UL LW[2000][2001] = {};
	UL LB[2000][2001] = {};
	UL dp[2001][2001];

	void Solve() {
		UL N; cin >> N;
		vector<UL> Black(N), White(N);
		rep(i, N * 2) {
			char c; cin >> c;
			UL a; cin >> a;
			((c == 'B') ? Black : White)[a - 1] = i;
		}
		rep(i, N) {
			for (UL j = 0; j < i; j++) {
				if (White[j] < White[i]) LW[i][0]++;
				if (Black[j] < Black[i]) LB[i][0]++;
			}
			for (UL j = 1; j <= N; j++) {
				if (Black[j - 1] < White[i]) LW[i][j]++;
				if (White[j - 1] < Black[i]) LB[i][j]++;
				LW[i][j] += LW[i][j - 1];
				LB[i][j] += LB[i][j - 1];
			}
		}
		rep(i, N) {
			rep(j, N + 1) {
				LW[i][j] = White[i] - LW[i][j];
				LB[i][j] = Black[i] - LB[i][j];
			}
		}
		rep(i, N + 1) rep(j, N + 1) dp[i][j] = 1000000000;
		dp[0][0] = 0;
		rep(i, N + 1) {
			rep(j, N + 1) {
				auto &p = dp[i][j];
				if (i != 0) p = min(p, dp[i - 1][j] + LW[i - 1][j]);
				if (j != 0) p = min(p, dp[i][j - 1] + LB[j - 1][i]);
				dp[i][j] = p;
				//cout << dp[i][j] << " ";
			} //cout << endl;
		}
		cout << dp[N][N] << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

class RollingHash_Mersenne {
	// RH (mod : 1UL << 61 - 1, base : random)
	// https://atcoder.jp/contests/abc141/submissions/16495886
	const unsigned long long MASK30 = (1ULL << 30) - 1;
	const unsigned long long MASK31 = (1ULL << 31) - 1;
	const unsigned long long MASK61 = (1ULL << 61) - 1;
	const unsigned long long MOD = MASK61;
	const unsigned long long base = rand() % (unsigned long long)1e5 + 3;
	const unsigned long long POSITIVIZER = MOD << 2;
	vector<unsigned long long> hash, power;

	// a * b と mod が等しい数を返す
	// 結果は (1UL << 63) + 3 - (1UL << 31) * 3 以下
	unsigned long long Mul(unsigned long long a, unsigned long long b) const {
		unsigned long long au = a >> 31;
		unsigned long long ad = a & MASK31;
		unsigned long long bu = b >> 31;
		unsigned long long bd = b & MASK31;
		unsigned long long mid = ad * bu + au * bd;
		unsigned long long midu = mid >> 30;
		unsigned long long midd = mid & MASK30;
		return au * bu * 2 + midu + (midd << 31) + ad * bd;
	}

	// mod 2^61-1を計算する
	unsigned long long CalcMod(unsigned long long x) const {
		unsigned long long xu = x >> 61;
		unsigned long long xd = x & MASK61;
		unsigned long long res = xu + xd;
		if(res >= MOD) res -= MOD;
		return res;
	}

   public:
	RollingHash_Mersenne(const string &s) {
		int sz = (int)s.size();
		hash.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = CalcMod(Mul(power[i], base));
			hash[i + 1] = CalcMod(Mul(hash[i], base) + s[i]);
		}
	}

	template <class T>
	RollingHash_Mersenne(const vector<T> &v) {
		int sz = (int)v.size();
		hash.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for(int i = 0; i < sz; i++) {
			power[i + 1] = CalcMod(Mul(power[i], base));
			hash[i + 1] = CalcMod(Mul(hash[i], base) + v[i]);
		}
	}

	unsigned long long get(int l, int r) const { return CalcMod(hash[r] + POSITIVIZER - Mul(hash[l], power[r - l])); }

	unsigned long long connect(unsigned long long h1, unsigned long long h2, unsigned long long h2len) const { return CalcMod(Mul(h1, power[h2len]) + h2); }

	// Longest Common Prefix
	int LCP(int l_this, int r_this, RollingHash_Mersenne &other, int l_other, int r_other) {
		int len = min(r_this - l_this, r_other - l_other);
		int low = 0, high = len + 1;
		while(high - low > 1) {
			int mid = (low + high) / 2;
			if(get(l_this, l_this + mid) == other.get(l_other, l_other + mid))
				low = mid;
			else
				high = mid;
		}
		return low;
	}
};


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

	RollingHash_Mersenne rh(s);
	int res = 0;
	for(int i=0 ;i<n;i++) {
		for(int j=0;j< n;j++) {
			if(j <= i + res) continue;
			int a = rh.LCP(i, n, rh, j, n);
			//	cout << a << endl;
			res = max(res, min(a, j - i));
		}
	}
	cout << res << endl;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(v) for (auto el : v) { cerr << el << ' '; } cerr << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22)
		cout << "bust" << endl;
	else
		cout << "win" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
ll A[100010],B[100010],L[100010],R[100010],u,up[200010];
#define mid ((l+r)>>1)
ll mn[800010];bool tag[800010];
void upd(int x){mn[x]=1e18;tag[x]=1;}
void down(int x){if(tag[x])upd(x<<1),upd(x<<1|1),tag[x]=0;}
void build(int x,int l,int r){
	mn[x]=-up[r];if(l==r)return;
	build(x<<1,l,mid),build(x<<1|1,mid+1,r);
}
void update(int x,int l,int r,int p,ll d){
	if(l==r){mn[x]=d;return;}
	down(x);
	if(p<=mid)update(x<<1,l,mid,p,d);
	else update(x<<1|1,mid+1,r,p,d);
	mn[x]=std::min(mn[x<<1],mn[x<<1|1]);
}
void update0(int x,int l,int r,int L,int R){
	if(L<=l&&r<=R)return upd(x);
	down(x);
	if(L<=mid)update0(x<<1,l,mid,L,R);
	if(mid<R)update0(x<<1|1,mid+1,r,L,R);
	mn[x]=std::min(mn[x<<1],mn[x<<1|1]);
}
ll query(int x,int l,int r,int L,int R){
	if(L<=l&&r<=R)return mn[x];
	down(x);
	if(L<=mid)
		if(mid<R)return std::min(query(x<<1,l,mid,L,R),query(x<<1|1,mid+1,r,L,R));
		else return query(x<<1,l,mid,L,R);
	else return query(x<<1|1,mid+1,r,L,R);
}
#undef mid
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),K=gi();
	for(int i=1;i<=n;++i){
		A[i]=gi(),B[i]=gi();
		if(B[i]==1&&A[i]*2>K)return puts("-1"),0;
	}
	for(int i=1;i<=n;++i)A[i]+=A[i-1];
	ll ans=1e18;
	for(int i=1;i<=n;++i)
		if(B[i]==1){
			L[i]=(-2*A[i-1]%K+K)%K,R[i]=(-2*A[i]%K+K)%K;
			up[++u]=L[i],up[++u]=R[i];
		}
	std::sort(up+1,up+u+1);u=std::unique(up+1,up+u+1)-up-1;
	for(int i=1;i<=n;++i)if(B[i]==1)L[i]=std::lower_bound(up+1,up+u+1,L[i])-up;
	for(int i=1;i<=n;++i)if(B[i]==1)R[i]=std::lower_bound(up+1,up+u+1,R[i])-up;
	if(u)build(1,1,u);
	for(int i=1;i<=n;++i)
		if(B[i]==1){
			int l=L[i],r=R[i];
			if(l<=r){
				ll _=1e18;
				_=std::min(_,query(1,1,u,1,l));
				if(r<u)_=std::min(_,K+query(1,1,u,r+1,u));
				update(1,1,u,l,_);
				if(l>1)update0(1,1,u,1,l-1);
				if(r<u)update0(1,1,u,r+1,u);
			}else{
				ll _=1e18;
				_=query(1,1,u,r+1,l);
				update(1,1,u,l,_);
				if(r+1<=l-1)update0(1,1,u,r+1,l-1);
			}
		}
	for(int i=1;i<=u;++i)ans=std::min(ans,query(1,1,u,i,i)+up[i]);
	if(!u)ans=0;
	printf("%lld\n",ans+A[n]*2);
	return 0;
}


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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())
#define inf          1<<25

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; }

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

ll num[100001];

int main() {
    ll N, K;
    cin >> N >> K;
    
    ll a, b;
    rep(i, N) {
        cin >> a >> b;
        num[a] += b;
    }
    
    ll c = 0;
    rep(i, 100001) {
        c += num[i];
        if (c >= K) {
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1152
package main

import (
    "fmt"
)

func main() {
  var a, b int
  // for i := 0; i < 2; i++ {
    fmt.Scan(&a, &b)
    c := a * b
    d := (a * 2) + (b*2)

    fmt.Printf("%d %d\n", c, d)
  // }
}


Measured memory_bytes: 1088
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
    auto res = 0;
    auto maxRes = 0;
    for ( auto && value : s )
    {
        if (value == 'R')
            res++;
        else
            res = 0;

        if (maxRes < res)
            maxRes = res;
    }
    cout << maxRes;
}


Measured memory_bytes: 3156
# -*- coding: utf-8 -*-
H, W = map(int, raw_input().split())
c = [[0 for i in range(10)] for j in range(10)]
A = [[0 for i in range(W)] for j in range(H)]
for i in range(10):
    n = map(int, raw_input().split())
    for j in range(10):
        c[i][j] = n[j]
for i in range(H):
    n = map(int, raw_input().split())
    for j in range(W):
        A[i][j] = n[j]
        
def getDistance(start):
    if start == 1:
        return 0
    d = [1001 for i in range(10)]
    d[start] = 0
    prev = [-1 for i in range(10)]
    Q = set()
    for i in range(10):
        Q.add(i)
    while len(Q) != 0:
        min = 1001
        for i in range(10):
            if d[i] < min and i in Q:
                min = d[i]
                u = i
        Q.remove(u)
        for v in range(10):
            if d[v] > d[u] + c[u][v]:
                d[v] = d[u] + c[u][v]
                prev[v] = u
    return(d[1])



if __name__ == '__main__':
    D = [0 for i in range(10)]
    for i in range(10):
        D[i] = getDistance(i)
    ans = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] != -1:
                ans += D[A[i][j]]
    print(ans)


Measured memory_bytes: 3076
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
// #define base 100001
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case %lld:\n", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const int N = 300010;
int n, mem[2010], cnt;
int dp(int sum) {
	cnt++;
	if (sum >= n) {
		if (sum == n) return 1;
		return 0;
	}
	int &ret = mem[sum];
	if (~ret) return ret;
	ret = 0;
	for (int i = 3; i <= n; i++)
	{
		if (sum + i <= n)
			ret = (ret + dp(sum + i)) % MOD;
		else break;
	}
	return ret;
}
int solve() {
	cin >> n;
	memn(mem);
	printf("%d\n", dp(0));
	return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return solve();
}

Measured memory_bytes: 3764
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    s = S()
    if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        return
    l = [chr(ord("a") + i) for i in range(26)]
    for si in s:
        l.remove(si)
    if l == []:
        s = s[::-1]
        l.append(s[0])
        ans = []
        f = True
        for si in s[1:]:
            if f:
                if l[-1] > si:
                    f = False
                    x = si
                else:
                    l.append(si)
            else:
                ans.append(si)
        l.sort()
        for ai in l:
            if ai > x:
                print("".join(ans[::-1]) + ai)
                return
    else:
        print("".join(s) + l[0])
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39024
//abc122_a.cpp
//Sat Mar 30 20:48:26 2019

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

int main(){
	char s;
	cin >> s;

	if (s=='A'){
		cout << 'T' << endl;
	}else if (s=='T'){
		cout << 'A' << endl;
	}else if (s=='G'){
		cout << 'C' << endl;
	}else if (s=='C'){
		cout << 'G' << endl;
	}

}

Measured memory_bytes: 256
import java.util.Scanner;

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

		String c="";
		if(a>b)c=">";
		if(a<b)c="<";
		if(a==b)c="==";
		System.out.println("a "+c+" b");
	}
}

Measured memory_bytes: 17172
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <iomanip>
#include <functional>
using namespace std;
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(int argc, char* argv[])
{
    int n , r;
    while(cin >> n >> r,n!=0 && r!=0){
        int p,c;
        int i=0,j=0;
        int temp[50];
        int huda[50];
        for(i=0;i<n;i++){
            huda[i] = i+1;
        }
        while(r){
            cin >> p >>c;
            for(i = 0;i < c;i++){
                
                temp[i] = huda[((n-1)-(p-2))-(c-i)];
//                cout << temp[i] << endl;
            }
            
            for (j=p-1; j>0;j-- ) {
                huda[(n-j)-c] = huda[n-j];
            }
//            for(i=0;i<10;i++)cout <<huda[i] <<" ";
//            cout<<endl;
            for(i=0;i<c;i++){
                huda[n-(c-i)] = temp[i];
            }
//            for(i=0;i<10;i++)cout <<huda[i] <<" ";
            r--;
        }
            cout << huda[n-1] << endl;
    }
    return 0;
}

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

double solve(int r)
{
  return 2 * r * 3.14159265358979323846;
}

int main()
{
  int r;
  std::cin >> r;


  std::cout << std::setprecision(20);
  std::cout << solve(r) << std::endl;
}


Measured memory_bytes: 3788