akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,n) for(int i = a; i < n; i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef long long ll;
int di[] = {-1,0,1,0};
int dj[] = {0,1,0,-1};

struct DICE{
  int dir[4];
  int t,b;
};

struct point{
  DICE dice;
  int height = 0;
};

point board[100][100];

map<VI,PII> mp;

void initDice() {
  mp[{2,3,5,4}] = {1,6};
  mp[{4,5,3,2}] = {6,1};
  mp[{4,1,3,6}] = {5,2};
  mp[{4,6,3,1}] = {2,5};
  mp[{2,6,5,1}] = {3,4};
  mp[{2,1,5,6}] = {4,3};
}

DICE makeDice(int t, int f){
  DICE d;
  d.t = t;
  d.b = 7-t;
  d.dir[2] = f;
  d.dir[0] = 7 - f;
  VI tmp = {d.t,d.dir[2], d.b, d.dir[0] };
  VI a(4);
  rep(i,4){
    rep(j,4) a[j] = tmp[(i+j) % 4];
    if(mp.find(a) != mp.end()){
      PII p = mp[a];
      d.dir[1] = p.first;
      d.dir[3] = p.second;
    }
  }
  return d;
}

void putDice(DICE d, int ci, int cj){

  vector<PII> v(4);
  rep(i,4) v[i] = {d.dir[i],i};
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  int cheight = board[ci][cj].height;
  bool flag = false;
  rep(i,4){
    if(v[i].first <= 3) continue;
    int ni = ci + di[v[i].second];
    int nj = cj + dj[v[i].second];

    if(cheight > board[ni][nj].height){ // 転がる
      int tmp1 = d.b;
      int tmp2 = d.t;
      d.b = d.dir[v[i].second]; //bottom
      d.t = d.dir[(v[i].second + 2) % 4];//top
      d.dir[(v[i].second + 2) % 4] = tmp1;
      d.dir[v[i].second] = tmp2;
      putDice(d, ni, nj);
      flag = true;
      break;
    }
  }
  if(flag == false){
    board[ci][cj].dice = d;
    board[ci][cj].height++;
  }
}

void cntSum(){
  map<int,int> ans;
  rep(i,100)rep(j,100){
    if(board[i][j].height > 0) ans[board[i][j].dice.t]++;
  }

  FOR(i,1,7){
    if(i != 6) cout << ans[i] << " ";
    else cout << ans[i] << endl;
  }
  return;
}

int n;
int main(){
  initDice();
  while(true){
    cin >> n;
    if(n == 0) break;
    rep(i,100)rep(j,100) board[i][j].height = 0;

    rep(i,n){
      int t,f;
      cin >> t >> f;
      DICE d = makeDice(t,f);
      putDice(d,50,50);
      // cout << "###########################" << endl;
      // FOR(_i,47,54){
      //   FOR(_j,47,54){
      //     if(board[_i][_j].height > 0) cout << board[_i][_j].height << " ";
      //     else cout << "- ";
      //   }
      //   cout << endl;
      // }
    }
    cntSum();
  }

}



Measured memory_bytes: 3308
#include <bits/stdc++.h>
#define fst                       \
    ios_base::sync_with_stdio(0); \
    ios::sync_with_stdio(0);      \
    cin.tie(0);                   \
    cout.tie(0);
#define PI acos(-1.0)
#define rd freopen("ip.txt", "r", stdin)
#define wr freopen("op.txt", "w", stdout)
#define wis(x) cout << #x << " is " << x << endl;
#define mem(array, int) memset(array, int, sizeof(array))
#define ll long long int
#define nl cout << endl;
#define mx 10000009
#define MOD 1000000007
using namespace std;



int main()
{
    
    
    int r,c;

    cin>>r>>c;

    cout<<(r-1)*(c-1)<<endl;

    

    return 0;
       
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 999999999;

int main(){
   string s;cin>>s;
   int one = count(s.begin(), s.end(), '1');
   int zero = count(s.begin(), s.end(), '0');
   cout << min(one,zero)*2;
   return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
  int H, i, A[251];
  
  scanf("%d",&H);

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

  for(i = 1; i <= H; i++)
    {
      printf("node %d: key = %d, ",i,A[i]);

      if(i != 1)printf("parent key = %d, ",A[i/2]);
      if(2*i <= H)printf("left key = %d, ",A[2*i]);
      if(2*i+1 <= H)printf("right key = %d, ",A[2*i+1]);
      printf("\n");
    }
  
  return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>

int main(void) {

	double a[500];
	int i=0;
	while( scanf("%lf", &a[i++]) != EOF) ;
	
	int j,k;
	for(j=0; j<i-1; j++){
		for(k=j; k<i-1; k++) {
			if(a[j] < a[k]){
				double temp = a[j];
				a[j] = a[k];
				a[k] = temp;
			}
		}
	}
	
	printf("%.1lf", a[0]-a[i-2]);

	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

#define MOD 1000000007

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for(int i = 0; i < H; i++){
    cin >> a.at(i);
  }
  vvi dp(H, vi(W, 0));
  dp.at(0).at(0) = 1;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(a.at(i).at(j) == '#') continue;
      if(i-1 >= 0) dp.at(i).at(j) += dp.at(i-1).at(j) % MOD;
      if(j-1 >= 0) dp.at(i).at(j) += dp.at(i).at(j-1) % MOD;
      dp.at(i).at(j) %= MOD;
    }
  }
  cout << dp.at(H-1).at(W-1) << endl;
}

Measured memory_bytes: 7168
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const mod = 1000000007

	n := nextInt()

	s := "ACGT"
	ok := func(j, k, l, m int) bool {
		if s[k] == 'A' && s[l] == 'G' && s[m] == 'C' {
			return false
		}
		if s[k] == 'G' && s[l] == 'A' && s[m] == 'C' {
			return false
		}
		if s[k] == 'A' && s[l] == 'C' && s[m] == 'G' {
			return false
		}
		if s[j] == 'A' && s[l] == 'G' && s[m] == 'C' {
			return false
		}
		if s[j] == 'A' && s[k] == 'G' && s[m] == 'C' {
			return false
		}
		return true
	}

	dp := make([][4][4][4]int, n+1)
	for j := 0; j < 4; j++ {
		for k := 0; k < 4; k++ {
			for l := 0; l < 4; l++ {
				str := string(s[j]) + string(s[k]) + string(s[l])
				if str == "AGC" || str == "GAC" || str == "ACG" {
					continue
				}
				dp[3][j][k][l] = 1
			}
		}
	}
	for i := 3; i <= n-1; i++ {
		for j := range s {
			for k := range s {
				for l := range s {
					for m := range s {
						if !ok(j, k, l, m) {
							continue
						}
						dp[i+1][k][l][m] += dp[i][j][k][l]
						dp[i+1][k][l][m] %= mod
					}
				}
			}
		}
	}

	ans := 0
	for j := 0; j < 4; j++ {
		for k := 0; k < 4; k++ {
			for l := 0; l < 4; l++ {
				ans = (ans + dp[n][j][k][l]) % mod
			}
		}
	}
	puts(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll int n;
	cin>>n;
	ll int ar[n], s=0;
	for(ll int i=0;i<n;i++) cin>>ar[i];
	sort(ar, ar+n, greater<ll int>());
	s += ar[0];
	ll int c = 0;
	for(ll int i=1;c<n-2; ){
		++c;
		s += ar[i];
		if(c & 1^1) i++;
	}
	cout<<s<<endl;
	return 0;
}


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

const int MAX_N = 105;

int n;
int F[MAX_N][10];
long long int P[MAX_N][11];
int c[MAX_N];
bool did = false;
long long int best = (long long int)-1e10;
long long int poyo;

void dfs(int i, bool tmp[10]) {
  if (i < 10) {
    bool at[10], af[10];
    for (int i = 0; i < 10; ++i) {
      at[i] = tmp[i];
      af[i] = tmp[i];
    }
    at[i] = true;
    af[i] = false;

    dfs(i + 1, at);
    dfs(i + 1, af);
  }
  else {
    poyo = 0;
    did = false;
    fill(c, c + n, 0);
    for (int i = 0; i < 10; ++i) did |= tmp[i];
    if (did) {

      for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < n; ++j) {
          if (tmp[i] && (F[j][i] == 1)) {c[j]++;}
        }
      }
      for (int i = 0; i < n; ++i) {
        poyo += P[i][c[i]];
      }
      best = max(best, poyo);
    }
  }
}

