akhauriyash/Code-Regression huggingface dataset:
N, Y = map(int, input().split())
s = [(x, y, N - x - y) for x in range(N + 1) for y in range(N - x + 1) if x * 10000 + y * 5000 + (N - x - y) * 1000 == Y]
if len(s) > 0:
  print(s[0][0], s[0][1], s[0][2])
else:
  print(-1, -1, -1)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    var op: String

    when (a - b) {
        0 -> {
            op = "=="
        }
        in 1..Int.MAX_VALUE -> {
            op = ">"
        }
        else -> {
            op = "<"
        }
    }

    println("a $op b")
}



Measured memory_bytes: 32092
#include <stdio.h>
#include<math.h>
int func(long long int a,int b){
    int n=0,m=0;
    while(a>0){
        n++;
        a/=10;
    }
    while(b>0){
        m++;
        b/=10;
    }
    int ans=n;
    if(n<m){ans=m;}
    return ans;
}
int main(void){
    int b,n,m,answ;
    long long int N,a;
    scanf("%lld",&N);
    answ=func(N,1);
    for(int i=2;i<=pow(N,0.5);i++){
        if(N%i==0&&answ>func(N/i,i)){answ=func(N/i,i);}
    }
    printf("%d\n",answ);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int n,ans;
vector<int>aa,bb,cc;

int main(){
  
  ios_base::sync_with_stdio(0);
 
	ans=0;
	cin>>n;
  aa.resize(n);bb.resize(n);cc.resize(n-1);
	for(int i=0;i<n;++i) cin>>aa[i];
	for(int i=0;i<n;++i) cin>>bb[i];
	for(int i=0;i<n-1;++i) cin>>cc[i];
	for(int i=0;i<n;++i){
		ans+=bb[aa[i]-1];
		if(i){
			if(aa[i]==aa[i-1]+1)
				ans+=cc[aa[i-1]-1];
 
		}
 
	}
  	ans+=1000;
	cout<<ans-1000<<endl;
	return 0;
}	

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    String s = scanner.next();
    int now = 1;
    int cnt = 0;
    List<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      if (s.charAt(i) == (char) ('0' + now)) {
        cnt++;
      } else {
        now = 1 - now;
        list.add(cnt);
        cnt = 1;
      }
    }
    if (cnt != 0) {
      list.add(cnt);
    }
    if (list.size() % 2 == 0) {
      list.add(0);
    }

    int add = 2 * K + 1;

    int[] sum = new int[list.size() + 1];

    for (int i = 0; i < list.size(); i++) {
      sum[i + 1] = sum[i] + list.get(i);
    }

    int ans = 0;
    for (int i = 0; i < list.size(); i += 2) {
      int tmp;
      int left = i;
      int right = Math.min(i + add, list.size());
      tmp = sum[right] - sum[left];
      ans = Math.max(tmp, ans);
    }

    System.out.println(ans);

  }

}


Measured memory_bytes: 26060
#include<iostream>

using namespace std;

int main(){
    int a[3][3];
    int x[3],y[3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> a[i][j];
        }
    }
    x[0]=0;
    for(int i=0;i<3;i++)y[i] = a[0][i]-x[0];
    for(int i=0;i<3;i++)x[i] = a[i][0]-y[0];
    bool ans = true;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(x[i]+y[j]!=a[i][j]){
                ans = false;
                cout << "No" <<endl;
                return 0;
            }
        }
    }
    cout << "Yes"<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int nMax=20010;
int a[nMax],b[nMax],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int ls;
		scanf("%d",&ls);
		a[ls]=b[ls]=i-1;
	}
	int Min=0;
	for(int i=1;i<=n;i++)
	{
		a[i]-=n*(n-i);
		b[i]+=n*(n-i);
		Min=min(min(a[i],b[i]),Min);
	}
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]-Min+1);
	printf("\n");
	for(int i=1;i<=n;i++)
		printf("%d ",b[i]-Min+1);
	printf("\n");
	return 0;
}

Measured memory_bytes: 640
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]
 
def set_top(dice, top):
    return [dice[i] for i in mask[top]]
 
def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]
 
def equal(dice1, dice2):
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False
         
dice1 = input().split()
dice2 = input().split()
 
print('Yes' if equal(dice1, dice2) else 'No')

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

#define IOS ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define vs vector<string>
#define all(v) v.begin(),v.end()

#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define ff  first
#define ss  second
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
 
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
     
#define pi 3.14159265358979323846264338327950L
#define MOD 1000000007
int rec(int h)
{
  if(h==1)
    return 1;
    return (2*rec(ceil(h/2))+1);
}
int32_t main(){

    
     IOS
  int h;
  cin>>h;
  cout<<rec(h);
  

  return 0;
}




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

