akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define maxn 200010
#define ll long long
char str[maxn];
int n,i,s=0;
ll ans=0;
int main()
{
	scanf("%s",str);
	n=strlen(str);
	for (i=0;i<n;i++)
		if (str[i]=='A') s++;
			else if ((str[i]=='B') && (str[i+1]=='C')) ans+=1LL*s,i++;
				else s=0;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int d[60];
int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&d[i]);
    int ans=0;
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            ans+=d[i]*d[j];
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
    int D, N; cin >> D >> N;

    if(N == 100) N = 101;

    rep(i,D) N *= 100;

    cout << N << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};

const double EPS = 1e-9;

struct Circle{
    point p;
    double r;
    int c;
    Circle(int x,int y,double r,int c) : p(x,y),r(r),c(c) {}
};

bool is_intersected_circle(const Circle& a,const Circle& b){
    return abs(a.p-b.p)<(a.r + b.r)-EPS;
}

inline int popcount(int x){
    int ret = 0;
    while(x){
        x &= x-1;
        ret++;
    }
    return ret;
}

void cerr_bits(int x,int n){
    for(int i=0;i<n;i++){
        cerr << ((x&(1 << i)) != 0) << " ";
    }
    cerr << endl;
}
int solve(const vector<Circle>& cs){
    int n = cs.size();

    vector<vector<char> > override(n,vector<char>(n,false));
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            if(is_intersected_circle(cs[i],cs[j])){
                override[i][j] = override[j][i] = true;
            }
        }
    }

    stack<int> S;
    int ret = 0;
    S.push(0);
    set<int> alr;
    while(not S.empty()){
        int cur = S.top();
        S.pop();
        if(alr.find(cur) != alr.end()) continue;
        alr.insert(cur);
        ret = max(ret,popcount(cur));
        vector<char> ov(n,false);
        for(int i=0;i<n;i++){
            if(cur & (1 << i)) continue;
            for(int j=i+1;j<n;j++){
                if(cur & (1 << j)) continue;
                if(override[i][j]){
                    ov[j] = true;
                }
            }
        }
        for(int i=0;i<n;i++){
            if((cur & (1 << i)) || ov[i]) continue;
            if(ov[i]) continue;
            for(int j=i+1;j<n;j++){
                if((cur & (1 << j)) || ov[j]) continue;
                if(cs[i].c == cs[j].c){
                    int here = cur;
                    here |= (1 << i);
                    here |= (1 << j);
                    S.push(here);
                }
            }
        }
    }
    return ret;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<Circle> cs;
        for(int i=0;i<n;i++){
            int x,y,r,c;
            cin >> x >> y >> r >> c;
            cs.push_back(Circle(x,y,r,c));
        }
        cout << solve(cs) << endl;
    }
    return 0;
}

