akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool checker(string s)
{
    string rev_s(s);
    reverse(rev_s.begin(), rev_s.end());

    return (s == rev_s);
}

int main(void)
{
    string s;
    size_t size = 0;

    cin >> s;
    size = s.size();

    if ((checker(s))
    && (checker(s.substr(0, (size - 1)/2)))
    && (checker(s.substr((size + 1)/2, size)))) // (N+3)/2は配列の要素にすると1減って
                                                // (N+3)/2 - 2/2 = (N+1)/2 
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC161_C
//
//  Created by Kosei on R 2/04/04.
//  Copyright © Reiwa 2 Kosei. All rights reserved.
//

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
signed main() {
    ll n, k;
    cin >> n >> k;
    int a = n / k;
    cout << min(abs(n - (a * k)), abs(n - ((a + 1)* k))) << endl;
}


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

int main(){
	
	int N,ans=0;
	cin >> N;
	string s;
	cin >> s;
	rep(i,N-1){
			   if(s[i] != s[i+1]) ans ++;
	}
	ans++;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
const int N=100005;
queue<int> q;
vector<int> g[N];
int d[N], f[N];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i=1, x, y; i<=m; i++) {
		scanf("%d%d", &x, &y);
		g[y].push_back(x);
		d[x]++;
	}
	for (int i=1; i<=n; i++) if (d[i]==0) q.push(i);
	
	int ans = 0;
	while (!q.empty()) {
		int x=q.front(); q.pop();
	//	printf("x:  %d\n", x);
		for (int i=0; i<g[x].size(); i++) {
			int y=g[x][i];
			d[y]--;
			f[y]=max(f[y], f[x]+1);
			if (d[y]==0) q.push(y);
		}
		ans=max(f[x], ans);
	}
//	for (int i=1; i<=n; i++) printf("%d ", f[i]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    vint h(N);
    REP(i,N) cin>>h[i];

    sort(ALL(h));

    int ans=1e18;
    REP(i,N-K+1){
        int diff=h[i+K-1]-h[i];
        ans=min(ans,diff);
    }
    cout<<ans<<endl;
 
}


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

using namespace std;


//tako jedne noci je izbegao metak
const int maxi =1e6+10;
#define pb push_back
#define pii pair<int,int>

int a[maxi];
string s;
int n, m;
vector<int> v[maxi];
int comp;

