akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
#define ll long long
int N=INT_MAX;
ll INF=1e18L+5;
map<int ,int>my;
//vector<PII>v[1000005];
const int M = 1e5+5;

vector<int>edges[M];
bool visited[M];
int in_degree[M];
int dist[M];

void dfs(int a){
    if(visited[a]==false){
        visited[a]=true;
        for(int b : edges[a]){
            dist[b]=max(dist[b],dist[a]+1);
            in_degree[b]--;
            if(in_degree[b]==0){
                dfs(b);
            }
        }
    }
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d%d",&a, &b);
        edges[a].PB(b);
        in_degree[b]++;
    }
    for(int i=1;i <= n;i++){
        if(!visited[i] && in_degree[i]==0){
            dfs(i);
        }
    }
    int ans=0;
    for(int i=1;i <= n;i++){
        ans=max(ans,dist[i]);
    }
    cout<<ans;
}


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

int main() {
  int A, B, C, a, b, c, cnt=0;
  cin >> A >> B >> C;
  if(A==B && A==C && A%2==0) cnt=-1;
  else{
    while(1){
      if(A%2!=0 || B%2!=0 || C%2!=0) break;
      a=A; b=B; c=C;
      A=b/2+c/2;
      B=a/2+c/2;
      C=a/2+b/2;
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

int main() {
    int n;
    cin >> n;
    string s[n];
    
    for(int i = 0; i < n; i++) cin >> s[i];

    for(int i = 0; i < n; i++) {
        sort(s[i].begin(), s[i].end());
    }
    sort(s, s + n);
    
    /*
    for(int i = 0; i < n; i++) {
        cout << s[i] << endl;
    }
    */
    
    long long ans = 0;
    long long cnt = 1;
    for(int i = 0; i < n - 1; i++) {
        if(s[i] == s[i + 1]) {
            cnt++;
        } else {
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }

    ans += cnt * (cnt - 1) / 2;

    cout << setprecision(20) << ans << endl;

    return 0;
}

Measured memory_bytes: 7296
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, list(input())[: -1]))
res = 0
rres = 0
for i in range(N):
  t = (((N - 1) & i) & i) == i
  res ^= t * a[i] % 2
  rres ^= t * (a[i] // 2) % 2
if (2 in a) and res == 0: print(0)
elif res == 1: print(1)
else:
  if rres: print(2)
  else: print(0)


Measured memory_bytes: 156888
#include <cstdio>
#include <cstdlib>

using namespace std;

typedef long long ll;

const int maxn = 210000;
const int modi = 1000000007;

int a[maxn], b[maxn];
int f[4100][4100];
int g[4100][4100];
ll fact[9100], inv[9100];

ll quickpow(ll base, ll times)
{
	ll ans = 1;
	while (times)
	{
		if (times & 1) ans = (ans * base) % modi;
		base = (base * base) % modi;
		times >>= 1;
	}
	return ans;
}

ll C(int n, int m)
{
	return fact[n] * inv[m] % modi * inv[n - m] % modi;
}

int main(int argc, char * argv[])
{
	int n;
	scanf("%d", &n);
	fact[0] = inv[0] = 1;
	for (int i = 1; i <= 8100; ++i)
	{
		fact[i] = fact[i - 1] * i % modi;
		inv[i] = quickpow(fact[i], modi - 2);
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d%d", &a[i], &b[i]);
		g[-a[i] + 2001][-b[i] + 2001]++;
		g[a[i] + 2001][b[i] + 2001]++;
		ans = (ans - C(2 * a[i] + 2 * b[i], 2 * a[i])) % modi;
	}
	f[0][0] = 1;
	for (int i = 1; i <= 4001; ++i)
	{
		for (int j = 1; j <= 4001; ++j)
		{
			f[i][j] = (f[i - 1][j] + f[i][j - 1]) % modi;
			if (i <= 2001 && j <= 2001)
				f[i][j] = (f[i][j] + g[i][j]) % modi;
			if (i > 2001 && j > 2001 && g[i][j] != 0)
			{
				ans = (ans + (ll)g[i][j] * f[i][j]) % modi;
			}
		}
	}
	printf("%lld\n", (ans * quickpow(2,modi-2) % modi + modi) % modi);
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A >= 13)
    cout << B << endl;
  else if (A >= 6)
    cout << B / 2 << endl;
  else
    cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

struct edge {
  int64_t cost;
  int src;
  int to;
  edge(int64_t a, int b, int c) : cost(a), src(b), to(c){};
};

vector<int64_t> bellman_ford(const vector<edge> &edges, int V, int s) {
  const auto INF = INT64_MAX;
  vector<int64_t> dist(V, INF);
  dist[s] = 0;
  bool negative = false;
  rep(i, V) {
    for (auto &e : edges) {
      if (dist[e.src] == INF) continue;
      if (dist[e.src] + e.cost < dist[e.to]) {
        dist[e.to] = dist[e.src] + e.cost;
        if (i == V - 1 && e.to == V - 1) negative = true;
      }
    }
  }
  /*
  for (auto &e : edges) {
    if (dist[e.src] == INF) continue;
    if (dist[e.src] + e.cost < dist[e.to]) return vector<int64_t>();
  }
  */
  if (negative)
    return vector<int64_t>();
  else
    return dist;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<edge> es;
  rep(i, M) {
    int64_t c;
    int a, b;
    cin >> a >> b >> c;
    a--, b--;
    es.emplace_back(-c, a, b);
  }

  auto dists = bellman_ford(es, N, 0);
  if (dists.empty()) {
    cout << "inf" << endl;
    return 0;
  }
  int64_t answer = -dists[N - 1];
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n;  cin >> n;
    string s;   cin >> s;
    if(n < 3){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    vector<int>dic(3);
    rep(i, n){
        if(s[i] == 'R') dic[0]++;
        if(s[i] == 'G') dic[1]++;
        if(s[i] == 'B') dic[2]++;
    }
    rep(i, 3)   ans *= dic[i];
    rep(i, n-2) for(int j = 0; i+2*(j+1) < n; j++){
        int I = i, J = i+j+1, K = i+2*(j+1);
        if(s[I] != s[J] && s[I] != s[K] && s[J] != s[K])    ans--;
    }
    cout << ans << endl;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  string s;
  cin >> s;
  if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) {
    cout << "Yes" << '\n';
  }
  else cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() 
{
	int n, x, y, a, b, c, d;
	cin >> n >> x >> y;
	a = b = (x + y);
	c = d = (x - y);
	for(int i = 0; i < n; i++)
	{
		cin >> x >> y;
		a = min(x + y, a);
		b = max(x + y, b);
		c = min(x - y, c);
		d = max(x - y, d);
	}
	cout << max(abs(a-b), abs(c-d));
}

Measured memory_bytes: 3624
N = int(input())
sdict = {}
mf = 0
for _ in range(N):
    s = input()
    if not s in sdict:
        sdict[s] = 1
        if mf == 0:
            mf = 1
    else:
        sdict[s] += 1
        if mf < sdict[s]:
            mf = sdict[s]

out = []
for k, f in sdict.items():
    if f == mf:
        out.append(k)
out.sort()
for o in out:
    print(o)






Measured memory_bytes: 32096
n,k = map(int,input().split())
a = [0]+list(map(int,input().split()))

def bin(arr,val):
    left,right = 0,len(arr)-1
    while left<=right:
        mid = (left+right)//2
        if arr[mid]==val: return 1
        elif arr[mid]<val: left = mid + 1
        else: right = mid - 1
    return 0

know = []
now = 1
while not bin(know, now):
    know.append(now)
    now = a[now]

start = a[know[-1]]
for i,num in enumerate(know):
    if num == start: loop = know[i:] ; break

ans = know[k] if k<len(know) else loop[(k-len(know))%len(loop)]
print(ans)



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, A, B;
  cin >> N >> A >> B;
  int p, a = 0, b = 0, c = 0;
  for (int i = 0; i < N; i++) {
    cin >> p;
    if (p <= A)
      a++;
    else if (p <= B)
      b++;
    else
      c++;
  }
  cout << min({a, b, c}) << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		Arrays.sort(a);

		if (n == 1) {
			System.out.println(0);
		} else {
			System.out.println(a[n - 1] - a[0]);
		}
	}

}


Measured memory_bytes: 20820
#include<stdio.h>
int main(){
  
  int n;
  int a;
  int i;
  int min = 1000001;
  int max = -1000001;
  long long int sum = 0;
  
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    
    scanf("%d",&a);
    
    sum += a;
    
    if(max < a){
      max  = a;
    }
    
    if(a < min){
      min = a;
    }
    
  }
  printf("%d %d %ld\n",min,max,sum);
  return(0);
}



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

class Dijkstra{ //O((N+M)logN)
    private:
        vector<vector<pair<int,long long>>> graph; //pair<next_path,cost>
        vector<long long> total_cost;
    
    public:
        Dijkstra(vector<vector<pair<int,long long>>> graph,int start,int size,bool path_check = false){
            priority_queue<
                pair<int,long long>,
                vector<pair<int,long long>>,
                greater<pair<int,long long>>> q;
            vector<long long> cost(size,1e18+7);
            cost[start] = 0;
            q.push(make_pair(start,0ll));
            while (!q.empty()){
                auto now = q.top();
                q.pop();
                int prev = now.first;
                if( cost[prev] < now.second) continue;
                for (auto next : graph[prev]){
                    if (cost[next.first] <= cost[now.first] + next.second) continue;
                    cost[next.first] = cost[now.first] + next.second;
                    q.push(next);
                }
            }
            total_cost = cost;
        }
        long long get_cost(int goal){ return total_cost[goal]; }
};
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n,m; cin >> n >> m;
    vector<vector<pair<int,ll>>> graph(n+1); //graph[i].first  i:現在地,first:次の場所,second:コスト
    rep(i,0,m){
        int b1,b2; cin >> b1 >> b2;
        graph[b2].push_back(make_pair(b1,1));
        graph[b1].push_back(make_pair(b2,1));
    }
    Dijkstra G(graph,1,n+1);
    if( G.get_cost(n) == 2) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 35828
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M; 
cin >> N >> M; 
long long int X[114514] = {}; 
long long int Y[114514] = {}; 
long long int P[114514] = {}; 
long long int Q[114514] = {};
long long int H[114514] = {}; 
long long int W[114514] = {}; 
long long int H1, W1; 
long long int p = 1000000007; 
for (int i = 0; i < N; ++i){
cin >> X[i];
}
for (int j = 0; j < M; ++j){
cin >> Y[j];
}
for (int i = 1; i < N; ++i){
P[i] = X[i] - X[i-1];
H[i] = ((((N-i) * P[i]) % p) * i) % p; 
}
for (int j = 1; j < M; ++j){
Q[j] = Y[j] - Y[j-1];
W[j] = ((((M-j) * Q[j]) % p) * j) % p; 
}
for (int i = 1; i < N; ++i){
H1 = (H1 + H[i]) % p; 
}
for (int j = 1; j < M; ++j){
W1 = (W1 + W[j]) % p; 
}
cout << (H1 * W1) % p << endl; 
}

