akhauriyash/Code-Regression huggingface dataset:
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> N, D, A;
  vector<pair<int,int>> XH(N);
  int area = D * 2 + 1;
  
  for (auto&& i : XH)
    cin >> i.first >> i.second;
  
  bst::sort(XH);

  ll r = 0, reduce = 0;
  map<ll, ll> reduces;
  REP(i, N) {
    for (auto it = reduces.begin(); it != reduces.upper_bound(XH[i].first);) {
      reduce -= it->second;
      reduces.erase(it++);
    }
    XH[i].second = max(0LL, (ll)XH[i].second - reduce);
    ll times = (XH[i].second + A - 1) / A;
    reduce += (ll)A * times;
    reduces[(ll)XH[i].first + area] += (ll)A * times;
    r += times;
  }

  return r;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}




Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<P> time(N);
    ll a,b;
    rep(i,N){
        cin >> a >> b;
        time[i] = P(b,a);
    }
    sort(all(time));//(due,cost)
    ll now = 0;
    rep(i,N){
        if(now + time[i].second > time[i].first){
            cout << "No" << endl;
            return 0;
        }
        now += time[i].second;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 6344
#include<stdio.h>
long long N;
long long a[100005],b[100005],c[100005],dp[100005][5];
long long max(long long a,long long b,long long c)
{
	if((a>=b)&&(a>=c))
	{
		return a;
	}
	else if(b>=a&&b>=c)
	{
		return b;
	}
	else
	{
		return c;
	}
}
long long f(long long day,long long co)
{
	if(dp[day][co]!=-1)return dp[day][co];
	else if(day>N)return 0;
	else
	{
		if(co==1)
		{
			return dp[day][co]=a[day]+max(f(day+1,2),f(day+1,3),0);
		}
		else if(co==2)
		{
			return dp[day][co]=b[day]+max(f(day+1,1),f(day+1,3),0);
		}
		else if(co==3)
		{

			return dp[day][co]=c[day]+max(f(day+1,2),f(day+1,1),0);
		}
	}
}
int main()
{
	scanf("%Ld",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%Ld %Ld %Ld",&a[i],&b[i],&c[i]);
	}
	for(int i=0;i<=N+3;i++)
	{
		for(int j=0;j<5;j++)
		{
			dp[i][j]=-1;
		}
	}
	printf("%Ld\n",max(f(1,1),f(1,2),f(1,3)));
	return 0;
}

	


Measured memory_bytes: 11136
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main {
	private static int h, w, n;
	private static boolean[] wall;
	private static int[] sx, sy;
	
	private static int[] dx = { 0, 1,  0, -1 };
	private static int[] dy = { 1, 0, -1,  0 };
	
	private static int getInt() throws Exception {
		int i = 0;
		while(true){
			int buf = System.in.read();
			if('0' > buf || buf > '9'){
				break;
			}
			i = i * 10 + buf - '0';
		}
		return i;
	}
	private static int heuristic(final int sx, final int sy, final int ex, final int ey) {
		return 0;//Math.abs(sx - ex) + Math.abs(sy - ey);
	}
	private static int search(final int sx, final int sy, final int ex, final int ey) {
		Comparator<int[]> cmp = new Comparator<int[]>() {
			@Override
			public int compare(int[] a, int[] b) {
				return Integer.compare(a[2] + heuristic(a[0], a[1], ex, ey), b[2] + heuristic(b[0], b[1], ex, ey));
			}
		};
		boolean[] visited = new boolean[h*w];
		PriorityQueue<int[]> q = new PriorityQueue<>(cmp);
		q.offer(new int[]{sx, sy, 0});
		while(true){
			int[] now = q.poll();
			for(int i = 0; i < 4; i++){
				int nx = now[0] + dx[i];
				int ny = now[1] + dy[i];
				int p = nx + ny*w;
				if(0 <= nx && nx < w && 0 <= ny && ny < h && !wall[p] && !visited[p]){
					if(nx == ex && ey == ny) return now[2] + 1;
					visited[p] = true;
					q.offer(new int[]{nx, ny, now[2] + 1});
				}
			}
		}
		
	}
	public static void main(String[] args) throws Exception {
		h = getInt();
		w = getInt();
		n = getInt();
		wall = new boolean[h*w];
		sx = new int[10];
		sy = new int[10];
		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++) {
				int buf = System.in.read();
				if(buf =='\n' || buf == '\r'){
					x--;
					continue;
				}
				wall[x + y*w] = buf == 'X';
				if(buf == 'S'){
					sx[0] = x;
					sy[0] = y;
				}
				if('1' <= buf && buf <= '9'){
					buf -= '0';
					sx[buf] = x;
					sy[buf] = y;
				}
			}
		}
		int a = 0;
		for(int i = 1; i <= n; i++) a += search(sx[i-1], sy[i-1], sx[i], sy[i]);
		System.out.println(a);
	}

}