#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long MOD=1e9+7;
const long long LINF=1e18;
const int INF=0x3f3f3f3f;
const int MAXN=200050;

char in[MAXN];
void solve(int T){
	scanf("%s",&in);
	printf("%s",in);
	int len=strlen(in);
	if(in[len-1]=='s')printf("es");
	else printf("s");
}
signed main(){
	int t=1;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	//scanf("%d",&t); 
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

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

namespace ABC116
{
    class CollatzProblem
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());
            int r = s;
            int ans = 1;
            while (s != 1 && s != 2 && s != 4)
            {
                if (s % 2 == 0) { s = s / 2; }
                else { s = s * 3 + 1; }
                ans++;
            }
            Console.WriteLine(ans + 3);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll A, V; std::cin >> A >> V;
  ll B, W; std::cin >> B >> W;
  ll T; std::cin >> T;

  ll d = std::abs(A-B);
  if ( V < W ) std::cout << "NO" << std::endl;
  else {
    if ( d <= (V-W)*T ) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;
  } 
  return 0;
}



Measured memory_bytes: 3688
#include<iostream>
#include<cstdio>
using namespace std;
int a[200000];
int main()
{
    int n,minn,ans=-2100000000;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    minn=a[0];
    for(int i=1;i<n;i++)
    {
        ans=max(ans,a[i]-minn);
        minn=min(minn,a[i]);
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 87;
char s[N],t[N];
int ps[N],pt[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int q;
    cin >> (s+1) >> (t+1) >> q;
    for (int i = 1; s[i]; ++i)
        ps[i] = (s[i] == 'A' ? 1 : -1) + ps[i-1];
    for (int i = 1; t[i]; ++i)
        pt[i] = (t[i] == 'A' ? 1 : -1) + pt[i-1];
    while (q--) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        int x = ((ps[b] - ps[a-1]) % 3 + 3) % 3;
        int y = ((pt[d] - pt[c-1]) % 3 + 3) % 3;
        cout << (x == y ? "YES\n" : "NO\n");
    }
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
struct BIT{
private:
  vector<ll> vec;
  ll n;
public:
  BIT(ll siz){
    n=siz;
    vec.resize(n+3,0);
  }
  void add(ll ps,ll x){
    ps++;
    while(ps<=n){
      vec[ps]+=x;
      ps+=ps&(-ps);
    }
  }
  ll sum(ll ps){
    ps++;
    ll res=0;
    while(ps>0){
      res+=vec[ps];
      ps-=ps&(-ps);
    }
    return res;
  }
};
ll tento_0(vector<ll> vec){
  ll n=vec.size(),res=0;
  BIT b(n+5);
  for(int i=1;i<=n;i++){
    ll val=vec[i-1];
    res+=b.sum(n+3)-b.sum(val);
    b.add(val,1);
  }
  return res;
}

int main(){
  ll n,q;
  string s,ks;
  cin>>n>>ks>>q;
  s='0'+ks;
  vector<BIT> bv;
  for(int i=0;i<26;i++){
    BIT bk=BIT(n+5);
    bv.push_back(bk);
  }

  for(int i=1;i<=n;i++){
    int c=(int)(s[i]-'a');
    bv[c].add(i,1);
  }
  for(int i=0;i<q;i++){
    int f;
    cin>>f;
    if(f==1){
      int pos;
      char kc;
      cin>>pos>>kc;
      int c=(int)(s[pos]-'a'),nc=(int)(kc-'a');
      bv[c].add(pos,-1);
      bv[nc].add(pos,1);
      s[pos]=kc;
    }
    else{
      int ans=0;
      ll l,r;
      cin>>l>>r;
      l--;
      for(int c=0;c<26;c++){
        if(bv[c].sum(r)-bv[c].sum(l)>0) ans++;
      }
      cout<<ans<<endl;
    }
  }
}


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

#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

struct status
{
    int num;
    string result;
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> vc(n + 1, -1);
    vector<int> ac(n + 1, 0);
    vector<int> penalty(n + 1, 0);

    rep(i, m)
    {
        int number;
        string temp;
        cin >> number >> temp;
        if (temp == "AC")
        {
            if (vc[number] == -1)
            {
                ac[number] = 1;
                vc[number] = 1;
            }
        }
        else
        {
            if (vc[number] == -1)
            {
                penalty[number]++;
            }
        }
    }
    int ans_ac = 0;
    int ans_pnealty = 0;
    for (int i = 1; i < n + 1; i++)
    {
        if (ac[i] == 1)
        {
            ans_ac += ac[i];
            ans_pnealty += penalty[i];
        }
    }

    cout << ans_ac << " " << ans_pnealty << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>

char a[11],b[11],c[21];

int main(){
	int i,j,k,N,L,sum=0,s1;
	scanf("%s",&b);
	L=strlen(b);
	scanf("%d",&N);
	for(i=0;i<N;i++){
		
		scanf("%s",&a);
		strcpy(c,a);
		strcat(c,a);
		for(j=0;j<10;j++){
			if(c[j]==b[0]){
				if(L==1){
					sum++;
					goto tugi;
				}
				for(k=1;k<L-1;k++){
					if(c[j+k]!=b[k]){
						break;
					}
				}
				if(k==L-1){
					sum++;
					goto tugi;
				}
			}
		}
		tugi:;
	}
	printf("%d\n",sum);
	return 0;
}
	

Measured memory_bytes: 620
c1x, c1y, c1r = map(int, input().split())
c2x, c2y, c2r = map(int, input().split())

distance = (pow(c1y - c2y, 2) + pow(c1x - c2x, 2)) ** 0.5
if distance > c1r + c2r:
    print(4)
elif distance == c1r + c2r:
    print(3)
elif distance == abs(c1r - c2r):
    print(1)
elif distance < abs(c1r - c2r):
    print(0)
else:
    print(2)


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

#define MEM(a, b) memset(a, b, sizeof a);
#define REP(i, k) for(int i = (0); i < int(k); i++ )
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define INF (int)INT_MAX
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long L;
typedef unsigned long UL;
typedef long long LL;
typedef unsigned long long ULL;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void solve(__attribute__((unused)) int tc = 0) {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> m(h, vector<char>(w));
    REP(i, h) REP(j, w) cin >> m[i][j];

    vector<vector<int>> dp(h, vector<int>(w, 0));
    REP(i, h) {
        REP(j, w) {
            if (m[i][j] == '#') continue;
            if (i == 0 && j == 0) dp[0][0] = 1;
            else if (i == 0) dp[i][j] = dp[i][j - 1];
            else if (j == 0) dp[i][j] = dp[i - 1][j];
            else dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
        }
    }

    cout << dp[h - 1][w - 1] << endl;
    return;
}

int main() {
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    /*int TC;
      cin >> TC;
      REP(tc, TC) {
      solve(tc);
      }*/
    solve();
#ifdef TIME
    cout << "Execution time(second) : " << int(clock() * 1000.0 / CLOCKS_PER_SEC) << " ms" << endl;
#endif
}

Measured memory_bytes: 5248
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int  n,k,q;
	cin >> n >> k >> q;
	map<long int ,long int >mp;
	long int m;
	for(long int i = 1 ; i <= q ; i++)
	{
		cin >> m;
		mp[m]++;
	}
	for(int i = 1 ; i<= n ; i++ ){
		if(mp.find(i)==mp.end() && k-q<=0){
			cout<<"No";
		}
		else if(k-(q-mp[i])<=0){
			cout<<"No";
		}
		else{
			cout<<"Yes";
		}
		cout<<'\n';
	}
}

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

int main() {
  int X,N;
  cin >> X>>N;
  vector<int>P(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  int C=0;
  int c=0;
  int ANS=0;
  for(int i=0;i<100;i++){
    for(int j=0;j<N;j++){
      if(X+i!=P[j]){
        C+=1;
      }
      if(X-i!=P[j]){
        c+=1;
      }
    }
    if(c==N){
      ANS=X-i;
      break;
    }
    else if(C==N){
      ANS=X+i;
      break;
    }
    else{
      C*=0;
      c*=0;
    }
  }
  cout<<ANS<<endl;
}

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

  long int i, len;
  long int cnt = 0;
  len = S.size();

  for(i=0; i < len; i++){
    if(S.at(i) != T.at(i)){
      cnt += 1;
    }
  }

  cout << cnt << endl;
 
}

Measured memory_bytes: 3912
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int[][] a = new int[H][W];
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) a[i][j] = scanner.nextInt();

    final StringBuilder sb = new StringBuilder();
    int size = 0;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (a[i][j] % 2 == 1) {
          if (j + 1 < W && a[i][j + 1] % 2 == 1) {
            size++;
            sb.append(String.format("%d %d %d %d\n", i + 1, j + 1, i + 1, j + 2));
            a[i][j]--;
            a[i][j + 1]++;
          } else if (i + 1 < H && a[i + 1][j] % 2 == 1) {
            size++;
            sb.append(String.format("%d %d %d %d\n", i + 1, j + 1, i + 2, j + 1));
            a[i][j]--;
            a[i + 1][j]++;
          } else if (j + 1 < W) {
            size++;
            sb.append(String.format("%d %d %d %d\n", i + 1, j + 1, i + 1, j + 2));
            a[i][j]--;
            a[i][j + 1]++;
          } else if (i + 1 < H) {
            size++;
            sb.append(String.format("%d %d %d %d\n", i + 1, j + 1, i + 2, j + 1));
            a[i][j]--;
            a[i + 1][j]++;
          }
        }
      }
    }

    System.out.println(size);
    System.out.print(sb.toString());
  }
}


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

