akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let (M, D): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = {
        let mut x = 0;
        for m in 1..(M + 1) {
            for d in 10..(D + 1) {
                let d_1 = d % 10;
                let d_10 = d / 10;
                if d_1 >= 2 && d_10 >= 2 && d_1 * d_10 == m {
                    x += 1;
                }
            }
        }
        x
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const long long INF = 10000;
using namespace std;

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

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

int V, E;
vector<vector<int>> dist(16, vector<int>(16, INF));
// dp[i][j] := 今まで{i}を通って現在jにいる時の最短経路長
int dp[(1 << 15) + 1][16];

int main()
{
  cin >> V >> E;

  rep(i, E)
  {
    int s, t, d;
    cin >> s >> t >> d;
    dist[s][t] = d;
  }

  for (int bit = 0; bit < (1 << V); ++bit)
    for (int v = 0; v < V; ++v)
      dp[bit][v] = 10000;

  dp[0][0] = 0;

  rep(bit, 1 << V) rep(j, V)
  {
    rep(k, V)
    {
      if (bit >> k & 1)
        continue; // kを使用済み
      int next_bit = (bit | 1 << k);

      dp[next_bit][k] = min(dp[next_bit][k], dp[bit][j] + dist[j][k]);
    }
  }

  cout << (dp[(1 << V) - 1][0] == 10000 ? -1 : dp[(1 << V) - 1][0]) << endl;

  return 0;
}


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

int max (int a,int b,int c) {
    int max = a;
    if(max < b) max = b;
    if(max < c) max = c;
    return max;
}

int main(void){
    int p,q,r;
    cin >> p >> q >> r;
    int answer = p + q + r;
    answer -= max(p,q,r);
    cout << answer;
}


Measured memory_bytes: 256
/* ex7_3
   reo012 */

#include<stdio.h>
#include<stdlib.h>

int main(void){
    int i, j, row, column;
    char **ptr;
    int *check_row, *check_col;
    //行数と列数の入力
    scanf("%d %d\n", &row, &column);

    //ptrについて、各行の配列へのポインタ分(row行分)のメモリ確保
    ptr = (char**)calloc(row, sizeof(char*));
    if(ptr == NULL){
        exit(1);
    }
    //ptrについて、各行の要素分（column列分）のメモリ確保
    for(i=0; i<row; i++){
        ptr[i] = (char*)calloc(column, sizeof(char));
        if(ptr[i] == NULL){
            exit(1);
        }
    }

    //check_rowについて、行数分のメモリ確保
    check_row = (int*)calloc(row, sizeof(int));
    if(check_row == NULL){
        exit(1);
    }
    //check_colについて、列数分のメモリ確保
    check_col = (int*)calloc(column, sizeof(int));
    if(check_col == NULL){
        exit(1);
    }

    //グリッドを入力
    for(i=0; i<row; i++){
        for(j=0; j<column; j++){
            scanf(" %c", &ptr[i][j]);
            if(ptr[i][j]=='#'){     //黒マスのときはcheck_row,check_colに1入力
                check_row[i] = 1;
                check_col[j] = 1;
            }
        }
    }

    //i行目、j列目がともに黒マスを含む場合のみ、出力
    for(i=0; i<row; i++){
        if(check_row[i]==1){
            for(j=0; j<column; j++){
                if(check_col[j]==1){
                    printf("%c", ptr[i][j]);
                }
            }
            printf("\n");   //行ごとに改行
        }
    }

    //メモリの解放を、各行の要素分の領域、各行の配列へのポインタ分の順に解放
    for(i=0; i<row; i++){
        free(ptr[i]);
    }
    free(ptr);
    free(check_row);
    free(check_col);

    return 0;
}

Measured memory_bytes: 1632
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, a, b;

int main() {
	cin >> n >> a >> b;
	if (a + b > n + 1) {
		cout << -1 << endl;
		return 0;
	}
	if (a*b < n) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = a - 1; i >= 0; i--) {
		cout << n - i << " ";
	}

	n -= a;
	LL num = b;
	--b;
	for (int i = 1; i < num; i++) {
		LL cur = n - b + 1;
		cur = min(cur, a);

		for (int j = cur - 1; j >= 0; j--) {
			cout << n - j << " ";
		}

		n -= cur;
		--b;
	}
	cout << endl;
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
//#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int power(int x, unsigned int y)
{
    int res = 1;

    x = x;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);

        y = y>>1;
        x = (x*x);
    }
    return res;
}
bool isprime(int x)
{
      if(x<2)
        return false;
    for(int i=2;i*i<=x;i++)
     {
        if (x%i==0)
            return false;
    }
    return true;
}
vector<int>primeFactors(int n)
{
    vector<int>v;
    int x=0;
    while (n % 2 == 0)
    {
        x++;
        n = n/2;
        v.pb(2);
    }
    //if(x>0)
    //v.pb({2,x});
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        int y=0;
        while (n % i == 0)
        {
            y++;
            n = n/i;
            v.pb(i);
        }
        //if(y>0)
        //v.pb({i,y});
    }
    if (n > 2)
        v.pb(n);
    return v;
}