Measured memory_bytes: 50280
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define fore(i,a,b) for(int i=a,thxicesi=b; i<thxicesi;i++)
#define FIN ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define sz(s) int(s.size())
using namespace std;
typedef long long ll;
ll mod = 2019;
int main()
{FIN;
    string s; cin>>s;
    int n= sz(s);
    vector<ll> cnt_suf(mod);
    ll suf = 0;
    ll power10 = 1;
    cnt_suf[suf]++;
    ll ans = 0;
    for(int i = n-1; i>= 0; i--){
        suf = (suf + power10* (s[i]-'0') )%mod;
        power10 = (10 *power10)%mod;
        ans += cnt_suf[suf];
        cnt_suf[suf]++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  int n;cin>>n;
  vector<int> a(n);
  vi p(n);
  vi q(n);
  rep(i,n){
    a[i]=i+1;
  }
  rep(i,n) cin>>p[i];
  rep(i,n) cin>>q[i];
  sort(all(a));
  vvi jisyo;
  do {
    
    jisyo.push_back(a);
    
  } while (next_permutation(a.begin(), a.end()));
  int A,B;
  rep(i,jisyo.size()){
    if(jisyo[i]==p) A=i;
    if(jisyo[i]==q) B=i;
  }
  cout<<abs(A-B)<<endl;
  
}


Measured memory_bytes: 3256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  int n;
  int count=0;
  int hantei;
  
  cin>>n;
  
  vector<int> a(n);
  vector<int> s(n);
  
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]%2==0)
    {
      s[count]=a[i];
      count++;
    }
  }
  
  for(int j=0;j<count;j++)
  {
    if(s[j]%5==0||s[j]%3==0)
    {
      hantei=0;
    }
    else
    {
      hantei=1;
    }
    if(hantei==1)
    {
      break;
    }
  }
  
  if(hantei==0)
  {
	cout<<"APPROVED"<<endl;
  }
  else
  {
    cout<<"DENIED"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*
[diverta2019] A - Consecutive Integers
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int N, K;

ll solve() { return N - K + 1; }

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const int Dist(const vector<int> &values, const int num)
{
    if (values.empty() || num == 0)
    {
        return 0;
    }
    else
    {
        return values[num - 1];
    }
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> lefts, rights;
    for (int i = 0; i < N; ++i)
    {
        int candle;
        cin >> candle;
        if (candle == 0)
        {
            --K;
        }
        else if (candle < 0)
        {
            lefts.push_back(-candle);
        }
        else
        {
            rights.push_back(candle);
        }
    }
    sort(lefts.begin(), lefts.end());
    int minSum = MOD;
    for (int leftNum = max(0, K - static_cast<int>(rights.size())), n = lefts.size(); leftNum <= n; ++leftNum)
    {
        int rightNum = K - leftNum;
        if (rightNum < 0)
        {
            break;
        }
        int sum = Dist(lefts, leftNum) + Dist(rights, rightNum);
        if (leftNum != 0 && rightNum != 0)
        {
            sum += min(lefts[leftNum - 1], rights[rightNum - 1]);
        }
        if (sum < minSum)
        {
            minSum = sum;
        }
    }
    cout << minSum << endl;
}


Measured memory_bytes: 1020
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





int main()
{
   
    int n, k;
    cin >> n >> k;
    vector<int>h(n+k+5),a(n+k+5);

    for (int i = 0; i < n; i++) {
        cin >> h[i]; a[i] = 1999999999;
    }
    a[0] = 0;
    for (int i = 0; i < n; i++) {
      //  cout << i;
        for (int j = i + 1; j <= i + k; j++) {
            a[j] = min(a[j], abs(h[i] - h[j])+a[i]);
        }

    }
    cout << a[n - 1] << endl;

    return 0;

}

Measured memory_bytes: 3992
MOD = 10 ** 9 + 7
fac = [1] * 200005
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
h, w, a, b = map(int, input().split())
ans = 0
x, y = b, h - a - 1
while x < w and y >= 0:
    p = w - x - 1
    q = h - y - 1
    ans += (fac[x + y] * pow(fac[x] * fac[y], MOD - 2, MOD) *
            fac[p + q] * pow(fac[p] * fac[q], MOD - 2, MOD)) % MOD
    x += 1
    y -= 1
print(ans % MOD)

Measured memory_bytes: 10868
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntSet as IntSet

rowToSet :: BS.ByteString -> IntSet.IntSet
rowToSet s = snd $ BS.foldl' (\(i,set) c -> let !i' = i+1
                                                !set' | c == '#' = IntSet.insert i set
                                                      | otherwise = set
                                            in (i', set')
                             ) (0, IntSet.empty) s

colToSet :: V.Vector BS.ByteString -> Int -> IntSet.IntSet
colToSet v !j = V.ifoldl' (\set i s -> if BS.index s j == '#'
                                       then IntSet.insert i set
                                       else set
                          ) IntSet.empty v

main = do
  [h,w] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  grid <- V.replicateM h BS.getLine
  let rowSets = V.map rowToSet grid
      colSets = V.map (colToSet grid) $ V.enumFromN 0 w
  let result = maximum [ r1 - r0 + c1 - c0 - 3
                       | i <- [0..h-1]
                       , j <- [0..w-1]
                       , let r0 = fromMaybe (-1) (IntSet.lookupLE j (rowSets V.! i))
                       , r0 /= j
                       , let c0 = fromMaybe (-1) (IntSet.lookupLE i (colSets V.! j))
                       , c0 /= i
                       , let r1 = fromMaybe w (IntSet.lookupGT j (rowSets V.! i))
                       , let c1 = fromMaybe h (IntSet.lookupGT i (colSets V.! j))
                       ]
  print result


