akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define vp vector<P>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
const int mod = 1000000007;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

template<class T> bool chmax(T &a, const T & b) {
    if (a<b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a, const T & b) {
    if (a>b) {
        a = b;
        return true;
    }
    return false;
}

//cout << fixed << setprecision(10) << y << endl;
struct edge {int to, cost;};
vector< vector<edge> > es;

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

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

const int MAX = 1000010;
ll fac[MAX], inv[MAX], finv[MAX]; 

void COMinit() {
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    FOR(i, 2, MAX) {
        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 COM(int n, int r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[n-r] * finv[r] % mod) % mod;
}

int main() {
    COMinit();
    int x, y;
    cin >> x >> y;
    if (2*y-x < 0 || 2*x-y < 0 || (2*y-x)%3 != 0 || (2*x-y)%3 != 0) {
        cout << 0 << endl;
    } else {
        int a = (2*y-x)/3;
        int b = (2*x-y)/3;
        cout << COM(a+b, b) << endl;
    }
    return 0;
}

Measured memory_bytes: 23680
r, c, R, C = [int(_) for _ in input().split()]
mod = 10**9 + 7

f = [1] * (3 * 10**6 + 10)
for i in range(1, 3 * 10**6 + 10):
    f[i] = i * f[i - 1] % mod
fi = {}


def comb(n, r):
    if r not in fi:
        fi[r] = pow(f[r], mod - 2, mod)
    if n - r not in fi:
        fi[n - r] = pow(f[n - r], mod - 2, mod)
    return (f[n] * fi[r] * fi[n - r]) % mod


a1 = (C + 2) * f[c + 1] * f[C + R + 2] - (c + 1) * f[C + 2] * f[c + R + 1]
a1 *= pow(R + 1, mod - 2, mod) * pow(f[c + 1], mod - 2, mod) * pow(
    f[C + 2], mod - 2, mod) * pow(f[R], mod - 2, mod)
a2 = (C + 2) * f[c + 1] * f[C + r + 1] - (c + 1) * f[C + 2] * f[c + r]
a2 *= pow(r, mod - 2, mod) * pow(f[c + 1], mod - 2, mod) * pow(
    f[C + 2], mod - 2, mod) * pow(f[r - 1], mod - 2, mod)
ans = a1 - a2
ans %= mod
print(ans)


Measured memory_bytes: 121716
def min(a,b)
  if a<b
    return a
  else
    return b
  end
end

n,m=gets.chomp.split(/ /).map{|i| i.to_i}
c=gets.chomp.split(/ /).map{|i| i.to_i}
d=Array.new(m).map{Array.new(n+1,10000)}
for i in 0..m-1
  d[i][0]=0
end
for j in 0..n
  if j%c[0]==0
    d[0][j]=j/c[0]
  end
end
for i in 1..m-1
  for j in 1..n
    if j>=c[i]
      d[i][j]=min(d[i-1][j],d[i][j-c[i]]+1)
    else
      d[i][j]=d[i-1][j]
    end
  end
end
puts d[m-1][n]

Measured memory_bytes: 16460
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	int k, x;
	cin >> k >> x;
	cout << ((k*500>=x)? "Yes" : "No" ) << endl; 
	return 0;
}

Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

int main(int argc, char const* argv[])
{
    double a,b,c,d,e,f,x,y;
    while (scanf("%lf %lf %lf %lf %lf %lf ", &a, &b, &c, &d, &e, &f) != EOF) {
        y = (a*f - d*c) / (a*e - b*d);
        x = (c - b*y) / a;
        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

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



int main(){
    int n, l;
    cin >> n >> l;
    string s[n];
    rep(i, n)   cin >> s[i];

    priority_queue<string, vector<string>, greater<string>> q;
    rep(i, n)   q.push(s[i]);
    rep(i, n){
        cout << q.top();
        q.pop();
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

const int mx = 2*160*80;
const int geta = 80;

bool dp[85][85][mx];

int main() {
    int h, w; cin >> h >> w;
    vvint a(h,vint(w)), b(h,vint(w));
    rep(i,h)rep(j,w) cin >> a[i][j];
    rep(i,h)rep(j,w) cin >> b[i][j];
    vector<vector<P>> cost(h,vector<P>(w));
    rep(i,h)rep(j,w) {
        int x = abs(a[i][j]-b[i][j]);
        cost[i][j] = P(x+geta,geta-x);
    }
    dp[0][0][cost[0][0].first] = dp[0][0][cost[0][0].second] = true;
    rep(i,h)rep(j,w)rep(k,mx) {
        int x = cost[i][j].first;
        int y = cost[i][j].second;
        if (i) {
            if (dp[i-1][j][k]) dp[i][j][k+x] = dp[i][j][k+y] = true;
        }
        if (j) {
            if (dp[i][j-1][k]) dp[i][j][k+x] = dp[i][j][k+y] = true;
        }
    }
    int ans = inf;
    rep(i,mx) {
        if (dp[h-1][w-1][i]) {
            chmin(ans,abs(i-(h+w-1)*geta));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 169088
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

template <class T>
inline bool chmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template <class T>
inline bool chmin(T &a, const T &b) { return b < a ? a = b, true : false; }

int main()
{
  int n;
  cin >> n;
  VI a(n);
  REP(i, n)
      cin >> a[i];
  sort(ALL(a));
  deque<int> q;
  int l=0,r=n;
  q.push_back(a[--r]);

  while ( l<r )
  {
    int x=a[l],y=a[r-1];
    int x1=abs(q.front() - x);
    int x2=abs(q.back()-x);
    int y1=abs(q.front()-y);
    int y2=abs(q.back() - y);
    int mx=max({x1,x2,y1,y2});
    if ( x1==mx ) {
      q.push_front(x); l++;
    }
    else if ( x2==mx ) {
      q.push_back(x); l++;
    }
    else if (y1 == mx)
    {
      q.push_front(y);
      r--;
    }
    else if (y2 == mx)
    {
      q.push_back(y);
      r--;
    }
  }

  LL ans = 0;
  int me = q.front();
  q.pop_front();
  while (q.size())
  {
    // cout << me << ' ';
    ans += abs(q.front() - me);
    me = q.front();
    q.pop_front();
  }
  // cout << me << '\n';

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define mod 998244353 
#define pb push_back
#define mb make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 1e5+7;
int main(){
	IOS;
	int n,k; cin >> n >> k;
	int inp[n];
	int dp[N];
	memset(dp , 0 , sizeof(dp));
	for(int i = 0 ;i < n; i++){
		cin >> inp[i] ;
		dp[inp[i]] = 1;
	}
	for(int i = 1 ; i < k+2 ; i++){
		if(dp[i] == 1)
			continue;
		for(int j = 0 ; j < n ; j++){
			if(inp[j]>=i)
				break;
			if(dp[i-inp[j]] == 0)
				dp[i] = 1;
		}
	}
	// for(int i = 1; i <= k ;i++)
	// 	cout << dp[i] << " ";
	if(dp[k])
		cout << "First";
	else
		cout << "Second";




	return 0;
}




Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new int[]{sc.nextInt(), sc.nextInt()});
        }
        list.sort(Comparator.comparingInt(e -> e[1]));
        int cur = 0;
        for (int[] e: list) {
            int deadline = e[1];
            cur += e[0];
            if (cur > deadline) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 67944
import java.util.Scanner;

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

    if (s.charAt(s.length() - 1) == 's') {
      System.out.println(s + "es");
    } else {
      System.out.println(s + "s");
    }
  }
}


Measured memory_bytes: 27008
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define double long double
int n,m;
vector<int>edge[605];
double dp[605];
double solve(){
	rep(i,605) dp[i] = 0;
	dp[n] = 0;
	for(int i=n-1;i>=1;i--){
		double sum = 0;
		double cnt = 0;
		rep(j,edge[i].size()){
			if(edge[i][j] == -1) continue;
			cnt += 1.0;
			sum += dp[edge[i][j]];
		}
		dp[i] = sum / cnt + 1.;
		dp[i] = min(dp[i],(double)1e18);
	}
	return dp[1];
}
int cut[605];
int main(){
	cin >> n >> m;
	rep(i,m){
		int a,b; cin >> a >> b;
		edge[a].pb(b);
	}
	repn(i,n) SORT(edge[i]);
	double ans = solve();
	repn(i,n){
	    rep(j,edge[i].size()){
	        if(cut[i] == 0 || dp[cut[i]] <= dp[edge[i][j]]) cut[i] = edge[i][j];
	    }
	}
	repn(i,n){
		if(edge[i].empty()) continue;
		rep(j,edge[i].size()){
		    if(edge[i][j] == cut[i]) edge[i][j] = -1;
		}
		ans = min(ans,solve());
		rep(j,edge[i].size()){
		    if(edge[i][j] == -1) edge[i][j] = cut[i];
		}
	}
	printf("%.12Lf\n",ans);
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// original: satanic-san
// https://atcoder.jp/contests/abc141/submissions/7525527
class RollingHash {
    template <int B, int M>
    class RollingHashPart {
      private:
        size_t len;
        std::vector<int> pow_b, hash;

      public:
        RollingHashPart() {}
        template <typename T>
        RollingHashPart(const T &s) : len(s.size()), pow_b(s.size() + 1), hash(s.size() + 1) {
            pow_b[0] = 1;
            hash[0]  = 0;
            for (int i = 0; i < len; i++) {
                pow_b[i + 1] = (ll)pow_b[i] * B % M;
                hash[i + 1]  = ((ll)hash[i] * B + s[i]) % M;
            }
        }
        // [l, r)
        int get(int l, int r) const {
            int res = (hash[r] - (ll)hash[l] * pow_b[r - l]) % M;
            if (res < 0)
                res += M;
            return res;
        }
    };

  public:
    using HashData = pair<int, int>;
    RollingHashPart<1033, 1000000007> rh1;
    RollingHashPart<6037, 999999937> rh2;

    RollingHash() {}
    template <typename T>
    RollingHash(const T &s) : rh1(s), rh2(s) {}
    // [l, r)
    HashData get(int l, int r) const { return HashData{rh1.get(l, r), rh2.get(l, r)}; }
    // [l1, r1), [l2, r2)
    int lcp(const RollingHash &rhs, int l1, int r1, int l2, int r2) const {
        int lb = 0, ub = std::min(r1 - l1, r2 - l2) + 1;
        while (ub - lb > 1) {
            int md                                               = (lb + ub) >> 1;
            (get(l1, l1 + md) == rhs.get(l2, l2 + md) ? lb : ub) = md;
        }
        return lb;
    }
};

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    RollingHash rh(s);
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        for (int k = i + 1; k < n; ++k) {
            int lcp = rh.lcp(rh, i, k, k, n);
            chmax(ret, lcp);
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n,t;
  cin >> n >> t;
  ll a[n],b[n];
  pair<ll, ll> p[n];
  rep(i,n){
    cin >> a[i] >> b[i];
    p[i]=mp(a[i],b[i]);
  }
  sort(p,p+n);
  ll dp[t];
  ll ndp[t];
  ll ans=0;
  rep(i,t) dp[i]=ndp[i]=0;
  rep(j,n){
    ll time=p[j].first;
    ll del=p[j].second;
    //    cout << time << endl;
    rep(i,t){
      if(i+time<t) ndp[i+time]=max(dp[i]+del,dp[i+time]);
      else ans=max(ans, dp[i]+del);
    }
    rep(i,t) dp[i]=ndp[i];
  }
  rep(i,t) ans=max(ans,dp[i]);
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

string w;

void input(){
    cin >> w;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
  	map<char, int> cnt;
  	for(int i=0;i<w.size();i++) cnt[w[i]]++;
  	for(auto& e: cnt){
      if(e.second % 2 == 1){
        cout << "No" << endl;
        return 0;
      }
    }
  	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    rep(i, s.size()) cout << "x";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define PB push_back
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  string S[2];
  cin >> S[0] >> S[1];

  vector<int> a;
  REP(i, N) {
    if (S[0][i] == S[1][i]) {
      a.PB(0);
    } else {
      a.PB(1);
      i++;
    }
  }

  ll ans;
  if (a[0] == 1) ans = 6;
  else ans = 3;
  for (int i = 1; i < a.size(); i++) {
    if (a[i - 1] == 0 && a[i] == 0) (ans *= 2)%=MOD;
    if (a[i - 1] == 0 && a[i] == 1) (ans *= 2)%=MOD;
    if (a[i - 1] == 1 && a[i] == 0) (ans *= 1)%=MOD;
    if (a[i - 1] == 1 && a[i] == 1) (ans *= 3)%=MOD;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    int A[210];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    bool frag;
    frag = true;
    int count=0;
    while (frag==true)
    {
            for (int i = 0; i < N; i++)
        {
                if (A[i]%2==1)
                {
                    frag = false;
                }
        }
        if (frag==true)
        {
            count++;
        }
        for (int i = 0; i < N; i++)
        {
            A[i]=A[i]/2;
        }
        
    }
    cout << count << endl;
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
ll fa[MAX];
ll power(ll p,ll q){
    ll res=1;
    p%=mod;
    while(q){
        if (q&1)
            res=(res*p)%mod;
        q>>=1;
        p=(p*p)%mod;
    }
    return res;
}
ll fact(ll n){
    if (n<=1)
        return fa[n]=1;
    if (fa[n])
        return fa[n];
    return fa[n]=(n*fact(n-1))%mod;
}
ll ncr(ll n,ll r){
    if (!r)
        return 1;
    return (((fact(n)*power(fact(n-r),mod-2))%mod)*power(fact(r),mod-2))%mod;
}
void solve(){
    ll n=7,k,count=1;
    cin>>k;
    while(count<=10000000){
        if (!(n%k)){
            cout<<count<<endl;
            return;
        }
        n=(((n%k)*10)%k+7)%k;
        count++;
    }
    cout<<-1<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long W = sc.nextLong();
        long S= H*W;
        if(H==1||W==1){
            System.out.println(1);
        }else{
            System.out.println((S+1)/2);
        }
        
    }
}


Measured memory_bytes: 35700
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

  static int N;
  static int K;
  static long Q;
  static int A;
  static int B;
  static long C;
  static double min = 9999999;
  static long ans = 0;

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


    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int[] map = new int[N + 1];

    for (int i = 0; i < M; i++) {
      int L = scanner.nextInt();
      int R = scanner.nextInt();

      map[L - 1]++;
      map[R]--;
    }

    for (int i = 0; i < N; i++) {
      map[i + 1] += map[i];
    }

    int ans = 0;

    for (int i = 0; i < N; i++) {
      if(map[i] == M)ans++;
//      System.out.println(map[i]);
    }

    System.out.println(ans);
  }
}



Measured memory_bytes: 63188
#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>;

int main(){
    ll n,k;
    cin >> n >> k;
    ll kk;
    kk=n/k;
    ll ans;
    ans=ll(pow(kk,3)+0.3);
    if(k%2==0){
        n-=k/2;
        if(n>=0){
        kk=n/k+1;
        ans+=ll(pow(kk,3)+0.5);
    }
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3908
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    double r;
    cin >> r;
    cout << setprecision(10);
    cout << 2 * r *  M_PI << endl;
    return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
using namespace std;
typedef long long ll;

int main(void) {
    string s;
    set<string> sets;
    int K;
    cin >> s >> K;
    for(int i=0; i<s.size(); i++) {
        for(int j=1; j<=5; j++)
            sets.insert(s.substr(i, j));
    }
    vector<string>vecs = vector<string>(sets.begin(), sets.end());
    cout << vecs[K-1] << endl;
}


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<c<<' '<<a<<' '<<b;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String S = sc.next();
        String K = sc.next();

        System.out.println(checkInf(S, K));
    }

    public static String checkInf(String S, String K){
        long count = 0;
        for(int i = 0; i < S.length(); i++){
            int val = S.charAt(i) - '0';
            if(val == 1)
                count++;
            else {
                if(K.compareTo(key) > 0 && val == 2){
                    while(i < S.length()){
                        int val1 = S.charAt(i) - '0';
                        if(val1 != 1)
                            return String.valueOf((char) ('0' + val));
                        i++;
                    }
                    return String.valueOf((char) ('0' + val));
                }
                return String.valueOf((char) ('0' + val));
            }
            if(K.compareTo(String.valueOf(count)) == 0)
                return String.valueOf((char)('0' + val));

        }
        return null;
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n,x;
    cin>>n>>x;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    int d=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        d=d+l[cnt];
        if(d>x) break;
        cnt++;
    }
    cnt++;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  int N;
  cin >>N;
  vi C(N);
  intl X = 0;
  Rep(i,N){
    cin >>C[i];
    X = (X^C[i]);
  }
  
  Rep(i,N){
    cout << (X^C[i])<<' ';
  }
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;

const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

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

  string s;
  cin >> s;

  s[k-1] = tolower(s[k-1]);
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n;
int m;
int s[7];
int c[7];
int d[7];
int ss;
int ans;
int main()
{
	cin>>n>>m;
	rep(i,7)d[i]=-1;
	rep(i,m)
	{
		cin>>s[i]>>c[i];
		s[i]--;
	}
	if(n==1)
	{
		int ff=0;
		rep(i,m)
		{
			if(c[i]!=0)ff=1;
		}
		if(ff==0)
		{
			cout<<0<<endl;
			return 0;
		}
	}
	rep(i,m)
	{
		ss=s[i];
		if(d[ss]==-1)
		{
			d[ss]=c[i];
		}
		else
		{
			if(d[ss]!=c[i])ans=-1;
		}
		
	}
	rep(i,n)
	{
		if(d[i]==-1)
		{
			if(i==0)d[i]=1;
			else d[i]=0;
		}
	}
	if(d[0]==0)
	{
		ans=-1;
	}
	if(ans==-1)
	{
		cout<<ans<<endl;
	}
	else
	{
		rep(i,n)cout<<d[i];
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int a,b;
char c;
while(scanf("%d %c %d",&a,&c,&b) != EOF){
if(c == '?'){
break;
}
if(c == '+'){
printf("%d\n",a+b);
}
else if(c == '-'){
printf("%d\n",a-b);
}
else if(c == '*'){
printf("%d\n",a*b);
}
else if(c == '/'){
printf("%d\n",a/b);
}
}
return 0;
}


Measured memory_bytes: 2108
#https://atcoder.jp/contests/abc157/tasks/abc157_d
N,M = map(int, input().split())

K = []
S = []
P = []

for i in range(M):
    k,*s = map(int, input().split())
    K.append(k)
    S.append(s)
*P, = map(int, input().split())
ans = 0

for i in range(2**N):
    Switch = ["on"]*N
    flg = 0

    for j in range(N):
        if (i>>j)&1:
            Switch[j] = "off"
    for s in range(len(S)):
        count = 0
        for switch in range(len(Switch)):
            if ((switch+1) in S[s]) and Switch[switch]=="on":
                count = count + 1
        if count%2!=P[s]:
            flg = 1
            continue
    if flg==0:
        ans = ans + 1
print(ans)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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();
		
		List<Integer> Pn = new ArrayList<>();
		
		for(int i =0; i<N; i++) {
			Pn.add(sc.nextInt());			
		}
		
		Collections.sort(Pn);
		
		int ans = 0;
		for(int i = 0; i<K; i++) {
			ans += Pn.get(i);
		}
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 30584
#include <stdio.h>

int main() {
	int numTimes[100], max = 0;
	int num;
	for (num = 0; num < 100; ++num) { numTimes[num] = 0; }
	while (scanf("%d", &num) != EOF) {
		if (++numTimes[num - 1] > max) {
			max = numTimes[num - 1];
		}
	}
	for (num = 0; num < 100; ++num) {
		if (numTimes[num] == max) {
			printf("%d\n", num + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 0
N, D = map(int, input().split())
X = []
for _ in range(N):
    line = list(map(int, input().split()))
    X.append(line)
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist2 = 0
        for k in range(D):
            dist2 += (X[i][k] - X[j][k])**2
        for l in range(200):
            if dist2 == l**2:
                ans += 1
                break
print(ans)


Measured memory_bytes: 64012
#include<iostream>
using namespace std;
int main() {
	int n,i;
	float x1, y1, x2, y2, x3, y3, x4, y4,a,b;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		if (x1 - x2 == 0 && x3 - x4 == 0) {
			cout << "YES" << endl;
		}
		else if (x1 - x2 == 0 || x3 - x4 == 0) {
			cout << "NO" << endl;
		}
		else {
			a = (x3 - x4)*(y1 - y2);
			b = (x1 - x2)*(y3 - y4);
			if (a == b) {
				cout << "YES" << endl;
			}
			else if (a != b) {
				cout << "NO" << endl;
			}
		}
	}
	return 0;
}

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

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  int j=0;
  vector<int> output(101);
  
  for(int i=1; i<=100; i++){
    if(i>A || i>B) break;
    else if(A%i==0 && B%i==0){
      output.at(j)=i;
      j++;
    }
  }
  sort(output.begin(),output.end());
  reverse(output.begin(),output.end());
  cout << output.at(K-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7,N=17;
int n,m,i,fac[1<<N],inv[1<<N],f[1<<N],t,L,j,ans,a[N],k;
void inc(int &x,int y){x+=y;if(x>=M)x-=M;if(x<0)x+=M;}
int C(int n,int m){
	if (n<m) return 0;
	return 1ll*fac[n]*inv[m]%M*inv[n-m]%M;
}
int main(){
	scanf("%d%d",&n,&m),L=1<<n;
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for (i=2;i<=L;i++) fac[i]=1ll*fac[i-1]*i%M,inv[i]=M-1ll*M/i*inv[M%i]%M;
	for (i=2;i<=L;i++) inv[i]=1ll*inv[i-1]*inv[i]%M;
	for (i=1;i<=m;i++) scanf("%d",&a[i]);
	f[0]=1;
	for (i=m;i;i--)
		for (j=L-1;~j;j--)
			for (k=0;k<n;k++)
				if (j&(t=1<<k)) inc(f[j],1ll*f[j^t]*C(L-a[i]-j+t,t-1)%M*fac[t]%M);
	for (i=0;i<L;i++) inc(ans,1ll*(__builtin_popcount(i)&1?-1:1)*f[i]*fac[L-1-i]%M);
	printf("%lld",1ll*ans*L%M);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main() {
  int a, b;
  cin >> a >> b;
  for(int i=1; i<1264; i++)
    if(floor(i*0.08)==a && floor(i*0.1)==b) {
      cout << i;
      return 0;
    }
  cout << -1;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N;
    scanf("%d",&N);
    int pro[N];
    for(int i=0;i<N;i++){
        scanf("%d",&pro[i]);
    }
    int M;
    scanf("%d",&M);
    data dri[M];
    rep(i,M){
        scanf("%d %d",&dri[i].a,&dri[i].b);
    }
    rep(i,M){
        int sum=0;
        rep(j,N){
            if(j==dri[i].a-1){
                sum+=dri[i].b;
            }else{
                sum+=pro[j];
            }
        }
        printf("%d\n",sum);
    }
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  string s;
  while(n){
    n--;
    s+='a'+n%26;
    n/=26;
  }
  reverse(s.begin(),s.end());
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3608
st = []
for c in input().split():
    if c in "+-*":#演算子がでてきたら
        v2 = st.pop()
        v1 = st.pop()
        st.append(str(eval(v1 + c + v2)))
    else: #普通の数値
        st.append(c)
print(st[0])


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

long long int a[300005]={0};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<3*n;++i)cin >> a[i];

    vector<long long int> former, latter;

    priority_queue<long long int, vector<long long int>, greater<long long int> > que;
    long long int sum = 0;
    for(int i=0;i<n;++i){
        que.push(a[i]);
        sum += a[i];
    }

    former.push_back(sum);
    for(int i=n;i<2*n;++i){
        sum += a[i];
        que.push(a[i]);
        sum -= que.top();
        que.pop();
        former.push_back(sum);
    }

    priority_queue<long long int> qu;
    sum = 0;
    for(int i=3*n-1;i>=2*n;--i){
        qu.push(a[i]);
        sum += a[i];
    }

    latter.push_back(sum);
    for(int i=2*n-1;i>=n;--i){
        sum += a[i];
        qu.push(a[i]);
        sum -= qu.top();
        qu.pop();
        latter.push_back(sum);
    }

    long long int ans = LLONG_MIN;
    for(int i=0;i<=n;++i){
        ans = max(ans, former[i]-latter[n-i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E15;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

ll po(ll i,ll p){
    if(p==0)return 1;
    else if(p==1)return mod(i);
    else if(p%2==0)return po(mod(mod(i)*mod(i)),p/2);
    else  return mod(mod(i)*po(i,p-1));
}
 
int main(){fastio
    
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    if(a[0]!=0){
        cout<<0<<endl;return 0;
    }
    ll ans=1;
    sort(a,a+n);
    ll c[n+1];memset(c,0,sizeof(c));
    rep(i,1,n-1){
        if(a[i]>n){
            cout<<0<<endl;return 0;
        }
        if(a[i]<=0){
            cout<<0<<endl;return 0;
        }
        c[a[i]]++;
    }
    rep(i,1,n-1){
        if(c[i]==0&&c[i+1]!=0){
            cout<<0<<endl;return 0;
        }
    }
    rep(i,1,n-1){
        if(c[i]==0){
            cout<<mod(ans)<<endl;return 0;
        }
        ans=mod(ans*po(c[i],c[i+1]));
    }
    cout<<mod(ans)<<endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#define INF 1000000
using namespace std;
struct data{
    int x,y;
};
int ans[1001][1001],H,W,N,cou;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
char field[1001][1001];
int main(){
    data s;
    cin>>H>>W>>N;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>field[i][j];
            if(field[i][j]=='S')s.x=i,s.y=j;
        }
    }
    for(int l=1;l<=N;l++){
        queue<data> q;
        data g;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                ans[i][j]=INF;
                if(field[i][j]=='0'+l)g.x=i,g.y=j;
            }
        }
        q.push(s);
        ans[s.x][s.y]=0;
        while(!q.empty()){
            data now;
            now=q.front();
            q.pop();
            if(now.x==g.x&&now.y==g.y)break;
            for(int i=0;i<4;i++){
                if(now.x+dx[i]>=0&&now.x+dx[i]<H&&now.y+dy[i]>=0&&now.y+dy[i]<W&&ans[now.x+dx[i]][now.y+dy[i]]==INF&&field[now.x+dx[i]][now.y+dy[i]]!='X'){
                    data next;
                    next.x=now.x+dx[i],next.y=now.y+dy[i];
                    q.push(next);
                    ans[now.x+dx[i]][now.y+dy[i]]=ans[now.x][now.y]+1;
                }
            }
        }
        cou+=ans[g.x][g.y];
        s=g;
    }
    cout<<cou<<endl;
return 0;
}

Measured memory_bytes: 6104
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
	int N,M;
	int Ntotal,Mtotal;
	int n[100],m[100];
	int min;
	
	while(true){
		Ntotal=0;
		Mtotal=0;
		min =INF;
		cin >> N >> M;
		if (N == M && N == 0)
			break;
		rep(i,N){
			cin >> n[i];
			Ntotal+=n[i];
		}
		rep(i,M){
			cin >> m[i];
			Mtotal+=m[i];
		}
		if(Mtotal== Ntotal){
			rep(i,N){
				rep(j,M){
					if(n[i] == m[j] && min > n[i])
						min = n[i];
				}
			}
			if(min == INF)
				cout << -1 << endl;
			else
				cout << min << ' ' << min << endl;
		}else{
			int tem1=INF,tem2=INF;
			min = Ntotal-Mtotal;
			rep(i,N){
				rep(j,M){
					if((n[i]-m[j])*2 == min && tem1+tem2 >n[i]+m[j]){
						tem1=n[i];
						tem2=m[j];
					}
				}
			}
			if(tem1==tem2)
				cout << -1 << endl;
			else
				cout <<tem1 << ' ' << tem2 <<  endl;
		}
 	}   
    return 0;
}

Measured memory_bytes: 1160
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = 10**13+4
for i in range(1,2*10**6):
    if (n/i).is_integer():
        res = min(res, i + n/i)
print(int(res-2))

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

int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
   for (int i = 0; i < N; i++) {
     cin >> vec.at(i);
   }
  
  sort(vec.begin(), vec.end());
  string S = vec.at(0);
  int c = 1;
  int x = 0;
  
   for (int i = 0; i < N-1; i++) {
     if (vec.at(i+1) == S){
       c ++;
     }
     else {
       S = vec.at(i+1);
       c = 1;
     }
     x = max(c, x);
   }
  int y = 0;
  S = vec.at(0);
  
   for (int i = 0; i < N; i++) {
     if (vec.at(i) == S)
       y ++;
     else {
       S = vec.at(i);
       y = 1;
     }
     if (y == x){
       cout << vec.at(i) << endl;
     }
   }
}

Measured memory_bytes: 9572
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    ll ans = k;
    rep(i, n-1) {
        ans *= k-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve():
    N, K = map(int, input().split())
    As = [int(i) - 1 for i in input().split()]

    visited = [-1 for _ in range(N)]
    roop_As = [0]
    now_i = 0
    visited[now_i] = 0
    for _ in range(K):
        now_i = As[now_i]
        if visited[now_i] >= 0:
            break
        roop_As.append(now_i)
        visited[now_i] = len(roop_As) - 1

    if K < len(roop_As):
        print(roop_As[-1] + 1)
    else:
        roop_As = roop_As[visited[now_i]:]
        print(roop_As[(K - visited[now_i]) % len(roop_As)] + 1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 32336
n = int(input())
a = list(map(int,input().split()))
v = []
before = 0
for i in a:
    if i!=before:v.append(i)
    before = i
money = 1000
stack = 0
if len(v) != 1:
    if v[0]<v[1]:
        buy_point = [1]
    else:
        buy_point = [0]
    for i in range(1,len(v)-1):
        if v[i-1]  < v[i] < v[i+1]:
            buy_point.append(2)
        elif v[i-1]  > v[i] > v[i+1]:
            buy_point.append(0)
        elif v[i-1]  < v[i] and v[i] > v[i+1]:
            buy_point.append(-1)
        elif v[i-1]  > v[i] and v[i] < v[i+1]:
            buy_point.append(1)
        else:
            print('error')
    if v[-2] < v[-1]:
        buy_point.append(-1)
    else:
        buy_point.append(0)

    for (i,j) in zip(v,buy_point):
        if j == 1:
            stack += money//i
            money = money%i
        elif j == -1:
            money += stack * i
            stack = 0
        elif j == 2:
            stack += money//i
            money = money%i

print(money)

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

int main(){
  string s1,s2,s3;
  cin >>s1>>s2>>s3;
  
  string ans1,ans2,ans3;
  
  ans1 = toupper(s1[0]);
  ans2 = toupper(s2[0]);
  ans3 = toupper(s3[0]);
  
  cout <<ans1<<ans2<<ans3<<endl;
}


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

#define BUFSIZE 200001

int main(void){
	long long int S,cw,cm;
	char buf[BUFSIZE];

	fgets(buf,sizeof(buf),stdin);
	S = strlen(buf);
	cw=cm=0;
	for(int i=S-1;i>-1;i--){
		if(buf[i]=='B'){
			cm += cw;
		}else if(buf[i]=='W'){
			cw++;
		}
	}
	printf("%lld",cm);
	return 0;
}


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

double calcAngle(double h, double m)  
{  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
  
    double hour_angle = 0.5 * (h * 60 + m);  
    double minute_angle = 6 * m;  
  
    double angle = abs(hour_angle - minute_angle);  
    
    angle = min(360 - angle, angle);  
  
    return angle;  
}  
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1,i,j;
   // cin>>t;
    while(t--)
    {
        int n,count=0,sum=0,maxi=0,mini=1e18;
        double a,b,h,m,pi=3.14159265359;
        cin>>a>>b>>h>>m;
        if(m==0) m=60;
        double ang=calcAngle(h,m);
        cout<<setprecision(20);
        double ans=sqrt(a*a+b*b-2*a*b*cos((ang*pi)/180));
        cout<<ans;
    }
}

Measured memory_bytes: 4232
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define pb push_back
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int t,head[N],fa[N],son[N],del[N],c[N],dep[N];
struct Edge{int v,next;Edge(int _v=0,int _n=0):v(_v),next(_n){}}edge[N];
inline void add(int x,int y){edge[++t]=Edge(y,head[x]);head[x]=t;}
struct Q
{	int x,y,p,id; vector<int> go[2];
	Q(int _x=0,int _y=0,int _id=0):x(_x),y(_y),id(_id){p=0;go[0].clear();go[1].clear();}
}q[N];
void dfs(int x,int la=0)
{	fa[x]=la; dep[x]=dep[la]+1;
	for(rint i=head[x];i;i=edge[i].next) if(to!=la) dfs(to,x),son[x]++;
}
vector<Q*> cur;
void Add(int x,int y)
{	if(dep[x]<dep[y]) swap(x,y);
	for(;dep[x]!=dep[y];x=fa[x]) c[x]++;
	for(;x!=y;x=fa[x],y=fa[y]) c[x]++,c[y]++;
}
int main()
{	int n,m,tot=0,x,y,sum=0; cin>>n>>m; tot=m;
	for(rint i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1);
	for(rint i=1;i<=m;i++) scanf("%d%d",&q[i].x,&q[i].y),Add(q[i].x,q[i].y),q[i].id=i;
	for(rint i=1;i<=n;i++) sum+=min(2,c[i]);
	cout<<sum<<endl;
	for(rint i=1;i<=n;i++)
	if(!son[i])
	{	son[fa[i]]--; son[i]=1e9;
		for(rint j=1;j<=tot;j++)
		{	if(!del[j]&&(q[j].x==i&&q[j].y==i)) del[j]=1;
			if(!del[j]&&(q[j].x==i||q[j].y==i)) cur.pb(&q[j]);
		}
		for(rint j=0;j<cur.size();j++) if(cur[j]->y==i)
		swap(cur[j]->x,cur[j]->y),cur[j]->p^=1,swap(cur[j]->go[0],cur[j]->go[1]);
		i=0; if(cur.size()==0) continue;
		if(cur.size()==1)
		for(rint j=0;j<cur.size();j++)
		{	del[cur[j]->id]=1,++tot,q[tot]=Q(fa[cur[j]->x],cur[j]->y,tot);
			q[tot].p=cur[j]->p; q[tot].go[0].push_back(cur[j]->id);
		}
		else
		{	for(rint j=0;j<cur.size();j+=2)
			if(j+1<cur.size())
			{	del[cur[j]->id]=del[cur[j+1]->id]=1;
				++tot,q[tot]=Q(cur[j]->y,cur[j+1]->y,tot);
				q[tot].go[1].pb(cur[j]->id),q[tot].go[0].pb(cur[j+1]->id);
			}
			else
			{	del[cur[j]->id]=1,++tot,q[tot]=Q(fa[cur[j]->x],cur[j]->y,tot);
				q[tot].p=cur[j]->p; q[tot].go[0].push_back(cur[j]->id);
			}
		}
		cur.clear();
	}
	for(rint i=tot;i>m;i--)
	{	for(rint j=0;j<q[i].go[0].size();j++) q[q[i].go[0][j]].p=q[i].p;
		for(rint j=0;j<q[i].go[1].size();j++) q[q[i].go[1][j]].p=q[i].p^1;
	}
	for(rint i=1;i<=m;i++)
	if(!q[i].p) printf("%d %d\n",q[i].x,q[i].y);
	else printf("%d %d\n",q[i].y,q[i].x);
	return 0;
}


Measured memory_bytes: 82432
#include <iostream>

using namespace std;

bool p[1000001];
int pn[1000001];

int main()
{
    for(int i = 0; i < 1000001; i++)
    {
        p[i] = true;
    }
    for(int i = 2; i <= 1000000;i++)
    {
        if(!p[i])
            continue;
        for(int j = 2; i*j <= 1000000; j++)
        {
            p[i*j] = false;

        }
    }
    int result = 0;
    for(int i = 2; i < 1000001; i++)
    {

        if(p[i])
        {
            result++;
        }
        pn[i] = result;
    }
    int n;
    while(cin >> n)
    {
        cout << pn[n]<< endl;
    }
}

Measured memory_bytes: 6044
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;

int main() {
	INIT
	int s, w;
	cin >> s >> w;
	if (s <= w) {
		cout << "unsafe";
	} else {
		cout << "safe";
	}

	return 0;
}


Measured memory_bytes: 3652
# N: 問題数
# M: 提出数
N, M = list(map(int, input().split()))

# 各問題の正答状態
answer_dict = {}

# 問題解答状態
class AnswerState:
    
    def __init__(self):
        self.wrong_num = 0         # 正解するまでのWA数
        self.is_corrected = False # 正解しているか
    
    def submit(self, is_correct):
        # まだ正解していない状態でWAを出した場合はペナルティ数を増やす
        if not is_correct and not self.is_corrected:
            self.wrong_num += 1
        # 正解したかどうか記録
        if is_correct:
            self.is_corrected = True

for _ in range(M):
    tmp = input().split()
    p_index = int(tmp[0])
    p_result = tmp[1]
    
    if not p_index in answer_dict:
        answer_dict[p_index] = AnswerState()
    
    answer_dict[p_index].submit(p_result == 'AC')

# 正解数、ペナルティ数を数える
correct_num = 0
penalty_num = 0

for state in answer_dict.values():
    if state.is_corrected:
        correct_num += 1
        penalty_num += state.wrong_num

print('%d %d' % (correct_num, penalty_num))

Measured memory_bytes: 29440
N = int(input())
ans = 10**9
def f(x):
    answer = 0
    while x>0:
        answer += x % 10
        x //= 10
    return answer

for a in range(1, N+1):
    b = N - a
    if f(a)+f(b)<ans and b != 0:
        ans = f(a)+f(b)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,mi=INT_MAX,cost=0;
    cin>>n;
    int ara[n],j;
    for(i=0;i<n;i++){
        cin>>ara[i];
    }
    for(i=-100;i<=100;i++){
        cost=0;
        for(j=0;j<n;j++){
            cost+=(ara[j]-i)*(ara[j]-i);
        }
        mi=min(cost,mi);
    }
    cout<<mi<<endl;
    return 0;
}

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

int main() {
  string S, T = "ACGT";
  cin >> S;

  int ans = 0, cnt = 0;

  for (int i = 0; i < S.size(); i++) {
    if ((int)T.find(S.at(i)) > -1) cnt++, ans = max(ans, cnt);
    else cnt = 0;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256