akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    ll s;cin >> s;
    vector<ll>a(6);
    a[4] = a[5] = 0;
    a[0] = 1e9;
    a[3] = (s+a[0]-1)/a[0];
    a[1] = 1;
    a[2] = a[0]*a[3] -s;
    show(a);
    rep(i,6)assert(a[i] >= 0 and a[i] <= 1e9);
    auto b = a;
    b[0] -= b[4],b[2] -=b[4];
    b[1] -= b[5],b[3] -= b[5];
    show(abs(b[0]*b[3]-b[1]*b[2]));
    assert(abs(b[0]*b[3]-b[1]*b[2])==s);
    rep(i,6)cout << a[i] << " \n"[i == 5];
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List
import qualified Data.Set as Set

main = do
    n <- readLn
    as <- map read . words <$> getLine
    putStrLn $ pp (solve n as)

pp (x,y) = (show x) ++ " " ++ (show y)

solve :: Int -> [Int] -> (Int,Int)
solve n as = colerNum fixed free
    where frees = filter ('Z'==) $ chars
          fixs  = filter ('Z'/=) $ chars
          chars = map color as
          fixed = length . nub $ fixs
          free = length frees



color :: Int -> Char
color n | n <= 399 = 'A'
        | n <= 799 = 'B'
        | n <= 1199 = 'C'
        | n <= 1599 = 'D'
        | n <= 1999 = 'E'
        | n <= 2399 = 'F'
        | n <= 2799 = 'G'
        | n <= 3199 = 'H'
        | otherwise = 'Z'
        

colerNum :: Int -> Int -> (Int,Int)
colerNum fixed free = (max fixed 1 , fixed + free)


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 1000;
ll mod = INF;