Measured memory_bytes: 63724
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define loop(i,n) for(int i=0;i<(n);i++)
#define cont(i,n) for(int i=1;i<=(n);i++)
#define circ(i,a,b) for(int i=(a);i<=(b);i++)
#define range(i,a,b,c) for(int i=(a);((c)>0?i<=(b):i>=(b));i+=(c))
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(),_e_D_=(v).end();it!=_e_D_;it++)
#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1 y1II11II11III11I1III11II111IIII1II1I1
#define pub push_back
#define pob pop_back
#define mak make_pair

typedef long long ll;
typedef long double lf;
const int Inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

map<lf,int> is;
int n;
int cnt[33][33];

ll gcd(ll a,ll b){
	return !b?a:gcd(b,a%b);
}

int main(){
	scanf("%d",&n);
	ll res=0;
	cont(i,n){
		lf a;scanf("%Lf",&a);
		ll A,B;A=a*1000000000+1e-5;B=1000000000+1e-5;
		ll C=gcd(A,B);A/=C;B/=C;
		int s2=0,s5=0;
		while(A%2==0)s2++,A/=2;
		while(A%5==0)s5++,A/=5;
		while(B%2==0)s2--,B/=2;
		while(B%5==0)s5--,B/=5;
		s2+=15;s5+=15;
		s2=min(s2,30);s5=min(s5,30);
		loop(i,s2+1)loop(j,s5+1)res+=cnt[i][j];
		cnt[30-s2][30-s5]++;
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i < (n); ++i)
#define repD(i, a, n) for(ll i = a; i > (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
// #define mp make_pair
#define pb push_back
// #define endl "\n"
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
ll p=1000000007;
float E = 0.00000000000001;
ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    if(y%2==0){
        ll q=power(x,y/2);
        q=q%p;
        return (q*q)%p;
    }
    ll q=power(x,y/2);
    q=q%p;
    return ((x%p)*((q*q)%p))%p; 
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}  

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a); 
}
long long int mod(long long int a, long long int b) {
    long long int ret = a%b; return ret>=0? ret: ret+b; 
}

int powerCount(int num, int x){
    int count = 0;
    while(!(num%x)){
        count++;
        num/=x;
    }
    return count;
}

vector <int> SieveOfEratosthenes(int n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
    vector<int> vec;
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) {
        vec.push_back(p);
          // cout << p << " ";
        } 
    return vec;
}

