akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if(abs(a-c)<=d || (abs(a-b) <= d && abs(b-c) <= d))cout << "Yes" << endl;
else cout << "No" << endl;

  
}


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

int main() {
    double a, b, c, C, S, L, h;

    cin >> a >> b >> C;
    h = b * sin(C * M_PI / 180.0);
    S = 0.5 * a * h;
    c = sqrt(a * a + b * b - 2 * a * b * cos(C * M_PI / 180.0));
    L = a + b + c;

    cout << fixed;
    cout.precision(4);
    cout << S << endl;
    cout << L << endl;
    cout << h << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;
typedef long long ll;

int main() {
    int N, Q;
    string S;
    cin >> N >> Q;
    cin >> S;
    vector<vector<int>> data(Q, vector<int>(2));
    for (int i = 0; i < Q; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> data.at(i).at(j);
        }
    }
    vector<int> rsum(N + 1, 0);
    int sum = 0;
    for (int i = 0; i < N - 1; i++) {
        if (S.at(i) == 'A' && S.at(i + 1) == 'C') {
            sum++;
        }
        rsum.at(i + 1) = sum;
    }
    int ans;
    for (int i = 0; i < Q; i++) {
        ans = rsum.at(data.at(i).at(1) - 1) - rsum.at(data.at(i).at(0) - 1);
        cout << ans << endl;
    }
}

Measured memory_bytes: 9340
#include <iostream>

using namespace std;

