akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){

    int m,f,r;
    
    while(1){
        cin >> m >> f >> r;
        if(m==-1 and f==-1 and r==-1){
            break;
        }else if(m==-1 or f==-1){
            cout << "F" << endl;
        }else if(m+f>=80){
            cout << "A" << endl;
        }else if(m+f>=65){
            cout << "B" << endl;
        }else if(m+f>=50){
            cout << "C" << endl;
        }else if(m+f>=30 and r>=50){
            cout << "C" << endl;
        }else if(m+f>=30){
            cout << "D" << endl;
        }else{
            cout << "F" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3072
package main

import "fmt"

func main() {
	s := make([]int, 5)
	for i := range s {
		fmt.Scan(&s[i])
	}

	lastOrder := -1
	lastOrderRemainder := 10
	for i := range s {
		if s[i]%10 < lastOrderRemainder && s[i]%10 != 0 {
			lastOrder = i
			lastOrderRemainder = s[i] % 10
		}
	}

	if lastOrder == -1 {
		sum := 0
		for i := range s {
			sum += s[i]
		}
		fmt.Println(sum)
		return
	}

	sum := 0
	for i := range s {
		if i == lastOrder {
			continue
		}
		sum += s[i]
		for sum%10 != 0 {
			sum++
		}
	}
	fmt.Println(sum + s[lastOrder])
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll i,n,ans,a[100001];
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(i=1;i<n;i++)ans+=a[i];
	printf("%lld",ans+a[n]/2);
}

Measured memory_bytes: 256
nk = input()
nk_list = nk.split(" ")
n = int(nk_list[0])
k = int(nk_list[1])
h = input()
h_list = h.split(" ")

number = 0
for i in range(n):
    if int(h_list[i]) - k >= 0:
        number += 1
print(number)

Measured memory_bytes: 9988
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, k, a[5010];
bool d[5010][5010], d2[5010][5010];
int cnt;
int ans;
int cum[5010];

signed main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt += a[i];
	}
	if (cnt < k) {
		cout << n << endl;
		return 0;
	}
	d[0][0] = true;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			if (d[i - 1][j])d[i][j] = true;
			if (a[i] <= j && d[i - 1][j - a[i]])d[i][j] = true;
		}
	}
	d2[n + 1][0] = true;
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j <= k; j++) {
			if (d2[i + 1][j])d2[i][j] = true;
			if (a[i] <= j && d2[i + 1][j - a[i]])d2[i][j] = true;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] >= k)continue;
		cum[0] = 1;
		for (int j = 1; j <= k; j++) {
			if (d2[i + 1][j])cum[j] = cum[j - 1] + 1;
			else cum[j] = cum[j - 1];
		}
		bool bl = true;
		for (int j = 0; j < k; j++) {
			if (!d[i - 1][j])continue;
			if (j + a[i] >= k) {
				bl = false;
				break;
			}
			if (cum[k - 1 - j] - cum[k - 1 - j - a[i]]) {
				bl = false;
				break;
			}
		}
		if (bl)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 49280
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e5+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};
int n;
string s[maxn];

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s+1,s+n+1);
    LL ans=0,cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(s[i]!=s[i+1])
        {
            ans+=cnt*(cnt-1)/2;
            cnt=1;
        }
        else
        {
            cnt++;
        }
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>

