akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N, K;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //freopen("5.txt", "r", stdin);
  cin >> N >> K;
  string s; cin >> s;
  for(int i=0; i<K-1; ++i)
    cout << s[i];
  cout << (char)tolower(s[K-1]);
  for(int i=K; i<N; ++i)
    cout << s[i];
  cout << "\n";
  return 0;  
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,h,n,a,sum=0;
  scanf("%d %d\n",&h,&n);
  for(i=0;i<n;i++){
    scanf("%d\n",&a);
    sum=sum+a;
    if(sum>=h){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
import math
n = int(input())

ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = math.gcd(i,j)
                ans = ans + math.gcd(ij,k)

print(ans)


Measured memory_bytes: 69356
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;

// 1-indexed BIT
class BIT{
    public:
    vector<ll>bit;
    int N;
    void init(int n){
        N = n;
        bit = vector<ll>(N, 0);
    }
    // [1, n] = {}
    BIT(int n = 0){
        init(n);
    }
    // sum [1, i]
    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, ll x){
        if(i == 0)return;
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};

int main(){
    ll N, K;
    cin >> N >> K;
    set<ll>S;
    S.insert(0);
    vector<ll>imos(N + 1, 0);
    for(int i = 1; i <= N; i++){
        ll A;
        cin >> A;
        // Kを引いて，和が非負の区間を数える問題にする
        ll B = A - K;
        imos[i] = imos[i - 1] + B;
        S.insert(imos[i]);
    }

    // 座標圧縮の気持ち
    map<ll, ll>M;
    int idx = 1;
    for(auto it = S.begin(); it != S.end(); it++){
        M[(*it)] = idx;
        idx++;
    }

    BIT bit(N + 2);
    bit.add(M[0], 1);
    ll ans = 0;
    for(int i = 1; i <= N; i++){
        // 累積和の要素imos[i]について，
        // それより手前にあるimos[i]以下の数だけansを増やす
        ans += bit.sum(M[imos[i]]);
        bit.add(M[imos[i]], 1);
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int h,w;
  cin>>h>>w;
  vector<string> a(h);
  for(int hi=0;hi<h;++hi) cin>>a[hi];
  
  for(int hi=-1;hi<=h;++hi) {
    for(int wi=-1;wi<=w;++wi){
        if (hi<0 or hi==h or wi<0 or wi==w) {
            cout<<"#";
        } else {
            cout<<a[hi][wi];
        }
    }
    cout<<endl;
  }
  
  return 0;
}

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


ans = 0

for i in range(1, 1000000):
    if N <= i:
        break
    # if (N-i) == i:
    #    break

    if (N - i) % i == 0:
        a = (N-i) // i
        if a <= i:
            break
        ans += a
        #print(i, (N-i) // i)

print(ans)


Measured memory_bytes: 63308
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

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

void solve() {
  ll a, b, c, d;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  if(a < b || d < b) {
    printf("No\n");
    return;
  }
  // a + m*d, mod b
  ll residue = a%b;
  ll delta = gcd(d%b, b);
  if(delta + c < b) {
    printf("No\n");
    return;
  }
  residue -= (residue / delta) * delta;
  residue += b - delta;
  if(residue > c) {
    printf("No\n");
    return;
  }
  printf("Yes\n");
}

int main() {
  int n;
  scanf("%d", &n);
  while(n--) {
    solve();
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

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

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

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  rep(i, n) {
    string s;
    cin >> s;
    m[s]++;
  }
  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;
  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){

	boost;
	// #ifndef ONLINE_JUDGE
	// 	// for getting input from input.txt
	// 	freopen("E:/c++ workspace/input.txt", "r", stdin);
	// 	// for writing output to output.txt
	// 	freopen("E:/c++ workspace/output.txt", "w", stdout);
	// #endif

	int n;
	cin>>n;
	double arr[n];

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

	sort(arr,arr+n);
	double sum = arr[0];

	for(int i=1;i<n;i++){
		sum = (double)(sum + arr[i])/2;
	}

	cout<<sum;
	return  0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

int n;
string s="Eve";

void input(){
	cin>>n;
	return;
}

void solve(){
	cout<<"Christmas"<<' ';
	n=abs(25-n);
	for(int i=0;i<n;i++){
		cout<<s<<' ';
	}
	cout<<endl;
	return;
}

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


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}


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

  ll n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  for(ll i = 0; i < m; i++){
    ll a, b;
    cin >> a >> b;
    mp[a]++, mp[b]++;
  }

  for(ll i = 1; i <= n; i++){
    cout << mp[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, ma, mb = I[:3]
abc = I[3:].reshape(n, 3)

def main():
    sa, sb = np.sum(abc, axis=0)[:2]
    res = np.full((sa+1, sb+1), np.inf)
    res[0, 0] = 0

    for a, b, c in abc:
        res[a:, b:] = np.minimum(res[a:, b:], res[:-a, :-b] + c)
    
    a = np.arange(ma, sa+1, ma)
    b = np.arange(mb, sb+1, mb)
    lim = min(sa//ma, sb//mb)
    ans = np.amin(res[a[:lim], b[:lim]])
    
    if ans == np.inf:
        return -1
    return int(ans)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 13852
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define SIZE 40

int main(){
    int N; cin>>N;
    int A[200000];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    bool trap=false;
    for(int i=1;i<N;i++){
        if(A[i]<=A[i-1]){
            trap=true;
            break;
        }
    }
    if(N==1){
        trap=false;
    }
    if(trap){//2文字以上必要
        int low=1;//不可能
        int high=200001;//可能
        //上60文字くらい見れば十分：ほんと？？？？？？？？？？？？？？
        while(low<high){
            int mid=(low+high)/2;
            //cout<<low<<' '<<mid<<' '<<high<<endl;
            if(low==mid){
                break;
            }
            //midという文字数で可能かどうか判定
            int mae[SIZE]={};
            bool flag=true;
            for(int i=1;i<N;i++){
                bool need=false;//繰り上げの必要性
                if(A[i]==A[i-1] && A[i]<SIZE){
                    mae[A[i]]++;
                    need=true;
                }else if(A[i]<A[i-1] && A[i]<SIZE){
                    mae[A[i]]++;
                    need=true;
                    for(int j=A[i]+1;j<SIZE;j++){
                        mae[j]=0;
                    }
                }
                //繰り上げ処理
                if(need){
                    for(int j=A[i];j>0;j--){
                        if(mae[j]==mid){
                            mae[j]=0;
                            mae[j-1]++;
                        }
                    }
                }
                if(mae[0]>0){
                    flag=false;
                    break;
                }
            }
            if(flag){
                high=mid;
            }else{
                low=mid;
            }
        }
        cout<<high<<endl;
    }else{
        cout<<1<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N;
    cin >> N;
    map<string, ll> A;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        A[s]++;
    }
    ll ans = 0;
    for (auto a : A)
    {
        ans += (a.second * (a.second - 1)) / 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define VEC(kata, num) (kata*)malloc(num * sizeof(kata))
#define DB puts("ok")
#define SENTINEL 1000000007
typedef long long lli;


int main()
{
    int i, r, d, x[11];
    scanf("%d%d%d",&r,&d,&x[0]);
    for(i=0; i<10; i++) {
        x[i+1] = r*x[i] - d;
        printf("%d\n",x[i+1]);
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type
#define int long long
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O 
#define openfile(file)      freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
#define testinput(file)     freopen(file".txt", "r", stdin); 
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << rl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << rl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << rl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << rl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.End()
#define rall(a)             a.rbegin(), a.rEnd()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc    
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 1000005, MAXM = 200010;
// code

int n, dp[MAXM][20], a[MAXM];
vector<int> calc(){
	vector<int> res(n+1, 0);
	for (int i = 0; i < 16; i++)
		dp[n][i] = i;
	
	for (int i = n - 1; i > 0; i--){
		int p = 1, t = 1, c = 0;
		res[i] = 1e18;
		for(int j = 0; j < 16; j++){
			while((1.0*a[i+1]/p) < (1.0*a[i]/t)){
				t*=4;
				c++;
			}
			dp[i][j] = j + dp[i+1][min(15ll, c)] + (n - i) * max(0ll, c - 15);
			p *= 4;
			res[i] = min(res[i], dp[i][j]);
		}
	}
	return res;
}

void Solve(){
    cin >> n;
	for (int i = 1; i <= n; i++){
	    cin >> a[i];
	}
	vector<int> suff = calc();
	reverse(a+1, a+n+1);
	vector<int> pref = calc();
	
	int ans = 1e18;
    for (int i = 0; i <= n; i++)
        ans = min(ans, 2*(suff[i+1] + pref[n+1-i]) + i);
        //cout << ans << ' ';
    
    cout << ans << endl;
}

signed main(){
    //openfile("task");
    FAST_IO;
    int TC = 1;
	//cin >> TC;
    while(TC--) Solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    cout << std::max(0LL, C - (A - B)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
char G[maxn][maxn];
int D[maxn][maxn];
const int Dx[4] = {-1, 0, 1, 0};
const int Dy[4] = {0, -1, 0, 1};
int main() {
	int n, m, sx, sy, dx, dy;
	scanf("%d%d", &n, &m);
	scanf("%d%d", &sx, &sy);
	scanf("%d%d", &dx, &dy);
	for(int i = 1; i <= n; ++i) scanf("%s", G[i] + 1);
	memset(D, 0x3f, sizeof D);
	auto f = [&] (int a, int b) {
		return 1 <= a && a <= n && 1 <= b && b <= m;
	};
	priority_queue< tuple<int, int, int> > Q;
	Q.emplace(0, sx, sy);
	D[sx][sy] = 0;
	while(!Q.empty()) {
		int x, y;
		tie(ignore, x, y) = Q.top();
		Q.pop();
		for(int k = 0; k < 4; ++k) {
			int nx = x + Dx[k], ny = y + Dy[k];
			if(f(nx, ny) && G[nx][ny] == '.' && D[nx][ny] > D[x][y]) {
				D[nx][ny] = D[x][y];
				Q.emplace(-D[nx][ny], nx, ny);
			}
		}
		for(int i = -2; i <= 2; ++i) {
			for(int j = -2; j <= 2; ++j) {
				int nx = x + i, ny = y + j;
				if(f(nx, ny) && G[nx][ny] == '.' && D[nx][ny] > D[x][y] + 1) {
					D[nx][ny] = D[x][y] + 1;
					Q.emplace(-D[nx][ny], nx, ny);
				}
			}
		}
	}
	printf("%d", D[dx][dy] == 0x3f3f3f3f ? -1 : D[dx][dy]);
	return 0;
}

Measured memory_bytes: 8880
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin >>a>>b>>c;
  if(a==b&&b==c&&c==a){
    cout <<"No"<< endl;
  }
    else if(a==b){
        cout << "Yes" << endl;
    }
    else if(c==b){
        cout << "Yes" << endl;
    }
    else if(a==c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}



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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

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

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

int main()
{
    ll x;
    cin >> x;
    int ans=0;
    ll money=100;
    while(1){
        if(x<=money)
            break;
            ans++;
            money+=money/100;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N, ans = 0, sum = 0;
    string S;
    cin >> N >> S;

    rep(i, S.size()) {
        if (S[i] == 'I') sum++;
        else sum--;
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int min = 1000;
  istringstream ss;
  for(int i = 0; i < S.size() - 2; i++){
    ss = istringstream(S.substr(i,3));
    int temp;
    ss >> temp;
    if(abs(temp - 753) < min)min = abs(temp - 753);
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn runlength<A: Copy + PartialEq>(xs: &Vec<A>) -> Vec<(A, usize)> {
    let m = xs.len();
    if m == 0 { return vec![]; }
    let mut count = 1;
    let mut result = vec![];
    for i in 0..m {
        if i > 0 {
            if xs[i - 1] == xs[i] {
                count += 1;
            } else {
                count = 1;
            }
        }
        if i == m - 1 || xs[i] != xs[i + 1] {
            result.push((xs[i], count));
        }
    }
    result
}

fn main() {
    let mut sc = Scanner::new();
    let s: Vec<char> = sc.chars();
    let g = runlength(&s);
    // trace!(&g);
    let mut ans: u64 = 0;
    for &(_, n) in g.iter() {
        let n = n as u64;
        ans += n * (n - 1) / 2;
    }
    for i in 0..g.len() - 1 {
        if g[i].0 == '<' && g[i + 1].0 == '>' {
            ans += max!(g[i].1, g[i + 1].1) as u64;
        }
    }
    if g[0].0 == '>' { ans += g[0].1 as u64; }
    if g[g.len() - 1].0 == '<' { ans += g[g.len() - 1].1 as u64; }

    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 10860
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);

		int[] x = new int[m];
		int[] y = new int[m];
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			x[i] = Integer.parseInt(sa[0]);
			y[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		int[] a = new int[n + 1];
		Arrays.fill(a, 1);

		Set<Integer> red = new HashSet<Integer>();
		red.add(1);
		for (int i = 0; i < m; i++) {
			a[x[i]]--;
			a[y[i]]++;
			if (red.contains(x[i])) {
				red.add(y[i]);
			}
			if (a[x[i]] == 0) {
				red.remove(x[i]);
			}
		}
		System.out.println(red.size());
	}
}


Measured memory_bytes: 47852
import sys

dic = {}
while True:
	try:
		a,b = map(str,input().split())
		page = int(b)

		if a not in dic:
			dic[a] = [page]
		else:
			dic[a].append(page)

	except EOFError:
		names = sorted(dic.keys())
		for i in range(len(names)):
			print(names[i])
			pages = sorted(dic[names[i]])
			for j in range(len(pages)):
				if j == len(pages)-1:
					print(pages[j])
				else:
					sys.stdout.write(str('{:} '.format(pages[j])))
		break

Measured memory_bytes: 7644
#include <stdio.h>

int main(void)
{
 int i,n,min,max,a[10000];
 long long sum;

 scanf("%d",&n);

 for(i=0;i<n;i++){
   scanf("%d",&a[i]);
 }

 min=a[0];
 max=a[0];
 sum=a[0];

 for(i=1;i<n;i++){
   if(a[i]<min){
       min=a[i];
   }else if(a[i]>max){
       max=a[i];
   }
   sum+=a[i];
 }

 printf("%d %d %lld\n",min,max,sum);

 return 0;
}

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
int n,m,ic,a[110],b[110],c[60],d[60],dp[55][3005],ans[60];
vector<pii>adj[60];

void solve(){
	cin >> n >> m >> ic;
    ic = min(ic,2500LL);
    FOR(i,1,m+1){
        int u,v;
        cin >> u >> v >> a[i] >> b[i];
        adj[u].pb({v,i});
        adj[v].pb({u,i});
    }
    FOR(i,1,n+1)cin >> c[i] >> d[i];
    FOR(i,1,n+1){
        if(i > 1)ans[i] = inf;
        FOR(j,0,3000)dp[i][j] = inf;
    }
    set<pair<int,pii>>s;
    s.insert({0,{1,ic}});
    while(!s.empty()){
        int tim = (*s.begin()).f, x = (*s.begin()).se.f,coins = (*s.begin()).se.se;
        s.erase(s.begin());
        if(dp[x][coins] <= tim)continue;
        dp[x][coins] = tim;
        if(coins < 2500)s.insert({tim+d[x],{x,coins+c[x]}});
        for(auto &y:adj[x]){
            if(coins >= a[y.se] && dp[y.f][coins-a[y.se]] == inf){
                s.insert({tim+b[y.se],{y.f,coins-a[y.se]}});
            }
        }
    }
    FOR(i,2,n+1){
        FOR(j,0,2500)ans[i] = min(ans[i],dp[i][j]);
    }
    FOR(i,2,n+1)cout << ans[i] << "\n";
}

signed main()
{
    //showoff;
    int t;
    //cin >> t;
    t = 1;
    while(t--){
    	solve();
    }
    
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ... 


Measured memory_bytes: 15140
#include<bits/stdc++.h>
using namespace std;
long long s[305][305];
const int INF=0x3f3f3f3f;
int main()
{
	int n,m,l;
	cin >> n >>m >>l;
	int a,b,c;
	memset(s,0x3f,sizeof(s));
	for(int i=0;i<m;i++){
		cin >> a>> b >> c;
		s[a][b] = c;
		s[b][a] = c;
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++) 
		   	for(int j=1;j<=n;j++) 	
			   if(s[i][j]>s[i][k]+s[k][j]) {
			   		s[i][j]=s[i][k]+s[k][j] ;
			   }
//	for(int i=1;i<=n;i++) {
//		for(int j=1;j<=n;j++) 
//			cout <<s[i][j] <<" ";
//		cout << endl;
//	}
	for(int i=1;i<=n;i++) 
		for(int j=1;j<=n;j++)
			s[i][j]=s[i][j]<=l?1:INF;
	
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++) 
		   	for(int j=1;j<=n;j++) 	
			   if(s[i][j]>s[i][k]+s[k][j]) {
			   		s[i][j]=s[i][k]+s[k][j] ;
			   }
	int q;
	cin >> q;
	for(int i=0;i<q;i++) {
		cin >> a >> b;
		cout << ((s[a][b]==INF)?-1:s[a][b]-1)<<endl;
	}
	return 0;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    cin >> q;
    for (int i=0; i < q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int n = a+b;
        int L = 0;
        int R = 1e9;
        while (R-L > 1){
            int M = (L+R) / 2;
            if ((min(a, b) + 1) * M < max(a, b)) L = M;
            else R = M;
        }
        int F, S;
        int u = (b-1) / R;
        a -= u;
        if (a <= R){
            F = a;
            S = n - a;
        }
        else{
            int l = 1;
            int r = b+1;
            while (r - l > 1){
                int m = (l + r) / 2;
                int U = (m-1) * R + 1;
                int ne = (b - m - 1) / R;
                U -= (u - ne);
                if (a - U >= R) l = m;
                else r = m;
            }
            int ne = (b - l - 1) / R;
            F = a + l + (u - ne);
            S = n - F;
        }
        for (int j=c-1; j < d; j++){
            if (j < F){
                if ((j+1) % (R+1) == 0){
                    cout << "B";
                }
                else cout << "A";
            }
            else{
                int J = n - j - 1;
                if ((J+1) % (R+1) == 0){
                    cout << "A";
                }
                else cout << "B";
            }
        }
        cout << endl;
    }
    return 0;
}





Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long c[100100];int a[100100];
int main()
{
	
	int n,q;long long k;
	while(cin>>n>>k>>q)
	{
	memset(a,0,sizeof(a));
	memset(c,0,sizeof(c));
	
	for(int i=1;i<=q;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=q;i++)
	{
		c[a[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		c[i]=c[i]-q+k;
		//cout<<c[i]<<" ";
		if(c[i]>0)
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
}
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main() {
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  s[k-1]=s[k-1]+'a'-'A';
  
  cout<<s<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;cin>>n;
	int odd = 0;
	ll minab = 9223372036854775807;
	ll mysum= 0;
	rep(i, n){
		ll a;cin >> a;
		chmin(minab, abs(a));
		if(a < 0){
			odd = (odd+1)%2;
		}
		mysum += abs(a);
	}
	if(odd == 0){
		cout << mysum << endl;
	}else{
		//cout << minab << endl;
		
		cout << mysum - 2*minab << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N = $stdin.gets.to_i
S = {
  'AC' => 0,
  'WA' => 0,
  'TLE' => 0,
  'RE' => 0,
}
0.upto(N - 1) do |i|
  w = $stdin.gets.strip
  S[w] += 1
end
[ 'AC', 'WA', 'TLE', 'RE' ].each do |w|
  puts "#{w} x #{S[w]}"
end


Measured memory_bytes: 14372
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	n := sc.nextInt()
	seen := make(map[string]interface{}, n)
	for i := 0; i < n; i++ {
		curr := sc.nextStr()
		if _, ok := seen[curr]; ok {
			fmt.Fprintln(wtr, "NO")
			return
		}
		seen[curr] = struct{}{}
	}
	fmt.Fprintln(wtr, "YES")
}

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 14208
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, m, q = map(int, input().split())
abcd = []
for i in range(q):
    abcd.append(readints())
# print(abcd)

tmp = []


def func(n, l):
    global tmp
    if len(l) == n:
        tmp.append(l)
        return
    if l == []:
        for i in range(1, m+1):
            func(n, []+[i])
        return
    for i in range(l[-1], m+1):
        func(n, l+[i])


func(n, [])
# print(tmp)


def func2(l):
    global abcd
    global q
    tmptmp = 0
    for i in range(q):
        # print(abcd[i])
        # print(q)
        # print(i)
        if l[abcd[i][1]-1]-l[abcd[i][0]-1] == abcd[i][2]:
            tmptmp += abcd[i][3]
    return tmptmp


tmp2 = []
for i in range(len(tmp)):
    tmp2.append(func2(tmp[i]))
# print(tmp2)
maxx = -100
for i in range(len(tmp2)):
    maxx = max(maxx, tmp2[i])

print(maxx)


Measured memory_bytes: 101204
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N; cin >> N;
	int D, A; cin >> D >> A;
	vector<pair<ll, ll>>vec(N);
	rep(i, N) {
		ll a, b;cin >> a >> b;
		vec[i] = make_pair(a, b);
	}
	sort(all(vec));
	vector<ll>num(N + 1, 0);
	ll ans = 0;
	rep(i, N) {
		ll hp = vec[i].second;
		if (num[i] < hp) {
			ll cnt = (hp - num[i] + A - 1) / A;
			ans += cnt;
			num[i] += A * cnt;

			int left = i;
			int right = vec.size();
			ll key = vec[i].first + 2LL * D;
			while (right - left > 1) {
				int mid = left + (right - left) / 2;
				if (vec[mid].first > key)right = mid;
				else left = mid;
			}
			int index = left;
			num[index + 1] -=A * cnt;
		}
		num[i + 1] += num[i];
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4992
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)
 
func run() {

	var S string;
    S = next();
	solve(S);

}
func solve(S string){
	for i , b := range S {
		if i==3 {
			break
		}
		if byte(b) == byte(S[i+1]) {
			Println("Bad")
			return
		}
	}
	Println("Good")
}


// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}


type IntHeap []int
func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

/////数字と文字
// 基本クラス
type NS struct {
    Num int
    Str string
}

//////　数字と数字
// 基本クラス
type NN struct {
    Num1 int
    Num2 int
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}



Measured memory_bytes: 2816
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

const int SZ = 200099;
int T, N, K[SZ], L[SZ], R[SZ];

ll max_happiness() {
  set<int> se;vector<int> A;
  rep(i,N) {se.insert(i+1);A.pb(i+1);}
  sort(A.begin(), A.end(), [](const int &i, const int &j){
    return (L[i]-R[i]) >= (L[j]-R[j]);
  });
  ll ans = 0;
  int i = 0;
  while((i < N) && (L[A[i]]-R[A[i]]) >= 0) {
    auto it = se.upper_bound(K[A[i]]);
    if(it == se.begin()) {ans += R[A[i]];i++;continue;}
    ans += L[A[i]];
    it--;
    se.erase(it);
    i++;
  }
  se.clear();
  for(int j = i+1;j <= N;j++)se.insert(j);
  int j = N-1;
  while(j >= i) {
    auto it = se.upper_bound(K[A[j]]);
    if(it == se.end()) {ans += L[A[j]];j--;continue;}
    ans += R[A[j]];
    se.erase(it);
    j--;
  }
  return ans;

}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 cin >> T;
 while (T--) {
   cin >> N;
   rep(i, N) cin >> K[i+1] >> L[i+1] >> R[i+1];
   cout << max_happiness() << endl;
 }

/*
1
3
1 100 80
1 115 109
2 100 95
ans should be 309 not 304

1
2
1 80 100
1 20 1000
should be 1080 not 120
*/

 return 0;
}


Measured memory_bytes: 15772
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <cstdio>
#include <cmath>

using namespace std;

typedef pair<int, int> P;

const int INF = 100000000;
const double EPS = 1e-8;

class State{
public:
  int pos, v, pre;
  double time;
  State(){}
  State(int pos, int v, int pre, double time) : pos(pos), v(v), pre(pre), time(time) {}
  bool operator < (const State& s) const { return time > s.time; }
};

int n, m, s, g;
P edge[30][30];
double cost[30][30][31];
bool vis[30][30][31];

bool equals(double a, double b){
  return fabs(a-b) < EPS;
}

void solve(){
  State u, v;
  u = State(s, 0, 0, 0.0);
  priority_queue<State> que;
  fill(vis[0][0], vis[30][0], (double)INF);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<31;k++){
        cost[i][j][k] = INF;
        vis[i][j][k] = false;
      }
    }
  }
  cost[0][0][1] = 0.0;
  for(int i=0;i<n;i++){
    if(edge[s][i].first != INF){
      cost[s][i][1] = edge[s][i].first;
      que.push(State(i, 1, s, (double)edge[s][i].first));
    }
  }
  while(!que.empty()){
    u = que.top(); que.pop();
    //cout << u.pos << ' ' << u.v << ' ' << u.pre << ' ' << u.time << endl;
    if(vis[u.pre][u.pos][u.v]) continue;
    vis[u.pre][u.pos][u.v] = true;
    if(u.pos == g && u.v == 1){
      printf("%.5f\n", u.time);
      return;
    }
    for(int i=0;i<n;i++){
      if(edge[u.pos][i].first == INF) continue;
      if(u.pre == i) continue;
      for(int k=-1;k<=1;k++){
        if(u.v + k > edge[u.pos][i].second) continue;
        if(u.v + k <= 0) continue;
        v = State(i, u.v + k, u.pos, u.time + edge[u.pos][i].first / (double)(u.v + k));
        //cout << '\t' << v.pos << ' ' << v.v << ' ' << v.pre << ' ' << v.time << ' ' << vis[v.pre][v.pos][v.v] << endl;
        if(cost[v.pre][v.pos][v.v] > v.time){
          cost[v.pre][v.pos][v.v] = v.time;
          que.push(v);
        }
      }
    }
  }
  printf("unreachable\n");
}

main(){
  while(scanf("%d%d", &n, &m) && (n|m)){
    scanf("%d%d", &s, &g);
    s--; g--;
    fill(edge[0], edge[30], P(INF, 0));
    for(int i=0;i<m;i++){
      int a, b, c, d;
      scanf("%d%d%d%d", &a, &b, &c, &d);
      a--; b--;
      edge[a][b] = edge[b][a] = P(c, d);
    }
    solve();
  }
}

Measured memory_bytes: 2388
n,k=map(int,input().split(" "))
a=[int(i)-1 for i in input().split(" ")]
was=[False]*n
pos=0
while k>0 and not was[pos]:
    was[pos]=True
    pos=a[pos]
    k-=1
if k>0:
    was=[False]*n
    cyc=0
    while not was[pos]:
        was[pos]=True
        pos=a[pos]
        cyc+=1
    k%=cyc
while k>0:
    pos=a[pos]
    k-=1
print(pos+1)

Measured memory_bytes: 90696
#include <iostream>
#include <vector>

using namespace std;

int
main()
{
	int x1, y1, x2, y2, x3, y3, x4, y4;

	cin >> x1 >> y1 >> x2 >> y2;

	if (x1 == x2) {
		if (y1 > y2) {
			x3 = (y1 - y2) + x2;
			y3 = y2;
			x4 = x3;
			y4 = y1;
		} else {
			x3 = x2 - (y2 - y1);
			y3 = y2;
			x4 = x3;
			y4 = y1;
		}
	} else {
		if (x1 < x2 && y1 > y2) {
			x3 = x2 + (y1 - y2);
			y3 = y2 + (x2 - x1);
			x4 = x3 - (x2 - x1);
			y4 = y3 + (y1- y2);
		} else if (x1 < x2 && y1 < y2) {
			x3 = x2 - (y2 - y1);
			y3 = y2 + (x2 - x1);
			x4 = x3 - (x2 - x1);
			y4 = y3 - (y2 - y1);
		} else if (x1 > x2 && y1 < y2) {
			x3 = x2 - (y2 - y1);
			y3 = y2 - (x1 - x2);
			x4 = x3 + (x1 - x2);
			y4 = y3 - (y2 - y1);
		} else {
			// (x1 > x2 && y1 > y2) 
			x3 = x2 + (y1 - y2);
			y3 = y2 - (x1 - x2);
			x4 = x3 + (x1 - x2);
			y4 = y3 + (y1 - y2);
		}
	}

	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
set<ll>s;
ll a[100006],n,k;
ll gcd(ll x,ll y)
{
    return y==0?x:gcd(y,x%y);
}
int main()
{
    scanf("%lld%lld",&n,&k);
    int ok=0,maxn=-1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==k)ok=1;
        maxn=max(maxn,a[i]);
    }
    sort(a,a+n);
    if(ok) {puts("POSSIBLE");return 0;}
    if(k>maxn) {puts("IMPOSSIBLE");return 0;}
    for(int i=1;i<n;i++)
    {
        s.insert(gcd(a[i],a[i-1]));
    }
    for(set<ll>::iterator it=s.begin();it!=s.end();it++)
    {
        if(k%*it==0)
        {
            puts("POSSIBLE");
            return 0;
        }
    }
    puts("IMPOSSIBLE");
    return 0;
}

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

int main() {
    pair<int, bool> a[4][4]; 
    rep(i, 3) {
        rep(j, 3) {
            cin >> a[i][j].first;
        }
    }
    int n; cin >> n;
    rep(i, n) {
        int x; cin >> x;
        rep(i, 3) {
            rep(j, 3) {
                if(a[i][j].first == x){
                    a[i][j].second = true;
                }
            }
        }
    }
    string ans = "No";
    rep(i, 3) {
        bool tmp = true;
        bool tmp2 = true;
        rep(j, 3) {
            tmp = tmp && a[i][j].second;
            tmp2 = tmp2 && a[j][i].second;
        }
        if(tmp || tmp2) ans = "Yes";
    }
    bool tmp = true;
    bool tmp2 = true;
    rep(i, 3) {
        tmp = a[i][i].second && tmp;
        tmp2 = a[2-i][i].second && tmp2;
    }
    if(tmp || tmp2) ans = "Yes";
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	float a,b;
	while(scanf("%f%f",&a,&b) != EOF){
		if(a < 35.50f && b < 71.00f){
			printf("AAA\n");
		}
		else if(a < 37.50f && b < 77.00f){
			printf("AA\n");
		}
		else if(a < 40.00f && b < 83.00f){
			printf("A\n");
		}
		else if(a < 43.00f && b < 89.00f){
			printf("B\n");
		}
		else if(a < 50.00f && b < 105.00){
			printf("C\n");
		}
		else if(a < 55.00f && b < 116.00f){
			printf("D\n");
		}
		else if(a < 70.00f && b < 148.00f){
			printf("E\n");
		}
		else printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define pyn(a) if(a)puts("Yes");else puts("No");
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int n,ans;
bool flag;
string s;
int main()
{
    cin>>n>>s;
    if(s.substr(0,n/2)==s.substr(n/2,n/2))flag=true;
    if(n==1||n%2==1)flag=false;
    pyn(flag);
    return 0;
}


Measured memory_bytes: 256
#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 = 4e5 + 5;


int n,cnt[105],dp[105];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n;

  for (int i=2; i<=n; i++) {
    int x = i;
    for (int j=2; x>1; j++) {
      while (x%j == 0) {
	cnt[j]++;
	x=x/j;
      }
    }
  }

  dp[1]=1;
  for (int i=1; i<=100; i++) {
    if (cnt[i]>0) {
      for (int j=75; j>=1; j--) {
	for (int x=1; x<=cnt[i]; x++) {
	  if ((x+1)*j <= 75) {
	    dp[(x+1)*j] += dp[j];
	  }
	}
      }
    }
  }

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    bool tak = true;
    while (a > 0 && c > 0) {
        if (tak)c -= b;
        else a -= d;
        tak = !tak;
    }

    cout << (tak ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 3604
N, A, B, C, *X = map(int, open(0).read().split())

def dfs(i, a, b, c):
    if i == N:
        if a * b * c == 0:
            return 10 ** 9 + 7
        return abs(A - a) + abs(B - b) + abs(C - c)

    v0 = dfs(i + 1, a, b, c)
    v1 = dfs(i + 1, a + X[i], b, c) + int(a > 0) * 10
    v2 = dfs(i + 1, a, b + X[i], c) + int(b > 0) * 10
    v3 = dfs(i + 1, a, b, c + X[i]) + int(c > 0) * 10

    return min(v0, v1, v2, v3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 43480