int main(){
    int h,n;
    int a[1000],b[1000];
    int dp[10001];
    cin >> h>>n;
    for(int i=0;i<n;i++){
        cin >> a[i]>>b[i];
    }
    for(int i=0;i<=10000;i++){
        dp[i]=INF;
    }
    dp[0]=0;//dp[damage]=min(mana)
    for(int d=1;d<=10000;d++){
        for(int j=0;j<n;j++){
            if(d-a[j]<0){
                dp[d]=min(dp[d],b[j]);
            }else if(d-a[j]>=0){
                dp[d]=min(dp[d],dp[d-a[j]]+b[j]);
            }
        }
    }

    for(int i=h;i<=10000;i++){
        if(dp[i]!=INF){
            cout << dp[i]<<endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace algorithm
{
	class Program
	{
		public class T
		{

			public Int64 cost;
			public Int64 num;
			public T(Int64 cost, Int64 num)
			{
				this.cost = cost;
				this.num = num;
			}
		}
		static void Main(string[] args)
		{	//件数/本数
			Int64[] q = Array.ConvertAll(Console.ReadLine().Split(), Int64.Parse);

			//コスト/本数


			List<T> qq = new List<T>();

			for (Int64 i = 0; i < q[0]; i++)
			{
				Int64[] q2 = new Int64[2];
				q2 = Array.ConvertAll(Console.ReadLine().Split(), Int64.Parse);
				qq.Add(new T(q2[0], q2[1]));
			}


			

			var qqq = qq.OrderBy(x => x.cost);
			Int64 ans=0;
			foreach (var tmp in qqq)
			{
				if (tmp.num <= q[1])
				{
					q[1] -= tmp.num;
					ans += tmp.num * tmp.cost;
				}
				else
				{
					//最後
					ans += q[1] * tmp.cost;
					break;
				}
			}

			//コストが低い順から取得していく



			Console.WriteLine(ans);
			
		}
	}

}




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

int main(void){
    int n;
    cin >> n;
    
    int a;
    int max = 0, min = 0;
    int max_idx = 1, min_idx = 1;
    int i;
    for(i = 1; i <= n; i++){
        cin >> a;
        if(a > max){
            max = a;
            max_idx = i;
        }
        if(a < min){
            min = a;
            min_idx = i;
        }
    }
    
    bool ispos;
    if(min >= 0){
        ispos = true;
    }else if(max <= 0){
        ispos = false;
    }else{
        ispos = (max >= abs(min)) ? true : false;
    }
    
    cout << (n - 1) * 2 << endl;
    
    if(ispos){
        for(i = 1; i <= n; i++){
            if(i != max_idx){
                printf("%d %d\n", max_idx, i);
            }
        }
        for(i = 1; i < n; i++){
            printf("%d %d\n", i, i + 1);
        }
    }else{
        for(i = 1; i <= n; i++){
            if(i != min_idx){
                printf("%d %d\n", min_idx, i);
            }
        }
        for(i = n - 1; i >= 1; i--){
            printf("%d %d\n", i + 1, i);
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#define scanf(...) scanf(__VA_ARGS__)+1
using namespace std;

int main(){
	int N, Q;
	char S[100000 + 1];

	scanf("%d %d\n", &N, &Q);
	scanf("%s\n", S);

	int len = strlen(S);

	short* block = new short[len / 100];
	short* startC = new short[len / 100];
	short* endA = new short[len / 100];

	for (int i = 0; i < len / 100; i++) {
		int flag = 0;
		int count = 0;
		for (int j = 0; j < 100; j++) {
			if (S[i * 100 + j] == 'A') {
				flag = 1;
			} else if (S[i * 100 + j] == 'C') {
				if (flag == 1) {
					count++;
				}
				flag = 0;
			} else {
				flag = 0;
			}
		}
		block[i] = count;
		startC[i] = (S[i * 100] == 'C') ? 1 : 0;
		endA[i] = (S[i * 100 + 99] == 'A') ? 1 : 0;
	}

	int s, e;

	for (int i = 0; i < Q; i++) {
		scanf("%d %d", &s, &e);
		s--;e--;

		int count = 0;
		short eA, sC;

		int startBlock = s / 100 + 1;
		int endBlock = e / 100;

		if (startBlock < endBlock) {
			// ブロック処理
			int flag = 0;
			for (int x = s; x < startBlock * 100; x++) {
				if (S[x] == 'A') {
					flag = 1;
				} else if (S[x] == 'C') {
					if (flag == 1) {
						count++;
					}
					flag = 0;
				} else {
					flag = 0;
				}
			}
			eA = (S[startBlock * 100 - 1] == 'A') ? 1 : 0;
			for (int x = startBlock; x < endBlock; x++) {
				if (eA && startC[x]) count++;
				count += block[x];
				eA = endA[x];
			}
			if (eA && S[endBlock * 100] == 'C') count++;
			flag = 0;
			for (int x = endBlock * 100; x <= e; x++) {
				if (S[x] == 'A') {
					flag = 1;
				} else if (S[x] == 'C') {
					if (flag == 1) {
						count++;
					}
					flag = 0;
				} else {
					flag = 0;
				}
			}


		} else {
			// 通常処理
			int flag = 0;
			for (int x = s; x <= e; x++) {
				if (S[x] == 'A') {
					flag = 1;
				} else if (S[x] == 'C') {
					if (flag == 1) {
						count++;
					}
					flag = 0;
				} else {
					flag = 0;
				}
			}
		}
		printf("%d\n", count);
	}
	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<string.h>
#include <math.h>
#include <stdlib.h>
#define MAX 10000

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node r;
 
Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}
 
Node treeSearch(Node u, int k){
  if(u == NIL || u->key == k) return u;
  else if(u->key > k) return treeSearch(u->left, k);
  else if(u->key < k) return treeSearch(u->right, k);
}
 
Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
 
void treeDelete(Node z){
  Node y;
  Node x;
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  if(y->left != NIL) x = y->left;
  else x = y->right;
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) r = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  if(y != z) z->key = y->key;
}
 
void insert(int k){
  Node y = NIL;
  Node x = r;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) r = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
 
}
 
void inorder(Node u){
  if(u->left != NIL) inorder(u->left);
  printf(" %d", u->key);
  if(u->right != NIL) inorder(u->right);
}
void preorder(Node u){
  printf(" %d", u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}
int main(){
  int data, i, x;
  char c[20];
  scanf("%d", &data);
 for ( i = 0; i < data; i++ ){
    scanf("%s", c);
    if (c[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(r, x);
      if ( t != NIL ) {
	printf("yes\n");
      }
      else {printf("no\n");
      }
    } else if ( c[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( c[0] == 'p' ){
      inorder(r);
      printf("\n");
      preorder(r);
      printf("\n");
    } else if ( c[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(r, x));
    }
  }
 
  return 0;
}



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

int main()
{
    string str;
    cin >> str;
    int n = str.length();
    if(n == 6) {
        if(str[2] == str[3] && str[4] == str[5]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
    return 0;
}


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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>();
	int N=S.size();

	REP(i,N-1){
		if(S[i]==S[i+1]){
			out(i+1,i+2);
			return 0;
		}
	}
	REP(i,N-2){
		if(S[i]==S[i+2]){
			out(i+1,i+3);
			return 0;
		}
	}
	out(-1,-1);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main ()
{
    double x1, y1, x2, y2, dis;
    cin >> x1 >> y1 >> x2 >> y2;
    double x = x1 - x2, y = y1 - y2;
    dis = sqrt(x * x + y * y);
    cout << setprecision(10) << dis << endl;
    return 0;
}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
const int N=6e5+5,mod=1e9+7;
typedef long long ll;
int n,m,l,r;
ll f[N],inv[N],invf[N];
ll C(int n,int m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
ll g(int x,int y,int k)
{
    int s=k-x*m;
    ll res=0;
    for(int i=0,f=1;i*y<=s&&i<=n-m;i++,f*=-1)
        res=(res+f*C(n-m,i)%mod*C(s-i*y+n,n))%mod;
    return res;
}
ll solve(int k)
{
    ll ans=0;
    for(int x=1;x*m<=k;x++)
        ans=(ans+g(x,x,k)-g(x+1,x,k))%mod;
    return (C(k+n,n)-ans*C(n,m))%mod;
}
int main()
{
    f[0]=f[1]=invf[0]=invf[1]=inv[1]=1;
    for(int i=2;i<N;i++)
    {
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        f[i]=f[i-1]*i%mod;
        invf[i]=invf[i-1]*inv[i]%mod;
    }
    scanf("%d%d%d%d",&n,&m,&l,&r);
    printf("%lld\n",((solve(r)-solve(l-1))%mod+mod)%mod);
}


Measured memory_bytes: 14464
#include<bits/stdc++.h>
#define mod 1e9L + 7
using namespace std;

using ll = long long;


void add_self(int& a, int b)
{
  a += b;
  if(a > mod)
    a -= mod;
}

int main()
{
  int n;
  scanf("%d", &n);
  int a[n][n];
  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j < n; j++)
    {
      scanf("%d", &a[i][j]);
    }
  }
  vector<vector<int>> dp(n + 1, vector<int> (1 << n));
  // dp[i][j] will store the numbers of ways in which we can assign j people from i persons
  
  dp[0][0] = 1;
  for(int mask = 0; mask < (1 << n) - 1; mask++)
  {
    int person = __builtin_popcount(mask);
    for(int j = 0; j < n; j++)
    {
      if(a[person][j] && !(mask & (1 << j)) && dp[person][mask])
      {
        add_self(dp[person + 1][mask | (1 << j)], dp[person][mask]);
      }
    }
  }

  printf("%d", dp[n][(1 << n) - 1]);
  
  return 0;
}


Measured memory_bytes: 188800
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    cout << (1000 -  n%1000)%1000;
    return 0;
}

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

int main() {
//sippuu
    int i;
    string j;

    cin >> i;
    cin >> j;
    if (j.length() > i){
        j = j.substr(0, i);
        cout << j + "...";
    }
    else {
        cout << j ;
    }




}

Measured memory_bytes: 3604
n, m = map(int, input().split())
counter_list = [0] * (n + 1)
for i in range(m):
    a, b = map(int, input().split())
    counter_list[a] += 1
    counter_list[b] += 1

for i in range(1, n + 1):
    print(counter_list[i])


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

int main(){
  int n;
  cin >> n;
  
  vector<pair <int, int>> tasks;
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    tasks.emplace_back(b, a);
  }
  
  sort(tasks.begin(), tasks.end());
  int sum = 0;
  
  bool clear = true;
  
  for (auto v : tasks) {
    sum += v.second;
    
    if(sum > v.first) {
      clear = false;
      break;
    }
  }
  
  if(clear) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 2420
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())
INF = float('inf')
graph = [[INF] * N for _ in range(N)]

for i in range(N):
    graph[i][i] = 0

for _ in range(M):
    A, B, C = map(int, input().split())
    A, B = A - 1, B - 1
    if C <= L:
        graph[A][B] = C
        graph[B][A] = C

distance = floyd_warshall(graph, directed=False)

graph = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if distance[i][j] <= L:
            graph[i][j] = 1

supply = floyd_warshall(graph, directed=False)


Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    if distance[s - 1][t - 1] == INF:
        print(-1)
    else:
        print(int(supply[s - 1][t - 1]) - 1)

Measured memory_bytes: 18104
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;

using P = std::pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;


template<typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

const int MOD = 1e9 + 7;

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int n;
    cin>>n;
    int ans=0;
    rep(a,1,n+1){
        ans+=n/a;
        if(n%a==0)ans--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3648
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem (I) in C++
// MAIN IDEA   : max sum of S(X) + S(S(X)) => 100 so brute force
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
vi v1, v2;
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	int n;
	cin >> n;
	lp(i,1,n)
		v1.pb(abs((n - i) - (i - 1)));
	lp(i,1,n)
	{
		int x;
		cin >> x;
		v2.pb(x);
	}
	sort(all(v1));
	sort(all(v2));
	lp(i,0,n-1)
		if (v1[i] != v2[i])
			f(0);
	int po = 1;
	lp(i,1,n/2)
	{
		po *= 2;
		po %= mod;
	}
	f(po);
	return 0;
}

Measured memory_bytes: 1400
use strict;
use warnings;
use utf8;

use feature qw(say);
use Data::Dumper;

my $k = <STDIN>;
chomp $k;

my $string = <STDIN>;
chomp $string;

my $string_array = [split //, $string];
my $count = scalar @$string_array;

if ($count <= $k) {
    say $string;
} else {
    my $former = [@$string_array[0..$k-1]];
    my $former_string = join('', @$former);
    my $latter = '.'  x 3;

    my $str = "$former_string$latter";
    say $str;
}

Measured memory_bytes: 6440
while data = gets
  a, b = data.chomp.split
  a, b = a.to_i, b.to_i
  m = a*b
  r = a%b
  while r>0
    a = b
    b = r
    r = a%b
  end
  puts b.to_s + ' ' +(m/b).to_s
end

Measured memory_bytes: 6096
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
ll X,Y;

void solve(){
  if((X+Y)%3!=0){
    cout << 0 << endl;
    return ;
  }
  ll manu = (X+Y)/3;
  ll m = (2*X-Y)/3;
  ll n = (2*Y-X)/3;
  if(m<0||n<0){
    cout << 0 << endl;
    return ;
  }
  ll ans = 1;
  for(int i=1;i<=manu;i++){
    ans *= i;
    ans %=MOD;
  }
  for(int i=1;i<=m;i++){
    ans *= modinv(i,MOD);
    ans %=MOD;
  }
  for(int i=1;i<=n;i++){
    ans *= modinv(i,MOD);
    ans %= MOD;
  }
  cout << (MOD+ans)%MOD << endl;
}

int main(){
    cin >> X >> Y;
    solve();
    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
s = nsn(n)

cnt = 0
dcnt = 0
dic = defaultdict(int)
for i in range(n):
    for j in range(len(s[i]) - 1):
        if s[i][j] == 'A' and s[i][j + 1] == 'B':
            cnt += 1
    dic['A'] += (s[i][-1] == 'A')
    dic['B'] += (s[i][0] == 'B')
    dcnt += s[i][-1] == 'A' and s[i][0] == 'B'

ans = min(dic['A'], dic['B'])
if dcnt >= 1 and max(dic['A'], dic['B']) == dcnt:
    print(ans - 1 + cnt)
else:
    print(ans + cnt)

Measured memory_bytes: 4060
N = list(map(int, input().split()))
A = list(map(int, input().split()))

# N = [7, 8]
# A = [3, 2, 4, 5, 6, 4, 2]
A = [A[k]-1 for k in range(N[0])]

L = [0]*N[0]
p = 0
t = 0
L[0] = 1
for k in range(N[1]):
    if L[A[p]] == 0:
        L[A[p]] = k+2
        p = A[p]
    else:
        t = 1
        break

if t == 0:
    print(p+1)
else:
    loop = L[p]-L[A[p]]+1
    stop = (N[1]-L[p]+1) % loop

    for k in range(stop):
        p = A[p]
    print(p+1)

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

int main(){
	int sum=0,n,k,x;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x>=abs(x-k)){
			sum+=2*abs(x-k);
		}
		else{
			sum+=2*x;
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

int N;
int T;
int A;
int H[1010];
double aveT[1010];
double Tdif[1010];

int main(){

 cin >> N >> T >> A ;
 for(int i=0; i<N; i++)cin >> H[i];
 for(int i=0; i<N; i++)aveT[i]=T-H[i]*0.006;

  
 
  for(int i=0; i<N; i++) Tdif[i]=abs(aveT[i]-A);
  double *mn=min_element(Tdif,Tdif+N);
 
  printf("%d",mn-Tdif+1);
  
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    string s1,s2;
    s1=s.substr(0,4);
    s2=s.substr(4);
    cout<<s1<<" "<<s2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <tuple>
#include <set>

using namespace std;

using TUP = tuple<long long, int, int, int>;
using TUP3 = tuple<int, int, int>;

int main() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;

	vector<long long> a(x), b(y), c(z);

	for (int i = 0; i < x; i++) { cin >> a[i]; }
	for (int i = 0; i < y; i++) { cin >> b[i]; }
	for (int i = 0; i < z; i++) { cin >> c[i]; }

	sort(a.begin(), a.end(), greater<long long>());
	sort(b.begin(), b.end(), greater<long long>());
	sort(c.begin(), c.end(), greater<long long>());


	vector<long long> ans;
	priority_queue<TUP> que;
	que.push(make_tuple(a[0] + b[0] + c[0], 0, 0, 0));
	set<TUP3> used;

	while (ans.size() < k) {
		auto tup = que.top();
		que.pop();

		int ia = get<1>(tup);
		int ib = get<2>(tup);
		int ic = get<3>(tup);

		auto tup3 = make_tuple(ia, ib, ic);

		if (used.count(tup3) > 0) {
			continue;
		}
		ans.emplace_back(get<0>(tup));
		used.insert(tup3);


		if (ia < x - 1) { que.push(make_tuple(a[ia+1] + b[ib]   + c[ic],   ia+1, ib,   ic)); }
		if (ib < y - 1) { que.push(make_tuple(a[ia]   + b[ib+1] + c[ic],   ia,   ib+1, ic)); }
		if (ic < z - 1) { que.push(make_tuple(a[ia]   + b[ib]   + c[ic+1], ia,   ib,   ic+1)); }
	}


	for (auto x: ans) {
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>

using namespace std;

class Union_Find {
public:
	Union_Find(int n) : d(n, -1) {}

	int find(int x)
	{
		if (d[x] < 0) return x;
		return d[x] = find(d[x]);
	}

	bool unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return false;
		if (-d[x] < -d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}

	int size(int x)
	{
		return -d[find(x)];
	}

private:
	vector<int> d;
};

int main()
{
	int n, m;
	cin >> n >> m;
	Union_Find uf(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		uf.unite(a, b);
	}

	set<int> ans;
	for (int i = 0; i < n; i++) {
		//cout << uf.find(i) << endl;
		ans.insert(uf.find(i));
	}
	cout << ans.size() - 1 << endl;

	return 0;
}

Measured memory_bytes: 7684
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
const int INF = 1e9 + 5;
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int n;
    scanf("%d", &n);
    vector<int> h(n);
    for (int& x : h) {
		scanf("%d", &x);
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j : {i + 1, i + 2}) {
			if (j < n) {
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		}
	}
	printf("%d\n", dp[n-1]);
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 4040
#include<iostream>
#include<string>

int main(){
    std::string S[3];
    for(int i = 0; i < 3; i++){
        std::cin >> S[i];
    }
    if((S[0][S[0].size() - 1] == S[1][0])
        && (S[1][S[1].size() - 1] == S[2][0])){
            std::cout << "YES" << std::endl;
        }else{
            std::cout << "NO" << std::endl;
        }
    return 0;
}


Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 3005;
int n;
double pHead[N], dp[N][N];
bool vis[N][N];

double f(int cur , int head) {
  int tail = cur - head;
  if (cur >= n) return head > tail;
  double &sol = dp[cur][head];
  if (vis[cur][head]) return sol;
  vis[cur][head] = 1;
  return sol = f(cur + 1 , head + 1) * pHead[cur] + f(cur + 1 , head) * (1 - pHead[cur]);
}

int main() {
  scanf("%d" , &n);
  for (int i = 0 ; i < n ; i++) {
    scanf("%lf" , &pHead[i]);
  }
  printf("%.10lf\n" , f(1 , 1) * pHead[0] + f(1 , 0) * (1 - pHead[0]));
  return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 59016
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
ARC103 D
"""

from collections import deque
n = int(input())
xyli = deque([tuple(map(int,input().split())) for i in range(n)])
zli = list(map(lambda t:(t[0]+t[1])%2,xyli))

if len(set(zli))>1:
    print(-1)
    exit()
oe = zli[0]
flag =False
if oe == 0:
    xyli = list(map(lambda t:(t[0]+1,t[1]),xyli))
    flag = True

uvli = list(map(lambda t:(t[0]+t[1],t[0]-t[1]),xyli))

def mode(ubin,vbin):
    if ubin and vbin:
        return('R')
    elif (not ubin) and vbin:
        return('D')
    elif ubin and (not vbin):
        return('U')
    else:
        return('L')

if flag:
    print(32)
    print(" ".join(map(str,[1]+[2**(30-i) for i in range(31)])))
else:
    print(31)
    print(" ".join(map(str,[2**(30-i) for i in range(31)])))

for u,v in uvli:
    ubin = format(((2**31-1)+u)//2,'031b')
    vbin = format(((2**31-1)+v)//2,'031b')
    if flag:
        print('L',end='')
    for i in range(31):
        print(mode(int(ubin[i]),int(vbin[i])),end='')
    print()






Measured memory_bytes: 5164
n, Y = map(int, input().split())
a = 10000
b = 5000
c = 1000

for x in range(n+1):
    for y in range(n+1):
        z = n-x-y
        if z < 0:
            continue
        if a*x+b*y+c*z == Y:
            print(x, y, z)
            exit()
else:
    print(-1, -1, -1)


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

using namespace std;

const int N = 234567;

int n, limit;
vector<pair<int, int>> adj[N], states[N];

void dfs(int x) {
  states[x].clear();
  if (!adj[x].size()) {
    states[x].emplace_back(0, 0);
  } else {
    int l = adj[x][0].first, r = adj[x][1].first;
    dfs(l);
    dfs(r);
    for (auto e : adj[x]) {
      int y = e.first;
      for (auto& state : states[y]) {
        state.first += e.second;
        state.second += e.second;
      }
    }
    if (states[l].size() > states[r].size()) {
      swap(l, r);
    }
    vector<pair<int, int>> all;
    auto cmpy = [&] (const pair<int, int>& a, const pair<int, int>& b) {
      return a.second > b.second;
    };
    auto cmpx = [&] (const pair<int, int>& a, const pair<int, int>& b) {
      return a.first < b.first;
    };
    sort(states[l].begin(), states[l].end(), cmpy);
    sort(states[r].begin(), states[r].end(), cmpx);
    for (int i = 0, j = 0, k = 1e7; i < states[l].size(); ++i) {
      int y = states[l][i].first, z = states[l][i].second;
      while (j < states[r].size() && z + states[r][j].first <= limit) {
        k = min(k, states[r][j].second);
        ++j;
      }
      if (j) {
        all.emplace_back(y, k);
        all.emplace_back(k, y);
      }
    }
    sort(all.begin(), all.end());
    for (int i = 0; i < all.size(); ++i) {
      if (i && all[i].first == all[i - 1].first) {
        continue;
      } else {
        states[x].push_back(all[i]);
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 2, x, y; i <= n; ++i) {
    cin >> x >> y;
    adj[x].emplace_back(i, y);
  }
  auto check = [&] (int x) {
    limit = x;
    dfs(1);
    return states[1].size() > 0;
  };
  int l = 0, r = 1e7;
  while (l != r) {
    int mid = l + r >> 1;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << '\n';
  return 0;
}

Measured memory_bytes: 27488
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long UL; // ULLONG_MAX, %llu
typedef unsigned int UI; //UINT_MAX %u
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const int N = 500005;
const int mod = 1000000007;
int fac[N], inv[N];
int mul(int a, int b){
    return a * 1ll * b % mod;
}
int add(int a, int b){
    if(a+b>=mod) return a+b-mod;
    return a+b;
}
int bp(int a, int b){
    int i, res = a, ans = 1;
    for(i = 1; i <= b; i<<=1,res=mul(res,res)){
        if(i&b) ans = mul(ans, res);
    }
    return ans;
}
int cnr(int a, int b){
    return mul(fac[a], mul(inv[a-b], inv[b]));
}
int calc(int n, int m){
    return mul( mul(cnr(m,n),cnr(m,n)), fac[n] );
}
int main(){
    fac[0] = inv[0] = 1;
    FOR(i, 1, 500000){
        fac[i] = mul(fac[i-1], i);
        inv[i] = bp(fac[i], mod-2);
    }
    int n, m;
    scanf("%d %d",&n,&m);
    int ans = calc(n, m);
    FOR(i, 1, n){
        int x = mul( cnr(m, i), calc(n-i, m-i) );
        if(i & 1) ans = add( ans , mod - x );
        else ans = add(ans, x);
    }
    printf("%d",mul(fac[n],ans));
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 7700
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define SIZE 100
#define rep(i, N) for (i = 0; i < N; i++) //制御変数iを用いてN回転
#define array(N, t) ((t)*)calloc(N, sizeof(t)) //t型N要素の配列を動的確保後0クリア(freeを忘れずに)
#define zero(a); {int iter; rep(iter, sizeof(a)/sizeof((a)[0])) (a)[iter]=0;} //1次元配列aのゼロ初期化?
typedef long long ll;
void printa_int(int *a, int size); //int型の1次元配列aを出力(for debug)

int N, M, X;
int A[12][12];
int C[12];
int Prog[12];

int money(int idx) {
    int i, min = -1, flag = 1;
    rep(i, M) {
        Prog[i] += A[idx][i + 1];
        if (Prog[i] < X) flag = 0;
    }
    if (flag) {
        rep(i, M) {
            Prog[i] -= A[idx][i + 1];
        }
        return A[idx][0];
    }
    for (i = idx + 1; i < N; i++) {
        int temp = money(i);
        if (temp == -1) continue;
        if (min == -1 || min > temp)
            min = temp;
    }
    rep(i, M) {
        Prog[i] -= A[idx][i + 1];
    }
    if (min != -1) min += A[idx][0];
    return min;
}

int main() {
    int i, j, min = -1, pattern;
    scanf("%d %d %d", &N, &M, &X);
    rep(i, N) {
        scanf("%d", C + i);
        rep(j, M) {
            scanf("%d", &A[i][j]);
            A[i][j];
        }
    }
    rep(pattern, 1 << N) {
        int cost = 0, flag = 1;
        zero(Prog);
        rep(i, N) {
            if (pattern >> i & 1) {
                cost += C[i];
                rep(j, M) Prog[j] += A[i][j];
            }
        }
        rep(j, M) {
            if (Prog[j] < X) {
                flag = 0;
                break;
            }
        }
        if (!flag) continue;
        if (min == -1 || min > cost) min = cost;
    }

    printf("%d\n", min);
    return 0;
}

void printa_int(int *a, int size) {
    int i;
    for (i = 0; i < size; i++)
        printf("%d, ", a[i]);
    printf("\n");
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	for(int i=1;i<=1000;i++)
	if(i*8/100==a&&i/10==b)
	{
		printf("%d",i);
		return 0;
	}
	printf("-1");
    return 0;
}

Measured memory_bytes: 256
import math

t = [ [ None,  300,  500,  600,  700, 1350, 1650 ],
      [ None, None,  350,  450,  600, 1150, 1500 ],
      [ None, None, None,  250,  400, 1000, 1350 ],
      [ None, None, None, None,  250,  850, 1300 ],
      [ None, None, None, None, None,  600, 1150 ],
      [ None, None, None, None, None, None,  500 ] ]

l = [ [ None, None, None, None, None, None, None ],
      [    6, None, None, None, None, None, None ],
      [   13,    7, None, None, None, None, None ],
      [   18,   12,    5, None, None, None, None ],
      [   23,   17,   10,    5, None, None, None ],
      [   43,   37,   30,   25,   20, None, None ],
      [   58,   52,   45,   40,   35,   15, None ] ]

def inside(h,m):
    return h*60+m >= 17*60+30 and h*60+m <= 19*60+30

def discount(n):
    return math.ceil(n / 2 / 50) * 50

while True:
    d = int(input())
    if d == 0:
        break

    [hd,md] = map(int,input().split())
    a = int(input())
    [ha,ma] = map(int,input().split())

    tt = t[d-1][a-1]
    ll = l[a-1][d-1]

    if ( ( inside(hd,md) or inside(ha,ma) ) and (ll <= 40) ):
        print(discount(tt))
    else:
        print(tt)
    


      



Measured memory_bytes: 5684
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin>>S;
    int N=S.length();
    int n=0,w=0,s=0,e=0;
    rep(i,0,N){
        if(S[i]=='N') n++;
        if(S[i]=='W') w++;
        if(S[i]=='S') s++;
        if(S[i]=='E') e++;
    }
    if(((n==0&&s==0)||(n&&s))&&((w==0&&e==0)||(w&&e))) cout <<"Yes"<<"\n";
    else cout << "No"<<"\n";
}

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

int main(){
   int m[4][4];
   for(int i=1;i<=3;i++){
       for(int j=1;j<=3;j++){
           cin >> m[i][j];
       }
   }
   //正しいと前提する
   //a1を決める
   int flag=1;
   for(int a1=0;a1<101;a1++){
       int b[4];
       for(int j=1;j<4;j++){
           b[j]=m[1][j]-a1;
       }
       int a[4];
       for(int i=1;i<4;i++){
           a[i]=m[i][1]-b[1];
       }
       for(int i=1;i<4;i++){
           for(int j=1;j<4;j++){
               if(m[i][j]!=a[i]+b[j]) flag=0;
           }
       }
   }
    cout << ((flag==1)? "Yes":"No") << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public int N { get; set; }
        public List<int> A { get; set; }

        public void Solve()
        {
            this.N = int.Parse(Console.ReadLine());
            this.A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToList();

            long val = 1000;
            long count = 0;
            foreach (var i in Enumerable.Range(0, this.N))
            {
                int next = i == this.N - 1 ? 0 : this.A[i + 1];
                if (this.A[i] < next)
                {
                    // 買う
                    var buyCount = val / this.A[i];
                    val -= this.A[i] * buyCount;
                    count += buyCount;
                }
                else
                {
                    // 買わない
                    val += this.A[i] * count;
                    count = 0;
                }
            }

            Console.WriteLine(val);
        }
    }
}


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

using namespace std;



int main(void){
    int N;
    cin>>N;
    vector<long long> H(N);
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    for(int i=N-2;i>=0;i--){
        if(H[i]>H[i+1]){
            H[i]--;
        }
    }
    int count=0;
    for(int i=0;i<N-1;i++){
        if(H[i]<=H[i+1]) count++;
    }
    if(count==N-1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main()
{
    string S;
    cin >> S;
    int cnt = 0;
    rep(i, S.length() / 2)
    {
        if (S[i] != S[S.length() - 1 - i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
  
  int n, m, a[110];

  cin>>n>>m;
  for(int i=1;i<=n;i++) cin>>a[i];

  for(int k=1;k<=m;k++){
    for(int i=1;i<n;i++){
      if(a[i]%k>a[i+1]%k) swap(a[i], a[i+1]);
    }
  }

  for(int i=1;i<=n;i++) cout<<a[i]<<endl;
  
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,t=0,i,j,k,x,p=100;
    cin>>x;
    while(p<x)
    {
        p+=p/100;
        t++;
    }
    cout<<t;
}


Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdlib>

using namespace std;
typedef long long int ll;

bool debug = false;
#define show(x) if (debug) {cout << "" # x << " = " << x << endl;}
#define rep(x, a, b) for (int x = a; x < b; x++)

int main()
{
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;

  int p = 0, q = 0;

  rep (i, 0, n) {
    bool ok = false;

    switch (s[i]) {
    case 'a':
      ok = (p + q < a + b);
      p += ok;
      break;
    case 'b':
      ok = (p + q < a + b) && (q < b);
      q += ok;
    }

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


Measured memory_bytes: 896
#include <iostream>
#include <string.h>
#define nmax 300000
using namespace std;
char s[nmax+5];
int st[nmax+5],dr[nmax+5],n,i,ans;
int main()
{
    cin>>n;
    cin>>s;
    st[0]=0;
    if(s[0]=='W')
        st[0]=1;
    for(i=1;i<n;i++)
    {
        st[i]=st[i-1];
        if(s[i]=='W')
            st[i]++;
    }
    dr[n-1]=0;
    if(s[n-1]=='E')
        dr[n-1]=1;
    for(i=n-2;i>=0;i--)
    {
        dr[i]=dr[i+1];
        if(s[i]=='E')
            dr[i]++;
    }
    ans=min(dr[0],st[n-1]);

    for(i=1;i<n-1;i++)
    {
        ans=min(ans,dr[i+1]+st[i-1]);
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 2944
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll dp[5001][5001];
int main(){
	int N;
	ll H[5001],P[5001];
	fill(dp[0],dp[5001],INFl);
	vpll ph;
	int ans=0;
	ll nowh=0;
	scan(N);
	rep(i,N+1){
		dp[i][0]=0;
	}
	rep(i,N){
		scan(H[i]);scan(P[i]);
		ph.push_back(mp(H[i]+P[i],(ll)i));
	}
	sort(ph.begin(),ph.end());
	rep1(i,N){
		ll h=H[ph[i-1].second],p=P[ph[i-1].second];
		for(int j=1;j<=i;j++){
			if(dp[i-1][j-1]>h){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+p);
			}
		}
	}
	for(int j=N;j>=0;j--){
		if(dp[N][j]!=INFl){
			prin(j);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 195968
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll N, A;
    cin >> N >> A;
    cout << N * N - A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)

int main(){
    string s; cin >> s;
    vector<bool> f(26);
    rep(i, 0, 26){
        f[i] = false;
    } 
    for(int i = 0; s[i] != '\0'; i++){
        f[s[i] - 'a'] = true;
    }
    for(int i = 0; i < 26; i++){
        if(!f[i]){
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define INF 10000000
typedef long long ll;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
using namespace std;

int main()
{
    ll n, sum = 0;
    cin >> n;
    vector<string> ss(n);
    rep(i, n)
    {
        string s;
        cin >> s;
        vector<char> a(all(s));
        sort(all(a));
        ss[i] = string(all(a));
    }
    sort(all(ss));
    ll count = 1;

    rep(i, ss.size() - 1)
    {
        if (ss[i] == ss[i + 1])
        {
            count++;
        }
        else
        {
            if (count >= 2)
            {
                sum += count * (count - 1) / 2;
            }
            count = 1;
        }
    }
    if (count >= 2)
    {
        sum += count * (count - 1) / 2;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5760