akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && (ch != '-')) ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int col[605][605];

void Solve(int n, int k) {
  int t = 0;
  while (!(k % 4)) k >>= 2, ++t;
  for (RI i = 0; i < 2 * n; ++i)
    for (RI j = 0; j < 2 * n; ++j) {
      if (k % 4 == 1) {
        if (((i >> t) + (j >> t)) & 1)
          col[i][j] = 1;
      }
      else
        if ((i >> t) & 1)
          col[i][j] = 1;
    }
  // if t % 2 == 0 then t^2 % 4 = 0
  // if t % 2 == 1 then t^2 % 4 = 1
  // so if k = a^2 + b^2 then k % 4 != 3
}

int main() {

//  FILEIO("a");

  int n, d1, d2; read(n), read(d1), read(d2);
  Solve(n, d1), Solve(n, d2);
  int cnt = 0;
  for (RI i = 0; i < 2 * n && cnt < n * n; ++i)
    for (RI j = 0; j < 2 * n && cnt < n * n; ++j)
      if (!col[i][j])
        printf("%d %d\n", i, j), ++cnt;

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 2304
N,M = map(int,input().split())
A= set(int(input()) for _ in [0]*M)
mod = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
if not (1 in A):dp[1] = 1
for i in range(2,N+1):
    dp[i] = (dp[i-1]+dp[i-2])%mod
    if i in A:dp[i]=0
print(dp[N])

Measured memory_bytes: 12652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,r;
	cin>>n>>r;
	cout<<floor(log(n)/log(r)) + 1;
}