int main(){
    std::ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t = 1;
    while(t--){
    	long long a;
    	long double b;
    	cin>>a>>b;
    	cout<<(long long)(a*b);
    }
    return 0;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n,Max=0;
  int t[100000];
  cin >> n;
  rep(i,n){
    cin >> t[i];
    Max = max(t[i],Max);
  }
  vector<int> v;
  for(int i=1; i<=Max; i++){
    if(Max%i == 0) v.push_back(i);
  }
  int ans = 0;
  rep(i,n){
    rep(j,v.size()){
      if(t[i]<=v[j]){
        ans += v[j]-t[i];
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int a[200009];

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

   int Max = -1;
   for (int i = 0; i < n; i++ ){
      int x;
      cin >> x;
      a[x]++;
      Max = max(Max, x);
   }

   sort(a, a+Max+1);

   int sum = 0;
   for (int i = 0; i <= Max - k; i++) {
      sum += a[i];
   }
   cout << sum << endl;

   return 0;
}

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

int main() {
    using namespace std;

    unsigned long N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    string T(S.begin(), S.end());
    T += string(S.rbegin(), S.rend());
    for(unsigned long i = 0; i < N; ++i)S = min(S, string(T.begin() + i, T.begin() + i + N));
    unsigned long k{static_cast<unsigned long>(find_if_not(S.begin(), S.end(), [&S](auto i){return i == S[0];}) - S.begin())};
    --K;
    unsigned long l = K > 13 ? N : min(N, (k << K) - k);
    string A(l, S[0]);
    A += string(S.begin(), S.begin() + N - A.size());

    cout << A << endl;

    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vii;

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 GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();

		Map<Integer, Integer> map = new HashMap<>();
		boolean fin = false;
		for (int i=0; i<M; i++) {
			int key = scan.nextInt();
			int value = scan.nextInt();
			if (map.get(key) == null) {
				map.put(key, value);
			}
			else {
				int v2 = map.get(key);
				if (v2 != value) {
					System.out.println(-1);
					fin = true;
					break;
				}
			}
		}

		StringBuilder ans = new StringBuilder();
		if (!fin) {
			for (int i=1; i<=N; i++) {
				if (map.get(i) == null) {
					if (i == 1 && N != 1) {
						ans.append(1);
					}
					else {
						ans.append(0);
					}
				}
				else {
					if (i == 1 && map.get(i) == 0 && N != 1) {
						System.out.println(-1);
						fin = true;
						break;
					}
					ans.append(map.get(i));
				}
			}
			if (!fin) {
				System.out.println(ans);
			}
		}
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
pair<ll,ll>a[55],b[55];
int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>l>>r;
        a[i]={l,r};
    }
    for(i=0;i<m;i++)
    {
        cin>>l>>r;
        b[i]={l,r};
    }
    for(i=0;i<n;i++)
    {
        ll mx=LLONG_MAX,ind=-1;
        for(j=0;j<m;j++)
        {
            r=abs(a[i].first-b[j].first)+abs(a[i].second-b[j].second);
            if(mx>r)
            {
                mx=r;
                ind=j+1;
            }
        }
        cout<<ind<<"\n";
    }
    return 0;
}



Measured memory_bytes: 256
n,m=map(int, input().split())
h = list(map(int, input().split()))
l = [input().split() for i in range(m)]

list = [0]*n
for j in range(m):
    if h[int(l[j][0])-1] > h[int(l[j][1])-1]:
        list[int(l[j][1])-1] -= 1
    elif  h[int(l[j][0])-1] < h[int(l[j][1])-1]:
        list[int(l[j][0])-1] -= 1
    else :
        list[int(l[j][0])-1] -= 1
        list[int(l[j][1])-1] -= 1

print(list.count(0))

Measured memory_bytes: 43172
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  constexpr ll INF = 10100100100100;

  ll ans = INF;
  for (ll i = 1; i <= 1000000; i++) {
    if (N % i == 0) {
      ll j = N / i;
      ans = min(ans, (i - 1) + (j - 1));
    }
  }
  if (ans == INF) ans = N - 1;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    string s;
    cin >> s;
    int ans = 0;
    int cnt = 0;
    rep(i,s.size()){
        char c = s[i];
        if(c == 'A' || c == 'C' || c == 'G' || c == 'T'){
            cnt += 1;
        }else cnt = 0;
        ans = max(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int,input().split())
a = list(map(int, input().split()))
dst = [1] #今まで行った町（最初も含む）のリスト
dsts = set(dst) #今まで行った町（最初も含む）のset
twn = 1 #テレポーター転送先
for _ in range(k):
    if a[twn - 1] in dsts: #テレポーター転送先が今まで行った町setに入っていたら（そこから先の転送はループする）
        index = dst.index(a[twn - 1]) #今まで行った町リストでのテレポーター転送先のindex取得
        ld = len(dst[:index]) #ループする前の長さとループ部分の周期を求める
        cyc = len(dst[index:])
        print(dst[(ld - 1) + (k + 1 - ld) % cyc] if (k + 1 - ld) % cyc != 0 else dst[-1])
        exit()
    else: #テレポーター転送先が今まで行った町setに入っていなかったら
        dst.append(a[twn - 1]) #入っていなかったら今まで行った町リストに追加
        dsts.add(a[twn - 1])
        twn = a[twn - 1] #テレポーター転送先の更新
print(dst[-1])

Measured memory_bytes: 32408
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll turn = 0;
  string win = "undef";
  while (true) {
    if(turn == 0){
      c -= b;
      if (c <= 0) {
        win = "Yes";
        break;
      }
    } else {
      a -= d;
      if (a <= 0){
        win = "No";
        break;
      }
    }
    turn = 1 - turn;
  }

  cout << win << endl;

  return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();

	out(N*N*N);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int x,n;
    cin >> x >> n;
    vector<bool> p(102,true);
    rep(i,n){
        int t;
        cin >> t;
        p[t]= false;
    }

    int ans = 103;
    rep(i,102){
        if(p[i] && abs(i-x) < abs(ans-x)){
            ans = i;
        }
    }
    cout << ans << endl;

return 0;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  int flag = 0;
  for(int i = A; i <= A*B; i+=A){
	if(i % B == C) flag = 1;
  }
  
  cout << (flag ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main()
{
  char a[27];
  int i, j, n, flag=0;
  //入力
  scanf("%s", &a);
  n = strlen(a);
  //処理
  for(i=0; i<n; i++)
  {
    for(j=0; j<n; j++)
    {
      if(a[i] == a[j] && i != j)
      {
        flag = 1;
      }
    }
  }
  //出力
  if(flag == 0)
  {
    printf("yes\n");
  }
  else
  {
    printf("no\n");
  }
  return 0;
}


Measured memory_bytes: 128
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
dp=[N]*(N+1)
#dp[i];=i個目まで選んで交換したときの最大
C=[B[i]-A[i] for i in range(3)]
for i in range(N):
    dp[i+1]=max(dp[i+1],dp[i])
    for j in range(3):
        if i+1-A[j]>=0:
            dp[i+1]=max(dp[i+1],dp[i+1-A[j]]+C[j])
M=dp[N]
dp=[0]*(M+1)
C=[A[i]-B[i] for i in range(3) if A[i]-B[i]>=0]
C=[]
b=[]
a=[]
for i in range(3):
    if A[i]-B[i]>=0:
        C.append(A[i]-B[i])
        b.append(B[i])
        a.append(A[i])
B=b
A=a
for i in range(M):
    dp[i+1]=max(dp[i+1],dp[i])
    for j in range(len(C)):
        if i+1-B[j]>=0:
            dp[i+1]=max(dp[i+1],dp[i+1-B[j]]+C[j])
print(M+dp[M])


Measured memory_bytes: 231064
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int b[100][100];

int p[4][50][50];

template<int N>
void rotate_cpy(int (*org)[N], int (*dist)[N], int n){
  REP(i,n) REP(j,n)
    dist[n-j-1][i] = org[i][j];
}


int main(){
  int n, m;

  while(scanf("%d%d",&n,&m), n+m){
    int ax = INT_MAX;
    int ay = INT_MAX;

    REP(i,n) REP(j,n) scanf("%d",&b[i][j]);
    REP(i,m) REP(j,m) scanf("%d",&p[0][i][j]);
    REP(i,3) rotate_cpy(p[i], p[i+1], m);

    REP(i,n-m+1) REP(j,n-m+1){
      bool ok[4] = { true, true, true, true };
      int xx[4] = { -1, -1, -1, -1 };
      int yy[4] = { -1, -1, -1, -1 };

      REP(c,4) REP(y,m) REP(x,m) if(ok[c]){
	if(p[c][y][x] == -1) continue;
	if(p[c][y][x] == b[i+y][j+x]){
	  if(xx[c] == -1){
	    xx[c] = j + x;
	    yy[c] = i + y;
	  }
	}else{
	  ok[c] = false;
	}
      }

      if(ok[0] || ok[1] || ok[2] || ok[3]){
	REP(c,4) if(ok[c]){
	  if(ay > yy[c]){
	    ay = yy[c];
	    ax = xx[c];
	  }else if(ay == yy[c] && ax > xx[c]){
	    ay = yy[c];
	    ax = xx[c];
	  }
	}
      }
    }

    if(ax == INT_MAX)
      puts("NA");
    else
      printf("%d %d\n",ax+1,ay+1);
  }

  return 0;
}

Measured memory_bytes: 960
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    int n=s.length(),m=t.length();
    ll dp[n+1][m+1];
    for(int i=0;i<=n;i++){
    	for(int j=0;j<=m;j++){
    		dp[i][j]=i+j;
    	}
    }
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		if(s[i-1]==t[j-1]){
    			dp[i][j]=min(dp[i][j],dp[i-1][j-1]);
    		}
    		dp[i][j]=min(dp[i-1][j-1]+1,min(dp[i][j],min(dp[i-1][j]+1,dp[i][j-1]+1)));
    	}
    }
    cout << dp[n][m] <<endl;
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  int c[500], s[500], f[500];
  for(int i = 0;i < n-1;i++){
    cin >> c[i] >> s[i] >> f[i];
  }

  for(int i = 0;i < n;i++){
    int t = 0;
    for(int j = i;j < n-1;j++){
      if(t < s[j]){
        t = s[j] + c[j];
      }else{
        int tmp = s[j];
        while(tmp < t){
          tmp += f[j];
        }
        t = tmp + c[j];
      }
    }
    cout << t << endl;
  }

  return 0;
}


Measured memory_bytes: 256
/*
Twitter: @NadjaHarold
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

// A - Ice Tea Store
// https://atcoder.jp/contests/agc019/tasks/agc019_a
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, q, s, d, n, w, ans = 0, count = 0;
  string t;
  cin >> q >> h >> s >> d;
  cin >> n;
  h = min(h, 2 * q);
  s = min(s, 2 * h);
  if (2 * s <= d)
  {
    ans = s * n;
  }
  else
  {
    ans = n / 2 * d + (n % 2) * s;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    agc012a()
}

fun agc012a() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }
        .sortedDescending().toLongArray()

    var answer = 0L
    for (i in 1..2 * n step 2) {
        answer += aList[i]
    }

    println(answer)
}


Measured memory_bytes: 93456
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
    }
    if (p > q) {
        swap(p, q);
    }
    lint ans = 0;
    while (p != q) {
        ans++;
        next_permutation(p.begin(), p.end());
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[35]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
	int n;
	cin>>n;
	cout<<a[n-1];

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  ll n, k; cin >> n >> k;
  vector<ll> grid(n);
  for (ll i = 0; i < n; i++) cin >> grid[i];
  map<ll, ll> mapp;
  ll pos = 0, cs, dist = 0, inn;
  while (true) {
    if (mapp.find(pos) != mapp.end()) {
      cs = dist-mapp[pos];
      inn = mapp[pos];
      break;
    }
    if (dist == k) {
      cout << pos + 1 << endl;
      return 0;
    }
    mapp[pos] = dist++;
    pos = grid[pos]-1;
  }
  vector<ll> path;
  for (ll i = 0; i < cs; i++) {
    path.push_back(pos);
    pos = grid[pos]-1;
  }
  cout << path[((k-inn)%cs + cs)%cs] + 1 << endl;
  return 0;
}

Measured memory_bytes: 16764
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="SUN")
	  cout<<7;
	  else if(s=="MON")
	        cout<<6;
	        else if(s=="TUE")
	             cout<<5;
	             else if(s=="WED")
	                  cout<<4;
	                  else if(s=="THU")
	                       cout<<3;
	                       else if(s=="FRI")
	                            cout<<2;
	                            else
	                            cout<<1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> snuke(n);
    for(int i=0;i<k;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int a;
            cin >> a;
            a--;
            snuke[a]++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(snuke[i]==0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
def main():
    a,b,c,d = map(int, input().split())
    while 1:
        if c >= 0:
            c -= b
        if c <= 0:
            print("Yes")
            break
        if  a >= 0:
            a -= d
        if a <= 0:
            print("No")
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 61676
s1=s2=0
n = int(input())
while ( n > 0 ):
    n = n -1
    (a,b)  =  map(str,input().split())

    if (a > b):
        s1 += 3
    elif (b > a):
        s2 += 3
    else:
        s1 += 1
        s2 += 1
print (s1,s2)


Measured memory_bytes: 5596
#N,*S=map(int,open(0).read().split())
N=int(input())
d={}
for i in range(N):
    k=input()
    d[k]= d[k]+1 if k in d else 1
dd=sorted(d.items(),key=lambda x:x[1])  
max_k=max(d,key=d.get)
max_v=d[max_k]
keys=[k for k,v in d.items() if v==max_v]
kk=sorted(keys)
for i in kk:
    print(i)

Measured memory_bytes: 47324
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>

using namespace std;
typedef long long ll;
ll a[3005],ans;
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		ans += a[i] - 1;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    long double r;
    cin >> r;
    long double pi=M_PI;
    cout << setprecision(20) << 2*pi*r ;
}

Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  int n = s.length();
  
  for(int i=0;i<n;i++){
    if(i % 2 == 0)
      cout << s[i];
  }
  
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct edge { 
  ll to; ll d;
  bool operator< (const edge &x) const { return to<x.to; }
};
map<ll, set<edge>> adj;

map<ll, ll> dijkstra(int n=0) {
  auto c = [](const p_ll &x, const p_ll &y){return x.second>y.second;};
  priority_queue<p_ll, vector<p_ll>, decltype(c)> q(c);
  map<ll, ll> result; result[n] = 0; q.push(make_pair(n,0));
  while(q.size()) {
    p_ll now = q.top(); q.pop();
    ll np = now.first, nd = now.second;
    if (nd>result[np]) continue;
    for (auto x: adj[np]) {
      if (result.count(x.to)&&result[x.to]<=result[np]+x.d) continue;
      q.push(make_pair(x.to, result[np]+x.d));
      result[x.to] = result[np]+x.d;
    }
  }
  return result;
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

ll C = pow(10,6)+10;

int main() {
  int N, M; cin >> N >> M;
  rep(i,M) {
    ll p, q, c; cin >> p >> q >> c; p--; q--;
    adj[p*C].insert({p*C+c,1}); adj[p*C+c].insert({p*C,0});
    adj[q*C].insert({q*C+c,1}); adj[q*C+c].insert({q*C,0});
    adj[p*C+c].insert({q*C+c,0}); adj[q*C+c].insert({p*C+c,0});
  }
  map<ll, ll> d = dijkstra();
  // for (auto x: d) cout << x.first << "->" << x.second << " "; cout << endl;
  ll result = d.count((N-1)*C) ? d[(N-1)*C] : -1;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 156012
#include <bits/stdc++.h>
#ifdef BUG
  #include "debug.hpp"
#else
  #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

int main(const int argc, char **argv) {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int a, b;
  cin >> a >> b;
  if (a < b) swap(a, b);
  int val = a--;
  cout << val + max(a, b);
  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
const int MAX_V=100001;
struct edge{int to, cost;};
int V;
vector<edge> G[MAX_V];
int d[MAX_V];
void dijkstra(int s){
    priority_queue<PA, vector<PA>, greater<PA>> que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(PA(0,s));
    while(!que.empty()){
        PA p=que.top(); que.pop();
        int v=p.SE;
        if(d[v]<p.FI) continue;
        FOR(i,0,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(PA(d[e.to],e.to));
            }
        }
    }
}

void add_edge(int s, int e, int c){
    G[s].PB(edge{e,c});
}
int main(){
    int k; cin>>k;
    V=k;
    FOR(i,0,k){
        G[i].PB({(i+1)%k,1});
        G[i].PB({(i*10)%k,0});
    }
    dijkstra(1);
    co(d[0]+1);
}


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

int main(){
    cin >> n;
    if(n%10==3){
        cout << "bon";
    }
    else if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout << "pon";
    }
    else{
        cout << "hon";
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

Int N,M,K;
Int H,W;
Int X,Y,Z,C;

const int MAXN=500005;
vector<Int> A;
vector<int> adj[MAXN];
Int perform(Int x){
    return (x*(x+1))/2LL;
}



int main()
{
    cin>>N>>X>>M;
    vector<long long> pref;
    pref.pb(X);
    long long sum=X;
    vector<int> pos(M,-1);
    pos[X]=0;
    for(Int i=1;i<N;++i){
        X=1LL*(X*X)%M;
        pref.pb(pref.back()+X);
        sum+=X;
        if(pos[X]==-1) pos[X]=i;
        else{
            Int length=i-pos[X];
            Int cycles=max(0LL,(N-i-2)/length);
            if(!cycles) continue;
            sum+=(pref[i]-pref[pos[X]])*cycles;
            i+=length*cycles;
        }
        
    }
    cout<<sum<<"\n";
    
}

Measured memory_bytes: 16416
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
namespace rng { using namespace boost; using namespace boost::range; }
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
constexpr auto color_s_ = "\033[2m\033[33m", color_e_ = "\033[0m";
template<class T> void trace_(const T& v) { cerr << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cerr << "\n"; for (const auto& v : m) { trace_(v); cerr << "\n"; } }
template<class T> void trace_(const char* s, const T& v) { cerr << color_s_ << s << "="; trace_(v); cerr << color_e_ << "\n"; cerr.flush(); }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { cerr << color_s_; for (; *s != ','; ++s) { cerr << *s; } cerr << "="; trace_(v); cerr << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = sx, y = sy;
    for (; x < tx; x++) cout << "R";
    for (; y < ty; y++) cout << "U";
    for (; x > sx; x--) cout << "L";
    for (; y > sy; y--) cout << "D";
    x--; cout << "L";
    for (; y < ty+1; y++) cout << "U";
    for (; x < tx; x++) cout << "R";
    y--; cout << "D";
    x++; cout << "R";
    for (; y > sy-1; y--) cout << "D";
    for (; x > sx; x--) cout << "L";
    y++; cout << "U";
    cout << nl;
}


Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H ==0 and W == 0:
        break
    else:
        if H%2==0:
            for i in range(int(H/2)):
                print("#."*int(W/2)) if W%2==0 else print("#."*int((W-1)/2)+"#")
                print(".#"*int(W/2)) if W%2==0 else print(".#"*int((W-1)/2)+".")
        else:
            for i in range(int((H-1)/2)):
                print("#."*int(W/2)) if W%2==0 else print("#."*int((W-1)/2)+"#")
                print(".#"*int(W/2)) if W%2==0 else print(".#"*int((W-1)/2)+".")
            print("#."*int(W/2)) if W%2==0 else print("#."*int((W-1)/2)+"#")
    print()


Measured memory_bytes: 5620
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    A,V = LI()
    B,W = LI()
    T = NI()

    if A < B:
        if A + V * T >= B + W * T:
            print('YES')
        else:
            print('NO')
    elif A > B:
        if A - V * T <= B - W * T:
            print('YES')
        else:
            print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

    string s;
    cin>>s;
    
    if(s[2] == s[3] && s[4] == s[5]) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g =gcd(a,b);
    return a/g*b;
}
int main(void){
    // Your code here!
    int n;
    long long t[100];
    std::cin >> n;
    long long ans=1LL;
    for (int i = 0; i < n; i++) {
        std::cin >> t[i];
        ans=lcm(ans,t[i]);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int ans1 = a + b;
	int ans2 = a + c;
	int ans3 = b + c;

	cout << min({ ans1,ans2,ans3 }) << endl;
	
}


Measured memory_bytes: 3588
# -*- coding: utf-8 -*-
# 標準入力を取得
N, X, M = list(map(int, input().split()))

# 求解処理


def f(x: int, m: int) -> int:
    return x**2 % m


A = [X]
s = {X}
i = 0
while True:
    A_next = f(A[-1], M)
    if A_next in s:
        i = A.index(A_next)
        break
    else:
        A.append(A_next)
        s.add(A_next)

loop_length = len(A) - i
loop_cnt = (N - i) // loop_length
loop_res = (N - i) % loop_length
ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i: i + loop_res])

# 結果出力
print(ans)


Measured memory_bytes: 13116
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i<N; i++) {
			A[i] = sc.nextInt();
		}
		for(int i=0; i<N; i++) {
			X += (D/A[i]);
			if(D%A[i] !=0) {
				X++;
			}
		}
		System.out.println(X);
	}

}


Measured memory_bytes: 36032
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  for(int i=0; i<N; i++){
    if(vec.at(i)%2==0){
      if((vec.at(i)%3!=0)and(vec.at(i)%5!=0)){
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
  return 0;
}

Measured memory_bytes: 256
from collections import  Counter
n = int(input())
lst = []
for _ in range(n):
    lst.append(input())

C = Counter(lst)
x = max(C.values())
anslst = []
for k,v in C.items():
    if v == x:
        anslst.append(k)
anslst.sort()
for v in anslst:
    print(v)

Measured memory_bytes: 38648
#include<bits/stdc++.h>
using namespace std;
#define P pair<int,int>

int main() {
  int H, W;
  long long INF = 1000000000;
  char a[1005][1005];
  int S[1005][1005];
  queue<P>que;
  int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
	  cin >> a[i][j];
      S[i][j] = INF;
	  if (a[i][j] == '#') {
	  	S[i][j] = 0;
		que.push({ i,j });
      }
	}
  }
  while (que.size()) {
	P p = que.front(); 
    que.pop();
	for(int i = 0; i < 4; i++) {
		int nx = p.first + dx[i], ny = p.second + dy[i];
		if (nx < 0 || nx >= H || ny < 0 || ny >= W)continue;
		if (S[nx][ny] == INF) {
			S[nx][ny] = S[p.first][p.second] + 1;
			que.push({ nx,ny });
		  }
	  }
  }
  int ans = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
  	ans = max(ans, S[i][j]);
    }
  }
  cout << ans;
}


Measured memory_bytes: 13328