akhauriyash/Code-Regression huggingface dataset:
def main(s):
    if s != s[-1::-1]:
        print("No")
        return

    n = len(s)

    p1 = s[: (n - 1) // 2]

    if p1 != p1[-1::-1]:
        print("No")
        return

    p2 = s[(n + 2) // 2 :]

    if p2 != p2[-1::-1]:
        print("No")
        return

    print("Yes")


if __name__ == "__main__":
    s = input()
    main(s)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int n;cin>>n;
    vector<int>m;
    REP(i,n)
    {
        int a;cin>>a;
        auto it =upper_bound(m.begin(),m.end(),a,greater<>());
        if(it==m.end())m.pb(a);else *it=a;
    }
    cout<<m.size()<<endl;
}

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

Measured memory_bytes: 892
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int P[20000];
int A[20000];
int B[20000];
int main(){
  int i;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(P[Lj4PdHRW]);P[Lj4PdHRW] += (-1);
    }
  }
  for(i=(0);i<(N);i++){
    A[i] = i * (N+1) + 1;
  }
  for(i=(0);i<(N);i++){
    B[i] = A[N-1-i];
  }
  for(i=(0);i<(N);i++){
    A[P[i]] += i;
  }
  {
    int t_ynMSdg;
    if(N==0){
      putchar_unlocked('\n');
    }
    else{
      for(t_ynMSdg=(0);t_ynMSdg<(N-1);t_ynMSdg++){
        wt_L(A[t_ynMSdg]);
        wt_L(' ');
      }
      wt_L(A[t_ynMSdg]);
      wt_L('\n');
    }
  }
  {
    int tU__gIr_;
    if(N==0){
      putchar_unlocked('\n');
    }
    else{
      for(tU__gIr_=(0);tU__gIr_<(N-1);tU__gIr_++){
        wt_L(B[tU__gIr_]);
        wt_L(' ');
      }
      wt_L(B[tU__gIr_]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20191125-1

// --- original code ---
// int N, P[2d4];
// int A[2d4], B[2d4];
// {
//   rd(N,(P--)(N));
//   rep(i,N) A[i] = i * (N+1) + 1;
//   rep(i,N) B[i] = A[N-1-i];
//   rep(i,N) A[P[i]] += i;
//   wt(A(N));
//   wt(B(N));
// }


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
 
class Atcoder{
   public static long[] cins() {
      string[] ss = Console.ReadLine().Split(' ');
      long[] Res = new long[ss.Length];
      for (int i = 0; i<ss.Length; i++) {
         Res[i]=long.Parse(ss[i]);
      }
      return Res;
   }
   public static void Main(string[] args) {
      long[] G = new long[100001];
      long[] k = cins();
      long N = k[0];long K = k[1];
      long q=1;
      for (int i = 0; i<N; i++) {
         k=cins();
         G[k[0]-1]+=k[1];
      }
      
      for (int i = 0; i<100001; i++) {
         K-=G[i];
         if (K<=0) { q=i+1; break; }
      }

      Console.WriteLine(q);
   }
}

Measured memory_bytes: 15820
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H){
    cin >> S[i];
  }

  rep(i,H){
    rep(j,W){
      if(S[i][j] == '#'){
        cout << "#";
      }else{
        int cnt = 0;
        for(int p=-1;p<=1; p++){
          for(int q=-1;q<=1; q++){
            if(p==0 && q==0) continue;
            if(i+p<0 || H<=i+p || j+q<0 || W<=j+q) continue;
            if(S[i+p][j+q]=='#') cnt++;
          }
        }
        cout << cnt;
      }
    }
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
ab = 0
for a_count in range(a + 1):
    for b_count in range(b + 1):
        ab = a_count * 500 + b_count * 100
        if ab <= x <= (ab + c * 50):
            ans += 1
print(ans)


Measured memory_bytes: 9124
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <algorithm>
#include <limits.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#define ll long long
#define MSET(x) memset((x), 0, sizeof((x)))
#define MMSET(x) memset((x), -1, sizeof((x)))
#define rep(i, a, b) for ( int (i) = a; (i) < (b) ; (i) ++ )
#define repA(i, a, b) for ( int (i) = a ;  (i) <= (b) ; (i) ++ )
#define repD(i, a, b) for ( int (i) = a; (i) >= (b) ; (i) -- )
#define fi first
#define se second
#define pb push_back
#define mfind(m, item) ((m).find((item)) != (m).end())
#define mp(a,b) make_pair((a),(b))
#define mt(a,b,c) make_pair(make_pair((a),(b)), (c))
#define tfi first.first
#define tse first.second
#define tth second
#define print cout << endl
#define tri pair<pair<int, int>, int>
using namespace std;

int n,m;
int fa[100005], cnt[100005];
void find(int x){
    if ( fa[x] == x ) return;
    find(fa[x]);
    cnt[x] += cnt[fa[x]]; fa[x] = fa[fa[x]];
}

int main(){
    while ( cin >> n >> m ) {
        bool has = false;
        MSET(fa); MSET(cnt);
        for ( int i = 0 ; i <= n ; ++ i ) fa[i] = i;
        for ( int i = 0, x, y, z ; i < m ; ++ i ) {
            scanf("%d %d %d", &x, &y, &z);
            find(x); find(y);
            if ( fa[x] == fa[y] ) {
                if ( cnt[y] != cnt[x] + z ) has = true;
            }
            else {
                cnt[fa[y]] = z - cnt[y];
                fa[fa[y]] = x;
            }
        }
        cout << (has ? "No" : "Yes" ) << endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1005,INF=1<<30;

ll inv[MAX],fac[MAX],finv[MAX];

void make(){
    
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    
    for(int i=2;i<MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll)i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
    
}

ll comb(ll a,ll b){
    if(b<0) return 0;
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

ll dp[23][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make();
    
    int N,K;cin>>N>>K;
    vector<int> A(K);
    for(int i=0;i<K;i++) cin>>A[i];
    
    dp[0][0]=1;
    for(int i=0;i<K;i++){
        for(int j=0;j<=N;j++){
            for(int k=j;k<=N;k++){
                int d=k-j;
                dp[i+1][k]+=dp[i][j]*comb(N-d,A[i]-d)%mod*comb(N-j,d)%mod;
                dp[i+1][k]%=mod;
            }
        }
    }
    
    cout<<dp[K][N]<<endl;
}


Measured memory_bytes: 512
// https://atcoder.jp/contests/abc134/tasks/abc134_d

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

inline int read() {
    int out = 0, fh = 1;
    char jp = getchar();
    while ((jp > '9' || jp < '0') && jp != '-')
        jp = getchar();
    if (jp == '-')
        fh = -1, jp = getchar();
    while (jp >= '0' && jp <= '9')
        out = out * 10 + jp - '0', jp = getchar();
    return out * fh;
}

int a[200001];
bool b[200001];
int main() {
    int n, ans = 0;
    n = read();
    for (int i = 1; i <= n; i++) {
        a[i] = read();
    }
    for (int i = n; i >= 1; i--) {
        int x = a[i];
        for (int j = i << 1; j <= n; j += i) {
            x ^= b[j];
        }
        b[i] = x;
        if (x)
            ans++;
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) {
        if (b[i])
            printf("%d ", i);
    }

    return 0;
}


Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select((num, i) =>
            {
                if (i == 0)
                    return long.Parse(num);
                else
                {
                    var tmp = num.Split('.');
                    return long.Parse(tmp[0] + tmp[1]);
                }
            }).ToArray();
            BigInteger big = new BigInteger(ab[0] * ab[1]);
            Console.WriteLine(BigInteger.Divide(big, 100));
        }
    }
}

Measured memory_bytes: 28100
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1
#define INF 1000000000 //1e9
#define PI 3.14159265359
#define mod 1000000007

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> ene(N);
    long long ans = 0;
    for(int i = 0 ; i < N; i++){
        int a;
        cin >> a;
        ene[i] = a;
    }
    sort(ene.begin(),ene.end(),greater<int>());
    if(N <= K){
        cout << 0 << endl;
        return 0;
    }
    for(int i = N-1 ; i >= K; i--){
        ans += ene[i]; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8

N = int(input())
S = input()

# ruisekiwa ba-jon

ruiseki_w = [0] * (N + 1)
ruiseki_e = [0] * (N + 1)

for i in range(0, len(S)):
    ruiseki_w[i+1] = ruiseki_w[i] + S[i].count("W")
    ruiseki_e[i+1] = ruiseki_e[i] + S[i].count("E")

res = 10**10
for i in range(0, len(S)):
    hidari_no_w_no_kazu = ruiseki_w[i]
    migi_no_e_no_kazu = ruiseki_e[-1] - ruiseki_e[i+1]
    res = min(hidari_no_w_no_kazu + migi_no_e_no_kazu, res)

print(res)


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

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str,strArray[];
		int result=0;
		double all=0;
		int i;

		for(i=0; (str=br.readLine()) != null; i++){
			strArray = str.split(",");
			int pr = Integer.parseInt(strArray[0]);
			int m = Integer.parseInt(strArray[1]);
			double m2 = Double.parseDouble(strArray[1]);
			result += pr*m;
			all += m2;
		}
		System.out.println(result);
		System.out.println(Math.round(all/i));
	}
}

Measured memory_bytes: 17060
#include<stdio.h>  
int code(char s){
  if(s=='A')return 0;
  if(s=='B')return 1;
  if(s=='C')return 2;
  return -1;
}
main(){
  int cup[3]={1,0,0};
  char x,y;
  int tmp;
  while(scanf("%c,%c ",&x,&y)!=EOF){
    tmp = cup[code(x)];
    cup[code(x)] = cup[code(y)];
    cup[code(y)] = tmp;
  }
  if(cup[0])printf("A\n");
  if(cup[1])printf("B\n");
  if(cup[2])printf("C\n");
  return 0;
}

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

bool match(char s[])
{
	int i,j,k,flag=1;
	k = strlen(s);
	if(k&1) return 0;
	
	for(i=0,j=k/2;i<(k/2);i++,j++)
	{
		if(s[i] == s[j]) continue;
		else 
		{
			flag = 0;
			break;
		}
	}
	if(flag == 1) return 1;
	else return 0;	
}

int main()
{
	char str[300];
	scanf("%s", str);
	int i,j,k;
	
	k = strlen(str);
	for(i=2;i<k;i++)
	{
		if(k%2 == 0) str[k-i+1] = str[k-i] = '\0';
		if(match(str) == 1) 
		{
			cout << strlen(str);
			//puts(str);
			break;
		}
	}
	
//	cout << endl;
//	puts(str);
}



Measured memory_bytes: 3676
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

int main() {
  int n;
  string s, t;
  cin >> s >> t;
  if (s == t.substr(0, s.length())) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
import collections
n=int(input())
d=[2]*n
w=collections.deque()
for i in range(n-1):
    a,b,c=map(int,input().split())
    if i==0:
        d[a-1]=0
        d[b-1]=c%2
    elif d[a-1]!=2:
        d[b-1]=(d[a-1]+c%2)%2
    elif d[b-1]!=2:
        d[a-1]=(d[b-1]+c%2)%2
    else:
        w.append((a,b,c))

while len(w):
    a,b,c=w.pop()
    if d[a-1]!=2:
        d[b-1]=(d[a-1]+c%2)%2
    elif d[b-1]!=2:
        d[a-1]=(d[b-1]+c%2)%2
    else:
        w.appendleft((a,b,c))
for i in d:
    print(i)


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

int main()
{
  string S;
  cin >> S;
  int cnt = 0;
  for(int i = 0; i < S.length(); i++) {
    if(cnt & 1) {
      if(S[i] == 'Z') {
        ++cnt;
        cout << "AZ";
      }
    } else {
      if(S[i] == 'A') {
        ++cnt;
      }
    }
  }
  if(cnt < 2) puts("-1");
  else puts("");

}

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

inline int gi()
{
	char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	int sum = 0;
	while('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

typedef long long ll;
const int maxn = 55, maxm = 105, mod = 1e9 + 7;

int n, m, col, fac[maxm << 1], ifac[maxm << 1];

struct edge
{
	int to, next;
} e[maxm * 2];
int h[maxn], tot;

inline void add(int u, int v)
{
	e[++tot] = (edge) {v, h[u]}, h[u] = tot;
	e[++tot] = (edge) {u, h[v]}; h[v] = tot;
}

int dfn[maxn], low[maxn], Time, top, bccno[maxn], cnt, siz_p[maxn], siz_e[maxn];
pair<int, int> stk[maxm];
vector<int> vec[maxn];

void dfs(int u, int fa)
{
	dfn[u] = low[u] = ++Time;
	for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
		if (v != fa) {
			if (!dfn[v]) {
				stk[++top] = make_pair(u, v);
				dfs(v, u);
				low[u] = min(low[u], low[v]);
				if (dfn[u] <= low[v]) {
					++cnt;
					while (1) {
						int x = stk[top].first, y = stk[top].second;
						++siz_e[cnt];
						if (bccno[x] != cnt) bccno[x] = cnt, ++siz_p[cnt], vec[cnt].push_back(x);
						if (bccno[y] != cnt) bccno[y] = cnt, ++siz_p[cnt], vec[cnt].push_back(y);
						--top;
						if (x == u && y == v) break;
					}
				}
			} else if (dfn[v] < dfn[u]) stk[++top] = make_pair(u, v), low[u] = min(low[u], dfn[v]);
		}
}

inline int fpow(int x, int k)
{
	int res = 1;
	while (k) {
		if (k & 1) res = (ll)res * x % mod;
		x = (ll)x * x % mod; k >>= 1;
	}
	return res;
}

inline int C(int n, int m)
{
	return (ll)fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int main()
{
	n = gi(); m = gi(); col = gi();
	
	for (int i = 1; i <= m; ++i) add(gi(), gi());

	for (int i = 1; i <= n; ++i)
		if (!dfn[i]) dfs(i, 0);

	fac[0] = ifac[0] = ifac[1] = 1;
	for (int i = 1; i <= m + col; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
	for (int i = 2; i <= m + col; ++i) ifac[i] = (ll)(mod - mod / i) * ifac[mod % i] % mod;
	for (int i = 2; i <= m + col; ++i) ifac[i] = (ll)ifac[i - 1] * ifac[i] % mod;
	
	int ans1 = 1, ans2 = 1, ans3 = 1;
	for (int i = 1; i <= cnt; ++i)
		if (siz_e[i] == 1) ans1 = (ll)ans1 * col % mod;
		else if (siz_e[i] == siz_p[i]) {
			int sum = 0;
			for (int j = 1; j <= siz_e[i]; ++j) {
				sum += fpow(col, __gcd(j, siz_p[i]));
				if (sum >= mod) sum -= mod;
			}
			ans2 = (ll)ans2 * sum % mod * fpow(siz_e[i], mod - 2) % mod;
		} else ans3 = (ll)ans3 * C(siz_e[i] + col - 1, col - 1) % mod;

	printf("%lld\n", (ll)ans1 * ans2 % mod * ans3 % mod);
	
	return 0;
}



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

#define PB push_back

int Partition(vector<pair<string,int> >&,int,int);
void Quicksort(vector<pair<string,int> >&,int,int);
void Mergesort(vector<pair<string,int> >&);

int n;

int main(int argc,char* argv[]){
  vector<pair<string,int> > quicks;
  pair<string,int> stri;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>stri.first>>stri.second;
    quicks.PB(stri);
  }
  vector<pair<string,int> > merges(quicks.begin(),quicks.end());

  Quicksort(quicks,0,n-1);
  Mergesort(merges);

  bool flag=true;
  for(int i=0;i<n;i++){
    if(quicks[i].first!=merges[i].first || quicks[i].second!=merges[i].second){
      flag=false;
      break;
    }
  }

  if(flag)
    cout<<"Stable"<<endl;
  else
    cout<<"Not stable"<<endl;

  for(int i=0;i<n;i++)
    cout<<quicks[i].first<<" "<<quicks[i].second<<endl;

  return 0;
}

int Partition(vector<pair<string,int> >& quicks,int p,int r){
  int x=quicks[r].second;
  int i=p-1;
  for(int j=p;j<r;j++){
    if(quicks[j].second<=x){
      i+=1;
      swap(quicks[i],quicks[j]);
    }
  }
  swap(quicks[i+1],quicks[r]);
  return i+1;
}

void Quicksort(vector<pair<string,int> >& quicks,int p,int r){
  if(p<r){
    int q=Partition(quicks,p,r);
    Quicksort(quicks,p,q-1);
    Quicksort(quicks,q+1,r);
  }
}

void Mergesort(vector<pair<string,int> >& merges){
  int vecsize=merges.size();

  if(vecsize>1){
    vector<pair<string,int> > lft(merges.begin(),merges.begin()+vecsize/2);
    vector<pair<string,int> > rht(merges.begin()+vecsize/2,merges.end());

    Mergesort(lft);
    Mergesort(rht);

    for(int i=0,l=0,r=0;i<vecsize;i++){
      if(l==(int)lft.size())
	merges[i]=rht[r++];
      else if(r==(int)rht.size())
	merges[i]=lft[l++];
      else if(lft[l].second<=rht[r].second)
	merges[i]=lft[l++];
      else
	merges[i]=rht[r++];
    }
  }
}

Measured memory_bytes: 11848
N = int(input())
X = input().split()

distance = 0
min_distance = float('Inf')

for i in range(1,101):
    for j in range(N):
        distance += (int(X[j]) - i) ** 2

    min_distance = min(min_distance, distance)
    distance = 0

print(min_distance)

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

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)

int main(){
    int H,W;
    cin>>H>>W;
    string A;
    bool b[1000][1000];
    vector<pair<int,int>> vec,nex;
    rep(i,H) rep(j,W) b[i][j]=false;
    rep(i,H) {
        cin>>A;
        rep(j,W) {
            if(A[j]=='#') {
                b[i][j]=true;
                vec.push_back(make_pair(i,j));
            }
        }
    }
    bool flag=true;
    rep(i,H)rep(j,W) flag=flag&&b[i][j];
    if(flag) {
        cout<<0<<endl;
        return 0;
    }
    pair<int,int> p;
    int num=0;
    while(true){
        num++;
        while(!vec.empty()){
            p=vec.back();
            vec.pop_back();
            if(p.first==0){
                if(!b[p.first+1][p.second]){
                    b[p.first+1][p.second]=true;
                    nex.push_back(make_pair(p.first+1,p.second));
                }
            }else if(p.first<H-1){
                if(!b[p.first+1][p.second]){
                    b[p.first+1][p.second]=true;
                    nex.push_back(make_pair(p.first+1,p.second));
                }
                if(!b[p.first-1][p.second]){
                    b[p.first-1][p.second]=true;
                    nex.push_back(make_pair(p.first-1,p.second));
                }
            }else{
                if(!b[p.first-1][p.second]){
                    b[p.first-1][p.second]=true;
                    nex.push_back(make_pair(p.first-1,p.second));
                }
            }
            if(p.second==0){
                if(!b[p.first][p.second+1]){
                    b[p.first][p.second+1]=true;
                    nex.push_back(make_pair(p.first,p.second+1));
                }
            }else if(p.second<W-1){
                if(!b[p.first][p.second+1]){
                    b[p.first][p.second+1]=true;
                    nex.push_back(make_pair(p.first,p.second+1));
                }
                if(!b[p.first][p.second-1]){
                    b[p.first][p.second-1]=true;
                    nex.push_back(make_pair(p.first,p.second-1));
                }
            }else{
                if(!b[p.first][p.second-1]){
                    b[p.first][p.second-1]=true;
                    nex.push_back(make_pair(p.first,p.second-1));
                }
            }
        }
        if(nex.empty()) break;
        while(!nex.empty()){
            vec.push_back(nex.back());
            nex.pop_back();
        }
    }
    cout<<num-1<<endl;
    return 0;
}

Measured memory_bytes: 15724
n,q = map(int, input().split())
s = input()
lr = []
for _ in range(q):
    l,r = map(int, input().split())
    lr.append((l,r))

x = [0] * len(s)
cur = 0
for i in range(len(s)-1):
    if s[i] == 'A' and s[i+1] == 'C':
        cur += 1
    x[i+1] = cur

#print(x)
for l,r in lr:
    print(x[r-1] - x[l-1])


Measured memory_bytes: 19756
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main implements Runnable{

	public static void main(String[] args) {
		new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
	}
	
	public void run() {
		FastScanner sc=new FastScanner();
		
		// N=MK^e
		// M-mK=1
		
		//N=(1+mK)K^e
		
		
		long ans=0;
		
		long N=sc.nextLong();
		
		for(long div=1;div*div<=N-1;++div) {
			// N-1=mK
			if((N-1)%div!=0)continue;
			++ans;
			if(div!=(N-1)/div)++ans;
		}
		
		
		for(long div=2;div*div<=N;++div) {
			if(N%div!=0)continue;
			ArrayList<Long> divs=new ArrayList<>();
			divs.add(div);
			if(N/div!=div)divs.add(N/div);
			for(long d:divs){
				long n=N;
				while(n%d==0) {
					n/=d;
				}
				if(n%d==1)++ans;
			}
			
		}
		
		System.out.println(ans);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23892
# Try AtCoder
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.strip end
def gi() gets.to_i end
def gf() gets.to_f end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
MV4 = [[0, 1], [1, 0], [0, -1], [-1, 0]]
MV8 = MV4 + [[1, 1], [1, -1], [-1, -1], [-1, 1]]
DV7 = 7 + 10 ** 9
############################################################

n = gi
a = gis
b = 0
c = 0
(n-1).times do |i|
    t = a[i] <=> a[i+1]
    next if t == 0 || t == b
    if b == 0
        b = t
        c += 1
    else
        b = 0
    end
end
c += 1 if b == 0

puts c


Measured memory_bytes: 8660
#include <bits/stdc++.h>
using namespace std;
void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

int a, b, c, x, y;

int main() {
    cin >> a >> b >> c >> x >> y;

    auto cnum = 2 * c < a + b ? min(x, y) : 0;
    x -= cnum, y -= cnum;

    auto res = 2 * cnum * c + x * min(a, 2 * c) + y * min(b, 2 * c);

    cout << res << endl;

    return 0;
}


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

#define task "C"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int mod = 1e9 + 7;
int power(int x, int y)
{
    int res = 1;
    while (y)
    {
        if (y & 1) res = res * 1LL * x % mod;
        y >>= 1;
        x = x * 1LL * x % mod;
    }
    return res;
}
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    int n;
    cin >> n;
    cout << (power(10, n) - (2LL * power(9, n) - power(8, n) + 2LL * mod) % mod + mod) % mod;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  string ans = "War";
  vector<int> x(N),y(M);
  REP(i,N) cin >> x[i];
  REP(i,M) cin >> y[i];
  VSORT(x);
  VSORT(y);

  for(int i=X+1;i<Y+1;i++){
    if(x[N-1] < i && y[0] >= i)  ans = "No War";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  for(int i=1;i<n;++i){
    int len=n-i;
    if(len%2!=0)continue;
    int half=len/2;
    string ss=s.substr(0,half);
    string tt=s.substr(half,half);
    if(ss==tt){
      cout<<len<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,d,x,a[100];
	scanf("%d",&n);
	scanf("%d %d",&d,&x);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		x += d / a[i];
		if(d % a[i] != 0)x++;
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	ls := make([]int, n)
	for i := range ls {
		fmt.Scan(&ls[i])
	}
	sum := 0
	max := 0
	for _, v := range ls {
		sum += v
		if v > max {
			max = v
		}
	}

	if sum-max > max {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	for (int i = 1; i <= 5; ++i) {
		int x;
		cin >> x;
		if (x == 0) {
			cout << i << '\n';
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



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


string C;
void input(void) {
	CI C;
	return;
}


int main(void) {
	input();
	reverse(C.begin(), C.end());
	
	CO C E

	return 0;
}

Measured memory_bytes: 3100
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = dict()
for v in a:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1

l = []
for v in d.values():
    l.append(v)
l.sort()

print(sum(l[:len(l)-k]))

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

#define N 200010 

using namespace std;

typedef long long ll;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
	int x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-')
			f = -1;
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
	}
	return x * f;
}

ll bin[40];

map <ll, int> MP;

ll a[N];

int main() {
	bin[0] = 1;
	for (int i = 1; i <= 35; i ++ ) {
		bin[i] = bin[i - 1] << 1;
	}
	int n = rd();
	for (int i = 1; i <= n; i ++ ) {
		a[i] = rd();
		MP[a[i]] ++ ;
	}
	sort(a + 1, a + n + 1);

	int ans = 0;
	for (int i = n; i; i -- ) {
		if (MP[a[i]] > 0) {
			MP[a[i]] -- ;
			for (int j = 32; j; j -- ) {
				if (bin[j] - a[i] <= a[i] && bin[j] > a[i]) {
					ll re = bin[j] - a[i];
					if (MP.count(re) && MP[re] > 0) {
						MP[re] -- ;
						ans ++ ;
						break;
					}
				}
			}
		}
	}

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

Measured memory_bytes: 14464
using System;
using System.Collections.Generic;
using System.Text;

namespace CSharpTest
{
    class Class1
    {
        static void Main(string[] args) {
            string[] SW = Console.ReadLine().Split();
            Int16 S = Int16.Parse(SW[0]);
            Int16 W = Int16.Parse(SW[1]);
            if (W >= S)
            {
                Console.WriteLine("unsafe");
            } else
            {
                Console.WriteLine("safe");
            }
        }
    }
}


Measured memory_bytes: 27532
#include<stdio.h>
int main(void){
  int r;
  int D;
  int x;
  int a;
  int b;
  int c;
  int d;
  int e;
  int f;
  int g;
  int h;
  int i;
  int j;
  scanf("%d",&r);
  scanf("%d",&D);
  scanf("%d",&x);
  a=x*r-D;
  printf("%d\n",a);
  b=a*r-D;
  printf("%d\n",b);
  c=b*r-D;
  printf("%d\n",c);
  d=c*r-D;
  printf("%d\n",d);
  e=d*r-D;
  printf("%d\n",e);
  f=e*r-D;
  printf("%d\n",f);
  g=f*r-D;
  printf("%d\n",g);
  h=g*r-D;
  printf("%d\n",h);
  i=h*r-D;
  printf("%d\n",i);
  j=i*r-D;
  printf("%d\n",j);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
from sys import stdin

def solve():
    n, x = map(int, stdin.readline().split())
    items = []
    items.append([1,1])
    for i in range(1,n+1):
        items.append([items[-1][0]*2+3, items[-1][1]*2+1])
    
    if x<=n:
        print(0)
        return
    
    ans = 0
    p = n
    while p and x:
        half = (items[p][0]+1)//2
        if x>=half:
            ans += items[p-1][1] + 1
            x -= half
        else:
            x -= 1
        p -= 1

    if x:
        ans += 1
    print(ans)

solve()

Measured memory_bytes: 3064
def get_max(x,y,z,m)
  w = []
  x.length.times do |i|
    w[i] = x[i]+y[i]+z[i]
  end
  w.sort!.reverse!
  w[0..m-1].inject(:+)
end

(n,m)=gets.chomp.split.map(&:to_i)
x=[]
y=[]
z=[]

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

if m == 0
  puts 0
else
  r_x = x.map{|n|n*-1}
  r_y = y.map{|n|n*-1}
  r_z = z.map{|n|n*-1}

  res = [
    get_max(x,y,z,m),
    get_max(r_x,y,z,m),
    get_max(x,r_y,z,m),
    get_max(x,y,r_z,m),
    get_max(r_x,r_y,z,m),
    get_max(x,r_y,r_z,m),
    get_max(r_x,y,r_z,m),
    get_max(r_x,r_y,r_z,m),
  ]

  puts res.max
end


Measured memory_bytes: 1916
use std::cmp::max;
use std::fs::File;
use std::io::{stdout, BufWriter, Read, Write};
use std::thread;

fn main() {
    thread::Builder::new()
        .stack_size(32 * 1024 * 1024) // 32MB
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    let stdin = std::io::stdin();
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => stdin.lock().read_to_string(&mut s).unwrap(),
    };
    s
}

fn run() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let input = read_input();
    let mut input = input.split_whitespace();

    let in_a: i64 = input.next().unwrap().parse().unwrap();
    let in_b: i64 = input.next().unwrap().parse().unwrap();
    let in_c: i64 = input.next().unwrap().parse().unwrap();

    let rem = max(max(in_a, in_b), in_c) * 3 - in_a - in_b - in_c;
    if rem % 2 == 0 {
        writeln!(out, "{}", rem / 2).ok();
    } else {
        writeln!(out, "{}", rem / 2 + 2).ok();
    }
}


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

bool f(string &s) {
  vector<char> stack;
  for(int i=0; i<s.length(); ++i) {
    if(s[i] == '(') {
      stack.push_back('(');
    }
    if(s[i] == '[') {
      stack.push_back('[');
    }
    if(s[i] == ']') {
      if(stack.empty()) return false;
      if(stack.back() == '[') {
        stack.pop_back();
      }else{
        return false;
      }
    }
    if(s[i] == ')') {
      if(stack.empty()) return false;
      if(stack.back() == '(') {
        stack.pop_back();
      }else{
        return false;
      }
    }
  }
  if(stack.size() == 0) return true;
  return false;
}

int main() {
  string s;
  while(getline(cin,s)) {
    if(s == ".") break;
    cout<<(f(s)?"yes":"no")<<endl;
  }
}

Measured memory_bytes: 0
n = gets.chomp.to_i
w = gets.chomp.split(" ").map{|s| s.to_i }

cl = 0
cr = n-1

left = w[cl]
right = w[cr]

until cl+1 == cr
  if left < right then
    cl += 1
    left += w[cl]
  else
    cr -= 1
    right += w[cr]
  end
end
puts (left - right).abs

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int sum[4010], sum2[4010], k, n;
vector<pair<int, int> > at[4010];
int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		bool wants;
		char c;
		scanf(" %c", &c);
		if (c == 'W') wants = 0;
		else wants = 1;
		int rat = ((x/k) + (y/k)) % 2;
		if (rat == wants)
		{
			// good, its where we want;
			sum[y % k]++;
			sum[2*k + (y % k)]++;
			sum2[x % k]++;
			at[y%k].emplace_back(x, y);
			at[2*k + (y%k)].emplace_back(x, y);
	//		printf("adding %d\n", x%k);
		}
		else
		{
			sum[k + (y % k)]++;
			at[k + (y%k)].emplace_back(x, y);
			sum2[x % k]--;
	//		printf("removing %d\n", x%k);
		}
	}
	for (int i = 1; i <= 3*k; i++)
	{
		sum[i] += sum[i-1];
	}
	int ans = 0;
	for (int i = 0; i <= 2*k; i++)
	{
		int range = sum[i+k-1];
		if (i) range -= sum[i-1];
		if (i)
		{
		for (auto a : at[i+k-1])
		{
			//going from out, to in;
			int x = a.first;
			sum2[x % k] += 2;
		}
		for (auto a : at[i-1])
		{
			int x = a.first;
			sum2[x % k] -= 2;
		}
		}
		int swapped = 0;
	//	printf(" %d\n", range);
		for (int j = 0; j < 2*k; j++)
		{
		//	printf("%d %d\n", i, j);
		//	printf("%d\n", swapped);
			ans = max(ans, range - swapped);
			if (j < k)
			{
				swapped += sum2[j];
			}
			else
			{
				swapped -= sum2[j-k];
			}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 2176
/*
* Problem Statement: 
* Author: ganpa
*/
#include <bits/stdc++.h>

#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    puts(n?"0\n":"1\n");
}


Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n, m;
int x[10000];

int main(){
	while(scanf("%d%d", &n, &m), n){
		rep(i, n){
			rep(j, m){
				int p;
				scanf("%d", &p);
				x[j] |= p << i;
			}
		}
		int ans = 0;
		rep(i, 1 << n){
			int t = 0;
			rep(j, m){
				int a = x[j] ^ i;
				int k = 0;
				while(a){
					a &= a - 1;
					++k;
				}
				t += max(k, n - k);
			}
			ans = max(t, ans);
		}
		printf("%d\n", ans);

		fill_n(x, m, 0);
	}
	return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
using namespace std;
using ll = long long;
using ld = long double;
using cd = complex<double>;
const double PI = acos(-1);

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin>>n;
	cout << n*n*n << '\n';
	return 0;
}

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

const int MOD = 1e+9 + 7;

int main() {
	long long N, ans = 1;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		ans *= i;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
s = []
s_10 = []
for i in range(N):
    x = int(input())
    if x%10 ==0:
        s_10.append(x)
    else:
        s.append(x)
s_10.sort()
s.sort()
if len(s)==0:
    print(0)
    exit()
if sum(s)%10==0:
    print(sum(s)+sum(s_10)-min(s))
else:
    print(sum(s)+sum(s_10))

Measured memory_bytes: 3064
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    print ((-N)%1000)
#%%submit!
resolve()

Measured memory_bytes: 61896
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

const int MAX_A = 300005;
int op(int a, int b) { return max(a,b);}
int e() { return 0;}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    segtree<int,op,e> dp(MAX_A);
    rep(i,n) {
        int x = a[i];
        int l = max(x-k,0), r = min(x+k+1,MAX_A);
        int now = dp.prod(l,r)+1;
        dp.set(x, now);
    }
    int ans = dp.prod(0,MAX_A);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9608
#include<bits/stdc++.h>
using namespace std;
char s[1000010];
int L[1000010];

int main()
{
	int n,m;cin>>n>>m;
	scanf("%s",s+1);
	for(int i=2;i<=n;i++){
		L[i]=L[i-1];
		if(s[i]=='C'&&s[i-1]=='A')L[i]++;
	}
	for(int i=1;i<=m;i++){
		int l,r;scanf("%d%d",&l,&r);
		printf("%d\n",L[r]-L[l]);
	}
}

Measured memory_bytes: 3328
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long N=sc.nextLong();
		int maxlen=12;
		long[] space=new long[maxlen];
		space[0]=1;
		int ketasu=0;
		String ans="";
		for(int i=1; i<maxlen; i++) {
			space[i]=space[i-1]*26;
		}
		for(int i=1; i<maxlen; i++) {
			space[i]+=space[i-1];
		}
		for(int i=0; i<maxlen; i++) {
			if(N>=space[i]) {
				ketasu=i+1;
			}
			else {
				break;
			}
		}
		N-=space[ketasu-1];
		//lp(N+" "+ketasu);
		for(int i=0; i<ketasu; i++) {
			ans=((char)(N%26+'a'))+ans;
			N/=26;
		}
		lp(ans);
	}
	public static void lp(Object o) {
		System.out.println(o);
	}
}

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

int main() {
	int x;
	string str, T;
	cin >> str >> T;
	for (int i = str.size() - T.size(); i >= 0; i--) {
		for (int j = 0; j < T.size(); j++) {
			if (str[i + j] != T[j] && str[i + j] != '?')	break;
			if (j == T.size() - 1) {
				x = i;
				goto endloop;
			}
		}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
	endloop:;
	for (int i = 0; i < T.size(); i++) {
		str[i + x] = T[i];
	}
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == '?')	str[i] = 'a';
	}
	cout << str << endl;
	return 0;
}

/*
?tc????
coder
*/

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

void swap(int& a, int& b) {
	int x = a;
	a = b;
	b = x;
}

void mySort(int& a, int& b, int& c) {
	int min = 0;
	int mid = 0;
	int max = 0;

	max = a;
	mid = b;
	if(mid >= max)	swap(mid, max);
	min = c;
	if(min >= mid)	swap(min, mid);
	if(mid >= max)	swap(mid, max);
	a = min;
	b = mid;
	c = max;
}

int main(){
	int n;
	cin >> n;
	int a, b, c;
	for(int i = 0; i < n; ++i) {
		cin >> a >> b >> c;
		mySort(a, b, c);
		if(a * a + b * b == c * c) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

using namespace std;

typedef unsigned long long int ulli;

int main(){
	double a,b;
	cin >> a >> b;
	for(int i = 1; i < 1260; i++){
		if(floor(i * 0.08) == a && floor(i * 0.1) == b){cout << i;exit(0);}
	}
	cout << -1;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 20000


int main(){
	vector<long long>a;
	long long b[N];
	f(i, N)b[i] = 0;
	int n, k;
	long long x;
	long long s, ans;
	int kk;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n, &k);
	f(i, n){
		scanf("%lld", &b[i]);
	}
	a.clear();
	f(i, n){
		s = 0;
		for (int j = i; j < n; j++){
			s += b[j];
			a.push_back(s);
		}
	}
	ans = 0;
	for (int i = 50; i >= 0; i--){
		kk = 0;
		x = 1;
		f(j, i)x = x * 2;
		ans += x;
		f(j, a.size()){
			if ((ans&a[j]) == ans)kk++;
		}
		if (kk < k)ans -= x;
	}
	printf("%lld\n", ans);



	return 0;
}

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

UL dp[1001][1001];

void Case(){
 string S,T; cin>>S>>T;
 rep(i,S.size()+1) rep(j,T.size()+1) dp[i][j]=0;
 rep(i,S.size()) rep(j,T.size()){
  dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
  if(S[i]==T[j]) dp[i+1][j+1]=dp[i][j]+1;
 }
 cout<<dp[S.size()][T.size()]<<endl;
}

int main() {
 UL T; cin>>T;
 rep(t,T) Case();
 return 0;
}



Measured memory_bytes: 7132
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;

int main(){
string s;
cin>>s;
if(s=="ABC")cout<<"ARC"<<endl;
else cout<<"ABC"<<endl;

return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

int main(){

  int H, W, D, A;
  int Q, L, R;
  int px[90001], py[90001];
  int d[90001];

  cin >> H >> W >> D;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> A;
      px[A]=i, py[A]=j;
    }
  }

  for(int i=D+1; i<=H*W; i++){
    d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
  }
  cin >> Q;
  while(Q--){
    cin >> L >> R;
    cout << d[R]-d[L] << endl;
  }

  return 0;
}

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

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

	char a,b;

	cin >> a >> b;

	if(a>b)
	{
		cout << '>' << '\n';
	}
	else if(a==b)
	{
		cout << '=' << '\n';
	}
	else
	{
		cout << '<' << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 256