int main(void){
    // Here your code !
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 10; ++j) {
        scanf("%d", &F[i][j]);
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 11; ++j) {
        scanf("%lld", &P[i][j]);
      }
    }

    bool base[10];
    fill(base, base + 10, false);
    dfs(0, base);
    printf("%lld\n", best);

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <cctype>
#include <cstdlib>
using namespace std;

#define INF (1 << 20)
#define EPS (1e-10)
#define EQ(a,b) (fabs((a)-(b)) < EPS)

int main(){
	int a[4], b[4];
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
		int match = 0;
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				if (a[i] == b[j]) ++match;
			}
		}
		int hit = 0;
		for (int i = 0; i < 4; ++i) {
			if (a[i] == b[i]) ++hit;
		}
		cout << hit << ' ' << match - hit << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 5e3 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll n,m,cur = 1,i;
set<ll> s;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>m;
    ll p = 2*m + 1,piv = m + 1;
    for (i = 1;i <= piv/2;i++) cout<<i<<" "<<piv - i + 1<<"\n",m--;
    piv++;
    for (i = piv;m > 0;i++) cout<<i<<" "<<p - i + piv<<"\n",m--;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
int n;
int a[maxn],b[maxn];
vector<int>p1,p2;
bool vis[maxn];
int main(){
    scanf("%d",&n);

    for(int i=1;i<=n;i++)scanf("%d",&a[i]);

    for(int i=1;i<=n;i++)scanf("%d",&b[i]);

    sort(b+1,b+1+n,greater<int>());


    int st=-1,len=0,val=-1;
    for(int i=1;i<=n;i++){
        if(a[i]==b[i]){
            val=b[i];
            if(st==-1)st=i;
            len++;
            p2.push_back(b[i]);
        }
    }
    if(st==-1){
        printf("Yes\n");
        for(int i=1;i<=n;i++)printf("%d ",b[i]);
        printf("\n");
        return 0;
    }

    int cnt=0;
    for(int i=1;i<=n;i++)
    if(a[i]!=b[i]&&cnt<len&&a[i]!=val&&b[i]!=val){
        cnt++;
     //   printf("a[%d]=%d\n",i,a[i]);
        p1.push_back(b[i]);
        vis[i]=1;
    }

    if(cnt<len){
        printf("No\n");
    }
    else{
     printf("Yes\n");

     int pos1=-1,pos2=-1;
     for(int i=1;i<=n;i++){
        if(a[i]==b[i]){
            b[i]=p1[++pos1];
        }
        else if(vis[i]){
            b[i]=p2[++pos2];
        }
     }

     for(int i=1;i<=n;i++)printf("%d ",b[i]);
        printf("\n");

    }
    return 0;
}


