akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    map<int,int>mp;
    rep(i,3){
        int a,b; cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    rep(i,4)if(mp[i+1]>2)return puts("NO")*0;
    cout << "YES" << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Locale;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);
    int age = sc.nextInt();
    if (age == 1){
      System.out.println("Hello World");
      return;
    }
    int A = sc.nextInt();
    int B = sc.nextInt();

    System.out.println(A + B);
  }
}


Measured memory_bytes: 24020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> num(N, -1);
    for (int i=0; i<M; i++) {
        int si, ci;
        cin >> si >> ci;
        si--;
        if ((num[si] != -1) && (num[si] != ci)){
            cout << -1;
            return 0;
        }
        num[si] = ci;
    }
    if (N == 1) {
        if (num[0] == -1) {
            cout << 0;
            return 0;
        } else {
            cout << num[0];
            return 0;
        }
    } else {
        for (int j=0; j<N; j++){
            if (j == 0 && num[j] == 0) {
                cout << -1;
                return 0;
            }
            if (j == 0 && (num[j] == -1)){
                num[j] = 1;
            }

            if (num[j] == -1) {
                num[j] = 0;
            }
        }
    }



    // // bool first_val = true;
    // for (int j=0; j<N; j++) {
    //     if ((j == 0) && (num[j] == 0) && (N != 1)){
    //         cout << -1;
    //         return 0;
    //     } else if ((j == 0) && (num[j]==-1)) {
    //         num[j] = 1;
    //     }

    //     // if (num[j] != -1) first_val = false;
    //     // if ((j==0) && (num[j] == -1)) num[j] = 1;
    //     if (num[j] == -1){
    //         num[j] = 0;
    //     }
    // }

    int ans = 0;
    for (int k=0; k<N;k++) {
        ans = ans * 10 + num[k];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MAXN = 300;

char str[MAXN + 1];

int dp[MAXN + 1][MAXN + 1][MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, k;
    ios::sync_with_stdio(false);
    cin >> str + 1;
    int n = strlen(str + 1);
    cin >> k;
    for(i = 1; i <= n; i++) {
        for(j = 0; j <= k; j++) {
            dp[i][i][j] = 1;
        }
    }
    for(int len = 1; len <= n; len++) {
        for(i = 1; i + len <= n; i++) {
            int l = i, r = i + len;
            for(j = 0; j <= k; j++) {
                dp[l][r][j] = max(dp[l + 1][r][j], dp[l][r - 1][j]);
                if(j >= (str[l] != str[r])) {
                    dp[l][r][j] = max(dp[l][r][j], dp[l + 1][r - 1][j - (str[l] != str[r])] + 2);
                }
            }
            for(j = 1; j <= k; j++) {
                dp[l][r][j] = max(dp[l][r][j], dp[l][r][j - 1]);
            }
        }
    }
    cout << dp[1][n][k];
    //cin.close();
    //cout.close();
    return 0;
}


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

int main() {
	char n[255];
	scanf("%[^\n]", &n);
	
	int len = strlen(n);
	
	for(int i = 0; i < len; i++){
		if(n[i] == ','){
			printf(" ");
		}
		else {
			printf("%c", n[i]);
		}
	}
	printf("\n");
	return 0;
}

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

using namespace std;

int main()
{
	int nums[4];

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

	int left = nums[0] + nums[1];
	int right = nums[2] + nums[3];

	if (left == right)
	{
		cout << "Balanced" << endl;
	}
	else if (left > right)
	{
		cout << "Left" << endl;
	}
	else
	{
		cout << "Right" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

class Stack {
  private:
    int top;
    int a[100];

  public:
    static const int MAX = 100;

    Stack() {
      top = 0;
    }

    bool isEmpty() {
      return top == 0;
    }

    bool isFull() {
      return top >= MAX;
    }

    void push(int x) {
      if (isFull()) {
        cout << "full" << endl;
        return;
      }
      top++;
      a[top] = x;
    }

    int pop() {
      if (isEmpty()) {
        cout << "empty" << endl;
        return 0;
      }
      top --;
      return a[top + 1];
    }
};

int main() {
  Stack stack;
  string str;
  int x;
  while (cin >> str) {
    if (str == "+") {
      stack.push(stack.pop() + stack.pop());
    } else if (str == "-") {
      x = stack.pop();
      stack.push(stack.pop() - x);
    } else if (str == "*") {
      stack.push(stack.pop() * stack.pop());
    } else {
      stack.push(atoi(str.c_str()));
    }
  }

  cout << stack.pop() << endl;
  return 0;
}

Measured memory_bytes: 1196
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
int n,a,b,c,ans;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&n);
	for(int i=0;i*500<=n && i<=a;i++)
	  for(int j=0;i*500+j*100<=n && j<=b;j++)
	    if((n-i*500-j*100)/50<=c)ans++;
	return printf("%d\n",ans),0;
}

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

int main(){
  int n,x,in=0,nu=0;
  cin>>n>>x;
  vector<int>d(n);
  for(int i=1;i<=n;i++){
    cin>>d[i];
  }
  for(int i=1;i<=n;i++){
    in+=d[i];
    if(in<=x){
      nu++;
    }
  }
  cout<<nu+1<<endl;
}
    
    


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll res=1000;
    int id=0;
    while(id<n){
        while(id+1<n&&a[id]>=a[id+1]){
            id++;
        }
        if(id==n-1)break;
        ll p=res/a[id];
        res%=a[id];
        id++;
        res+=p*a[id];
    }
    printf("%lld\n",res);
}


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

