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

int main(void){
  string str;
  cin >> str;
  char next[] = {'A', 'Z'};
  int next_ind = 0;
  for(int i=0; i < str.length(); i++){
    if(str[i] != next[next_ind]){
      str.erase(str.begin() + i);
      i--;
    }else{
      next_ind = (next_ind + 1) % 2;
    }
  }

  for(int i=str.length()-1; i >= 0; i--){
    if(str[i] == 'A'){
      str.erase(str.begin()+i);
    }else{
      break;
    }
  }

  if(!str.empty() || str[str.length()-1] == 'Z')
    cout << str << endl;
  else
    cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 1196
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#define inf 0x3f3f3f
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef double db;
const int mod = 1e9;
const int maxn = 1e5+5;
int n,m,vis[maxn],h[maxn],a,b;
int main(){
	cin >> n >> m;
	for(int i = 1;i <= n;i++)	cin >> h[i];
	int ans = 0;
	for(int i = 1;i <= m;i++){
		cin >> a >> b;
		vis[a] = max(vis[a],h[b]);
		vis[b] = max(vis[b],h[a]);
	}
	for(int i = 1;i <= n;i++){
		if(!vis[i])
			ans++;
		else if(h[i] > vis[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3940
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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

  if(N < 10) { // 1
	total = N;
  } else if(N < 100) { // 2
	total = 9;
  } else if(N < 1000) { // 3
	total = 9 + N - 100 + 1;
  } else if(N < 10000) { // 4
	total = 9 + 900;
  } else if(N < 100000) { // 5
	total = 9 + 900 + N - 10000 + 1;
  } else if(N < 1000000) { // 6
	total = 9 + 900 + 90000;
  } else abort();
  cout << total;
}


Measured memory_bytes: 888
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int i,coin=0;
  for(i=0;i<2;i++){
    if(a<b){
      coin=coin+b;
      b=b-1;
    }else{
      coin=coin+a;
      a=a-1;
    }
  }
  printf("%d",coin);
  return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 




int main() {
int a, b;
cin >> a >> b;
int ans = a + b;
if(ans >= 10) print("error");
else print(ans);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    lint a;
    int b1, b2;
    scanf("%lld %d.%d", &a, &b1, &b2);
    b1 *= 100;
    b1 += b2;
    a *= b1;
    a /= 100;
    cout << a << endl;
    return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;

  vector<int> h(n);
  for (auto&& e : h) {
    cin >> e;
  }

  vector<bool> f(n, true);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    if (h[a] <= h[b]) {
      f[a] = false;
    }
    if (h[b] <= h[a]) {
      f[b] = false;
    }
  }

  int ans = count_if(begin(f), end(f), [](int x){return x;});
  cout << ans << endl;
}


Measured memory_bytes: 3800
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long LL;
const int INF=2e9+1e8;

const int MOD=1e9+7;
const double eps=0.0000000001;
void fre()
{
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
}
#define MSET(a,b) memset(a,b,sizeof(a))

const int maxn=1e6+10;

LL a[maxn],sum[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	LL ans=1e18;
	for(int i=1;i<=n;i++)
	{
	    scanf("%lld",&a[i]);
	}
	sum[0]=0;
	for(int i=1;i<=n;i++)
		sum[i]=a[i]+sum[i-1];
	for(int i=2;i<=n;i++)
	{
	    LL t=abs(sum[n]-sum[i-1]-(sum[i-1]));
		ans=min(ans,t);
	}
	printf("%lld\n",ans);
    return 0;
}

/**************************************************/
/**             Copyright Notice                 **/
/**  writer: wurong                              **/
/**  school: nyist                               **/
/**  blog  : http://blog.csdn.net/wr_technology  **/
/**************************************************/


Measured memory_bytes: 5888
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
int main()
{
	int a,b;
	scanf("%i%i",&a,&b);
	if(a>9 || b>9)
	{
		printf("-1");
	}
	else if(a==0 || b==0)
	{
		printf("-1");
	}
	else
	{
		printf("%i",a*b);
	}
	return 0;
}


Measured memory_bytes: 128
<?php
  $pageList = [];
  while(($line = trim(fgets(STDIN))) !== ''){
    sscanf($line,"%s %d",$word,$page);
    if(!isset($pageList[$word])){
      $pageList[$word] = [];
    }
    $pageList[$word][] = $page;
  }

  ksort($pageList);

  foreach($pageList as $word => $vals){
    echo $word . "\n";
    sort($vals);
    echo implode(' ',$vals) . "\n";
  }

Measured memory_bytes: 15388
import fractions
from functools import reduce


n, m = map(int, input().split())
A = list(set(map(int, input().split())))

hA = [a//2 for a in A]
lcm = 1
for a in hA:
    lcm = (lcm * a) // fractions.gcd(lcm, a)
    if lcm > m:
        print(0)
        break
else:
    for a in A:
        if lcm % a == 0:
            print(0)
            break
    else:
        if (m//lcm) % 2 == 0:
            print(m//lcm//2)
        else:
            print(m//lcm//2 + 1)


Measured memory_bytes: 21732
#include <bits/stdc++.h>
using namespace std;
#define int long long 
signed main() {
    int N;
    cin >> N;
    int ans = N-1;
    for(int i = 1; i*i <= N; i++) {
        if(N%i == 0) {
            ans = min(ans,(N/i)+i-2);
        }
     }
    cout << ans << endl; 
}



Measured memory_bytes: 256
//C - Boxes and Candies: 25Min;
//Assunto: AdHoc;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, x, aux;
    ll ans1 = 0, ans2 = 0, ans;
    cin >> n >> x;
    vector<int> caixas(n), caixas2(n);
    loop(i, 0, n) {
        cin >> caixas[i];
        caixas2[i] = caixas[i];
    }
    loop(i, 0, n-1) {
        aux = (caixas[i] + caixas[i+1]) - x;
        if(aux < 0) aux = 0;
        ans1 += aux;
        caixas[i+1] -= aux;
        if(caixas[i+1] < 0) caixas[i+1] = 0;
        //cout << aux << "\n";
    }
    loop(i, 1, n) {
        aux = (caixas2[i] + caixas2[i-1]) - x;
        if(aux < 0) aux = 0;
        ans2 += aux;
        caixas2[i] -= aux;
        if(caixas2[i] < 0) caixas2[i] = 0;
    }
    ans = min(ans1, ans2);
    cout << ans1 << "\n";
}
    

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.stream.Stream;

public class Main {
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        func();
        pw.flush();
        return;
    }

    static void func() throws IOException {
        int[] input = arrayOfInt();
        int n = input[0];
        int m = input[1];

//        int HALF = (int)Math.floor(m/2);
//        int DIVIDE = (int)Math.floor(m/n);
//        int MAX = Math.min(HALF,DIVIDE);
        int MAX = (int)Math.floor(m/n);
        long ans = 1;
        for(int i = MAX;1 < i;i--){
            if (m%i == 0){
                ans = i;
                break;
            }
        }
        println(ans);
    }
    // 入力受け取り
    static String next() throws IOException {return br.readLine();}
    static int nextInt() throws IOException{return getInt(br.readLine());}
    static long nextLong() throws IOException{return getLong(br.readLine());}
    static String[] arrayOfString() throws IOException{return br.readLine().split(" ");}
    static int[] arrayOfInt() throws IOException{return toIntArray(arrayOfString());}
    // 変換
    static long getLong(String val) {return Long.parseLong(val);}
    static int getInt(String val) {return Integer.parseInt(val);}
    static int[] toIntArray(String[] array) {return Stream.of(array.clone()).mapToInt(Integer::parseInt).toArray();}
    static String joinToString(String[] array) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < array.length;i++) sb.append(array[i]);
        return sb.toString();
    }

    // 出力
    static void println(Object val){pw.println(val);}
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const int MAX = 51;
const ld EPS = 1e-13;

inline ld dist(ld x1, ld y1, ld x2, ld y2) {
    ld dx = x1 - x2, dy = y1 - y2;
    return powl(dx*dx+dy*dy, 0.5);
}

int N;

int X[MAX], Y[MAX];

ld get_r(ld x, ld y) {
    ld r = 0;
    REP (i, N) CHMAX(r, dist(x, y, X[i], Y[i]));
    return r;
}

ld sub(ld x) {
    ld up = 1000, bottom = 0;
    while (up - bottom > EPS) {
        ld y1 = (2*bottom + up) / 3;
        ld y2 = (bottom + 2*up) / 3;
        if (get_r(x, y1) > get_r(x, y2)) bottom = y1;
        else up = y2;
    }
    return get_r(x, up);
}

ld solve() {
    if (N == 2) return dist(X[0], Y[0], X[1], Y[1]) / 2;

    ld left = 0, right = 1000;
    while (right - left > EPS) {
        ld x1 = (2*left + right) / 3;
        ld x2 = (left + 2*right) / 3;

        if (sub(x1) > sub(x2)) left = x1;
        else right = x2;
    }

    return sub(left);
}

int main() {
    cin >> N;
    REP (i, N) cin >> X[i] >> Y[i];
    cout << setprecision(15) << solve() << endl;
}

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

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-8;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    int n;
    cin >> n;
    set <pair <ll, ll> > lt, rt;
    vector <ll> al(n, 0), ar(n, 0);
    for (int i = 0; i < n; i++) {
        ll l, r;
        cin >> l >> r;
        al[i] = l, ar[i] = r;
        lt.insert({l, i});
        rt.insert({r, i});
    }
    ll sum = 0;
    ll pos = 0;
    while (lt.size()) {
        ll x = lt.rbegin()->first;
        if (pos < x) {
            //cout << pos << " " << x << "\n";
            sum += x - pos;
            pos = x;
            ll y = lt.rbegin()->second;
            lt.erase({al[y], y});
            rt.erase({ar[y], y});
            continue;
        }
        x = rt.begin()->first;
        if (pos > x) {
            //cout << pos << " " << x << "\n";
            sum += pos - x;
            pos = x;
            ll y = rt.begin()->second;
            lt.erase({al[y], y});
            rt.erase({ar[y], y});
            continue;
        }
        break;
    }
    sum += abs(pos);
    ll res1 = sum;
    sum = 0, pos = 0;
    lt.clear(), rt.clear();
    for (int i = 0; i < n; i++) {
        lt.insert({al[i], i});
        rt.insert({ar[i], i});
    }
    while (lt.size()) {
        ll x = rt.begin()->first;
        if (pos > x) {
            //cout << pos << " " << x << "\n";
            sum += pos - x;
            pos = x;
            ll y = rt.begin()->second;
            lt.erase({al[y], y});
            rt.erase({ar[y], y});
            continue;
        }
        x = lt.rbegin()->first;
        if (pos < x) {
            //cout << pos << " " << x << "\n";
            sum += x - pos;
            pos = x;
            ll y = lt.rbegin()->second;
            lt.erase({al[y], y});
            rt.erase({ar[y], y});
            continue;
        }
        break;
    }
    sum += abs(pos);
    cout << max(res1, sum);
}


Measured memory_bytes: 14464
class UnionFind:
    def __init__(self, n):
        self.parent = [ -1 for _ in range(n) ]
        self._size = n

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            if self.parent[y] < self.parent[x]:
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x
            self._size -= 1

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

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

    def size(self, x):
        return -self.parent[self.root(x)]


n, m = map(int, input().split())
ab = [ map(int, input().split()) for _ in range(m) ]

ans = []
inconv = n * (n-1) // 2
uf_tree = UnionFind(n)

for a, b in ab[::-1]:
    a -= 1; b -= 1;
    ans.append(inconv)
    if not uf_tree.same(a, b):
        x = uf_tree.size(a)
        y = uf_tree.size(b)
        uf_tree.unite(a, b)
        inconv -= x*y

print(*ans[::-1], sep="\n")

Measured memory_bytes: 50908
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int a;
    cin >> a;
    int ans;
    ans = 1000 - a % 1000;


    if (ans == 1000)cout << 0;
    else {
        cout << ans;
    }




    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define Nmax 51
#define ll long long

using namespace std;

const long long INF=1e18l+2;
const ll MOD = 1e9+7;

ifstream f("1.in");

ll a[Nmax][Nmax];
ll r[Nmax][Nmax];
ll r_[Nmax][Nmax];
ll n, k;

void mult(ll a[Nmax][Nmax], ll b[Nmax][Nmax])
{
    ll c[Nmax][Nmax]={0};
    for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                {
                    for (int k = 1; k <= n; k++)
                        (c[i][j] += a[i][k]*b[k][j]) %= MOD;

                }
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                     a[i][j] = c[i][j];
}

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        r[i][i]=1;
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    }

    while(k)
    {
        if(k&1)
        {
           /* for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                {
                    r_[i][j]=0;
                    for (int k = 1; k <= n; k++)
                        (r_[i][j] += r[i][k]*a[k][j]) %= MOD;

                }
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                     r[i][j] = r_[i][j];*/
            mult(r, a);
        }

        /*for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
            {
                r_[i][j]=0;
                for (int k = 1; k <= n; k++)
                 (r_[i][j] += a[i][k]*a[k][j]) %= MOD;

            }
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                a[i][j]=r_[i][j];*/
        mult(a, a);

        k >>= 1;
    }

    ll s=0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
            s=(s+r[i][j])%MOD;
    }
    cout << s;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
  int n,i,j;
  int a[10000];
  int count=0;
  
  scanf("%d",&n);

  for(i=0; i<n; i++)
    scanf("%d",&a[i]);

  count=n;

  for(i=0; i<n; i++){

    if(a[i]==2);
    
    else if(a[i]%2==0)
      count--;
    
    else{
      for(j=3; j<=(int)sqrt(a[i]); j+=2){
	if(a[i]%j==0){
	  count--;
	  break;
	}
      } 
    }
  }
  printf("%d\n",count);
  
  return 0;
}
    



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

