akhauriyash/Code-Regression huggingface dataset:
EPS = 1e-9

def cross(p)
  x0 = (p[2] - p[0]).to_f
  y0 = (p[3] - p[1]).to_f
  x1 = (p[6] - p[4]).to_f
  y1 = (p[7] - p[5]).to_f
  x2 = (p[4] - p[0]).to_f
  y2 = (p[5] - p[1]).to_f
  r = (y1 * x2 - x1 * y2) / (x0 * y1 - x1 * y0)
  s = (y0 * x2 - x0 * y2) / (x0 * y1 - x1 * y0)
  p[0] + r * (p[2] - p[0]) if r > -EPS && r < 1.0 + EPS && s > -EPS && s < 1.0 + EPS
end

gets.to_i.times do
  xa, ya ,xb, yb = gets.split.map(&:to_i)
  arr = []
  gets.to_i.times do
    xc, yc, xd, yd, o, l = gets.split.map(&:to_i)
    px = cross([xa, ya, xb, yb, xc, yc, xd, yd])
    arr << [px, o, l] unless px.nil?
  end
  unless arr.empty?
    arr.sort!
    _, so, sl = arr.shift
    cl = (so == 1 ? sl : 1 - sl)
  end
  p arr.reduce(0){ |cnt, (_, o, l)|
    if o != 1 && cl == l
      cl = 1 - cl; cnt + 1
    elsif o == 1 && cl != l
      cl = l; cnt + 1
    else cnt
    end
  }
end

Measured memory_bytes: 9240
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}

void Yn(bool f)
{
  cout << (f ? "Yes" : "No") << endl;
}

void yn(bool f)
{
  cout << (f ? "yes" : "no") << endl;
}

void YN(bool f)
{
  cout << (f ? "YES" : "NO") << endl;
}