int main()
{
  string t,p; cin>>t>>p;
  int nt = t.size();
  int np = p.size();
  if(nt < np) return 0;
  REP(i,nt-np+1) if(t[i] == p[0]) if(t.substr(i,np)==p) printf("%d\n",i);
  return 0;
}

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

int main(){
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> P(N);
  int A;
  for(int i=0; i<Q; i++){
    cin >> A;
    P.at(A-1)++;
  }
  int Ans=0;
  for(int i=0; i<N; i++){
    if(K-(Q-P.at(i))>0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1024
n = int(input())

h = list(map(int,input().split()))


dp=[float('inf')]*n
dp[0]=0


for i in range(n):
     if  i+1 < n:
          dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
     if  i+2 < n:
          dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]))
print(dp[-1])
     


Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    string str="es";
    string str1="s";
    ll l=s.size();
    if(s[l-1]=='s')
    {
        s.insert(l,str);
    }
    else
    s.insert(l,str1);
    cout<<s<<endl;
}


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

int main() {
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC" << endl;
  } else if (r < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    x, k, d = map(int, input().split())

    if x < 0:
        step = abs(x) // d
        if step >= k:
            ans = abs(x + k*d)
        else:
            residue = k - step
            residue %= 2
            ans = abs(x + (step+residue)*d)

    elif x == 0:
        k %= 2
        ans = k * d
    else:
        step = abs(x) // d
        if step >= k:
            ans = abs(x - k*d)
        else:
            residue = k - step
            residue %= 2
            ans = abs(x - (step+residue)*d)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
/**
 *  author: Behradm
 *  Created: 2020.06.27 16:31:09
 *  In The Name Of God
**/
#include <bits/stdc++.h>

using namespace std;

int main() {   
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int res = 0;
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] != t[i])
      res += 1;
  }

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


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
const ull BASE = 1e9 + 7;

vector<int> KMPTable(const string &pt) {
    int m = pt.size();
    vector<int> nx(m + 1, -1);
    int j = -1;
    for (int i = 0; i < m; i++) {
        while (j >= 0 && pt[i] != pt[j]) {
            j = nx[j];
        }
        j += 1;
        nx[i + 1] = j;
    }
    return nx;
}

vector<int> KMPSearch (const string &text, const string &pt) {
    int n = text.size(), m = pt.size();
    int start = 0;
    int pt_idx = 0;
    vector<int> ret;
    vector<int> nx = KMPTable(pt);
    while (start + pt_idx < n) {
        if (text[start + pt_idx] == pt[pt_idx]) {
            pt_idx++;
            if (pt_idx == m) {
                ret.push_back(start);
                start = start + (pt_idx - nx[pt_idx]);
                pt_idx = nx[pt_idx];
            }
        }
        else {
            if (pt_idx == 0) start++;
            else {
                start = start + (pt_idx - nx[pt_idx]);
                pt_idx = nx[pt_idx];
            }
        }
    }
    return ret;
}