int main()
{
    char str[3];
    scanf("%s", &str);
    if ((str[0]=='A' || str[1]=='A' || str[2]=='A') && (str[0]=='B' || str[1]=='B' || str[2]=='B'))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
	}
	for(int i=0;i<s.size()-2;i++){
		if(s[i]==s[i+2] && s[i]!=s[i+1]){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<"-1"<<" "<<"-1"<<endl;
	return 0;
}

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

typedef struct P {
	int n;
	double p;
	bool operator<(const P &r) {
		return p < r.p;
	}
} P;
P p[24];


int main(){
	for (int i = 0; i < 24; i++) {
		cin >> p[i].n >> p[i].p;
	}
	sort(p, p + 8);
	sort(p + 8, p + 16);
	sort(p + 16, p + 24);
	for (int i = 0; i < 3; i++) {
		cout << p[8 * i].n << " " << p[8 * i].p << endl << p[8 * i + 1].n << " " << p[8 * i + 1].p << endl;
	}
	P a[3] = { p[2],p[10],p[18] };
	sort(a, a + 3);
	cout << a[0].n << " " << a[0].p << endl << a[1].n << " " << a[1].p << endl;

	return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  vector<ll> a(3);
  REP(i, 3) { cin >> a[i]; }
  sort(all(a));

  if (a[0] == a[1]) {
    cout << a[2] << "\n";
  } else {
    cout << a[0] << "\n";
  }
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, K := nextInt(), nextInt()
	var A, B int
	ans := 1
	if K != 1 {
		tmp := 1
		for i := 1; ; i++ {
			tmp *= 2
			if tmp >= K {
				A = i
				break
			}
		}
	}
	A = MinOf(A, N)
	B = MaxOf(N-A, 0)
	if A != 0 {
		ans *= pow(2, A)
	}
	ans += B * K
	fmt.Println(ans)
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<ll, ll> ll_ll;
struct edge { int v, w; };
const int INF = INT_MAX / 2;
const int MOD = 1e9 + 7;
const ll e18 = 1e18;

int main() {
	int N, A, B; cin >> N >> A >> B;
	cout << ((B - A) % 2 == 0 ? "Alice" : "Borys") << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    ll n, m, ans;
    cin >> n >> m;
    if (n > m / 2) ans = m / 2;
    else {
        ans = (n + m / 2) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 1e9
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(min(a,b),c)<<" "<<a+b+c-(min(min(a,b),c)+max(max(a,b),c))<<" "<<max(max(a,b),c)<<endl;
}


Measured memory_bytes: 3116
#include <cstdio>

using namespace std;

int a[1001];

int main() {
    int n, m = 1000000007, i, j;
    long long ans = 1;
    
    scanf("%d", &n);
    
    for (i = 2; i <= n; i++) {
        int x = i;
        
        for (j = 2; j * j <= x; j++) {
            while (x % j == 0) {
                a[j]++;
                x /= j;
            }
        }
        
        if (x > 1) a[x]++;
    }
    
    for (i = 2; i <= n; i++) ans = ans * (a[i] + 1) % m;
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
using namespace std;

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

int main() {
int N;
cin >> N;
vector<int> A(N);
long long i,j;
for(i=0;i<N;i++)cin >> A[i];
long long ans = 0;
map<long long,int> f;
long long lcm;
for(i=1;i<((long long)1<<N);i++) {
lcm = 1;
for(j=0;j<N;j++)if((i&(long long)1<<j) != 0)lcm = lcm*A[j]/gcd(lcm,A[j]);
ans += 1-f[lcm];
f[lcm] = 1;
}
cout << ans << endl;
}


Measured memory_bytes: 4296
#include<iostream>

typedef long long ll;

using namespace std;

int main(){
 ll N; cin >> N;
  ll k = 1;
  
  while( k*(k+1) < 2*N){ k++;}
  
  ll c = k*(k+1) / 2 - N ;
  
  for(int i = 1; i <= k; i++){
    if( i != c){ cout << i << endl;}}
  
  return 0;}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  string s, t;
  cin >> s >> t;
  int min = 10000;
  for (int i = 0; i < s.size()-t.size()+1; i++) {
    string str = s.substr(i, t.size()); //文字列Sのl文字目からl+r-1文字までの部分文字列を返す
    int count = 0;
    //cout << str << endl;
    rep(j, t.size()) {
      if (str.at(j) != t.at(j)) {
        count++;
      }
    }
    if (min > count) {
      min = count;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 3604
N,Y=map(int,input().split())
#x:1000
#y:5000
#z:10000
ans=(-1,-1,-1)
for x in range(N+1):
    for y in range(N+1):
        z=N-x-y
        if z<0:
            continue
        if 1000*x+5000*y+10000*z==Y:
            print(z,y,x)
            exit()
print(-1,-1,-1)

        


Measured memory_bytes: 40812
from collections import defaultdict,deque
v,n=map(int,input().split())
es=[[int(x)for x in input().split()]for _ in range(n)]
outs=defaultdict(list)
ins=defaultdict(int)
for v1,v2 in es:
    outs[v1].append(v2)
    ins[v2]+=1
q=deque(v1 for v1 in range(v+1)if ins[v1]==0)
res=[]
p=[0]*-~v
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2]-=1
        if ins[v2]==0:
            q.append(v2)
            p[v2]=v1
dp=[0]*-~v
for i in res[1:]:
  dp[i]=dp[p[i]]+1
print(max(dp)-1)

Measured memory_bytes: 51076
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
	IOS;
	int t=1;
	while(t--){
		string a,b;
		cin>>a>>b;
		int dp[a.size()+1][b.size()+1];
		// dp[i][j] denotes the maximum length subsequence when we have
		// reached at i in string a and index j in string b
		for(int i=0; i<=a.size(); ++i){
			for (int j = 0; j <= b.size(); ++j)
			{	
				if(i==0 || j==0){
					dp[i][j]=0;
				}
				else if(a[i-1] == b[j-1]){
					dp[i][j] = dp[i-1][j-1] + 1;	
				}
				else
					dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
		// cout<<"Length of longest common subsequence: "<<dp[a.size()][b.size()];
		int len = dp[a.size()][b.size()];
		int i=a.size(), j=b.size(); 
		char ans[len+1]; ans[len] = '\0';
		while(i>0 && j>0){
			if(a[i-1] == b[j-1]){
				ans[len-1] = a[i-1];
				i--; j--; len--;
			}
			else if(dp[i-1][j] > dp[i][j-1] )
				--i;
			else
				--j;
		}	
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define vec_rep(itr,v) for(auto itr = v.begin(); itr != v.end(); ++itr)

int main(void){
    ll N,X,Y;
    cin >> N >> X >> Y;X--;Y--;
    ll ans[N];
    rep(i,N)ans[i]=0;
    rep(i,N)for(int j = i+1;j < N;j++){
        ll num = min(j-i,int(abs(X-i)+abs(Y-j)+1));
        ans[num]++;
    }
    rep1(i,N)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
K = list(map(int,input().rstrip().split()))
CK = [0 for i in range(N + 1)]
ans = 0
for i in K:
  CK[i] += 1
for i in range(N + 1):
  ans += CK[i] * (CK[i] - 1) /2
for i in range(N):
  bans = ans - CK[K[i]] * (CK[K[i]] -1 ) / 2 + (CK[K[i]] -1) * (CK[K[i]] -2) / 2
  print(int(bans))

Measured memory_bytes: 26140
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    boolean[] cups = new boolean[3];
    cups[0] = true;
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      String line = sc.nextLine();
      String[] a  = line.split(",");
      boolean tmp = cups[(a[0].charAt(0)-'A')];
      cups[(a[0].charAt(0)-'A')] = cups[(a[1].charAt(0)-'A')];
      cups[(a[1].charAt(0)-'A')] = tmp;
    }
    if(cups[0]) {
      System.out.println("A");
    }
    if(cups[1]) {
      System.out.println("B");
    }
    if(cups[2]) {
      System.out.println("C");
    }
  }
}

Measured memory_bytes: 26260
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define MOD 1e9+7
int main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    rep(i,0,n)cin>>a[i];
    sort(a,a+n);
    vector<pair<int,int>> vc(m);
    rep(i,0,m)cin>>vc[i].second>>vc[i].first;
    sort(vc.begin(),vc.end(),greater<pair<int,int>>());
    int j=0;
    for(int i=0;i<m;i++){
        for(int left=vc[i].second;left>0;left--){
            if(a[j]<vc[i].first)a[j]=vc[i].first;
            else goto out;
            j++;
            if(j>=n)goto out;
        }
    }
    out:
    ll ans=0;
    rep(i,0,n)ans+=a[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


func numToPrefix(num int) string {
	ab := "AB"
	candidates := "CDEFGHIJKLMNOPQRSTUVWXYZ"
	a := int(math.Floor((float64(num) - 1) / 999))
	return ab + string(candidates[a])
}

func main() {
	a,_ := strconv.Atoi(readLine())
	fmt.Println(numToPrefix(a)) 
}


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

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()

inline bool inside(int i, int j, int n){
  return 0 <= i && i < n && 0 <= j && j < n;
}

pair<int, vector<string> > flip(const vector<string> &field, int x, int y, char c){
  int n = field.size();
  
  int ans = 0;
  vector<string> board = field;
  board[x][y] = c;
  
  REP2(dx, -1, 2)REP2(dy, -1, 2){
    if(dx == 0 && dy == 0) continue;
    int tx = x + dx, ty = y + dy;
    
    while(inside(tx, ty, n) && board[tx][ty] != '.' && board[tx][ty] != c){
      tx += dx;
      ty += dy;
    }
    
    if(inside(tx, ty, n) && board[tx][ty] == c){
      tx = x + dx, ty = y + dy;
      while(inside(tx, ty, n) && board[tx][ty] != '.' && board[tx][ty] != c) {
        board[tx][ty] = c;
        tx += dx;
        ty += dy; 
        ans++;
      }
    }
  }
  return make_pair(ans, board);
}

int main(){
  vector<string> field(8);
  int  bad = 0;
  bool mami = true;  
  REP(i, 8) cin >> field[i];

  while(true){
    int best = 0;
    vector<string> bestboard;
    
    REP(i, 8) REP(j, 8)if(field[i][j] == '.'){
      pair<int, vector<string> > p = flip(field, i, j, mami ? 'o' : 'x');
      if(p.first > best || (!mami && p.first >= best)){
        best = p.first;
        bestboard = p.second;
      }
    }
    
    if(best > 0){
      bad = 0;
      field = bestboard;
    }
    
    if(best == 0 && bad++ > 10) break;
    mami = !mami;
  }
  REP(i, 8) cout << field[i] << endl;
  return 0;
}

Measured memory_bytes: 1188
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second
#define pill pair<ll,ll>
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const ll N = 3e3;
char a;
int main() {
	speed;
	cin >> a;
	cout << (char)((a - 'a' + 1) % 26 + 'a');
}
/*
Timus : 288471KD
Atcoder : I_LOVE_TROTT
Codeforces : Zhabka
mail : dzhon.snoudin@mail.ru
*/



Measured memory_bytes: 256
#pragma optimization_level 3
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  998244353;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ll k, n, l[N], r[N];
ll dp[N], pre[N];

void MAIN(int tc) {
    cin >> n >> k;
    for (int i = 1; i <= k; i++) {
        cin >> l[i] >> r[i];
    }

    pre[1] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            ll L = l[j], R = r[j];
            dp[i] += (pre[max(i - L, 0ll)] - pre[max(i - R - 1, 0ll)] + MOD) % MOD;
            dp[i] %= MOD;
        }
        pre[i] += (pre[i - 1] + dp[i]) % MOD;
        pre[i] %= MOD;
    }

    deb1(dp[n]);
}

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

    int test_cases = 1;
    //cin>>test_cases;
    for (int i = 1; i <= test_cases; i++) {
        MAIN(i);
    }
}

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

using namespace std;

int main(){
    string N;
    while(cin >> N){
        N = "0" + N;
        int a = N.back() - '0', b = 11 - (N.back() - '0');
        for(int i=N.size()-2;i>=0;i--){
            int d = N[i] - '0';
            int na = min(a, b) + d;
            int nb = min(a + 11, b + 9) - d;
            a = na;
            b = nb;
        }
        cout << min(a, b) << endl;
    }
}

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

int main(){

const int MAX_NO=100000;
int m[MAX_NO],f[MAX_NO],r[MAX_NO];
char hyouka[MAX_NO];
int a=0;
long long int b=0;
long long int c=0;

for(int i=1;i<MAX_NO;i++){

cin>>m[i]>>f[i]>>r[i];

a++;

for(long long int j=1;j<2000000000000;j++){
b++;
b--;
b++;
if(b%2==0){
c++;
}
}

if(m[i]==-1 && f[i]==-1 && r[i]==-1){
goto aa;
}

if(m[i]==-1 || f[i]==-1){
hyouka[i]='F';
}

else if((m[i]+f[i])>=80){
hyouka[i]='A';
}
else if((m[i]+f[i])>=65){
hyouka[i]='B';
}

else if((m[i]+f[i])>=50){
hyouka[i]='C';
}

else if((m[i]+f[i])>=30 && r[i]<50){
hyouka[i]='D';
}
else if((m[i]+f[i])>=30 && r[i]>=50){
hyouka[i]='C';
}

else if((m[i]+f[i])<30){
hyouka[i]='F';
}

}

aa:;

for(int i=1;i<a;i++){

cout<<hyouka[i]<<endl;

}

return 0;
}

Measured memory_bytes: 1168
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
ll evaluate(VV &S,ll d,V &prev,V &C,ll j){
    
    ll temp = 0;
    temp+=S[d][j];
    rep(k, 26) {
        if (j == k) {
            continue;
        }
        temp -= C[k] * (d - prev[k]);
    }
    return temp;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll d;
    cin >> d;
    V C(26);
    rep(i, 26) cin >> C[i];
    VV S(d, V(26));
    rep(i, d) { rep(j, 26) cin >> S[i][j]; }
    ll width=250;
    vector<tuple<ll,V,V>> vec;
    V temp;
    rep(i,26)temp.push_back(-1);
    V temp2;
    vec.push_back({0,temp,temp2});
    rep3(i,0,d){
        priority_queue<tuple<ll, V, V>> q;
        ll reg=-INF;
        ll res=0;
        for(auto j:vec){
            ll score=get<0>(j);
            V prev=get<1>(j);
            V history=get<2>(j);
            rep(k,26){
                ll value=evaluate(S,i,prev,C,k);
                V prev2=prev;
                prev2[k]=i;
                V history2=history;
                history2.push_back(k);
                q.push({score+value,prev2,history2});
            }
        }
        vec={};
        for(ll j=0;j<width&&!q.empty();j++){
            vec.push_back(q.top());
            q.pop();
        }
    }
    for(auto i:get<2>(vec[0])){
        cout<<i+1<<endl;
    }
}


Measured memory_bytes: 25360
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100+19;
const int P=N*N+19;
const int oo=(1<<30)-1;

struct Edge{
	int y,f,nxt;
} E[200000];
int las[P],dis[P];
int n,m,cnt,S,T,ans,sx,sy,tx,ty;
char s[N][N];

void Add_Edge(int x,int y,int f){
	E[cnt]=(Edge){y,f,las[x]};las[x]=cnt++;
}
bool bfs(){
	memset(dis,-1,sizeof(dis));
	static int Q[P];
	int f=1,w=0;
	Q[1]=S;dis[S]=1;
	while (f>w){
		int x=Q[++w];
		for (int i=las[x],y;~i;i=E[i].nxt)
			if (E[i].f&&dis[y=E[i].y]==-1){
				dis[y]=dis[x]+1;
				Q[++f]=y;
			}
	}
	return dis[T]!=-1;
}
int dinic(int x,int flow){
	if (x==T||!flow) return flow;
	int res=0;
	for (int i=las[x],y;~i;i=E[i].nxt)
		if (E[i].f&&dis[y=E[i].y]==dis[x]+1){
			int tmp=dinic(y,min(flow,E[i].f));
			res+=tmp,flow-=tmp,E[i].f-=tmp,E[i^1].f+=tmp;
		}
	if (!res) dis[x]=-1;
	return res;
}

int main(){
	memset(las,-1,sizeof(las));
	n=IN(),m=IN();
	For(i,1,n+1) scanf("%s",s[i]+1);
	For(i,1,n+1) For(j,1,m+1){
		if (s[i][j]=='S') sx=i,sy=j;
		if (s[i][j]=='T') tx=i,ty=j;
		if (s[i][j]=='o'){
			Add_Edge(i,j+n,1);
			Add_Edge(j+n,i,1);
		}
	}
	if (sx==tx||sy==ty){
		puts("-1");
		return 0;
	}
	S=n+m+1,T=S+1;
	Add_Edge(S,sx,oo);
	Add_Edge(sx,S,0);
	Add_Edge(S,sy+n,oo);
	Add_Edge(sy+n,S,0);
	Add_Edge(tx,T,oo);
	Add_Edge(T,tx,0);
	Add_Edge(ty+n,T,oo);
	Add_Edge(T,ty+n,0);
	while (bfs()) ans+=dinic(S,oo);
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
	int a, b, c, d, e, f, g, h, i;
	cin >> a >> b >> e;
	g = a + b - e;
	f = a + g - e;
	c = a + e - f;
	d = b + c - g;
	h = a + e - g;
	i = b + e - g;
	cout << a << " " << b << " " << c << endl << d << " " << e << " " << f << endl << g << " " << h << " " << i << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
using namespace std;
bool iseven(int x){ return x % 2 == 0; }
bool isodd(int x){ return !iseven(x); }

int dist(int x, int y) { return abs(x - y); }
int main(){
    int D, N;
    cin >> D >> N;
    // 100でD回割り切れる数字 -> 100 ^ D * N
    // ただし，N=100に関してはちょうどD+1回割り切れてしまうため不適
    //if (N < 100) cout << pow(100, D) * N;
    //else cout << pow(100, D) * (N+1);
    int tmp = 1;
    for(int i = 0; i < D; i++) tmp *= 100;
    if (N == 100) cout << tmp * (N+1);
    else cout << tmp * N;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<pair<int,int>,int>mp;
multiset<int> des[100010];
pair<int,int> st[10000100];int top,js;
bool erz[100010];
int main()
{
	//freopen("in.txt","r",stdin);
	int n;scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		des[u].insert(v);des[v].insert(u);
		mp[make_pair(min(u,v),max(u,v))]++;
	}
	for (int i=1;i<n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		des[u].insert(v);des[v].insert(u);
		mp[make_pair(min(u,v),max(u,v))]++;
	}
	for (map<pair<int,int>,int>::iterator it=mp.begin();it!=mp.end();it++) if (it->second>=2) st[++top]=it->first;
	//cerr<<top<<endl;
	while (top)
	{
		int u=st[top].first,v=st[top].second;top--;
		if ((erz[u])||(erz[v])) continue;js++;if (mp[make_pair(min(u,v),max(u,v))]>2) assert(0);
		des[u].erase(v);des[v].erase(u);
		if (des[u].size()<des[v].size()) swap(u,v);
		erz[v]=true;
		for (multiset<int>::iterator it=des[v].begin();it!=des[v].end();it++) if (!erz[*it])
		{
			if (u==*it) assert(0);
			des[u].insert(*it);des[*it].insert(u);
			mp[make_pair(min(u,*it),max(u,*it))]++;
			if (mp[make_pair(min(u,*it),max(u,*it))]>=2) st[++top]=make_pair(min(u,*it),max(u,*it));
		}
	}
	//for (map<pair<int,int>,int>::iterator it=mp.begin();it!=mp.end();it++)
	//if ((it->second>=2)&&(!erz[it->first.first])&&(!erz[it->first.second])) assert(0);
	
	//cerr<<js<<' '<<top<<endl;
	puts((js==n-1)?"YES":"NO");
}
		
		

Measured memory_bytes: 45952
import java.util.Scanner;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R));

        sc.close();
    }

    static int solve(int N, int[] L, int[] R) {
        int lower = Integer.MIN_VALUE;
        int upper = Integer.MAX_VALUE;
        for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        }

        return Math.max(0, upper - lower + 1);
    }
}