int a[3];
int main()
{
  REP(i, 3){
    cin >> a[i];
  }
  Yn((a[0] < a[2] && a[2] < a[1]) || (a[1] < a[2] && a[2] < a[0]));
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	
	string s;
	cin>>s;
	
	for(int i=0;i<s.size();i++){
		s[i]=('A'+((s[i]-'A')+n)%26);
	}
	
	cout<<s;
	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++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long sum = 0;

typedef pair<int, int> Pa;
typedef long long ll;

int main() {
    cin >> N;
    cout << (N-1)/2;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

long a[21][21];

int main(int argc, char* argv[])
{
    long n, m, c;
    scanf("%ld%ld%ld", &n, &m, &c);

    vector<long> b(m);
    long i, j;
    for(i=0; i<m; i++) {
        scanf("%ld", &b[i]);
    }

    long cnt=0;
    for(i=0; i<n; i++) {
        ll sum=0;
        for(j=0; j<m; j++) {
            scanf("%ld", &a[i][j]);
            sum += a[i][j] * b[j];
        }
        sum += c;
        if(sum>0) {
            cnt++;
        }
    }
    printf("%ld\n", cnt);


    return 0;
}



Measured memory_bytes: 256
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

k=int(input())
s=input()
n=len(s)
if n<=k:
    print(s)
else:
    print(s[:k]+"...")

Measured memory_bytes: 9488
#include<bits/stdc++.h>
using namespace std;
int Y[4]={-1,0,1,0};
int X[4]={0,1,0,-1};
bool in(int a,int b){
  if(a<0||b<0||3<=a||3<=b)return false;
  return true;
}
int main(){
  int a;
  string start="",goal="123456780";
  for(int i=0;i<9;i++){
    cin>>a;
    start+=(a+'0');
  }
  queue<string> q;
  map<string,int> m;
  m[start]=0;
  q.push(start);
  while(!q.empty()){
    string u=q.front();
    q.pop();
    if(u==goal){
      cout<<m[u]<<endl;
      break;
    }
    int s=-1;
    for(int i=0;i<u.length();i++)if(u[i]=='0')s=i;
    int y=s/3,x=s%3;
    for(int i=0;i<4;i++){
      int ny=y+Y[i],nx=x+X[i];
      if(!in(ny,nx))continue;
      int g=ny*3+nx;
      string t=u;
      swap(t[s],t[g]);
      if(m.find(t)==m.end()){
        m[t]=m[u]+1;
        q.push(t);
      }
    }
  }
  return 0;
}




Measured memory_bytes: 23260
n=int(input())
m=int(input())
a=list(map(int,input().split()))
b=[list(map(int,input().split())) for _ in range(m)]
point=[0]*n
for i in range(m):
    for j in range(n):
        x=n-b[i].count(a[i]) #only target gets the point
        if a[i]==b[i][j]:
            point[j]+=1
            if a[i]==j+1:
                point[j]+=x
for i in point:
    print(i)


Measured memory_bytes: 5696
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
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(N); for (int i = 0; i < N; i++) B[i] = A[i] - i + 1;
  sort(B.begin(), B.end());
  int b = B[N / 2];
  long long ans = 0;
  for (int i = 0; i < N; i++) ans += abs(B[i] - b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;
    return 0;
}

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

int main() {
  vector<int> vec(5);
  for (int i = 0; i < 5; i++){
    cin >> vec.at(i);
  }
  int k;
  cin >> k;
  
  bool a = true;
  
  for (int i=0; i<5; i++){
    for (int j =i; j <5; j++){
      if ((vec.at(j) - vec.at(i)) > k){
        a = false;
        break;
      }
    }
  }
  if (a == true){
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}  

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

int main()
{
    int A;
    int B;
    int ans = -1;

    cin >> A >> B;

    for (int i = 1; i <= 1000; i++)
    {
        // cout << i*0.08 << endl;
        if (floor(i * 0.08) != A)
        {
            continue;
        }

        if (floor(i * 0.1) != B)
        {
            continue;
        }

        ans = i;
        break;
    }

    cout << ans << endl;
}

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

int main() {
  long long n,c=0,d=0,b;
  b = 1000000007;
  cin >> n;
  vector<long long> a(n);
  for(int i=0; i < n ; i++) {
    cin >> a.at(i);
    if(a.at(i) >= b) a.at(i) -= b;
    if(i>0){
      c += a.at(i);
      if(c >= b) c -= b; 
    }
  }
  for(int i=0; i < n-1; i++){
    d += a.at(i) * c ;
    d = d % b;
    c -= a.at(i+1);
    if(c < 0) c += b;
    
  }
  cout << d;
}


Measured memory_bytes: 4800
#include <bits/stdc++.h>
//include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
typedef long long int ll;
 
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 200005;
const ll mod = 10e8+7;
const long long int inf = 10000000000;
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);

ll cnt[N];
ll a[N];
int main()
{
	ll n;
	cin>>n;
	ll x;

	rep(i,n){
		cin>>a[i];
		cnt[a[i]]++;
	}
	ll ans = 0;
	rep(i,N){
		if(cnt[i]>1){
			ans += cnt[i]*(cnt[i]-1)/2;
			 //cout<<ans<<" "<<cnt[i]<<endl;
		}
	}
	ll res;
	//cout<<ans<<endl;
	rep(i,n){
		res = ans - cnt[a[i]]*(cnt[a[i]]-1)/2+(cnt[a[i]]-1)*(cnt[a[i]]-2)/2;
		cout<<res<<endl;
		
	}
	



}


	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

Measured memory_bytes: 4736
l = input().split()
N = int(l[0])
W = int(l[1])
products = [] # [[value, weigth]]
for i in range(N):
    l = input().split()
    products.append([int(l[0]),int(l[1])])

DP = [0 for _ in range(W+1)]
for i in range(N):
    for j in range(products[i][1], W + 1):
        product_in = DP[j - products[i][1]] + products[i][0]
        if product_in >= DP[j]:
            DP[j] = product_in
        else:
            DP[j] = DP[j]
print(DP[W])

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

int main(void){
    int n;
    int w[41];
    string s;
    while(cin >> n && n) {
        rep(j, n) {
            cin >> s;
            w[j] = s.size();
        }
        bool clear;
        int i;
        for(i=0; i<n; ++i) {
            int j = i;
            int stage = 0;
            clear = false;
            int tmp = 0;
            while(j < n) {
                tmp += w[j] ;
                if(stage == 0) {
                   if(tmp == 5) stage++, tmp = 0;
                   if(tmp > 5) break;
                }
                if(stage == 1) {
                   if(tmp == 7) stage++, tmp = 0;
                   if(tmp > 7) break;
                }
                if(stage == 2) {
                   if(tmp == 5) stage++, tmp = 0;
                   if(tmp > 5) break;
                }
                if(stage == 3) {
                   if(tmp == 7) stage++, tmp = 0;
                   if(tmp > 7) break;
                }
                if(stage == 4) {
                   if(tmp == 7) stage++, clear = true;
                   if(tmp > 7) break;
                }
                j++;
            }
            if(clear) {
                cout << i+1 << endl;
                break;
            }
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "YES" << endl;}
void no(){ cout << "NO" << endl;}

//-----------------------------------------
class segment_tree{
  private:
    ll N = 1;
    vector<vector<int>> data;
    ll def = 0;
  public:

    segment_tree(string &s){
      ll m = s.size();
      while(N < m) N *= 2;
      data.resize(2*N, vector<int>(26,0));

      for(int i=0;i<m;i++) update(i,s[i]);
    }

    void update(ll k, char a, char b = '$'){
      k += N - 1;
      data[k][a - 'a']++;
      if(b != '$') data[k][b - 'a']--;
      while(k > 0){
        k = (k-1) / 2;
        for(ll i = 0; i < 26; i++){
          data[k][i] = data[k * 2 + 1][i] +  data[k * 2 + 2][i];
        }
      }
    }

    // [a,b) のクエリを処理する
    vector<int> query_(ll a, ll b, ll k, ll l, ll r){
      // [a,b)　と [l,r) が交差しない時
      if(r <= a || b <= l) return {}; 

      // 完全に含まれている時
      if(a <= l && r <= b) return data[k];
      else{
        ll mid = (l + r) / 2;
        // 2つの子の最小値
        vector<int> vl = query_(a,b,k*2+1,l,mid);
        vector<int> vr = query_(a,b,k*2+2,mid,r);
        if(vl.size() == 0) return vr;
        if(vr.size() == 0) return vl;
        vector<int> res(26,0);
        for(ll i = 0; i < 26; i++){
          res[i] = vl[i] + vr[i];
        }
        return res;
      }
    }

    int query(ll a, ll b){
      vector<int> tmp =  query_(a, b, 0, 0, N);
      if(tmp.size() == 0) return 0;
      ll res = 0;
      for(ll i = 0; i < 26; i++){
        if(tmp[i]) res++;
      }
      return res;
    }
};
//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  string s;
  cin >> n >> s;
  segment_tree tree(s);

  ll q;
  cin >> q;
  REP(i,q){
    ll com;
    cin >> com;
    if(com == 1){
      ll p;
      char c;
      cin >> p >> c;
      p--;
      tree.update(p,c,s[p]);
      s[p] = c;
    }
    else{
      ll l, r;
      cin >> l >> r;
      l--; r--;
      cout << tree.query(l,r+1) <<endl;
    }
  }






  return 0;
}



Measured memory_bytes: 143140
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n, T);
	VEC(int, t, n);

	int ans = T;
	REP(i, n) {
		int diff = t[i];
		if (i > 0) diff -= t[i - 1];
		ans += min(T, diff);
	}
	OUT(ans)BR;

  
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll n;
	cin >> n;
	ll p = 100;
	for(ll i = 1;; i ++)
	{
		ll q = p / 100;
		p += q;
		if(p >= n)
			return cout << i, 0;	
	}





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int x; cin>>x;
  if (x==1) out("Hello World");
  int a,b; cin>>a>>b;
  out(a+b);
  

  return 0;
}


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

int const N = (1 << 18) + 5;
pair<int, int> a[N], b[N];

int c[N];

void mxx(pair<int, int> &a1, pair<int, int> &a2, pair<int, int> a3, pair<int, int> a4) {
	pair<int, int> e[4];
	e[0] = a1;
	e[1] = a2;
	e[2] = a3;
	e[3] = a4;
	sort(e, e + 4);
	int cn = unique(e, e + 4) - e;
	a1 = e[cn - 1];
	a2 = e[cn - 2];
}


int main() {
	int n;
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < (1 << n); i++) {
		cin >> a[i].first;
		a[i].second = i;
		b[i] = {0, -1};
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (1 << n); j++) {
			if (((j >> i) & 1) == 0) {
				int to = j | (1 << i);
				mxx(a[to], b[to], a[j], b[j]);
			}
		}
	}
	for (int i = 0; i < (1 << n); i++) c[i] = a[i].first + b[i].first;
	for (int i = 1; i < (1 << n); i++) c[i] = std::max(c[i], c[i - 1]);
	for (int i = 1; i < (1 << n); i++) {
		cout << c[i] << '\n';
	}
}


