akhauriyash/Code-Regression huggingface dataset:
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n, k;
int a[101010];

int main() {
	cin >> n >> k;
	REP(i, n)cin >> a[i];
	int ans = INF<int>();
	int l = 0, r = 0, cnt1 = 0;
	map<int, int>cnt2;
	while (1) {
		while (r < n&&cnt1 < k) {
			if (a[r] <= k) {
				if (cnt2[a[r]] == 0)cnt1++;
				cnt2[a[r]]++;
			}
			r++;
		}
		if (cnt1 < k)break;
		ans = min(ans, r - l);
		if (a[l] <= k) {
			cnt2[a[l]]--;
			if (cnt2[a[l]] == 0) {
				cnt1--;
			}
		}
		l++;
	}
	cout << (ans == INF<int>() ? 0 : ans) << endl;
}


Measured memory_bytes: 8128
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    string s,t; cin >> s >> t;
    int a,b; cin >> a >> b;
    string u; cin >> u;
    if (u == s) a--;
    else b--;
    cout << a << " " << b << "\n";
}

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

int main(){
 int N;
  cin >> N;
  long long int ans = 0;
  vector<int> A(N);
  vector<int> B(N-1);
  for(int i = 0; i < N-1; i++){
   	cin >> B[i];
  }
  A[0] = B[0];
  A[N-1] = B[N-2];
  for(int i = 1; i < N-1; i++){
   	A[i] = min(B[i-1],B[i]); 
  }
  for(int i = 0; i < N; i++){
    ans += A[i];
  }
cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt(); //モンスターの数
		int k=sc.nextInt(); //必殺技の回数

		ArrayList<Long>hp=new ArrayList<>();

		for(int i=0;i<n;i++) {		//モンスターの分,数回す
			hp.add(sc.nextLong()); //モンスターの体力
			//3System.out.println(n);


		}
		Collections.sort(hp);
		Collections.reverse(hp);
		//System.out.println(hp);

		long nomalAttackCount = 0; //通常攻撃の回数
		int roopcounta = 0;//ループが何回回ったかをカウント



		for(int i=0;i<hp.size();i++) {
			roopcounta +=1;
			if(roopcounta>k) {
				long Attack = hp.get(i);
				nomalAttackCount +=Attack;
			}

		}
		//System.out.println(hp.size());
		System.out.println(nomalAttackCount);

	}

}


Measured memory_bytes: 94408
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n , k;
	cin >> n >> k;
	vector<ll> h(n);
	rep(i,0,n) cin >> h[i];

	vsort(h);

	ll ans = INF;
	rep(i,0,n - k + 1){
		ans = min( ans , h[ i + k - 1 ] - h[i] );
	}

	cout << ans << endl;
	ret 0;
}

Measured memory_bytes: 1024
class Unionfind:
    
    def __init__(self,n):
        self.uf = [-1]*n

    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]

    def same(self,x,y):
        return self.find(x) == self.find(y)

    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x

    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

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


gp = Unionfind(n)
gr = Unionfind(n)

for i in range(k):
    a,b = map(int,input().split())
    gp.union(a-1,b-1)
for i in range(l):
    a,b = map(int,input().split())
    gr.union(a-1,b-1)

l = []
dic = {}
for i in range(n):
    a = gp.find(i) 
    b = gr.find(i)
    if a < 0:
        a = i
    if b < 0:
        b = i
    s = (a,b)
    l.append(s)
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = []
for i in range(n):
    ans.append(dic[l[i]])
print(*ans)

Measured memory_bytes: 121308
#include<iostream>

using namespace std;

int main()