string t;
string p;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> t >> p;
    vector<int> ans = KMPSearch(t, p);
    int size = ans.size();
    for (int i = 0; i < size; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 8992
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

ll cnt[10][10];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++){
        string I = to_string(i);
        int len = I.size();
        int s = I[0]-'0';
        int t = I[len-1]-'0';
        cnt[s][t]++;
    }
    ll ans = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            ans += cnt[i][j]*cnt[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def ABC162C(a,b):#ユークリッドの互除法
    while b != 0:
        a %= b
        if a == 0:break
        b %= a
    return max(a,b)

k = int(input())
p=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            p+=ABC162C(i,ABC162C(j,m))
print(p)

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

typedef long long ll;
ll ans = 0;
ll MOD = 1e9 + 7;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	for(auto && x: A) cin >> x;
	ll c1 = 0,c2 = 0;
  
	REP(i,N){
      REP(j,N){
       	if(A[i] > A[j]){
          if(i < j) c1++;
    	  c2++;
          
        }
      }
      c1 %= MOD;
      c2 %= MOD;
    }
   ans += c1 * K % MOD;
    ans %= MOD;
    ans += c2 * ( ((K * K - K) / 2)% MOD ) % MOD;
  	cout << ans % MOD << endl;
}

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

int main(void) {
    int W, H, x, y;
    cin >> W >> H >> x >> y;

    double S = (double)W*(double)H;

    cout << S/2.0 << " " << (2*x==W&&2*y==H) << endl;

    return (0);
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

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

    vector<ll> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];

    sort(all(p), greater<ll>());
    sort(all(q), greater<ll>());

    priority_queue<ll, vector<ll>, greater<ll>> pq;
    rep(i, x) pq.push(p[i]);
    rep(i, y) pq.push(q[i]);

    for (ll i : r) {
        ll v = pq.top();
        pq.pop();
        pq.push(max(v, i));
    }

    ll ans = 0;
    while (!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{ 
	ll n;
	cin>>n;
	ll arr[n+1];
	REP(i,1,n+1) cin>>arr[i];
	unordered_map<ll,ll> um;
	REP(i,1,n+1){
		um[arr[i]-i]++;
	}
	ll ct = 0;
	REP(i,1,n+1){
		ct += um[-(arr[i]+i)]; 
	}
	cout<<ct<<endl;
	return 0;	
}  


Measured memory_bytes: 19952
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>
#include <cstdio>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint h,w;

void solve(){
  while(1){
    cin >> h >> w;
    if(h==0 && w==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(i==0 || j==0 || i==h-1 || j==w-1)cout <<'#';
        else cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
}

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



Measured memory_bytes: 3096
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n;
	int p[23];
	int cnt = 0;
	scanf("%d",&n);
	for (int i = 0; i < n; ++i)	scanf("%d",&p[i]);
	for (int i = 1; i < n - 1; ++i)
	{
		if((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])){
			++cnt;
		}
	}
	printf("%d\n", cnt);
	return 0;
}


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

int main() {
  int D;
  cin >> D;
  vector<int> con(27);
  for(int i = 1; i <= 26; i++){
  	cin >> con[i];
  }
  int maxi = 0;
  int a,ans;
  for(int i = 0; i < D; i++){
  	for(int j = 0; j < 26; j++){
    	cin >> a;
      if(a > maxi){
      	ans = j+1;
      }
      maxi = max(maxi,a);
    }
    cout << ans << endl;
    maxi = 0;
    ans = 0;
  }
  
  
  
}
 

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
//#define int ll
using pii = pair <int, int>;

int Tlen[101010];
int Alen[101010];
int ans[101010];

vector <int> tree[101010];
int n, t, a;
queue <int> q;
bool vst[101010];

void print()
{
	printf("TLEN : ");
	for (int i = 1; i<=n; i++)
	{
		printf("%d ",Tlen[i]);
	}
	printf("\n");
	printf("ALEN : ");
	for (int i = 1; i<=n; i++)
	{
		printf("%d ",Alen[i]);
	}
	printf("\n");
}

int32_t main()
{
	usecppio
	cin >> n >> t >> a;
	for (int i = 1; i<n; i++)
	{
		int x, y;
		cin >> x >> y;
		tree[x].push_back(y);
		tree[y].push_back(x);
	}
	Tlen[t] = 0;
	vst[t] = 1;
	q.push(t);
	while(!q.empty())
	{
		int tp = q.front();
		q.pop();
		for (auto it:tree[tp])
		{
			if (!vst[it])
			{
				vst[it] = 1;
				Tlen[it] = Tlen[tp]+1;
				q.push(it);
			}
		}
	}
	Tlen[t] = 2;
	memset(vst,0,sizeof(vst));

	Alen[a] = 0;
	vst[a] = 1;
	q.push(a);
	while(!q.empty())
	{
		int tp = q.front();
		q.pop();
		for (auto it:tree[tp])
		{
			if (!vst[it])
			{
				vst[it] = 1;
				Alen[it] = Alen[tp]+1;
				q.push(it);
			}
		}
	}
	//print();

	for (int i = 1; i<=n; i++)
	{
		if (Tlen[i] >= Alen[i])
			Tlen[i] = 10000000;
	}

	memset(vst,0,sizeof(vst));
	Tlen[t] = 0;
	vst[t] = 1;
	q.push(t);
	while(!q.empty())
	{
		int tp = q.front();
		q.pop();
		for (auto it:tree[tp])
		{
			if (!vst[it])
			{
				vst[it] = 1;
				Tlen[it] = max(Tlen[it],Tlen[tp]+1);
				q.push(it);
			}
		}
	}
	Tlen[t] = INT_MAX;
	for (auto it:tree[t])
	{
		Tlen[t] = min(Tlen[t],Tlen[it]+1);
	}

	//print();

	int res = 0;
	for (int i = 1; i<=n; i++)
		ans[i] = Alen[i]-1;


	/*printf("ANSW : ");
	for (int i = 1; i<=n; i++)
	{
		printf("%d ",ans[i]);
	}
	printf("\n");*/
	memset(vst,0,sizeof(vst));



	vst[t] = 1;
	q.push(t);
	while(!q.empty())
	{
		int tp = q.front();
		q.pop();
		for (auto it:tree[tp])
		{
			if (!vst[it])
			{
				vst[it] = 1;
				if (Tlen[tp] >= 10000000)
					ans[it] = min(ans[it],ans[tp]);
				q.push(it);
			}
		}
	}

	for (int i = 1; i<=n; i++)
		res = max(res, ans[i]);

	/*printf("ANSW : ");
	for (int i = 1; i<=n; i++)
	{
		printf("%d ",ans[i]);
	}
	printf("\n");*/

	cout << res << '\n';
}


Measured memory_bytes: 7168
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	ll  a,b,k;
	cin>>a>>b>>k;
	if(a>=1 && a-k<=0){
		k-=a;
		a=0;
	}else if(a>=1 &&a-k>0){
		a-=k;
		cout<<a<<" "<<b<<endl;
		return 0;
	}
	if(b>=1 && b-k<=0){
		cout<<0<<" "<<0<<endl;
	}else if(b>=1 && b-k>0){
		cout<<0<<" "<<b-k<<endl;
	}
	if(b==0){
		cout<<0<<" "<<0<<endl;
	}

	return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] args) throws IOException
    {
    	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
 		String [] anArray = reader.readLine().split(" ");
      
      	int counterFor7 = 0;
        int counterFor5 = 0;
      
      	for(int i = 0; i < anArray.length; i++)
        {
        	if(Integer.parseInt(anArray[i]) == 7)
            {
            	counterFor7++;
            }
            else if(Integer.parseInt(anArray[i]) == 5)
            {
            	counterFor5++;
            }
        }
      
      	if(counterFor7 == 1 && counterFor5 == 2)
        {
        	System.out.println("YES");
        }
      	else
        {
        	System.out.println("NO");
        }
    }
}