void solve()
{
int l,r,d;
cin>>l>>r>>d;
int ans=0;
for(int i=l;i<=r;i++)
{
    if(i%d==0)
        ans++;
}
cout<<ans<<endl;

}

signed main()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
//cin>>t;
t=1;
while(t--)
{
solve();
}
}



Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define ld long double
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005;
int tong[N<<1],a[N],n,k;
ll check(int x){
	memset(tong,0,sizeof(tong));
	int dq=n,dd=1; ll ans=0;
	tong[n]=1; 
	for(int i=1;i<=n;i++){
		a[i]>=x?dd+=tong[++dq]:dd-=tong[dq--]; 
		ans+=dd++; tong[dq]++; 
	}
	return ans;
}
signed main(){
	n=read(); ll k=((ll)n*(n+1)/2+1)/2;
	for(int i=1;i<=n;i++)a[i]=read(); //cout<<check(30)<<endl; return 0;
	int l=1,r=1e9;
	while(l<r){
		int mid=(l+r)>>1; mid++;
		if(check(mid)>=k)l=mid; else r=mid-1;
	}
	cout<<l<<endl;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int N, S;

int main(){
  while( cin >> N && N > 0){ //N??????????????????????????????????????§while????????????
    int sum = 0; 
    int min = 1001; //min????°?????????¨?????????
    int max = -1;
    int average = -1;

    for (int i = 0; i < N; i++){
      cin >> S;
      sum += S;
      if( S > max ) max = S;
      if(S < min) min = S; 
    }

    average = (sum - min - max) / (N - 2); //???N-2?????§???????????¨?????¨??????????????????????????¨????????????????????????

    cout << average << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())

ll dp[100002];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N ;
  cin >> N;
  rep(i,N){
    ll inp;
    cin >> inp;
    if(dp > 0)dp[inp-1]++;
    dp[inp]++;
    dp[inp+1]++;
  }

  ll ans = 0;
  rep(i,100002){
    if(dp[i]>ans) ans = dp[i];
  }

  cout << ans << endl;

  
  return 0;
}


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

int main() {
  string s1, s2, s3;
  int a1, a2, b;
  cin >> s1 >> s2;
  cin >> a1 >> a2;
  cin >> s3;
  if(s1 == s3){
    cout << a1 - 1 << " " << a2 << endl;
  } else {
    cout << a1 << " " << a2 - 1 << endl;
  }
}

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

using namespace std;
typedef long long ll;
    
int main()
{
    ll X;
    cin >> X;

    ll year = 0;
    ll yokin = 100;
    while (yokin < X) {
        yokin *= 1.01;
        year++;
    }
    cout << year;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

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

	vector<int> div(n + 1);
	rep(i, 2, n + 1) {
		int m = i, j = 2;
		while (j * j <= m) {
			while (m % j == 0) {
				m /= j;
				div[j]++;
			}
			++j;
		}
		if (m != 1) div[m]++;
	}
	
	ll ans = 1;
	rep(i, 2, n + 1) {
		ans = ans * -~div[i] % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M,X;
    cin >> N >> M >> X;
    int C[N];
    int A[N][M];
    for(int i=0; i<N; i++){
        cin >> C[i];
        for(int j=0; j<M; j++){
            cin >> A[i][j];
        }
    }
    int imax=1;
    for(int i=0; i<N; i++){
        imax*=2;
    }
    int minc=2e9;
    int D[M];
    int c;
    int flag;
    int a=0;
    for(int i=0; i<imax; i++){
        c=0;
        for(int j=0; j<M; j++){
            D[j]=0;
        }
        for(int j=0; j<N; j++){
            if(i>>j & 1){
                for(int k=0; k<M; k++){
                    D[k]+=A[j][k];
                }
                c+=C[j];
            }
            
        }
        flag=1;
        for(int j=0; j<M; j++){
            if(D[j]<X){
                flag=0;
                break;
            }
        }
        if(flag){
            minc=min(minc,c);
            if(minc==c) a=i;
        }
    }
    if(minc==2e9) minc=-1;
    cout << minc;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    int d[1000006][2] = {};
    cin >> s;
    reverse(s.begin(), s.end());
    if (s[0] != '0') d[0][0] = s[0] - '0', d[0][1] = 10 - s[0] + '0';
    else d[0][0] = 0, d[0][1] = 10;
    for (int i = 1; i < s.length(); i++) {
        if (s[i] == '9') {
            d[i][0] = d[i - 1][0] + 9;
            d[i][1] = min(d[i - 1][0] + 1, d[i - 1][1]);
        } else {
            d[i][0] = min(d[i - 1][0] + s[i] - '0', d[i - 1][1] + s[i] - '0' + 1);
            d[i][1] = min(d[i - 1][0] + 10 - s[i] + '0', d[i - 1][1] + 10 - s[i] + '0' - 1);
        }
        //cout << d[i][0] << ' ' << d[i][1] << '\n';
    }
    cout << min(d[s.length() - 1][0], d[s.length() - 1][1] + 1);
}


Measured memory_bytes: 12160
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
#include <cstdarg>
#include <sstream>
#include <functional>
using namespace std;

int const MAX_N = 512 * 1024;

int dg[10];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	long long k, a, b;
	cin >> k >> a >> b;

	long long mx = 1 + k;
	if (b > a) {
		long long x = a;
		long long rem_k = k - (x-1);
		if (rem_k >= 0) {
			x += (rem_k / 2)*(b - a);
			x += rem_k % 2;
			mx = max(mx, x);
		}
	}
	cout << mx;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
import numpy as np
N = int(input())
T, A = [int(x) for x in stdin.readline().rstrip().split()]
H = list(map(int, input().split()))
d = []

for i in range(len(H)):
    d.append(abs(T-H[i]*0.006-A))
print(np.argmin(d)+1)

Measured memory_bytes: 12404
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define pi 3.14159265358979323846
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  int a,b; cin >> a >> b;
  if (b%a==0){cout << a+b << endl;}
  else {cout << b-a << endl;}

  return 0;
}


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

const int MX = 3000;

double memo[MX][MX];
bool seen[MX][MX];

int main() {
  int n;
  cout << fixed << setprecision(12);
  while ( cin >> n ) {
    vector<double> probs(n);
    memset(memo, 0, sizeof memo);

    for ( auto& i : probs ) cin >> i;
    for ( int i = n / 2 + 1; i <= n; ++i ) memo[n][i] = 1;
    for ( int i = n - 1; i >= 0; --i ) {
      for ( int j = 0; j <= i; ++j ) {
        memo[i][j] = probs[i] * memo[i + 1][j + 1] + (1 - probs[i]) * memo[i + 1][j];
      }
    }

    cout << memo[0][0] << endl;
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a, ans = 1000000;
	for(int i=0;i<n;i++){
		cin >> a;
		int l=0;
		while(a%2==0)a/=2,l++;
		ans = min(ans,l);
	} 
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int a,b,c;
  
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  
  if((a==b && b!=c)||(a==c && b!=c)||(b==c && a!=c))
    printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);

  for (int i = 0; i < n; i++) {
    int x, l;
    cin >> x >> l;
    p[i].first = x + l;
    p[i].second = x - l;
  }

  sort(begin(p), end(p));

  int cur = -2000000001;
  int ans = 0;

  for (int i = 0; i < n; i++) {
    if (cur <= p[i].second) {
      ans++;
      cur = p[i].first;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

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

int main(){
    int N, K;
    cin >> N >> K;
    ll ans = 0;
    for(int b = K + 1; b <= N; b ++){
        int tmp = N / b * (b - K) + (K == 0 ? max(0, N % b - K) : max(0, N % b - K + 1));
        ans += 1L * tmp;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N = input()
a = input().split()
scores = [0,0,0,0,0,0,0,0]
score8 = 0
for i in a:
    check = int(int(i) / 400)
    if check > 7:
        score8 += 1
    else:
        scores[check] = 1
score1to7 = sum(scores)
saidai = score1to7 + score8
if score1to7 < 1:
    saisho = 1
else:
    saisho = score1to7
print(str(saisho) + " " + str(saidai))

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

int main()
{
    int D;
    cin >> D;
    
    if(D==25)
    {cout << "Christmas" << endl;
    }
    else if(D==24)
    {
        cout << "Christmas Eve" << endl;
    }
    else if(D==23)
    {
        cout << "Christmas Eve Eve" << endl;
    }
    else
    {
        cout << "Christmas Eve Eve Eve" << endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  int A[N];
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }

  bool kabu_flag = false;
  unsigned long long money = 1000;
  unsigned long long kabu = 0;
  int limit = N - 1;
  // for (int i = N - 2; i >= 0; --i) {
  //   if (A[i] < A[A[i + 1]]) {
  //     limit = i;
  //     break;
  //   }
  // }
  for (int i = 0; i < N; ++i) {
    if (i == limit) {
      money += kabu * A[i];
      kabu = 0;
      break;
    }
    if (kabu_flag) {
      if (A[i] > A[i + 1]) {
        money += kabu * A[i];
        kabu = 0;
        kabu_flag = false;
      }
    } else {
      if (A[i] < A[i + 1]) {
        kabu = money / A[i];
        money %= A[i];
        kabu_flag = true;
      }
    }
  }

  std::cout << money << std::endl;

  return 0;
}


Measured memory_bytes: 3628
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int n;

int a[100001];

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    
    int tot = 0;
    
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) tot += a[i]-1;
    
    cout << tot << '\n';

    return 0;
    
}




Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#define SIZE 244140625

int Hash(const char* c)
{
    int Hash = 0;
    while(1){
        Hash *= 5;
        switch(*c){
        case 'A':
            Hash += 1; break;
        case 'C':
            Hash += 2; break;
        case 'G':
            Hash += 3; break;
        case 'T':
            Hash += 4; break;
        default:
            return Hash;
        }
        ++c;
    }
}
int main()
{
    bool* dic = new bool[SIZE];
    int n;
    std::scanf("%d", &n);
    char command[7];
    char str[13];
    for(int i = 0; i < n; ++i){
        std::scanf("%s %s", command, str);
        if(command[0] == 'i'){
            dic[Hash(str)] = true;
        }else
        if(command[0] == 'f'){
            std::puts((dic[Hash(str)] ? "yes" : "no"));
        }
    }
    return 0;
 }

Measured memory_bytes: 50480
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j;
    vector<vector<int>> moji;
    cin>>a;
    for(i=0;i<a;i++){
        string s;
        cin>>s;
        int al[26];
        for(j=0;j<26;j++)
        al[j]=0;
        for(j=0;j<10;j++){
            c=s[j]-0x61;
            al[c]++;
        }
        vector<int> v;
        for(j=0;j<26;j++){
            v.push_back(al[j]);
        }
        moji.push_back(v);
    }
    sort(moji.begin(),moji.end());
    unsigned long long ans,f;
    f=0;
    ans=0;
    for(i=0;i<a-1;i++){
        if(moji[i]==moji[i+1])
        f++;
        else{
            ans = ans + f*(f+1)/2;
            f=0;
        }
    }
    ans=ans+f*(f+1)/2;
    
    cout<<ans<<endl;
}


Measured memory_bytes: 14128
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
mod = 10**9 + 7

#maincode-------------------------------------------------

n = ini()
a = inl()
A = 10**6+5
b = [0] * A
ans = "pairwise coprime"

for i in a: #数の個数を数える配列を作成
    b[i] += 1

for i in range(2,A): #倍数があったらpairwiseではない
    cnt = 0
    for j in range(i,A,i):
        cnt += b[j]
    if cnt >= 2:
        ans = "setwise coprime"
        break

if ans == "setwise coprime":
    g = a[0]
    for i in range(1,n):
        g = gcd(a[i],g)
    if g != 1:
        ans = "not coprime"

print(ans)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {\
return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;
using ll = int64_t;

const ll INF = 1000000000000001;

int getSum(ll N)
{
    int sm = 0;
    while (0 < N)
    {
        ll tmp = N % 10;
        sm += (int)tmp;
        N /= 10;
    }
    return sm;
}

ll getAll9(ll N)
{
    ll all9 = 0;
    int times = 0;

    // n
    ll minn = INF;

    // S / S(n)
    ll minssn = INF;

    ll tmpN = N;
    ll lastN;
    while (0 < tmpN)
    {
        times++;
        lastN = tmpN % 10;
        tmpN /= 10;
    }

    ll tmp = N;
    int t = 0;
    while (0 < tmp)
    {
        tmp /= 10;

        if (tmp == 0)
        {
            all9 = pow((ll)10, times - 1) * lastN + all9;
            if (all9 / (ll)getSum(all9) <= minssn)
            {
                minssn = all9 / (ll)getSum(all9);
                minn = all9;
            }
        }
        else
        {
            t++;
            all9 = all9 * 10 + 9;
            ll tmp9 = tmp * pow(10, t) + all9;
            if (tmp9 / (ll)getSum(tmp9) <= minssn)
            {
                minssn = tmp9 / (ll)getSum(tmp9);
                minn = tmp9;
            }
        }
    }
    return minn;
}

void f(int K)
{
    ll N = 1;
    REP(i, K)
    {
        ll sunuke = N / (ll)getSum(N);
        ll a9 = getAll9(N);
        ll minsunuke = a9 / (ll)getSum(a9);

        if (minsunuke < sunuke)
        {
            cout << a9 << endl;
            N = a9;
        }
        else cout << N << endl;

        N++;
    }
}

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

    f(K);

    return 0;
}


Measured memory_bytes: 256
#coding: utf-8

import bisect
import math

N, M = (int(v) for v in input().split())

seen = {}
WA = {}

acs = 0
was = 0

for i in range(M):
    q, tmp = input().split()
    if tmp == "AC":
        if q not in seen:
            acs += 1
            if q not in WA:
                WA[q] = 0
            was += WA[q]
            seen[q] = 1
    else:
        if q not in WA:
            WA[q] = 1
        else:
            WA[q] += 1

print (acs, was)



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

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

int main(){
	string s;
	cin >> s;
	bool flag = false;
	REP(i, s.size()-1) if(s[i] == 'A' && s[i+1] == 'C') flag = true;
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

const int INF = 1e9;
int n, ma, mb;

int chemA[40];
int chemB[40];
int chemC[40];

int dp[401][401];

int main() {
	cin >> n >> ma >> mb;
	for(int i = 0; i < n; i++) {
		cin >> chemA[i] >> chemB[i] >> chemC[i];
	}

	for(int i = 0; i < 401; i++) for(int j = 0; j < 401; j++) dp[i][j] = INF;

	dp[0][0] = 0;
	for(int k = 0; k < n; k++) {
		for(int i = 10*n; i >= 0; i--) {
			for(int j = 10*n; j >= 0; j--) {
				if(dp[i][j] == INF) continue;
				dp[i+chemA[k]][j+chemB[k]] = min(dp[i+chemA[k]][j+chemB[k]], dp[i][j] + chemC[k]);
			}
		}
	}

	int ans = INF;
	int fac = 1;
	while(fac*ma <= 10*n && fac*mb <= 10*n) {
		ans = min(ans, dp[fac*ma][fac*mb]);
		fac++;
	}
	cout << ((ans == INF)? -1:ans) << endl;

	return 0;
}

Measured memory_bytes: 896
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();
 
    if(n == 1){
      System.out.println("Hello World");
    }else{
     int a = sc.nextInt();
     int b = sc.nextInt();
    System.out.println(a+b);
    }

  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 22484
//E knapsack approach 1
#include<bits/stdc++.h>
#define int long long
#define inf 1e10+1
using namespace std;
class event{
public:
  int wt,val;  
};
int32_t main(){
    int n,w;
    cin>>n>>w;
    event arr[n+1];
    for(int i=1;i<=n;i++){
        cin>>arr[i].wt;
        cin>>arr[i].val;
    }
    int maxval=1000*n;
    int dp[n+1][maxval+1];
    //memset(dp,INT_MAX,sizeof dp);
    memset(dp,inf,sizeof dp);
    for(int val=0;val<=maxval;val++){
        //dp[1][val]=INT_MAX;
        dp[1][val]=inf;
    }
    dp[1][0]=0;
    dp[1][arr[1].val]=arr[1].wt;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=maxval;j++){
            dp[i][j]=dp[i-1][j];
            if(arr[i].val<=j){
                dp[i][j]=min(dp[i][j],arr[i].wt+dp[i-1][j-arr[i].val]);
            }
        }
    }
    int ans=0;
    for(int x=0;x<=maxval;x++){
        if(dp[n][x]<=w){
            ans=x;
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 79104
import java.util.Scanner;

public class Main {
	static long euclid(long x, long y) {
		if (y == 0) {
			return x;
		} else {
			return euclid(y, x%y);
		}
	}
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long k=sc.nextLong();
		long a[]=new long[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		long gcd=a[0];
		for (int i = 1; i < n; i++) {
			gcd=euclid(gcd,a[i]);
		}
		for(int i=0;i<n;i++) {
			if(a[i]>=k&&(a[i]-k)%gcd==0) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
		
	}
}


Measured memory_bytes: 60372
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
template<typename T>
T argument(const pair<T, T> &a, const pair<T, T> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

int const MAX = 2000000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

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

    COMinit();
    int n, k; std::cin >> n >> k;
    if (n < k) { std::cout << 0 << std::endl; return 0; }
    std::cout << COM(n-1, k-1) << std::endl;
    
    return 0;
}


Measured memory_bytes: 50056
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
//11-40 A
//41-70 B
//71-130 C
//131-200 pw2
#define less nfoafnloe
void less(int x,int y,int z){
	//a[x]=a[y]<a[z]
	printf("< %d %d %d\n",y,z,x);
}
void add(int x,int y,int z){
	//a[x]=a[y]+a[z]
	printf("+ %d %d %d\n",y,z,x);
}
void init(int l,int r){
	less(l,2,0);
	for(int i=l+1;i<=r;i++){
		add(i,i-1,i-1);
	}
}
int pw(int x){
	return 131+x;
}
int tot=301;
#define FOR for(int _=0;_<2;_++)
void add_mul(int x,int y,int z){
	//x+=y*z (0<=z<=1)
	int a=++tot,b=++tot,c=++tot,d=++tot,e=++tot;
	FOR{
		printf("+ %d %d %d\n",a,z,a);
	}
	FOR{
		printf("+ %d %d %d\n",a,c,b);
		printf("< %d %d %d\n",b,y,d);
		printf("+ %d %d %d\n",d,c,c);
	}
	//e+c=y
	FOR{
		printf("+ %d %d %d\n",c,e,a);
		printf("< %d %d %d\n",a,y,d);
		printf("+ %d %d %d\n",e,d,e);
	}
	printf("+ %d %d %d\n",x,e,x);
}
void binary(int x,int l,int r){
	const int tmp=201,use=202;
	less(tmp,2e5-1,x);add(x,x,tmp);
	for(int i=r;i>=l;i--){
		add(tmp,2e5-1,2e5-1);
		for(int j=i+1;j<=r;j++){
			add(tmp,tmp,j);
		}
		int pos=i-l;
		add(tmp,tmp,pw(i-l));
		less(use,tmp,x);
		add(i,i,use);
		for(int j=0;j<i-l;j++){
			add(i,i,i);
		}
	}
	for(int i=l;i<=r;i++)less(i,2e5-1,i);
}
const int reg=300;
int main(){
//	freopen("input.txt","w",stdout);
	puts("15724");
	init(131,190);
	binary(0,11,40);
	binary(1,41,70);
	for(int i=11;i<=40;i++){
		for(int j=41;j<=70;j++){
			int a=i-11,b=j-41;
			add_mul(a+b+71,i,j);
		}
	}
	int f1=299,f2=298,f3=297;
	for(int i=130;i>=71;i--){
		add(2,2,2);
		add(2,2,i);
	}
	return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, k; scanf("%d%d", &n, &k); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(begin(a), end(a));
	
	if(std::accumulate(begin(a), end(a), 0LL) < k) {
		printf("%d\n", n);
		return 0;
	}
	
	auto f = [&](int t) {
		if(a[t] >= k) return true;
		
		std::bitset<5001> dp; dp[0] = true; 
		for(int i = 0; i < n; i++) if(i != t) dp |= dp << a[i];
		for(int i = k - a[t]; i < k; i++) if(dp[i]) return true;
		return false;
	};
	
	int ok = n - 1, ng = -1;
	while(std::abs(ok - ng) > 1) {
		int mid = (ok + ng) >> 1;
		
		if(f(mid)) ok = mid;
		else ng = mid;
	}
	
	printf("%d\n", ok);
	return 0;
}


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

int main(){
    long long int X,fiveth,afiveth,bfiveth,five;
    long long int ans;
    cin>>X;
    fiveth=X/500;
    afiveth=X%500;
    ans=fiveth*1000;
    if(afiveth>0){
        bfiveth=X-500*fiveth;
        five=bfiveth/5;
        ans+=five*5;
    }
    cout<<ans<<endl;
    
}

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

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);

    sort(v.begin(), v.end());
    int ans = v[2] * 10 + v[1] + v[0];

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

Measured memory_bytes: 256
import math
S=input()
dp=[0]*13
dp[0]=1
# dp[k] 13で割った余りkのパターン数
mod = 1000000007

for i in range(len(S)):
    nextDp=[0]*13
    if S[i] == "?":
        for j in range(13):
            for k in range(10):
                nextDp[((10*j) + k) % 13] += dp[j]
                nextDp[((10*j) + k) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            nextDp[((10*j) + k) % 13] += dp[j]
            nextDp[((10*j) + k) % 13] %= mod
    for j in range(13):
        dp[j] = nextDp[j]

print(dp[5])


Measured memory_bytes: 43244
#include <iostream>

#define max_3(a, b, c) max(a, max(b, c))
using namespace std;

int main()
{
    int p, q, r;
    cin >> p >> q >> r;

    int maximum = max_3(p, q, r);
    int sum = p + q + r;

    cout << (sum - maximum);
    return 0;
}


Measured memory_bytes: 256
N, M, K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A=[0]+A
B=[0]+B
import numpy as np
a=np.cumsum(A)
b=np.cumsum(B)

ans=0
j=M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    ans=max(ans, i+j)
print(ans)

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

int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int ans = 0;
    int res = 0;
    rep(i,n-1){
        if(h[i]>=h[i+1]){
            res++;
        }
        else{
            ans = max(ans,res);
            res=0;
        }
    }
    ans = max(ans,res);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;


int main(void){

string st;
	cin >> st;
	reverse(st.begin(),st.end());
	cout << st << endl;
	return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

int x, a, b;

signed main(void){
	cin >> x >> a >> b;
	if(abs(x-a)<abs(x-b)){
		cout << 'A' << endl;
	}else{
		cout << 'B' << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };




int main() {
	fastIO;
	int k;
	cin >> k;
	int n;
	cin >> n;
	vector<int> v;
	for (int i = 0, x; i < n; i++) {
		cin >> x;
		v.push_back(x);
	}

	sort(v.begin(), v.end());
	int dist = k;
	for (int i = 0; i < n; i++) {
		int prev = i ? i-1 : n-1;
		if (v[prev] > v[i]) {
			dist = min(dist, abs(v[prev]-v[i]));
		}
		else {
			dist = min(dist, k - abs(v[prev]-v[i]));
		}
	}

	cout << dist;


}


Measured memory_bytes: 1400
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    S = input()
    l = []
    for i in range(len(S)):
        if S[i] == 'W':
            l.append(i-len(l))
    print(sum(l))


if __name__ == '__main__':
    main()


Measured memory_bytes: 79956
def abc171d_replacing():
    n = int(input())
    a = list(map(int, input().split()))
    a_dict = {}
    for v in a:
        if a_dict.get(v) is None:
            a_dict[v] = 1
        else:
            a_dict[v] += 1
    q = int(input())
    s = []
    total = 0
    for k, v in a_dict.items():
        total += k * v
    for _ in range(q):
        b, c = map(int, input().split())
        if b in a_dict.keys():
            total += (c * a_dict[b] - b * a_dict[b])
            if c in a_dict.keys():
                a_dict[c] += a_dict[b]
            else:
                a_dict[c] = a_dict[b]
            del a_dict[b]
        s.append(total)

    for v in s:
        print(v)


abc171d_replacing()

Measured memory_bytes: 21260
#include "bits/stdc++.h"
using namespace std;
const long long mod = 1000000007;
const int maxn = 100100;
int deg[maxn], cnt[16];
int dp[1<<16], xo[1<<16];
int main(){
    int n;
    cin >> n;
    for(int e = 0; e < n - 1; e++){
        int u, v, w;
        cin >> u >> v >> w;
        deg[u] ^= w;
        deg[v] ^= w;
    }
    for(int e = 0; e < n; e++){
        cnt[deg[e]]++;
    }
    int ans = cnt[0];
    for(int e = 1; e < 16; e++){
        ans += cnt[e] / 2;
        cnt[e] %= 2;
    }
    for(int e = 1; e < 1<<16; e++){
        xo[e] = 0;
        for(int f = 0; f < 16; f++)
            if(e & (1<<f)) xo[e] ^= f;
    }
    dp[0] = 0;
    for(int e = 1; e < 1<<16; e++){
        for(int f = e; f > 0; f = (f - 1) & e){
            if(xo[f] == 0) dp[e] = max(dp[e], dp[f ^ e] + 1);
        }
    }
    int msk = 0;
    for(int e = 1; e < 16; e++)
        if(cnt[e]) msk |= (1<<e);
    ans += dp[msk];
    cout << n - ans << endl;
	return 0;
}


Measured memory_bytes: 1280
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map (fun x -> int x)


let n = readString()
if n.[0] = n.[2] then "Yes" else "No"
|> printfn "%s"

Measured memory_bytes: 11984
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int n, a, b;
int mx = 0;
int cnt;
int main() {
	cin >> n;
	lp(n) {
		cin >> a >> b;
		if (a > mx) {
			mx = a;
			cnt = b;
		}
	}
	cout << mx + cnt << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use num::integer::gcd;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let k = st.trim().parse::<i32>().unwrap();
    let mut r = 0;
    for i in 1..(k+1) {
        for j in 1..(k+1) {
            let mut x: i32 = gcd(i, j);
            for y in 1..(k+1) {
                r += gcd(x, y);
            };
        };
    };
    println!("{}", r);
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=3;i++){
		if(a!=i&&b!=i){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	string str;cin >> str;
	REP(i, str.size()){
		if(str[i] != str[str.size() - i - 1]){
			cout << "No" << endl;
			return 0;
		}
	}

	REP(i, str.size() / 2){
		//cout << i << " " << str.size() / 2 - 1 - i << endl;
		if(str[i] != str[str.size() / 2 - 1 - i]){
			cout << "No" << endl;
			return 0;
		}
		//cout << str.size() / 2 + i << " " << str.size() - i - 1 << endl;
		if(str[str.size() / 2 + i + 1] != str[str.size() - i - 1]){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


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

using namespace std;

int main()
{
	int S;
	int a;
	int b;
	int c;
	int d;
	int f;
	int g;
	int count = 0;

	
		cin >> S;
		
	a = S / 1000;
	b = S % 1000;
	c = b / 100;
	d = b % 100;
	f = d / 10;
	g = d % 10;

	if ( a==c )
	{
		count = count + 1;
	}
	if (c ==f )
	{
		count = count + 1;
	}
	if (f == g)
	{
		count = count + 1;
	}



	
	if(count>0)
	{
		cout << "Bad" << endl;
	}
	else { cout << "Good" << endl; }


    
}

Measured memory_bytes: 256
import itertools
n = int(input())
number_list = [1,2,3,4,5,6,7,8,9]
pattern_list = list(itertools.combinations_with_replacement(number_list,2))
kuku = []
for tup in pattern_list:
    kuku.append(tup[0]*tup[1])
if n in kuku:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384