Measured memory_bytes: 34192
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int max0=a[1]-a[0];
    int min0=a[0];
    for(int i=1;i<n;i++)
    {
        max0=max(max0,a[i]-min0);
        min0=min(min0,a[i]);
    }
    cout<<max0<<endl;
    return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rp(i,n){
        cin >> a[i];
    }
    sort(a);
    vi b(a[n-1]+1);
    rp(i,a[n-1]+1){
        b[i]=1;
    }
    int max=0;
    rp(i,n){
        
        if(a[i]!=0){
            b[a[i]-1]++;
            max = (max<b[a[i]-1]?b[a[i]-1]:max);
        }
        
        b[a[i]]++;
        max = (max<b[a[i]]?b[a[i]]:max);
        
        if(a[i]!=a[n-1]){
            b[a[i]+1]++;
            max = (max<b[a[i]+1]?b[a[i]+1]:max);
        }
        
    }
    cout << max-1 << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    s = IS()
    n = len(s)
    dp = DD2(n,4)
    dp[0][0] = 1
    dp[1][1] = 1
    for i in range(1, n):
        if s[i-1] != s[i]:
            dp[i][0] = max(dp[i-1][0], dp[i-1][2]) + 1
        if i < n-1:
            dp[i+1][1] = max(dp[i-1][0], dp[i-1][2]) + 1
        dp[i][2] = max(dp[i-1][1], dp[i-1][3]) + 1
        if 2 <= i < n-1 and (s[i-2] != s[i] or s[i-1] != s[i+1]):
            dp[i+1][3] = max(dp[i-1][1], dp[i-1][3]) + 1
    print(max(dp[-1]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 52276
N, T = gets.split.map(&:to_i)
Ts = gets.split.map(&:to_i)

s, r = 0, 0
Ts.each_cons(2) do |a, b|
  t = [[T, r].max, b - a].min
  s += t
  r = [T - t, 0].max
end
puts s + T

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

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
  ios_base::sync_with_stdio(false);

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

  auto get_dp = [&]() {
    vector<vector<bool>> dp(n + 1, vector<bool>(k));
    dp[0][0] = true;
    for (int i = 0; i < n; i++) {
      if (a[i] < k) {
        dp[i + 1][a[i]] = true;
      }
      dp[i + 1] = dp[i];
      for (int j = a[i]; j < k; j++) {
        dp[i + 1][j] = dp[i + 1][j] || dp[i][j - a[i]];
      }
    }
    return dp;
  };

  auto pref = get_dp();
  reverse(a.begin(), a.end());
  auto suff = get_dp();
  reverse(a.begin(), a.end());
  vector<vector<int>> suff_sum(n + 1, vector<int>(k + 1));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      suff_sum[i][j + 1] = suff_sum[i][j] + suff[i][j];
    }
  }

  debug(pref);
  int num = 0, l, r;
  for (int i = 0; i < n; i++) {
    if (a[i] >= k) {
      num++;
      continue;
    }
    // [L, R] = [k - a[i], k - 1]
    for (int j = 0; j < k; j++) {
      if (pref[i][j] == false) continue;
      l = k - a[i] - j;
      r = k - 1 - j;
      l = max(l, 0);
      if (r < 0) break;
      if (suff_sum[n - 1 - i][r + 1] - suff_sum[n - 1 - i][l] > 0) {
        num++;
        break;
      }
    }
  }

  cout << n - num << '\n';

  return 0;
}


Measured memory_bytes: 107788
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <vector>
#define F first
#define S second
#define pb push_back
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vLL vector<LL>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long LU;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LD l, vol;
    cin >> l;
    l = l / 3;
    vol = l * l * l;
    cout.precision(18);
    cout << vol << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	int A,B; SCD2(A,B);
	if ((A<=8) and (B<=8)){
		printf("Yay!\n");
	}else{
		printf(":(\n");
	}
	
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
#define N 100000
#define INF 100000000
 
typedef struct{
  int g;
  int b;
  int c;
}data;
 
int n,A[N];
data D[500000];
 
void singlesource(int num)
{
  int i,ch=1;
 
  for(i=0; i<n; i++)A[i]=INF;
  A[0]=0;
 
  while(ch!=0){
    ch=0;
    for(i=0; i<num; i++){
      if(D[i].c+A[D[i].b]<A[D[i].g]){
    A[D[i].g]=D[i].c+A[D[i].b];
    ch=1;
      }
    }
  }
}
 
int main()
{
  int i,j,k,p,con=0;
 
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d%d",&p,&k);
    for(j=0; j<k; j++){
      D[con].b=p;
      scanf("%d%d",&D[con].g,&D[con].c);
      con++;
    }
  }
  singlesource(con);
  for(i=0; i<n; i++)printf("%d %d\n",i,A[i]);
  return 0;
}


Measured memory_bytes: 7552
#include "bits/stdc++.h"

using namespace std;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int n;
string s;

int main() {
	while (true) {
		cin >> n;
		if (!n)break;
		cin >> s;
		int play[11] = { 0 }, now = 0, remain = 0;
		for (int i = 0;i < 100;i++) {
			if (s[i] == 'M')play[now]++;
			else if (s[i] == 'S') {
				remain += play[now] + 1;
				play[now] = 0;
			}
			else {
				play[now] += remain + 1;
				remain = 0;
			}
			now = (now + 1) % n;
		}
		sort(play, play + n);
		for (int i = 0;i < n+1;i++) {
			if (i != n)cout << play[i] << ' ';
			else cout << remain << endl;
		}
	}
	return 0;
}




Measured memory_bytes: 3220
N = int(input())
S = list(input())

abc = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") 
ans = []

for i in range(len(S)):
    index = abc.index(S[i])
    if index + N < 26:
        ans.append(abc[index + N])
    else:
        ans.append(abc[index + N - 26])
