akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,m;
    long long s;
    scanf("%d%d",&n,&m);
    if(n>m)
        swap(n,m);
    if(n==1)
    {
        if(m==1)
        printf("1\n");
        else
        if(m>1)
        printf("%d\n",m-2);
        return 0;
    }
    if(n==2)
    {
        printf("0\n");
        return 0;
    }
    if(n>2)
    {
        s=(long long)n*m-n*2-m*2+4;
        printf("%lld\n",s);
    }
    return 0;
}


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

int main() {
  int n,ans=0;
  cin >> n;
  vector<int> b(n-1);
  rep(i,n-1){
    cin >> b[i];
  }
  rep(i,n-2){
    ans += min(b[i],b[i+1]);
  }
  ans += b[0];
  ans += b[n-2];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
score = [0, 0]

n = int(raw_input())
for i in range(n):
    t, h = raw_input().split()
    if t < h:
        score[1] += 3
    elif t > h:
        score[0] += 3
    else:
        score[0] += 1
        score[1] += 1
print score[0], score[1]

Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 1e5 + 5;
int n;
pll a[N];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		ll x, l;
		cin >> x >> l;
		a[i].first = x + l;
		a[i].second = x - l;
	}
	sort(a, a + n);
	ll lst = a[0].first;
	int cnt = 1;
	for (int i = 1; i < n; i++) {
		if (a[i].second >= lst) {
			cnt++;
			lst = a[i].first;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
      public static void main(String[]args) {
    	  int sum=0;
    	  Scanner scan=new Scanner(System.in);
    	  int column=scan.nextInt();
    	  int[][] nums=new int[2][column];
    	  for(int row=0;row<2;row++) {
    		  for(int co=0;co<column;co++) {
    		  nums[row][co]=scan.nextInt();
    		  }
    	  }
    	  for(int i=0;i<column;i++) {
    		  int solve=0;
    		  int j,k;
    		  for(j=0;j<=i;j++) {
    			  solve+=nums[0][j];
    		  }
    		  for(k=i;k<column;k++) {
    			  solve+=nums[1][k];
    		  }
    		  if(solve>sum) {
    			  sum=solve;
    		  }
    	  }
    	  System.out.println(sum);
      }
}


Measured memory_bytes: 23636
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] sums = new int[26];
		String sentence;
		
		while ((sentence = br.readLine()) != null) {
			for (char sc : sentence.toLowerCase().toCharArray()) {
				for (char c = 'a', i = 0; c <= 'z'; c++, i++) {
					if (sc == c) sums[i]++;
				}
			}
		}
		
		for (char c = 'a', i = 0; c <= 'z'; c++, i++) {
			System.out.println(c + " : " + sums[i]);
		}
	}
}

Measured memory_bytes: 24108
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
using namespace std;

int main(){
    // あとで消す
    //std::ifstream in("cin4.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    cin >> N;

    string Si;

    map<string, int> table;

    for(size_t i=0;i<N;i++){
        cin >> Si;
        table[Si] = table[Si]+1;
    }
    
    int maxv = 0;
    int value;
    string key;

    for (auto i=table.begin() ; i != table.end(); ++i){
        value = i->second;
        if(maxv<value){
            maxv = value;
        }
    }
    for (auto i=table.begin() ; i != table.end(); ++i){
        key = i->first;
        value = i->second;
        
        if(maxv==value){
            cout << key << endl;
        }
    }

    /*
    for (const auto& [key, value] : table){
        if(maxv<value){
            maxv = value;
        }
    }
    for (const auto& [key, value] : table){
        if(maxv==value){
            cout << key << endl;
        }
    }
    */
    

    return 0;
}


Measured memory_bytes: 25216
#include<stdio.h>