Measured memory_bytes: 4348
#include<bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

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


    cout << a*a*a+a*a+a << endl;
    return 0;
}

Measured memory_bytes: 3592
long N,M,a,i,m=1e9+7;long f(int A){return A?A*f(A-1)%m:1;}main(){scanf("%d%d",&N,&M);printf("%d",(M^N?M>N+1||M<N-1?0:1:2)*f(N)*f(M)%m);}

Measured memory_bytes: 1664
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <chrono>
#include <queue>
#include <string>
#include <cassert>
#include <bitset>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 998244353
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <ll> vll;

int arr[100000][3];
int n;
int dp[100000][3];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) scanf("%d", &arr[i][j]);
	}
	for (int i = 0; i < 3; i++) dp[0][i] = arr[0][i];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) 
				if (k != j) dp[i][j] = max(dp[i][j], dp[i - 1][k] + arr[i][j]);
		}
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
	return 0;
}

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

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

	int64_t s = 0;

	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			for (int c = 1; c <= k; c++) {

				int d = a;
				int e = b;
				int f = c;
				int p;
				while (d%e != 0) {
					p = d;
					d = e;
					e = p % e;
				}

				while (f%e != 0) {
					p = f;
					f = e;
					e = p % e;
				}
				
				s += e;

			}
		}
	}

	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3580
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 55;
const int mod = 1000000007;