int main(){
	string s;
	cin >> s;
	int count = 0;
	rep(i, s.size()-1){
		count += s[i] != s[i+1];
	}
	cout << count << endl;
	return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VI a;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  a.resize(n);
  forn(i,n)
    cin>>a[i];
  sort(all(a));
  in mxbg=0;
  in sm=0;
  forn(i,n-1){
    sm+=a[i];
    if(sm*2<a[i+1])
      mxbg=i+1;
  }
  cout<<n-mxbg<<endl;
  return 0;
}


Measured memory_bytes: 1024
x = int(input())
OP = [+1, -1]
for a in range(1000):
    for b in range(a + 1):
        for op1 in OP:
            for op2 in OP:
                if (op1 * a)**5 - (op2 * b)**5 == x:
                    print(op1 * a, op2 * b)
                    exit()

Measured memory_bytes: 9180
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)

class SegmentTree():
    def __init__(self,param,default,func):
        if isinstance(param,list):
            n=len(param)
        else:
            n=param
        self.d=default
        self.leaf=1<<(n-1).bit_length()
        if isinstance(param,list):
            self.tree=[default]*(self.leaf-1)+param+[default]*(self.leaf-n)
            for i in range(self.leaf-2,-1,-1):
                self.tree[i]=func(self.tree[i*2+1],self.tree[i*2+2])
        else:
            self.tree=[default]*(self.leaf*2-1)
        self.f=func
    def find(self,i):
        return self.A[i+self.leaf-1]
    def update(self,idx,a):
        idx+=self.leaf-1
        self.tree[idx]=a
        while idx:
            idx=(idx-1)>>1
            self.tree[idx]=self.merge(self.tree[idx*2+1],self.tree[idx*2+2])
    def merge(self,a,b):
        return self.f(a,b)
    def get_top(self):
        return self.tree[0]
    def query(self,a,b):
        T=self.tree
        l,r=a+self.leaf-1,b+self.leaf-1
        res=self.d
        while l<r:
            if not l%2:
                res=self.merge(res,T[l])
                l+=1
            if not r%2:
                r-=1
                res=self.merge(res,T[r])
            l>>=1
            r>>=1
        return res