Measured memory_bytes: 256
#include<stdio.h>
long long int prime(long long int a);
int main()
{
    long long int X,check;
    scanf("%llu",&X);
    check=prime(X);
    while(check!=1)
    {
         X++;
         check=prime(X);
    }
    printf("%llu",X);
    return 0;

}
long long int prime(long long int a)
{
    long long int i,count=0;
    for(i=2;i<=a/2;i++)
    {
        if(a%i==0)
        {
            count+=1;
            break;
        }
        else
            count=0;
    }
    if(count==1)
        return 0;
    else
        return 1;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define Rep(i, N) for(int i = 0; i < N; i++)

char ch[] = {'m', 'c', 'x', 'i'};
int value[] = {1000, 100, 10, 1};


int to_val(string s) {
  
  int ret = 0;
  Rep(i, s.size()) {
    int v = 1;
    if('2' <= s[i] && s[i] <= '9') {
      v = s[i] - '0', i++;
    }
    Rep(j, 4) {
      if(s[i] == ch[j]) ret += value[j] * v;
    }
  }

  return ret;
}
  
signed main()
{
  int N;
  
  cin >> N;
  Rep(i, N) {
    string a, b;

    cin >> a >> b;
    
    int val = to_val(a) + to_val(b);
    
    string ans;
    
    Rep(j, 4) {
      if(val >= value[j]) {
	if(val >= value[j] * 2) {
	  ans += '0' + val / value[j];
	}
	ans += ch[j];
	val -= (val / value[j]) * value[j];
      }
    }
    cout << ans << endl;
  }

  return 0;
}
    

Measured memory_bytes: 3152
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int X;
    cin >> X;
    if (X == 3 || X==5 || X==7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const long long MAX = 119;
const long long MIN = -118;

ll fact(ll *num){
  ll sum = 1ll;
  rep(_,5) sum = sum * (*num);
  return sum;
}

int main() {
  ll X;
  cin >> X;
  for(ll a = MIN;a <= MAX;a++){
    for(ll b = MIN;b <= MAX;b++){
      if(fact(&a)-fact(&b)==X){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3636
X = int(input())
# = str(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

if X >= 1800:
    print(1)

elif X >= 1600:
    print(2)
elif X >= 1400:
    print(3)
elif X >= 1200:
    print(4)
elif X >= 1000:
    print(5)
elif X >= 800:
    print(6)
elif X >= 600:
    print(7)
else:
    print(8)


Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[5],s,i;
	for (i=1;i<=3;i++) cin>>a[i];
	sort (a+1,a+3+1);
	s=s+a[1]+a[2];
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
	int house[4][3][10] = {0};
	int b, f, r, v;
	int n, i, j, m;

	
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		house[b-1][f-1][r-1] += v;		
	}



	for(i=0; i<4; i++){
		for(j=0; j<3; j++){
			for(m=0; m<10; m++){
		    printf(" %d",house[i][j][m]);
		    }
		    printf("\n");
		}
		if(i == 3) break;
	 	printf("####################\n");
	}

	return 0;
}

Measured memory_bytes: 612
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int k = sc.nextInt();
		int h;
        int count = 0;
        for (int i=0; i<n; i++) {
            if (sc.nextInt() >= k) {
                count++;
            }
        }
        System.out.print(count);
    }
}

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

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

const double PI = acos(-1);
const double EPS = 1e-10;
int sgn(double d) { return d > EPS ? 1 : d < -EPS ? -1 : 0; }

struct Point {
  double x, y;
  Point() {}
  Point (const double& x, const double& y) : x(x), y(y) {}
  Point& operator += (const Point& other) { x += other.x; y += other.y; return *this; }
  Point& operator -= (const Point& other) { x -= other.x; y -= other.y; return *this; }
  Point& operator *= (const double& factor) { x *= factor; y *= factor; return *this; }
  Point& operator /= (const double& factor) { x /= factor; y /= factor; return *this; }
};
using Vector = Point;
using Polygon = vector<Point>;

Point operator + (const Point&lhs, const Point& rhs) { return Point(lhs.x + rhs.x, lhs.y + rhs.y); }
Point operator - (const Point& lhs, const Point& rhs) { return Point(lhs.x - rhs.x, lhs.y - rhs.y); }
Point operator * (const Point& lhs, const double& factor) { return Point(lhs.x * factor, lhs.y * factor); }
Point operator * (const double& factor, const Point& rhs) { return Point(factor * rhs.x, factor * rhs.y); }
Point operator / (const Point& lhs, const double& factor) { return Point(lhs.x / factor, lhs.y / factor); }
double operator * (const Point& lhs, const Point& rhs) { return lhs.x * rhs.x + lhs.y * rhs.y; }
double operator ^ (const Point& lhs, const Point& rhs) { return lhs.x * rhs.y - lhs.y * rhs.x; }
bool operator == (const Point& lhs, const Point& rhs) { return sgn(lhs.x - rhs.x) == 0 && sgn(lhs.y - rhs.y) == 0; }
bool operator != (const Point& lhs, const Point& rhs) { return !(lhs == rhs); }
bool operator < (const Point& lhs, const Point& rhs) { return sgn(lhs.x - rhs.x) ? lhs.x < rhs.x : lhs.y < rhs.y; }
bool operator > (const Point& lhs, const Point& rhs) { return rhs < lhs; }
bool operator <= (const Point& lhs, const Point& rhs) { return !(lhs > rhs); }
bool operator >= (const Point& lhs, const Point& rhs) { return !(lhs < rhs); }
istream& operator >> (istream& is, Point& point) { return is >> point.x >> point.y; }
ostream& operator << (ostream& os, Point& point) { return os << "(" << point.x << "," << point.y << ")"; }
double norm(const Point& point) { return point.x * point.x + point.y * point.y; }
double abs(const Point& point) { return sqrt(norm(point)); }
double arg(const Point& point) { return atan2(point.y, point.x); }
Point polar(const double& a, const double& r) { return Point(cos(r) * a, sin(r) * a); }
bool sort_x(Point lhs, Point rhs) { return sgn(lhs.x - rhs.x) ? lhs.x < rhs.x : lhs.y < rhs.y; }
bool sort_y(Point lhs, Point rhs) { return sgn(lhs.y - rhs.y) ? lhs.y < rhs.y : lhs.x < rhs.x; }

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  Point p(0, 0);
  int d, a;
  double s = PI / 2;
  char c;
  while (cin >> d >> c >> a) {
    if (d == 0 && a == 0) break;
    p += polar(d, s);
    s -= a * PI / 180;
  }
  cout << (int)p.x << endl;
  cout << (int)p.y << endl;

  return 0;
}


Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double N;
  cin >> N;
  int n = N;
  double ans;
  if((n % 2) == 0){
    cout << 0.5 << endl;
  } else {
    ans = ((N + 1) / 2) / N;
    cout << ans << endl;
  }
  return 0;
}      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=1000000007;
int a(int A,int B){
  if(B==0)
    return 1;
  if(B%2==1)
    return a(A,B-1)*A%M;
  int C=a(A,B/2);
  return C*C%M;
}
int b(int A,int B){
  int C=1;
  for(int i=A;i<=B;i++)
    C=C*i%M;
  return C;
}
signed main(){
  int X,Y;
  cin>>X>>Y;
  if((X+Y)%3!=0 || X*2<Y || Y*2<X){
    puts("0");
    return 0;
  }
  int A=X-(X+Y)/3,B=Y-(X+Y)/3;
  cout<<b(B+1,A+B)*a(b(1,A)%M,M-2)%M<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    int a,b,t;
    cin>>a>>b>>t;

    cout<<(t/a)*b<<endl;

    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	string s;
	cin>>n>>s;
	
	for(int i=0;i<(int)s.size();i++){
		int t = s[i]-'A';
		t += n;
		t %= 26;
		s[i] = 'A' + t;
	}
	
	cout<<s;
	
	return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int plug = 1;
		int tap = 0;
		while (plug < b) {
			plug += a - 1;
			tap++;
		}
		
		System.out.println(tap);
		
		sc.close();
	}
}


Measured memory_bytes: 23252
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n");
  const [n, k] = lines.shift().split(' ').map(Number);
  const w = lines.map(Number);

  const canAllStack = (p) => {
    let cnt = 0, sum = 0;
    for (let i = 0; i < k; i++) {
      for (sum = 0; sum + w[cnt] <= p;) {
        sum += w[cnt++];
        if (cnt === n) return n;
      }
    }
    return cnt;
  };

  let mid, left = 0, right = 1e9;
  while (right - left > 1) {
    mid = (right + left) / 2;
    if (canAllStack(mid) >= n) right = mid;
    else left = mid;
  }
  console.log(Math.floor(right));
})();



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