#define INF 100000000000
int n,w;
int we[100];
ll v[100];

//dp[i]: 값이 i가 되도록하는 최소 무게
ll dp[100001];

int main(){
	cin>>n>>w;
	for(int i=0; i<n; i++){
		scanf("%d %lld",we+i,v+i);
	}
	for(int i=0;i<=100000;i++){
		dp[i]=INF;
	}
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=100000;j>=v[i]; j--){
			dp[j]=min(dp[j],dp[j-v[i]]+we[i]);
		}
	}
	for(int i=100000;i>=0;i--){
		if(dp[i]<=w){
			printf("%d",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define PI 3.14159265358979323846

double a, b, x;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b >> x;
    double h = x / (a*a);
    double ans;
    if (x > (a*a*b)/2) {
        ans = atan((2*(b-h)) / a) * 180 / PI;
    } else {
        ans = atan((b*b)/(2*a*h)) * 180 / PI;
    }
    cout << setprecision(10) << ans << endl;
    return 0;
}


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

int three_min(int a,int b,int c) {
  if (((a < b) && (b < c)) || (a > b) && (b > c)) {
    return 1;
  }
  else {
    return 0;
  }
}


int main() {
  int n;
  cin >> n;
  int P[20];
  for (int i = 0 ; i < n; i++) {
    cin >> P[i];
  }
  int ans = 0;
  for (int i = 2; i < n; i++) {
    ans += three_min(P[i-2],P[i-1],P[i]);
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
 
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        long k = s.nextLong();
        int tel[] = new int[n];
        for(int i=0; i<n; i++)
        {
            tel[i] = s.nextInt();
        }
        int[] ct = new int[n];
        int town = 1;
        int chk = 1;
        int sw = 0;
        int tr = 0;
        for(int i=0; i<k; i++)
        {
            ct[town-1]++;
            town = tel[town-1];
            tr++;
            if(ct[town-1]==2)
            {
                if(sw==0)
                {
                    sw=1;
                }
                else
                {
                    chk++;
                }
            }
            else if(ct[town-1]==3)
            {
                int rem = (int) ((k-tr)%chk);
                for(int j=0; j<rem; j++)
                {
                    town = tel[town-1];
                }
                break;
            }
        }
        System.out.println(town);
    }
}


Measured memory_bytes: 60004
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N;
VI A;
VI cnt(100010, 0);

LL powmod(LL a, LL p, LL mod) {
	if (p == 0) return 1;
	if (p & 1) return (a * powmod(a, p - 1, mod)) % mod;
	LL t = powmod(a, p / 2, mod);
	return (t * t) % mod;
}

int main(void) {
	scanf("%d", &N);
	A.resize(N);
	for_each(ALL(A), [&](int &e){scanf("%d", &e);cnt[e]++;});
	LL ans = 0;
	int sum = 0;
	if (N % 2) {
		for (int i = 0; i < N; i += 2) {
			if (!((i == 0 && cnt[i] == 1) || (i && cnt[i] == 2))) {
				cout << 0 << endl;
				return 0;
			}
			sum += cnt[i];
		}
	} else {
		for (int i = 1; i < N; i += 2) {
			if (cnt[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
			sum += 2;
		}
	}
	ans = powmod(2, N / 2, MOD);
	cout << ans << endl;
}


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

double GetJiao(double a,double b)
{
    double c,ca;
    c=sqrt(a*a+b*b);
    ca=(b*b+c*c-a*a)/(2*c*b);
    return acos(ca)*180/3.1415926;
}


int main()
{
    double di,gao,tiji;
    while(cin>>di>>gao>>tiji)
    {
        double Alltiji=di*di*gao;
        double Othertiji=Alltiji-tiji;
        double bian=Othertiji*2/(di*di);
        if(bian>gao)
        {
            bian=tiji*2/(di*gao);
            printf("%.10lf\n",GetJiao(gao,bian));
        }
        else
            printf("%.10lf\n",GetJiao(bian,(double)di));
    }
    return 0;
}

Measured memory_bytes: 256
import collections

def comb(a, b):
    result = 1
    for i in range(b):
        result = result * ((a-i)/(b-i))
    return int(result)

N = int(input())
A = list(map(int, input().split()))
all_comb = 0
freq = collections.Counter(A)
for i in freq.values():
    if (i == 1) or (i == 0):
        pass
    else:
        all_comb += comb(i, 2)

for k in range(N):
    result = all_comb
    if freq[A[k]] == 1:
        pass
    else:
        tmp = comb(freq[A[k]], 2)
        result = result - tmp + tmp*((freq[A[k]]-2)/freq[A[k]])
    print(int(result))

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

int main(){
	int N;
	cin >> N;
	int ans = 0;
	for(int i=1;i<=N;i++){
		for(int x=1;x * x < i;x++){
			for(int y=1;y<=x;y++){
				for(int z=1;z<=y;z++){
					if(x*x + y*y + z*z + x*y + y*z + z*x == i){
						ans++;
						if(x == y && y != z) ans += 2;
						if(x != y && y == z) ans += 2;
						if(x != y && y != z) ans += 5;
					}
				}
			}
		}
		cout << ans << endl;
		ans = 0;
	}
}


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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

char BigAlphaToSmall(char a){
    if (a >= 65 && a <= 90){
        return a + 32;
    }
    return a;
}

char SmallAlphaToBig(char a){
    if (a >= 97 && a <= 122){
        return a - 32;
    }
    return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q;cin >> n >> q;
    vector<stack<int>> hoge(n);

    int a, b, c;
    rep_i(i, q){
        cin >> a;
        if(a == 0){
            cin >> b >> c;
            hoge[b].push(c);
            continue;
        }

        if(a == 1){
            cin >> b;
            if(hoge[b].empty()) continue;
            say(hoge[b].top())
            continue;
        }

        if(a == 2){
            cin >> b;
            if(hoge[b].empty()) continue;
            hoge[b].pop();
            continue;
        }
    }
}


Measured memory_bytes: 4256
n,k = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
v = x[0..k-1]
t = max = v.sum
(1..n-k).each do |i|
  t = t - x[i-1] + x[i+k-1]
  if max < t
    max = t
    v = x[i..i+k-1]
  end
end
e = 0
h = {}
v.each do |y|
  if h.has_key?(y)
    e += h[y]
  else
    m = (y*(y+1)/2.0)*(1.0/y)
    e += m
    h[y] = m
  end
end
puts e

Measured memory_bytes: 26772
// AOJ 341 Repeated Spell
// 2017.10.26

#include <stdio.h>
#include <string.h>

#define M 1000000007
long long a[1001][1001];
char t[1001], b[1001];

int main()
{
	int i, j, st, sb;

	scanf("%s%s", t, b);
	st = strlen(t);
	sb = strlen(b);
	for (i = 0; i <= st; i++) a[i][0] = 1;
	for (i = 1; i <= st; i++) {
		for (j = 0; j < sb; j++) {
			a[i][j+1] = a[i-1][j+1] % M;
			if (t[i-1] == b[j]) {
				a[i][j+1] = (a[i-1][j+1] + a[i-1][j]) % M;
			}
		}
	}
	printf("%lld\n", a[st][sb]);
	return 0;
}

Measured memory_bytes: 9552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main(){
    ios::sync_with_stdio(false);
    cin>>s;
    int n = s.length();
    int cnt = 0;
    ll n1=0;
    for(int i=0;i<n;i++){
        if(s[i]=='B') {
            n1+=i;
            cnt++;
        }
    }
    ll n2 = 1ll*(n-1+n-cnt)*cnt/2;
    cout<<n2-n1<<endl;
}



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int C[512],S[512],F[512];
ll solve(int N, int s) {
  ll t = 0;
  for (; s < N;) {
    if (t < S[s]) t = S[s];
    ll wait = (t % F[s] == 0) ? 0 : (F[s] - t % F[s]);
    t += wait + C[s];
    s++;
  }
  return t;
}

int main2() {
  int N = nextInt();
  REP(i, N - 1) {
    C[i] = nextInt();
    S[i] = nextInt();
    F[i] = nextInt();
  }
  REP(i, N) {
    cout << solve(N-1, i) << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  
  vector<int> d(0);
  for(int i = 0; i < N; i++){
    if(i < N-1)
      d.push_back(A[i+1]-A[i]);
    else
      d.push_back(K-A[i]+A[0]);
  }
  
  int max = d[0];
  
  for(int i = 0; i < d.size(); i++){
    if(max < d[i])
      max = d[i];
  }
  
  cout << K-max << endl;
  
  return 0;
}

Measured memory_bytes: 2168
n = int(input())
a = list(int(x) for x in input().split())
a.sort()

a_i = a[-1]

key_small, key_large = 0, n-1
border = a_i//2
while key_small < key_large-1:
    key = (key_small+key_large)//2
    if a[key] <= border:
        key_small = key
    else:
        key_large = key

p, q = a[key_small], a[key_large]

judge = a_i / 2
if abs(p-judge) < abs(q-judge):
    a_j = p
else:
    a_j = q
if a_i == a_j:
    a_j = 0
print(a_i, a_j)

Measured memory_bytes: 14428
import copy
n=int(input())
s=[]
for i in range(n):
    s.append(input())
t=copy.deepcopy(s)
s=list(set(s))
s.sort()
t.sort()
#print(s,t)
ans=[0]*len(s)
cnt=0
c=0
for i in range(n):
    if i==0:
        cnt+=1
        continue
    if t[i]!=t[i-1]:
        ans[c]=cnt
        cnt=1
        c+=1
    else:
        cnt+=1
if c!=len(s)-1:
    c+=1
    ans[c]=cnt
elif ans[len(s)-1]==0:
    ans[c]=cnt
#print(ans)
ma=max(ans)
for i in range(len(s)):
    if ans[i]==ma:
        print(s[i])


Measured memory_bytes: 127320
# include <iostream>
# include <algorithm>
# include <stdio.h> 
using namespace std;
int a[101];
int c[101];

int main(){
    int num = 0;
    int max = 0;
    int b;
   while((scanf("%d",&b)) != EOF){
        a[b]++;
    }
    for(int i = 1; i < 101 ; i++){
        if (a[i] > max) max=a[i];
    }
    for(int i = 1; i < 101 ; i++){
        if (a[i] == max){
            c[num] = i;
            num++;
        }
    }
    sort(c,c+num);
    for(int i = 0; i < num; i++){
        cout<<c[i]<<endl;
    }
}


Measured memory_bytes: 3152
import sys
input = sys.stdin.readline
n = int(input())
P = list(map(int,input().split()))

A = [[P[i], i] for i in range(len(P))]
A.sort(reverse=True)
# print(A)

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

B = Bit(n+1)
L0 = [[0] * 2 for i in range(n)]
for i in range(n):
    ind = A[i][1]
    B.add(ind+1, 1)
    s = B.sum(ind+1)
    R = [-1, -1]
    for j in range(2):
        l = -1
        r = ind+1
        m = (l+r+1)//2
        while r-l > 1:
            if B.sum(m) < s-1-j:
                l = m
            else:
                r = m
            m = (l+r+1)//2
        R[j] = r
    L0[i] = [ind+1-R[0], R[0]-R[1]]
    # print(i, ind, R, L0[i])

# print(L)
    
B = Bit(n+1)
L1 = [[0] * 2 for i in range(n)]
for i in range(n):
    ind = n-1-A[i][1]
    B.add(ind+1, 1)
    s = B.sum(ind+1)
    R = [-1, -1]
    for j in range(2):
        l = -1
        r = ind+1
        m = (l+r+1)//2
        while r-l > 1:
            if B.sum(m) < s-1-j:
                l = m
            else:
                r = m
            m = (l+r+1)//2
        R[j] = r
    L1[i] = [ind+1-R[0], R[0]-R[1]]
    # print(i, ind, R, L1[i])

# print(L0,L1)
ans = 0
for i in range(n):
    ans += (n-i) * (L0[i][0] * L1[i][1] + L0[i][1] * L1[i][0])
print(ans)

Measured memory_bytes: 125472
// --------------
// Tejas Pandey  |
// 11 - 04 - 20  |
// Atcoder BC 162|
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

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

ll mpow(ll a,ll b){
	ll res = 1;
	while(b){
		if(b&1) res *= a,res %= mod;
		a *= a;
		a %= mod;
		b >>= 1;
	}
	return res;
}

int main (void)
{
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  //cin >> t;
  while(t--){
  	//cout << "Case :" << c - t << ": ";
  	int n,k;
  	cin >> n >> k;
  	ll ans = 0;
  	ll cal[k];
  	for(int i = k;i;i--){
  		cal[i] = mpow(k/i,n);
  		for(int j = i*2;j <= k;j += i) cal[i] -= cal[j],cal[i] += mod,cal[i] %= mod;
  		ans += (i*cal[i])%mod,ans %= mod;
  	}
  	cout << ans;
  }
  return 0;
}

Measured memory_bytes: 4420
N = int(input())


for i in range(0,N // 4 + 1): # 4で除した値まで回す
    for j in range(0,N // 7 + 1):# 7で除した値まで回す
        if (4* i + 7 * j) == N:
            print("Yes")
            #print("i is", i)
            #print("j is", j)
            exit()

print("No")



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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  
  if((A+B)<(C+D)){
    cout<<"Right"<<endl;
  }
  else if((A+B)>(C+D)){
    cout<<"Left"<<endl;
  }
  else
    cout<<"Balanced"<<endl;
}


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

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



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

  int sum=0;

  sum+=min(a,k)*1;
  k-=min(a,k);

  if(k>0){
     k-=min(b,k);
  }
  if(k>0){
     sum-=min(c,k);
     k-=min(c,k);
     
  } 
  cout<<sum;
   return 0;
}



Measured memory_bytes: 3632
import java.util.*;
import static java.lang.Math.abs;
public class Main{
public static void main(String... args){
Scanner sc=new Scanner(System.in);
String string=sc.next();
int[] x=new int[26];
for(char c:string.toCharArray()){
x[c-'a']++;
}
for(int i=0;i<x.length;i++){
if(x[i]==0){
System.out.println((char)('a'+i));
return;
}
}
System.out.println("None");
}
}


Measured memory_bytes: 26156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		if(s.equals("AAA") || s.equals("BBB")) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
			
	}

}


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

int N;
vector<int> arr;

int main() {
  cin >> N;
  arr.resize(N);
  for(int i = 0; i < N; i++)
    cin >> arr[i];

  int ans = INT_MAX;
  for(int p = 1; p <= 100; p++) {
    int cur = 0;
    for(int i = 0; i < N; i++)
      cur += (arr[i] - p)*(arr[i] - p);
    ans = min(ans, cur);
  }
  cout << ans;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a==b){
        for(int i=0;i<a;i++){
            cout << a;
        }
        cout << endl;
    }
    else{
        for(int i=0;i<max(a,b);i++){
            cout << min(a,b);
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    vector<int> b = a;
    sort(b.rbegin(), b.rend());
    for(int i=0; i<n; ++i){
        if(a[i] == b[0])
            cout << b[1] << endl;
        else
            cout << b[0] << endl;
    }

    return 0;
}


Measured memory_bytes: 3200
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define mxn 20
#define mxm 26
using namespace std;
char s[mxn][mxn];
int n,m,p[mxn],a[mxn];
string t[mxn];
bool mirror(int l,int r) {
    for(int i=0;i<n;i++)
        if(s[i][l]!=s[p[i]][r])
            return 0;
    return 1;
}
void dfscol(int d,bool b) {
    if(d==m) {  puts("YES");    exit(0);    }
    if(~a[d]) {    dfscol(d+1,b);  return; }
    for(int i=d+1;i<m;i++)
        if(a[i]==-1&&mirror(d,i)) {
            a[d]=i,a[i]=d;
            dfscol(d+1,b);
            a[d]=-1,a[i]=-1;
        }
    if(b&&mirror(d,d))  a[d]=d,dfscol(d+1,0),a[d]=0;
}
void dfsrow(int d,bool b) {
    if(d==n) {  dfscol(0,m&1);  return; }
    if(~p[d]) {    dfsrow(d+1,b);  return; }
    for(int i=d+1;i<n;i++)
        if(p[i]==-1&&t[d]==t[i]) {
            p[d]=i,p[i]=d;
            dfsrow(d+1,b);
            p[d]=-1,p[i]=-1;
        }
    if(b)   p[d]=d,dfsrow(d+1,0),p[d]=0;
}
int main() {
    memset(p,-1,sizeof(p));
    memset(a,-1,sizeof(a));
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) {
        scanf("%s",s[i]);
        for(int j=0;j<m;j++)
            t[i]+=s[i][j];
        sort(t[i].begin(),t[i].end());
    }
    dfsrow(0,n&1);
    puts("NO");
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
const int mod = 1e9 + 7;
int n;
ll ans,x;
int cnt[100];
int main()
{
    scanf("%d", &n);
    for (int j = 0; j < n; ++j)
    {
        scanf("%lld", &x);
        for (int i = 0; i <= 60; ++i)
            if ((1ll << i) & x)
                ++cnt[i];
    }
    for (int i = 0; i <= 60; ++i)
    {
        ll tmp = (1ll << i) % mod;
        ans = (ans + tmp * (n - cnt[i]) % mod * cnt[i]) % mod;
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
X = [0]*60
sumA = 0
for i in A:
    for j in range(60):
        if i >> j & 1 == 1:
            X[j] += 1
    sumA += i
ans = 0
for i in range(N):
    sumA -= A[i]
    ans += sumA
    for j in range(60):
        if A[i] >> j & 1 == 1:
            X[j] -= 1
            ans += ((2**j) * (N-i-1-X[j]*2))%MOD
    ans %= MOD

print(ans)

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

class Dice{
public:
    int n1,n2,n3,n4,n5,n6;
    
    void East(){
        int t = n1;
        n1 = n4;
        n4 = n6;
        n6 = n3;
        n3 = t;
    }
    void West(){
        int t = n1;
        n1 = n3;
        n3 = n6;
        n6 = n4;
        n4 = t;
    }
    void South(){
        int t=n1;
        n1 = n5;
        n5 = n6;
        n6 = n2;
        n2 = t;
    }
    void North(){
        int t=n1;
        n1 = n2;
        n2 = n6;
        n6 = n5;
        n5 = t;
    }
};

int main() {
    Dice dice;
    int n1, n2, n3, n4, n5, n6;
    int q;
    cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    dice.n1 = n1;
    dice.n2 = n2;
    dice.n3 = n3;
    dice.n4 = n4;
    dice.n5 = n5;
    dice.n6 = n6;
    
    cin >> q;
    for(int i=0; i<q; i++){
        int a, b;
        cin >> a >> b;
        if(b == dice.n1){
            dice.South();
        }else if(b == dice.n3){
            dice.West();
            dice.South();
        }else if(b == dice.n4){
            dice.East();
            dice.South();
        }else if(b == dice.n5){
            dice.South();
            dice.South();
        }else if(b == dice.n6){
            dice.North();
        }
        if(a == dice.n3){
            dice.West();
        }else if(a == dice.n4){
            dice.East();
        }else if(a == dice.n6){
            dice.East();
            dice.East();
        }
        cout << dice.n3 << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    if A == C and B == C:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()

using namespace std;



long long dist(long long x , long long y){
	return x * x  + y * y;
}

int main(){
	// freopen("input.text" , "r" , stdin);
	// freopen("output.text" , "w" , stdout);
	long long n , d; cin >> n >> d;
	d = d * d;
	int ans = 0;
	for(int i = 0 ; i < n; ++i){
		long long x, y; cin >> x >> y;
		// cerr << dist(x , y) << endl;
		if(dist(x , y) <= d)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll h,w,n,sy,sx;
	cin>>h>>w>>n>>sy>>sx;
	string s,t;
	cin>>s>>t;
	bool ch=true;
	ll cy=sy;ll cx=sx;
	for(ll i=0;i<n;i++){
		if(s[i]=='D'){
			cy++;
			if(cy==h+1){
				ch=false;
			}
		}
		if(t[i]=='U'){
			cy--;
			if(cy==0){
				cy++;
			}
		}
	}
    cy=sy;cx=sx;
	for(ll i=0;i<n;i++){
		if(s[i]=='U'){
			cy--;
			if(cy==0){
				ch=false;
			}
		}
		if(t[i]=='D'){
			cy++;
			if(cy==h+1){
				cy--;
			}
		}
	}    cy=sy;cx=sx;
	for(ll i=0;i<n;i++){
		if(s[i]=='L'){
			cx--;
			if(cx==0){
				ch=false;
			}
		}
		if(t[i]=='R'){
			cx++;
			if(cx==w+1){
				cx--;
			}
		}
	}    cy=sy;cx=sx;
	for(ll i=0;i<n;i++){
		if(s[i]=='R'){
			cx++;
			if(cx==w+1){
				ch=false;
			}
		}
		if(t[i]=='L'){
			cx--;
			if(cx==0){
				cx++;
			}
		}
	}		
	cout << (ch? "YES":"NO");
	// your code goes here
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

int a[22][22];
int dp[22][(1<<22)];

int n;
int solve(int idx, int mask){
	if(idx == n){
		return 1;
	}
	if(dp[idx][mask] != -1){
		return dp[idx][mask];
	}
	int ans = 0;
	for(int i= 0;i<n;i++){
		if(a[idx][i] == 1){
			if(!(mask & (1<<i))){
				ans += (solve(idx+1, mask + (1<<i))% MOD);
				ans %= MOD;
			}
		}
	}
	return dp[idx][mask] = ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n;
    memset(dp, -1, sizeof(dp)); 
    for(int i= 0;i<n;i++){
    	for(int j= 0;j<n;j++){
    		cin>>a[i][j];
    	}
    }
    cout<<solve(0, 0)<<endl;
    return 0;
}




Measured memory_bytes: 724516
n = gets.chomp.split('')
a = (n[0] + n[1]).to_i
b = (n[2] + n[3]).to_i
## &&
ans = "NA"
if (a >= 1 && a <= 12) && (b >= 1 && b <= 12)
  ans = "AMBIGUOUS"
else
  ans = "YYMM" if b >= 1 && b <= 12
  ans = "MMYY" if a >= 1 && a <= 12
end

puts ans

Measured memory_bytes: 1788
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=100+10;
int n,Ans;
int a[maxn];

inline void file() {
	freopen("AGC026A.in","r",stdin);
	freopen("AGC026A.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

int main() {
//	file();
	n=read();
	For (i,1,n) a[i]=read();
	For (i,2,n)
		if (a[i]==a[i-1]) {
			if (a[i-1]!=1 && a[i+1]!=1) a[i]=1;
			else if (a[i-1]!=2 && a[i+1]!=2) a[i]=2;
			else if (a[i-1]!=3 && a[i+1]!=3) a[i]=3;
			++Ans;
		}
	printf("%d",Ans);
	return 0;
}

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


int main(){
	int N;
	cin >> N;
	set<string> shiritori;
	string S, T;
	cin >> S;
	shiritori.insert(S);
	bool ok = true;
	for(int i = 2;i <= N; i++){
		cin >> T;
		if(shiritori.count(T)){
			ok = false;
		}
		if(T[0] != S[S.size()-1]) ok = false;
		shiritori.insert(T);
		S = T;
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;

}










Measured memory_bytes: 3648