int main(void){
  int n , k;
  scanf("%d %d",&n ,&k);

  long long a[n+1];
  for(int i = 1;i <= n;i ++){
    scanf("%lld",&a[i]);
  }

  long long ans = 1;
  for(int i = k;i > 0;i --){
    ans *= a[i];
  }

  for(int i = k+1;i <= n;i ++){
    if(a[i] > a[i-k]){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }

  return 0;
}

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

int main() {
  char s[3];
  cin >> s;
  int b = 0;
  for (int i = 0; i < 3; i++) {
    b += s[i] == '1' ? 1 : 0;
  }
  cout << b << endl;
  
  return 0;
}

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

long DIV = 1000000007;

int main(void) {
   string S;
   cin>>S;
   bool flag = true;
   if (S[1] == S[0]) flag = false;
   if (S[2] == S[1]) flag = false;
   if (S[3] == S[2]) flag = false;
   if (flag) cout<<"Good"<<endl;
   else cout<<"Bad"<<endl;


   return 0;
}

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

using namespace std;

int main(){
  
  int N;
  cin >> N;
  
  vector<int> x(N), y(N);
  vector<long> h(N);
  vector<long> tmp(N);
  
  for (int i = 0; i < N; i++)
    cin >> x.at(i) >> y.at(i) >> h.at(i);
  
  int cx, cy;
  long H;
  bool flag = false;
  
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      if (h.at(0) != 0) {
        H = h.at(0) + abs(x.at(0) - i) + abs(y.at(0) - j);
      } else {
        for (int k = 0; k < N; k++) {
          tmp.at(k) = h.at(k) + abs(x.at(k) - i) + abs(y.at(k) - j);
          if (h.at(k) != 0) {
            H = h.at(k) + abs(x.at(k) - i) + abs(y.at(k) - j);
            break;
          }
          if (k == N - 1) {
            auto itr = std::max_element(tmp.begin(), tmp.end());;
            size_t index = distance(tmp.begin(), itr);
            H = tmp.at(index);
          }
        }
      }
      for (int k = 0; k < N; k++) {
        if (h.at(k) == H - abs(x.at(k) - i) - abs(y.at(k) - j)) {
          if (k == N - 1) {
            cx = i;
            cy = j;
            flag = true;
            break;
          } else continue;
        } else if (h.at(k) == 0 && H - abs(x.at(k) - i) - abs(y.at(k) - j) <= 0) {
          if (k == N - 1){
            cx = i;
            cy = j;
            flag = true;
            break;
          } else continue;
        } else break;
      }
      if (flag) break;
    }
    if (flag) break;
  }
  
  cout << cx << " " << cy << " " << H << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int N,H,W,M,K,A,B,C,ans=0,cnt=0;
string S,T;
vector<int> P,Q;
vector<pair<int,int>> PP;
bool CAN=false;


int main(){
  cin>>H>>W>>A>>B;
  int L[H][W];
  
  REP(i,H){
    REP(j,W) L[i][j]=0;
  }
  
  REP(i,H){
    if(i<B) {
      for(int j=A; j<W; ++j) L[i][j]=1;
    }
    else{
      for(int j=0; j<A; ++j) L[i][j]=1;
    }
  }
  
  REP(i,H){
    REP(j,W) cout<<L[i][j];
    cout<<endl;
  }
}

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

int main(){
    ll A,B,C,D;
    cin>>A>>B>>C>>D;
    while(true){
        if(0<C-B){
            C-=B;
        }else{
            cout<<"Yes";
            break;
        }
        if(0<A-D){
            A-=D;
        }else{
            cout<<"No";
            break;
        } 
    }
}

Measured memory_bytes: 3532
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};