print("".join(ans))
    

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int MX=100000;
const int mod=1000000007;
const ll inf=1e18;
ll dp[MX+5],n;
int main(){
    ll i,j,k,W,x,y;
    cin >> n >> W;
    for(i=1;i<=100005;i++)dp[i]=inf;
    for(i=1; i<=n; i++){
        cin >> x >> y;
        for(j=MX;j>=y;j--){
            dp[j]=min(dp[j],dp[j-y]+x);
        }
    }
    ll res=0;
    for(i=1; i<=MX; i++){
        if(dp[i]<=W) res=i;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
max_L = 0
min_R = 1000000
for i in range(M):
    L, R = map(int, input().split())
    if max_L < L:
        max_L = L
    if min_R > R:
        min_R = R
    
ans = min_R - max_L + 1
if ans >= 0:
    print(ans)
else:
    print(0)

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

int main(){
    int x;
    cin >> x;
    bool ok = true;
    bool ok2 = true;
    while(ok){
        ok2 = true;
        for(int i=2;i<x;i++){
            if(x%i==0){
                ok2 = false;
                continue;
            }
        }
        if(ok2){
            cout << x << endl;
            return 0;
        }
        x++;
    }

    return 0;
}

Measured memory_bytes: 256
let rec seq a b = if a >= b then [] else a :: seq (a+1) b
let (>>=) x f = List.map f x |> List.concat
let () =
  Scanf.scanf "%d %d" @@ fun n c ->
  let d =
    Array.init c (fun i ->
      Array.init c (fun j -> Scanf.scanf " %d" ((+) 0)))
  in
  let b =
    Array.init n (fun i ->
      Array.init n (fun j -> Scanf.scanf " %d" ((+) 0)))
  in

  let sc = Array.init 3 (fun _ -> Array.make c 0) in
  let _ =
    seq 0 n >>= fun x ->
    seq 0 n >>= fun y ->
      let i = (x + y) mod 3 in
      seq 0 c |> List.iter (fun j -> sc.(i).(j) <- sc.(i).(j) + d.(b.(x).(y)-1).(j));
      []
  in

  (seq 0 c >>= fun i ->
   seq 0 c >>= fun j ->
   seq 0 c >>= fun k ->
     if i = j || j = k || k = i then []
     else [ sc.(0).(i) + sc.(1).(j) + sc.(2).(k) ])
  |> List.fold_left min 10101010101010 
  |> Printf.printf "%d\n"

Measured memory_bytes: 5888
#include<stdio.h>

int main(){

  int N,i,j,k,v,minj,count=0;

  scanf("%d", &N);
  int A[N];

  for(i=0;i<N;i++)scanf("%d",&A[i]);
  
  for(i = 0 ; i <= N-1 ; i++){
    minj = i;
    for( j = i ; j <= N-1 ; j++){
      if(A[j] < A[minj])minj = j;
    }
    if(i != minj){
      v = A[i];
      A[i] = A[minj];
      A[minj] = v;
      count++;
    }
  }

  printf("%d",A[0]);
  for(k = 1 ; k < N ; k++)printf(" %d",A[k]);
  printf("\n%d\n",count);
   
 return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  long long t, a, pt = 1, pa = 1, k;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%lld%lld", &t, &a);
    k = max((pt-1) / t, (pa-1) / a) + 1;
    pt = t*k; pa = a*k;
  }
  printf("%lld\n", pt+pa);
}

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++) cin >> d.at(i);
  sort(d.begin(),d.end());
  int K = d.at(N/2)-d.at(N/2-1);
  cout << K << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>	
