akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define MAX 10001

void Count(int *,int *,int);

int main(void){

  int i,n;
  int *A,*B;

  scanf("%d",&n);
  A = malloc(sizeof(int)*(n+1));
  B = malloc(sizeof(int)*(n+1));

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

  Count(A,B,n);

  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i!=n) printf(" ");
  }
  printf("\n");
  return 0;
}

void Count(int *A,int *B,int n){

  int i,j;
  int C[MAX];

  for(i=0;i<MAX;i++){
    C[i] = 0;
  }

  for(j=0;j<n;j++){
    C[A[j]]++;
  }

  for(i=1;i<MAX;i++){
    C[i] = C[i] + C[i - 1];
  }

  for(j=n-1;j>=0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

Measured memory_bytes: 16272
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2



int main() {
	int N;
	cin >> N;
	rep(i, 0, N) {
		int tmp;
		cin >> tmp;
		if (tmp % 2 != 0) {
			puts("first");
			return 0;
		}
	}
	puts("second");

	return 0;
}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

struct Dice{
  int t, r, f;
  int top() { return t; }
  int bottom() { return 7 - t; }
  int right() { return r; }
  int left() { return 7 - r; }
  int front() { return f; }
  int back() { return 7 - f; }
  void toFront() { swap(f, t); t = 7 - t; }
  void toBack() { toFront(); toFront(); toFront(); }
  void toRight() { swap(t, r); t = 7 - t; }
  void toLeft() { toRight(); toRight(); toRight(); }
  void toClock() { swap(f, r); r = 7 - r; }
  void toConter() { toClock(); toClock(); toClock(); }
  int roll(int tt, int ff) {
    REP(i,30) {/*top??¨front???????????¨right????????????*/
      if (i % 10 == 0) toRight();
      else if (i % 10 == 5) toFront();
      else toClock();
      if (tt == t && ff == f) return r;
    }
    return 0;
  }
};

bool isdicesame(int a[7],int b[7]){
	Dice dai1,dai2;
	dai1.t = 1; dai1.f = 2; dai1.r = 3;
	dai2.t = 1; dai2.f = 2; dai2.r = 3;
	bool rst = false;
	REP(i,30) {/*top??¨front???????????¨right????????????*/
      if (i % 10 == 0) dai2.toRight();
      else if (i % 10 == 5) dai2.toFront();
      else dai2.toClock();
      if (b[dai2.t] == a[dai1.t] && b[dai2.f] == a[dai1.f]){
      	if(b[dai2.r]==a[dai1.r]&&b[dai2.bottom()]==a[dai1.bottom()]&&b[dai2.left()]==a[dai1.left()]&&b[dai2.back()]==a[dai1.back()]) rst = true;
      }
    }
    return rst;
}
int main(){
	int n;
	cin >> n;
	int data[100][7];
	REP(i,n) FOR(j,1,7) cin >> data[i][j];
	bool ans = true;
	REP(i,n){
		FOR(j,i+1,n){
			if(isdicesame(data[i],data[j])) ans = false;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1160
import math
a, b, x = map(int, input().split())

# 空いている空間の体積
emp = a*a*b - x
# 空いた空間の三角柱の辺のうち、傾けて長さが変動する一辺の長さ
t_length = (emp * 2) / (a*a)

# 水が入った部分が三角柱型になる時は上の処理、空いた空間が三角柱型であるうちは下の処理、
if t_length >= b:
    print(90 - math.degrees(math.atan2((x*2) / (a*b), b)))
else:
    print(math.degrees(math.atan2(t_length, a)))


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int W,H,x,y,r;
		
		W=scan.nextInt();
		H=scan.nextInt();
		x=scan.nextInt();
		y=scan.nextInt();
		r=scan.nextInt();
		
		if(r<=x&&r<=y&&x<=W-r&&y<=H-r){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
		scan.close();
	}
}

Measured memory_bytes: 17356
#include <stdio.h>

int main(){
  int a, b, c, x, y;
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
  int ans = 0;
  if(x < y){
    if(a + b < 2 * c){
      ans += (a + b) * x;
    }else{
      ans += 2 * c * x;
    }
    if(b < 2 * c){
      ans += b * (y - x);
    }else{
      ans += 2 * c * (y - x);
    }
  }else{
    if(a + b < 2 * c){
      ans += (a + b) * y;
    }else{
      ans += 2 * c * y;
    }
    if(a < 2 * c){
      ans += a * (x - y);
    }else{
      ans += 2 * c * (x - y);
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define D(i, a, b) for (int i = (a); i >= (b); i--)
#define R(i, a, b) for (int i = (a); i < (b); i++)
#define N 500000
#define ALL(vt) vt.begin(), vt.end()
int main()
{
    string s; cin >> s;
    string ans = "";
    for(char c : s){
        if(c == 'B' && ans.size() != 0) ans.pop_back();
        if(c != 'B') ans.push_back(c);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX  500001
int tree[MAX],total;;
void includeFindMaximum(int num)//找子结点最大值
{
	int leftnumber, rightnumber,largestnumber,change;
	leftnumber = num * 2;
	rightnumber = num * 2 + 1;
	if (leftnumber <= total && tree[leftnumber] > tree[num])//左节点值大于父节点
		largestnumber = leftnumber;
	else
		largestnumber = num;
	if (rightnumber <= total && tree[rightnumber] > tree[largestnumber])//右子结点最大
		largestnumber = rightnumber;
	if (largestnumber != num)//当父节点小于任意的节点的时候
	{
		change = tree[largestnumber];//交换数据应单独做成一个函数
		tree[largestnumber] = tree[num];
		tree[num] = change;
		includeFindMaximum(largestnumber);
	}
}


int main()
{	
	 
	cin >> total;
	for (int i = 1; i <= total; i++)
		cin >> tree[i];
	for(int i=total/2;i>=1;i--)//由下到上找最大，
		includeFindMaximum(i);
	for (int i = 1; i <= total; i++)
		cout << " " << tree[i];

	cout << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> ans(n);

  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;

    ans[a-1] = i+1;
  }

  for (int i = 0; i < n; i++)
  {
    cout << ans[i] << " ";
  }
  cout << endl;
  
  
}

Measured memory_bytes: 1152
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;

template<class T>
inline T read(T &a){
    register T x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
    return a = x * flag;
}

template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 

int a, b, c, d, e;
string s;
int main() {
	cin >> a >> b >> c >> d >> e;
	if (a == 0) {
		cout << 1 << endl;
	}
	else if (b == 0) {
		cout << 2 << endl;
	}
	else if (c == 0) {
		cout << 3 << endl;
	}
	else if (d == 0) {
		cout << 4 << endl;
	}
	else if (e == 0) {
		cout << 5 << endl;
	}
	return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        boolean ans = false;
        String[] strArray = new String [3];
        for(int i=0;i<3;i++) {
            strArray[i] = String.valueOf(str.charAt(i));
        }
        for(int i=0;i<3;i++) {
            if(strArray[i].equals("7")) {
                ans = true;
            }
        }
        if(ans == true) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}


Measured memory_bytes: 35596
import queue

K = int(input())
q = queue.Queue()
count=0

for i in range(1,10):
    q.put(i)
x=0
while True:
    count+=1
    x = q.get()

    if count==K:
        break

    xmod10 = x%10

    if xmod10 != 0 :
        q.put(10*x + xmod10 - 1)

    q.put(10*x + xmod10)

    if xmod10 != 9:
        q.put(10*x + xmod10 + 1)

print(x)


Measured memory_bytes: 57172
import copy as cp

n = int(input())
A = [str(x) for x in input().split()]
AS = cp.copy(A)


def bubble(X):
    for i in range(n):
        X[i] = list(X[i])
        X[i][1] = int(X[i][1])

    for i in range(n):
        for j in range(n-1):
            if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

    for i in range(n):
        X[i][1] = str(X[i][1])
        X[i] = "".join(X[i])
    return(X)


BA = bubble(A)



def minsort():

    for i in range(n):
        AS[i] = list(AS[i])
        AS[i][1] = int(AS[i][1])

    for i in range(n):
        minj = i
        for j in range(i,n):
            if (AS[j][1] < AS[minj][1]):
                minj = j

        if (minj != i):
            AS[i],AS[minj] = AS[minj],AS[i]

    for i in range(n):
        AS[i][1] = str(AS[i][1])
        AS[i] = "".join(AS[i])

    return(AS)

MA = minsort()


for k in range(n-1):
    print(str(BA[k])+" ",end = "")
print(str(BA[n-1]))
print("Stable")

for k in range(n-1):
    print(str(MA[k])+" ",end = "")
print(str(MA[n-1]))
if (BA == MA):
    print("Stable")
else :
    print("Not stable")



Measured memory_bytes: 6356
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    vector x(5,0);
    for (int i=0; i<5; i++) cin >> x[i];
    int ans = 0;
    for (int i=0; i<5; i++) {
        if (x[i] == 0) ans = i+1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3172
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n = 3;
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b) --n;
    if (b == c) --n;
    if (c == a) --n;
    cout << max(n, 1) << endl;   
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>
using namespace std;
#define rep(i,n) for (int i=0 ; i<(n);i++)
#define INF 1e9+7
int main() {
	string t;
	cin >> t;

	while (1) {
		int pos = t.find("dreameraser");
		if (pos!=-1)
			if (&t[pos]==&t[0])
		{
			t.erase(pos, 11); continue;
		}
		pos = t.find("dreamerase");
		if (pos != -1)
		if (&t[pos] == &t[0]){
			t.erase(pos, 10); continue;
		}
		pos = t.find("dreamer");
		if (pos != -1)
		if (&t[pos] == &t[0]) {
			t.erase(pos, 7); continue;
		}

		pos = t.find("dream");
		if (pos != -1)
		if (&t[pos] == &t[0]) {
			t.erase(pos, 5); continue;
		}

		pos = t.find("eraser");
		if (pos != -1)
		if (&t[pos] == &t[0]) {
			t.erase(pos, 6); continue;
		}

		pos = t.find("erase");
		if (pos != -1)
		if (&t[pos] == &t[0]) {
			t.erase(pos, 5); continue;
		}

		break;
	}
	/*cout << t << endl;*/
	if (t.empty())
		cout << "YES" << endl;
	else cout << "NO" << endl;
		
}

Measured memory_bytes: 512
///in the name of Allah the most beneficent the most merciful.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
#define out(x) cout << #x << " -> " << x << endl;
using namespace std;
const ll N = 200010, M = 2000005;
ll a;
int solve()
{
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;    return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int ret = solve();
    return 0;
}
/*

*/


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, a[200000], b=0, c=0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (b <= a[i]) {
      c = b;
      b = a[i];
    } else if (c <= a[i]) {
      c = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (b <= a[i]) {
      cout << c << endl;
    } else{
      cout << b << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2432
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 4e2 + 10;
int dp[N][N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cout << n * 800 - n / 15 * 200 << endl;
	return 0;
}

Measured memory_bytes: 256
s = int(input())
A = [s]

for i in A:
    if(i%2==0):
        A.append(int(i/2))
        inde = (int(i/ 2))
    else:
        A.append(int(3*i + 1))
        inde = int(3 * i) + 1
    if(inde in A[:-1]):
        print(len(A))
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define vbi vector<bool> 
#define mod 1000000007
#define INF 1000000000
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define ms(x,v)    memset(x, v, sizeof x)
#define endl '\n'
#define cnl cout<<endl;
#define fr(i,b) for(ll i=0; i<b;i++)
#define frr(i,a,b) for(ll i=a;i<=b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define pi  3.141592653589793238
ll i,j;
int main(){
  

     string s; cin>>s;
     string t; cin>>t;
     ll cnt=0;
     for(i=0;i<3;i++){
      if(s[i]==t[i]) cnt++;
     }
     cout<<cnt<<endl;
  
return 0;
}
 

Measured memory_bytes: 256
S = input()
n = len(S)
ans = 0
for i in range(n):
    for j in range(i, n):
        # ↓文字cがACGTでない。ACGT文字列でない。
        if all('ACGT'.count(c) == 1 for c in S[i:j + 1]):
            ans = max(ans, j - i + 1)
print(ans)

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	cout<<a[n-1];
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;




int main(){
  int h,w;
  int grid[55][55];
  cin>>h>>w;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      char ch;
      cin>>ch;
      if(ch=='#') grid[i][j]=BLACK;
      else grid[i][j]=WHITE;
    }
  }
  
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(grid[i][j]==WHITE) continue;
      grid[i][j]=WHITE;
      bool ok=false;
      queue<P> que;
      que.push(mk(i,j));
      while(!que.empty()){
      P q=que.front(); que.pop();
      for(int k=0; k<4; k++){
        int x=q.second+dx[k],y=q.first+dy[k];
        if(x<0||x>=w||y<0||y>=h) continue;
        if(grid[y][x]==BLACK){
          grid[y][x]=WHITE;
          ok=true;
          que.push(mk(y,x));
        }
      }
      if(!ok){
        cout<<"No"<<en
        RE
      }
      }
    }
  }
  
  cout<<"Yes"<<en
  RE
}


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

// 小数点以下桁数
// fixed << setprecision(i)

int gcd(int a,int b){return (a%b==0?b:gcd(b, a%b));}
int lcm(int a,int b){return a*b/gcd(a, b);}

int main()
{
  string s;
  int64_t k;
  
  cin >> s >> k;
  for (int i = 0; i < min((int64_t)s.size(), k); i++)
  {
    if (s[i] != '1')
    {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fi first
#define se second
using ll=long long int;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	vector<ll>x(n);
	rep(i,n)cin>>x[i];
	ll ans=0;
	for(int i=1;i<n;++i){
		ans+=min(a*(x[i]-x[i-1]),b);
	}	
	cout<<ans<<endl;
}



Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    grid = [input() for _ in range(N)]

    ans = 0
    for i in range(N):
        flag = True
        for j in range(N):
            for k in range(N):
                if j == k:
                    continue
                if grid[j][(k + i)%N] != grid[k][(j + i)%N]:
                    flag = False
                    break
        if flag:
            ans += N
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 73856
#include <stdio.h>

int f(int n) {
	if (n % 2 == 0) {
		return n / 2;
	}
	else {
		return 3 * n + 1;
	}
}


int main(void) {
	int s, cout = 1;
	int memo[100000];
	scanf("%d", &s);
	memo[0] = s;

	int  n = 1;
	while (n)
	{
		s = f(s);
		memo[cout] = s;
		++cout;

		for (int i = 0; i < cout-1; ++i) {
			if (memo[i] == s) {
				n = 0;
				break;
			}
		}

	}

	printf("%d", cout);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll A, B, Q;
vi s;
vi t;
vi x;

int main()
{
    cin >> A >> B >> Q;
    s = vi(A + 2);
    t = vi(B + 2);
    x = vi(Q);
    s[0] = -INF;
    REP(i, A)
    {
        cin >> s[i + 1];
    }
    s[A + 1] = INF;
    t[0] = -INF;
    REP(i, B)
    {
        cin >> t[i + 1];
    }
    t[B + 1] = INF;
    REP(i, Q)
    {
        cin >> x[i];
    }

    REP(k, Q)
    {
        ll i = lower_bound(ALL(s), x[k]) - s.begin();
        ll j = lower_bound(ALL(t), x[k]) - t.begin();
        ll sl = x[k] - s[i - 1];
        ll sr = s[i] - x[k];
        ll tl = x[k] - t[j - 1];
        ll tr = t[j] - x[k];
        ll ans = min({max(sl, tl), max(sr, tr), 2 * min(sl, tr) + max(sl, tr), 2 * min(sr, tl) + max(sr, tl)});
        OUT(ans);
    }
}

Measured memory_bytes: 3712
import sys, heapq
input = sys.stdin.buffer.readline # 入出力高速化

def main():
    N, Q = map(int, input().split())
    tl = [] # イベントタイムライン
    for _ in range(N):
        S, T, X = map(int, input().split())
        tl.append((S-X, 1, X)) # insert
        tl.append((T-X, 0, X)) # erase
    for _ in range(Q):
        D = int(input())
        tl.append((D, 2, 0)) # min
    tl.sort()
    working = list() # 工事中
    todelete = list() # 削除用
    for t, c, x in tl:
        if c == 0: # erase
            heapq.heappush(todelete, x)
        elif c == 1: # insert
            heapq.heappush(working, x)
        else: # min
            while todelete and todelete[0] == working[0]:
                heapq.heappop(todelete)
                heapq.heappop(working)
            print(-1 if not working else working[0])
    return
    
if __name__ == "__main__":
    main()


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

int main()
{
    int n,m,c=0;
    int sum=0;
    cin>>n>>m;

    int n1[n];

    for(int i=0;i<n;i++)
    {
        cin>>n1[i];
        sum=sum+n1[i];
    }
    //cout<<sum<<endl;
    //cout<<sum/(4*m)<<endl;
    for(int i=0;i<n;i++)
    {
       // cout<<n1[i]<<endl;
        if(n1[i]>=(sum/(4.0*m)))
            {c++;
            }

    }
    //cout<<c<<endl;
    if(c>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


}


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

int main(void){
    int sum = 0;
    string s, t;
    
    cin >> s >> t;
    
    rep(i, 3){
        if(s.at(i) == t.at(i)){
            sum++;
        }
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
ll n,w,wi[105],vi[105],dp[100005][105];
int main(){
   cin>>n>>w;
   for(ll i=1;i<=n;i++) cin>>wi[i]>>vi[i];
   for(ll i=1;i<=w;i++){
      for(ll j=1;j<=n;j++){
         if(i-wi[j]>=0) dp[i][j]=max(dp[i][j-1],dp[i-wi[j]][j-1]+vi[j]);
         else dp[i][j]=dp[i][j-1];
      }
   }
   cout<<dp[w][n];
   return 0;
}

Measured memory_bytes: 85560
def main():
    X = int(input())
    A = 0
    B = 0
    while True:
        A += 1
        for B in reversed(range(A*(-1)+1,A)):
            # print(A**5 - B**5)
            if A**5 - B**5 == X:
                print(A,B)
                return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
#include<iostream>

#define MAX 101
using namespace std;

int main(void){
	while( true ){
		int oddDimensionPoints = 0;
		int D[MAX] = {0,};

		while( true ){	
			int c1, c2;

			cin >> c1 >> c2;
			if( c1 == 0 && c2 == 0 ) break;

			D[c1]++;D[c2]++;
		}
		if( cin.eof() ) break;

		for(int i = 0; i < MAX; i++){
			if( D[i] % 2 == 1 ) oddDimensionPoints++;
		}

		if( oddDimensionPoints == 2 && D[1] % 2 == 1 && D[2] % 2 == 1 ) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int N, M;
int cost[100];
string S[100], O[100], Q[100][100], T;
int P[100], K[100];
vector<int> g[100];

int main() {
	while (cin >> N, N) {
		REP(i, N) cin >> S[i] >> P[i];
		cin >> M;
		REP(i, M) {
			cin >> O[i] >> K[i];
			REP(j, K[i]) cin >> Q[i][j];
		}
		cin >> T;
		
		map<string, int> conv;
		REP(i, N) conv[S[i]] = conv.size() - 1;
		
		REP(i, M) g[i].clear();
		REP(i, M) {
			g[i].push_back(conv[O[i]]);
			REP(j, K[i]) g[i].push_back(conv[Q[i][j]]);
		}
		
		fill(cost, cost + 100, INF);
		REP(i, N) chmin(cost[conv[S[i]]], P[i]);
		
		REP(t, M - 1) {
			REP(i, M) {
				ll sum = 0;
				FOR(j, 1, g[i].size()) sum += cost[g[i][j]];
				chmin(cost[g[i][0]], sum);
			}
		}
		
		cout << cost[conv[T]] << endl;
	}
	return 0;
}

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

int main() {
  int N,K;
  string S;
  cin >> N>>K>>S;
  K--;
  if (S.at(K)=='A' ) {
    S.at(K)='a';
    cout << S << endl;
  }
  else if (S.at(K)=='B' ) {
   S.at(K)='b';
    cout << S << endl;
  }
  else if (S.at(K)=='C' ) {
    S.at(K)='c';
    cout << S << endl;
  }
}

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

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
using static Func;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		//SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int M = I[0], K = I[1], X = 1 << M;
		if (K == 0)
		{
			var sb = new StringBuilder("0 0");
			for (var i = 1; i < X; i++) sb.Append($" {i} {i}");
			WriteLine(sb.ToString());
			return;
		}
		if (K >= X || M == 1) { WriteLine(-1); return; }
		var ans = new List<int>();
		for (var i = 0; i < X; i++) if (i != K) ans.Add(i);
		ans.Add(K);
		for (var i = X - 1; i >= 0; i--) if (i != K) ans.Add(i);
		ans.Add(K);
		WriteLine(string.Join(" ", ans));
	}
}
static class Func { }


Measured memory_bytes: 30424
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
int K;
int D[11];
int jdg;
int ans = 0;

int main(){
	
	cin>>N>>K;
	
	REP( i, K ) cin>>D[i];
	
	
	while( 1 ){
		jdg = N;
		ans = 0;
		while( jdg ){
			REP( i, K ) if( jdg%10 == D[i] ) ans = 1;
			jdg /= 10;
		}
		if( !ans ) break;
		N++;
	}
	
	cout<<N<<endl;
	
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll a;cin>>a;cout<<a*a*a+a*a+a<<"\n";
}


Measured memory_bytes: 3644
import heapq
n,h= map(int,input().split())
bl = []
heapq.heapify(bl)
maxa = -1
for i in range(n):
    a,b=map(int,input().split())
    maxa=max(maxa,a)
    heapq.heappush(bl,-b)
count=0
while len(bl)>0:
    if -bl[0]>maxa:
        h-=-heapq.heappop(bl)
        count+=1
        if h<=0:break
    else:break
if h<=0:print(count)
else:print(count + h//maxa + (1 if h%maxa>0 else 0))


Measured memory_bytes: 12940
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;


int main(){
    ll a, b, c, d, t;
    cin >> a >> b >> c >> d >> t;
    ll e = abs(a - c);
    ll f = b - d;
    if(f <= 0){
        cout << "NO" << endl;
        return 0;
    }

    if(f * t >= e){
        cout << "YES" << endl;
    } else {
         cout << "NO" << endl;
    }
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
using namespace std;
 
int main (){
    string s;
    cin >> s;
    int count[26];
    fill(count,count+26,0);
    for(int i=0;i<s.length();i++){
        count[s[i]%26]++;
    }
    for(int i=0;i<26;i++){
        if(count[i]>1){
            puts("no");
            return 0;
        }
    }
    puts("yes");
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
inline char rdc(){
	char c=getchar();
	while(!isupper(c))c=getchar();
	return c;
}
const int N=200050;
char s[N],t[N];
int n,q;
bool opt[N];
inline bool check1(int p){
	for(int i=0;i<q;++i)if(s[p]==t[i])if(opt[i])if(!--p)return 1;
	else;
	else ++p;
	return 0;
}
inline bool check2(int p){
	for(int i=0;i<q;++i)if(s[p]==t[i])if(opt[i])--p;
	else if(++p>n)return 1;
	return 0;
}
int main(){
	int i,l=1,r,m,s1=0,s2;
	char c;
	scanf("%d%d%s",&n,&q,s+1);
	s2=(r=n)+1;
	for(i=0;i<q;++i){t[i]=rdc();opt[i]=rdc()=='L';}
	while(l<=r){
		m=l+r>>1;
		if(check1(m))l=(s1=m)+1;
		else r=m-1;
	}
	l=s1+1;r=n;
	while(l<=r){
		m=l+r>>1;
		if(check2(m))r=(s2=m)-1;
		else l=m+1;
	}
	printf("%d\n",s2-s1-1);
	return 0;
}

Measured memory_bytes: 768
f,b,d,e,m;main(a){
	for(;d=!scanf("%d",&a),m=a;printf("%d\n",m))
		for(m=9e7;(e=d*d*d-a)<1;d++)
			for(b=0;(f=-e-b*b)>=0;)
				m=fmin(d+f+b++,m);
}

Measured memory_bytes: 412
#include <stdio.h>

int main(){
  int n,i,j;
  scanf("%d",&n);

  for(i=1; i<=n; i++){
    if(i%3==0) printf(" %d",i);
    else{
      for(j=i; j>0; j/=10){
	if(j%10==3){
	  printf(" %d",i);
	  break;
	}
      }
    }
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    vector<int> p(N - 1);
    ll res = 0;
    if(a[0] > x) {
        res += a[0] - x;
        a[0] = x;
    }
    rep(i, N - 1) {
        if(a[i] + a[i + 1] > x) {
            res += (a[i] + a[i + 1]) - x;
            a[i + 1] -= (a[i] + a[i + 1]) - x;
        }
    }
    cout << res << endl;
    return 0;
}

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

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

long long N, M; string S, T;

int main() {
	cin >> N >> M >> S >> T;
	long long V = gcd(N, M);
	for (int i = 0; i < S.size(); i++) {
		if (i % (N / V) == 0) {
			long long E = i / (N / V);
			long long E1 = (N / V) * E, E2 = (M / V) * E;
			if (S[E1] != T[E2]) {
				cout << "-1" << endl;
				return 0;
			}
		}
	}
	cout << N * M / V << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

bool IsHarshad(int n) {
  int sum = 0;
  for (int i = n; i > 0; i /= 10) {
    sum += i % 10;
  }
  return n % sum == 0;
}

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

  int N;
  cin >> N;

  if (IsHarshad(N))
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    b[--x] = i;
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0)
      printf(" ");
    printf("%d", b[i] + 1);
  }
  puts("");
  return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

template <class T> T
gcd(T x, T y) { return y ? gcd(y, x % y) : x; }


int gcd3(int a, int b, int c) {
	return gcd(gcd(a, b), c);
}

int main() {
	int N;
	cin >> N;

	int sum = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			for (int k = 1; k <= N; ++k) {
				sum += gcd3(i, j, k);
			}
		}
	}
	
	cout << sum << endl;
	return 0;
}

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

string tree_op(string t1, string t2, string op)
{
  if (t1.empty())
    if (op == "i") return "";
    else return t2;
  if (t2.empty())
    if (op == "i") return "";
    else return t1;

  int n1 = 0, n2 = 0;
  int p1 = 0, p2 = 0;
  while (1)
  {
    if (t1[p1] == '(') n1++;
    else if (t1[p1] == ')') n1--;
    else if (t1[p1] == ',') if (n1 == 1) break;
    p1++;
  }
  while (1)
  {
    if (t2[p2] == '(') n2++;
    else if (t2[p2] == ')') n2--;
    else if (t2[p2] == ',') if (n2 == 1) break;
    p2++;
  }

  return "(" + tree_op(t1.substr(1, p1-1), t2.substr(1, p2-1), op) + "," +
    tree_op(t1.substr(p1+1, t1.size()-2-p1), t2.substr(p2+1, t2.size()-2-p2), op)
    + ")";
}

string union_tree(string t1, string t2)
{
  if (t1.empty()) return t2;
  if (t2.empty()) return t1;
  int n1 = 0, n2 = 0;
  int p1 = 0, p2 = 0;
  while (1)
  {
    if (t1[p1] == '(') n1++;
    else if (t1[p1] == ')') n1--;
    else if (t1[p1] == ',') if (n1 == 1) break;
    p1++;
  }
  while (1)
  {
    if (t2[p2] == '(') n2++;
    else if (t2[p2] == ')') n2--;
    else if (t2[p2] == ',') if (n2 == 1) break;
    p2++;
  }
  return "(" + union_tree(t1.substr(1, p1-1), t2.substr(1, p2-1)) + "," +
    union_tree(t1.substr(p1+1, t1.size()-2-p1), t2.substr(p2+1, t2.size()-2-p2))
    + ")";
}


int main()
{
  string str;
  string op;

  while (getline(cin,str))
  {
    op = str[0];

    int k=1;
    while (str[k]==' ') k++;

    string tree1, tree2;
    while (str[k] != ' ')
    {
      tree1.push_back(str[k]);
      k++;
    }
    while (str[k]==' ') k++;
    while (k < str.size())
    {
      tree2.push_back(str[k]);
      k++;
    }
    cout << tree_op(tree1, tree2, op) << endl;
  }

  return 0;
}

Measured memory_bytes: 1196
#!/usr/bin/env python3
#ABC56 A

a,b = map(str,input().split())

if a == 'D':
    if b == 'H':
        print('D')
    elif b == 'D':
        print('H')
else:
    if b == 'H':
        print('H')
    else:
        print('D')


Measured memory_bytes: 38256
X, Y = map(int, input().split())
mod = 10 ** 9 + 7

if (X + Y) % 3 == 0 : 
    n = (X + Y) // 3
    a = 2 * n - X
    
    if 0 <= a <= n and a * 2 + (n - a) == Y :
        fac = [1]
        inv = [1]
        for i in range(1, n + 1) :
            fac.append(fac[-1] * i % mod)
            inv.append(pow(fac[-1], mod - 2, mod))
        print(fac[n] * inv[n-a] * inv[a] % mod)
    
    else :
        print(0)
        
else :
    print(0)

Measured memory_bytes: 115120
// abc176_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

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

bool bound_check(int i, int j, int N, int M) {return (0 <= i) && (i < N) && (0 <= j) && (j < M);}


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int H, W;
    cin >> H >> W;

    int ch, cw;
    cin >> ch >> cw;
    int dh, dw;
    cin >> dh >> dw;
    ch--; cw--; dh--; dw--;

    vector<string> S(H);
    REP(i, H) cin >> S[i];

    using PP = pair<int, pair<int, int>>;

    priority_queue<PP, vector<PP>, greater<PP>> pq;
    pq.push(PP(0, P(ch, cw)));

    vector<vector<int>> dist(H, vector<int>(W, INF));
    dist[ch][cw] = 0;

    while (!pq.empty()){
        PP pp = pq.top(); pq.pop();

        int cost = pp.first;
        int i = pp.second.first;
        int j = pp.second.second;

        if (i == dh && j == dw){
            print(cost);
            return 0;
        }

        REP(k, 4){
            int ni = i + dx[k];
            int nj = j + dy[k];
            if (not bound_check(ni, nj, H, W)) continue;
            if (S[ni][nj] == '#') continue;

            if (cost < dist[ni][nj]){
                dist[ni][nj] = cost;
                pq.push(PP(cost, P(ni, nj)));
            }
        }

        REPN(k, -2, 2 +1) REPN(l, -2, 2+1){
            int ni = i + k;
            int nj = j + l;
            if (not bound_check(ni, nj, H, W)) continue;
            if (S[ni][nj] == '#') continue;

            int ncost = cost + 1;
            if (ncost < dist[ni][nj]){
                dist[ni][nj] = ncost;
                pq.push(PP(ncost, P(ni, nj)));
            }
        }
    }

    print(-1);

    return 0;
}


Measured memory_bytes: 8620
#include<stdio.h>

int main(void)
{
	int n, m;   //n*m行列
	int i, j;   //くり返し用
	int matrix[100][100];   //行列
	int column_vector[100];   //列ベクトル
	int answer[100] = { 0 };   //行列*列ベクトルの答え

	scanf("%d %d", &n, &m);
	/*行列入力*/
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &matrix[i][j]);
		}
	}
	/*列ベクトル入力*/
	for (i = 0; i < m; i++)
	{
		scanf("%d", &column_vector[i]);
	}
	/*行列*列ベクトル*/
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			answer[i] = answer[i] + matrix[i][j] * column_vector[j];
		}
	}
	/*答え出力*/
	for (i = 0; i < n; i++)
	{
		printf("%d\n", answer[i]);
	}
	return 0;

}


Measured memory_bytes: 2140
n=int(input())
llist=list(map(int,input().split()))
counter=0
for i in range(n):
    for j in range(i+1):
        for k in range(j+1):
            tmp=[llist[i],llist[j],llist[k]]
            if len(tmp)==len(set(tmp)) and sum(tmp)-max(tmp)>max(tmp):
                counter += 1
print(counter)

Measured memory_bytes: 9212
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};


int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;


//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(n); readll(m); readll(v); readll(p);

        vector<ll> score;
        forr(i,0,n) {
            readll(kk); score.push_back(kk);
        }
        if (n-p<=0) {
            cout << n << endl;
            break;
        }

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

        ll ans = binary_search([&score, &p, &m, &v, &n](ll x){
            vector<ll> scores;
            ll max_val = score[x] + m;
            forr(i,0,n) {
                if ((i<n-p+1) && (i!=x)) {
                    scores.push_back(score[i]);
                }
            }
            int v_new = v-(p-1)-1;
            if (v_new <= 0) {
                return (scores.back() <= max_val);
            }
            if (scores.back() > max_val) {
                return false;
            }

            ll filled = 0;
            for(auto s : scores) {
               filled += min(m, max_val-s);
            }
            return (filled >= v_new * m);

        }, 0, n-p);

        cout << n-ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

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

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

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    ll n, m;
    cin >> n >> m;
    map<ll, set<ll>> mp;
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        mp[a].insert(b);
        mp[b].insert(a);
    }

    vector<ll> ans(n + 1, -1);
    ans[1] = 1;

    queue<ll> q;

    q.push(1);
    while (!q.empty()) {
        // キューの先頭の要素を取り出す dequeue(pop)
        ll now = q.front(); q.pop();

        // BFS
        for (cauto next : mp[now]) {
            if (ans[next] == -1) {
                ans[next] = now;
                q.push(next);
            }
        }
    }

    bool exist = true;
    for (int i = 2; i < n + 1; i++) {
        if (ans[i] == -1) {
            exist = false;
        }
    }

    if (! exist) {
        cout << "No" << newl;
    } else {
        cout << "Yes" << newl;
        for (int i = 2; i < n + 1; i++) {
            cout << ans[i] << newl;
        }
    }

    return 0;
}


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

/////////////////////////////////////////////////////////

class Data{
public:
  int C, S, F;
  Data(){C = S = F = 0;}
};

void Main(){
  int N; cin >> N;
  vector<Data> D(N - 1);
  rep(i, 0, N - 1) cin >> D[i].C >> D[i].S >> D[i].F;

  for(int i = 0; i < N; i++){
    int cur = i;
    int time = 0;
    while(cur < N - 1){
      time = max(D[cur].S, (int)ceil((float)time / D[cur].F) * D[cur].F) + D[cur].C;
      cur++;
    }
    cout << time << endl;
  }
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
'use strict'

function main(input) {

  input = input.split(' ')

  const A = input[0][0].toUpperCase()
  const B = input[1][0].toUpperCase()
  const C = input[2][0].toUpperCase()
  const ans = A+B+C
  
  console.log(ans)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
(let* ((n (read))
       (arr (make-array n
                        :element-type 'fixnum
                        :initial-element 0))
       (ans 0))

  (loop for i from 0 to (1- n)
        do (setf (aref arr i) (1- (read))))

  (defun f (k)
    (cond ((< n ans) (princ "-1"))
          ((= k 1) (princ ans))
          (t (incf ans) (f (aref arr k)))))

  (f 0))




Measured memory_bytes: 68196