void dfs(int x)
{
    a[x] = 1;
    comp++;

    for (int i:v[x])
        if (!a[i])dfs(i);
}
int main()
{
    cin>>n>>m;

    for (int i = 1;i<=m;i++)
    {
        int x, y;
        scanf("%d%d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }

    int ans = 0;
    for (int i = 1;i<=n;i++)
        if (!a[i])
    {
        comp = 0;
        dfs(i);
        ans = max(ans, comp);
    }

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



Measured memory_bytes: 40372
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <limits>
#include <cmath>
#include <numeric>
using namespace std;
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; }
const long long INF = 1LL << 60;

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

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

int main() {
	long long A, B, C, D, E;
	cin >> A >> B >> C >> D;
	E = lcm(C, D);
	long long res1, res2;
	res1 = A - 1 - (A - 1) / C - (A - 1) / D + (A - 1) / E;
	res2 = B - B / C - B / D + B /E;
	cout << res2 - res1 << endl;
}

Measured memory_bytes: 504
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b;
    cin >> a;
    cin >> b;

    if (a < b)
    {
        for (int i = 0; i < b; i++)
        {
            cout << a;
        }
        cout << endl;
    }else if (a > b)
    {
        for (int i = 0; i < a; i++)
        {
            cout << b;
        }
        cout << endl;
    }else if (a == b)
    {
        for (int i = 0; i < a; i++)
        {
            cout << b;
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1000000000
#define MOD 1000000007

int main(){

    ll mxnr,mxng;

    ll nr,ng,nc;

    cin >> mxnr >> mxng >> nr >> ng >> nc;

    vector<ll> r;
    vector<ll> g;
    vector<ll> c;

    ll i,a1;

    for(i=0;i<nr;i++){
        cin >> a1;
        r.push_back(a1);
    }
    for(i=0;i<ng;i++){
        cin >> a1;
        g.push_back(a1);
    }
    for(i=0;i<nc;i++){
        cin >> a1;
        c.push_back(a1);
    }

    sort(r.rbegin(),r.rend());
    sort(g.rbegin(),g.rend());
    sort(c.rbegin(),c.rend());


    ll sum = 0;

    vector<ll> ns1;
    vector<ll> ns2;
    vector<ll> ns3;

    vector<ll> ans;

    for(i=0;i<mxnr;i++){
        ans.push_back(r[i]);
    }
    for(i=0;i<mxng;i++){
        ans.push_back(g[i]);
    }

    ll tmp = min(mxnr+mxng,nc);

    for(i=0;i<tmp;i++){
        ans.push_back(c[i]);
    }

    sort(ans.rbegin(),ans.rend());

    for(i=0;i<mxng+mxnr;i++){
        sum = sum + ans[i];
    }

    cout << sum << endl;

}







Measured memory_bytes: 8816
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, board[110][110];

signed main() {
    cin >> N;
    rep(i,0,N) rep(j,0,N) cin >> board[i][j];
    int ans = 0;
    rep(i,0,N) rep(j,i+1,N) ans += min(board[i][j], board[j][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 998244353
#define mod2 1000000006
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
using namespace std ;
 
const lli dx4[] = {-1, 0, 1, 0};
const lli dy4[] = {0, 1, 0, -1};
const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
 
#define N 200005

void solve()
{
	lli k,n;
	cin>>k>>n;

	lli a[n];
	loopl(i,0,n) cin>>a[i];

	lli ans = k-a[n-1]+a[0];

	loopl(i,1,n)
	ans = max(ans , a[i]-a[i-1]);

	cout<<k-ans;



}
 
int main()
{
/////////////////////////////////////
    
    fastio;
/////////////////////////////////////  
 	
	lli t;
	t=1;
 
	while(t--)
		solve();
 
}

Measured memory_bytes: 1792
K, X = map(int,input().split())
amin = X - K + 1
amax = X + K - 1
if amin < -1000000:
    amin = -1000000
if amax > 1000000:
    amax = 1000000

answer = []
for i in range(amin, amax+1):
    answer.append(i)
print(*answer)

Measured memory_bytes: 3060
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools
 
def solve():
  a, b, c, d = map(int, input().split())
  a -= 1
  lc = (c*d)//fractions.gcd(c,d)
  ans = (b-a)-(b//c-a//c)-(b//d-a//d)+(b//lc-a//lc)
  print(ans)
  return 0
 
if __name__ == "__main__":
  solve()

Measured memory_bytes: 13320
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;

typedef pair<int, int> P;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int H, W, sx, sy, gx, gy;
    cin >> H >> W >> sx >> sy >> gx >> gy;
	--sx; --sy; --gx; --gy;
    char s[H][W];
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            cin >> s[i][j];
            if(s[i][j] == 's'){
                sx = i, sy = j;
            }
            if(s[i][j] == 'g'){
                gx = i, gy = j;
            }
        }
    }

    int dist[H][W];
    fill(dist[0], dist[H], INF);
    deque<P> que;
    dist[sx][sy] = 0;
    que.emplace_front(sx,sy);
    while(!que.empty()){
        P p = que.front();
        que.pop_front();
        int x = p.first;
        int y = p.second;
        
        for(int i = 0; i < 4; ++i){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= H || ny < 0 || ny >= W)  continue;
			/*
            if(s[nx][ny] == '#'){
                if(dist[nx][ny] > dist[x][y] + 1){
                    dist[nx][ny] = dist[x][y] + 1;
                    que.emplace_back(nx,ny);
                }
            }
			*/
            if(s[nx][ny] == '.'){
                if(dist[nx][ny] > dist[x][y]){
                    dist[nx][ny] = dist[x][y];
                    que.emplace_front(nx,ny);
                }
            }
        }
		rep(z,5){
			rep(w, 5){
				int nx = x-2+z, ny = y-2+w;
				if(nx < 0 || nx >= H || ny < 0 || ny >= W)  continue;
				if(s[nx][ny] == '.'){
					if(dist[nx][ny] > dist[x][y] + 1){
						dist[nx][ny] = dist[x][y] + 1;
						que.emplace_back(nx,ny);
					}
				}
			}
		}
    }
	if(dist[gx][gy] >= MOD) cout << -1 << endl;
    else cout << dist[gx][gy] << endl;
}

Measured memory_bytes: 12496
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
for i in range(n-1):
    p,r = divmod(A[i], 2)
    A[i] = r
    ans += p
    if A[i]*A[i+1]:
        A[i+1] -= 1
        ans += 1
print(ans+A[-1]//2)

Measured memory_bytes: 13048
N, Y = map(int, input().split())
result = [-1, -1, -1]
for a in range(0, N + 1):
    for b in range(0, N - a + 1):
        c = N - a - b
        if 10000 * a + 5000 * b + 1000 * c == Y:
            result = [a, b, c]
print(*result)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define DIM 104
#define ll long long
ll n;
ll S(ll n) {
    ll c = 0;
    while (n > 0) {
        c += (n % 10);
        n /= 10;
    }
    return c;
}
int main()
{
    cin >> n;
    if (n % S(n) == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
def base_10_to_n(a, b):
    if (int(a/b)):
        return base_10_to_n(int(a/b), b) + str(a%b)
    return str(a%b)

n, k =map(int, input().split())

a = base_10_to_n(n, k)
print(len(a))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
 long sum=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    if(i%3==0 || i%5==0){
        continue;
    }
   sum+=i; 
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <math.h>
#include <stack>
#include <tuple>
#include <cstring>
#include <chrono>
#include <bitset>
#include <list>
#include <stdlib.h>
#include <iomanip>
#include <bitset>
#include <chrono>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long

bool comparator(const pair<ll, ll> &x, const pair<ll, ll> &y)
{
    return x.second - x.first < y.second - y.first;
}

ll gcd(ll x, ll y)
{
    return y == 0LL ? x : gcd(y, x % y);
}

struct dot {
    ll coordinate, tree;
    bool is_left;

    dot(ll _coordinate, ll _tree, bool _is_left)
    {
        coordinate = _coordinate;
        tree = _tree;
        is_left = _is_left;
    }

    ll dist() const
    {
        return abs(coordinate - tree);
    }

    bool operator<(const dot& other) const
    {
        return dist() > other.dist();
    }
};

bool is_free(ll x, set<ll> &used_coords)
{
    return used_coords.find(x) == used_coords.end();
}

char get_stronger(char c) {
    if (c == 'r') return 'p';
    if (c == 'p') return 's';
    return 'r';
}

bool is_stronger(char c, char t) {
    if (c == 'r' && t == 's') return true;
    if (c == 's' && t == 'p') return true;
    if (c == 'p' && t == 'r') return true;
    return false;
}

int get_price(char c, int r, int s, int p) {
    if (c == 'r') return r;
    if (c == 'p') return p;
    return s;
}

int main()
{
    std::ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    
    int r, s, p;
    cin >> r >> s >> p;
    
    string t;
    cin >> t;
    
    vector<char> solution(n);
    ll total_price = 0LL;
    
    for (int i = 0; i < k; i++) {
        solution[i] = get_stronger(t[i]);
        total_price += get_price(solution[i], r, s, p);
    }
    
    for (int i = k; i < n; i++) {
        char c = t[i];
        char stronger = get_stronger(c);
        
        if (stronger != solution[i - k]) {
            solution[i] = stronger;
        } else {
            if (i + k < n) {
                // has next; take it, so not to take stronger for next
                solution[i] = t[i + k] == stronger ? solution[i] : t[i + k];
            } else {
                // who cares; takes same
                solution[i] = t[i];
            }
        }
        
        if (is_stronger(solution[i], t[i])) {
            total_price += get_price(solution[i], r, s, p);
        }
        
        if (i - k >= 0 && solution[i] == solution[i - k]) {
            //cout << "";
        }
        
        //cout << t[i] << ' ' << solution[i] << ' ' << (i - k >= 0 ? solution[i - k] : '-') << endl;
    }
    
    cout << total_price << endl;
    

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,j,a,ind;

    // scanf("%d",&t);
   for(i=1;i<=5;i++)
   {
       scanf("%d",&a);
       if(a==0)
       ind=i;
    }

    printf("%d\n",ind);
   

}

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  cout << (h-a)*(w-b) << endl;
  return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    io.Source.stdin.getLines().foreach(rec)
  }

  def rec(s: String): Unit = {
    if (s.matches(""".*(the|that|this).*""")) {
      println(s)
      return
    }

    rec(next(s))
    
    def next(s: String): String = {
      val sss = s.map({
        case cc if 'a' to 'z' contains cc => (((cc - 'a' + 1) % 26) + 'a').toChar
        case ch => ch
      })
      sss.toString
    }
  }
}

Measured memory_bytes: 46540
import scala.io.StdIn.readLine

object Main {
    def main(args: Array[String]): Unit = { 
        var seq: Seq[Int] = Seq()
        for(i <- 0 until 10) seq:+= readLine().toInt
        seq = seq.sorted(Ordering[Int].reverse)
        for(i <- 0 until 3) println(seq(i))
    }   
}

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

int main()
{
	int a,b;
	cin>>a>>b;
	
	int s,t,u,v,cnt=0;
	for(int i=a;i<=b;i++)
	{
		s=i%10;
		t=i/10000%10;
		u=i/10%10;
		v=i/1000%10;
		
		if(s==t&&u==v) cnt++;
	}
	
	cout<<cnt<<endl;
}

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

#define F first
#define S second

using ll = long long;
using pii = pair <int, int>;

const int oo = 1e9 + 4;
const int SZ = 2e5 + 4;

ll n, m;

void read() {
    cin >> n >> m;
}

void solve() {
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    read();
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

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

const int N = 1e5+10, M = 1e9+7;
int n, dp[N][2];
vector<int> g[N];

int add(int a, int b) {return (a+b)%M;}
int mult(int a, int b) {return ((ll)a*b)%M;}

int rec(int s, bool black, int par = 0) {
	int& memo = dp[s][black];
	if(memo != -1) return memo;
	int res = 1;
	for(int v : g[s]) {
		if(v == par) continue;
		if(black) res = mult(res, rec(v, 0, s));
		else res = mult(res, add(rec(v, 0, s), rec(v, 1, s)));
	}
	return memo = res;
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    memset(dp, -1, sizeof(dp));
    cin >> n;
    REP(i, n-1) {
    	int a, b;
    	cin >> a >> b;
    	g[a].push_back(b);
    	g[b].push_back(a);
    }
    cout << add(rec(1, 0), rec(1, 1)) << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

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

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

int i,j,k,tmp;
ll ans = 0;

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

  ll N; cin >> N;
  ll X, M; cin >> X >> M;
  ll sum = 0; ll ans = 0; ll start = 0; ll end = 0;

  ll chk[M+1]; rep(i,M+1){chk[i]=0;}
  ll tmp[M+1]; rep(i,M+1){tmp[i]=0;}
  tmp[1]=X; chk[X]=1; sum = X;
  ll circle = 0;

  for(int i=2;i<=M;i++){
	ll cal = tmp[i-1] * tmp[i-1] % M;
	if(cal == 0){cout << sum << endl; return 0;}
	if(chk[cal]>0){end = i-1; start = chk[cal]; break;}
	chk[cal]=i; tmp[i]=cal; sum += cal;
	if(i == N){cout << sum << endl; return 0;}
  }

  ans += sum;
  N -= end; circle = end - start + 1;
  for(int i=1; i<start; i++){sum -= tmp[i];}
  ans += (N / circle) * sum;
  
  if(N % circle > 0){
	  ll end2 = N % circle;
	  for(int i=1; i <= end2;i++){
		  ans += tmp[i+start-1];
	  }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5156
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main()
{
	int i, n;
	int a[200005];
	int b[200005];
	scanf("%d", &n);
	for(i = 1 ; i <= n ; i++)
	{
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	sort(a + 1, a + n + 1);
	for(i = 1 ; i <= n ; i++)
	{
		if(b[i] > a[ n / 2])
		{
			printf("%d\n",a[n / 2]);
		}
		else
		{
			printf("%d\n",a[ (n / 2) + 1]);
		}
	}
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        
        for (int i = 0; i < S.length(); ++i){
            if (S.equals(T)){ 
                System.out.println("Yes");
                return;
            }
            S = S.substring(S.length()-1, S.length()) + S.substring(0, S.length()-1);
        }
 
        System.out.println("No");
 
    }
}

Measured memory_bytes: 39376
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define For(a, b, c) for(int i = a; i < b; i+=c)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    ll n, k; cin >> n >> k;
    vi v(n + 1);
    for(int i = 0; i < n; i++) {
        cin >> v[i + 1];
    }
    ll j = 1;
    ll k1 = k;
    unordered_map<ll, ll> m;
    ll cnt = 0;
    ll mod = 1;
    while(k--) {
        if(m[j] == 0) {
            m[j] = cnt;
            j = v[j];
        }
        else {
            mod = cnt - m[j];
            break;
        }
        cnt++;
    }
    k = (k1 - m[j]) % mod;
    while(k--) {
        j = v[j];
    }
    cout << j;
    return 0;
}

Measured memory_bytes: 11032
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;


class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        for (int i = s.Length - 2; i >= 0; i--)
        {
            if(s.Substring(0, i) == s.Substring(0, i / 2) + s.Substring(0, i / 2))
            {
                Console.WriteLine(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 11092
from collections import defaultdict
di = defaultdict(int)
N, K = map(int, input().split())

d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

for i in range(N):
    di[i + 1] = 0

for i in A:
    for j in i:
        di[j] += 1

count = 0
for i, k in di.items():
    if (k == 0):
        count += 1

print(count)


Measured memory_bytes: 9500
#include<stdio.h>
int n,m;
char s[111];
int a[26];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0; i<n; i++){
		scanf("%s",s);
		for(int j=0; j<m; j++)
			a[s[j]-'a']++;
	}
	int c4 = (n/2) * (m/2);
	int c1 = (n-n/2*2) * (m-m/2*2);
	int c2 = (n*m-c4*4-c1)/2;
	while(c4 > 0){
		bool flag = true;
		for(int i=0; i<26; i++)
			if(a[i] >= 4){
				a[i] -= 4;
				flag=false;
				break;
			}
		if(flag){
			puts("No");
			return 0;
		}
		c4 --;
	}
	while(c2 > 0){
		bool flag = true;
		for(int i=0; i<26; i++)
			if(a[i] >= 2){
				a[i] -= 2;
				flag=false;
				break;
			}
		if(flag){
			puts("No");
			return 0;
		}
		c2 --;
	}
	while(c1 > 0){
		bool flag = true;
		for(int i=0; i<26; i++)
			if(a[i] >= 1){
				a[i] -= 1;
				flag=false;
				break;
			}
		if(flag){
			puts("No");
			return 0;
		}
		c1 --;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define REP(i,a,b) for(int i=a; i<b; i++)

const int MX=1e5+3;

int n;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	if(n==25) cout<<"Christmas"<<endl;
	if(n==24) cout<<"Christmas Eve"<<endl;
	if(n==23) cout<<"Christmas Eve Eve"<<endl;
	if(n==22) cout<<"Christmas Eve Eve Eve"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,a[100005],fa[100005],ans;
int find(int u){
	if(fa[u]!=u)fa[u]=find(fa[u]);
	return fa[u];
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		fa[i]=i;
	}
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		fa[find(u)]=find(v);
	}
	for(int i=1;i<=n;i++)
		if(find(i)==find(a[i]))ans++;
	printf("%d\n",ans);
} 

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

using namespace std;

int main()
{
    long long n;
    cin>>n;
    string s;
    while(n)
    {
        long long a=n%26;
        n=n/26;
        if(a==0)
        {
            n--;
            s+='z';
        }
        else
            s+=('a'+a-1);

    }
    reverse(s.begin(), s.end());

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


Measured memory_bytes: 3596
#include <iostream>
#include <cmath>
using namespace std;
int n,d;
int a[15][15];
double sum=0,ans=0;
bool ispow(int x){
	for(int i=0;i*i<=x;i++){
		if(i*i==x) return 1;
	}
	return 0;
}
int main(){
	cin>>n>>d;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=d;j++)
			cin>>a[i][j];
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			sum=0;//////
			for(int k=1;k<=d;k++){
				sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]); 
			}
			if(ispow(sum)){
				//cout<<i<<" "<<j<<endl;
				ans++;
			} 
			///floor()直接用
			///int()向下取整（强制类型转换） 
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    n, d = getList()
    ans = 0
    for i in range(n):
        a, b = getList()
        if a ** 2 + b ** 2 <= d ** 2:
            ans += 1

    print(ans)


def main():
    n = getN()
    for _ in range(n):
        solve()


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

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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

string s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    int sum = 0;
    for(int i = 0; i < s.size(); i++)
        sum += s[i] - '0';
    if(sum % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}



Measured memory_bytes: 3736
n = gets.chop.to_i
list = gets.chop.split(' ').map(&:to_i)

max = -1000000
min = 1000000
total = 0

list.each do |n|
  total = total + n
  max = n if max < n
  min = n if min > n
end

printf "%d %d %d\n", min, max, total



Measured memory_bytes: 7268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int count = 0;
		do {
			//ログイン日数
			count++;
			if (count % 7 == 0) {
				C -= B;
			}
			C -= A;

		} while(C > 0);
		System.out.println(count);
	}

}


Measured memory_bytes: 26336
l = gets.chomp.split
s = []

l.each do |x|
  case x
  when '+', '-', '*', '/'
    b = s.pop
    a = s.pop
    case x
    when '+'
      s.push(a + b)
    when '-'
      s.push(a - b)
    when '*'
      s.push(a * b)
    when '/'
      s.push(a / b)      
    end
  else
    s.push(x.to_i)
  end
end

puts s



Measured memory_bytes: 6876
import sys

n = int(input())

w = []
for i in range(n) : 
    w.append(input())

def is_unique(seq):
    return len(seq) == len(set(seq))

if not is_unique(w):
    print("No")
    sys.exit(0)

pre_word = w[0]
for word in w[1:]:
    # print(pre_word[-1], word[0])
    if pre_word[-1] != word[0]:
        print("No")
        sys.exit(0)
    pre_word = word
print("Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int a,b;
  string s;
  cin >> a >> b >> s;
  int i;
  char temp;
  for(i = 0;i < a;++i){
    temp = s.at(i) - '0';
    if(temp >= 0 && temp <= 9){
      continue;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  if(s.at(a) == '-'){
  }else{
    cout << "No" << endl;
      return 0;
  }
  for(i = a+1;i < a+b+1;++i){
    temp = s.at(i) - '0';
    if(temp >= 0 && temp <= 9){
      continue;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

bool inter(int x1, int y1, int r1, int x2, int y2, int r2){
  int dx = x1-x2, dy = y1-y2;
  return dx*dx+dy*dy < (r1+r2)*(r1+r2);
}

int N;
int pv[24];
bool dp[1<<24];

int bc(int x){
  int res = 0;
  while(x>0) res += x&1,  x>>=1;
  return res;
}

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

  while(cin>>N, N){
	VI xs(N), ys(N), rs(N), cols(N);
	REP(i,N) cin >> xs[i] >> ys[i] >> rs[i] >> cols[i];

	fill(pv, pv+24, 0);
	REP(i,N) FOR(j,i+1,N){
	  if(inter(xs[i], ys[i], rs[i], xs[j], ys[j], rs[j]))
		pv[j] |= 1<<i;
	}

	fill(dp, dp+(1<<24), false);
	dp[0] = true;
	for(int b=0;b<1<<N;++b){
	  if(!dp[b]) continue;
	  for(int j=0;j<N;++j){
		if(b>>j&1) continue;
		for(int k=j+1;k<N;++k){
		  if(b>>k&1 || cols[j] != cols[k]) continue;
		  bool ok = (b & (pv[j] | pv[k])) == (pv[j] | pv[k]);
		  dp[b|(1<<j)|(1<<k)] = dp[b|(1<<j)|(1<<k)] || ok;
		}
	  }
	}

	int ans = 0;
	for(int b=0;b<1<<N;++b) if(dp[b]) ans=max(ans,bc(b));
	cout << ans << endl;
  }

  return 0;
}

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

namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] L = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderByDescending(x => x).ToArray();
            int sum = L.Sum() - L[0];
            Console.WriteLine("{0}", (L[0] < sum) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	string S;
	cin >> S;
	for (int i = 0; i < A + B + 1; i++) {
		if (i < A || i > A) {
			if (S.at(i) < 48 || S.at(i) > 57) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (S.at(i) != '-') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import dijkstra
import itertools
from scipy.sparse import csr_matrix
inf = 1 + 10**8
n, m, r = list(map(int, input().split()))
r = list(map(int, input().split()))
graph = np.full((n+1,n+1), inf)
for i in range(m):
    a,b,c = list(map(int, input().split()))
    graph[a][b] = c
    graph[b][a] = c
p_list = list(itertools.permutations(r,len(r)))
graph = dijkstra(csr_matrix(graph))
min_cost = inf * 200
for i in p_list:
    candidate = 0
    for j in range(len(i) - 1):
        candidate += graph[i[j]][i[j + 1]]
    if min_cost > candidate:
        min_cost = candidate
print(int(min_cost))

Measured memory_bytes: 33056
using System;
using System.Collections.Generic;

class Program {
  static void Main(string[] args) {
    string s = Console.ReadLine();
    HashSet<char> hs = new HashSet<char>();

    for (int i = 0; i < s.Length; ++i) {
      hs.Add(s[i]);
    }

    if (hs.Count == 2) {
      Console.WriteLine("Yes");
    } else {
      Console.WriteLine("No");
    }
  }
}

Measured memory_bytes: 13396
#include <stdio.h>

int main(int argc, const char * argv[])
{
    
    int tanka, suryo, sum = 0, cnt = 0, sum1 = 0, ave = 0;
    double syousu;
    
    while (scanf("%d, %d", &tanka, &suryo) != EOF) {
        sum += tanka * suryo;
        sum1 += suryo;
        cnt++;
    }
    
    ave = sum1 / cnt;
    
    syousu = (double)sum1 / (double)cnt - (double)ave;
    
    if (syousu >= 0.5) {
        ave += 1;
    }
    
    printf("%d\n%d\n", sum, ave);
    
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

int main(){
  string S[3];
  for (int i = 0; i < 3; ++i)
  { 
    cin >> S[i];
  }

  char next = 'a';
  char now;
  int count = 0;
  while(true){
    now = next - 'a';
    if(S[now].length() != 0){
      next = S[now].front();
      S[now].erase(0, 1);
    }
    else break;
  }
  char answer = next - 32;
  cout << answer;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

N, M, Q = MI()
E = [[] for _ in range(Q)]
for i in range(Q):
    a, b, c, d = MI()
    E[i] = [a, b, c, d]
ans = 0
def dfs(A):
    global ans
    if len(A) == N + 1:
        res = 0
        for (a, b, c, d) in E:
            if A[b] - A[a] == c:
                res += d
        # print(A)
        ans = max(ans, res)
        return

    A.append(A[-1])
    while A[-1] <= M:
        dfs(A.copy())
        A[-1] += 1

def solve():

    dfs([1])
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9156
def main():
    n = int(input().rstrip())
    from collections import defaultdict
    
    edges = defaultdict(dict)
    for i in range(n - 1):
        a, b, distance = [int(x) for x in input().rstrip().split(" ")]
        edges[a][b] = distance
        edges[b][a] = distance

    passed = {1: 0}

    distances = {1: 0}
    candidates = [(1, 0)]
    total_distance = 0
    while candidates:
        a, total_distance = candidates.pop(0)
        for b, distance in edges[a].items():
            if not b in passed:
                distances[b] = total_distance + distance
                passed[b] = 1
                candidates.append((b, total_distance + distance))
    for number in range(1, n + 1):
        print(distances[number] % 2)


if __name__ == '__main__':
    main()


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

using namespace std;

const int N = 2e5 + 10;
const int M = 4e5 + 10;

typedef long long ll;

int n;
string s;

int main()
{
	scanf("%d", &n);
	cin >> s;
	if(n % 2)
	{
		puts("No");
		return 0;
	}
	if(s.substr(0, n / 2) == s.substr(n / 2, n))
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
}

Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc085
// C - Otoshidama
// status:
// tag:

#define SUBMIT

#include <iostream>

using namespace std;


int main() {
    int N, Y;
    cin >> N >> Y;

    Y /= 1000;

    for (int x = 0; x <= N; ++x) {
        for (int y = 0; x + y <= N; ++y) {
            auto z = N - (x + y);
            auto sum = 10 * x + 5 * y + z;
            if (sum == Y) {
                cout << x << " " << y << " " << z << endl;
                exit(0);
            }
        }
    }

    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
def resolve():
    N=int(input())
    mini=10**10
    for i in range(N+1):
        j=N-i
        mini=min(mini,f(i,6)+f(j,9))
    print(mini)


def f(n,m):#nをm進数にしたときの桁和
    i=0
    while n>0:
        i=i+n%m
        n=n//m
    return(i)
resolve()

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

string a,b;
ll n,k;
 
ll count(ll m) 
{  
    ll lookup[m + 1][n + 1] = { { 0 } }; 
  
    for (int i = 0; i <= n; ++i) 
        lookup[0][i] = 0; 
  
    for (int i = 0; i <= m; ++i) 
        lookup[i][0] = 1; 

    for (int i = 1; i <= m; i++) 
    { 
        for (int j = 1; j <= n; j++) 
        { 
            if (a[i - 1] == b[j - 1]) 
                lookup[i][j] = lookup[i - 1][j - 1] +  lookup[i - 1][j]; 
                  
            else
                lookup[i][j] = lookup[i - 1][j]; 
        } 
    } 

    // for(int i=0;i<=m;i++)
    // {
    //     for(int j=0;j<=n;j++)
    //     {
    //         cout<<lookup[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    // cout<<endl;
  
    return lookup[m][n]; 
} 



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    //cin>>t;
     t=1;
    while(t--)
    {
        ll n;
        cin>>n;
        ll ini = 360;
        ll ans = 1;
        while(true)
        {
            ll val=ans*n;
            if(val==ini)
                break;
            if(val>ini)
                ini+=360;
            else
                ans++;
        }
        cout<<ans<<endl;

    }
    
    return 0;
}

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

using namespace std;

void solution()
{
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int b = 0, e = 1;
    int nk = s[0] == '0' ? 1 : 0;
    int score = 1;
    while(b < n){
        if(nk <= k){
            score = max(score, e - b);
        }
        if(nk <= k && e < n){
            e += 1;
            if(s[e-2] == '1' && s[e-1] == '0') {
                nk += 1;
            }
        }
        else{
            b += 1;
            if(b < n){
                if(s[max(0, b-1)] == '0' && s[b] == '1') {
                    nk -= 1;
                }
                if(b >= e) e = b + 1;
            }
        }
    }
    cout << score << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String[] s = in.nextStringArray(3);
            for (int i = 0; i < 3; i++) {
                out.print(s[i].charAt(i));
            }
            out.println();
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public String[] nextStringArray(int n) {
            String[] res = new String[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextString();
            }
            return res;
        }

    }
}



Measured memory_bytes: 21460
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                ans+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
N=int(input())
H=list(map(int,input().split()))
for i in range(N-1,0,-1):
    if H[i]<H[i-1]:
        H[i-1]=H[i-1]-1
        if H[i]<H[i-1]:
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 15400
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(void)
{
	char Sa[101],Sb[101],Sc[101];
	int len_A,len_B,len_C,hantei_A,hantei_B,hantei_C;
	char joutai = 'A';
	
	scanf("%s",Sa);
	scanf("%s",Sb);
	scanf("%s",Sc);
	
	hantei_A=0;
	hantei_B=0;
	hantei_C=0;
	len_A = strlen(Sa);
	len_B = strlen(Sb);
	len_C = strlen(Sc);
	
	while(1){
	
		if(joutai == 'A'){
			joutai = toupper( Sa[hantei_A]);
			hantei_A++;
			if(hantei_A == len_A + 1){
				printf("A\n");
				break;
			}
		}else if(joutai == 'B'){
			joutai = toupper(Sb[hantei_B]);
			hantei_B++;
			if(hantei_B == len_B + 1){
				printf("B\n");
				break;
			}
		}else if(joutai == 'C'){
			joutai = toupper(Sc[hantei_C]);
			hantei_C++;
			if(hantei_C == len_C + 1){
				printf("C\n");
				break;
			}
		}else{
		}
	}
	
	return 0;
}


Measured memory_bytes: 128