akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ull unsigned long long 
#define ul unsigned long
#define ll long long
#define pb push_back
#define sodayoda_C  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define f(i,a,b) for(int i = a;i<b;i++)
#define fb(i,a,b) for(int i = a;i>b;i--)
#define endl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
//memset(name,'',size)
//reverse(s,begin(),s.end())

using namespace std;

int main(){	
	sodayoda_C;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int t;
	//cin>>t;
	t = 1;
	while(t--){
		ll x,k,d;
		cin>>x>>k>>d;
		ll b = abs(x)/d;
		if(x>=0){
			if(b<k){
				k-=b;
				if(k%2==0){
					cout<<abs(x-b*d);
				}else{
					cout<<abs(x-(b+1)*d);
				}
			}else if(b == k){
				cout<<abs(x-b*d);
			}else{
				cout<<abs(x-k*d);
			}
		}else{
			if(b<k){
				k-=b;
				if(k%2==0){
					cout<<abs(x+b*d);
				}else{
					cout<<abs(x+(b+1)*d);
				}
			}else if(b == k){
				cout<<abs(x+b*d);
			}else{
				cout<<abs(x+k*d);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3656
package main

import (
	"fmt"
)

func main() {
	var c1,c2 string
	fmt.Scan(&c1,&c2)
	
	if c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
int en;
int f=0;

while(1){
scanf("%d",&en);
if(en==0)break;
en=1000-en;
f=0;
while(1){
if(en==0)break;
else if(en>=500){
en=en-500;
f++;
continue;
}
else if(en<500 && en>=100){
en=en-100;
f++;
continue;
}
else if(en<100 && en>=50){
en=en-50;
f++;
continue;
}
else if(en<50 && en>=10){
en=en-10;
f++;
continue;
}
else if(en<10 && en>=5){
en=en-5;
f++;
continue;
}
else if(en<5 && en>=1){
en=en-1;
f++;
continue;
}
}
printf("%d\n",f);
}
return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_120
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] abk = ReadInts();
            int a = abk[0];
            int b = abk[1];
            int k = abk[2];
            int now = 0;
            for(int i = Min(a, b); i >= 1; i--)
            {
                if (a % i == 0 && b % i == 0) now++;
                if (now == k)
                {
                    WriteLine(i);
                    return;
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define LL   long long
#define LIM  100000
#define SZ   100

LL n, capacity, dp[SZ+5][LIM+5], weight[SZ+5], val[SZ+5];
bool vis[SZ+5][LIM+5];


LL f(LL in, LL rem){
    if(in > n || rem < 0) return 0;

    if(vis[in][rem]) return dp[in][rem];
    vis[in][rem] = 1;
    LL take = 0, notTake;
    if(rem-weight[in] >= 0) take = val[in] + f(in+1, rem-weight[in]);
    notTake = f(in+1, rem);
    return dp[in][rem] = max(take, notTake);
}

int main(){
    cin>>n>>capacity;
    for(int i = 1; i <= n; i++) cin>>weight[i]>>val[i];
    LL res = f(1, capacity);
    cout<<res<<'\n';
}




Measured memory_bytes: 84920
n, a, b = gets.split.map(&:to_i)
total = 0

(1..n).each do |i|
  digit_total = 0
  i.to_s.each_char do |str|
    number = str.to_i
    digit_total += number
  end
  if digit_total >= a && digit_total <= b
    total += i
  end
end

puts total

Measured memory_bytes: 1788
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
d = sum(b)
e = d / (4*a[1])

for i in b:
    if i >= e:
        c.append(i)

if len(c) < a[1]:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

vector<int> graph[200100];
int dp[200100];

int dfs(int n) {
  if(dp[n] > 0) {
    return dp[n];
  }
  int res = 0;
  for (int v : graph[n]) {
    res = max(dfs(v) + 1, res);
  }
  return dp[n] = res;
}

int main(){
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    graph[x].push_back(y);
  }
  int ans = 0;
  rep(i, n) {
    ans = max(ans, dfs(i));
  }
  
  cout << ans << endl;

}

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

int main()
{
    int N;
    cin >> N;
    
    map<int,int> map;
    for(int i = 0; i < N; i++){
        int a,b;
        cin >> a;
        cin >> b;
        map[a] = b;
    }
    
    vector<int> key;
    for(auto m : map) {
        key.push_back(m.first);
    }
    
    int count = 0;
    count += (map.begin() -> first);//上
    count += (map.rbegin() -> second);//下
    
    for(int i = 0; i < key.size() -1 ; i++) { //全要素参照
        int fdif = abs(key[i] - key[i+1]);
        int sdif = abs(map[key[i]] - map[key[i+1]]);
        int dif = (fdif >= sdif) ? sdif : fdif; 
        count += dif;
    }

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

Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(ll i=0;i<n;i++)
#define bf(i,n)    for(ll i=n-1;i>=0;i--)


#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 bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < ll ,ll ,ll > > ;
// #define vector< ll ,ll > pv;
// vector< pair <ll,ll> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll num,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll num,ll y)
{
    if(num==0) return y;
    return gcd(y%num,num);
}

ll powM(ll num,ll y,ll m)
{
    ll ans=1,r=1;
    num%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=num;
            ans%=m;
        }
        r<<=1;
        num*=num;
        num%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,num=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=num-q*y;
        num=t;
    }
    if(num<0) num+=m0;
    return num;
}

//---------------------------------------------------------------------------

// variable = Enumpression1 ? Enumpression2 : Enumpression3
// manum = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// ll n;cin>>n;ll a[n];for(ll i=0;i<n;i++)cin>>a[i];    
// for(ll i=0;i<n;i++)cout<<a[i];
// ll a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < ll ,ll ,ll > > tv;
// vector< ll ,ll > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	ll tt=1;
   // cin>>tt;
	while(tt--)
	{
	ll num,n; cin>>num>>n;
	map <ll,bool>g;
	f(i,n)
	{
	    ll z; cin>>z;
	    g[z] = 1;
	}
	ll ind1;
	for(ind1=num;;ind1++)
	if(g[ind1]==0) 
	    break;
	ll indenum;
	for(indenum=num;;indenum--) 
	{
	    if(g[indenum]==0) 
	      break;
	}
	if( abs(num-indenum) <= abs(num-ind1) ) 
	    cout<<indenum;
	else
	    cout<<ind1;
	   
	   
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vp v;
    rep(i,n) {
        int l,r;
        cin >> l >> r;
        v.eb(l,r);
    }
    sort(all(v),[](P a,P b){ return a.second < b.second; });
    int ans = 0;
    multiset<int> st;
    int l = v[0].first;
    rep2(i,1,n) st.insert(v[i].first);
    rep2(i,1,n) {
        st.erase(st.find(v[i].first));
        int r;
        if(st.size()) r = *st.rbegin();
        else r = -inf;
        {
            int L = max(v[0].second-l+1,0);
            int R = max(v[i].second-max(r,v[i].first)+1,0);
            chmax(ans,L+R);
        }
        {
            int L = max(v[0].second-max(l,r)+1,0);
            int R = v[i].second-v[i].first+1;
            chmax(ans,L+R);
        }
        chmax(l,v[i].first);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8764
#include<stdio.h>

int main(void)
{
  int N,i;
  char S[110],T[110];
  scanf("%d%s%s",&N,S,T);
  for(i=0;i<N;i++)
    printf("%c%c",S[i],T[i]);
  printf("\n");
  return 0;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n;
  cin >> n;
  int card[4*13] = {};
  
  string type;
  int val;
  for(int i=0;i<n;i++){
      cin >> type >> val;
      val -= 1;
      if(type.compare("S")==0){
          card[val] = 1;
      }
      else if(type.compare("H")==0){
          card[val+13] = 1;
      }
      else if(type.compare("C")==0){
          card[val+13*2] = 1;
      }
      else if(type.compare("D")==0){
          card[val+13*3] = 1;
      }
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<13;j++){
        if(card[j+13*i]==0){
            switch(i){
                case 0:
                    cout << "S ";
                    break;
                case 1:
                    cout << "H ";
                    break;
                case 2:
                    cout << "C ";
                    break;
                case 3:
                    cout << "D ";
                    break;
                default:
                    break;
            }
            cout << j+1 << endl;
        }
    }
  }
  return 0;
}


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

int main() {
  int A,B,M;
  cin >> A >> B >> M;
  vector<int> p_a(A);
  vector<int> p_b(B);
  vector<vector<int>> W(M, vector<int>(3));
  
  for(int i=0; i<A; i++){
    int a=0;
    cin >> a;
    p_a.at(i)=a;
  }
  
  for(int i=0; i<B; i++){
    int b=0;
    cin >> b;
    p_b.at(i)=b;
  }
  
  for(int i=0; i<M; i++){
    int x,y,c;
    cin >> x >> y >> c;
    W.at(i).at(0) = x;
    W.at(i).at(1) = y;
    W.at(i).at(2) = c;
  }
  
  int ans = 1000000;
  for(int i=0; i<M; i++){
    int tmp = p_a.at(W.at(i).at(0)-1) + p_b.at(W.at(i).at(1)-1) - W.at(i).at(2);
    if (tmp < ans){
      ans = tmp;
    }
  }
  
  sort(p_a.begin(), p_a.end());
  sort(p_b.begin(), p_b.end());
  int tmp2 = p_a.at(0) + p_b.at(0);
  if(tmp2<ans){
    ans=tmp2;
  }
  
  cout << ans << endl;
  
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}

Measured memory_bytes: 6528
N,M,X,Y=gets.chomp.split.map(&:to_i)
x=gets.chomp.split.map(&:to_i).sort
y=gets.chomp.split.map(&:to_i).sort

if x[-1] >= y[0]
    puts "War"
    exit
end

if X >= y[0]
    puts "War"
    exit
end

if Y <= x[-1]
    puts "War"
    exit
end

puts "No War"

Measured memory_bytes: 1788
import java.io.*;

public class Main{
public static void main(String[] args){
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
	int i = 0;
	while(true){
	i++;
	String str = br.readLine();
	int x = Integer.parseInt(str);
	
		if(x == 0){
		break;
		}

	sb.append("Case ").append(i).append(": ").append(Integer.toString(x)).append("\n");
	}
	
	System.out.print(sb.toString());
}catch(IOException e){
System.out.println(e);
}
}
}

Measured memory_bytes: 24816
/* 
    Author : Jeff Ahn
    Sun 05 Jul 2020 04:51:01 AM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'

signed main() {
  fastio;
  int n;
  cin >> n;
  int pay = 1000;
  if (n % pay) {
    cout << pay - n % pay << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n;
	cin>>n;
	int a[101010]={};
	FOR(i,0,n){
		int c;
		cin>>c;
		if(c-1>=0)a[c-1]++;
		if(c+1<100001)a[c+1]++;
		a[c]++;

	}
	int mx=0;
	FOR(i,0,100001){
		mx=max(mx,a[i]);
	}
	cout<<mx<<endl;

    return 0;
}


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

#define int long long

void solve(int tt)
{
    int a,b,n;
    cin>>a>>b>>n;
    if(n>=b-1)
        n=b-1;
    cout<<((a*n)/b);
}

int32_t main()
{
    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++)
        solve(i);
}

Measured memory_bytes: 3624
N, K = gets.split(' ').map(&:to_i)

h = []
N.times do 
  h.push(gets.to_i)
end
h.sort!
op = []
(N - K + 1).times do |i|
  op.push(h[i + K - 1] - h[i])
end

puts op.min

Measured memory_bytes: 4640
#include<stdio.h>
int max(long int a, long int b) {
  if (a > b) return a;
  else return b;
}

int min(long int a, long int b) {
  if (a > b) return b;
  else return a;
}


int main(void) {
  long int A, B, C, X, Y;
  scanf("%ld%ld%ld%ld%ld", &A, &B, &C, &X, &Y);
  
  int x = X, y = Y;
  long int cost2 = x*A+y*B;
  while (cost2 > cost2 + 2*C - B - A && y-1 >= 0 && x-1 >= 0) {
    cost2 = cost2 + 2*C - B - A;
    x--, y--;
  }
  
  long int a, b, c;
  c = 2*min(X, Y);
  a = X-c/2;
  b = Y-c/2;
  long int cost = a*A + b*B + c*C;
  if (a == 0) {
    while (cost > cost + 2*C - B && b-1 >= 0) {
      cost = cost + 2*C - B;
      b--;
    }
  }
  if (b == 0) {
    while (cost > cost + 2*C - A && a-1 >= 0) {
      cost = cost + 2*C - A;
      a--;
    }
  }
  
  if (cost < cost2) printf("%ld", cost);
  else printf("%ld", cost2);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
bool judge(string a,string b){
  for(int i=0;i<a.size();i++){
    if(a.at(i)-'a'<b.at(i)-'a'){
      return true;
    }
    else if(a.at(i)-'a'>b.at(i)-'a'){
      return false;
    }
      else if(i==a.size()-1){
        return true;
      }
  }
}
int main(){
  int N,L;
  cin>>N>>L;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  for(int j=0;j<N-1;j++){
  for(int i=0;i<N-1-j;i++){
    if(!judge(S.at(i),S.at(i+1))){
      string L=S.at(i);
      S.at(i)=S.at(i+1);
      S.at(i+1)=L;
    }
  }
  }
  for(int i=0;i<N;i++){
    cout<<S.at(i);
  }
  cout<<endl;
}

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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int n;
vi a;
ll k;

int main(){
	scanf("%d", &n);
	scanf("%lld", &k);
	a.resize(n);
	for(int i = 0; i<n; i++){
		scanf("%d", &a[i]);
		a[i]--;
	}

	vi cycle;
	vector<bool> vis(n, false);
	cycle.pb(0);
	do{
		int curr = cycle.back();
		vis[curr] = true;
		int next = a[curr];
		cycle.pb(next);
	}while(vis[cycle.back()] != true);

	int inflection = cycle.back();

	vi roda;
	vi comeco;
	bool achouStart = false;
	for(int i = 0; i < sz(cycle); i++){
		if(!achouStart && cycle[i] != inflection){
			comeco.pb(cycle[i]);
		} else {
			achouStart = true;
			roda.pb(cycle[i]);
		}
	}

	roda.pop_back();

	if(k < sz(comeco)){
		cout << comeco[k] + 1 << endl;
		return 0;
	} 
	k -= sz(comeco);
	cout << roda[k%sz(roda)] + 1 << endl;
	return 0;
}


Measured memory_bytes: 6336
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    char s[1005];
    scanf("%s",s);
    if(strlen(s)==6&&s[2]==s[3]&&s[4]==s[5])
    {
        int flag=1;
        for(int i=0;i<6;i++)
        {
            if(s[i]<'a'||s[i]>'z')
            {
                flag=0;
                break;
            }
        }
        if(flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    else
        printf("No\n");
    return 0;
}


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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifndef __linux
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 1e6 + 5, INF = 0x3f3f3f3f;

int main() {
	int k; rd(k);
	bitset<MAXN> vis(1);

	int cur = 7 % k, ans = 1;
	while(!vis[cur]) {
		ans++;
		vis[cur] = 1;
		cur = (cur * 10 + 7) % k;
	}

	printf("%d\n", cur == 0 ? ans : -1);
}


Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long int
int main()
{
	int n;
	cin>>n;
	vector<ld>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	ll k=n/2+1;
	vector<vector<ld>>dp(n,vector<ld>(n/2+1,0));
	dp[0][0]=v[0];
	dp[0][1]=1-v[0];
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<k;j++)
		{
			dp[i][j]=dp[i-1][j]*v[i] + (j!=0 ? dp[i-1][j-1]*(1-v[i]) : 0);
		}
	}
	ld ans=0;
	for(int i=0;i<k;i++)
	{
		ans=ans+dp[n-1][i];
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 73788
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define sq(a) (a)*(a)
#define ms(a,v)	memset(a,v,sizeof a)
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<string, string> mss;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;  cin>>n;
  if (n==1){
    cout<<1<<"\n";
    return 0;
  }
  ll sum=1l*n*(n+1)/2;
  int n1=(n-3)/3+1;
  int n2=(n-5)/5+1;
  int n3=(n-15)/15+1;
  ll sum1=0,sum2=0,sum3=0;

  if (n1>0){
    sum1=1ll*n1*(6+(n1-1)*3)/2;
  }
  if (n2>0){
    sum2=1ll*n2*(10+(n2-1)*5)/2;
  }
  if (n3>0){
    sum3=1ll*n3*(30+(n3-1)*15)/2;
  }
  cout<<sum-sum1-sum2+sum3<<"\n";
    return 0;
}


Measured memory_bytes: 3652
s = gets.chomp.reverse

pattern = ['dream', 'dreamer', 'erase', 'eraser'].map(&:reverse)

while s != ""
  status = false
  for i in pattern
    if i == s[0..i.length-1]
      s = s[i.length..-1]
      status = true
      break
    end
  end
  if !status
    puts "NO"
    exit
  end
end

puts "YES"

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

int main(){
  int h, w;
  cin >> h >> w;
  char S[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> S[i][j];
    }
  }
  string ans = "Yes";
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(S[i][j]=='#'){
        if(j>0 && S[i][j-1]=='#'){
          continue;
        }
        if(j<(w-1) && S[i][j+1]=='#'){
          continue;
        }
        if(i>0 && S[i-1][j]=='#'){
          continue;
        }
        if(i<(h-1) && S[i+1][j]=='#'){
          continue;
        }
        ans = "No";
      }
    }
  }
  cout << ans << endl;
  return 0;

}



Measured memory_bytes: 256
#include <stdio.h>
#define N 101
#define BLACK 0
#define WHITE 1
#define GRAY -1
 
 
int a[N][N];
 
int n;
int color[N];
int time=0;
int d[N];
int k;
int head=0,tail=0;
int queue[N];
 
void BFS (int);
 
void Enqueue(int u){
    if(tail == N)tail=0;
    queue[tail] =u;
    tail++;
}
 
int Dequeue(void){
    if(head==N)head=0;
    return queue[head++];
     
}
 
 
 
int main(void){
    int t,u,i,j;
 
     
     
    scanf("%d",&n);
     
     
   for(i=1;j<=n;i++){
        for(j=1;j<=n;j++){
            a[i][j]=0;
        }
    }
     
    for(i=1;i<=n;i++){
        scanf("%d",&u);
        scanf("%d",&k);
        for(j=1;j<=k;j++){
            scanf("%d",&t);
            a[i][t] =1;
        }
         
    }
     
 
      BFS(1);
         
        for(i=1;i<=n;i++){
            if(d[i]==2147483647)d[i]=-1;
            printf("%d %d",i,d[i]);
            printf("\n");
        }
         
    return 0;
}
   
void BFS(int s){
        int u,v,i;
        int empty=0;
         
         
        for(u=1;u<=n;u++){
            color[u]=WHITE;
            d[u]=2147483647;
        }
         
        color[s]=GRAY;
        d[s]=0;
 
     
        Enqueue(s);
        empty++;
         
        while(empty!=0){
            u=Dequeue();
            empty--;
            for(v=1;v<=n;v++){
               //v=a[u][v];
                if(color[v] == WHITE && a[u][v]==1){
                    color[v]=GRAY;
                    d[v]=d[u]+1;
                    Enqueue(v);
                    empty++;
                }
            }
           //
            color[u]=BLACK;
        }
    
         
}

Measured memory_bytes: 640
#include <stdio.h>

int main(int argc, char*argv[]){

    int a, b;
    int sum;

    b = 0;

    scanf("%d",&a);

while(b == 0){
    if(1<=a && a<=10){
        sum = a + a*a + a*a*a;
        printf("%d",sum);
        return 0;
    }else{
        printf("1から10の値を入力してね！");
        b = 1;

    }
}
}

Measured memory_bytes: 1728
import java.util.*;

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

        long a = sc.nextLong();
        long b = sc.nextLong();

        long tmp = 0;
        while ((tmp = a % b) != 0){
            a = b;
            b = tmp;
        }

//        System.out.println(b);

        long ans = 0;

//        boolean flag = false;

//        if (b%2==0) ans++;

        double sqrt = Math.sqrt(b);

        for (int i=2; i<=sqrt; i++){
            if (b%i==0){
                ans++;
                while (b%i==0){
                    b /= i;
                }
            }
        }

        if (b!=1){
            ans++;
        }



        System.out.println(ans+1);
    }
}




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

class Cmondai
{
    static void Main()
    {
        var n=Int32.Parse(Console.ReadLine());
        var list = new List<long>();
        for (int i = 0; i < n; ++i) list.Add(Int64.Parse(Console.ReadLine()));
        var line=list.OrderBy(x=>x).ToArray();
        var ans = 0L;
        var m = n / 2;
        if (n % 2 == 0)
        {         
            for (int i=0;i<n;++i)
            {
                if (i < m - 1) ans += (-2) * line[i];
                else if (i == m - 1) ans -= line[i];
                else if (i == m) ans += line[i];
                else ans += 2 * line[i];
            }
        }
        else
        {
            var a = 0L;
            var b = 0L;
            for (int i=0;i<n;++i)
            {
                if (i == m || i == m + 1) a += line[i];
                else if (i < m) a -= 2 * line[i];
                else a += 2 * line[i];
            }
            for (int i=0;i<n;++i)
            {
                if (i == m - 1 || i == m) b -= line[i];
                else if (i < m - 1) b -= 2 * line[i];
                else b += 2 * line[i];
            }
            ans = Math.Max(a,b);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 23772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 1e5+5;
int v[N_MAX];
int s[N_MAX];

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,C;cin >> N >> C;
  vector<pair<int,PII> > in(N); 
  rep(i,N) cin >> in[i].second.first >> in[i].second.second >> in[i].first;
  sort(all(in));
  in.push_back(pair<int,PII>(31,PII(1,0)));
  int pc = in[0].first;
  int px = in[0].second.first;
  int py = in[0].second.second;
  rep(i,N){
    int c = in[i+1].first;
    int x = in[i+1].second.first;
    int y = in[i+1].second.second;
    if(pc == c && py == x){
      py = y;
    }else{
      --px;
      ++v[px];
      --v[py];
      pc = c;
      px = x;
      py = y;
    }
  }
  int maximum = 0;
  rep(i,N_MAX){
    s[i+1] = s[i] + v[i];
    maximum = max(maximum,s[i]);
  }
  cout << maximum << endl;
  return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i=0;i<n;i++) a[i] = sc.nextLong();
		sc.close();

		int count = 1;
		int[] b = new int[n-1];
		for(int i=1;i<n;i++){
			if(a[i]>a[i-1]){
				b[i-1] = 1;
			} else if(a[i]<a[i-1]){
				b[i-1] = -1;
			} else {
				b[i-1] = 0;
			}
			//System.out.print(b[i-1]+" ");
		}
		//System.out.println();
		int lastnum = 0;
		for(int i=0;i<n-1;i++){
			if(lastnum*b[i]<0){
				count ++;
				i++;
				if(i<n-1)lastnum = b[i];
			} else if(lastnum == 0&&b[i] != 0){
				lastnum = b[i];
			}
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 50408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) cout << (x) << endl;
#define _GLIBCXX_DEBUG

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

  if(a == 1) a = 14;
  if(b == 1) b = 14;

  if(a > b){
    COUT("Alice");
  }
  else if(a < b){
    COUT("Bob");
  }
  else{
    COUT("Draw");
  } 
  
}

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

using namespace std;

main(){
    int n;
    scanf("%d",&n);
    vector<int> arr (n+1);
    for(int i=1;i<=n;++i) scanf("%d",&arr[i]);
    int count = 0;
    for(int i=1;i<n;++i){
        if(arr[i]==i){  
            int temp  = arr[i];
            arr[i] = arr[i+1];
            arr[i+1] = temp;
            count++;
        }
    }
    if(arr[n]==n) count++;
    printf("%d\n",count);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#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; }
using ll = long long;
const ll MOD=1e9+7;
const long long INF = 1LL<<60;

int main() {
    int ans = 1;
    vector<int> x(5);
    rep(i, 5) cin >> x.at(i);

    rep(i,5){
        if(x.at(i)==0){
            break;
        }
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
import math
import sys
MOD = 998244353

N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
    print(0)
    sys.exit(0)

T = [0] * N

for i in range(N):
    T[D[i]] += 1

for i in range(1, N):
    if T[i] > 0 and T[i-1] == 0:
        print(0)
        sys.exit(0)

if T[0] != 1:
    print(0)
    sys.exit(0)

ans = 1
for i in range(2, N):
    if T[i] == 0:
        break
    # ans = (ans * int(math.pow(T[i-1], T[i])) % MOD
    ans = (ans * (T[i-1] ** T[i])) % MOD

print(ans)


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}


int main() {
	int n = ri();
	int k = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	std::set<int> cur;
	for (int i = 0; i < k; i++) cur.insert(a[i]);
	int inc[n];
	for (int i = 0; i < n - 1; i++) inc[i + 1] = a[i] < a[i + 1];
	for (int i = 0; i < n - 1; i++) inc[i + 1] += inc[i];
	int res = 1;
	int tona = 0;
	for (int i = 0; i < n - k; i++) {
		if (*cur.begin() != a[i] || *std::prev(cur.end()) > a[i + k]) res++;
		if (inc[i + k - 1] - inc[i] == k - 1 && inc[i + k] - inc[i + 1] == k - 1) tona++;
		cur.erase(a[i]);
		cur.insert(a[i + k]);
	}
	
	// sorted phase
	int inc_num = 0;
	for (int i = 0; i < n - k + 1; i++) {
		if (inc[i + k - 1] - inc[i] == k - 1) inc_num++;
	}
	if (inc_num > 1) {
		res -= inc_num - 1;
		res += tona;
	}
	std::cout << res << std::endl;
	return 0;
}


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

using namespace std;

typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define inf 1000*1000*1000+5
void solve()
{
	ll r,c,k;
	cin>>r>>c>>k;
	vector<string> arr(r);
	fr(i,0,r)
		cin>>arr[i];
	vector<VL> pref(r+1,VL(c+1,0));
	fr(i,0,r)
	{
		fr(j,0,c)
		{
			if(arr[i][j]=='1')
			{
				pref[i+1][j+1]=1;
			}
		}
	}
	fr(i,0,r+1)
	{
		fr(j,1,c+1)
		{
			pref[i][j]+=pref[i][j-1];
		}
	}
	ll ans=inf,ccut=0;
	fr(j,0,c+1)
	{
		fr(i,1,r+1)
		{
			pref[i][j]+=pref[i-1][j];
		}
	}
	ll pset=pow(2,r-1);
	fr(s,0,pset)
	{
		ccut=0;
		ll pct=0,colc=0;
		fr(j,1,c+1)
		{
			ll rcut=0;
			ll fg=1;
			fr(i,1,r+1)
			{
				if(i==r)
				{
					ll ct=pref[i][j]-pref[rcut][j];
					ct-=pref[i][ccut]-pref[rcut][ccut];
					if(ct>k)
						fg=0;
				}
				else
				{
					if(s&(1<<(r-1-i)))
					{
						ll ct=pref[i][j]-pref[rcut][j];
						ct-=pref[i][ccut]-pref[rcut][ccut];
						if(ct>k)
							fg=0;
						rcut=i;
					}
				}
			}
			if(fg==0)
			{
				if(ccut!=j-1)
				{
					ccut=j-1;
					colc++;
					j--;
				}
				else
				{
					pct=-1;
					break;
				}
			}
		}
		if(pct!=-1)
		{
			pct=colc;
			pct+=__builtin_popcount(s);
			ans=min(ans,pct);
		}
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

bool chk[111];
int x,n;

int main()
{
  scanf ("%d %d",&x,&n);
  for (int i=0;i<n;i++){
int v; scanf ("%d",&v); chk[v] = 1;
  }
  for (int d=0;;d++){
    if (!chk[x-d]){
printf ("%d\n",x-d);
      break;
    }
    if (!chk[x+d]){
printf ("%d\n",x+d);
      break;
    }
  }
return 0;
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << a[2] * 10 + a[1] + a[0] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l



int main() {
	string s;
	cin >> s;
	
	string b = s.substr(5, 2);
	
	int bb = stoi(b);

	if (bb < 5)cout << "Heisei" << endl;
	else cout << "TBD" << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	void run() {
		Map<String, Integer> map = new HashMap<String, Integer>();
		Queue<char[]> que = new LinkedList<char[]>();
		que.add("01234567".toCharArray());
		map.put("01234567", 0);
		while (!que.isEmpty()) {
			String b = String.valueOf(que.poll());
			int index = b.indexOf("0");
			if (index != 0 && index != 4) {
				char[] panel = b.toCharArray();
				char tmp = panel[index];
				panel[index] = panel[index - 1];
				panel[index - 1] = tmp;
				String p = String.valueOf(panel);
				if (map.get(p) == null) {
					map.put(p, map.get(b) + 1);
					que.add(p.toCharArray());
				}
			}
			if (index != 3 && index != 7) {
				char[] panel = b.toCharArray();
				char tmp = panel[index];
				panel[index] = panel[index + 1];
				panel[index + 1] = tmp;
				String p = String.valueOf(panel);
				if (map.get(p) == null) {
					map.put(p, map.get(b) + 1);
					que.add(p.toCharArray());
				}
			}
			if (index < 4) {
				char[] panel = b.toCharArray();
				char tmp = panel[index];
				panel[index] = panel[index + 4];
				panel[index + 4] = tmp;
				String p = String.valueOf(panel);
				if (map.get(p) == null) {
					map.put(p, map.get(b) + 1);
					que.add(p.toCharArray());
				}
			}
			if (index > 3) {
				char[] panel = b.toCharArray();
				char tmp = panel[index];
				panel[index] = panel[index - 4];
				panel[index - 4] = tmp;
				String p = String.valueOf(panel);
				if (map.get(p) == null) {
					map.put(p, map.get(b) + 1);
					que.add(p.toCharArray());
				}
			}
		}
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			String board = "";
			for (int i = 0; i < 8; i++)
				board += scan.next();
			System.out.println(map.get(board));
		}
	}
	public static void main (String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 44776
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

x1 = 0
for i in 1..N do
  x1 += lines[1][i-1] * ((-1) ** ((i+1) % 2))
end

ans = [x1]
for i in 2..N do
  ans[i-1] = 2 * lines[1][i-2] - ans[i-2]
end

for i in 1..N do
  print ans[i-1].to_s + " "
end

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

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
 	if(a > b)
      for(int i=0; i<a; i++)
        cout << b;
  
 	else
      for(int i=0; i<b;i++) cout << a;
  
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
long long n,m,i,j,k,x,a[100005],f[100005],ans[100005];
int main()
{
	scanf("%lld%lld",&a[m=1],&n);
	long long _=a[1];
	fz1(i,n){
		scanf("%lld",&x);
		while(m&&a[m]>=x) m--;
		a[++m]=x;
	}
	f[m]=1;
	fd1(i,m){
		k=a[i];
		while(k>a[1]){
			j=lower_bound(a+1,a+m+1,k)-a-1;
			f[j]+=k/a[j]*f[i];
			k%=a[j];
		}
		ans[k]+=f[i];
	}
	fd1(i,_)ans[i]+=ans[i+1];
	fz1(i,_)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        //入力
        Scanner scn=new Scanner(System.in);
        int[] time=new int[5];
        for(int i=0;i<5;i++){
            time[i]=scn.nextInt();
        }
        //処理
        int min_no1=9;
        int place=0;
        int cnt=0;
        int total=0;
        for(int i=0;i<5;i++){
            if(time[i]%10!=0){
                if( min_no1>time[i]%10) {
                    min_no1=time[i]%10;
                    place=i;
                }
            }else{
                cnt++;
            }
        }
        if(cnt==5)min_no1=0; 

        for(int i=0;i<5;i++){
            if(time[i]%10==0||place==i){
                total+=time[i];
            }else{
                total+=time[i]-time[i]%10+10;
            }
        }
        //出力
        System.out.println(total);
    }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

void solve(long long A, long long B) {
  LL a = A+B;
  LL b = A-B;
  LL c = A*B;
  vector<LL> arr;
  arr.PB(a);arr.PB(b);arr.PB(c);
  SORT(arr);
  cout<<arr[2]<<endl;

}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

const int N = 2e5 + 10;
char stack[N], s[N];

int n, top;
int main(){
    while(~scanf("%s", s)){
        n = strlen(s);
        top = 0;
        for(int i=0; i<n; i++){
            if(top && stack[top-1]=='S' && s[i]=='T'){
                top--;
            } else {
                stack[top++] = s[i];
            }
        }
        printf("%d\n", top);
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

const int M=1e5+5;
int a[M];

vector<int> ans;

int main()
{
	int n; scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<n;i++)
	{
		int p=upper_bound(ans.begin(),ans.end(),a[i],greater<int>())-ans.begin();
		if(p==(int)ans.size())
			ans.push_back(a[i]);
		else
			ans[p]=a[i];
	}
	printf("%d\n",ans.size());
	return 0;
}

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

const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);

using Point = complex<double>;
using Polygon = vector<Point>;

inline int sgn(const double &a) { return (a < -EPS ? -1 : (a > EPS ? 1 : 0)); }

inline bool eq(const Point &a, const Point &b) { return abs(a - b) < EPS; }

namespace std {
inline bool operator<(const Point &a, const Point &b) {
    if (sgn(a.real() - b.real()))
        return sgn(a.real() - b.real()) < 0;
    return sgn(a.imag() - b.imag()) < 0;
}
} // namespace std

double dot(const Point &a, const Point &b) { return real(conj(a) * b); }

double det(const Point &a, const Point &b) { return imag(conj(a) * b); }

struct Line {
    Point p1, p2;

    Line(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}

    bool operator<(const Line &rhs) const {
        if (eq(p2, rhs.p2))
            return p1 < rhs.p1;
        return p2 < rhs.p2;
    }
    bool operator==(const Line &rhs) const {
        return (eq(p1, rhs.p1) && eq(p2, rhs.p2)) ||
               (eq(p1, rhs.p2) && eq(p2, rhs.p1));
    }
};

enum CCW {
    ONLINE_FRONT = -2,
    CLOCKWISE,
    ON_SEGMENT,
    COUNTER_CLOCKWISE,
    ONLINE_BACK
};

int ccw(Point p0, Point p1, Point p2) {
    Point a = p1 - p0;
    Point b = p2 - p0;
    if (sgn(det(a, b)) == 1)
        return COUNTER_CLOCKWISE;
    if (sgn(det(a, b)) == -1)
        return CLOCKWISE;
    if (sgn(dot(a, b)) == -1)
        return ONLINE_BACK;
    if (sgn(norm(b) - norm(a)) == 1)
        return ONLINE_FRONT;
    return ON_SEGMENT;
}

double distanceLP(Line line, Point p) {
    return abs(det(line.p2 - line.p1, p - line.p1)) / abs(line.p2 - line.p1);
}

double distanceSP(Line line, Point p) {
    if (sgn(dot(line.p2 - line.p1, p - line.p1)) < 0)
        return abs(p - line.p1);
    if (sgn(dot(line.p1 - line.p2, p - line.p2)) < 0)
        return abs(p - line.p2);
    return distanceLP(line, p);
}

bool intersectLS(Line a, Line b, bool segflag) {
    if (segflag)
        return (ccw(a.p1, a.p2, b.p1) * ccw(a.p1, a.p2, b.p2) <= 0) &&
               (ccw(b.p1, b.p2, a.p1) * ccw(b.p1, b.p2, a.p2) <= 0);
    else
        return (sgn(det(a.p2 - a.p1, b.p1 - a.p1) *
                    det(a.p2 - a.p1, b.p2 - a.p1)) <= 0) &&
               (sgn(det(b.p2 - b.p1, a.p1 - b.p1) *
                    det(b.p2 - b.p1, a.p2 - b.p1)) <= 0);
}

double distanceSS(Line s1, Line s2){
    if(intersectLS(s1, s2, true))return 0;
    double d1 = distanceSP(s1, s2.p1);
    double d2 = distanceSP(s1, s2.p2);
    double d3 = distanceSP(s2, s1.p1);
    double d4 = distanceSP(s2, s1.p2);
    return min({d1, d2, d3, d4});
}

int main(){
    int q;
    cin >> q;
    for(int i=0;i<q;++i){
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        Point p0 = Point(x0, y0), p1 = Point(x1, y1), p2 = Point(x2, y2), p3 = Point(x3, y3);
        Line s1 = Line(p0, p1), s2 = Line(p2, p3);
        printf("%.10f\n", distanceSS(s1, s2));
    }

    return 0;
}



Measured memory_bytes: 3244
# frozen_string_literal: true

x, k, d = gets.split.map(&:to_i)

k1 = -x / d
k2 = k1 - 1
k3 = k1 + 1

km = [k1, k2, k3].sort_by { |e| (x + e * d).abs }.filter { |e| e % 2 == k % 2 }[0]

if k < km.abs
  if km < 0
    km = -k
  else
    km = k
  end
end
puts (x + km * d).abs


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

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int dif = a[i] - a[j];
      ans = max(ans, dif);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628