def f(a,b):
    return max(a,b)

n=int(input())
H=list(map(int,input().split()))
A=list(map(int,input().split()))
seg=SegmentTree(n+1,0,f)
for h,a in zip(H,A):
    t=seg.query(0,h)
    seg.update(h,a+t)
print(seg.get_top())

Measured memory_bytes: 114044
#include <stdio.h>
#include <stdlib.h>
int main(){
  int *k = malloc(sizeof(int)), *s = malloc(sizeof(int));
  int resp = 0;
  scanf("%d%d", k, s);
  for(int x = 0;x <= *k;++x){
    for(int y = 0; y <= *k;++y){
      int z = (*s)-x-y;
      if (*k >= z && z >= 0) ++resp;
    }
  }
  printf("%d\n",resp);
  free(k);
  free(s);
}

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

typedef long long ll;

int K, N;
ll F[100010] = {1};
ll R[100010];
ll mod = 1000000007;

ll pow_mod(ll a, ll b)
{
    if(b == 0)return 1;
    ll ret = pow_mod(a * a % mod, b >> 1);
    if(b & 1)ret = ret * a % mod;
    return ret;
}

ll con(int a,int b)
{
    if(a < b || a < 0 || b < 0)return 0;
    return F[a] * R[b] % mod * R[a - b] % mod;
}

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

    for(int i = 1; i < 100010; i++)F[i] = F[i - 1] * i % mod;
    for(int i = 0; i < 100010; i++)R[i] = pow_mod(F[i], mod - 2);

    for(int i = 1; i <= K; i++)
    {
        ll ans = con(N - K + 1, i);
        ans = ans * con(i + K - i - 1, K - i) % mod;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

Num_str = list(input().rstrip())
L = len(Num_str)
Num = []

for n in reversed(Num_str):
    Num.append(int(n))

S = 0
up = False
for i, n in enumerate(Num):
    if up:
        n += 1
    if n < 5:
        S += n
        up = False
    elif n == 5:
        S += 5
        up = (i != L-1 and Num[i+1] >= 5)
    else:
        S += 10 - n
        up = True
if up:
    S += 1
print(S)

Measured memory_bytes: 21100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 100003;

string s,ss3,ss2;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>s;
	if(s.size()==2){
		if(s[0]==s[1])cout<<1<<" "<<2<<endl;
		else cout<<-1<<" "<<-1<<endl;
		return 0;
	}
	FOR(i,0,s.size()-2){
		ss3=s.substr(i,3);
		ss2=s.substr(i,3);
		if(ss3[0]==ss3[2]){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
		if(ss2[0]==ss2[1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
	}
	cout<<-1<<" "<<-1<<endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	ll ans = LONG_LONG_MAX;
	rep(i, s.size()-2){
		ll sum=0;
		sum += 100*(ll)(s[i]-'0');
		sum += 10*(ll)(s[i+1]-'0');
		sum += (ll)(s[i+2]-'0');
		ans = min(ans, (ll)abs(753-sum));
	}
	cout << ans << "\n";
	return 0;
}

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

int main(void){
    int N, Abuf;
    cin >> N;
    bool approvable = true;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        if(Abuf%2==0){
            if((Abuf%3!=0)&&(Abuf%5!=0)){
                approvable = false;
            }
        }
    }
    if(approvable){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
#include<stack>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
typedef long long LL;

const LL INF = 1LL << 60;
const int maxn = 2e5 + 5;
LL a[maxn];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%lld",&a[i]);
		a[i] -= (LL) i;
	}
	sort(a + 1,a + 1 + n);
	LL sum = 0,x = a[(n + 1) / 2];
	for(int i = 1;i <= n;i++){
		a[i] = abs(a[i] - x);
		sum += a[i];
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int m;
	string s;
	cin >> m >> s;
	for(int i = 0; i < s.size(); i++){
		s[i] = ((s[i]-'A'+m) % 26) + 'A';
	}
	cout << s;

	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
ll n,m,j,k,t,l,r;
ll a,b,c,d;
char A,B,C,X,Y,Z;
float ans,MAX,MIN,num,sum;
ll ax[200050],bx[200050],th[200050];

int main()
{
    ll i,s,x;
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
    	memset(bx,0,sizeof(bx));
    	memset(th,-1,sizeof(th));
    	scanf("%lld%lld",&n,&k);
    	for(i=1;i<=n;i++)
		   scanf("%lld",&ax[i]);
    	l=1;
    	num=0;
	for(i=1;i<=n;i++)
	{
		bx[i]=ax[l];
		l=ax[l];
		if(th[l]!=-1)
		{
			num=i;
			break;
		}
		th[l]=i;	
	}
if(k<=num) printf("%lld",bx[k]);
	else
	{
		r=num-th[l];
		k-=th[l];
		k%=r;
		printf("%lld",bx[k+th[l]]);
	}
	}
	return 0;
}

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

#undef false
#undef true

using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;

/* [💭] [💡] [🎈] */

int a[100];

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    memset(a, -1, sizeof a);

    int n, m;
    cin >> n >> m;

    bool flag = true;
    for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        if (a[s] != c && a[s] != -1) flag = false;
        a[s] = c;
    }

    if (flag && n == 1) {
        if (a[0] == -1) {
            cout << 0;
        } else {
            cout << a[0];
        }
        return 0;
    }

    if (a[0] == -1) a[0] = 1;
    
    for (int i = 0; i < n; i++) {
        if (a[i] != -1) continue;
        a[i] = 0;
    }

    if (flag && a[0]) {
        for (int i = 0; i < n; i++) {
            cout << (a[i] == -1 ? 0 : a[i]);
        }
    } else {
        cout << -1;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};
const long long INF = 1LL << 60;

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

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> h(n),a(m),b(m);
    rep(i,n) cin >> h[i];
    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    vector<bool> yoi(n,true);
    rep(i,m){
        if(h[a[i]] <= h[b[i]]) yoi[a[i]] = false;
        if(h[b[i]] <= h[a[i]]) yoi[b[i]] = false;
    }
    ll ans = 0;
    rep(i,n){
        if(yoi[i]) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

void Main() {
    int N;
    cin >> N;
    vector<long long> A(N, 0LL);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<long long>());

    long long ans = 0;
    int indexToAdd = 0;
    for (int i = 1; i < N; ++i) {
        if (i == 1) {
            ans += A[0];
            ++indexToAdd;
            continue;
        }
        if (i % 2 == 0) {
            ans += A[indexToAdd];
        }
        else {
            ans += A[indexToAdd];
            ++indexToAdd;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

// a^b
ll mypow(ll a, ll b) {
    if (b == 0) return 1;
    ll tmp = mypow(a, b / 2);
    if (b % 2) return (((tmp*tmp) % MOD)*a) % MOD;
    else return (tmp*tmp) % MOD;
}

// nCk
ll comb(ll n, ll k) {
    ll res = 1;
    k = min(n - k, k);
    for (ll i = n - k + 1; i <= n; i++) res = (res*i) % MOD;
    for (ll i = 1; i <= k; i++)res = (res*mypow(i, MOD - 2)) % MOD;
    return res;
}

// nHk = n+k-1 C k
ll H(ll n, ll k) {
    return comb(n + k - 1, k);
}

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

    ll n,m;cin>>n>>m;
    ll res=1,num=m;
    map<ll,ll> mp;
    for(ll i=2;i*i<=m;i++){
        if(num%i!=0) continue;
        while(num%i==0){
            mp[i]++;
            num /= i;
        }
    }
    if(num!=1) mp[num]++;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ll key=(*itr).first,val=(*itr).second;
        res *= H(n,val);
        res %= MOD;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N;
  vector<string> S(N);
  vector<string> T(M);
  int total;
  int max_total=0;
  for (int i=0; i<N; i++){
    cin >> S.at(i);
  }
  cin >> M;
  for (int i=0; i<M; i++){
    cin >> T.at(i);
  }
  string word;
  for (int i = 0; i < N; i++){
    total = 0;
    word = S.at(i);
    for (int k=0; k<N; k++){
      if (word == S.at(k)){
        total += 1;
      }
    }
    for (int j=0; j<M; j++){
      if (word == T.at(j)){
        total -= 1;
      }
    }
    if (total > max_total){
      max_total = total;
    }
  }
  cout << max_total;
}

Measured memory_bytes: 512
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var a = new int[3].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
		var b = new int[int.Parse(Console.ReadLine())].Select(_ => int.Parse(Console.ReadLine())).ToHashSet();

		var r3 = new[] { 0, 1, 2 };
		Console.WriteLine(a.Any(ai => ai.All(b.Contains)) || r3.Any(j => r3.All(i => b.Contains(a[i][j]))) || r3.All(i => b.Contains(a[i][i])) || r3.All(i => b.Contains(a[i][2 - i])) ? "Yes" : "No");
	}
}


Measured memory_bytes: 28408
import java.io.IOException;
import java.util.StringTokenizer;

class Main {

	public static void main(String[] args) throws IOException{
		java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
		try{
			int count =Integer.parseInt(in.readLine());
			String ans [] = new String [count];
			for(int i=0;i<count;i++){
				String s = in.readLine();
				StringTokenizer st = new StringTokenizer(s);
				int num [] = new int [4];
				for(int j=0;j<3;j++){
					num[j] = Integer.parseInt(st.nextToken());
					if(num[0] < num[j]){
						int tmp = num[0];
						num[0] = num[j];
						num[j] = tmp;
					}
				}
				if (num[0] * num[0] == num[1] * num[1] + num[2] * num[2]){
					ans[i] = "YES";
				}else{
					ans[i] = "NO";
				}
			}
			for(int i=0;i<count;i++){
				System.out.println(ans[i]);
			}
		}catch(Exception e){
			System.exit(0);
		}
	}

}

Measured memory_bytes: 18468
import java.util.*;
public class Main{

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        List<Integer> list = new ArrayList<>(3);
        while(sc.hasNext()){
            list.add(Integer.parseInt(sc.next()));
        }
        
        Collections.sort(list);
        
        StringBuilder sb = new StringBuilder();
        for(Integer i: list){
            sb.append(i);
            sb.append(" ");
        }
        
        sb.deleteCharAt(sb.length()-1);
        
        System.out.println(sb);

    }

}



Measured memory_bytes: 26144
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m, s=0;
    
    cin >> n;
    m = n;
    
    s += m % 10;
    while(m /= 10) s += m % 10;
    
    if (n % s) cout << "No" << "\n";
    else cout << "Yes" << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int a,b;
	cin>>a>>b;
	if(a%b==0) cout<<a/b<<endl;
	else cout<<a/b+1<<endl;
    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 long long int ll;
typedef pair<int, int> P;
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; }

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	rep(i,n){
		cin >> p[i];
		p[i]--;
	}
	union_find uf(n);
	rep(i,m){
		int x, y;
		cin >> x >> y;
		x--; y--;
		uf.unite(x, y);
	}
	int ans = 0;
	rep(i,n){
		if(uf.same(i, p[i])) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
def solve(info):
    have = 0
    for m, w in info:
        have += w
        if m < have:
            return "No"
    return "Yes"

while True:
    shima_count = input()
    if shima_count == 0: break
    info = []
    for i in range(shima_count):
        lu, w = map(int, raw_input().split())
        info.append((w, lu))
    info.sort()
    print solve(info)

Measured memory_bytes: 4216
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define MAX 55
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int n;
long long C[MAX][MAX],f[MAX][MAX];
long long mo(long long x)
{
	return x<mod?x:x-mod; 
}
int main()
{
	n=read();
	C[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=mo(C[i-1][j]+C[i-1][j-1]);
	}
	f[1][0]=f[1][1]=n;
	for(int i=1;i<n;i++)
		for(int j=0;j<=i;j++)
			for(int k=j;k<=n-i;k++)
			{
				if(!k||(k-j)&1) continue;
				int y=(k-j)/2;
				for(int x=0;x<=k;x++)
					f[i+k][abs(y-x)]=(f[i+k][abs(y-x)]+f[i][j]*C[n-i][k]%mod*C[k][x])%mod;
			}
	printf("%lld",f[n][0]);
	return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int a, b;
  cin >> a >> b;

  if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  string s; cin >> s;
  set<char> S;
  rep(i,s.size()){
    if (S.count(s[i])==true) {
      cout << "no" << endl;
      return 0;
    }
    else S.insert(s[i]);
  }
  cout << "yes" << endl;
  
  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int C[20];

int main(){
  int N,temp,ans=0;
  cin>>N;
  for(int i=1;i<=N;i++){
    cin>>temp;
    if(temp==i){
      ans++; i++; cin>>temp;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
a,t,w,r = 0,0,0,0
for i in range(N):
	s = input()
	if(s == 'AC'):
		a += 1
	if(s == 'RE'):
		r += 1
	if(s == 'TLE'):
		t += 1
	if(s == 'WA'):
		w += 1
print('AC x',a)
print('WA x',w)
print('TLE x',t)
print('RE x',r)



Measured memory_bytes: 69832
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.nextString();
            int[] a = new int[4];
            for (int i = 0; i < 4; i++) {
                a[i] = s.charAt(i) - '0';
            }
            for (int i = 0; i < 8; i++) {
                int tmp = a[0];
                StringBuilder sb = new StringBuilder("" + a[0]);
                for (int j = 0; j < 3; j++) {
                    if ((i >> j & 1) == 1) {
                        tmp += a[j + 1];
                        sb.append("+" + a[j + 1]);
                    } else {
                        tmp -= a[j + 1];
                        sb.append("-" + a[j + 1]);
                    }
                }
                if (tmp == 7) {
                    sb.append("=7");
                    out.println(sb.toString());
                    return;
                }
            }
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <ios>
#include <iomanip>
#include <limits>
#include <algorithm>
#include <sstream>
#include <bitset>
#define REP(i, n) for(int i=0; i<n; i++)
#define FOR(i, s, n) for(int i=s; i<n; i++)

using namespace std;

int main(){
    int A, B;
    int ans;
    cin >> A >> B;
    ans = max({A+B, A-B, A*B});
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter

N, P = list(map(int, input().split()))
S = input()

ans = 0

if not 10 % P:
    for r in range(N):
        if not int(S[r]) % P:
            ans += r+1
else:
    S = S[::-1]
    s = 0
    d = [0] * (N+1)
    
    for i in range(N):
        s = (s + int(S[i]) * pow(10, i, P)) % P
        d[i+1] = s

    c = Counter()
    for i in range(N+1):
        ans += c[d[i]]
        c[d[i]] += 1
              
print(ans)

Measured memory_bytes: 12048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        uf.merge(a,b);
    }

    set<int> s;
    rep(i,n){
        s.insert(uf.root(i));
    }

    ll ans=s.size()-1;
    cout<<ans<<endl;
}

Measured memory_bytes: 7508
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 1000010
ll inv[N],fact[N],invfact[N];
void Pre(){
    inv[1]=fact[0]=invfact[0]=1;
    for(int i=1;i<N;i++){
	if(i>1)inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	fact[i]=fact[i-1]*i%mod;
	invfact[i]=invfact[i-1]*inv[i]%mod;
    }
}
ll C(ll n,ll k){
    if(n<0||k<0||n<k)return 0;
    return fact[n]*invfact[n-k]%mod*invfact[k]%mod;
}
int main(){
    Pre();
    ll n;cin>>n;n--;
    ll ans=0,bef=0;
    for(ll k=1;k<=n;k++){
	ll cur=C(k-1,n-k)*fact[k]%mod*fact[n-k]%mod;
	ans+=(mod+cur-bef)*k;ans%=mod,bef=cur;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 23680
ss = gets.chars.sort
ts = gets.chars.sort
su = ss.uniq
tu = ts.uniq
ans_s = []
ans_t = []
su.each do |s|
  ans_s << ss.count{|i| i == s}
end
tu.each do |t|
  ans_t << ts.count{|i| i == t}
end
puts ans_s.sort == ans_t.sort ? "Yes" : "No"


Measured memory_bytes: 27108
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;

ll N,K;
void input()
{
    cin >> N >> K;
}

void solve()
{
    ll a,b,c; 
    ll ans = 0;
    for(a = 1; a <= K; ++a){
        b = c = K - a % K;
        ll a_cnt = 0, b_cnt = 0;
        if((b+c) % K == 0){
            ll tmp_a = a;
            while(a <= N){
                a += K; ++a_cnt;
            }
            while(b <= N){
                b += K; ++b_cnt;
            }
            ans += a_cnt * b_cnt * b_cnt;
            a = tmp_a;
            // cout << a_cnt << " " << b_cnt << endl;
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
int main(void)
{
  double v;
  
  while(scanf("%lf",&v)!=EOF){
    double t=v/9.8;
	double y=4.9*t*t;
	int n=(y+10)/5.0;
	printf("%d\n",n);
  }

  return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
const int N = 2e5 + 87;
int n, c[N], lt[N], rt[N], tp, sz[N];
vector<int> g[N], g2[N];
vector<int> t[N];
void dfs(int u, int p)
{
    t[c[u]].push_back(u);
    auto it = find(g[u].begin(), g[u].end(), p);
    if (it != end(g[u]))
        g[u].erase(it);
    lt[u] = tp++;
    sz[u] = 1;
    for (int v : g[u])  {
        dfs(v, u);
        sz[u] += sz[v];
    }
    rt[u] = tp;
}
bool in (int u, int v)
{
    return lt[v] <= lt[u] && rt[u] <= rt[v];
}
void build_g2(vector<int> & a)
{
    // sort(a.begin(), a.end(), [&] (int i, int j) {return lt[i] < lt[j];});
    // already sorted!
    vector<int> st = {0};
    g2[0].clear();
    for (int u : a) {
        while (!in(u, st.back()))
            st.pop_back();
        g2[st.back()].push_back(u);
        st.push_back(u);
    }
}
ll gao(int u)
{
    ll ret = 0;
    int i = 0;
    ll s = g[u].size() ? sz[g[u][0]] : 0;
    for (int v : g2[u]) {
        while (i < g[u].size() && !in(v, g[u][i])) {
            ret += s * (s + 1) / 2;
            ++i;
            if (i < g[u].size())
                s = sz[g[u][i]];
        }
        s -= sz[v];
        ret += gao(v);
    }
    while (i < g[u].size()) {
        ret += s * (s + 1) / 2;
        ++i;
        if (i < g[u].size())
            s = sz[g[u][i]];
    }
    return ret;
}
ll solve(vector<int> & a)
{
    build_g2(a);
    return n * (n + 1ll) / 2 - gao(0);
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> c[i];
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    g[0].push_back(1);
    dfs(0, 0);
    for (int i = 1; i <= n; ++i)
        cout << solve(t[i]) << '\n';
}


Measured memory_bytes: 46464
var drawRect = function (h, w) {
    console.log(Array(h + 1).join(Array(w + 1).join('#') + '\n'));
};

var chunk = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = chunk.split('\n');

while (true) {
    var hw = lines.shift().split(' ').map(Number);
    if (hw.every(function (a) {return 0 === a;})) {
        break;
    }
    drawRect(hw[0], hw[1]);
}

Measured memory_bytes: 16564
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int n, t, a;
	cin >> n >> t >> a;
	double mn = 10000;
	int res = 0;
	rep(i, n) {
		int h;
		cin >> h;
		double tt = t - 0.006 * h;
		if (abs(a - tt) < mn) {
			mn = abs(a - tt);
			res = i+1;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(1,len(P)-1):
    p_ = [P[i-1], P[i], P[i+1]]
    if (P[i] != min(p_)) and (P[i] != max(p_)):
        count+= 1

print(count)


Measured memory_bytes: 9136