Measured memory_bytes: 8192
fun main() = ABC162B.main()

object ABC162B {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun main() {
        val N = readLong()
        val nums = (1..N).filterNot { it % 3 == 0L || it % 5 == 0L }
        val ans = nums.sum()
        println(ans)
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readLong() = readLine()!!.toLong()
    fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "Yes" else "No"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

Measured memory_bytes: 58964
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int t; scanf("%d", &t);
    while(t--){
        int n,d; scanf("%d %d", &n, &d);
        if(n%2 == 1){
            printf("%d\n", (n-1)*127 + d);
        } else {
            printf("%d\n", n*127 - d);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x=0,max=0;
  string name;
  cin >> n >> name;
  for(int i=0;i<n;i++){
    
    if(name[i]=='I'){
      x += 1;
    }else if(name[i]=='D') {
     x -= 1;
    }
    if(max<x){
      max = x;
    }
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int X, Y, Z;
	cin >> X >> Y >> Z;

	cout << Z << " " << X << " " << Y << endl;

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=1e9;
const double PI=acos(-1);

const int MAX=2000010;

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

void cmbInit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}


ll cmb(int n, int k){
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main() {
    ios_base::sync_with_stdio(false); 

    int k;
    cin >> k;
    string s;
    cin >> s;
    int n=k+s.size();
    vector<ll> a(n+1),b(n+1);
    a[0]=1;
    b[0]=1;
    rep(i,n) {
        a[i+1]=(a[i]*25)%MOD;
        b[i+1]=(b[i]*26)%MOD;
    }
    cmbInit();
    ll ans=0;
    rep(i,s.size()) {
        ans=(ans+(cmb(n,i)*a[n-i])%MOD)%MOD;
    }
    ans=(b[n]+MOD-ans)%MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 82356
/**
 * Title: B - Sum of Three Integers
 * Url: https://atcoder.jp/contests/abc051/tasks/abc051_b
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int k, s; cin >> k >> s;
    ll ans = 0;
    for(int x=0; x<=k; x++) {
        for(int y=0; y<=k; y++) {
            int tmp = s-x-y;
            if(tmp>=0&&tmp<=k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

long long fun(long long a)
{
	if(a<0)
	a=a*(-1);
	return a;
}
using namespace std;
int main()
{
	int n,k,j;
	long long a;
	cin>>n>>k;
	long long A[n],B[n];
	for(int i=0;i<n;i++)
	cin>>A[i];
	for(int i=0;i<n;i++)
	B[i]=200000000000;
	B[0]=0;
	for(int i=1;i<n;i++)
	{
		j=i-k;
		if(j<0)
		j=0;
		for(j;j<i;j++)
		{
			a=B[j]+fun(A[j]-A[i]);
			if(a<B[i])
			B[i]=a;
		}
	}
	cout<<B[n-1];
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
  int N, C;
  vector<int> s(100000), t(100000), c(100000);
  vector<int> sm(200002);
  vector<int> tt(200002);
  cin >> N >> C;
  for (int i = 0; i < N; ++i)  // Gets input.
    cin >> s[i] >> t[i] >> c[i];
  for (int i = 1; i <= C; ++i) {  // For each channel.
    fill(tt.begin(), tt.end(), 0);
    for (int j = 0; j < N; ++j) {  // for each program.
      if (c[j] == i) {
        ++tt[s[j] * 2 - 1];
        --tt[t[j] * 2];
      }
    }
    for (int j = 1; j < 200002; ++j) {
      tt[j] += tt[j - 1];
    }
    for (int j = 0; j < 200002; ++j) {
      if (tt[j] > 0) {
        ++sm[j];
      }
    }
  }
  cout << *max_element(sm.begin(), sm.end()) << endl;
}


Measured memory_bytes: 2944
a, b, c, x, y = map(int, input().split())
ans = 0
if c * 2 <= a + b:
    ans += min(x, y) * c * 2
    if x >= y:
        ans += min(c * 2 * (x - y), a * (x - y))
    else:
        ans += min(c * 2 * (y - x), b * (y - x))
else:
    ans = a * x + b * y
print(ans)


Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string s;cin>>s;
  string t="";
  ll n=s.size();
  rep(i,n){
    if(s[i]!='x')t+=s[i];
  }
  string u=t;
  reverse(u.begin(),u.end());
  if(u!=t){
    cout<<-1<<endl;
    return 0;
  }
  ll k=t.size();
  string res=s;
  reverse(res.begin(),res.end());
  ll a=0;
  ll b=0;
  ll ans=0;
  ll j=-1,i=-1;
  ll cnta=0,cntb=0;
  while(true){
    cnta=0;
    cntb=0;
    i++;j++;
    while(i<n&&s[i]!=u[a]){
      cnta++;i++;
    }
    while(j<n&&res[j]!=u[b]){
      cntb++;j++;
    }
    a++;b++;
    //cout<<i<<" "<<j<<" "<<cnta<<" "<<cntb<<endl;
    ans+=abs(cnta-cntb);
    if(a>=(k+1)/2)break;
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
double m,n,c[120];
double ans;
int main() {
	cin>>m>>n;
	c[0]=1.0;
	for(int x=1; x<25; x++) {
		c[x]=c[x-1]*2.0;
	}
	for(double x=1; x<=m; x+=1) {
		for(int y=0; y<25; y++) {
			if(x*c[y]>=n) {
				ans+=1.0/c[y]/m;
				break;
			}
		}
	}
	printf("%.10lf",ans);
}

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

int main() {
  int A,B,C,X;
  int ans = 0;
  cin >> A >> B >> C >> X;

  for(int i=0;i<=A;++i){
    for(int j=0;j<=B;++j){
      for(int k=0;k<=C;++k){
        if(500*i + 100*j + 50*k == X) ans += 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3572
#pragma GCC optimize(1)
#include<bits/stdc++.h>
using namespace std;
const int maxn=4;
char x[maxn];int n;
int main(){
	scanf("%s",x);
	n=strlen(x);
	if(n==2) printf("%s\n",x);
	else{
		putchar(x[2]);putchar(x[1]);putchar(x[0]);putchar('\n');
	}
	for(register int i=1;i<=n;i++);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<time.h>

using namespace std;

typedef long long ll;
typedef vector<int> VI;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	int n;
	cin >> n;
	map<ll, int> m;
	vector<ll> a(n), b;
	FOR(i, n) {
		cin >> a[i];
		m[a[i]]++;
	}
	SORT(a);
	ll o = 2;
	for (int i = 0; o <= 2000000000; i++) {
		b.push_back(o);
		o *= 2;
	}
	int cnt = 0;
	for (int i = n - 1; i >= 0; i--) {
		FOR(j, 30) {
			if (m[a[i]] && a[i] < b[j] && m[b[j] - a[i]]) {
				if (a[i] * 2 == b[j]) {
					if (m[a[i]] >= 2) {
						m[a[i]] -= 2;
						cnt++;
					}
				}
				else {
					m[a[i]]--; m[b[j] - a[i]]--;
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 40192
#include <iostream>

int main() {
  // 入力
  int a, b;
  std::cin >> a >> b;

  // 積の奇遇判定
  std::string ans = (a * b % 2) ? "Odd" : "Even";

  // 出力
  std::cout << ans << std::endl;

  return 0;
}


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll K, N;
vi A, diff;

void solve(){
    diff.resize(N);

    rep(i, N-1){
        diff[i] = A[i+1] - A[i];
    }

    diff[N-1] = A[0] + K - A[N-1];

    sort(diff.begin(), diff.end());

    cout << K - diff[N-1] << endl;
}

int main(){
    cin >> K >> N;
    A.resize(N);

    rep(i, N){
        cin >> A[i];
    }

    solve();
}


Measured memory_bytes: 1920
import bisect

A, B, Q = map(int, input().split())

S = [int(input()) for i in range(A)]
S.insert(0, -float("inf"))
S.append(float("inf"))

T = [int(input()) for i in range(B)]
T.insert(0, -float("inf"))
T.append(float("inf"))

X = [int(input()) for i in range(Q)]

for x in X:
    ans = float("inf")
    idx_a = bisect.bisect_right(S, x)
    idx_b = bisect.bisect_right(T, x)
    
    for s in [S[idx_a-1], S[idx_a]]:
        for t in [T[idx_b-1], T[idx_b]]:
            temp = abs(s-t) + min(abs(x-s), abs(x-t))
            if temp < ans:
                ans = temp
    print(ans)



Measured memory_bytes: 16144
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define per(i,x,y) for (int i=(x);i>=(y);i--)
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 1000000001
#define INF 1000000000000000001ll
#define pii pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define y1 y1_
#define mset(x,y) memset((x),(y),sizeof(x))
#define mcpy(x,y) memcpy((x),(y),sizeof(y))
using namespace std;
const ld pi=acos(-1);
const ld eps=1e-8;
template<typename T> void cmin(T &x,T y){x=y<x?y:x;}
template<typename T> void cmax(T &x,T y){x=y>x?y:x;}
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar();ll x=0;int op=1;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10);putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#ifdef mod
ll ksm(ll x,ll p){
	ll ret=1;
	for (;p;p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
ll getinv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,ll p){
	ll ret=1;
	for (;p;p>>=1,x=x*x) if (p&1) ret=ret*x;
	return ret;
}
#endif
//////////////////////////// qpow ////////////////////////////
#define N 100005
int n,m,p[N],ans,tim,col[N],head[N],cnt;
struct edge{int to,nxt;}e[N<<1];
void adde(int x,int y){e[++cnt].to=y;e[cnt].nxt=head[x];head[x]=cnt;}
void ins(int x,int y){adde(x,y);adde(y,x);}
void dfs(int u){
	col[u]=tim;
	for (int i=head[u],v;i;i=e[i].nxt){
		v=e[i].to;if (!col[v]) dfs(v);
	}
}
//#define local
int main(){
#ifdef local
	freopen("test.in","r",stdin); freopen("test.out","w",stdout);
#endif
	n=read(),m=read();
	rep (i,1,n) p[i]=read();
	rep (i,1,m){
		int x=read(),y=read();ins(x,y);
	}
	rep (i,1,n) if (!col[i]) tim++,dfs(i);
	rep (i,1,n){
		if (i==p[i]){ans++;continue;}
		int x=i,y=p[i];
		if (y<x) swap(x,y);
		if (col[x]==col[y]) ans++;
	}
	cout<<ans<<'\n';
	return 0;
}
// sample data:
/*

*/

// rest:
/*

*/

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

bool check(char ch, int n) {
  if (n % 2 == 0) {
    if (ch == 'L' || ch == 'U' || ch == 'D') {
      return true;
    } else {
      return false;
    }
  } else {
    if (ch == 'R' || ch == 'U' || ch == 'D') {
      return true;
    } else {
      return false;
    }
  }
};


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

  string S;
  cin >> S;

  bool flag = true;
  rep(i, 0, S.size()) {
    int n = i+1;
    if (!check(S[i], n)) {
      flag = false;
      break;
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
};


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

int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);
	int A[10010];
	for (int i = 0; i < M; i++) {
		scanf("%d", &A[i]);
		N -= A[i];
	}
	if (N < 0) {
		printf("-1");
	} else {
		printf("%d", N);
	}

	return 0;
}


Measured memory_bytes: 3820
#include<stdio.h>
#include<string.h>
int main(int argc,char **argv)
{
    char s [20];
    char n[50]="2018";
    scanf("%s",s);
    strncpy(s,s+4,6);
    s[6] ='\0';
    strcat(n,s);
    printf("%s\n",n);
    return 0;
}

Measured memory_bytes: 128
N,K=map(int, input().split())
if N%K==0:
    print(N%K)
elif N>=K:
    A=N//K
    B=N-(A*K)
    if B>=abs(B-K):
        print(abs(B-K))
    else:
        print(B)
else:
    if N>=abs(N-K):
        print(abs(N-K))
    else:
        print(N)

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

int main(){
    int N, M;  cin >> N >> M;
    vector<pair<long long,long long>> P(N);
    for(int i=0; i<N; i++){
        cin >> P[i].first >> P[i].second;
    }
    sort(P.begin(), P.end());
    long long ans = 0;
    for(int i=0; i<N; i++){
        long long A = P[i].first;
        long long B = P[i].second;
        if(M>B){
            M-=B;
            ans += A*B;
        }else{
            ans += A*M;
            cout << ans << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1792
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const [K, N] = lines[0].split(' ').map(Number)
    const A = lines[1].split(' ').map(Number)

    const diff = []
    diff[0] = A[0] + K - A[N - 1]
    for (let i = 1; i < N; i++) {
        diff[i] = A[i] - A[i - 1]
    }
    const max = diff.reduce((a, b) => Math.max(a, b))
    console.log(K - max)

})(input)


Measured memory_bytes: 54552
horizontals = [[int(i) for i in input().split()] for j in range(3)]
n = int(input())

for i in range(n):
    b = int(input())
    for j, k in enumerate(horizontals):
        if b in k:
            horizontals[j][k.index(b)] = 0

verticals = [[horizontals[i][j] for i in range(3)] for j in range(3)]
diagonals = [[horizontals[i][i] for i in range(3)],
            [horizontals[j][2-j] for j in range(3)]]
card = horizontals + verticals + diagonals
bingo = [0, 0, 0]
if bingo in card:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <utility>
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1e9
typedef long long int ll;
using namespace std;

int main(){
    ll K,A,B;
    cin >> K >> A >> B;
    ll biscuit=1, money=0;
    bool flag=false;
    if(B-A>=2)   flag=true;

    ll i=0;

    if(!flag){
        cout << K+1 << endl;
        return 0;
    }

    while(i<K){
        if(biscuit>=A and i+2<=K){
            biscuit+=(B-A),i+=2;
        }else{
            biscuit++, i++;
        }
    }
    
    cout << biscuit << endl;

    return 0;
}

Measured memory_bytes: 256
function Main(input){
  var data = input.split("\n")[1];
  var red=0;
  var blue=0;
  for(var i=0;i<data.length;i++){
  	if(data[i]=="B")blue++;
    if(data[i]=="R")red++;
  }
  console.log(red>blue?"Yes":"No");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  ll  n ; cin>>n  ;
  vector<ll>a(n);
  vector<ll>b(n,0);
 for(int i=0;i<n;i++){cin>>a[i];}  
  
 for(int i=n/2;i<n;i++){
 b.at(i)=a.at(i);
 } 
  
  for(int i=n/2-1;i>=0;i--){
  ll cnt=0;
    for(int k=2;k<MM;k++){
  ll t=k*(i+1)-1;
    if(t>n-1)break;
    else cnt+=b[t];
  }
    if(cnt%2!=a[i])b[i]=1;
    else b[i]=0;
  }

 deque<ll>ans;
  rep(i,n){
 if(b[i]==1)ans.push_back(i+1);

  }
  if(ans.empty())cout<<0<<endl;
else{
  cout<<ans.size()<<endl;
  rep(i,ans.size()){
    if(i==ans.size()-1)cout<<ans[i]<<endl;
  else cout<<ans[i]<<" ";
  }

}

}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 5e5 + 10;
const ll mod = 1e9 + 7;
int n, x, t;
int main() {
	scanf("%d%d%d", &n, &x, &t);
	printf("%d\n", (n + x - 1) / x * t);
	return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};int dy[4] = {0,-1,0,1};
using Graph = vector<vector<int> >;

int main() {
    int n; cin >> n;
    ll k; cin >> k;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
	cin >> a[i];
    }
    int ans;
    if(k<=n){
	ans = 1;
	for(int i=0;i<k;i++){
	    ans = a[ans];
	}
	cout << ans << endl;
    }else{
	int tmp = 1,roop;
	vector<bool> b(n+1,false);
	while(1){
	    if(b[tmp] == true){
		roop = tmp;
		break;
	    }else{
		b[tmp] = true;
		tmp = a[tmp];
	    }
	}
	int roop_count = 0,roop_made=0;
	tmp = roop;
	for(int i=0;i<n;i++){
	    tmp = a[tmp];
	    roop_count++;
	    if(tmp==roop)break;
	}
//	cout << "roop_count=" << roop_count <<endl;
	tmp = 1;	
	for(int i=0;i<n;i++){
	    tmp = a[tmp];
	    roop_made++;
	    if(tmp==roop)break;
	}
//	cout << "roop_made=" << roop_made <<endl;
	ll D = (k-roop_made)%roop_count;
	ans = roop_made + D;
	tmp = 1;
	for(int i=1;i<=ans;i++){
	    tmp = a[tmp];
	}
	cout << tmp << endl;
    }

    return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <climits>
#include <cstdlib>
using namespace std;

int main()
{
    long long int N {};
    cin>>N;
    vector<long long int> xi (N),yi (N);
    signed long long int maxxPlus {LLONG_MIN},minnPlus {LLONG_MAX};
    signed long long int maxxMinus {LLONG_MIN},minnMinus {LLONG_MAX};
    for(int i=0;i<N;i++)
    {
        cin>>xi.at(i)>>yi.at(i);
    }
    long long int posMinPlus {},posMaxPlus {};
    long long int posMinMinus {},posMaxMinus {};
    for(int i=0;i<N;i++)
    {
        if (maxxPlus<(xi.at(i)+yi.at(i)))
        {
            maxxPlus=xi.at(i)+yi.at(i);
            posMaxPlus=i;
        }
        if(minnPlus>(xi.at(i)+yi.at(i)))
        {
            minnPlus=xi.at(i)+yi.at(i);
            posMinPlus=i;
        }


        if (maxxMinus<(xi.at(i)-yi.at(i)))
        {
            maxxMinus=xi.at(i)-yi.at(i);
            posMaxMinus=i;
        }
        if(minnMinus>(xi.at(i)-yi.at(i)))
        {
            minnMinus=xi.at(i)-yi.at(i);
            posMinMinus=i;
        }

    }
    cout<<max((llabs(xi.at(posMaxPlus)-xi.at(posMinPlus))+llabs(yi.at(posMaxPlus)-yi.at(posMinPlus))),
              (llabs(xi.at(posMaxMinus)-xi.at(posMinMinus))+llabs(yi.at(posMaxMinus)-yi.at(posMinMinus))));
    return 0;
}

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

using namespace std;

// Optimization stuff
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("debug.in", "r", stdin);
    #endif // ONLINE_JUDGE
}

inline void optimizeIt() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
}
// End optimization stuff

inline double ABS(const int &x) {
    return max(x, -x);
}

inline bool isPrime(const int &x) {
    if(x == 1) return false;

    for(int d = 2; d * d <= x; d++) {
        if(x % d == 0) return false;
    }

    return true;
}

typedef long long int ll;

const int NMax = 1e6 + 5;
const int LIM = 1e6;
const int MOD = 666013;

int main(){
    //debugMode();
    optimizeIt();

    ll n;
    cin >> n;

    ll ans = 0;
    ll i;
    for(i = 1; ans < n; i++) ans += i;

    cout << i - 1;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
   string s,t;
   cin >> s >> t;
   int ans = 0;
   for(int i = 0;i<s.size()-t.size()+1;i++){
        int cnt = 0;
     for(int j = 0;j<t.size();j++){
        if(s[i+j]==t[j]) cnt++;
     }
        ans = max(ans,cnt);
   }
   cout << t.size()-ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int ans = 0;
        int cur = 0;
        for (var i = 0; i < s.Length; i++)
        {
            string c = s[i].ToString();
            if (c == "A" || c == "T" || c == "G" || c == "C")
            {
                cur += 1;
            }
            else
            {
                ans = Math.Max(cur, ans);
                cur = 0;
            }
        }
        ans = Math.Max(cur, ans);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
int n,x;
void trans(int &b,int k,int &x1,int &x2,int dlt){
	if(k==-1){
		if(b>=dlt)b-=dlt;
		else{
			dlt-=b;b=0;
			x1=min(x1+dlt,x);
			x2=max(x2-dlt,0);
		}
	}else{
		int rest=x-(b+x2);
		if(rest>=dlt)b+=dlt;
		else{
			b=min(b+dlt,x);
			dlt-=rest;
			x2=max(x2-dlt,0);
		}
	}
}
int m;
int r[100005];
int main(){
	read(x);read(n);
	rep(i,1,n)read(r[i]);
	read(m);
	int last=0;
	int b=0,k=-1,x1=0,x2=x,now=1;
	while(m--){
		int t,a;read(t);read(a);
		while(now<=n&&r[now]<=t){
			trans(b,k,x1,x2,r[now]-last);
			last=r[now];
			now++;
			k=-k;
		}
		trans(b,k,x1,x2,t-last);
		last=t;
		if(a<=x1)cout<<b<<endl;
		else if(a<=x1+x2)cout<<b+(a-x1)<<endl;
		else cout<<b+x2<<endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int A,B,M;
  cin>>A>>B>>M;
  vector<int> a(A), b(B);
  for(int i=0;i<A;i++)cin>>a[i];
  for(int j=0;j<B;j++)cin>>b[j];
  
  int ma=*min_element(a.begin(),a.end());
  int ans=1e9;
  for(int j=0;j<B;j++)ans=min(ans,ma+b[j]);

  for(int k=0;k<M;k++){
    int x,y,c;
    cin>>x>>y>>c;
    x-=1,y-=1;
    ans=min(ans,a[x]+b[y]-c);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 4040
def resolve():
    import bisect
    n, k = map(int, input().split())
    x = list(map(int, input().split()))
    ans = 10**9
    for i in range(n-k+1):
        if x[i] * x[i+k-1] < 0:
            ans = min(ans, max(abs(x[i]), abs(x[i+k-1]))+(min(abs(x[i]), abs(x[i+k-1])))*2)
        else:
            ans = min(ans, max(abs(x[i]), abs(x[i+k-1])))

    print(ans)

resolve()

Measured memory_bytes: 62576