Measured memory_bytes: 5796
import numpy as np

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

up = np.zeros((h, w), dtype=int)
down = np.zeros((h, w), dtype=int)
right = np.zeros((h, w), dtype=int)
left = np.zeros((h, w), dtype=int)

map = np.array([list(input()) for i in range(h)]) == "."

for i in range(1, h):
    up[i] = (up[i-1] + 1) * map[i-1]
    down[h-1-i] = (down[h-i] + 1) * map[h-i]
for j in range(1, w):
    left[:,j] = (left[:,j-1] + 1) * map[:,j-1]
    right[:,w-1-j] = (right[:,w-j] + 1) * map[:,w-j]

print(((up+down+right+left+1) * map).max())


Measured memory_bytes: 219684
N, M = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(N)])
ans = 0
for i in range(len(L)):
    A, B = L[i][0], L[i][1]
    if M > B:
        ans += B * A
        M -= B
    else:
        ans += A * M
        break
print(ans)


Measured memory_bytes: 28648
N,A,B = map(int,input().split())
cnt = 0
for i in range(1,N+1):
    z = i // 10000
    a = (i%10000)//1000
    b = (i%1000)//100
    c = (i%100)//10
    d = i%10
    if z+a+b+c+d >= A and z+a+b+c+d <= B:
        cnt += i
        
print(cnt)

Measured memory_bytes: 3060
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):
    b = B[i]
    a = bisect.bisect_left(A,b)
    c = bisect.bisect_right(C,b)
    ans+=(a*(len(C)-c))
print(ans)

Measured memory_bytes: 23092
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class Main {

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

        final int N = sc.nextInt();

        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            A[i]--;
        }

        final long[] cnt = new long[N];
        for (int i = 0; i < N; i++) {
            cnt[A[i]]++;
        }

        long total = LongStream.of(cnt).map(Main::choose2).sum();

        for (int i = 0; i < N; i++) {
            long ans = total;
            ans -= choose2(cnt[A[i]]);
            ans += choose2(cnt[A[i]]-1);
            System.out.println(ans);
        }
    }

    private static long choose2(long n) {
        return n * (n - 1) / 2;
    }
}