int n,m,q;
int a[maxn],b[maxn],c[maxn],d[maxn];

int path[maxn];
int ret=0;
void dfs(int pos, int pre){
  if(pos>n){
    int tt = 0;
    for(int i=0;i<q;i++){
      if(path[b[i]]-path[a[i]]==c[i])tt+=d[i];
    }
    ret=max(ret, tt);
    return;
  }
  for(int i=pre;i<=m;i++){
    path[pos] = i;
    dfs(pos+1, i);
  }
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n>>m>>q;
  for(int i=0;i<q;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
  dfs(1, 1);
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 3624
(format t "~:[Yes~;No~]~%"
	(let ((a (loop repeat 9 collect (read)))
	      (b (loop repeat (read) collect (read))))
	  (map-into a
		    (lambda (x) (find x b :test #'=))
		    a)
	  (loop for (i j k) in '((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 4 7) (2 5 8) (0 4 8) (2 4 6))
	     never (and (elt a i) (elt a j) (elt a k)))))

Measured memory_bytes: 16228
#include<cstdio>
using namespace std;int a,b;
int main(){
    scanf("%d%d",&a,&b);
    if(a>0)puts("Positive");else if(b>=0)puts("Zero");       
    else if((a&1)^(b&1))puts("Positive");else puts("Negative");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main()
{
	char S[101], T[101];
	scanf("%s", S);
	scanf("%s", T);
	
	int i, j, l, flag = 0;
	for (l = 1; S[l] != 0; l++);
	for (i = 0; i < l; i++) {
		for (j = 0; j < l; j++) {
			if (S[(i+j)%l] != T[j]) break;
		}
		if (j == l) flag = 1;
	}
	
	if (flag == 1) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N;
    while (~scanf("%d", &N)) {
          int cnt4 = 0, cnt2 = 0, cnt0 = 0;
          for (int i = 0; i < N; i++) {
              int tmp;
              scanf("%d", &tmp);
              if (tmp % 4 == 0) cnt4++;
              else if (tmp % 2 == 0) cnt2++;
              else cnt0++;
          }
          if (cnt0 <= cnt4 || (cnt0 == cnt4 + 1 && !cnt2)) puts("Yes");
          else puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int x; cin>>x;
	for (int i=x; i<=999; i++) {
		string cur=to_string(i);
		set<char> st(cur.begin(),cur.end());
		if (st.size()==1) {
			cout<<i<<endl;
		break;
		}
	}
	return 0;
}


Measured memory_bytes: 3708
a, b = map(int, input().split())
aList = []
bList = []

for i in range(0, b):
    aList.append(str(a))

for i in range(0, a):
    bList.append(str(b))


if "".join(aList) < "".join(bList):
    print("".join(aList))
else:
    print("".join(bList))

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

int twoave(int a,int b)
{
	return (a+b)/2;
}
int theave(int a,int b,int c)
{
	return (a+b+c)/3;
}

int main()
{
	int n,pm,pe,pj;
	while(cin >> n){
		if(n==0)
			break;
		for(int i=0;i<n;i++){
			cin >> pm >> pe >> pj;
			if(pm==100 || pe==100 || pj==100)
				cout << 'A' << endl;
			else if(twoave(pm,pe)>=90)
				cout << 'A' << endl;
			else if(theave(pm,pe,pj)>=80)
				cout << 'A' << endl;
			else if(theave(pm,pe,pj)>=70)
				cout << 'B' << endl;
			else if(theave(pm,pe,pj)>=50 && (pm>=80 || pe>=80))
				cout << 'B' << endl;
			else
				cout << 'C' << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=3e5+5;
typedef long long ll;
const ll mod=1e9+7;
ll a[maxn],n,suf[maxn][63][3],ans;
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for (int i=n;i>=1;i--){
		for (int j=0;j<=61;j++){
			suf[i][j][0]=suf[i+1][j][0];
			suf[i][j][1]=suf[i+1][j][1];
			int tp=(a[i]>>j)&1;
			suf[i][j][tp]++;
		}
	}
	for (int i=1;i<=n-1;i++){
		for (int j=0;j<=61;j++){
			int tp=(a[i]>>j)&1;
			tp=tp ^ 1;
			ll po=(1ll<<j)%mod;
			ans=(ans+suf[i+1][j][tp]*po%mod)%mod;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 445568
#include <iostream>
#include <string>
using namespace std;
int m,n,k,imos[3][1001][1001];
string s[1000];
int main(){
	cin >> m >> n >> k;
	for(int i=1;i<=m;i++){
		cin >> s[i];
		for(int j=0;j<n;j++){
			int hoge;
			if(s[i][j]=='J') hoge=0;
			if(s[i][j]=='O') hoge=1;
			if(s[i][j]=='I') hoge=2;
			imos[0][i][j+1]=imos[0][i][j];
			imos[1][i][j+1]=imos[1][i][j];
			imos[2][i][j+1]=imos[2][i][j];
			imos[hoge][i][j+1]++;
		}
	}
	for(int i=0;i<3;i++){
		for(int j=1;j<=m;j++){
			for(int h=1;h<=n;h++){
				imos[i][j][h]+=imos[i][j-1][h];
			}
		}
	}
	for(int i=0;i<k;i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		cout << imos[0][c][d]-imos[0][a-1][d]-imos[0][c][b-1]+imos[0][a-1][b-1] << " ";
		cout << imos[1][c][d]-imos[1][a-1][d]-imos[1][c][b-1]+imos[1][a-1][b-1] << " ";
		cout << imos[2][c][d]-imos[2][a-1][d]-imos[2][c][b-1]+imos[2][a-1][b-1];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 13952
def solve(d,p,t):
  if d - p * t <= 0:
    return "YES"
  else:
    return "NO"

A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

d = abs(B-A)
p = V - W
print(solve(d,p,T))

Measured memory_bytes: 9084
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x+l-1, x-l+1))
    X.sort()
    ans = 1
    now = X[0][0]
    for i in range(1,N):
        b, a = X[i]
        if now +1< a:
            now = b
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 16980
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define N 200005
ll mod=1000000007;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(x) x.begin(),x.end()
#define lb lower_bound
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
 
int main(){
    
    fast;
    
    ll n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(n%i==0 && n/i >= 1 && n/i <= 9){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

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

const ll MOD = 1000000007;
const ll INF = LLONG_MAX;
const ll MAX_N = 100000;
const double EPS = 10e-8;

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

ll n, a[200002]{}, ans = INF;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] += a[i - 1];
	}
	for (int i = 1; i < n; i++) {
		ans = min(ans, abs(a[n] - a[i] * 2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
# region
import sys

DEBUG = True if (len(sys.argv) > 1 and sys.argv[1] == "DEBUG") else False


def dp(value):
    if DEBUG:
        print(value)
    return


def input_text(split=" "):
    # 入力
    result = []
    while True:
        try:
            row = list(
                map(lambda x: int(x) if x.isdecimal() else x, input().split(split))
            )
            result.append(row)
        except EOFError:
            break
    return result


# endregion
it = input_text()

s = it[0][0]
print("ABC" if s == "ARC" else "ARC")


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  ll H, W;
  int ans = 0;
  cin >> N >> H >> W;

  rep(i, N){
    int a, b;
    cin >> a >> b;
    if(a >= H && b >= W){
      ans++;
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  string s;cin>>s;
  if(s[0]>='A'&&s[0]<='Z'){
    cout<<"A";
  }else{
    cout<<"a";
  }
  
  return 0;
}
//2020.06.23 17:05:21


Measured memory_bytes: 3588
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func display(A []int, N int) {
	array := make([]string, N)
	for i := 0; i < N; i++ {
		array[i] = strconv.Itoa(A[i])
	}
	fmt.Println(strings.Join(array, " "))
}

// InsertionSort Sort int slice by insertion sort algorythm
// average of quontity of calculation is O(N^2)
func InsertionSort(A []int, N int) {
	display(A, N)
	for i := 1; i < N; i++ {
		v := A[i]
		j := i - 1
		for j >= 0 && A[j] > v {
			A[j+1] = A[j]
			j--
		}
		A[j+1] = v
		display(A, N)
	}
}

func main() {
	line := nextLine()
	length, _ := strconv.Atoi(line)

	line = nextLine()
	array := make([]int, length)
	splitedLine := strings.Split(line, " ")

	for i := 0; i < length; i++ {
		num, _ := strconv.Atoi(splitedLine[i])
		array[i] = num
	}

	InsertionSort(array, len(array))
}



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

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll a, b, c, d;
int main() {
	cin >> a >> b >> c >> d;
	if (a % 2 == 0 or b % 2 == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << ((c + d) % 2 == 0 ? "Yes" : "No") << endl;
}





Measured memory_bytes: 3112
import java.io.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{

		int N = nextInt();
		int K = nextInt();
		Long[] x = new Long[N];
		for(int i=0;i<N;i++) {
			x[i]=Long.valueOf(nextLong());
		}

		int idx =~Arrays.binarySearch(x, 0,(s1,s2)->s1.longValue()-s2.longValue()>=0?1:-1);

		int leftIdx =Math.max(0,idx-K-1);
		int rightIdx = leftIdx+K-1;

		long left=0;
		long right=0;
		long ans = Long.MAX_VALUE;
		for(;rightIdx<N;rightIdx++,leftIdx++) {
			if(x[leftIdx]<0) {
				left=Math.abs(x[leftIdx]);
			}else {
				left=0;
			}
			if(x[rightIdx]>0) {
				right=Math.abs(x[rightIdx]);
			}else {
				right=0;
			}

			if(left!=0&&right!=0) {
				if(left<right) {
					left*=2;
				}else {
					right*=2;
				}
			}
			ans=Math.min(ans, left+right);
		}



		pw.println(ans);

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 47248
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

struct UnionFind {
    parent: Option<usize>,
    dist: u32,
}

impl Clone for UnionFind {
    fn clone(&self) -> Self {
        UnionFind {
            parent: self.parent.clone(),
            dist: self.dist,
        }
    }
}

fn union(l: usize, r: usize, d: u32, uf: &mut Vec<UnionFind>) -> bool {
    let (lr, ld) = root(l, uf);
    let (rr, rd) = root(r, uf);

    if lr == rr {
        if ld + d == rd {
            return true;
        } else {
            return false;
        }
    }
    if ld + d >= rd {
        uf[rr].parent = Some(lr);
        uf[rr].dist = ld + d - rd;
    } else {
        uf[lr].parent = Some(rr);
        uf[lr].dist = rd - ld - d;
    }
    true
}

fn root(a: usize, uf: &mut Vec<UnionFind>) -> (usize, u32) {
    if let Some(b) = uf[a].parent {
        let (r, d) = root(b, uf);
        uf[a].dist += d;
        uf[a].parent = Some(r);
        (r, uf[a].dist)
    } else {
        (a, 0)
    }
}

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];

    let mut uf: Vec<UnionFind> = vec![
        UnionFind {
            parent: None,
            dist: 0,
        };
        n
    ];

    for _ in 0..m {
        let lrd: Vec<usize> = read_vec();
        let l = lrd[0] - 1;
        let r = lrd[1] - 1;
        let d = lrd[2] as u32;
        if !union(l, r, d, &mut uf) {
            println!("No");
            return;
        }
    }

    println!("Yes");
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, i, ok = true;
	string s;
	cin >> s;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == 'U' || s[i] == 'D')
			continue;
		if (i & 1) {
			if (s[i] == 'R') {
				ok = false;
				break;
			}
		}
		else {
			if (s[i] == 'L') {
				ok = false;
				break;
			}
		}
	}
	if (ok)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
s = list(input())
k = int(input())
s += '+'

releki = []
cnt = 1
pre = s[0]
for i in range(1,len(s)):
    if pre==s[i]:
        cnt += 1
    else:
        releki.append([pre,cnt])
        pre = s[i]
        cnt = 1
        
ans = 0
for i in range(len(releki)):
    ans += releki[i][1]//2
if len(releki)==1:
    print((len(s)-1)*k//2)
    exit()
if s[0]!=s[-3]:
    print(ans*k)
else:
    a = releki[0][1]
    b = releki[-1][1]
    ans = ans*k - (k-1)*(a//2 +b//2 -(a+b)//2)
    print(ans) 



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

using namespace std;

typedef long long LL;
const int N = 55, M = 288, Mod = 1e9 + 7;

inline int Pow(int x, int y, int res = 1) {
	for (; y; y >>= 1, x = (LL)x * x % Mod)
		if (y & 1) res = (LL)res * x % Mod;
	return res % Mod;
}
inline int Inv(int x) { return Pow(x, Mod - 2); }

int gcd(int x, int y) {
	if (!y) return x;
	return gcd(y, x % y);
}

int dex, Top, cnt, dfn[N], low[N], cntv[N], cnte[N];
int n, m, K, tot, pw[N], bel[N], Head[N], Next[M], Adj[M], f[M][M];
pair<int, int> S[M + 1 /* not N!!! */];

vector<int> vt[N];

void Tarjan(int x, int fat) {
	dfn[x] = low[x] = ++dex;
	for (int e = Head[x]; e; e = Next[e])
		if (Adj[e] != fat) {
			if (dfn[Adj[e]] == -1) {
				S[++Top] = make_pair(x, Adj[e]);
				Tarjan(Adj[e], x);
				low[x] = min(low[x], low[Adj[e]]); /* ! */
				if (low[Adj[e]] >= dfn[x]) {
					++cnt;
					while (1) {
						int nx = S[Top].first, ny = S[Top].second;
						--Top, ++cnte[cnt];
						if (bel[nx] != cnt) bel[nx] = cnt, ++cntv[cnt];
						if (bel[ny] != cnt) bel[ny] = cnt, ++cntv[cnt];
						if (nx == x && ny == Adj[e]) break;
					}
				}
			} else if (dfn[x] > dfn[Adj[e]])
				S[++Top] = make_pair(x, Adj[e]), low[x] = min(low[x], dfn[Adj[e]]);
		}
}

int main()
{
	scanf("%d%d%d", &n, &m, &K), pw[0] = 1;
	for (int i = 1; i <= n; ++i) pw[i] = (LL)pw[i - 1] * K % Mod;
	for (int i = 1, x, y; i <= m; ++i) {
		scanf("%d%d", &x, &y);
		Next[++tot] = Head[x]; Head[x] = tot; Adj[tot] = y;
		Next[++tot] = Head[y]; Head[y] = tot; Adj[tot] = x;
	}
	memset(dfn, -1, sizeof(dfn)), memset(low, -1, sizeof(low));
	for (int i = 1; i <= n; ++i)
		if (dfn[i] == -1) {
			dex = 0;
			Tarjan(i, 0);
		}
	f[0][0] = 1;
	for (int i = 1; i <= K; ++i) {
		int sum = 0;
		for (int j = 0; j <= m; ++j)
			sum = (sum + (LL)f[i - 1][j]) % Mod;
		for (int j = m; j >= 0; --j) {
			f[i][j] = (sum % Mod + Mod) % Mod;
			sum = (sum - f[i - 1][j] + Mod) % Mod;
		}
	} /* (1 / (1 - x)) ^ K */
	int fans = 1;
	for (int i = 1; i <= cnt; ++i) {
		if (cnte[i] == 1) fans = (LL)fans * K % Mod;
		else if (cntv[i] == cnte[i]) {
			int sum = pw[cnte[i]];
			for (int j = 1; j < cnte[i]; ++j)
				sum = (sum + (LL)pw[gcd(cnte[i], j)]) % Mod;
			sum = (LL)sum * Inv(cnte[i] /* n */) % Mod;
			fans = (LL)fans * sum % Mod;
		} else {
			fans = (LL)fans * f[K][cnte[i]] % Mod;
		//	printf("%d %d %d\n", cnte[i], K, f[K][cnte[i]]);
		}
	}
	printf("%d\n", (fans % Mod + Mod) % Mod);
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N, k, flag;
    int a[5];
    for(int i = 0 ; i < 5 ; i++){
        cin >> a[i];
    }
    cin >> k;
    flag = 0;

    for(int i = 0 ; i < 5 ; i++){
        for(int j = i; j < 5; j++ ){
            if((a[j] - a[i]) > k ){
                flag = 1;
            }
        }
    }
    if(flag == 1){
        printf(":(");
    }else{
        printf("Yay!");
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  string s;
  cin>>s;
  int sum = 700;
  for(int i = 0; i < 3; i++){
    if(s[i]=='o') sum+=100;
  }
  cout<<sum<<endl;
  return 0;
}




Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};

#define lim 1000005

ll fastexpo(ll b,ll p){
    ll res = 1;
    while( p ){
        if ( p&1 ){
            res = (res*b)%mod;
        }
        p = p>>1LL;
        b = ( b*b )%mod;
    }
    return res;
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,ans,tmp;
    sfl(n);
    if( n==1 ){
        printf("0\n");
        return 0;
    }
    ans = fastexpo(10,n);
    ans = (ans - ((2*fastexpo(9,n))%mod)+mod)%mod;
    ans = (ans+fastexpo(8,n))%mod;
    pfl(ans);
    return 0;
}

Measured memory_bytes: 3736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split("");

		int ans=0;
		int now=0;
		
		for (int i = 0; i < str.length; i++) {
			if (str[i].equals("(")) {
				now++;
			} else if (str[i].equals(")")) {
				now--;
			} else {
				ans=now;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 24620
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,i,j,k,ans=0;
    string X;
    cin >> N;
    string music_name[50]={};
    int music_time[50]={};
    for(i=0;i<N;i++){
        cin >> music_name[i] >> music_time[i];
    }
    cin >> X;
    for(j=0;j<N;j++){
        if(X==music_name[j]){
            for(k=j+1;k<N;k++)ans += music_time[k];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll
#define endl '\n'

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
string s;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> n >> s){
        int ans = count(ALL(s), 'B') < count(ALL(s), 'R');
        puts(ans ? "Yes" : "No");
    }
    return 0;
}


Measured memory_bytes: 256
from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

while True:
    n = int(input())
    if n == 0:
        break
    P = [int(i) for i in input().split()]
    D = [int(i) for i in input().split()]

    E = [list() for i in range(n + 1)]

    for i, (p, c) in enumerate(zip(P, D), 2):
        E[i].append((p, c))
        E[p].append((i, c))

    ans = 3 * sum(D)
    visited = [False] * (n + 1)
    is_leaf = [len(E[i]) == 1 for i in range(n + 1)]
    ans -= 2 * sum(E[i][0][1] for i in range(n + 1) if is_leaf[i])

    def dfs(i):
        visited[i] = True
        res = 0

        for e, c in E[i]:
            if is_leaf[e] or visited[e]:
                continue
            res = max(res, dfs(e) + c)

        return res    

    r = 0

    for i in range(1, n + 1):
        if is_leaf[i]:
            continue
        visited = [False] * (n + 1)
        r = max(r, dfs(i))

    print(ans - r)


Measured memory_bytes: 6760
h,n = map(int,input().split())
p = []
inf = 10**9
for i in range(n):
    a,b = map(int,input().split())
    p.append([a,b])
m = [[0 for i in range(h)]for i in range(n+1)]
for i in range(n+1):
    for j in range(h):
        m[i][j] = inf
for i in range(n):
    for j in range(h):
        if p[i][0] >= j+1:
            m[i+1][j] = min(m[i][j],p[i][1])
        else:
            m[i+1][j] = min(m[i][j],m[i+1][j-p[i][0]]+p[i][1])
print(m[n][h-1])

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main() {
	ll k, i;
	cin >> k;
	int n = 50;
	ll x = k / 50, y = k % 50;
	vl a(n);
	for (i = 0; i < n; i++) {
		if (i < y) {
			a[i] = (n - 1) + x + n - (y - 1);
		}
		else {
			a[i] = (n - 1) + x - y;
		}
	}
	cout << n << endl;
	for (i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n; cin >> n;
  ll ans=0;
  for(int i=1;i<sqrt(n);i++){
    if(n%i==0&&n/i-i>=2){
      ans+=n/i-1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};


void solve(){
    int n,k;
    cin>>n>>k;
    int x[n];
    rep(i,n) cin>>x[i];
    int ans;
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=2*min(x[i], abs(k-x[i]));
    }
    cout<<sum<<endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}//send mod-2 for a^-1 if mod is a prime number

ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll subs(ll a,ll b)
{
    return (((a%mod)-(b%mod)+mod)%mod);
}
ll dv(ll a,ll b)
{
    ll inv=binpow(b,mod-2);
    return mul(a,inv);
}

ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        dsu_arr[i]=i;
        dsu_sz[i]=1;
    }
}
ll find(ll x)
{
     ll root=x;
    while (root!=dsu_arr[root])
    {
        root=dsu_arr[root];
    }
    while(x!=dsu_arr[x])
    {
        dsu_arr[x]=root;
        x=dsu_arr[x];
    }
    return root;
}
ll merge(ll x,ll y)
{
    ll root1=find(x);
    ll root2=find(y);
    
    if(root1==root2)
    return 0ll;
 
    if(dsu_sz[x]>dsu_sz[y]){
    dsu_arr[root2]=root1;
    dsu_sz[root1]+=dsu_sz[root2];
    }
    else
    {
         dsu_sz[root2]+=dsu_sz[root1];
        dsu_arr[root1]=root2;
    }
    return 1ll;
}
/*
vector<ll>adj[100005];
bool vis[100005];
ll dist[100005];
void bfs(ll c)
{
  vis[c]=true;
  dist[c]=0;
  q.push(c);
while(!q.empty())
{
    ll x=q.front();
    q.pop();
   
    for(ll i=0;i<adj[x].size();i++)
    {
        ll y=adj[x][i];
        if(!vis[y])
        {
            vis[y]=true;
            dist[y]=dist[x]+1;
            
            q.push(y);
        }
    }
 
}
}
*/

int main()
{
    Fast
ll x,y,z;
cin>>x>>y>>z;
map<ll,bool>ma;
ll ans=0;
ll cou=0;

ll i;
for(i=0;i<x;i++)
{

ans+=y;
cou++;
y*=y;
y%=z;


if(ma[y])
break;



ma[y]=true;


}


ll u=y;
ll b=y;
ll ans2=0;
ll cnt=0;
vector<ll>pasa;
while(1)
{
    pasa.push_back(u);
 ans2+=u;

 u*=u;
 u%=z;
 if(b==u)
 break;
 
}
cnt=pasa.size();
x-=cou;

ll d=x/cnt;
ans+=(d*ans2);
x%=cnt;

ll j=0;
while(x--)
{
 ans+=pasa[j];
 j++;
}


cout<<ans<<endl;


}



   
      
    
        



Measured memory_bytes: 6980
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int dig = 1;
    int c = b;
    while (b > 0) {
        b /= 10;
        dig++;
    }
    int num = 1;
    for (int i = 1; i < dig; i++) {
        num *= 10;
    }
    num *= a;
    num += c;

    int sq = sqrt(num);
    if (sq * sq == num) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

int main(){
	int n, m, k;
	cin >> n >> m >> k;
    for(int i = 0; i <= n; i++){
        int t = m * i;
        for(int j = 0; j <= m; j++){
            if(t + (n - 2 * i) * j == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256