Measured memory_bytes: 32740
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
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;}

int main(){
	int S[13],H[13],C[13],D[13];
	REP(i,13){
		S[i]=H[i]=C[i]=D[i]=0;
	}
	int n;
	cin >> n;
	REP(i,n){
		char p;
		int number;
		cin >> p >> number;
		if(p=='S') S[number-1]=1;
		else if(p=='H') H[number-1]=1;
		else if(p=='C') C[number-1]=1;
		else if(p=='D') D[number-1]=1;
	}
	REP(i,13) if(S[i]==0) cout << "S " << i+1 << endl;
	REP(i,13) if(H[i]==0) cout << "H " << i+1 << endl;
	REP(i,13) if(C[i]==0) cout << "C " << i+1 << endl;
	REP(i,13) if(D[i]==0) cout << "D " << i+1 << endl;

}

Measured memory_bytes: 1160
#A=500円の枚数、B=100円の枚数,C=50円玉の枚数,X=お年玉の金額
A = int(input())
B = int(input())
C = int(input())
X = int(input())
#答えとなる変数の定義
ans = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if(500*i+100*j+50*k == X):
                ans +=1

print(ans) 

Measured memory_bytes: 3064
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, m] <- getIntList
    print $ (comb2 n) + (comb2 m)

comb2 n = (n * (n-1)) `div` 2