Measured memory_bytes: 58728
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll power(ll k, ll n, int M){
  if (n < 0) return 0;

  ll res = 1;
  while(n > 0) {
    if (n & 1) res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

int N;
vector<int> G[SIZE];
int num_child[SIZE];

ll ans1 = 0, ans2 = 0; // ans = ans1 / ans2

int dfs(int now, int back = -1) {
  int size = 1;

  for (int to : G[now]) {
    if (to == back) continue;

    size += dfs(to, now);
  }

  int r = N - size;

  ans1 = (ans1 + power(2, N - 1, mod) - 1) % mod;

  for (int to : G[now]) {
    if (to == back) {
      ans1 = (ans1 + mod - power(2, r, mod) + 1) % mod;
    } else {
      ans1 = (ans1 + mod - power(2, num_child[to], mod) + 1) % mod;
    }
  }

  return num_child[now] = size;
}

int main() {

  scanf("%d", &N);

  for (int i=0; i<N-1; i++) {
    int a, b;

    scanf("%d%d", &a, &b);
    a--; b--;

    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0);

  ans2 = power(2, N, mod);
  debug(ans1); debug(ans2);

  ll ans = ans1 * power(ans2, mod-2, mod) % mod;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 23040
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
inline ll add(ll a, ll b)   { a += b; if(a>=mod) a-=mod; return a; }
inline ll sub(ll a, ll b)   { a -= b; if(a<0) a+=mod; return a; }

const int N = 101, K = 1e5+5;
ll n, p, a[N], dp[N][K], pre[N][K];

void solve()
{
       cin>>n>>p;
       rep(i,1,n+1) cin>>a[i];
       rep(i,0,n+1) dp[i][0]=pre[i][0]=1;  // if we have zero candies then there is 1 way, give zero to all
       rep(j,0,p+1) pre[0][j]=1; // 0-th row means no child present, total ways of this
       rep(i,1,n+1)              // pre[0][j] = 1 => dp[0][0] = 1, and for j > 0, dp[0][j]=0, means no way to give non-zero candies to zero child
       {                         // simulate first test case to understand
              rep(j,1,p+1)
              {
                     ll f = (j-a[i]-1 >= 0)?pre[i-1][j-a[i]-1]:0;     // all ways from candies = 0...j possible and a[i]>=j
                     ll s = pre[i-1][j];                              // sum : dp[i-1][0] + dp[i-1][1] + ... + dp[i-1][j]
                     dp[i][j] = add(dp[i][j], sub(s,f));
                     pre[i][j] = add(pre[i][j-1],dp[i][j]);
              }
       }
       cout<<dp[n][p]<<endl;
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

const long long mo=1000000000+7;

std::string K;
int D;
long long dp[2][100][10001];//1:strict

int main(){
  std::cin >> K;
  std::cin >> D;
  dp[1][0][0]=1;
  for(int i=0;i<(int)(K.length());++i){
    for(int k=0;k<D;++k){
      for(int j=0;j<=9;++j){
	int nk=(j+k)%D;
	dp[0][nk][i+1]+=dp[0][k][i];
	dp[0][nk][i+1]%=mo;
      }
      for(int j=0;j<(int)(K[i]-'0');++j){
	int nk=(j+k)%D;
	dp[0][nk][i+1]+=dp[1][k][i];
	dp[0][nk][i+1]%=mo;
      }
      int nk=(k+(int)(K[i]-'0'))%D;
      dp[1][nk][i+1]+=dp[1][k][i];
      dp[1][nk][i+1]%=mo;
    }
  }
  std::cout<<(dp[0][0][(int)(K.length())]+dp[1][0][(int)(K.length())]+mo-1)%mo<<std::endl;
  return 0; 
}


Measured memory_bytes: 15872
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.Scanner;

import javax.swing.plaf.synth.SynthSeparatorUI;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		String K = sc.next();
		int k = 101;
		if(K.length() <= 3) k = Integer.valueOf(K);
		
		int index0 = -1;
		
		if(S.charAt(0) == '1'){
			for(int i = 0; i < S.length(); i++){
				if(S.charAt(i) == '1'){
					index0++;
				}else break;
			}
		}
		
		if(index0 == -1) System.out.println(S.charAt(0));
		else{
			if(k <= index0 + 1) System.out.println(1);
			else System.out.println(S.charAt(index0+1));
		}
	}
}

Measured memory_bytes: 21716
#include<stdio.h>
int main(void)
{
	int a,b,c,max;

	scanf("%d %d %d",&a,&b,&c);


	if(a>b){
		max=a;
		a=b;
		b=max;
	}
	if(b>c){
		max=b;
		b=c;
		c=max;
	}

	if(a>b){
		max=a;
		a=b;
		b=max;
	}

	printf("%d %d %d\n",a,b,c);

	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n,m;
    cin>>n>>m;
    vector<pair<long long int,long long int>> v(n);
    REP(i,n){
        v[i]=make_pair(linf,i+1);
    }
    long long int tmp;
    REP(i,m){
        cin>>tmp;
        v[tmp-1]=make_pair(-i,v[tmp-1].second);
    }
    /*
    REP(i,n){
        cout << v[i].first << " " << v[i].second << endl;
    }*/
    sort(v.begin(),v.end());
    
    REP(i,n){
        cout<<v[i].second<<endl;
    }

    return 0;
}



Measured memory_bytes: 6000
#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[100];
    int i;
    int len;
    int flag;
    int count;

    count = 0;
    while (scanf("%s", str) != EOF)
    {
        len = strlen(str);
        flag = 0;
        for (i = 0; i < len / 2; i++){
            if (str[i] != str[len - 1 - i]){
                flag = 1;
                break;
            }
        }
        if (flag == 0){
            count++;
        }
    }
    printf("%d\n", count);

    return (0);
}


Measured memory_bytes: 2028
#include<iostream>
#include<string>
#include<climits>
#include<vector>
#include <sstream>
#include<algorithm>

using namespace std;

int main(void) {

	int a, b, c, x, y;
	cin >> a>>b>>c>>x>>y;
	int buf=INT_MAX;

	for (int pizC = 0;pizC <= max(x, y);pizC++) {
		int cost = (pizC * c * 2 + max(0, (x - pizC) * a) + max(0, (y - pizC)*b));
		if (buf > cost) {
			buf = cost;
		}else {
			cout << buf;
			return 0;
		}
	}
  	cout << buf;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;

}


Measured memory_bytes: 256
while true do
  price, pay = gets.split.map {|x| x.to_i }
  break if price == 0 && pay == 0
  change = pay - price
  sen_yen = change / 1000
  change -= sen_yen * 1000
  gohyaku_yen = change / 500
  change -= gohyaku_yen * 500
  hyaku_yen = change / 100

  puts "#{hyaku_yen} #{gohyaku_yen} #{sen_yen}"
end

Measured memory_bytes: 6108
fun main(args : Array<String>) {
    var n = readLine()!!.toLong()

    if (n == 1L) {
        println(0)
        return
    }

    val ff = factors(n)
    val seen = mutableListOf<Long>()
    var cnt = 0

    outer@while (n > 1) {
        for (f in ff.entries.sortedBy { it.key }) {
            var tmp = 1L
            for (i in 1..f.value) {
                tmp *= f.key
                if (n % tmp == 0L && !seen.contains(tmp)) {
                    cnt++
                    seen.add(tmp)
                    n /= tmp
                    continue@outer
                }
            }
        }
        break
    }

    println(cnt)
}

fun factors(value: Long): Map<Long, Long> {
    val factors = mutableMapOf<Long, Long>()
    val max = Math.sqrt(value.toDouble()).toLong()
    var tmp = value

    for (i in 2..max) {
        while (tmp % i == 0L) {
            tmp /= i
            factors[i] = (factors[i] ?: 0) + 1
        }
    }

    if (factors.isEmpty()) {
        factors[value] = 1
    } else {
        var f = value
        factors.entries.forEach {
            f /= Math.pow(it.key.toDouble(), it.value.toDouble()).toLong()
        }
        if (f != 1L) {
            factors[f] = 1
        }
    }

    return factors
}

Measured memory_bytes: 38600
N = int(input())
A = [0]  # parser
A += [int(input()) for i in range(N)]
count = 1
flashed = A[1]
if flashed==2:
    print(1)
    exit(0)
while True:
    flashed = A[flashed]
    count += 1
    if flashed == 2:
        print(count)
        exit(0)
    elif count > 10 ** 6:
        print(-1)
        exit(0)


Measured memory_bytes: 7852
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x = in.nextInt();
        int t = in.nextInt();
        System.out.println((int)Math.ceil(n/(double)x)*t);
    }
}