int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int x;
    cin >> x;
    x = !x;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 3524
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for(ll i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

const int MAXN = 1e5+1;
int vis[MAXN];
vector<int> E[MAXN];

void DFS(int cur, int pre, int ban) // only two vertexs have degree 4, others are 2
{
    for(auto x: E[cur]) {
        if(!vis[x] && x != pre && x != ban) {
            vis[x] = 1;
            DFS(x, cur, ban);
        }
    }
}

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

    int n, m;
    cin >> n >> m;
    vector<int> d(n, 0);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        ++d[--a];
        ++d[--b];
        E[a].push_back(b);
        E[b].push_back(a);
    }
    vector<int> v4;
    int ck = 0;
    REP(i, n) {
        if(d[i]%2 != 0) {
            cout << "No" << endl;
            return 0;
        }else if(d[i] >= 6) {
            ck = 1;
        }else if(d[i] == 4) {
            v4.push_back(i);
        }
    }
    if(ck || v4.size() > 2) {
        cout << "Yes" << endl;
        return 0;
    }
    if(v4.size() == 2) {
        DFS(v4[0], -1, v4[1]);
        if(vis[v4[0]]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 7680
n,m=map(int,input().split())
b=[]
for i in range(m):
    b.append(list(map(int,input().split())))
b.sort(key=lambda x:x[1])
time=0
count=0
for k in range(len(b)):
    if b[k][0]>=time:
                time=b[k][1]
                count+=1
print(count)

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


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL <<60;
const long long Mo=1000000007;
     
long long gcn(long long x,long long y){
  if(x%y==0){
    return y;  
  }
  else{
    return gcn(y,x%y);
  }
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(void){
  long long tmp;
  long long n;
  long long i,j,k;
  long long m10=1,m9=1,m8=1;
  long res=0;

  cin>>n;

  /*
  for(i=0;i<n;i++){
    m10=(m10*10)%Mo;
    m9=(m9*9)%Mo;
    m8=(m8*8)%Mo;
  }
  */
  m10=modpow(10,n,Mo);
  m9=modpow(9,n,Mo);
  m8=modpow(8,n,Mo);
  
  res=(m10-2*m9+m8);
  
  if(res<0){
    res=res+3*Mo;
  }
  res=res%Mo;
  
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<pair<ll, int>> a(N);
	rep(i,N) {
		ll b;
		cin >> b;
		a[i] = make_pair(b,i);
	}

	sort(all(a));
	set<ll> dic;
	dic.emplace(-1);
	dic.emplace(N);
	ll ans = 0;
	rep(i,N) {
		auto itm = dic.lower_bound(a[i].second);
		itm--;
		auto itl = dic.upper_bound(a[i].second);
        ans += (a[i].second - *itm) * (*itl - a[i].second) * a[i].first;
		dic.emplace(a[i].second); 
	} 

	cout << ans << endl;

}


Measured memory_bytes: 13952
A = int(input())+1
B = int(input())+1
C = int(input())+1
X = int(input())

count = 0

for a in range(A):
  for b in range(B):
    for c in range(C):
      if (a*500 + b*100 + c*50) == X:
        count = count + 1
print(count)


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

int main(){
  int n;
  cin>>n;
  vector<string> W(n);
  int ans = 0;
  for(int i=0;i<n;++i){
    cin>>W[i];
  }
  for(int i=0;i<n-1;++i){
    if(W[i].back()!=W[i+1][0]){
      ans+=1;
      break;
    }
  }
  for(int i=0;i<n;++i){
    for(int j=0;j<i;++j){
      if(W[i]==W[j]){
        ans += 1;
        break;
      }
    }
  }
  if(ans>0) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

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

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

int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	
	std::vector<std::pair<int, int> > set;
	std::vector<int> res(n + 1);
	for (int i = 0; i < n; ) {
		int init = i;
		for (; i < n && s[i] == '>'; ) i++;
		int mid = i;
		for (; i < n && s[i] == '<'; ) i++;
		int end = i;
		for (int j = mid; j >= init; j--) res[j] = std::max(res[j], mid - j);
		for (int j = mid; j <= end; j++) res[j] = std::max(res[j], j - mid);
	}
	std::cout << std::accumulate(res.begin(), res.end(), 0LL) << std::endl;
	return 0;
}



Measured memory_bytes: 2820
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl
typedef long long ll;

int fact(ll n)
{
    int cnt = 0, root = sqrt(n);
    for(int i = 2; i <= root; i++)
    {
        if(n % i == 0)
        {
            cnt++;
            while(n % i == 0) n /= i;
        }
        if(n == 0) break;
    }
    if(n > 1) ++cnt;
    return ++cnt;
}
int main ()
{
    ios_base :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
    ll a, b, gcd;
    cin >> a >> b;
    gcd = __gcd(a, b);
    cout << fact(gcd) << endl;
}


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

#define forn(i,x,y) for(int i = x; i<y; i++)
int h[100001], N;
long long memo[100001];


long long solve(int atual, long long custo){
	if(atual >= N-1) return custo;
	if(memo[atual] != -1) return memo[atual] + custo;

	long long pula1, pula2;

	pula1 = solve(atual+1, custo + abs(h[atual] - h[atual+1]));
	if(atual < N-2) pula2 = solve(atual+2, custo + abs(h[atual] - h[atual+2]));
	else pula2 = LLONG_MAX;


	memo[atual] = min(pula1, pula2) - custo;
	return min(pula1, pula2);

}

int main(){
	ios::sync_with_stdio(false);
	cin >> N;
	forn(i,0,N) cin >> h[i];
	memset(memo, -1, sizeof(memo));

	cout << solve(0, 0) << '\n';

	
}

Measured memory_bytes: 6144
#include <iostream>
#include <cmath>
#include <string>
#include<set>
#include<vector>
#define MAX 5000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> point;
int main(void) {
    ll i, j, h, w, d, q, num, l, r, dis[200000];
    point posi[90001];
    cin >> h >> w >> d;
    for(i=1; i<=h; i++) {
        for(j=1; j<=w; j++) {
            cin >> num;
            posi[num] = make_pair(i, j);
        }
    }
    cin >> q;
    for(i=1; i<=h*w; i++)
        dis[i] = 0;
    for(i=1; i<=h*w; i++)
        dis[i+d] = dis[i] + abs(posi[i+d].first-posi[i].first) + abs(posi[i+d].second-posi[i].second);
        
    
    for(i=0; i<q; i++) {
        cin >> l >> r;
        cout << dis[r]-dis[l] << endl;
    }
}


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

int main(){
  int N,H; cin >> N >> H;
  int a[100000], b[100000];
  for(int i=0; i<N; i++){
    cin >> a[i] >> b[i];
  }
  sort(a,a+N,greater<int>());
  sort(b,b+N,greater<int>());
  int count=0;
  for(int i=0; i<N; i++){
    if(b[i]<=a[0]) break;
    if(H<=0) break;
    H-=b[i];
    count++;
  }
  if(H<=0) cout << count << endl;
  else{
    count+=(H+a[0]-1)/a[0];
    cout << count << endl;
  }
}

Measured memory_bytes: 1024
# AtCoder Beginner Contest 176
# C - Step

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

ans=0

for i in range (1,N):
    if Als[i]>=Als[i-1]:
        pass
    else :
        step=abs(Als[i]-Als[i-1])
        ans+=step
        Als[i]+=step
print(ans)

Measured memory_bytes: 32036
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MAX 3005
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int n;
long long mod,inv[MAX],S2[MAX][MAX];
long long quick_pow(long long x,long long y,long long p)
{
	long long re=1;
	while(y)
	{
		if(y&1) re=re*x%p;
		x=x*x%p;
		y>>=1;
	}
	return re;
}
int main()
{
	n=read();mod=read();
	inv[1]=1;
	for(int i=2;i<=n;i++)
		inv[i]=inv[mod%i]*(mod-mod/i)%mod;
	S2[0][0]=1;
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=i;j++)
			S2[i][j]=(S2[i-1][j-1]+S2[i-1][j]*j)%mod;
	long long ans=0,C=1;
	for(int i=0;i<=n;i++)
	{
		long long sm=0,pw2=quick_pow(2,n-i,mod),ha=quick_pow(2,quick_pow(2,n-i,mod-1),mod)*C%mod,tp=1;
		C=C*(n-i)%mod*inv[i+1]%mod;
		for(int j=0;j<=i;j++)
			sm=(sm+S2[i+1][j+1]*tp)%mod,tp=tp*pw2%mod;
		if(i&1) ans=(ans-sm*ha)%mod;
		else ans=(ans+sm*ha)%mod;
	}
	ans=(ans+mod)%mod;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 49836
//ABC141D
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	long long int x;
	priority_queue<long long int> a;
	for(int i=0;i<n;i++){
		cin >> x;
		a.push(x);
	}
	long long int max;
	for(int i=0;i<m;i++){
		max = a.top();
		max /= 2;
		a.pop();
		a.push(max);
	}
	long long int sigma = 0;
	for(int i=0;i<n;i++){
		sigma += a.top();
		a.pop();
	}
	cout << sigma << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <complex>
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 
vector<int> memo(1000000, -1);
 
int recursion(const int n) {
  if (n < 0) {
    return std::numeric_limits<int>::max();
  }
  if (n == 0) {
    return 0;
  }
  if (memo[n] != -1) {
    return memo[n];
  }
  vector<int> count;
  for (auto draw :
       {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049}) {
    count.push_back(recursion(n - draw));
  }
  memo[n] = *min_element(count.begin(), count.end()) + 1;
  return memo[n];
}
 
int main() {
  int n;
  cin >> n;
  cout << recursion(n) << endl;
}

Measured memory_bytes: 13568
N, K = map(int, input().split())
A = list(map(int,input().split()))
MOD = 1000000007
count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if A[i] > A[j]:
            count += 1
first = (count * K) % 1000000007

count2 = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            count2 += 1

ans = ((count * K) + (count2 * K * (K-1) // 2)) % MOD
#second = (count2 * (K*(K-1)/2)%MOD) % MOD

#print(int((first+second)%MOD))
print(ans)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  ll arr[n + 5], arr2[n + 5], arr3[n + 5];
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];

  ll sum1 = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> arr2[i];
    sum1 += arr2[i];
  }

  for (ll i = 1; i < n; i++)
    cin >> arr3[i];

  for (ll i = 1; i < n; i++) {
    if (arr[i] == (arr[i + 1] - 1))
      sum1 += arr3[arr[i]];
  }

  cout << sum1 << en;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n);
    rep(i,n) cin>>a[i];
    ll ans=LONG_LONG_MAX;
    FOR(i,-100,100){
        ll cost=0;
        rep(j,n) cost+=(i-a[j])*(i-a[j]);
        chmin(ans,cost);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
(n,),*a=[[*map(int,i.split())]for i in open(0)]
d={0:0}
for i,j in a:
    for x,y in a:
        if i!=x or j!=y:
            d[(i-x,j-y)]=d.get((i-x,j-y),0)+1
print(n-max(d.values()))

Measured memory_bytes: 9400
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
//#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int tenCq(int q) {
	int ret=1;
	for (int i = 0; i < q; i++){
		ret*=(10-i);
		ret %= oku7;
	}
	for (int i = 1; i <= q;i++) {
		ret /= i;
	}
	return ret;
}

int a[1000];

signed main() {
	int N, ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	double ave, sum = 0.0;
	for (int i = 0; i < N; i++) {
		sum += a[i];
	}
	ave = sum / N;
	double maxN = 114514.0;
	for (int i = 0; i < N; i++) {
		if (maxN > abs(ave - a[i])) { 
			maxN = abs(ave - a[i]); 
			ans = i;
		}
	}
	
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
ans = 0
for i in range(N):
	sum = 0
	li = list(map(int,input().split()))
	for j in range(M):
		sum += B[j] * li[j]
	if sum + C > 0:
		ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<stdio.h>
#define debug(x) cout << '>' << #x << ':' << x << endl;

#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
const int INF = 1e9+5;
using namespace std;
using ll = unsigned long long int;
const ll mod = 998244353; 
int main() {
	// your code goes here
	
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int n;cin>>n;
	bool flag = false;
	if(n%10==7) flag = true;
	n/= 10;
	if(n%10==7) flag = true;
	n/=10;
	if(n%10==7) flag = true;

	if(flag) cout<<"Yes"<<'\n';
	else cout<<"No"<<"\n";
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	bool ok = s[2] == s[3] && s[4] == s[5];
	cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	long long n,i,j,s,a[11],max=-1;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(max<a[i]) 
		{
			max=a[i];
			j=i; 
		}
	}
	for(i=0,s=0;i<n;i++)
	{
		if(i==j) s+=a[i]/2;
		else s+=a[i];
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
N,m=map(int,input().split())

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

#print(X)

M=[[]for i in range(m)]
for i in range(len(X)):
    M[X[i]%m].append(X[i])
    
#print(M)

ans=len(M[0])//2
if m%2==0:
    ans+=len(M[m//2])//2
#print(0,ans)
for i in range(1,(m//2)+1):
    if m%2==0:
        if i==(m//2):
            break
    ans+=min(len(M[i]),len(M[m-i]))
    #print(i,ans)
    L=[0]
    cnt=1
    if len(M[i])>len(M[m-i]):
        A=M[i]
    else:
        A=M[m-i]
    A.sort()
    for j in range(1,max(len(M[i]),len(M[m-i]))):
        if A[j]==A[j-1]:
            cnt+=1
        else:
            L.append(cnt//2)
            cnt=1
    L.append(cnt//2)
    #print(L)
    if (abs(len(M[i])-len(M[m-i]))//2)<=sum(L):
        ans+=(abs(len(M[i])-len(M[m-i]))//2)
    else:
        ans+=sum(L)
    #print(i,ans)
print(ans)


Measured memory_bytes: 18788
#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#define dump(x ...) cerr  <<  "|| "  <<  # x  <<  "  =  ", _dump(x) 
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define __ ' '
#define LL long long
#define LD long double
#define pii pair<int,int>
const int INF = 1e9;
const int N = 200;
int n;
int arr[N+3], k[N+3];
int xr;

int grundy(int n, int k){
	if(n %k == 0) return n / k;
	
	int x = n / k;
	int y = n %k;
	
	int nb = max(1, y / (n/k + 1));
	return grundy(n - nb * (n/k + 1), k);
}

int main(){ FAST
	cin >> n;
	for(int i=1; i<=n; ++i){
		cin >> arr[i] >> k[i];
	}

	for(int i=1; i<=n; ++i){
		xr ^= grundy(arr[i], k[i]);
	}

	if(xr > 0) cout << "Takahashi" << ln;
	else cout << "Aoki" << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<vector<long long int>> vvint;
typedef vector<string> vstr;
typedef long long int llint;

llint gcd(llint x, llint y) {
	while (y != 0) {
		if (x > y) {
			llint r = x % y;
			x = y;
			y = r;
		}
		else {
			llint r = y % x;
			y = r;
		}
	}
	return x;
}

int main(void) {
	int N,ans1,ans2;
	cin >> N;
	vint x(N), y(N), b(N), p(N);
	for (int i = 0; i < N; i++)cin >> x[i] >> y[i] >> b[i] >> p[i];
	for (int i = 0; i < N; i++){
		ans1 = x[i] * b[i] + y[i] * p[i];
		if (b[i] <= 5 && p[i] <= 2){
			ans2 =( x[i] * 5 + y[i] * 2) * 0.8;
		}
		else if (b[i]>5 && p[i] <= 2){
			ans2 = (x[i] * b[i] + y[i] * 2) * 0.8;
		}
		else if (b[i] <= 5 && p[i]>2){
			ans2 = (x[i] * 5 + y[i] * p[i]) * 0.8;
		}
		else{
			ans2 = (x[i] * b[i] + y[i] * p[i]) * 0.8;
		}
		cout << min(ans1, ans2) << endl;
	}
}




Measured memory_bytes: 3124
#include <iostream>

using namespace std;

int main(){
    
    int x, arr[200005], max1 = 0, max2 = 0, imax=0;
    cin >> x;
    for(int i=1; i<=x; i++){
        cin >> arr[i];
        if(arr[i]>max1){
            max1=arr[i];
            imax = i;
        }
    }
    for(int i=1; i<=x; i++){
        if(arr[i]>max2 && imax!=i)
        max2=arr[i];
    }
    for(int i=1; i<=x; i++){
        if(arr[i]==max1){
            cout << max2 << endl;
        }
        else{
            cout << max1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2432
//AtCoder ABC122 B - ATCoder
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    string S; cin>>S;    
    ll mxans=0;
    ll tmp=0;
    for(const auto& s:S){
        if(s=='A'||s=='C'||s=='G'||s=='T'){
            ++tmp;
        } else {
            tmp=0;
        }
        mxans=max(tmp,mxans);
    }
    cout<<mxans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {

	int a, b, c, d;

	cin >> a >> b >> c >> d;

	int sign = 0;

	if (abs(a - c) <= d) { sign = 1; }
	if ((abs(a - b) <= d) && (abs(b - c) <= d)) { sign = 1; }
	
	if (sign) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	//system("pause");
	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }


signed main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int ymin = 101, xmax = -101;
  REP(i, N) chmax(xmax, read());
  REP(i, M) chmin(ymin, read());
  chmax(xmax, X);
  chmin(ymin, Y);
  if (xmax < ymin)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}


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

int main()
{
  int n;
  cin >> n;
  
  string result = "No";
  string sn = to_string(n);
  for(int i = 0;i < 3;i++)
  {
    if(sn.at(i) == '7') result = "Yes";
  }
  cout << result << endl;
}

Measured memory_bytes: 3652
require "set"
n,k = gets.chomp.split(" ").map(&:to_i)
p_arr = gets.chomp.split(" ").map(&:to_i)
c_arr = gets.chomp.split(" ").map(&:to_i)

# 添字調整
p_arr.unshift(0)
c_arr.unshift(0)

cycle_arr = []

set = Set.new
# 閉路がいくつかあるのでそれを求める
(1..n).each do |i|
  start_index = i
  # 重複してたどるのを避ける
  next if set.include?(start_index)
  index = start_index
  in_cycle_arr = []
  sum = 0
  while true do
    # 問題文では移動先のスコアを計上するとあるが, 対象のグラフは閉路なので移動元のスコアで計上しても大丈夫
    score = c_arr[index]
    in_cycle_arr << score
    sum += score
    # 通った印づけ
    set << index
    # 次のindex
    index = p_arr[index]
    # ループ判定
    break if index == start_index
  end
  cycle_arr << [in_cycle_arr, sum]
end

# 負の無限大(c_iの最小値で良い)
max = (10 ** 9) * (-1)

# 各閉路の各indexで試す
cycle_arr.each do |(cycle, sum)|
  cycle.each_with_index do |c, i|
    loop_num = 0
    t = cycle.length
    # sumが正ならなるべく繰り返した方がお得, 負なら繰り返さないほうがお得(0はどっちでもOK)
    if sum > 0
      # 最後の余りの部分だけ試したい
      loop_num = k / cycle.length
      t = k % cycle.length 
      # 余りは0にしないように
      if t == 0
        loop_num -= 1
        t += cycle.length
      end
    end
    in_sum = sum * loop_num
    t.times do |j|
      in_sum += cycle[(i + j) % cycle.length]
      max = in_sum if in_sum > max
    end
  end
end

puts max


Measured memory_bytes: 15432
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long A = nl();
        long B = nl();
        long C = nl();

        if (A + B >= C) {
            out.println(B + C);
        } else {
            // at last, eat a poisoned cookie
            out.println(B + (A + B) + 1);
        }
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  ll dp[n+1];
  ll h[n+1];
  for(ll i=1;i<=n;i++)
    cin>>h[i];
  dp[1]=0;
  dp[2]=abs(h[2]-h[1]);
  for(ll i=3;i<=n;i++)
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  cout<<dp[n];
  return 0;
}

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

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    ll X, Y; cin >> X >> Y;
    if ((2 * Y - X) % 3 != 0 || (2 * X - Y) % 3){
        cout << 0 << endl;
        return 0;
    }
    else {
      COMinit();
        ll a = (2 * Y - X) / 3;
        ll b = (2 * X - Y) / 3;
        cout << COM(a+b, a) << endl;
    }
}



Measured memory_bytes: 234624
#入力
N = int(input())
ip = input().split()
a =[]
for i in range(N):
    a.append(int(ip[i]))
f = []

#aの要素の素因数2の数を調べる
for x in a:
    #カウンター
    c = 0
    while x%2 == 0:
        c += 1
        x /= 2
    f.append(c)

#素因数2の数の合計を出力
print(sum(f))

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

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

        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++ ) {
            A[i] = Integer.parseInt(sc.next());
        }

        int[] B = new int[N];
        for (int i = 0; i < N; i++) {
            B[A[i]-1] = i + 1;
        }
        for (int i = 0; i < N; i++) {
            if (i != 0) {
                out.print(" ");
            }
            out.printf("%d", B[i]);
        }
        out.printf("\n");
        out.flush();
    }
}


Measured memory_bytes: 64088
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    A=[]
    for i in range(n):
        B=int(input())
        A.append(B)
    C=sum(A[0:m])
    D=C
    for i in range(m,n):
        C=C+A[i]-A[i-m]
        if C>D:
            D=C
    print(D)


Measured memory_bytes: 9868
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#include<stdio.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;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9+10;
typedef long long ll;
typedef pair<ll,int> P;
int ceil(int a,int b){// a以上bの倍数の最小値//
     return (a+b-1)/b*b;
 }
int stoii(string s){//stoi関数の代用 文字列⇒int型//
    return atoi(s.c_str());
}

char maze[51][51];
int n,m;
int sx,sy,gx,gy;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
void Hanoi(int n,const char* from,const char* work,const char* dest){
	if(n>=2) Hanoi(n-1,from,dest,work);
	cout<<n<<"->"<<"from"<<from<<"to"<<dest<<endl;

  if(n>=2) Hanoi(n-1,work,from,dest);
}
long long fibloop(int n){
	int f0=1,f1=1;
	if(n==0) return f0;
    else if(n==1) return f1;
	else{
		for(int j=1;j<n;j++){
			int copy=f1;
			f1=f0+f1;
			f0=copy;
		}
		return f1;
	}
}
int dp[101][10001];
int main(){
	int n,W;
	cin>>n>>W;
	vector<int> w(n,0);
	vector<int> v(n,0);
	rep(i,n){
		cin>>v[i]>>w[i];
	}
	for(int j=1;j<=10001;j++) dp[0][j]=inf;
	dp[0][0]=0;
	for(int i=1;i<n+1;i++){
		for(int j=0;j<=10000;j++){
			if(v[i-1]<=j) dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	int res=0;
	for(int j=0;j<=10000;j++){
		if(dp[n][j]<=W){
            res=j;
        } 
	}
	cout<<res<<endl; 
	return 0;
}



Measured memory_bytes: 7080
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

int main(int, char**) {
  int n;
  unsigned long long k;
  std::cin >> n >> k;
  std::vector<int> as(n);
  for(int i{}; i < n; ++i) {
    std::cin >> as[i];
    --as[i];
  }
  int town{};
  int cnt{};
  std::set<int> history{0};
  while(true) {
    ++cnt;
    int to = as[town];
    auto it = history.find(to);
    town = to;
    if(cnt == k) {
      std::cout << town + 1 << std::endl;
      return 0;
    }
    if(it != end(history)) {
      // loop detected!
      break;
    }
    history.insert(to);
  }
  int cnt2{};
  int const the_town{town};
  while(true) {
    ++cnt2;
    int to = as[town];
    if(to == the_town) {
      break;
    }
    town = to;
  }
  int offset = (k - cnt) % cnt2;
  town = the_town;
  for(int i{}; i < offset; ++i) {
    town = as[town];
  }
  // std::cout << "cnt: " << cnt << ", cnt2: " << cnt2 << std::endl;
  std::cout << town + 1 << std::endl;

  return 0;
}


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

int main() {
	int a,b,c,n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		if(a*a==b*b+c*c or b*b==a*a+c*c or c*c==a*a+b*b){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <utility>
#include <cmath>
#include <string>
#include <bitset>
#include <queue>
#include <cstdio>
#include <cstring>
#include <deque>
#include <unordered_map>
#include <climits>
#include <map>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <ctime>
#include <cstdint>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define fa(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>b;--i)
#define setp pair<pair<int,int>,int>
#define setl pair<int,int>

using namespace std;

LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }
pair <int, int> vu[4] = { {0,1}, {0,-1} , {1,0},{-1,0} }; // EWSN

const int max_v = 2e5 + 7;
const int INF = 1e9 + 7;



int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int k; ci(k);
	string s;
	ci(s);
	if (s.size() <= k) co(s);
	else
	{
		fa(i, 0, k)
		{
			co(s[i]);
		}
		co("...");
	}
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 10000010;
int a,b,c,d;
 
map < long long , long long > dp;
 
long long solve(long long cur){
	if(cur == 0)
		return 0;
	if(cur == 1)
		return d;
	if(dp.find(cur) != dp.end())
		return dp[cur];
	long long res = 1e18;
	if(cur < res / d)
		res = min(res , cur * d);
	for(long long tmp = max(1LL , cur - 1);tmp <= cur + 1;tmp++){
		if(tmp % 2 == 0){
			res = min(res , a + solve(tmp / 2) + abs(tmp - cur) * (long long)d);
		}
	}
	for(long long tmp = max(1LL , cur - 2);tmp <= cur + 2;tmp++){
		if(tmp % 3 == 0){
			res = min(res , b + solve(tmp / 3) + abs(tmp - cur) * (long long)d);
		}
	}
	for(long long tmp = max(1LL , cur - 4);tmp <= cur + 4;tmp++){
		if(tmp % 5 == 0){
			res = min(res , c + solve(tmp / 5) + abs(tmp - cur) * (long long)d);
		}
	}
	return dp[cur] = res;
 
}

 
int main(){
	int t;
	long long n;
	cin >> t;
	while(t--){
		scanf("%lld",&n);
		scanf("%d%d%d%d",&a,&b,&c,&d);
		dp.clear();
		printf("%lld\n",solve(n));
	}
	return 0;
}

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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    REP (i, 0, R) cin >> r[i];
    sort(r.begin(), r.end());
    lli inf = 1LL << 60;
    vector<vector<lli>> cost(N, vector<lli>(N, inf));
    REP (i, 0, N) cost[i][i] = 0;
    REP (i, 0, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        cost[a][b] = cost[b][a] = c;
    }
    REP (k, 0, N) REP (i, 0, N) REP (j, 0, N) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
    }
    lli ans = inf;
    do {
        int f = r[0];
        lli temp = 0;
        REP (i, 1, R) {
            temp += cost[f - 1][r[i] - 1];
            f = r[i];
        }
        ans = min(ans, temp);
    } while (next_permutation(r.begin(), r.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
from itertools import permutations
from itertools import combinations


a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

ans=float('inf')

aa=[]
aa.append(a)
aa.append(b)
aa.append(c)
aa.append(d)
aa.append(e)

per = list(permutations(aa))

for i in range(len(per)):
    p = per[i]
    time = 0
    for j in range(5):
        if(time % 10 != 0):
            time = time+(10-(time%10))
        time += p[j]
    if(time < ans):ans = time

print(ans)

Measured memory_bytes: 38384
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	x := io.NextInt()
	y := 100
	i := 0
	for y < x {
		y += y / 100
		i++
	}
	io.Println(i)
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1776
/**
*    created: 10.05.2020 11:23:33
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    int n;
    cin >> n;
    int x[n], y[n], t[n];
    rep(i, n) cin >> t[i] >> x[i] >> y[i];
    int ans = 0;
    rep(i,n){
        if(i==0){
            if(abs(x[i])+abs(y[i])<=t[i]&&(abs(x[i])+abs(y[i]))%2==t[i]%2){
                ans++;
                continue;
            }
        }
        if(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])<=abs(t[i]-t[i-1])&&(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2==(abs(t[i]-t[i-1]))%2){
            ans++;
        }
    }
    if(ans==n){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1408
#include <stdio.h>
void classchecker(int m,int e,int j);
int main(void){
    int loop,pm,pe,pj;
    while(1)
    {
        scanf("%d", &loop);
        if(loop == 0)
        {
            break;
        }
        for(int i=0;i<loop;i++){
            scanf("%d %d %d", &pm , &pe, &pj);
            classchecker(pm,pe,pj);
        }
    }

    return 0;
}
void classchecker (int m, int e, int j)
{
    if (m == 100 || e == 100 || j == 100)
    {
        printf("A\n");
    } else if (m + e >= 180)
    {
        printf("A\n");
    } else if (m + e + j >= 240)
    {
        printf("A\n");
    } else if (m + e + j >= 210)
    {
        printf("B\n");
    } else if (m + e + j >= 150 && (m >= 80 || e >= 80))
    {
        printf("B\n");
    }else {
        printf("C\n");
    }
    return;
}

Measured memory_bytes: 1012