{

    long long n,
	factorial=1;

    
    cin>>n;


    if (n<=20){
        for(int a=1;a<=n;a++)

    {

        factorial=factorial*a;

    }
	}
    
	
		
    cout<<factorial<<endl;

    return 0;

}

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<complex>
#define EPS 1.0e-10
using namespace std;
typedef double elem;
typedef complex<elem> point,vec;
inline elem dist(const point &a, const point &b){return abs(a-b);}
inline vec normr(const vec &v){return v*vec(0,-1);}
inline vec norml(const vec &v){return v*vec(0,1);}
inline vec unormr(const vec &v){return normr(v) / abs(v);}
inline vec unorml(const vec &v){return norml(v) / abs(v);}
int main(){
	while(true){
		int ans = 1;
		int n;
		scanf("%d", &n);
		if(n==0)break;
		vector< point > points;
		for(int i=0;i<n;++i){
			elem x, y;
			scanf("%lf%lf", &x, &y);
			points.push_back( point(x,y) );
		}
		for(unsigned int i = 0; i < points.size(); ++i){
			for(unsigned int j = i + 1; j < points.size(); ++j){
				if( dist( points[i], points[j] ) <= 2 ){
					int count_p = 0;
					int count_q = 0;
					elem d = (elem)sqrt( 1.0 - pow( dist(points[i], points[j]) / 2.0, 2.0 ) );
					point p,q;
					vec ab = points[j] - points[i];
					point t = 0.5 * ab + points[i];  
					p = d * unormr(ab) + t;
					q = d * unorml(ab) + t;
					//cout << i << "," << j << endl;
					for(unsigned int k = 0; k < points.size(); ++k){
						//cout << dist(p,points[k]) << " " << dist(q,points[k]) << endl;

						if( dist(p, points[k]) <= 1+EPS ){ count_p++; }
						if( dist(q, points[k]) <= 1+EPS ){ count_q++; }
					}
					ans = max(ans, max(count_q, count_p) );
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 988
#include <iostream>

 

using namespace std;

 

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = i / 60 - h * 60;
   s = i % 60;
   cout << h << ":"<< m << ":" << s << endl; 
   
   return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=2e5+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
char s[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    r(m);
    LL ans=0;
    FOR(i,1,len-1){
        if(m==1){
            ans+=9;
        }
        else if(m==2){
            if(i>=2) ans+=81*(i-1);
        }
        else if(m==3){
            if(i>=3) ans+=81ll*9*(i-1)*(i-2)/2;
        }
    }

    if(m==1) ans+=s[1]-'0';
    else if(m==2){
        int get=s[1]-'0'-1;
        if(get>0) ans+=get*9*(len-1);
        FOR(i,2,len){
            bool flag=1;
            FOR(j,2,i-1) if(s[j]!='0') flag=0;
            if(flag){
                ans+=s[i]-'0';
            }
            else ans+=9;
        }
    }
    else if(m==3){
        int get=s[1]-'0'-1;
        if(get>0) ans+=get*9*9*(len-1)*(len-2)/2;
        FOR(i,2,len){
            bool flag=1;
            FOR(j,2,i-1) if(s[j]!='0') flag=0;
            if(flag){
                int gg=s[i]-'0'-1;
                if(gg>0) ans+=gg*9*(len-i);
                if(gg>=0){
                    FOR(j,i+1,len){
                        bool ff=1;
                        FOR(k,i+1,j-1) if(s[k]!='0') ff=0;
                        if(ff){
                            ans+=s[j]-'0';
                        }
                        else ans+=9;
                    }
                }
            }
            else{
                ans+=9*9*(len-i);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a, b;
        cin>>a>>b;
        v.push_back(make_pair(-b,-a));
    }
    sort(ALL(v));

    set<ll> s;
    rep(i, m) {
        s.insert(-i);
    }

    ll sum = 0;
    rep(i, n){
        auto value = -v[i].first;
        auto days = -v[i].second;
        auto start = -m + days;
        if(start > 0) continue;
        if(s.count(start) ==1) {
            s.erase(start);
            sum+=value;
        } else {
            while(1){
                auto y = s.upper_bound(start);
                if(y == s.end()) break;
                
                s.erase(*y);
                sum+=value;
                break;
            }
        }
    }
    pr(sum);


    return 0;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define enld endl
int main(){
    int i,j,k;
    string s;
    cin>>i>>j>>k;
    cout<<min(i*j,k)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  cin >>N;
 vector<pair<pair<string,int>,int>> A(N);
  for(int i=0;i<N;i++){
    
    cin >> A.at(i).first.first >> A.at(i).first.second;
    A.at(i).first.second *= -1;
    A.at(i).second = i+1;
  }
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    cout << A.at(i).second << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int  n; cin>>n; int a[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}
   sort(a,a+n);
   int k=a[n-2];
   for(int i=0;i<n;i++)
   {
   	if(b[i]!=a[n-1])
   	{
   		cout<<a[n-1]<<endl;
   	}
   	else
   	{
   		cout<<a[n-2]<<endl;
   	}
   }
}

Measured memory_bytes: 3200
s = input()
if s.count('C')==1:
    a=s.index('C')
else:
    a=0
print('AC' if s[0]=='A' and s.count('C')==1 and s[1:a]+s[a+1:]==(s[1:a]+s[a+1:]).lower() and 1<a<len(s)-1 else 'WA')

Measured memory_bytes: 3060
loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0
    futons = gets.split.map(&:to_i)
    temps = gets.split.map(&:to_i).sort

    total = [0]
    (1..2**n-1).each do |x|
        y = x & (x-1)
        i = Math.log2(x - y)
        total[x] = total[y] + futons[i]
    end

    table = []
    m.times do |k|
        t = temps[k]
        table << [(0..k).map {|i| temps[i]}.inject(:+)]
        (1..2**n-1).each do |x|
            if total[x] <= t
                table[-1][x] = (table.size >= 2 ? table[-2][x] : 0) + t - total[x]
            else
                min = (table.size >= 2 ? table[-2][x] : 0) + total[x] - t
                (0..n-1).each do |i|
                    next if x[i] == 0
                    y = x - (1 << i)
                    m = table[-1][y]
                    min = m if m < min
                end
                table[-1][x] = min
            end
        end
    end
    p table[-1][-1]
end

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> ans;
  if(n%2){
    for(int l = 1, r = n-1; l < r; l++, r--){
      ans.emplace_back(l,r);
    }
  }else{
      bool flag = false;
      for(int l = 1, r = n-1; l < r; l++, r--){
        if(!flag && r-l <= n/2){
          --r;
          flag = true;
        }
        ans.emplace_back(l,r);
      }
    }

  rep(i,m){
    printf("%d %d\n",ans[i].first,ans[i].second);
  }
  return 0;
}


Measured memory_bytes: 4248
/***
* When I wrote this
* only God & I understood
* what I was doing
* Now, God only knows
/***/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
#define rep(i,a,n) for (int i=a;i<=n;i++)/*i为循环变量，a为初始值，n为界限值，递增*/
#define per(i,a,n) for (int i=a;i>=n;i--)/*i为循环变量， a为初始值，n为界限值，递减*/
const int mod = 1e9 + 7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//fixed<< setprecision(2)

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    while (cin >> s)
    {
        ll flag = 1;
        for (int i = 0; i < s.length(); i++)
        {
            if (s[i] == 'e')
            {
                if (s[i + 1] == 'r' && s[i + 2] == 'a' && s[i + 3] == 's' && s[i + 4] == 'e' && s[i + 5] == 'r')
                {
                    i += 5;
                }
                else if (s[i + 1] == 'r' && s[i + 2] == 'a' && s[i + 3] == 's' && s[i + 4] == 'e')
                {
                    i += 4;
                }
                else flag = 0;
            }
            else if (s[i] == 'd') {
                if (s[i + 1] == 'r' && s[i + 2] == 'e' && s[i + 3] == 'a' && s[i + 4] == 'm' && s[i + 5] == 'e' && s[i + 6] == 'r' && s[i + 7] != 'a')
                {
                    i += 6;
                }
                else if (s[i + 1] == 'r' && s[i + 2] == 'e' && s[i + 3] == 'a' && s[i + 4] == 'm' && s[i + 5] == 'e' && s[i + 6] == 'r' && s[i + 7] == 'a')
                {
                    i += 4;
                }
                else if (s[i + 1] == 'r' && s[i + 2] == 'e' && s[i + 3] == 'a' && s[i + 4] == 'm')
                {
                    i += 4;
                }
            }
            else flag = 0;
            if (!flag)break;
        }
        if (!flag)cout << "NO\n";
        else cout << "YES\n";
    }
}

Measured memory_bytes: 3212
def abc():
    n = int(input())
    tasks = []
    for i in range(n):
        a, b = map(int, input().split())
        tasks.append((a, b))
    tasks.sort(key=lambda x: x[1])
    tmp = 0
    for t in tasks:
        a, b = t
        if tmp + a > b:
            print('No')
            return
        tmp += a
    print('Yes')


abc()


Measured memory_bytes: 31860
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string ans = "Yes";
    vector<string> w(n);
    cin >> w.at(0);
    for(int i = 1; i < n; ++i){
        cin >> w.at(i);
        if(w.at(i - 1).back() != w.at(i).at(0)) ans = "No";
    }
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            if(w.at(i) == w.at(j)) ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N, 0));
  REP(i, 2) {
    REP(j, N) { cin >> A.at(i).at(j); }
  }

  int ans = 0;

  REP(i, N) {
    int tmp_ans = A.at(0).at(0);
    int r = 0;
    REP(j, N) {
      if (j > 0) {
        tmp_ans += A.at(r).at(j);
      }
      if (i == j) {
        ++r;
        tmp_ans += A.at(r).at(j);
      }
    }
    ans = max(ans, tmp_ans);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)


ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    ios_base::sync_with_stdio(false);
    ll n,d,ans=0;
    ll x,y;
    cin >> n >> d;
    rep(i,n){
        cin >> x >> y;
        if(x*x+y*y<=d*d){
            ans++;
        }
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll L, R;
string S;

void solve() {
	cin >> L >> R;

	if (L % 2019 == 0 || R % 2019 == 0 || L / 2019 != R / 2019) {
		cout << 0;
		return;
	}

	L %= 2019;
	R %= 2019;

	int ans = 2019;
	for (int i = L; i <= R; i++) {
		for (int j = i + 1; j <= R; j++) {
			ans = min(ans, (i*j) % 2019);
		}
	}

	cout << ans;

}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//SET PRECIOSION   cout << fixed ;  cout << setprecision(n) << ans << endl;
#define ll double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector <ll> v;
long long x,y,z,a,b,c,sum,ans,total,t,cnt,n,m,k,p,kase;
ll dp[3001][3001];
bool vis[3001][3001];
ll findAns(long long i, long long cnt)
{
    if(i==n)
    {
        if(cnt<n-cnt)
            return 1;
        else return 0;
    }
    if(vis[i][cnt])
        return dp[i][cnt];
    ll ans1 = v[i]*findAns(i+1,cnt);
    ll ans2 = (1-v[i])*findAns(i+1,cnt+1);
    vis[i][cnt]= true;
    return dp[i][cnt]=(ans1+ans2);
}
int main()
{
	FAST;
	cin>>n;
	v.resize(n);
	for(ll i=0; i<n; ++i)
        cin>>v[i];
   memset(vis,false,sizeof(vis));
    cout<<fixed<<setprecision(10)<<findAns(0,0)<<endl;

	return 0;
}


Measured memory_bytes: 58864
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string x, t;
	cin >> x >> t;
	int co1 = 0;
	for (int i = 0; i < x.size(); i++)
	{
		if (x[i] != t[i])
			co1++;
	}
	cout << co1 << endl;
    return 0;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define pb push_back

using namespace std;

const int N = 100010;

vector<int> G[N];
int fa[N], sz[N];
int n, m;

int find(int x){
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int col[N];

bool DFS(int o){
	for(int v : G[o]){
		if(!col[v]){
			col[v] = 3 - col[o];
			if(!DFS(v)) return false;
		}
		else if(col[v] == col[o]) return false;
	}
	return true;
}

int main(){
	scanf("%d%d", &n, &m);
	For(i, 1, n) fa[i] = i, sz[i] = 1;
	For(i, 1, m){
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].pb(v), G[v].pb(u);
		u = find(u), v = find(v);
		if(u ^ v) fa[u] = v, sz[v] += sz[u];
	}
	
	int ct = n, blk = 0, blk2 = 0;
	For(i, 1, n) if(fa[i] == i){
		col[i] = 1;
		if(sz[i] == 1) --ct;
		else{
			++blk;
			if(DFS(i)) ++blk2; 
		}
	}

	printf("%lld\n", 1ll * n * n - 1ll * ct * ct + 1ll * blk * blk + 1ll * blk2 * blk2);
	return 0;
}

Measured memory_bytes: 8064
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

s = str(input())

s_list = list(s)
len_slist = len(s_list)

s_list_a = s_list[0: (len_slist-1)//2]
s_list_b = s_list[(len_slist+3)//2 - 1:]

s_list_rev = deepcopy(s_list)
s_list_rev.reverse()

s_list_a_rev = deepcopy(s_list_a)
s_list_a_rev.reverse()

s_list_b_rev = deepcopy(s_list_b)
s_list_b_rev.reverse()

flg = s_list == s_list_rev
flg_a = s_list_a == s_list_a_rev
flg_b = s_list_b == s_list_b_rev

if flg and flg_a and flg_b:
    print("Yes")
else:
    print("No")





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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<string>> S(30,vector<string>(30));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++)cin >> S[i][j];
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(S[i][j]=="snuke"){
        char a='A'+j-1;
        cout << a << i << endl; return 0;}
    }
  }
}

Measured memory_bytes: 256
r = 10 ** 9 + 7
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
dp = [0] * (N+1)
a = sorted(set(a))

if 1 in a:
    dp[1] = 0
    del a[0]
else:
    dp[1] = 1

if N == 1:
    print(dp[1])
    exit()

if 2 in a:
    dp[2] = 0
    del a[0]
else:
    dp[2] = dp[1] + 1

if N == 2:
    print(dp[2])
    exit()

for i in range(1,N-1):
    if a == [] :
        dp[i+2] = (dp[i] + dp[i+1]) % r
    elif i+2 == a[0]:
        dp[i+2] = 0
        del a[0]
    else:
        dp[i+2] = (dp[i] + dp[i+1]) % r

print(dp[N])

Measured memory_bytes: 13984
#include <iostream>
#include <cctype>
using namespace std;
int main(){
    string cards, subcards;
    int m,h;
    while(true){
        cin >> cards;
        if(cards == "-"){
            break;
        }
        cin >> m;
        for(int i = 0; i < m; i++){
            cin >> h;
            subcards = cards.substr(0, h);
            cards.erase(0, h);
            cards = cards + subcards;
        }
        cout << cards << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int ans = 0;
  for (int i = 1; i  < n; i++) {
    if (a[i] == a[i - 1]) {
     a[i] = -1, ans++;
    }
  }
  cout << ans;
  return 0;
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 
#define INF INT_MAX/2 //(1<<(4*4-1))
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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

  int A,B;
  cin>>A>>B;
  if(B%A==0)cout<<A+B<<endl;
  else cout<<B-A<<endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d1 = new int[n];
        int[] d2 = new int[n];
        for (int i = 0; i < n; i++) {
            d1[i] = sc.nextInt();
            d2[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            if(d1[i] == d2[i]) {
                count++;
                if(count > 2) {
                    System.out.println("Yes");
                    return;
                }
            } else {
                count = 0;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 35988
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
ll n,m,v,p;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    cin>>n>>m>>v>>p;
    vector <ll> a(n);
    rep(i,n)
    cin>>a[i];
    vector <ll> pref(n+1,0);
    sort(a.begin(),a.end());
    reverse(all(a));
    for (int i=1;i<=n;i++)
        pref[i]=pref[i-1]+a[i-1];
    ll cur=0,ans=0;
    ans=p,cur=p;
    while (cur<n&&a[cur]==a[p-1])
        cur++,ans++;
    ll t=a[p-1];
    while (cur<n)
    {
    ll f=n-1-cur;
    ll g=a[cur]+m;
    if (g<t) {
        cur++;
        continue;
    }
    if (f>=v-p) {
        ans++, cur++;
        continue;
    }
    f+=p;
    f=v-f;
    ll sum=g*(cur-p+1)-(pref[cur]-pref[p-1]);
    if (sum>=f*m)
        ans++;
    cur++;


    }
    cout<<ans;




}

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

int main(){ 
  int a,b; cin >> a >> b;
  if( a == 1){ a = 14;} if( b == 1){ b = 14;}
  
  if( a < b){ cout << "Bob" << endl;}
  else if( a > b){ cout <<"Alice" << endl;}
  else{cout <<"Draw" << endl;}
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define R register
#define ll long long
using namespace std;

ll base[40];
int D;
int ans=0;
int st[40];

inline void dfs(int now,int len,ll sum)
{
	if(now==len/2+1)
	{
		if(sum!=D) return;
		int tans=st[1]>=0?(9-st[1]):(9+st[1]);
		for(R int i=2;i<now;i++) tans=tans*(st[i]>=0?(10-st[i]):(10+st[i]));
		ans+=len&1?tans*10:tans;
		return ;
	}
	if(sum+10ll*(base[len-now]-base[now-1])<D) return ;
	if(sum-10ll*(base[len-now]-base[now-1])>D) return ;
	for(R int ss=-9;ss<=9;ss++)
	{
		st[now]=ss;
		dfs(now+1,len,sum+st[now]*(base[len-now]-base[now-1]));
	}
	return ;
}

int main()
{
	scanf("%d",&D);
	int tmp=0;int d=D;while(d) tmp++,d/=10;
	base[0]=1;
	for(R int i=1;i<=18;i++) base[i]=base[i-1]*10;
	for(R int i=tmp;i<=18;i++) dfs(1,i,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>



int main(void){
  int x,y;
  int i,j;

  for(i = 1; i < 10; i++){
    for(j = 1; j < 10; j++){
      printf("%dx%d=%d\n",i,j,i * j);
    }
  }
 
  return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
#include<vector>
// int dep[100000];
// bool isvis[100000];
// int bfs(int n,int a,int b)
// {
//     std::queue<int> path;
//     int next;
//     path.push(1);
//     while(!path.empty()){
//         next=path.front();path.pop();
//         if(next==1) break;
//         if(!isvis[next]&&dep[next]==(n))
//     }
    
// }
int main()
{
    int n,a,b;
    unsigned long long fl=0;
    // memset(isvis,false,sizeof(isvis));
    // memset(dep,0,sizeof(dep));
    std::cin>>n>>a>>b;
    std::vector<unsigned long long> distance(n);
    for(int i=0;i<n;i++){
        std::cin>>distance[i];
    }
    for(int i=1;i<n;i++){
        fl+=std::min(a*(distance[i]-distance[i-1]),(unsigned long long)b);
    }
    std::cout<<fl;

    return 0;
}

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

#define MAX 10000
#define INF (1<<30)
#define BLACK 0
#define GRAY 1
#define WHITE 2

int n;
vector< pair<int,int> > graph[MAX];

// プロトタイプ宣言
void dijkstra();
// ここまで

int main(){
	int now,k,to,w;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>now>>k;
		for(int j=0;j<k;j++){
			cin>>to>>w;
			graph[now].push_back( make_pair(to,w) );
		}
	}

	dijkstra();


	return 0;
}

void dijkstra(){
	priority_queue< pair<int,int> > PQ;
	int color[MAX];
	int d[MAX];
	for(int i=0;i<n;i++){
		d[i]=INF;
		color[i]=WHITE;
	}

	d[0]=0;
	PQ.push(make_pair(0,0));		// （重み、ノード番号）
	color[0]=GRAY;


	while(PQ.empty()==false){
		pair<int,int> f=PQ.top();	PQ.pop();
		int from = f.second;
		color[from]=BLACK;

		if(d[from] < f.first*(-1) )continue;

		for(pair<int,int> next:graph[from]){
			int to=next.first;
			int w=next.second;
			if(color[to]==BLACK) continue;

			if(d[to]>d[from]+w){
				d[to]=d[from]+w;

				PQ.push( make_pair(d[to]*(-1), to) );
				color[to]=GRAY;
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<i<<" "<<(d[i]==INF? -1:d[i])<<endl;
	}
}



Measured memory_bytes: 8096
#include <stdio.h>

int main()
{
    int N,M,a[50],b[50],i,c[50]={};
    scanf("%d%d",&N,&M);
    for(i=0;i<M;i++){
        scanf("%d%d",&a[i],&b[i]);
        c[a[i]-1]++;
        c[b[i]-1]++;
    }
    for(i=0;i<N;i++) printf("%d\n",c[i]);
    return 0;
}

Measured memory_bytes: 128
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T& v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

const ll INF = 100000000000000000;
int main() {
  int n,m,r; in(n),in(m),in(r);
  vector<int> R(r);
  loop(i,0,r) in(R[i]),R[i]--;
  ll G[n][n];
  loop(i,0,n) loop(j,0,n) {
    if (i==j) G[i][j] = 0;
    else G[i][j] = INF;
  }
  loop(i,0,m) {
    int u, v; ll d; in(u),in(v),in(d);
    u--;v--;
    G[u][v] = G[v][u] = d;
  }
  
  loop(k,0,n)
    loop(i,0,n)
      loop(j,0,n)
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
  
  sort(R.begin(), R.end());
  ll ans = INF;
  do {
    ll sum = 0;
    loop(i,0,r-1) {
      int a = R[i];
      int b = R[i+1];
      sum += G[a][b];
    }
    ans = min(ans, sum);
  } while (next_permutation(R.begin(), R.end()));
  print(ans);
  return 0;
}


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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
// vll x(n); x[i]=a;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;
typedef vector<vector<ll>> vvll;
// vvll x(m,vi(n)); x[i][j]=a;

#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll n, cnt=0, ans=0;
    cin >> n;
    vll a(n);
    cin >> a;
    REP(i,n-1){
        if(a[i]-a[i+1]>=0) cnt++;
        else{
            if(ans<cnt) ans=cnt;
            cnt = 0;
        }
    }
    if(ans<cnt) ans=cnt;
    cout << ans << endl;
    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int n = s.size();
	long ans = 0;
	for(int i = 0; i < (1 << (n - 1)); i++){
		bitset<9> mask(i);
		string num = "";
		num += s.at(0);
		for(int j = 0; j < n - 1; j++){
			if(mask.test(j)){
				num += "+";
			}
			num += s.at(j + 1);
		}
		num += "+";
		// cout << num << endl;
		string c = "";
		for(int j = 0; j < (int)num.size(); j++){
			if(num.at(j) == '+'){
				ans += stoll(c);
				c = "";
			}
			else{
				c += num.at(j);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

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

void button(int &A, int &B, int &cnt) {
  if (A > B) { cnt += A; A--; }
  else { cnt += B; B--; }
} 

int main() {
  int A, B, cnt = 0;
  cin >> A >> B;
  button(A, B, cnt);
  button(A, B, cnt);
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	int ans1 = 0, ans2 = 0;

	int current = n;

	while (current > 0){
		ans1 += b;
		current -= a;
	}

	current = n;

	while (current > 0){
		ans2 += d;
		current -= c;
	}
	cout << (ans1 < ans2 ? ans1 : ans2) << endl;

}


Measured memory_bytes: 3116
import java.util.*;
 
public class Main{
 
 
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
 
 
    dfs(0,0,0,0);
 
    System.out.println(count);
 
  }
 
 
  static int count = 0;
  static int flag3 , flag5 , flag7;
  static int n;
 
  static void dfs(long a,int f3,int f5, int f7){
    //System.out.println("a:"+a);
    if(f3>0&&f5>0&&f7>0&&(a <= n) ){
 
            //System.out.println(a);
            //System.out.println(f3+":"+f5+":"+f7);
            count++;
 
    }
    if(a > n){
    }else{
      if(a*10<n){
        dfs(a*10+3,f3+1,f5,f7);
        dfs(a*10+5,f3,f5+1,f7);
        dfs(a*10+7,f3,f5,f7+1);
      }
      //System.out.println("**"+ans);
 
    }
 
 
 
  }
}

Measured memory_bytes: 27420
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <unordered_map>

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


int main(){
    ll sx,sy,tx,ty,dx,dy;
    cin>>sx>>sy>>tx>>ty;
    dx=tx-sx;dy=ty-sy;
    string s="";
    for(int i=0;i<dx;i++) s+='R';
    for(int i=0;i<dy;i++) s+='U';
    for(int i=0;i<dx;i++) s+='L';
    for(int i=0;i<dy;i++) s+='D';
    s+='D';
    for(int i=0;i<dx+1;i++) s+='R';
    for(int i=0;i<dy+1;i++) s+='U';
    s+="LU";
    for(int i=0;i<dx+1;i++) s+='L';
    for(int i=0;i<dy+1;i++) s+='D';
    s+='R';

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


Measured memory_bytes: 256
visited=[0]
visited_set=set()
visited_set.add(0)
n,k=map(int,input().split())
a=list(map(int,input().split()))
next1=0
next2=-1
while True:
    next2=a[next1]-1
    next1=next2
    if next2 in visited_set:
        break
    else:
        visited.append(next2)
        visited_set.add(next2)
#print(visited)
if k<len(visited):
    print(visited[k]+1)
else:
    loop_len=(len(visited)-visited.index(next2))
    k-=(len(visited)-loop_len)
    print(visited[k%loop_len+visited.index(next2)]+1)

Measured memory_bytes: 35716
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

string N;
ll mod = 9;
ll ans = 0;

cin >> N;

for (ll i = 0; i < N.size();++i) ans = (ans + (N[i] - '0'))%mod;

if(ans == 0)
    cout << "Yes" << endl;
else
    cout << "No" << endl;

return 0;

}


Measured memory_bytes: 3720
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<float>vec(N);
	for (int ia = 0; ia < N; ia++) {
		cin >> vec.at(ia);
	}
	sort(vec.begin(), vec.end());
	float A = vec.at(0);
	float B;
	for (int ib = 0; ib < N - 1; ib++) {
		B = (A + vec.at(ib + 1) )/ 2;
		A = B;
	}
	cout << A << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, M, i, j; string S; cin >> N >> M >> S;
vector<int> ans;
for(i=N; i>0; i-=j){
for(j=M; j>0; j--){ 
  if(i-j<0||S[i-j]=='1'){ continue; }
  else{ ans.push_back(j); break; }
}
if(j==0){ cout << -1 << "\n"; return 0; }
}
for(i=ans.size(); i>0; i--){ cout << ans[i-1] << " "; }
cout << "\n";
}

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

namespace Frog1
{
	static class Program
	{
		static void Main(string[] args)
		{
			var line = Console.ReadLine();
			var N = int.Parse(line);

			var line2 = Console.ReadLine();
			var line2Splited = line2.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
			var H = new List<int>();
			foreach (var token in line2Splited) {
				H.Add(int.Parse(token));
			}

			var costs = new int[N];
			for (int i = 0; i < N; i++) {
				costs[i] = int.MaxValue;
			}

			int cost = 0;

			costs[0] = cost;

			cost = costs[0] + Math.Abs(H[1] - H[0]);
			if (costs[1] > cost)
				costs[1] = cost;

			for (int i = 2; i < N; i++) {
				cost = costs[i - 1] + Math.Abs(H[i] - H[i - 1]);
				if (costs[i] > cost)
					costs[i] = cost;
				
				cost = costs[i - 2] + Math.Abs(H[i] - H[i - 2]);
				if (costs[i] > cost)
					costs[i] = cost;
			}

			Console.WriteLine(costs[costs.Length - 1]);
		}
	}
}

Measured memory_bytes: 19552
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#define PI 2.0*acos(0.0)
#define ll              long long int
#define ull             unsigned long long int
#define sc              scanf
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define pf              printf
#define MOD             1000000007
#define mx              123456789
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
using namespace std;
int main()
{
    int n, m, i, j, k, sum=0, sum1=0;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        if(i%2==0)
            sum++;
        else
            sum1++;
    }
    cout<<sum*sum1<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
  
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ( a+b > c+d ) {
		cout << "Left" << endl;
	} else if ( a+b == c+d ) {
		cout << "Balanced" << endl;
	} else {
		cout << "Right" << endl;
	}
	return 0;	
}

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

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

  vector<int> A(N, 0);
  vector<int> ans(N, 0);

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < 30; i++) {
    int count = 0; //0or1
    for (int j = 0; j < N; j++) {
      count ^= (A[j] >> i) & 1;
    }
    for (int j = 0; j < N; j++) {
      A[j] ^= (count << i);
    }
  }

  for (int i = 0; i < N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
int main(){ 
    string s;
    cin>>s;
    ll a=0;
    REP(i,s.size()-1){
    if(s[i]!=s[i+1]){
        a++;
    }
    }
    cout<<a;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(){
	int N,D;
	cin >> N >> D;
	vector<vi> v(N,vi(D));
	for(int i=0; i<N; i++){
		for(int j=0; j<D; j++){
			cin >> v[i][j];
		}
	}

	int count=0;
	for(int i=0; i<N-1; i++){
		for(int j=i+1; j<N; j++){
			double dist_d=0;
			for(int k=0; k<D; k++){
				double differ=v[i][k]-v[j][k];
				dist_d+=differ*differ;
			}
			double dist=sqrt(dist_d);
			double integer;
			double fraction;
			fraction = modf(dist, &integer);
			if(dist==integer){
				count++;
			}
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#21 Next Prime
X=int(input())
num=X 
for _ in range(1000000):
    flg = True
    # 2からnumまでの数でわりきれるかどうか（True：どの数字でも割り切れなかったので、素数。False:素数じゃない）
    for i in range(2,num):
        if num%i==0:
            flg = False
            break
    
    if flg:
        print(num)
        break
    else:
        num+=1
        pass

Measured memory_bytes: 9124