Measured memory_bytes: 35680
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

L = input()
N = len(L)
MOD = 10 ** 9 + 7

ans = 0

# one cnt
cnt = 0
for i in range(N):
    if L[i] == '1':
        cnt += 1
        ans += pow(3, N - i - 1, MOD) * pow(2, cnt - 1, MOD)
        ans %= MOD

ans += pow(2, cnt, MOD)
ans %= MOD

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <numeric>
#include <queue>
#include <stack>

using namespace std;
using ll = long long;

int main() {

	int n;
	ll sum = 0, sum1 = 0,ans = 1e15;

	cin >> n;

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

	for (int i = 0; i < n; i++) {
		sum1 += a[i];
		if (i + 1 < n)ans = min(ans, abs(sum - 2 * sum1));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::min;

const MAX_N: usize = 100_005;

#[fastout]
fn main() {
    input! {
    n: usize
    }
    let mut dp = (0..MAX_N).collect::<Vec<usize>>();
    for &i in [6usize, 9usize].iter() {
        for j in 1.. {
            let t = i.pow(j);
            if t > MAX_N { break }
            for i in 0..MAX_N - t {
                dp[i + t] = min(dp[i] + 1, dp[i + t]);
            }
        }
    }
    println!("{}", dp[n]);
}



Measured memory_bytes: 2744
def split_by_0(arr, ans = [])
	return ans if arr.empty?
	index = arr.index(0)
	return ans << arr if index.nil?
	ans << arr[0..index-1] if index != 0
	split_by_0(arr[index+1..-1], ans)
end

def calc(hs, i = 0)
	return i if hs.empty?
	split_by_0(hs).each do |h|
		while !h.include?(0)
			h = h.map{ |h| h - 1 }
			i += 1
		end
		i = calc(h, i)
	end
	i
end

def test
	n = gets.to_i
	hs = gets.split(" ").map(&:to_i)
	calc(hs)
end

p test


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main()
{
    fast();
    ll k;
    cin>>k;
    vb vis(k,false);
    ll num=7%k;
    ll a=0;
    while(!vis[num] && !vis[0])
    {
        a++;
        vis[num]=true;
        num=(num*10+7)%k;
    }
    if(vis[0])
        cout<<a<<nl;
    else
        cout<<-1<<nl;

}


Measured memory_bytes: 3688
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()


alphasm=[chr(i) for i in range(97, 97+26)]
s=input().rstrip()
t=input().rstrip()
u=Counter(list(s))
v=Counter(list(t))
a,b=[],[]
for i in alphasm:
    a.append(u[i])
    b.append(v[i])
a.sort()
b.sort()
if a==b:
    print("Yes")
else:
    print("No")

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

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rep(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long int ll;
using graph = vector<vector<int>>;
using edgedp = vector<vector<pair<int,ll>>>;
constexpr int INF=1000000;
//constexpr int MOD=998244353;
constexpr int MOD=1e9+7;


int n,k,r,s,p;
int point(char c){
    if(c=='r'){
        return p;
    }else if(c=='p'){
        return s; 
    }else{
        return r;
    }
}


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

    
    cin >> n >> k;
    cin >> r >> s >> p;
    string t;
    cin >> t;

    bool pick=true;
    ll sum=0;
    rep(i,k){
        int cur=i;
        pick=true;
        sum+=point(t[i]);
        cur+=k;
        while(cur<n){
            if(t[cur]==t[cur-k]){
                pick = !pick;
            }else{
                pick=true;
            };
            if(pick) sum+=point(t[cur]);
            cur+=k;
        }
    }
    cout << sum << "\n";
    

}   




Measured memory_bytes: 512
class UnionFind
  def initialize(n)
    @root = Array.new(n)
    @rank = Array.new(n)
    @size = Array.new(n)
    (0...n).each do |i|
      @root[i] = i
      @rank[i] = 0
      @size[i] = 1
    end
  end

  def find(x)
    if @root[x] == x
      x
    else
      @root[x] = find(@root[x])
    end
  end

  def unite(x, y)
    x_root = find(x)
    y_root = find(y)
    return if x_root == y_root

    if @rank[x_root] < @rank[y_root]
      @root[x_root] = y_root
      @size[y_root] += @size[x_root]
    else
      @root[y_root] = x_root
      @size[x_root] += @size[y_root]
      if @rank[x_root] == @rank[y_root]
        @rank[x_root] += 1
      end
    end
    nil
  end

  def size(x)
    x_root = find(x)
    @size[x_root]
  end

  def same?(x, y)
    find(x) == find(y)
  end
end

N = gets.to_i
points = N.times.map do |i|
  x, y = gets.split.map(&:to_i)
  [i, x, y]
end

edges = Array.new((N - 1) * 2)
x_sorted = points.sort_by { |_, x, _| x }
y_sorted = points.sort_by { |_, _, y| y }
(N - 1).times do |n|
  i, x, _ = x_sorted[n]
  j, x2, _ = x_sorted[n + 1]
  yen = (x - x2).abs
  edges[n] = [i, j, yen]
end
(N - 1).times do |n|
  i, _, y = y_sorted[n]
  j, _, y2 = y_sorted[n + 1]
  yen = (y - y2).abs
  edges[(N - 1) + n] = [i, j, yen]
end

def kruskal(n, edges)
  edges.sort_by! { |_, _, c| c }
  uf = UnionFind.new(n)
  ret = 0
  edges.each do |u, v, c|
    if !uf.same?(u, v)
      uf.unite(u, v)
      ret += c
    end
  end
  ret
end

puts kruskal(N, edges)

Measured memory_bytes: 24272
#include<iostream>
using namespace std;
int main(){
    long long h,n;
    cin >> h >> n;
    long long pre, all = 0;
    for(int i = 0;i < n; i++){
        cin >> pre;
        all += pre;
    }
    if(all >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int):
    dp = [[-1]*(X+1) for _ in range(7)]
    price = [100,101,102,103,104,105]
    m = [10**5]*6

    for i in range(7):
        dp[i][0] = 10**5

    ## i番目まででjを払えるか
    for i in range(6):
        for j in range(X+1):
            if dp[i][j]>=0:
                dp[i+1][j] = m[i]
            elif j < price[i] or dp[i+1][j-price[i]]<=0:
                dp[i+1][j] = -1
            else:
                dp[i+1][j] = dp[i+1][j-price[i]]-1

    if dp[6][X]>=0:
        print(1)
    else:
        print(0)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


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

using namespace std;


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

	int n, q;
	cin >> n;
	vector<int>S(n);
	for (int i = 0; i < n; ++i)cin >> S[i];
	sort(S.begin(), S.end());
	cin >> q;
	vector<int>T(q);
	for (int i = 0; i < q; ++i)cin >> T[i];
	sort(T.begin(), T.end());
	int ans = 0;
	for (int i = 0; i < q; ++i) {
		if(binary_search(S.begin(), S.end(), T[i]))++ans;
	}cout << ans << endl;
}

Measured memory_bytes: 1788
#include <iostream>
 
using namespace std;
 
int main(){
 int N,i,j,k;
 long long a[5];
 cin >> N;
 string s;
 for (i=0;i<5;i++) {
  a[i]=0;
 }
 for (i=0;i<N;i++) {
  cin >> s;
  if (s.substr(0,1)=="M") {
   a[0]+=1;
  } else if (s.substr(0,1)=="A") {
   a[1]+=1;
  } else if (s.substr(0,1)=="R") {
   a[2]+=1;
  } else if (s.substr(0,1)=="C") {
   a[3]+=1;
  } else if (s.substr(0,1)=="H") {
   a[4]+=1;
  }
 }
 
 unsigned long long n=0;
 for (i=0;i<3;i++) {
  for (j=i+1;j<4;j++) {
   for (k=j+1;k<5;k++) {
    n+=a[i]*a[j]*a[k];
   }
  }
 }
 cout << n;
 return 0;
}

Measured memory_bytes: 256