Measured memory_bytes: 380
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string, str[];
		
		int n, t;
		double x, y, x1, y1, maxslope, tmp, d, h;
		while(!(string = reader.readLine()).equals("0")){
			n = Integer.valueOf(string);
			
			ArrayList<Pair> list = new ArrayList<Pair>();
			ArrayList<Integer> res = new ArrayList<Integer>();
			for(int i = 0; i < n; i++){
				str = reader.readLine().split(",");
				
				x = Double.parseDouble(str[0]);
				y = Double.parseDouble(str[1]);
				list.add(new Pair(x, y));
			}
			Collections.sort(list);
			
			double dx = list.get(0).x;
			double dy = list.get(0).y;
			
			t = 1;
			maxslope = (list.get(1).y - dy) / (list.get(1).x - dx);
			for(int i = 2; i < n; i++){
				x = list.get(i).x;
				y = list.get(i).y;
				
				tmp = (y - dy) / (x - dx);
				if(maxslope < tmp){
					maxslope = tmp;
					t = i;
				}
			}
			
			res.add(0);
			res.add(t);
			while(true){
				h = 0;
				t = 0;
				for(int i = 0; i < n; i++){
					x = list.get(i).x;
					y = list.get(i).y;
					
					x1 = list.get(res.get(res.size() - 1)).x;
					y1 = list.get(res.get(res.size() - 1)).y;
					
					dx = list.get(res.get(res.size() - 2)).x;
					dy = list.get(res.get(res.size() - 2)).y;
					
					dx = dx - x1;
					dy = dy - y1;
					
					x = x - x1;
					y = y - y1;
					
					d = ((dx * x) + (dy * y)) / (Math.hypot(dx, dy) * Math.hypot(x, y));
					d = Math.acos(d);
					if(h < d){
						t = i;
						h = d;
					}
				}
				if(t == 0) break;
				res.add(t);
			}
			
			System.out.println(n - res.size());
		}
		reader.close();
	}
}

class Pair implements Comparable<Pair>{
	double x;
	double y;
	
	Pair(double x, double y){
		this.x = x;
		this.y = y;
	}
	
	@Override
	public int compareTo(Pair o) {
		return x > o.x ? 1 : -1;
	}
}

Measured memory_bytes: 24568
n = int(input())
max_cnt = 0
cnt = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1==d2:
        cnt += 1
    else:
        max_cnt = max(max_cnt, cnt)
        cnt = 0
max_cnt = max(max_cnt, cnt)
if max_cnt >= 3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int X;

    cin >> X;

    int count500;
    int amari;

    int count5;

    int lucky500 = 0;
    int lucky5 = 0;

    if (X >= 500)
    {
        count500 = X / 500;
        amari = X % 500;

        lucky500 = count500 * 1000;

        if (amari >= 5)
        {
            count5 = amari / 5;

            lucky5 = count5 * 5;
        }
    }
    else
    {

        if (X >= 5)
        {
            count5 = X / 5;

            lucky5 = count5 * 5;
        }
    }

    cout << lucky500 + lucky5 << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = 104729;
    int counter = 0;
    boolean[] isprime = new boolean[n+1];
    for (int i = 2; i <= n; i++) {
      isprime[i] = true;
    }
    for (int i = 2; i*i <= n; i++) {
      if(isprime[i]) {
        for (int j = 2*i; j <= n; j += i) {
          isprime[j] = false;
        }
      }
    }
    while(true) {
      n = sc.nextInt();
      if(n == 0) {
        break;
      }
      int sum = 0;
      int j = 0;
      for (int i = 0; i < n;) {
        if(isprime[j]) {
          sum += j;
          i++;
        }
        j++;
      }
      System.out.println(sum);
    }
  }
}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    if ((b - a) % 2) cout << min(a + (b - a - 1) / 2, n - b + 1 + (b - a - 1) / 2) << endl;
    else cout << (b - a) / 2 << endl;
    return 0;
}


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