int main(){
  int i, a, b, temp;

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

  if(a == b){
    printf("%d\n", a);
    return 0;
  }
  
  if(a<b){
    temp = a;
    a = b;
    b = temp;
  }

  temp = a%b;
  
  while(1){
    a = b;
    b = temp;
    temp = a%b;
    if(temp == 0) break;
    }

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

Measured memory_bytes: 592
s = input()
a = [int(c) for c in s]

def ans1(a):
	c = 0
	for i in range(len(a)):
		if(i%2 == 0 and a[i]==1):
			c = c + 1
		elif(i%2 == 1 and a[i] == 0):
			c = c + 1
	return c
	
def ans2(a):
	c = 0
	for i in range(len(a)):
		if(i%2 == 0 and a[i]==0):
			c = c + 1
		elif(i%2 == 1 and a[i] == 1):
			c = c + 1
	return c

ans = min(ans1(a), ans2(a))
print(ans)

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

struct card{
    char suit;
    int value;
};

void bubbleSort(card c[], int n);
void selectionSort(card c[], int n);
bool isSame(card A[], card B[], int n);

int main() {
    int n;
    cin >> n;
    card A[n], B[n];
    
    for(int i=0;i<n;i++){
        cin >> A[i].suit >> A[i].value;
        B[i] = A[i];
    }
    bubbleSort(A, n);
    selectionSort(B, n);
    
    for(int i=0; i<n; i++){
        cout << A[i].suit << A[i].value;
        if (i<n-1){
            cout << " ";
        }
    }
    cout << endl << "Stable" << endl;
    
    for(int i=0; i<n; i++){
        cout << B[i].suit << B[i].value;
        if (i<n-1){
            cout << " ";
        }
    }
    if (isSame(A, B, n)){
        cout << endl << "Stable" << endl;
    }else{
        cout << endl << "Not stable" << endl;
    }
    return 0;
}// End of main

void bubbleSort(struct card C[], int n){
    bool flag = true;
    int i,j;
    i = 0;
    card temp;
    while (flag) {
        flag = false;
        for (j = n-1; j>i; j--){
            if (C[j].value < C[j-1].value){
                temp = C[j];
                C[j].value = C[j-1].value;
                C[j].suit = C[j-1].suit;
                C[j-1] = temp;
                flag = true;
            }
        }
        i++;
    }//End of while
}// End of bubble sort

void selectionSort(card C[], int n){
    int min;
    card temp;
    for (int i = 0; i<n; i++){
        min = i;
        for (int j = i; j<n; j++){
            if (C[j].value < C[min].value){
                min = j;
            }
        }
        temp = C[i];
        C[i] = C[min];
        C[min] = temp;
    }
}

bool isSame(card A[], card B[], int n){
    for(int i=0; i<n; i++){
        if (A[i].suit != B[i].suit){
            return false;
        }
    }
    return true;
}

Measured memory_bytes: 1168
# C
N = int(input())
S = list(input())
S1 = S[:N]
S2 = S[2*N-1:N-1:-1]

dict_1 = dict()
q_list = [""]*(2**N)
res = 0

for i in range(2**N):
    sb = bin(2**N+i)[3:]
    red = []
    blue = []
    red2 = []
    blue2 = []
    for j in range(N):
        if sb[j]=="0":
            red.append(S1[j])
            red2.append(S2[j])
        else:
            blue.append(S1[j])
            blue2.append(S2[j])
    sss = "".join(red+["|"]+blue)
    sss2 = "".join(red2+["|"]+blue2)
    if sss not in dict_1.keys():
        dict_1[sss] = 1
    else:
        dict_1[sss] += 1
    q_list[i] = sss2
for q in q_list:
    res += dict_1.get(q, 0)
print(res)

Measured memory_bytes: 54884
#include <bits/stdc++.h>
#define H ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
using namespace std;
const ll  mod = 1000000007;


int solve(int n, int m, int counter){
	//base case
	if (n == m) return counter;
	if (m < n) return counter + (n - m);

	//sol steps
	if (m % 2 == 0)
		return solve(n, m / 2, counter + 1);
	return solve(n, m + 1, counter + 1);
}

int main()
{
	H
	int n, k;
	cin >> n >> k;
	int arr[n + 1];
	for (int i = 1; i <= n; i++){
		cin >> arr[i];
	}
	int dp[n + 1];
	memset(dp, 0x3f3f3f3f, sizeof dp);
	dp[0] = dp[1] = 0;
	dp[2] = abs(arr[1] - arr[2]);
	for (int i = 3; i <= n; i++){
		for (int j = 1; i - j > 0 && j <= k; j++){
			dp[i] = min(dp[i], dp[i - j] + abs(arr[i] - arr[i - j]));
		}
	}
	cout << dp[n];
	return 0 ;
}


Measured memory_bytes: 1152
s = str(input())
n = len(s)

w = []
for i in range(n):
    w.append(int(s[i]))

counta = 0
for i in range(n):
    if i % 2 == 0:
        if w[i] != 0:
            counta = counta + 1
    else:
        if w[i] != 1:
            counta = counta + 1

countb = 0
for i in range(n):
    if i % 2 == 0:
        if w[i] != 1:
            countb = countb + 1
    else:
        if w[i] != 0:
            countb = countb + 1

print(min(counta, countb))

Measured memory_bytes: 3956
S = input()
K = int(input())
l = len(S)
topk = []
a = []

for i in range(l):
    for j in range(i + 1, i + K + 1):
        if j > l:
            break
        ss = S[i: j]
        a.append(ss)

print(sorted(list(set(a)))[K-1])


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

const long long INF=1012345678012345LL;

int main(){
	int n;
	scanf("%d",&n);
	int arr[2*n-1];
	for(int i=0;i<2*n-1;i++)scanf("%d",&arr[i]);
	int t[2*n-1];
	int l=1,r=2*n-1;
	while(l<r){
		int m=(l+r+1)/2;
		for(int i=0;i<2*n-1;i++)t[i]=(arr[i]>=m);
		int a=-1,cur=0;
		for(int x=1;x<n;x++){
			if(t[n-1+x]==t[n-1+(x-1)]&&t[n-1-x]==t[n-1-(x-1)]){
				if(t[n-1+x]==t[n-1-x])a=t[n-1+x];
				else{
					if(cur>=x)a=1;
					else a=0;
				}
				break;
			}else if(t[n-1+x]==t[n-1+(x-1)]){
				a=t[n-1+x];break;
			}else if(t[n-1-x]==t[n-1-(x-1)]){
				a=t[n-1-x];break;
			}
			cur+=t[n-1-x]+t[n-1+x];
		}
		if(a==-1){
			if(t[0]==0)a=0;
			else a=1;
		}
		if(a)l=m;
		else r=m-1;
	}
	printf("%d",l);
}


Measured memory_bytes: 1920
import sys
write=sys.stdout.write

h_numbers=[]
w_numbers=[]

while True:
    numbers=[]
    numbers=input().split()
    numbers[0]=int(numbers[0])
    numbers[1]=int(numbers[1])
    if numbers[0]==0 and numbers[1]==0:
        break
    h_numbers.append(numbers[0])
    w_numbers.append(numbers[1])

for i in range(0,len(h_numbers)):
    for j in range(0,h_numbers[i]):
        for k in range(0,w_numbers[i]):
            if (j+k+2)%2==0:
                write('#')
            else:
                write('.')
        print()
    print()

Measured memory_bytes: 8376
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

int main() {
	int x, y; cin >> x >> y;
	if((x + y) % 3 != 0) cout << "0" << endl;
	else {
		int a, b;
		a = (2 * y - x) / 3;
		b = (2 * x - y) / 3;
		if(a < 0 || b < 0) cout << "0" << endl;
		else {
			init_nCk(1001001);
			cout << nCk(a + b, a) << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 23808
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define REP(i, n) for(int i=1; i<=(int)(n); i++)

using namespace std;

int main(){
    string hoge;

    cin >> hoge;

    if (hoge == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }

    return 0;
}



Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define eps 1e-7
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
mt19937_64 mrand(random_device{}()); 
const int mod = 1e9 + 7;
const int N = 110;
const int M = 1e5 + 10;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}
inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}
inline ll C(ll y, ll x) { ll ans = 1; if(y < 0 || x < 0 || y < x) return 0; y %= mod; if(!y || !x) return 1; rep(i, 0, x-1) ans = ans * (y-i) % mod; rep(i, 1, x) ans = ans * Pow(i, mod-2) % mod; return ans; }
/*==================================================*/

int n, k, a[N];
ll dp[M], sum[M];

int main() {
   ms(dp, 0);
   // 利用滚动数组优化掉了第i个人这一维度
   dp[0] = 1;
   scanf("%d %d", &n, &k);
   rep(i, 1, n) scanf("%d", &a[i]);
   rep(i, 1, n) {
      ms(sum, 0);
      rep(j, 0, k) {
         int l = j+1, r = j + min(k - j, a[i]);
         if(l > r) break;
         // 差分前缀和优化
         sum[l] = (sum[l] + dp[j]) % mod;
         sum[r+1] -= dp[j];
         if(sum[r+1] < 0) sum[r+1] += mod;

      }
      rep(j, 1, k) {
         sum[j] = (sum[j] + sum[j-1]) % mod;
         dp[j] = (dp[j] + sum[j]) % mod;
      }
   }
   printf("%lld\n", dp[k]);
   return 0;
}

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

int main() {
  string s;
  cin>>s;

  vector<string> days = {
    "SUN",
    "MON",
    "TUE",
    "WED",
    "THU",
    "FRI",
    "SAT"
  };

  for (int i=0; i<days.size(); i++) {
    if (days[i] == s) {
      cout << 7-i;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a[100000],i=0,dp[100000]={0};
    cin>>n;
    while(i<n)
    {
        cin>>a[i++];
    }
    i=2;
    dp[1]=abs(a[0]-a[1]);
    while(i<n)
    {
        dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
        i++;
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    map<int,int> mp;
    for(int i=0;i<n;++i){
        int a; cin >> a;
        mp[a]++;
    }
    if(mp.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define mem(a, b) memset(a, b, sizeof(a))
#define MOD 1000000007
#define MAX (int) 1e9
#define PI 3.141592653589793238462643383279502884

template <typename T, typename U>
T max(T x, U y) {
    return x > y ? x : y;
}

template <typename T, typename U>
T min(T x, U y) {
    return x < y ? x : y;
}

template<typename T>
void debug(string msg, T t) {
	cout << msg << ": " << t << "\n";
}

int toDigit(char c) { return c - '0'; }

int k, n;

int main() {

	cin >> k;

	if(k % 7 == 0) {
		k /= 7;
	}
	
	if(k % 2 == 0 || k % 5 == 0) {
		cout << -1 << "\n";
	} else {
		n = 1;
		for(int i = 1 % k; ; i = (i * 10 + 1) % k) {
			if(i == 0) {
				cout << n << "\n"; 
				break;
			}
			n++;
		}
	}

	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int a[3][3];
    rep(i,3){
        rep(j,3)cin >> a[i][j];
    }
    int n,b;
    cin >> n;
    rep(k,n){
        cin >> b;
        rep(i,3){
            rep(j,3){
                if(a[i][j]==b)a[i][j]=0;   
            }
        }
    }
    int ans=0;
    rep(i,3)if(a[i][0]==0 and a[i][1]==0 and a[i][2]==0)ans++;
    rep(j,3)if(a[0][j]==0 and a[1][j]==0 and a[2][j]==0)ans++;
    if(a[0][2]==0 and a[1][1]==0 and a[2][0]==0)ans++;
    if(a[0][0]==0 and a[1][1]==0 and a[2][2]==0)ans++;
    
    if(ans>0)cout << "Yes";
    else cout << "No"; 
    
        
}

Measured memory_bytes: 3572
//  cd Desktop/Atcoder
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,n) for(i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

int main(){
    int n,i,count=0;
    char s[100002]={};
    scanf("%d",&n);
    scanf("%s",s);
    s[n]='A';
    rep(i,n){
        if(s[i]!=s[i+1])count++;
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
ll n, m, add, ans, A[101010];
char s[1010];
int main() {
	cin >> n;
	for (int i = n; i > 0; i--) {
		if (sqrt(i) == ceil(sqrt(i))) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())

for _ in range(n):
    y, m, d = map(int, input().split())
    ans = (1000 - y) * 195 + (1002 - y) // 3 * 5
    if y % 3 == 0:
        tyear = (m - 1) * 20 + d - 1
    else:
        tyear = (m - 1) * 20 + d - 1 - ((m - 1) // 2)
    print(ans - tyear)

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

int main()
{
	int i, j, k, l, m, n, sum, flag,A,B,C,D;
	sum = 0;
	flag = 0;
	cin >> A;
	if (A <= 999) {
		cout << "ABC" << endl;

	}
	else
		cout << "ABD" << endl;
    return 0;
}



Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s: String = read(&mut stdin_lock, &mut buf, b'\n');
    let mut cv: Vec<char> = s.chars().collect();
    cv.sort();
    let ans = cv[0] == cv[1] && cv[1] != cv[2] && cv[2] == cv[3];
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 2e5 + 17;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
 
 
int h, w, a, b, c[N];
multiset < int > Q;
set < int > q;


int get (int pos) {
	auto it = q.upper_bound(pos);
	--it;

	return *it;
}

main () {
	cin >> h >> w;
	c[0] = inf;

	for (int i = 1; i <= w; ++i) {
		q.insert(i);               
		Q.insert(0);
	}

	for (int i = 1; i <= h; ++i) {
		cin >> a >> b;
		int j = 0;
		if (a > 1)
			j = get(a - 1);
			
		j = c[j] - j + a;
		while (1) {
			auto it = q.lower_bound(a);
			if (it == q.end() || *it > b) 
				break;

			auto it1 = it;
			++it1;
			if (b < w && (it1 == q.end() || *it1 > b) && !q.count(b + 1)) {
				c[b + 1] = c[*it] + b + 1 - *it;
				q.insert(b + 1);
				Q.insert(c[b + 1]);
			}

			Q.erase(Q.find(c[*it]));
			q.erase(it);
		}

		q.insert(a);
		c[a] = j;
		Q.insert(c[a]);
		int ans = *Q.begin() + i;
		if (ans >= inf)
			ans = -1;
		cout << ans << endl;
	}
}

Measured memory_bytes: 23924
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;

int main() {
	
	ll x, y;
	cin >> x >> y;

	if (abs(x) == abs(y)) {
		cout << 1 << endl;
		return 0;
	}

	if (x < y) {
		if (x < 0 && y>0) {
			cout << abs(abs(x) - abs(y)) + 1 << endl;
		}
		else {
			cout << abs(abs(x) - abs(y)) << endl;
		}

		return 0;
	}

	if (x > y) {

		if (x > 0 && y < 0) {
			cout << abs(abs(x) - abs(y)) + 1 << endl;
			return 0;
		}

		if (y == 0 || x==0) {
			cout << abs(abs(x) - abs(y)) + 1 << endl;
		}
		else {
			cout << abs(abs(x) - abs(y)) + 2 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
priority_queue<int>q;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        q.push(x);
    }
    while(m--)
    {
        int now=q.top();q.pop();
        q.push(now/2);
    }
    long long ans=0;
    while(!q.empty()) ans+=q.top(),q.pop();
    printf("%lld\n",ans);
}


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

int main() {
  int x;
  cin >> x;
  int i, j;
  for (int a = -120; a <= 120; a++) {
    int flag = 0;
    for (int b = -120; b <= 120; b++) {
      long long tmp;
      tmp = pow(a, 5) - pow(b, 5);
      if (1 <= tmp <= 1e9 && tmp == x) {
        i = a;
        j = b;
        flag = 1;
        break;
      }
    }
    if (flag) break;
  }
  cout << i << " " << j;
  return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define lld long double
int main() {
	// your code goes here
 int n,m;
 cin>>n>>m;
 map<int,vector<int> > mp;
 int a,b;
 for(int i=0;i<m;i++){
 	cin>>a>>b;
 	mp[a].push_back(b);
 	mp[b].push_back(a);
 }
 bool vis[n+1];
 memset(vis,false,sizeof(vis));
 queue<int> q;
 vector<int> ans(n+1);
 for(int i=0;i<mp[1].size();i++){
 	 vis[mp[1][i]]=true;
 	 q.push(mp[1][i]);
 	 ans[mp[1][i]]=1;
 }
 vis[1]=true;
 while(!q.empty()){
 	int cur=q.front();
 	q.pop();
 	for(int i=0;i<mp[cur].size();i++){
 		if(!vis[mp[cur][i]]){
 			vis[mp[cur][i]]=true;
 			q.push(mp[cur][i]);
 			ans[mp[cur][i]]=cur;
		 }
	 }
 }
 int f=0;
 for(int i=1;i<=n;i++){
 	if(vis[i]==false){
 		f=1;
 		cout<<"No";
	 }
 }
 if(f==0){
 	cout<<"Yes\n";
 	for(int i=2;i<=n;i++){
 		cout<<ans[i]<<"\n";
	 }
 }
}


Measured memory_bytes: 15828
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(c,b/a);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int i=0,o=0,z=0;
  cin>>s;
  while(s[i]!='\0'){
    if(s[i]=='1'){
      o++;
    }else{
      z++;
    }
    i++;
  }
  cout<<min(o,z)*2<<'\n';
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define f(i, n) for (int i = 0; i < n; ++i)

using namespace std;
void solve() {
    int n;
    cin >> n;
    unordered_set<string> a;
    int ans = 0;
    f(i, n) {
        string s;
        cin >> s;
        if (a.count(s)) continue;
        ++ans;
        a.insert(s);
    }
    cout << ans << nl;
}

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

Measured memory_bytes: 17700
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;


signed main(){
  int a, b, c;
  scanf("%lld%lld%lld", &a, &b, &c);
  printf("%lld\n", (a*b)/2);
  return 0;
}






Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int[] m = new int[n];
		int count = 0;
		if (a < b)
			while(true) {
				if (b - a > 1)
					a++;
				else if (a != 1)
					a--;
				else {
					System.out.println("Borys");
					return;
				}
				if (b - a > 1)
					b--;
				else if (b != n)
					b++;
				else {
					System.out.println("Alice");
					return;
				}
				count++;
				if (count > 200) {
					System.out.println("Draw");
					return;
				}
			}
		else
			while(true) {
				if (a - b > 1)
					a--;
				else if (a != n)
					a++;
				else {
					System.out.println("Borys");
					return;
				}
				if (a - b > 1)
					b++;
				else if (b != 1)
					b--;
				else {
					System.out.println("Alice");
					return;
				}
				count++;
				if (count > 200) {
					System.out.println("Draw");
					return;
				}
			}
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	map<char, int> M;
	for(int i=0; i<s.length(); i++){
		M[s[i]]++;
	}
	bool flag = true;
	for(auto i : M){
		if(i.second>1){
			flag = false;
			break;
		}
	}
	if(flag){
		cout << "yes\n";
	}
	else{
		cout << "no\n";
	}
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool easy_to_dance = true;
  for (int i = 0; i < s.length(); ++i) {
    if (i % 2 == 0 and s[i] == 'L') easy_to_dance = false;
    if (i % 2 == 1 and s[i] == 'R') easy_to_dance = false;
  }
  cout << (easy_to_dance? "Yes" : "No") << endl;
}

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

#define X_MAX 600

int main()
{
	int d;
	long s;
	int i;
	while(cin >> d)
	{
		s = 0;
		for(i=d; i<X_MAX; i+=d)
		{
			s += d * i * i;	/* d:width i*i:height */
		}
		cout << s << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3060
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
rem = 0
tot=0
for i in range(N):
    tot=tot+min(A[N-i],B[N-i-1])
    rem = max(B[N - i - 1] - A[N - i], 0)
    tot = tot+min(rem, A[N-i-1])
    A[N - i - 1] = max(A[N - i - 1] - rem, 0)
print(tot)


Measured memory_bytes: 18624
n,d=map(int,input().split())
point=[]
for _ in range(n):
    point.append(list(map(int,input().split())))
ans=0
for i in range(n-1):
    for l in range(i,n):
        if i==l:
            continue
        dis=0
        for f in range(d):
            dis+=(point[i][f]-point[l][f])**2
        dis=dis**(0.5)
        #print(dis)
        if dis.is_integer():
            ans+=1
print(ans)

Measured memory_bytes: 9372
H = int(input())
W = int(input())
N = int(input())

if H > W:
    if N % H == 0:
        print(N // H)
    else:
        print(N // H + 1)
else:
    if N % W == 0:
        print(N // W)
    else:
        print(N // W + 1)

Measured memory_bytes: 38256
/*
  AOJ #0328
  title:Metal Recycling
  @kankichi573
 */
#include <stdio.h>
#include <string.h>

int a,b,n,bok[200017];

main()
{
  int i;
  scanf("%d",&n);
  memset(bok,0,sizeof(bok));
  for(i=0;i<n;i++)
    {
      scanf("%d %d",&a,&b);
      bok[a+b]++;
    }
  for(i=0;i<200017;i++)
    {
      bok[i+1] += bok[i]/2;
      bok[i]   &= 1;
    }
  for(i=0;i<200017;i++)
    if(bok[i])
      printf("%d 0\n",i);
  
  return(0);
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
const int mod=1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
//mint
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint& operator/=(const mint& a){ (x*=a.pow(mod-2).x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  mint operator/(const mint& a)const{ return mint(*this) /= a;}
  mint pow(ll t) const {
    if(!t) return 1;
    mint res = pow(t/2);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
struct comb {
  vm f, g;
  comb(){}
  comb(int mx):f(mx+1),g(mx+1) {
    f[0] = 1;
    rep(i,1,mx) f[i] = f[i-1]*i;
    g[mx] = f[mx].pow(mod-2);
    for(int i=mx;i>0;i--) g[i-1] = g[i]*i;
  }
  mint c(int a, int b) {
    if (a < b) return 0;
    return f[a]*g[b]*g[a-b];
  }
} c(3e6);
//c.c(a,b)=>aCb

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,0,n-1)cin >> a[i];
    vector<int> col(3,-1);
    mint ans = 1;
    rep(i,0,n-1){
        int cnt = 0;
        rep(j,0,2){
            if(col[j]==(a[i]-1))cnt++;
        }
        rep(j,0,2){
            if(col[j]==(a[i]-1)){
                col[j]=a[i];
            break;
            }
        }
        ans = ans * cnt;
    }


    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 47488
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
 ll mod=1e9+7;
const ll inf=1e15+10;
const ll N=3e6;

struct matrix
{
	vector<vector<ll> > mat;
	void resize(ll a,ll b, ll initial)
	{
		mat.resize(a,vector<ll> (b,initial));
	}
	void identity()// first resize with initial = 0
	{
		for(ll i=0;i<(ll)mat.size();i++) mat[i][i]=1;
	}
	ll get_rows()
	{
		return mat.size();
	}	
	ll get_cols()
	{
		return mat[0].size();
	}
	matrix operator + ( matrix & b)  const
	{
		matrix temp;
		ll ro,co;
		ro=b.get_rows();
		co=b.get_cols();
		temp.resize(ro,co,0);
		for(ll i=0;i<ro;i++)  
		{
			for(ll j=0;j<co;j++)
			{
				temp.mat[i][j]=mat[i][j]+b.mat[i][j];
				temp.mat[i][j]%=mod;
			}
		}	
		return temp;
	}
	matrix operator * ( matrix & b)  const
	{
		matrix temp;
		ll ro,co;
		ro=mat.size();
		co=b.get_cols();
		ll mi=b.get_rows();
		temp.resize(ro,co,0);
		for(ll i=0;i<ro;i++)  
		{
			for(ll j=0;j<co;j++)
			{
				for(ll k=0;k<mi;k++)
				{
					//temp.mat[i][j]+=mat[i][k]*b.mat[k][j];
					temp.mat[i][j]+=((mat[i][k]%mod) * (b.mat[k][j]%mod));
					temp.mat[i][j]%=mod;
				}
			}
		}	
		return temp;
	}	
	void print()
	{
		for(auto &i:mat)
		{
			for(auto &j:i) cout<<j<<" ";
			cout<<endl;	
		}	

	}


};

matrix power(matrix a,ll b)
{
	matrix ans;
	ans.resize(a.get_rows(),a.get_cols(),0);
	ans.identity();
	while(b)
	{
		if(b & (ll)1)
		{
			ans=ans*a;
		}
		a=a*a;
		b>>=1;
	}
	return ans;
}
int main()
{
	boost;
	ll l,a,b,m;
	cin>>l>>a>>b>>m;
	mod=m;
	ll lo,hi;
	matrix ans;
	ans.resize(1,3,0);
	ans.mat[0][0]=a%mod;
	ans.mat[0][1]=(a+b)%mod;
	ans.mat[0][2]=1;
	ll term =1,d=10;
	while(term<l)
	{
		lo=max((ll)0,((d/10-1)-a)/b);
		hi=min(l-1,max((d-1-a)/b,(ll)0));
		term+=hi-lo;
		ll now=hi-lo;
		matrix temp;
		temp.resize(3,3,0);
		temp.mat[0][0]=d%mod;
		temp.mat[1][0]=1;
		temp.mat[1][1]=1;
		temp.mat[2][1]=b%mod;
		temp.mat[2][2]=1;
		temp=power(temp,now);
		ans=ans*temp;
		d*=10;
		//check(term);check(hi);check(lo);
	}
	cout<<ans.mat[0][0];
  	return 0;
}  

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

using namespace std;

const int MAXN = 3000;
int dp[MAXN + 1][MAXN + 1];
pair<int, int> from[MAXN + 1][MAXN + 1];

int main()
{
    string s, t;
    cin >> s >> t;
    int n = (int) s.length();
    int m = (int) t.length();
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            from[i][j] = make_pair(0, 0);
            if (s[i - 1] == t[j - 1])
            {
                dp[i][j] = 1 + dp[i - 1][j - 1];
                from[i][j] = make_pair(i - 1, j - 1);
            }
            else
            {
                int a = i;
                int b = j - 1;
                if (dp[i - 1][j] > dp[i][j - 1])
                {
                    a = i - 1;
                    b = j;
                }
                dp[i][j] = dp[a][b];
                from[i][j] = make_pair(a, b);
            }
        }
    }
    string ans = "";
    pair<int, int> pr = make_pair(n, m);
    while (pr.first != 0 && pr.second != 0)
    {
        int a = pr.first;
        int b = pr.second;
        if (s[a - 1] == t[b - 1])
        {
            ans = s[a - 1] + ans;
        }
        pr = from[a][b];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 105856
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int i;
	int cnt = 0, a = 0;
	for (i = 0; i < n; i++)
	{
		if (s.at(i) == 'C')
		{
			if (a == 2)
			{
				cnt++;
				a = 0;
			}
			else
				a = 0;
		}
		else if (s.at(i) == 'B')
		{
			if (a == 1)
				a++;
			else
				a = 0;
		}
		else if (s.at(i) == 'A')
			a = 1;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3572
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(200000000)


# my functions here!

#入力

def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    N=input()
    n=len(N)//2
    ans=0
    
    for i in range(n):
        if N[0:i]*2==N[0:i*2]:
            ans=max(ans,i*2)
    print(ans)
        
     
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """abaababaab"""
        output = """6"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """xxxx"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """abcabcabcabc"""
        output = """6"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """akasakaakasakasakaakas"""
        output = """14"""
        self.assertIO(input, output)
if __name__=="__main__":resolve()

Measured memory_bytes: 5660
import java.util.*;
public class Main{
 public static void main(String args[])
   { Scanner sc=new Scanner(System.in);
     int n=sc.nextInt();
     int m=sc.nextInt();
      int a=n*(n-1)/2;
      int b=m*(m-1)/2;
    	System.out.println(a+b);
   }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define INF 1e9
#define IIN -1e9
using namespace std;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int x[200];
int y[200];
int main(){
    int N;
    while(cin>>N,N){
        int n,d;
        for(int i=1;i<N;i++){
            cin>>n>>d;
            x[i]=x[n];
            y[i]=y[n];
            x[i]+=dx[d];
            y[i]+=dy[d];
        }
        int xx=IIN,xn=INF,yx=IIN,yn=INF;
        for(int i=0;i<N;i++){
            xx=max(xx,x[i]);
            xn=min(xn,x[i]);
            yx=max(yx,y[i]);
            yn=min(yn,y[i]);
        }
        cout<<xx-xn+1<<" "<<yx-yn+1<<endl;
    }
    return 0;
}



Measured memory_bytes: 2984
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    		Scanner scan=new Scanner(System.in);
    		int n=Integer.parseInt(scan.next());
    		int k=Integer.parseInt(scan.next());
    		int x=Integer.parseInt(scan.next());
    		int y=Integer.parseInt(scan.next());
    		
    		if (n<k) {
    			System.out.print(x*n);
    		}else {
    			System.out.print(k*x+y*(n-k));
    		}
    }
     
    }

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m,l; cin>>n>>m>>l;
	vector<vector<int>>a(n,vector<int>(m)),b(m,vector<int>(l));
	for(auto&&i:a)for(auto&&j:i)cin>>j; for(auto&&i:b)for(auto&&j:i)cin>>j;
	for(int i=0;i<n;++i){
		for(int j=0;j<l;++j){
			int64_t sum=0;
			for(int k=0;k<m;++k){
				sum+=a.at(i).at(k)*b.at(k).at(j);
			}
			cout<<sum;
			if(j!=l-1)cout<<" "s;
		}
		cout<<"\n"s;
	}
}


Measured memory_bytes: 3312
long long n, k, i, a[200000], f[200000], top, bottom, med;

int cmp (const void *a, const void *b) {
    return *((long long*)a) - *((long long*)b);
}

int test (long long targetTime) {
    long long sum = 0, i, tmp;
    for (i = 0; i < n; i++) {
        tmp = a[i] - targetTime / f[n - i - 1];
        if (tmp > 0) sum += tmp;
    }
    return sum > k;
}

int main (void) {
    scanf("%lld %lld", &n, &k);
    for (i = 0; i < n; i++) scanf("%lld", &a[i]);
    for (i = 0; i < n; i++) scanf("%lld", &f[i]);

    qsort(a, n, sizeof(long long), cmp);
    qsort(f, n, sizeof(long long), cmp);

    /* binary search */
    for (i = 0; i < n; i++) if (a[i] * f[n - i - 1] > top) top = a[i] * f[n - i - 1];
    bottom = -1;

    while (top - bottom > 1) {
        med = (top + bottom) / 2;
        if (test(med)) {
            bottom = med;
        } else {
            top = med;
        }
    }

    printf("%lld\n", top);
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, k;
    cin >> n >> k;
    vector<bool> v(n, false);

    REP(i, k){
        int d;
        cin >> d;
        REP(j, d){
            int a;
            cin >> a;
            v[a-1] = true;
        }
    }

    int ans = 0;
    REP(i, n){
        ans += !v[i];
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long int ll;

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

int main() {
	int N;
	cin >> N;
	vector<string> s(N);
	rep(i, N) {
		cin >> s[i];
		sort(all(s[i]));
	}
	sort(all(s));
	vector<ll> cnts(0);
	ll cnt = 0;
	rep1(i, N) {
		if (s[i] == s[i - 1]) {
			cnt++;
			if (i == N - 1) {
				cnts.push_back(++cnt);
			}
		}
		else {
			cnts.push_back(++cnt);
			cnt = 0;
		}
	}
	ll ans = 0;
	rep(i, cnts.size()) {
		ans += cnts[i] * (cnts[i] - 1LL) / 2LL;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8444
from itertools import product


def solve(string):
    l = len(string)
    *s, = map(int, string)
    n = int(string)
    t = [[0] * 10 for _ in range(10)]
    for i in range(n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    return str(sum(t[i][j] * t[j][i] for i, j in product(range(1, 10), repeat=2)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int r;
    cin >> r;
    cout << r*r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pa; 
#define mp make_pair;


int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  cin>>N;
  mat a(N,vec(N));
  rep(i,N) rep(j,N) cin>>a.at(i).at(j);
  class union_find{
        vector<long> parent, tree_size;
    public:
        union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){
            for(unsigned long i = 0; i < _n; ++i)parent[i] = i;
        }
        ll find(ll x){
            while(parent[x] != x)x = parent[x] = parent[parent[x]];
            return x;
        }
        void merge(ll a, ll b){
            a = find(a);
            b = find(b);
            if(tree_size[a] < tree_size[b])swap(a, b);
            tree_size[a] += tree_size[b];
            parent[b] = a;
            return;
        }
	bool same(ll a, ll b){
	    a = find(a);
	    b = find(b);
	    return a == b;
	}
  };
  union_find uf(N);
  vector<pair<ll,ll> > edge(0);
  rep(i,N){
    reps(j,i+1,N){
      if(a[i][j] != -1){
	edge.push_back(pa(a[i][j],i*N+j));
      }
    }
  }
  sort(edge.begin(),edge.end());
  ll anse=0,ans=0;
  rep(i,edge.size()){
    pa e = edge[i];
    if(uf.same(e.se/N,e.se%N)) continue;
    ans += e.fi;
    uf.merge(e.se/N,e.se%N);
    ++anse;
    if(anse == N-1) break;
  }
  if(anse<N-1) cout<<"impossible"<<endl;
  cout<<ans<<endl;
  //uf.mergeのように使う
  //ufはMAX_N+1でとるか、代入時に0-indexedにする
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Blue ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,n) for(int i=a;i<n;++i)
typedef vector<int> vi;
typedef long long ll;
const int mod=1e9+7;
 
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
const int N=2e5;
int n,m;
vi g[N];
int used[N],dist[N];

void bfs(int s){
	queue<int>q;
	q.push(s);
	used[s]=1;
	dist[s]=0;
	while(!q.empty()){
		int v=q.front();
		q.pop();
		for(auto to:g[v]){
			if(!used[to]){
				used[to]=1;
				dist[to]=v;
				q.push(to);
			}
		}
	}
}


void solve(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		--u,--v;
		g[u].pb(v);
		g[v].pb(u);
	}
	bfs(0);
	for(int i=1;i<n;i++){
		if(!used[i]){
			cout<<"No";
			return;
		}
	}
	cout<<"Yes\n";
	for(int i=1;i<n;i++){
		cout<<dist[i]+1<<'\n';
	}
}
 
 
int main(){
	Blue;
	int test=1;
	//cin>>test;
	while(test--)
		solve();
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int st, en;
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == 'A') {
      st = i + 1;
      break;
    }
  }
  for(int i = S.size() - 1; i > 0; --i) {
    if(S[i] == 'Z') {
      en = i + 1;
      break;
    }
  }
  cout << en - st + 1 << endl;
}

Measured memory_bytes: 640