int t_,x_,y_;
int t=0,x=0,y=0;

bool can(int t,int x,int y){
  return abs(x)+abs(y)<=t && (t-x-y)%2==0;
}

int main(){
  bool ans=true;
  int N;
  cin >> N;
  for (int i=0;i<N;i++){
    t_=t;
    x_=x;
    y_=y;
    cin >> t >> x >> y;
    if(!can(t-t_,x-x_,y-y_)) ans = false;
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

ll solve() {
    ll K;
    cin >> K;
    ll n = 50, r = K % n;
    vector<ll> a(n);
    for ( int i = 0; i < n; i++ ) {
        a[i] = n - 1 + K / n;
    }
    for ( int i = 0; i < n; i++ ) {
        if ( i < r ) {
            a[i] += n - r + 1;
        } else {
            a[i] += -r;
        }
    }
    cout << n << "\n";
    for ( int i = 0; i < n; i++ ) {
        cout << a[i] << " ";
    }
    cout << "\n";
    return 0;
}

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

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc122/tasks/abc122_b


def is_acgt(c):
    acgt = ['A', 'C', 'G', 'T']

    return c in acgt


if __name__ == "__main__":
    S = input()

    result = 0
    tmp_result = 0
    for c in S:
        if (is_acgt(c)):
            tmp_result += 1
            result = max(result, tmp_result)
        else:
            tmp_result = 0

    print(result)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};


ll s2int(string a, ll& l, ll& r){
    string sl, sr;
    ll n = a.size();
    ll res = 0;
    rep(i, 0, n) {
        if(a[i] == '.') {
            sr = a.substr(i+1, n-i-1);
            res = n - i - 1;
            break;
        }else{
            sl.push_back(a[i]);
        }
    }
    reverse(ALL(sl));
    reverse(ALL(sr));
    ll pw = 1;
    l = 0, r = 0;
    rep(i, 0, sl.size()) {
        l += pw * (sl[i] - '0');
        pw *= 10;
    }
    pw = 1;
    rep(i, 0, sr.size()) {
        r += pw * (sr[i] - '0');
        pw *= 10;
    }
    if(r == 0) res = 0;
    return res;
}

ll factorize(ll n, ll d){
    ll res = 0;
    while(n % d == 0) {
        res++;
        n /= d;
    }
    return res;
}

int main(){

    // input
    ll n;
    cin >> n;
    VS a(n);
    rep(i, 0, n) cin >> a[i];
    
    // string2int
    VL l(n), r(n), s(n);
    rep(i, 0, n) s[i] = s2int(a[i], l[i], r[i]);

    // debug
    //rep(i, 0, n) cerr << s[i] << " " << l[i] << " " << r[i] << endl;

    // factorize
    VL x(n), y(n), p(n);
    rep(i, 0, n) {
        p[i] = l[i] * pow(10LL, s[i]) + r[i];
        x[i] = factorize(p[i], 5);
        y[i] = factorize(p[i], 2);
    }    

    // debug
    //rep(i, 0, n) cerr << p[i] << " " << x[i] << " " << y[i] << endl;

    // ans search
    VVL t(50, VL(100, 0));
    ll ans = 0;
    rep(j, 0, n) {
        // update ans
        rep(i, -(x[j] - s[j]), 25) {
            rep(k, -(y[j] - s[j]), 50) {
                ll ri = i + 25;
                ll rk = k + 50;
                /*
                if(t[ri][rk] > 0) {
                    cerr << a[j] << "(" << ri << "," << rk << ")" << endl;
                }
                */
                ans += t[ri][rk];
            }
        }
        // update t
        t[x[j]-s[j]+25][y[j]-s[j]+50]++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int dp[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) dp[i] = i;
    
    for (int i = 0; i < n; i++) {
        for (int j = 6; i + j <= n; j *= 6) {
            dp[i + j] = min(dp[i + j], dp[i] + 1);
        }

        for (int j = 9; i + j <= n; j *= 9) {
            dp[i + j] = min(dp[i + j], dp[i] + 1);
        }
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF 1000000000LL
using namespace std;
typedef long long ll;

ll N, MA, MB;
vector<ll> A[2], B[2], C[2];
ll dp[2][201][201];

int main(void) {
  cin >> N >> MA >> MB;
  REP(i, 0, N) {
    ll a, b, c;
    cin >> a >> b >> c;
    A[i % 2].push_back(a);
    B[i % 2].push_back(b);
    C[i % 2].push_back(c);
  }

  if(N == 1) {
    cout << (MA * B[0][0] == MB * A[0][0] ? C[0][0] : -1) << endl;
  } else {
    REP(p, 0, 2) {
      ll n = A[p].size();
      REP(i, 0, 201) REP(j, 0, 201) dp[p][i][j] = INF;
      REP(i, 0, 1 << n) {
        ll a = 0, b = 0, c = 0;
        REP(j, 0, n) if(i & (1 << j)) a += A[p][j], b += B[p][j], c += C[p][j];
        dp[p][a][b] = min(dp[p][a][b], c);
      }
    }
    ll ans = INF;
    REP(i, 0, 201) REP(j, 0, 201) REP(k, 0, 201) if((i + k) % MA == 0) {
      ll l = MB * ((i + k) / MA) - j;
      if(l > 200 || dp[0][i][j] + dp[1][k][l] == 0) continue;
      ans = min(ans, dp[0][i][j] + dp[1][k][l]);
    }
    cout << (ans != INF ? ans : -1) << endl;
  }
}


Measured memory_bytes: 896
#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 <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef complex<double> P;

//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())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

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

char bits[40000];
LL primes[40000], n_primes; 
char str[]="CP";

void sieve(){
	int i, j;
	memset(bits, 1, 40000);
	bits[0] = bits[1] = 0;
	for (i = 0; i < 200; i++)
		if (bits[i])
			for (j = i * i; j < 40000; j += i)
				bits[j] = 0;
	for (i = j = 0; i < 40000; i++)	
		if (bits[i]) primes[j++] = i;
	n_primes = j;
}

int main(){
	sieve();
	int a,b,n;
	cin>>n;
	REP(i,n){
		cin>>a>>b;
		if (a < 0) a = -a;
		if (b < 0) b = -b;

		if (a == 0)cout << str[(b % 4 == 3 && bits[b])] << endl;
		else if (b == 0)cout << str[(a % 4 == 3 && bits[a])] << endl;
		else cout<<str[(bits[a*a+b*b]!=0)]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    
    int n, a;
    
    cin >> n >> a;
    
    if(n%500<=a){
    
    cout << "Yes" << endl; 
    
    }else{
    
    cout << "No" << endl;
    
    }
    
    
    
    
    
    
    

    
/////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;
char s[100];
int main ()
{
    ll n,tle=0,ac=0,wa=0,re=0,i;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%s",s);
        if(s[0]=='A')
            ac++;
        if(s[0]=='T')
            tle++;
        if(s[0]=='W')
            wa++;
        if(s[0]=='R')
            re++;
    }
    printf("AC x %lld\nWA x %lld\nTLE x %lld\nRE x %lld\n",ac,wa,tle,re);
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int evens[N];
  for(int i=0; i<N; i++)
    cin >> evens[i];
  int count=-1;
  int judgh = N;
  while(judgh==N){
  count++;
  judgh=0;
  for(int i=0; i<N; i++){
    if(evens[i]%2==0)
    	judgh++;
    evens[i]=evens[i]/2;
  }
  }
  cout << count << endl;
}

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

template <class T, class Op = multiplies<T>>
T power(T a, long long n, Op op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

unsigned mod = 2;
struct mint {
  using m = mint;
  unsigned v;
  mint(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m b) { if ((v += b.v) >= mod) v -= mod; return *this; }
  m& operator-=(m b) { if (v < b.v) v += mod; v -= b.v; return *this; }
  m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }
  m& operator/=(m b) { return *this *= power(b, mod - 2); }
  friend m operator+(m a, m b) { return a += b; }
  friend m operator-(m a, m b) { return a -= b; }
  friend m operator*(m a, m b) { return a *= b; }
  friend m operator/(m a, m b) { return a /= b; }
  friend bool operator==(m a, m b) { return a.v == b.v; }
  friend string to_string(m a) { return to_string(a.v); }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n >> mod;
  string s;
  cin >> s;
  if (mod == 2 or mod == 5) {
    long long res = 0;
    for (int i = 0; i < n; ++i) {
      if (mint(s[i] - '0') == 0) {
        res += i + 1;
      }
    }
    cout << res << '\n';
    exit(0);
  }
  vector<mint> p10(n + 1);
  for (int i = 0; i <= n; ++i) {
    p10[i] = i ? 10 * p10[i - 1] : 1;
  }
  vector<mint> ip10(n + 1);
  ip10[n] = 1 / p10[n];
  for (int i = n; i--; ) {
    ip10[i] = ip10[i + 1] * 10;
  }
  long long res = 0;
  auto rec = [&](auto&& self, int l, int r) -> void {
    if (r - l == 1) {
      res += mint(s[l] - '0') == 0;
      return;
    }
    int m = (l + r) / 2;
    self(self, l, m);
    self(self, m, r);
    map<int, int> mp;
    mint t;
    for (int i = m; i-- > l; ) {
      t += (s[i] - '0') * p10[m - i - 1];
      ++mp[t.v];
    }
    t = 0;
    for (int i = m; i < r; ++i) {
      t *= 10;
      t += s[i] - '0';
      res += mp[(-t * ip10[i - m + 1]).v];
    }
  };
  rec(rec, 0, n);
  cout << res << '\n';
}


Measured memory_bytes: 2452
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from fractions import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-2],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))

Measured memory_bytes: 80660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        int a,b,ans=0;
        FastIO fastIO = new FastIO();

        a=fastIO.readInt();
        b=fastIO.readInt();
        --b;
        while(b>0)
        {
            b-=a;
            b+=1;
            ++ans;
        }
        System.out.println(ans);
    }

    private static class FastIO
    {
        private StringTokenizer stringTokenizer;
        private BufferedReader bufferedReader;

        public FastIO()
        {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            stringTokenizer = null;
        }

        public String read()
        {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens())
            {
                try
                {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                }
                catch (IOException e)
                {
                    throw new RuntimeException(e);
                }
            }
            return stringTokenizer.nextToken();
        }

        public int readInt()
        {
            return Integer.parseInt(read());
        }

        public long readLong()
        {
            return Long.parseLong(read());
        }
    }
}

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

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);

		char[] c = sc.next().toCharArray();

		Map<Character, Integer> count = new HashMap<>();

		for (char key : c) {
			if (!count.containsKey(key)) {
				count.put(key, 1);
			} else {
				int value = count.get(key);
				count.put(key, value + 1);
			}
		}

		for (char key : count.keySet()) {
			int value = count.get(key);
			if (value % 2 != 0) {
				System.out.println("No");
				return;
			}
		}

		System.out.println("Yes");

	}

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

}