int main(){
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  int delx = abs(tx - sx);
  int dely = abs(ty - sy);
  for(int cnt = 0; cnt <= 1; cnt++){
    if(cnt == 1) cout << "DR";
    for(int i = 0; i < delx; i++){
      cout << 'R';
    }
    for(int i = 0; i < dely; i++){
      cout << 'U';
    }
    if(cnt == 1) cout << "ULUL";
    for(int i = 0; i < delx; i++){
      cout << 'L';
    }
    for(int i = 0; i < dely; i++){
      cout << 'D';
    }
    if(cnt == 1) cout << "DR" <<endl;
  }
}

Measured memory_bytes: 256
*T, = map(int,input().split())
*A, = map(int,input().split())
*B, = map(int,input().split())

if A[0]*T[0]+A[1]*T[1] == B[0]*T[0]+B[1]*T[1]:
    print("infinity")
else:
    if A[0]<B[0] : A,B = B,A
    if A[0]*T[0]+A[1]*T[1] > B[0]*T[0]+B[1]*T[1] :
        print(0)
    else:
        L = (A[0]-B[0]) * T[0]
        d = -((A[0]-B[0]) * T[0] + (A[1]-B[1]) * T[1])
        ans = L//d*2 + (L%d>0)
        print(ans)

Measured memory_bytes: 38256
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;

int main(){
	int n;
	cin >> n;
	int cou[101]={0};
	for(int i=0;i<n*(n-1)/2;i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		if(c > d) cou[a]+=3;
		else if(c < d) cou[b]+=3;
		else {
			cou[a]++;
			cou[b]++;
		}
	}
	P score[101];
	for(int i=1;i<=n;i++){
		P p; p.first=cou[i]; p.second=i;
		score[i-1] = p;
	}
	sort(score,score+n,greater<P>() );
	int rank[101]={0};
	for(int i=0;i<n;i++){
		if(i!=0&&score[i].first==score[i-1].first){
			rank[score[i].second] = rank[score[i-1].second];
		}
		else rank[score[i].second] = i+1;
	}
	for(int i=1;i<=n;i++){
		cout << rank[i] << endl;
	}
}

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

int main(void){
    int m,f,r,x;
    for(;;){
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1){
            break;
        }
        x =m+f;
        if(m==-1||f==-1){
            cout<<"F"<<endl;
        } else if(x>=80){
            cout<<"A"<<endl;
        } else if(x>=65&&x<80){
            cout<<"B"<<endl;
        } else if(x>=50&&x<65){
            cout<<"C"<<endl;
        } else if(x>=30&&x<50){
            if(r>=50){
                cout<<"C"<<endl;
            } else{
                cout<<"D"<<endl;
            }
        } else if(x<30){
            cout<<"F"<<endl;
        }
        
        
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }




int main() {

  int n,k;
  cin >> n >> k;

  vector<int> p(n);
  rep(i,n) cin >> p[i];

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

  int ans =0;
  for (int i= 0; i< k; i++) {
    ans += p[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

    int n,m,r,R[8];
    int g[200][200];
    cin >> n >> m >> r;
    rep(i,200){
        rep(j,200){
            if(i==j) g[i][j] = 0;
            else g[i][j] = INF;
        }
    }
    rep(i,r){
        cin >> R[i];
        R[i]--;
    }
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        g[a][b] = g[b][a] = c;
    }

    rep(k,n){
        rep(i,n){
            rep(j,n){
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }

    vector<vi> dp(1<<r, vector<int>(r,INF));
    rep(i,r) dp[1<<i][i] = 0;

    rep(i,1<<r){
        rep(j,r){
            rep(k,r){
                dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j]+g[R[j]][R[k]]);
            }
        }
    }

    int ret = INF;
    rep(i,r){
        ret = min(ret, dp[(1<<r)-1][i]);
    }

    cout << ret  << endl;
    return 0;
    
}

Measured memory_bytes: 384
/+ dub.sdl:
    name "C"
    dependency "dcomp" version=">=0.6.0"
+/

import std.stdio;
// import dcomp.scanner;

int main() {
    auto sc = new Scanner(stdin);
    long x;
    sc.read(x);
    long sm;
    foreach (i; 1..1000000) {
        sm += i;
        if (sm >= x) {
            writeln(i);
            break;
        }
    }
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}


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

int main(){
    int n, k, h[200000], dp[200000];
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> h[i];
    }
    dp[1]=0;
    for(int i=2; i<=n; i++){
        dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        for(int j=i-2; j>=i-k && j>0; j--){
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }
    cout << dp[n] << endl;
}

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

int main(){
  int a;
  cin >> a;
  int t_a = a;
  int b=0;
  while(a!=0){
    a /= 10;
    b += 1;
  }
  b--;
  int ans=0;
  if(b%2==1){
    while(b>=0){
      b--;
      ans += 9*pow(10,b);
      b--;
    }
  }else{
    ans += t_a-pow(10,b)+1;
    b--;
    while(b>=0){
      b--;
      ans += 9*pow(10,b);
      b--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		String s = sc.next();
		if(s.length()<=k) {
			System.out.println(s);
		}
		else {
			String result = s.substring(0,k);
			System.out.println(result+"...");
		}


	}

}


Measured memory_bytes: 38420
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=61
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
ld amari(ld m,ld n){
while(m>n){
m-=n;
}
return m;
}
int main() {
  ld a,b,h,m;
 ld t;
  cin>>a>>b>>h>>m;
  t=h*60+m;
  ld lx,ly;
  lx=a*(cos)((t/2)/180*pi);
  ly=a*(sin)((t/2)/180*pi);cerr<<lx<<ly;
  ld sx,sy,ts;
  ts=(amari(6*t,360)/180*pi);
  sx=b*(cos)(ts);
  sy=b*(sin)(ts);
  ld x,y;
  x=abs(sx-lx);
  y=abs(sy-ly);
  ld ans=(sqrt)(x*x+y*y);
    cout<< fixed << setprecision(15)<<ans<<endl;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 500100, MAXK = 30;
const ll MOD = 998244353;
const int INF = 1e8;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}



int main() {
	setIO();

    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x/500) * 1000;
    x%= 500;
    ans += (x/5)*5;
    cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main() {
      long n, m[5] = {};
      cin >> n;
      string s[n];
      for (long i = 0; i < n; i++) {
        cin >> s[i];
        switch(s[i][0]) {
          case 'M':
            m[0]++;
            break;
          case 'A':
            m[1]++;
            break;
          case 'R':
            m[2]++;
            break;
          case 'C':
            m[3]++;
            break;
          case 'H':
            m[4]++;
        }
      }
      cout << m[0] * m[1] * (m[2] + m[3] + m[4]) + m[0] * m[2] * (m[3] + m[4]) + m[0] * m[3] * m[4] + m[1] * m[2] * (m[3] + m[4]) + m[1] * m[3] * m[4] + m[2] * m[3] * m[4] << endl;
      return 0;
    }


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

int main() {
  int n,c=9999;
  cin>>n;
  for (int i = 0; i < n; i++){
    int a,b=0;
    cin>>a;
    while(a%2==0){
      a/=2;
      b++;
    }
    c=min(b,c);
  }
  cout << c << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		if(prime(n)) {
			System.out.println(n-1);
		}else {
			for(long i=(long)Math.sqrt(n);i>1;i--) {
				if(n%i==0) {
					System.out.println(i+n/i-2);
					break;
				}
			}
		}
	}
	public static boolean prime(long n) {
		if(n==1 || n==2)return true;
		else if(n%2==0)return false;

		for(int i=3;i<=Math.sqrt(n);i+=2) {
			if(n%i==0)return false;
		}
		return true;
	}
}



Measured memory_bytes: 23892
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int N=scan.nextInt();
    int[] a=new int[N];
    for(int i=0;i<N;i++){
      a[i]=scan.nextInt();
    }
    for(int i=0;i<N;i++){
      if(a[i]%2!=0){
        System.out.println("first");
        System.exit(0);
      }
    }
      System.out.println("second");
  }
}

Measured memory_bytes: 50040
#include<bits/stdc++.h>
#define qtr ios::sync_with_stdio(0); cin.tie(0);
#define int long long
using namespace std;