Measured memory_bytes: 98384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N-1);
  for(int i=0;i<N;i++){
    cin >> A[i];
    A[i]--;
  }
   for(int i=0;i<N;i++){
    cin >> B[i];
   }
   for(int i=0;i<N-1;i++){
    cin >> C[i];
   }
  int cnt=0;
  for(int i=0;i<N;i++){
    cnt += B[A[i]];
    if(i>0 && A[i]==A[i-1]+1){
      cnt += C[A[i-1]];
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<time.h>

using namespace std;

#define ll long long
#define MOD 1000000007

int main(){
	int n,k;
	string s;
	cin >> n >> k >> s;
	char a = s[k-1];
	if('a' <= a && a <= 'z'){
		a += ('A' - 'a');
	}else{
		a -= ('A' - 'a');
	}
	s[k-1] = a;
	cout << s << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for dx in range(N-M+1):
    for dy in range(N-M+1):
        flg = True
        for i in range(M):
          if A[i+dx][dy:dy+M] != B[i]:
            flg = False
            break
        if flg:
          print("Yes")
          exit()
print("No")


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

using namespace std;
const int nn = 2e5 + 5;
int arr[nn];

int main() {
	int n, ans = 0;
	scanf("%d", & n);
	for (int i = 0; i < n; i++) {
		scanf("%d", & arr[i]);
	}
	for (int i = 0; i < n; i++) {
		int bil;
		scanf("%d", & bil);
		if (arr[i] > bil) ans += (arr[i] - bil);
	}
	printf("%d\n", ans);
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && a == c && b == c)
    cout << 1 << endl;
  else if(a != b && a != c && b != c)
    cout << 3 << endl;
  else
    cout << 2 << endl;
  return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll X, Y;
    cin >> X >> Y;
    bool flag = false;
    for (ll a = 0; a <= X; ++a)
    {
        ll b = X - a;
        ll sumL = 2 * a + 4 * b;
        if (sumL == Y)
        {
            flag = true;
            break;
        }
    }
    string ans = flag ? "Yes" : "No";

    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
#define N 10
int main(){
  while(true){
    int total;
    cin >> total;
    if( total == 0 ) break;
    for(int i = 0; i < N-1; ++i){
      int t;
      cin >> t;
      total -= t;
    }
    cout << total << endl;
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
data = [tuple(map(int,input().split())) for _ in range(n)]


res = [[None,None,None] for _ in range(n)]
res[0][0] = data[0][0]
res[0][1] = data[0][1]
res[0][2] = data[0][2] 

for i,(a,b,c) in enumerate(data[1:]):
    res[i+1][0] = max(res[i][1],res[i][2])+a
    res[i+1][1] = max(res[i][0],res[i][2])+b
    res[i+1][2] = max(res[i][1],res[i][0])+c
print (max(res[-1][0],res[-1][1],res[-1][2]))


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b, c;

int main() {
	cin >> a >> b >> c;
	
	cout << (a + b >= c ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  input = input.split(" ");
  var A = Number(input[0]);
  var B = Number(input[1]);
  console.log(Math.max((A+B),(A-B),(A*B)));
  

 }
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <stdio.h>

int main(void)
{
    int N, x;
    int *a, temp;
    int i, j;
    char c;
    int accum = 0;
        
    
    scanf("%d %d", &N, &x);
    
    a = (int*)malloc((sizeof(int)*(N+1)));
    
    scanf("%d%c", &a[0], &c);
    
    for(i=1; i<N; i++)
    {
        scanf("%d%c", &temp, &c);
        
        for(j=i-1; j>=0; j--)
        {
            if(temp > a[j])
            {
                a[j+1] = temp;
                
                break;
            }
            else
            {
                a[j+1] = a[j];
            }
        }
        
        if(j < 0)
            a[0] = temp;
    }
    
    for(i=0; i<N; i++)
    {
        accum += a[i];
        
        if(accum > x)
            break;
    }
    
    if(accum >= x)
        printf("%d\n", i);
    else if(accum < x)
        printf("%d\n", i-1);
    
    
    
    free(a);

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

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

int N;
int main(){
    cin >> N;
    string S[N];
    for(int i=0;i<N;i++){
        cin >> S[i];
    }
    set<string> st;
    for(int i=0;i<N;i++){
        st.insert(S[i]);
    }
    cout << st.size() << endl;

}

Measured memory_bytes: 20288
#include <bits/stdc++.h> 
using namespace std; 
  
typedef long long int ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pll> vll; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
  
double EPS = 1e-9; 
long long INF = 1000000000000000005ll; 
double PI = acos(-1); 
#define M 1000000007ll
#define D 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound  
#define SQR(x) ((LL)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a))
#define GCD(a,b) __gcd(a,b)
#define setbits(x)   __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x) 
#define ps(x,y)  fixed<<setprecision(y)<<x
#define endl '\n'
#define ff first 
#define ss second 
#define mp make_pair  
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
  
inline string IntToString(ll a) 
{ 
    char x[100]; 
    sprintf(x, "%lld", a); 
    string s = x; 
    return s; 
} 
  
inline ll StringToInt(string a) 
{ 
    char x[100]; 
    ll res; 
    strcpy(x, a.c_str()); 
    sscanf(x, "%lld", &res); 
    return res; 
} 
  

inline string uppercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'a' && s[i] <= 'z') 
        s[i] = s[i] - 'a' + 'A'; 
    return s; 
} 
  
inline string lowercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'A' && s[i] <= 'Z') 
        s[i] = s[i] - 'A' + 'a'; 
    return s; 
}

bool sortcol( const vector<ll>& v1, 
               const vector<ll>& v2 ) { 
 return v1[0] > v2[0]; 
}

ll primeFactors(ll n)  
{
  	map<ll,ll> m;
    while (n % 2 == 0)  
    {  
        m[2]++;
        n = n/2;  
    }  
 
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
            m[i]++;
            n = n/i;  
        }  
    }   
    if (n > 2)  
        m[n]++;

    ll cnt=0;
    for(auto i=m.begin();i!=m.end();i++){
    	ll x=1;
    	//cout<<i->first<<" "<<i->second<<endl;
    	while(x<=i->second){
    		cnt++;
    		//x++;
    		i->second-=x;
    		x++;
    	}
    }
    return cnt;
}

int main() {
    FAST
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n;
    cin>>n;
    cout<<primeFactors(n)<<endl;
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int ba = b * a;
    string ans = "NO";

    for (int i = a; i <= ba; i += a) {
        if (i % b == c) {
            ans = "YES";
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    int N,X,T;
    cin>>N>>X>>T;
    int tmp = 0;
    tmp = N%X;
    int ttmp = N/X;
    int ans = 0;
    if(tmp==0){
        ans = ttmp * T;
    }
    else{
        ans = (ttmp+1)*T;
    }
    cout<<ans<<endl;
}

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

public class Main {	
	private static void solve(){
		//Implement solution here.
		int A = ni();
		int B = ni();
		int Ar = (int)Math.ceil((double)A * 100 / 8);
		int Br = B * 10;
		int result = -1;
		for(int i = Math.min(Ar, Br); i <= Math.max(Ar, Br); i++) {
			if(i * 8 / 100 == A && i * 10 / 100 == B) {
				result = i;
				break;
			}
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

const string RADIX = "753";
int n;

bool is_753(string s) {
    for(char c : RADIX)
    	if(s.find(c) == string::npos) 
    		return false;
    return true;
}

int dfs(string s) 
{
  if(stoll(s) > (ll)n) return 0;
  int res = is_753(s) ? 1 : 0;
  for(char c : RADIX) res += dfs(s + c);
  return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cout << dfs("0") << ln;
    return 0;
}


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

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

	long long int minimal = 1000000000000000;
	for(int i = 0; i < 5; i++)
	{
		long long int a;
		cin >> a;
		minimal = (a<minimal)? a : minimal;
	}

	cout << (N-1) / minimal + 5 << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws IOException
	{
		// TODO 自動生成されたメソッド・スタブ
		for(int i = 1;; i++)
		{
			String str[] = input(2);
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			if(a == 0 && b == 0) break;
			for(int j = 0; j < a; j++)
			{
				for(int k = 0; k < b; k++)
				{
					if((j == 0 || j == a-1) || (k == 0 || k == b-1))System.out.print("#");
					else System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}

	public static String[] input(int Num) throws IOException
	{
		String str[] = new String[Num];
		String str2 = br.readLine();
		int j = 0;
		for(int i = 0; i < Num; i++)
		{
			if(i < Num - 1)
			{
				str[i] = str2.substring(j, str2.indexOf(" ", j));
				j = str2.indexOf(" ", j) + 1;
			}
			else
			{
				str[i] = str2.substring(j);
			}
		}
		return str;
	}

}



Measured memory_bytes: 30848
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int A;
	int B;

	cin >> A >> B;

	cout << A * B << endl;

	
	return 0;
}

Measured memory_bytes: 3620
import copy
H, W, K = map(int, input().split())
Co = [list(map(str, input())) for _ in range(H)]
ans = 0
for i in range(2 ** H):
  C = copy.deepcopy(Co)
#書き換え
  for j in range(H):
    if (i >> j & 1) == 1:
      for k in range(W):
        C[j][k] = ""
  for l in range(2 ** W):
    C1 = copy.deepcopy(C)
    for m in range(W):
      if (l >> m & 1) == 1:
        for n in range(H):
          C1[n][m] = ""
#数え上げ
    cnt = 0
    for o in range(H):
      for p in range(W):
        if C1[o][p] == "#":
          cnt += 1
    if cnt == K:
      ans += 1
print(ans)

Measured memory_bytes: 9352
n, m = gets.split(" ").map(&:to_i)
cards = gets.split(" ").map(&:to_i).sort!

changes = []
m.times do
  changes << gets.split(" ").map(&:to_i)
end

changes = changes.sort_by {|_, x| x}.reverse

end_flag = false
i = 0
changes.each do |data|
  data[0].times do
    if cards[i] < data[1]
      cards[i] = data[1]
    else
      end_flag = true
      break
    end
    i += 1
    if i >= n
      end_flag = true
      break
    end
  end
  break if end_flag
end


sum = 0
cards.each{|x| sum += x}
puts sum


Measured memory_bytes: 19744
class UnionFind():
    def __init__(self,n):
        self.parents = [-1]*n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        

N,M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
ans = 0
for i in range(M):
    if i == M-1:
        ab = AB[:M-1]
    else:
        ab = AB[:i]+AB[i+1:]
    uf = UnionFind(N)
    for j in ab:
        uf.union(j[0]-1,j[1]-1)
    if uf.parents[uf.find(0)] != - N:
        ans += 1
print(ans)

Measured memory_bytes: 9192
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> odd(100000,0);
    vector<int> even(100000,0);
    for(int i = 0; i<n;i++){
        int tmp;
        cin >> tmp;
        
        if(i % 2 == 0){
            even[tmp] += 1;
            
            
        }else{
            odd[tmp] += 1;
            
        }
    }
    int maxEven = 0;
    int maxOdd = 0;
    int cand1 = 0;
    int cand2 = 0;
    for(int i = 0; i < 100000; i++){
        if(even[maxEven] < even[i]){
            maxEven = i;
        }
    }
    for(int i = 0; i < 100000; i++){
        if(odd[maxOdd] < odd[i] && maxEven != i){
            maxOdd = i;
        }
    }
    cand1 = odd[maxOdd] + even[maxEven];
    maxEven = 0;
    maxOdd = 0;
    for(int i = 0; i < 100000; i++){
        if(odd[maxOdd] < odd[i]){
            maxOdd = i;
        }
    }
    for(int i = 0; i < 100000; i++){
        if(even[maxEven] < even[i] && maxOdd != i){
            maxEven = i;
        }
    }
    cand2 = odd[maxOdd] + even[maxEven];
    if(cand1 > cand2){
        cout << n - cand1 << endl;
    }else{
        cout << n - cand2 << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(0)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
const int MOD = 1000 * 1000 * 1000 + 7; // odd modulus
const int N = 100;
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int main()
{
    Fast_IO();
    ll  n , a  , b  ; 
    cin >>  n >> a >> b  ; 
    cout << min ( n * a  ,  b ) ; 
    



    return 0 ;
}


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

int main() {
    for (;;) {
        string str;
        cin >> str;

        if (str == "-") break;

        int m;
        cin >> m;

        for (int i = 0; i < m; ++i) {
            int j;
            cin >> j;

            str = str.substr(j) + str.substr(0, j);
        }

        cout << str << endl;
    }

    return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>


int MAX(int a,int  b){


return (((a) > (b)) ? (a) : (b));
}
int MIN(int a,int  b){
      return  (((a) < (b)) ? (a) : (b));
     }
int main(){
  int n;
  int i;
  int R[200000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }
  int maxv = -2000000000;
  int minv = R[0];
  for(i=1;i<n;i++){
maxv=MAX(maxv,R[i]-minv);
minv=MIN(minv,R[i]);


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



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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  ll N, K;

  void init() {
    cin >> N >> K;
  }

  void solve() {
    if(K==0) {
      cout << N*N << "\n";
      return;
    }
    ll ans = 0;
    REPC(i, 1, N) {
      ll b = i;
      ans += N/b*max(b-K, 0LL) + max(N%b-K+1, 0LL);
    }
    cout << ans << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 256
/*
Template for vjudge.net

	Author: Iqbal Hossain Rasel
	CodeForces: The_Silent_Man
	AtCoder   : IHR57
	TopCoder  : IHR57

*/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 3005
using namespace std;

typedef long long ll;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

ll dp[MAX][MAX][2];
ll arr[MAX];
int n;

ll solve(int i, int j, int x)
{
    if(i > j)
        return 0;
    if(dp[i][j][x] != -1)
        return dp[i][j][x];
    ll ret = 0;
    if(x == 0){
        ret = arr[i] + solve(i + 1, j, !x);
        ret = max(ret, arr[j] + solve(i, j - 1, !x));
    }
    else{
        ret = solve(i + 1, j, !x) - arr[i];
        ret = min(ret, solve(i, j - 1, !x) - arr[j]);
    }

    return dp[i][j][x] = ret;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif
    cin>>n;

    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    memset(dp, -1, sizeof(dp));
    ll result = solve(0, n - 1, 0);

    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 141696
#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<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
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;
int N;
vint adj[100001];
int p[100001];
bool visited[100001]={};
vint edgedepth[100001];
int hmax[100001]={};
int depthmax=0;
void dfs(int u,int depth){
	visited[u]=1;
	edgedepth[depth].push_back(u);
	depthmax=max(depthmax,depth);
	rep(i,adj[u].size()){
		int v=adj[u][i];
		if(visited[v]==0){
			p[v]=u;
			dfs(v,depth+1);
		}
	}
}
int main(){
	scan(N);
	int u,v;
	scan(u>>v);
	u--; v--;
	rep(i,N-1){
		int a,b;
		scan(a>>b);
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	p[v]=-1;
	dfs(v,0);
	int udepth;
	brep1(d,depthmax){
		rep(j,edgedepth[d].size()){
			int w=edgedepth[d][j];
			if(w==u) udepth=d;
			hmax[w]=max(hmax[w],d);
			hmax[p[w]]=max(hmax[p[w]],hmax[w]);
		}
	}
	int ans=hmax[u]-1;
	int now=u;
	rep(k,(udepth-1)/2){
		now=p[now];
		ans=max(ans,hmax[now]-1);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 15360
#include <iostream>
#include <cstdint>
#include <string>

int main() {
	std::string a, b;
	std::cin >> a >> b;
	uint32_t ans = 0;
	for (uint32_t i = 0;i < a.size();i++) {
		ans += a[i] == b[i];
	}
	std::cout << ans << "\n";
}


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

int main()
{
 long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    long long int e=max(a*c,a*d);
   long long int f=max(b*c,b*d);
 
         cout<<max(e,f)<<endl;
}

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

int main() {
  string s;
  cin>>s;
  int e=s.size();
  int ans=0;
  if(e%2==1) {
    cout<<"No"<<endl;
    return 0;
  }
  else {
    vector<char>vec(e);
    for(int i=0;i<e;i++) {
      vec.at(i)=s.at(i);
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<(e-1);i+=2) {
      if(vec.at(i)!=vec.at(i+1)){
        cout<<"No"<<endl;
        ans++;
        break;
      }
    }
    if(ans==0) {
      cout<<"Yes"<<endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N=2e5+5;
bool ispal(const string &x){
	int n=x.size();
	for (int i = 0,j=n-1; i < n/2; ++i,--j){
		if(x[i]!=x[j])return false;
	}
	return true;
}
int main(){
	string s,a,b;
	cin>>s;
	int n=s.size();
	if(!ispal(s))return puts("No"),0;
	for (int i = 0,j=n-1; i < n/2; ++i,--j){
		a.pb(s[i]);
		b.pb(s[j]);
	}
	if(!ispal(a))return puts("No"),0;
	if(a!=b)return puts("No"),0;
	puts("Yes");



}	

Measured memory_bytes: 256
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

#[fastout]
fn main() {
    input! {
        s: Bytes,
        t: Bytes,
    }
    let n = s.len();
    let m = t.len();
    let mut ans = m;
    for i in 0..=n - m {
        let mut x = 0;
        for j in 0..m {
            if s[i + j] != t[j] {
                x += 1;
            }
        }
        ans = min(ans, x);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2156
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int A;
  scanf("%d", &A);

  long long int N = 1;
  while(N*(N+1)/2 < A) N++;

  string ret = "";
  for(int i=0; i<N; i++) ret += ")";
  for(int i=0; i<N; i++) ret += "(";

  long long int rest = N*(N+1)/2 - A;
  // printf("N = %lld, rest = %lld\n", N, rest);

  int l = N - rest;
  swap(ret[l], ret[N]);

  printf("%s\n", ret.c_str());
  return 0;
}
  



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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;



int main() {
    int N; cin >> N;
    string S; cin >> S;
    ll moji[26] = {};

    rep(i, N) {
        int a = S[i] - 'a';
        moji[a]++;
    }

    ll ans = 1;
    rep(a, 26) {
        ans = (ans * (moji[a] + 1)) % MOD;
    }

    ans = (ans - 1 + MOD) % MOD;

    cout << ans << endl;

}

Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, a[200100], cnt[200100];
int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
		scanf("%d", a + i);
	for (int i = 1; i < n; i++)
		cnt[a[i] - 1]++;
	for (int i = 0; i < n; i++)
		printf("%d\n", cnt[i]);
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//実行部
void Main()
{
  ll n, flag = 0; cin >> n;
  vll a(n); rep(i, n) cin >> a[i];
  ll ans = 1;
  for(ll i = 0;i < n - 1;i++)
  {
    if(a[i] == a[i + 1]) continue;
    if(a[i] < a[i + 1]&&flag == 0)
    {
      flag = 1;
    }
    else if(a[i] > a[i + 1]&&flag == 0)
    {
      flag = 2;
    }
    else if(flag == 1&&a[i] > a[i + 1])
    {
      flag = 0;
      ans++;
    }
    else if(flag == 2&&a[i] < a[i + 1])
    {
      flag = 0;
      ans++;
    }
  }
  fin(ans);
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

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

    int n, p;
    while (cin >> n >> p, n) {
        vector<int> v(n, 0);
        int pot = p;
        rep(r, 1000000) {
            int i = r % n;
            if (pot > 0) {
                pot--;
                v[i]++;
            } else {
                pot += v[i];
                v[i] = 0;
            }

            if (v[i] == p) {
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3016
s = input()
a = ""
b = ""
if len(s)%2==0:
    a = s[:(len(s)//2)]
    b = s[(len(s)//2):][::-1]
else:
    a = s[:(len(s)//2)]
    b = s[(len(s)//2)+1:][::-1]
cnt = 0
for a_, b_ in zip(a,b):
    if not a_ == b_:
        cnt += 1
print(cnt)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int a,int b){
    int ret=1;
    while(b){
        if(b&1)ret=ret*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ret;
}
const int FACTSIZE=1111111;
int fact[FACTSIZE];
int factinv[FACTSIZE];
class FactInit{
public:
    FactInit(){
        fact[0]=1;
        for(int i=1;i<FACTSIZE;i++)fact[i]=fact[i-1]*i%mod;
        factinv[FACTSIZE-1]=mpow(fact[FACTSIZE-1],mod-2);
        for(int i=FACTSIZE-2;i>=0;i--)factinv[i]=factinv[i+1]*(i+1)%mod;
    }
}factInit;


int binom(int n,int k){
    return fact[n]*factinv[n-k]%mod*factinv[k]%mod;
}

int perm(int n,int k){
    return fact[n]*factinv[n-k]%mod;
}

int N;
int A[111111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];

    vint S(N+1);
    rep(i,N)S[i+1]=S[i]+mpow(i+1,mod-2);

    int ans=0;
    rep(i,N){
        int tmp=(S[i+1]+S[N-i]+mod-1)%mod;
        add(ans,tmp*A[i]%mod);
    }
    cout<<ans*fact[N]%mod<<endl;
    return 0;
}

Measured memory_bytes: 19200
#include <iostream>
using namespace std;
char S[4];
int ans=0;
void solve()
{
    for(int i=0;i<4;i++)
    {
        if(S[i]=='+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    } 
}
int main()
{
    for(int i=0;i<4;i++)
    {
        cin >> S[i];
    }
    solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long n;
    cin >> n;
    string str = "";
    while(n > 0){
        n -= 1;
        str = (char)((n % 26) + 97) + str;
        n = n / 26;
    }
    cout << str << endl;
}


Measured memory_bytes: 3624
def main():
    #1. input
    A, B, K = map(int, input().split())
    
    #2. append nums while A+K<B
    ans_set = set()
    for k in range(K):
        if A+k > B:
            break
        ans_set.add(A+k)
        ans_set.add(B-k)
    ans_set = sorted(ans_set)
    
    #3. output
    for ans in ans_set:
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

ll gcd(ll a,ll b){
if(a==0||b==0)return max(a,b);
if(b>a)swap(a,b);
 while(1){
        if(a%b!=0){
            ll tmp=b;b=a%b;
            a=tmp;
        }else{
            return b;
        }
    }
}
int main(){
    int k;
    cin>>k;
    ll ans=0;
    for(ll i=1;i<=k;i++){
        for(ll j=1;j<=k;j++){
            for(ll l=1;l<=k;l++){
                ll s =gcd(i,j);
                ans+=gcd(l,s);
            }
        }
    }
    cout<<ans<<endl;

    
return 0;
}


Measured memory_bytes: 3188