Measured memory_bytes: 9424
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX + 1];
  int n,i,j;
  scanf("%d",&n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for(i = 0; i <= VMAX; i++)
    C[i] = 0;

  for(i = 0; i < n; i++){
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }

  for(i = 1; i <= VMAX; i++)
    C[i] = C[i] + C[i-1];

  for(j = 1; j <= n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i <= n; i++){
    if(i > 1)
      printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 9560
def countScc(s, c):
    res = 0
    if(2*s <= c):
        res = s
        c = c - 2*s
        res = res + c / 4
    else:
        res = c / 2
    return res

try:
    while True:  
        s, c = raw_input().strip().upper().split()
        print countScc(int(s), int(c))
except EOFError:
    pass

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;

    int N = S.length();
    int count = 0;

    for (int i = 0; i < N; i++){
        int tmp = 0;
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C'){
            while (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C'){
                tmp++;
                i++;
            }
            count = max(count, tmp);
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define REP(i,p,n) for(int i=p;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define INF 1e8

using namespace std;

const int MAX_V = 100;
int d[MAX_V][MAX_V];
int ans[MAX_V][MAX_V] = { 0 };

void setCost(int d[MAX_V][MAX_V], int s, int e, int cost){
    d[s][e] = d[e][s] = cost;
}

struct EdgeVal
{
    int a;
    int b;
    int c;
};

int main()
{
    int V, M;
    cin >> V >> M;

    // 辺のコスト初期化
    rep(i, V){
        rep(j, V){
            if (i == j) d[i][j] = 0;
            else d[i][j] = INF;
        }
    }

    int a, b, c;
    vector< EdgeVal > edge;
    rep(i, M)
    {
        cin >> a >> b >> c;
        setCost(d, a-1, b-1, c); 
        EdgeVal val = {a-1, b-1, c};
        edge.push_back(val);
    }

    // Warshall Floyd
    rep(k, V){
        rep(i, V){
            rep(j, V){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    // 各辺が最短経路に含まれているか確認
    int count = 0;
    rep(i, edge.size())
    {
        bool isFind = false;
        rep(j, V) {
            rep(k, V) {
                //if(j == k || j == edge[i].first || k == edge[i].second){ continue; }
                if(d[j][k] == d[j][edge[i].a] + edge[i].c + d[edge[i].b][k])
                {
                    //printf("%d %d j:%d k:%d\n", edge[i].a, edge[i].b, j, k);
                    isFind = true;
                    break;
                }
            }
            if(isFind){ break; }
        }
        if(isFind){ count++; }
    }
    cout << M - count << endl;

    return 0;
}


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

const int INF = (1 << 30) - 1;

int main()
{
	int N;
	int dp[100005];
	cin >> N;

	fill_n(dp, 100005, INF);
	
	dp[0] = 0;
	for ( int i = 0; i < N; i++ ) {
		dp[i + 1] = min(dp[i + 1], dp[i] + 1);
		for ( int nine = 9; nine <= N - i; nine *= 9 ) {
			dp[i + nine] = min(dp[i + nine], dp[i] + 1);
		}
		for ( int six = 6; six <= N - i; six *= 6 ) {
			dp[i + six] = min(dp[i + six], dp[i] + 1);
		}
	}
	cout << dp[N] << endl;
	return ( 0 );
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 2005

using namespace std;

int n, x, y;
int head[N], nex[N << 1], to[N << 1], ecnt;
int dist[N][N], cnt[N];

int que[N];
void bfs(int s) {
	int hd = 0, tl = -1;
	que[++tl] = s, dist[s][s] = 0;
	while(hd <= tl) {
		int u = que[hd++];
		if(s < u) ++cnt[dist[s][u]];
		for(int i = head[u], v; i; i = nex[i]) {
			v = to[i];
			if(dist[s][v] > dist[s][u] + 1) {
				dist[s][v] = dist[s][u] + 1;
				que[++tl] = v;
			}
		}
	}
}

inline void addE(int u, int v) {
	to[++ecnt] = v;
	nex[ecnt] = head[u], head[u] = ecnt;
}

int main() {
	scanf("%d %d %d", &n, &x, &y);
	addE(x, y), addE(y, x);
	for(int i = 1; i < n; ++i)
		addE(i, i + 1), addE(i + 1, i);
	
	memset(dist, 32, sizeof dist);
	for(int i = 1; i <= n; ++i)
		bfs(i);
	
	for(int i = 1; i < n; ++i)
		printf("%d\n", cnt[i]);
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long i, sum=0;
    for(i=1; i<=n;i++){
        if((i%3!=0)&&(i%5!=0)) sum += i;
    }
    cout << sum << endl;
    return 0;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{N * (N + 1) * (N + 2) / 6};
    for(unsigned long i{1}, u, v; i < N; ++i){
        cin >> u >> v;
        if(u > v)swap(u, v);
        ans -= u * (N - v + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
function main(input) {
  input = input.split('\n');
  var n = Number(input[0]);
  var seq = input[1];
  var change = 0;
  for (var i = 1; i < n; i++) {
    if (seq[i] === 'E') change += 1;
  }
  var minChange = change;
  var prev = seq[0];
  for (i = 1; i < n; i++) {
    if (prev === 'W') {
      change += 1;
    }
    if (seq[i] === 'E') {
      change -= 1;
    }
    minChange = Math.min(change, minChange);
    prev = seq[i];
  }
  console.log(minChange);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
 int N;
 cin >> N;
 if ( (N/100)%10==(N/10)%10 && ( N/1000==(N/100)%10 || (N/10)%10==N%1000) ) {
   cout << "Yes" << endl;
 }
 else {
   cout << "No" << endl;
 }
}

Measured memory_bytes: 256
N,Eat = map(int,input().split())
cakes_ls = [[0,0,0] for _ in range(N)]
for i in range(N):
    cakes_ls[i] = list(map(int,input().split()))

Patterns = 2**3
ans = 0
for i in range(Patterns):
    mult = [1] * 3
    for j in range(3):
        if (i>>j) & 1:
            mult[j] = -1
    
    value_ls = [0] * N
    for n in range(N):
        target = cakes_ls[n]
        value = 0
        for x in range(3):
            value += target[x] * mult[x]
        value_ls[n] = value
    value_ls.sort(reverse=True)
    #print(value_ls)
    #print(mult,sum(value_ls[:Eat]))
    ans = max(ans,sum(value_ls[:Eat]))
print(ans)

Measured memory_bytes: 9368
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
import math

DEG60 = math.pi/3

def repl_edge(n, edges):
    # print('n=',n, 'edges=', len(edges))
    if n == 0:
        return edges
    new_list = list()
    for edge in edges:  # single tupple
        p1 = edge[0]
        p2 = edge[1]
        p_angle = edge[2]
        s = ((p1[0]*2+p2[0])/3, (p1[1]*2+p2[1])/3)
        t = ((p1[0]+p2[0]*2)/3, (p1[1]+p2[1]*2)/3)
        r = abs((t[0]-s[0])**2 + (t[1]-s[1])**2) ** 0.5
        angle = p_angle + DEG60
        u = (s[0] + math.cos(angle)*r, s[1] + math.sin(angle)*r)
        # print('r=', r, 'u=', u, 'angle=', angle)
        new_list += [(p1, s, p_angle), (s, u, p_angle+DEG60), \
                    (u, t, p_angle-DEG60), (t, p2, p_angle)]

    new_list = repl_edge(n-1, new_list)
    return new_list


n = int(sys.stdin.readline())
p1 = (0.0, 0.0)
p2 = (100.0, 0.0)
edges = [(p1, p2, 0.0)]

edges = repl_edge(n, edges)
for edge in edges:
    print(round(edge[0][0],6), round(edge[0][1],6))
print(round(edges[-1][1][0],6), round(edges[-1][1][1],6))



Measured memory_bytes: 6860
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,maxv=0,sum=0;
	cin>>n;
	int a[n];
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		if (a[i]>maxv)
		{
			maxv=a[i];
		}
	}
	cout<<sum-maxv+maxv/2;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,besar1,besar2,nilai1=-1,nilai2=-1,x;
	vector<int> v;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>x;
		v.push_back(x);
	}
	sort(v.begin(),v.end());
	besar1=1;
	besar2=0;
	for (int i=v.size()-1; i>=0; i--){
		if (besar1==2 and besar2==2) break;
		if (besar1==2){
			if (besar2==1 and nilai2==v[i]) ++besar2;
			else{
				besar2 = 1;
				nilai2=v[i];	
			}
		}
		else
		if (besar1==1 and nilai1==v[i]){
			++besar1;
		} else{
			besar1=1; nilai1=v[i];
		}
	}
	//cout<<nilai2<<" "<<besar2<<endl;
	if (besar1==2 and besar2==2)
	cout<<(long long)nilai1*nilai2<<"\n";
	else cout<<0<<"\n";
}

Measured memory_bytes: 892
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int total = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			total += Math.max(0, arr[i] - a);
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 23764
N = int(input())
used = [False]*(N+1)
used[1] = True
a = [None]*(N+1)
for i in range(1,N+1):
    x = int(input())
    a[i] = x
x = a[1]
cnt = 1
while True:
    if used[x] == True:
        print(-1)
        break
    if x == 2:
        print(cnt)
        break
    used[x] = True
    x = a[x]
    cnt += 1


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll a, b; cin >> a >> b;
    ll ans = 0;
    ll left = a, right = b;
    if(a %2 == 1){
        ans ^= a;
        left = a + 1;
    }
    if(b %2 == 0){
        ans ^= b;
        right = b - 1;
    }
    ll num = (right - left + 1) / 2;
    ans ^= (num %2);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<cstdlib>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define x first
#define y second

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	
	const double PI = acos(-1);
	
	int N;
	double ans = 0;
	vector<pair<int,int>> in;
	
	cin>>N;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].x>>in[i].y;
	}
	
	for(int a = 0; a < 10000; a++){
		 double an = a/10000.0*(2*PI);
		 double dx = cos(an), dy = sin(an), nx = 0, ny = 0;
		
		for(int i = 0; i < N; i++){
			if(dx*in[i].x + dy*in[i].y >= 0){
				nx += in[i].x;
				ny += in[i].y;
			}
		}
		
		ans = max(ans, sqrt(nx*nx + ny*ny));
	}
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#define NMAX 100

int main(void){

  int i,j,N,inp[NMAX],temp,cnt = 0;
  scanf("%d",&N);
  for(i = 0;i < N;i++){
    scanf("%d",&inp[i]);
  }

  for(i = 0;i < N;i++){
    for(j = N - 1;j >= i + 1;j--){
      if(inp[j] < inp[j - 1]){
	temp = inp[j];
	inp[j] = inp[j - 1];
	inp[j - 1] = temp;
	cnt++;
      }
    }
  }
  for(i = 0;i < N;i++){
    if(i == N - 1){
      printf("%d",inp[i]);
    }else{
      printf("%d ",inp[i]);
	}
  }
  printf("\n%d\n",cnt);
  
  return 0;
}



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

signed main(){
    int n , a[100005] , ans;
    cin >> n;
    for(int i=0 ;i<n ;i++ ){
        cin >> a[i];
    }
    
    sort(a,a+n);
    a[n] = 0 , ans = n;
    
    for(int i=0 ;i<n-1 ;i++ ){
        if(max(a[ans] , a[n-1]-a[ans]) >= max(a[i] , a[n-1]-a[i]) ){
            ans = i;
        }
    }
    
    cout << a[n-1] << ' ' << a[ans] << endl;
    return(0);
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    if (a < b && b < c) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 2068
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int64_t get_int3(int64_t *a1, int64_t *a2, int64_t *a3) {
  scanf("%lld %lld %lld", a1, a2, a3);
  return 0;
}

int main(void) {
    int64_t a, b, c;
    get_int3(&a, &b, &c);
    // a + 2*sqrt(a*b) + b < c
    // 2*sqrt(a*b) < c-a-b
    int64_t right = c-a-b;
    int flag;
    if(right<=0) {
        flag = 0;
    } else {
        flag = (right*right-a*b*4)>0;
    }
    printf("%s\n", flag ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n-1; i++) {
        cin >> c[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += b[i];
    }
    for (int i = 0; i < n-1; i++) {
        if (a[i+1]-a[i] == 1) {
            ans += c[a[i]-1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long int town[300000],i,start,en,ans,n,k,check[300000],cnt;
    cin >>n>>k;
    cnt=0;
    for(i=1;i<=n;i++)
    {
        cin>>town[i];
        check[i]=0;
    }
    ans=town[1];
    k=k-1;
    start=0;
    while(k--)
    {

        ans=town[ans];
        if(start==1)cnt++;
        else if(check[ans]==1&&start==0)
        {
            start=1;
        }
        if(check[ans]==2&&start==1)
        {
            en=cnt;
            start=2;
            if(k>en)
            {
               k%=en;
            }
           // cout <<k <<endl;
        }

        check[ans]++;
    }

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


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

int main(){
  ll n,p; cin>>n>>p;
  vector<ll> num(1001000,0);
  if(n==1){
    cout<<p<<endl;
    return 0;
  }if(p==1){
    cout<<1<<endl;
    return 0;
  }
  ll ans=1;
  if(p%2==0){
    while(p%2==0){
      p/=2;
      num[2]++;
    }
    if(num[2]/n>0) ans*=pow(2,num[2]/n);
  }
  for(ll x=3;x*x<=p;x+=2){
    int i=int(x);
    while(p%x==0){
      p/=x;
      num[i]++;
    }
    if(num[i]/n>0) ans*=pow(x,num[i]/n);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(b-a>x) cout<<"dangerous"<<endl;
    if(a>=b) cout<<"delicious"<<endl;
    if(b>a&&b-a<=x) cout<<"safe"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static int S;
    static void INPUT()
    {
        S = NextInt();
    }
    static void OUT()
    {
        var ans = 0L;
        for (var a = 1; a <= S; a++)
            for (var b = 1; b<= S; b++)
                for (var c = 1; c <= S; c++)
                {
                    ans += GCD(GCD(a, b), c);
                }

        Console.WriteLine(ans);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{        
    /// <summary>
    /// 最大公約数
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    /// <returns></returns>
    public static long GCD(long a, long b)
    {
        if (b == 0) return a;
        return GCD(b, a % b);
    }
}




Measured memory_bytes: 17764
#include <iostream>

using namespace std;

const int num = 39;

int main()
{
    int inp, cal;

    while (cin >> inp) {
        cal = inp % num;
        if (cal == 0)
            cal = num;

        cout << "3C";
        if (cal / 10 == 0)
            cout << "0";
        cout << cal << endl;
    }

    return 0;
}

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

vector<int> to[10];
int ans = 0;
const int nmax = 8;

void dfs(int v, int n, bool visited[nmax]) {
  visited[v]=1;
  bool all=1;
  rep(i,n){
    if(visited[i]==0)all=0;
  }
  ans += all;
  for (int u : to[v]) {
    if (visited[u]==1) continue;
    dfs(u,n,visited);
  }
  visited[v]=0;
}

int main() {
  int n,m;
  cin >> n >> m;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  bool visited[nmax];
  dfs(0,n,visited);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		String out;
		
		if (a > b) {
			out = "a > b";
		} else if (a < b) {
			out = "a < b";
		} else {
			out = "a == b";
		}
		System.out.println(out);
	}	
}

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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for ( int64_t i = 0; i < N; ++i){
        cin >> A.at(i);
    }
    
    vector<int64_t> S(N);
    map<int64_t,int64_t> D;
    for ( int64_t i = 0; i < N; ++i){
        S.at(i) = A.at(i) + i ;
        D[A.at(i) - i] = D[A.at(i) - i] + 1;
    }
    
    int64_t res = 0;
    for ( int64_t i = 0; i < N; ++i){
        int64_t X;
        X = - S.at(i);
        int64_t cnt;
        cnt = D[X];
        if ( X == A.at(i) - i ){
            cnt = cnt - 1;
        }
        res = res + cnt;
    }
    
    
    cout << res << endl;
    return 0;
}


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

using PP = pair<int, int>;
const int INF = 1e9;
int h, w;
string s[50];

const int di[] = {1, 0, -1, 0};
const int dj[] = {0, 1, 0, -1};

int dist[50][50];
int BFS() {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      dist[i][j] = INF;
    }
  }
  
  queue<pair<int, PP>> Q;
  Q.push(make_pair(0, PP(0, 0)));
  while (!Q.empty()) {
    auto q = Q.front(); Q.pop();
    int d = q.first;
    int i = q.second.first;
    int j = q.second.second;
    
    if (i < 0 || i >= h) continue;
    if (j < 0 || j >= w) continue;
    if (s[i][j] == '#') continue;
    if (dist[i][j] != INF) continue;
    dist[i][j] = d;
    
    for (int k = 0; k < 4; ++k) {
      int ni = i + di[k];
      int nj = j + dj[k];
      Q.push(make_pair(d + 1, PP(ni, nj)));
    }
  }
  return dist[h - 1][w - 1];
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }
  int dist = BFS();
  if (dist == INF) {
    cout << -1 << endl; 
  } else {
    int cnt = 0;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (s[i][j] == '.') ++cnt;
      }
    }
    cout << cnt - dist - 1 << endl;
  }
}


Measured memory_bytes: 256
H, W = map(int, input().split())

def div_3(H, W):
    w = W // 3
    if w == 0:
        return 10000000000
    if W % 3 == 0:
        return 0 
    else:
        return H

def w_div_h_div(H, W):
    min_diff = 10000000000
    for w in range(1, W):
        a1 = w * H
        a2 = (W - w) * (H // 2)
        a3 = W * H - a2 - a1
        diff = max(a1, a2, a3) - min(a1, a2, a3)
        if diff < min_diff:
            min_diff = diff
    return min_diff

print(min(div_3(H, W), div_3(W, H), w_div_h_div(H, W), w_div_h_div(W, H)))

Measured memory_bytes: 3064
# time complexity: O(N√N)

from collections import defaultdict


def prime_factorize(n, prime_numbers):
    i = 2
    while i * i <= n:
        if n % i == 0:
            exponent = 0
            while n % i == 0:
                n //= i
                exponent += 1
            prime_numbers[i] += exponent
        i += 1
    if n != 1:
        prime_numbers[n] += 1
    return prime_numbers


N = int(input())
MOD = 10**9 + 7

prime_numbers = defaultdict(int)
for n in range(1, N + 1):
    prime_factorize(n, prime_numbers)

num_divisors = 1
for exponent in prime_numbers.values():
    num_divisors *= (exponent + 1)
    num_divisors %= MOD

print(num_divisors)


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

int f(int n){
    if(n%2==0) return n/2;
    else return 3*n+1;
}

int main(){
    int s;
    cin>>s;
    vector<int> num(1000005,0);
    
    bool exist=true;
    int i=1;
    num[s]++;
    while(exist){
        s=f(s);
        num[s]++;
        if(num[s]>1) exist=false;
        i++;
    }
    
    cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 7204