struct SegmentTree{
	vector<int> data;
	vector<int> tree;
	vector<int> lazytag;
	queue<int> q;
	queue<int> updateQueue;
	int n;
	SegmentTree(vector<int> data){
		n = data.size();
		if((1 << __lg(n)) != n){
			n = 1 << (__lg(n) + 1);
		}
		data.resize(n);
		tree.resize(2*n);
		lazytag.resize(2*n);
		for(int i = 0; i < n; i++){
			q.push((n+i)/2);
			tree[n+i] = data[i];
		}
		build();
	}
	void build(){
		while(!q.empty()){
			int index = q.front();
			int a = tree[index*2];
			int b = tree[index*2+1];
			tree[index] = a+b;
			q.pop();
			if(index / 2 == 0) continue;
			q.push(index/2);
		}
	}
	int query(int l, int r, int lt){
		queue<tuple<int,int,int>> bfs;
		int sum = 0;
		bfs.push(make_tuple(1,n,1));
		while(!bfs.empty()){
			tuple<int,int,int> top = bfs.front();
			int ll = get<0>(top);
			int rr = get<1>(top);
			int index = get<2>(top);
			int mid = (ll+rr)/2;
			bfs.pop();
			if(lazytag[index] > 0){
				passOnLazyTag(index);
			}
			if(ll >= l && rr <= r){
				if(lt > 0){
					//cout << "update push " << index << endl; 
					updateQueue.push(index/2);
					lazytag[index] += (rr-ll+1) * lt;
					passOnLazyTag(index);
				}
				sum += tree[index];
				continue;
			}
			if(r <= mid){
				bfs.push(make_tuple(ll, mid, index*2));
			}else if(l > mid){
				bfs.push(make_tuple(mid+1, rr, index*2+1));
			}else{
				bfs.push(make_tuple(ll, mid, index*2));
				bfs.push(make_tuple(mid+1, rr, index*2+1));
			}
		}
		if(!updateQueue.empty()) update();
		//print();
		return sum;
	}
	void passOnLazyTag(int index){
		tree[index] += lazytag[index];
		if(index*2 < tree.size()){
			lazytag[index*2] += lazytag[index] / 2;
		}
		if(index*2+1 < tree.size()){
			lazytag[index*2+1] += lazytag[index] / 2;
		}
		lazytag[index] = 0;
	}
	void update(){
		while(!updateQueue.empty()){
			int index = updateQueue.front();
			passOnLazyTag(index);
			passOnLazyTag(index*2);
			passOnLazyTag(index*2+1);
			tree[index] = tree[index*2] + tree[index*2+1];
			if(index / 2 != 0) updateQueue.push(index/2);
			updateQueue.pop();
		}
	}
	void print(){
		for(int i = 1; i < tree.size(); i++){
			cout << tree[i] << " "; 
		}
		cout << endl;
	}
};

int32_t main(){ qtr
	int n;
	cin >> n;
	int use = ceil(n * 1.0 / 1000);
	cout << use*1000-n << endl;
}

Measured memory_bytes: 3744
import java.util.Scanner;
public class Main
{
	static int H,W;
	static int b[][];
	static int ans;
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			W=in.nextInt();
			H=in.nextInt();
			if((W|H)==0)
				return;
			b=new int[H][W];
			for(int i=0;i<H;i++)
				for(int j=0;j<W;j++)
					b[i][j]=in.nextInt();
			ans=0;
			for(int i=0;i<H;i++)
				for(int j=0;j<W;j++)
				{
					if(b[i][j]==1)
					{
						solve(i,j);
						ans++;
					}
				}
			System.out.println(ans);
		}
	}
	public static void solve(int h, int w)
	{
		b[h][w]=0;
		for(int dh=-1;dh<=1;dh++)
			for(int dw=-1;dw<=1;dw++)
			{
				int nh=h+dh;
				int nw=w+dw;
				if(nh>=0&&nh<H&&nw>=0&&nw<W&&b[nh][nw]==1)
				{
					solve(nh,nw);
				}
			}
		return;
	}
}

Measured memory_bytes: 12000
#include <iostream>
using namespace std;
int main()
{
    int n, p, count = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> p;
        if(p < i || i < p) count++;
    }
    cout << (count > 2 ? "NO" : "YES") << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
flag=False
k=int(input())
for i in range(k+1) :
  if c*2**i>b*2**(k-i) and b*2**(k-i)>a :
    flag=True
    break

if flag :
  print('Yes')
else :
  print('No')

Measured memory_bytes: 61636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) vc<vc<T>> xs(n, vc<T>(m)); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

bool p(int n){
    if(n < 2) return false;
    for(int i = 2; i*i <= n; i ++){
        if(n % i == 0) return false;
    }
    return true;
}

int main(void){
    Cin(int, x);
    while(!p(x)) x ++;
    Cout(x);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


int main(){
   int A,B; cin >> A >> B;
   int ans = 0;
   if(B % A == 0) ans = A + B;
   else ans = B-A;
   cout << ans << endl;

  

}



Measured memory_bytes: 256