using namespace std;
int main() {
	long long m;
	cin >> m;
	for (long long i = sqrt(m + 1); i >= 1; i--) {
		if (m % i == 0) {
			cout << m / i + i - 2;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int x;
    cin >> x;
    int ans = x^1;
    cout << ans << endl;
}

Measured memory_bytes: 3644
/*==============================================*\
Codeforces ID:    mdshihab                        
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI(); /// skip this line for compile
    int n,m;
    cin >> n >> m;
    if(m>=n) cout << "unsafe\n";
    else cout << "safe\n";
    return 0;
}



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

alpha = 'abcdefghijklmnopqrstuvwxyz'

counts = dict()
for l in alpha:
    counts[l] = 50
    
for i in range(n):
    S = input()
    for l in alpha:
        counts[l] = min(counts[l], S.count(l))

res = ""
for l in alpha:
    for _ in range(counts[l]):
        res = res + l
print(res)

Measured memory_bytes: 3064
x1, x2, x3, x4, x5 = map(int, input().split())
if x1 == 0:
  print(1)
elif x2 == 0:
  print(2)
elif x3 == 0:
  print(3)
elif x4 == 0:
  print(4)
elif x5 == 0:
  print(5)

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

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

  if(hitachi == "hi" || hitachi == "hihi" || hitachi == "hihihi" || hitachi == "hihihihi" || hitachi == "hihihihihi"){
    cout << "Yes" << endl;
    return 0;
  } 
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

int i, j, k, l, m, n;
int H, W, N, M, Q;
int a, b, c;

int main()
{
	cin >> N;
	cout << "ABC" << N << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
using namespace std;
#define ll long long
const int P=1e9+7,maxn=1e6;
ll h,w,a,b,ans,D[maxn],U[maxn];
ll q_pow(ll a,ll b){
    ll ret=1;
    while(b){
        if (b&1) ret=ret*a%P;
        a=a*a%P;
        b>>=1;
    }
    return ret;
}
ll C(ll n,ll m){
    return U[n]*D[m]%P*D[n-m]%P;
}
int main() {
    U[0]=D[0]=1;
    for (int i=1; i<maxn; i++){
        U[i]=U[i-1]*i%P;
        D[i]=q_pow(U[i],P-2);
    }
	scanf("%lld%lld%lld%lld",&h,&w,&a,&b);
	ll x=h-a;
    for (int i=b+1; i<=w; i++)
        ans=(ans+C(h-a+i-2,i-1)*C(a-1+w-i,a-1))%P;
	printf("%lld\n",ans);
}

Measured memory_bytes: 18852
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
uv = [ set() for _ in range(N)]
vu = [ set() for _ in range(N)]
for _ in range(M):
    A, B = inpl()
    uv[A-1].add(B-1)
    vu[B-1].add(A-1)

EMPTY, LOOP, TREE = 0, 1, 2
ENTER, EXIT = 0, 1
status = [EMPTY] * N
for s in range(N):
    states_pool = [(s,[],ENTER)]
    while states_pool:
        u, chain, flag = states_pool.pop()
        if flag == EXIT or status[u] == TREE:
            status[u] = TREE
            continue
        elif status[u] == LOOP:
            break
        else: # ENTER, EMPTY
            status[u] = LOOP
            states_pool.append((u,chain,EXIT))
            new_chain = chain.copy()
            new_chain.append(u)
            for c in uv[u]:
                states_pool.append((c, new_chain, ENTER))
    else:
        continue
    break
else:
    print(-1)
    exit()

n = 0
while chain[n] != u:
    n += 1
chain = chain[n:]
L = len(chain)
nextnode = [None]*N
for i in range(L-1):
    nextnode[chain[i]] = chain[i+1]
nextnode[chain[L-1]] = chain[0]
pos = [None]*N
for p in range(len(chain)):
    pos[chain[p]] = p
i = 0
while i < L:
    h = 1
    c = chain[(i+1)%L]
    for j in uv[chain[i % L]]:
        p = pos[j]
        if p is None:
            continue
        else:
            if (p-i)%L > h:
                h = (p-i)%L
                c = j
    nextnode[chain[i % L]] = c
    i += 1
    while chain[i % L] != c:
        pos[chain[i % L]] = None
        i += 1

loop = [c]
k = c
while nextnode[k] != c:
    k = nextnode[k]
    loop.append(k)
print(len(loop))
for l in loop:
    print(l+1)

Measured memory_bytes: 8432
#include <bits/stdc++.h>
using namespace std;
int main(){

    int N,P,i,a = 0,b = 0;
    long long int c = 1,d = 1,e = 1;
    cin >> N >> P;
    int A[N];
    for(i = 0; i < N; i++){
        cin >> A[i];
    }

    for(i = 0; i < N; i++) {
        if (A[i] % 2 == 0) {
            a++;
        } else if(A[i] % 2 == 1){
            b++;
        }
    }

    for(i = 1; i <= N; i++){
        d = d * 2;
    }

    if(b == 0 && a != 0) {
        if(P == 1){
            cout << 0  << endl;
        }else{
            cout << d << endl;
        }
    }else{
        for(i = 1; i < N-1; i++){
            c = c * 2;
        }
        cout << 2 * c << endl;
    }


    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

"""
while N > K:
  N = abs(N - K)
  #print(N)

print(min(N, abs(N-K)))
"""

m = N//K
print(min(N - m*K, -(N - (m+1)*K)))

"""
print(min(N%K, abs(N%K - K)))
"""

Measured memory_bytes: 9080
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    H, W = (int(_) for _ in input().split())
    a = []
    for i in range(H):
        a.append(list(_ for _ in input()))
    a_1 = []
    for i in range(H):
        if a[i].count('.') != W:
            a_1.append(a[i])
    W_bit = list(1 for _ in range(W))
    for h in range(len(a_1)):
        for w in range(W):
            if a_1[h][w] == '#':
                W_bit[w] = 0    

    for h in range(len(a_1)):
        for w in range(W):
            if W_bit[w] == 0:
                print(a_1[h][w],end='')
        print('')
if __name__ == '__main__':
    main()


Measured memory_bytes: 5092
import java.util.*;
public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int count = 0;

        for(int i = 0;i < s.length();i++) {
            if(s.charAt(i) == 'o'){
                count++;
            }
        }

        System.out.println(count * 100 + 700);

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
    
int main() {
  int N, M; cin >> N >> M;
  int a[100000] = {};
  for(int i=0; i<N; i++)
    scanf("%d", a+i);

  int l = 0, r = INT_MAX/4;
  while(r - l > 1) {
    int m = (l+r)/2;
    int num = 0;
    for(int i=0; i<M; i++) {
      int size = m;
      for(;;) {
        if(num == N) break;
        if(size - a[num] < 0) break;
        size -= a[num++];
      }
      if(num == N) break;
    }
    if(num == N) { r = m;}
    else { l = m; }
  }
        
  printf("%d\n", l+1);

  return 0;
}

Measured memory_bytes: 1628
N = int(input())
ans = 0
if N >9:
    ans += 9
    if N > 99:
        if N > 999:
            ans += 900
            if N > 9999:
                if N > 99999:
                    ans += 90000
                else:
                  ans += N-9999
            else:
              pass   
        else:
          ans += N-99
    else:
      pass
else:
    ans += N
print(ans)

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

using namespace std;

//#define FILE_IO

int N, M, l, c;
int a[1005][1005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &M);
    scanf("%d%d", &l, &c);

    if(l == 1 && c == 1)
    {
        printf("No\n");
        return 0;
    }


    int val1 = (int(1e9) - 1) / (l * c - 1);
    int val2 = -( (l * c - 1) * val1 + 1 );

    for(int i = 1; i <= N; i += l)
        for(int j = 1; j <= M; j += c)
        {
            for(int x = 0; x < l; x++)
                for(int y = 0; y < c; y++)
                    a[i + x][j + y] = val1;
            a[i + l - 1][j + c - 1] = val2;
        }

    long long S = 0;
    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= M; j++)
            S += a[i][j];

    if(S <= 0)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
        for(int i = 1; i <= N; i++, printf("\n"))
            for(int j = 1; j <= M; j++)
                printf("%d ", a[i][j]);
    }

    return 0;
}


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

int main() {
    ll x;
    cin >> x;
    ll ans = 2*(x/11);
    x%=11;
    if(x >= 1 && x <= 6) ans++;
    else if(x > 6) ans+=2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define pii pair<int, int>

const int MAXN = 200009;
vector<int> g[MAXN];
int n;
bool used[MAXN];

pii bfs(int v)
{
    pii ans;
    queue<pii> q;
    q.emplace(v, 0);
    for (int i = 0; i < n; i++)
        used[i] = false;
    used[v] = true;
    while (!q.empty())
    {
        pii cur = q.front();
        q.pop();
        ans = cur;
        for (int to : g[cur.ff])
        {
            if (!used[to])
            {
                q.emplace(to, cur.ss + 1);
                used[to] = true;
            }
        }
    }
    return ans;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    pii cur = bfs(0);
    cur = bfs(cur.ff);
    if (cur.ss % 3 == 1)
        cout << "Second";
    else
        cout << "First";
}


Measured memory_bytes: 16288
import sys
sys.setrecursionlimit(2**20)  


class Node:
    def __init__(self, parent=None, left=None, right=None):
        self.parent = parent
        self.left = left  
        self.right = right


def pre_parse(T, u, pre_ls):
    if u == None:
        return
    pre_ls.append(u)
    pre_parse(T, T[u].left, pre_ls) 
    pre_parse(T, T[u].right, pre_ls)


def in_parse(T, u, in_ls):
    if u == None:
        return
    in_parse(T, T[u].left, in_ls)
    in_ls.append(u)
    in_parse(T, T[u].right, in_ls)


def insert(T, ROOT, z):
    if ROOT == z:
        T[z] = Node()
    else:
        T[z] = Node()  
        x = ROOT
        while x is not None:  
            next_parent = x  
            if z < x:  
                x = T[x].left
            else:
                x = T[x].right
        T[z].parent = next_parent
        if z < next_parent:
            T[next_parent].left = z
        else:
            T[next_parent].right = z


def find(T, ROOT, k):
    x = ROOT
    while x and k != x:
        if k < x:
            x = T[x].left
        else:
            x = T[x].right
    return x

def print_result(T):
    pre_ls, in_ls = [], []
    in_parse(T, ROOT, in_ls)
    pre_parse(T, ROOT, pre_ls)
    print('', *in_ls)
    print('', *pre_ls)


n = int(input())
T = {}
for i in range(n):
    tmp = input()
    if i == 0:
        ROOT = int(tmp[7:])
    if tmp[0] == "p":
        print_result(T)
    elif tmp[0] == "f":
        if find(T, ROOT, int(tmp[5:])):
            print("yes")
        else:
            print("no")
    else:
        insert(T, ROOT, int(tmp[7:]))


Measured memory_bytes: 118092
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
typedef long long int llint;

int main(void){
  std::string s;
  int n;
  std::cin >> n >> s;

  int count = 0;
  for(int i=0; i<n-2; i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      count++;
    }
  }
  std::cout << count << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
p = int(1e9+7)
def modpow(a, n, p):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % p
        a = a * a % p
        n >>= 1
    return res

n, a, b = map(int, input().split())
h = max(a, b)
l = min(a, b)

x = n
y = 1
c_low = x*modpow(y, p-2, p) % p
for i in range(1, h):
    x = x*(n-i) % p
    y = y*(i+1) % p
    if i+1 == l:
        c_low = x*modpow(y, p-2, p) % p
c_high = x*modpow(y, p-2, p) % p

print((modpow(2, n, p) -1 -c_low - c_high) % p)


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

using namespace std;

int n,i,j;
double S,a[3010],b[3010],d[3010][3010][2];

int main()
{
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
        b[i]=1-a[i];
    }

    d[1][1][1]=a[1];
    d[1][0][2]=b[1];

    for(i=2; i<=n; i++)
    {
        d[i][0][1]=0;
        d[i][0][2]=d[i-1][0][2]*b[i];
    }

    for(i=2; i<=n; i++)
    {
        for(j=i; j>=1; j--)
        {
            d[i][j][2]+=(d[i-1][j][1]+d[i-1][j][2])*b[i];
            d[i][j][1]+=(d[i-1][j-1][1]+d[i-1][j-1][2])*a[i];

        }
    }

    for(j=n; j>=(n+1)/2; j--)
    {
        S+=(d[n][j][1]+d[n][j][2]);
    }
    cout<<fixed<<setprecision(9)<<S<<'\n';
    return 0;
}


Measured memory_bytes: 139776
def main():
  n = int(input())
  #s = input()
  #s = input().split()
  #a,b = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  print(n*2*3.1415926535)

if __name__ == '__main__':
  main()

Measured memory_bytes: 9156
N = int(input())

P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append((x, y))

from collections import defaultdict

if N == 1:
    print(1)
    exit(0)

cnt = defaultdict(int)
for pi in range(N):
    for pj in range(N):
        if pi == pj:
            continue
        # x
        dx = P[pi][0] - P[pj][0]

        # y
        dy = P[pi][1] - P[pj][1]

        cnt[(dx, dy)] += 1

ans = N-max(cnt.values())
print(ans)



Measured memory_bytes: 74368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fun(ll b,ll n){
    return n<b ? n : fun( b , n / b ) + n % b;
}
int main(){
    ll n,s;
    scanf("%lld%lld",&n,&s);
    if( s > n ) 
        return puts( "-1" ) , 0 ;
    if( s == n ) 
        return printf("%lld\n",n+1),0;
    ll m=sqrt(n);
    for(ll i=2; i<=m; i++){
        if(fun(i,n)==s){
            printf("%lld\n",i);
            return 0;
        }
    }
    ll ans=1e11;
    ll ns=n-s;
    for(ll i=1;i*i<=ns;i++){
        if((ns)%i==0){
            ll b=(ns)/i+1;
            if(fun(b,n)==s){
                ans=min(ans,b);
            }
            if(fun(i+1,n)==s){
                ans=min(ans,b);
            }
        }
    }
    printf("%lld\n",ans!=1e11?ans:-1);
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

P = [0] * M
Y = [0] * M
dic = {}
ano_dic = {}
for m in range(M):
    line = list(map(int, input().split()))
    P[m] = line[0]
    Y[m] = line[1]
    
    dic[m] =[P[m], Y[m]]


ID = {}
count = 0
sorted_list = sorted(dic.items(), key=lambda x: (x[1][0], x[1][1]))



for i, item in enumerate(sorted_list):
    if item[1][0] == sorted_list[i - 1][1][0]:
        count += 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)
    else:
        count = 1
        ID[item[0]] = str(item[1][0]).zfill(6) + str(count).zfill(6)

for item in sorted(ID.items(), key=lambda x: x[0]):
    print(item[1])

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

using namespace std;

const int maxn = 110;

int n, m;
int dp[maxn][maxn];
char str[maxn][maxn];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%s", str[i] + 1);
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[1][1] = (str[1][1] == '#');
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (i > 1) dp[i][j] = min(dp[i][j], dp[i-1][j] + (str[i][j] == '#' && str[i-1][j] == '.'));
			if (j > 1) dp[i][j] = min(dp[i][j], dp[i][j-1] + (str[i][j] == '#' && str[i][j-1] == '.'));
		}
	}
	printf("%d\n", dp[n][m]);
	return 0;
}


Measured memory_bytes: 3832
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

static int solve(int u, int p, const vector<vector<int>>& conn){
	int g = 0;
	for(const auto v : conn[u]){
		if(v == p){ continue; }
		g ^= (solve(v, u, conn) + 1);
	}
	return g;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<int>> conn(n);
	for(int i = 1; i < n; ++i){
		int a, b;
		cin >> a >> b;
		--a; --b;
		conn[a].push_back(b);
		conn[b].push_back(a);
	}
	cout << (solve(0, -1, conn) == 0 ? "Bob" : "Alice") << endl;
	return 0;
}



Measured memory_bytes: 12032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[][] a=new int[s[0]][];
		if(s[1]==1){Console.WriteLine(s[0]);return;}
		int[] h=new int[s[0]];
		bool[] b=new bool[s[1]+1];
		St st=new St(1,s[1],true);
		for(int i = 0;i<s[0];i++) {
			a[i]=sc.Ia;
			st.Ud(a[i][0],1);
		}
		long ans=Math.Min(s[0],st.Get(1,s[1]).d);
		for(int k = 0;k<s[1]-1;k++) {
			int q=st.Get(1,s[1]).n;
			st.Ud(q,-st.Get(1,s[1]).d);
			b[q]=true;
			for(int i = 0;i<s[0];i++) {
				if(a[i][h[i]]==q){
					while(b[a[i][h[i]]]){h[i]++;}
					st.Ud(a[i][h[i]],1);
				}
			}
			ans=Math.Min(ans,st.Get(1,s[1]).d);
		}
		Console.WriteLine(ans);
	}
}
public class St{
	public class Mo{
		public int n;
		public long d;
		public Mo(long d,int n){this.d=d;this.n=n;}
	}
	public Mo[] dat;
	private int m=1,f;
	private bool mm;
	private Mo du;
	private Func<Mo,Mo,bool> compare;
	public St(int f,int n,bool mm){
		this.f=f;
		n+=f^1;
		this.mm=mm;
		if(mm){du=new Mo(long.MinValue,-1);compare=CoMax;}
		else{du=new Mo(long.MaxValue,-1);compare=CoMin;}
		while(m<n){m*=2;}
		dat=new Mo[m+n];
		for(int i=0;i<m+n;i++){dat[i]=du;}
	}
	private bool CoMax(Mo x,Mo y){return x.d>y.d;}
	private bool CoMin(Mo x,Mo y){return x.d<y.d;}
	public void Ud(int q,long b){
		q+=m-1-f;
		if(dat[q]==du){
			int z=q;
			dat[q]=new Mo(b,q-(m-1-f));
			while(q>0&&compare(dat[z],dat[(q-1)/2])){
				dat[(q-1)/2]=dat[z];
				q=(q-1)/2;
			}
		}
		else{
			b+=dat[q].d;
			dat[q].d=du.d;
			dat[q]=new Mo(b,q-(m-1-f));
			q=(q-1)/2;
			while(q>=0){
				Mo o=compare(dat[2*q+1],dat[2*q+2])?dat[2*q+1]:dat[2*q+2];
				if(dat[q]==o){break;}
				dat[q]=o;
				q=(q-1)/2;
			}
		}
	}
	private Mo Fdg(int a,int b,int k,int l,int r){
		if(r<a||b<l){return du;}
		if(a<=l&&r<=b){return dat[k];}
		Mo p=Fdg(a,b,k*2+1,l,(l+r)/2);
		Mo q=Fdg(a,b,k*2+2,(l+r+1)/2,r);
		return compare(p,q)?p:q;
	}
	public Mo Get(int a,int b){return Fdg(a,b,0,f,m-(f^1));}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll((Console.ReadLine()+" 0").Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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;
}

template<class T>
void DEBUG_DP(T* viewdp, int ilen, int jlen){
    REP(i,ilen){
        REP(j,jlen){
            if(viewdp[i][j] != -1)
                printf("[% 4d]", viewdp[i][j]);
            else
                printf("[    ]");
        }
        puts("");
    }
}

constexpr int MX = 3000+5;
int dp[MX][MX];
int main() {
    //ios::sync_with_stdio(false); cin.tie(0);
    string s,t;
    cin>>s>>t;
    s += '$';
    t += '#';

   int ss=s.size();
   int ts=t.size();
    REP(i,ss) REP(j,ts){
        chmax(dp[i+1][j], dp[i][j]);
        chmax(dp[i][j+1], dp[i][j]);

        if(s[i]==t[j])
            chmax(dp[i+1][j+1], dp[i][j]+1);
    }

    //DEBUG_DP(dp, ss+1, ts+1);

    string ans = "";
    {
        int i = ss-1;
        int j = ts-1;

        while(i && j){
            int now = dp[i][j];
            if(i && dp[i-1][j]==now){
                i--;
            }else if(j && dp[i][j-1]==now){
                j--;
            }else{
                i--;
                j--;
                ans = s[i]+ans;
            }
        }
    }

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

Measured memory_bytes: 35456
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int n = sc.nextInt();
        long soukei = 0;
      	int amae = 0;

      	for(int i = 0 ; i < n ; i++){
        	int a = sc.nextInt();
        	if(a < amae){
            	soukei = soukei + (amae-a);
            }else{
            	amae = a;
            }
        	
        }

		System.out.println(soukei);

		
	}
}

Measured memory_bytes: 58700