akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 1000000

void insertionSort(int [], int, int);
void shellSort(int [], int);

int cnt = 0;
int a[N];

main(){
  int n, i;

  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
  }
  shellSort(a, n);
  printf("%d\n", cnt);
  for(i = 0;i < n;i++){
    printf("%d\n", a[i]);
  }
  return 0 ;
}

void insertionSort(int a[], int n, int g){
  int i, j, key;

  for(i = g;i < n;i++){
    key = a[i];
    j = i - g;
    while(j >= 0 && a[j] > key){
      a[j+g] = a[j];
      j = j - g;
      cnt++;
    }
    a[j+g] = key;
  }
}

void shellSort(int a[], int n){
  int m = 13; 
  int g[13] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 165720, 797161};
  int i;

  cnt = 0;
  while(g[m-1] > n){
    m--;
  }
  printf("%d\n", m);
  for(i = m-1;i >= 1;i--){
    printf("%d ", g[i]);
  }
  printf("%d\n", g[0]);
  for(i = m-1;i >= 0;i--){
    insertionSort(a, n, g[i]);
  }
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> h(n);
    REP(i,n) cin >> h[i];
    int ans = 0, right = 0, cnt;
    REP(left,n) {
        cnt = 0;
        while(h[right]>=h[right+1] && right+1<n) {
            ++ right;
            ++ cnt;
        }
        chmax(ans,cnt);
        left = right-1;
        ++ right;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))
a=A[-1]
A=A[:-1]
dp=[[0]*21 for i in range(N)]
#dp[ii[j]コメまででjになる個数
dp[0][0]=1
for i in range(1,N):
    for j in range(21):
        if i==1:
            dp[i][A[i-1]]=1
        if j-A[i-1]>=0:
            dp[i][j]+=dp[i-1][j-A[i-1]]
        if j+A[i-1]<=20:
            dp[i][j]+=dp[i-1][j+A[i-1]]
print(dp[N-1][a])




Measured memory_bytes: 6032
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
#define MOD 1000000007

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll mod = pow(10, 9) + 7LL;

    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);

    for(ll i = 0; i < N; i++) cin >> A[i];

    sort(A.begin(), A.end());

    ll base = 1LL;
    ll ans = 0LL;

    for(ll i = K - 1LL; i < N; i++) {
        ans += (base * A[i]) % mod;
        ans %= mod;
        ans -= (base * A[N - 1LL - i]) % mod;
        while(ans < 0LL) ans += mod;
        ans %= mod;

        base *= i + 1LL;
        base %= mod;
        base *= modpow(i - K + 2LL, mod - 2LL, mod) % mod;
        base %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3952
sa = input()
sb = input()
sc = input()

pos_a, pos_b, pos_c = 0, 0, 0
turn = 'a'
while True:
    if turn == 'a':
        if pos_a == len(sa):
            print('A')
            break
        turn = sa[pos_a]
        pos_a += 1

    elif turn == 'b':
        if pos_b == len(sb):
            print('B')
            break
        turn = sb[pos_b]
        pos_b += 1

    else:
        if pos_c == len(sc):
            print('C')
            break
        turn = sc[pos_c]
        pos_c += 1

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

#define rep(i,n) for(int i=0;i<n;i++)
#define clear(v) memset(v,0,sizeof(v))
#define ALL(v) (v).begin(),(v).end()

int table[15][15];

void pnt1(int x, int y){
	int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };
	rep(i, 4){
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 0 && ny >= 0 && nx < 10 && ny < 10){
			table[nx][ny]++;
		}
	}
	table[x][y]++;
}

void pnt2(int x, int y){
	int dx[] = { 1, 1, -1, -1 }, dy[] = { 1, -1, 1, -1 };
	pnt1(x, y);
	rep(i, 4){
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 0 && ny >= 0 && nx < 10 && ny < 10){
			table[nx][ny]++;
		}
	}
}

void pnt3(int x, int y){
	int dx[] = { 2, 0, -2, 0 }, dy[] = { 0, 2, 0, -2 };
	pnt2(x, y);
	rep(i, 4){
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 0 && ny >= 0 && nx < 10 && ny < 10){
			table[nx][ny]++;
		}
	}
}

int main(){
	int x, y, size;
	while (scanf("%d,%d,%d",&x,&y,&size)!=EOF){
		if (size == 1) pnt1(x, y);
		else if (size == 2) pnt2(x, y);
		else pnt3(x, y);
	}
	int ans[2] = {};
	int max = 0;
	rep(i, 10) rep(j, 10) if (max < table[i][j]) max = table[i][j];
	rep(i, 10) rep(j, 10){
		if (table[i][j] == max) ans[0]++;
		if (table[i][j] == 0) ans[1]++;
	}
	printf("%d\n", ans[1]);
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main(){
  int n;
  ll h;
  cin >> n >> h;
  vector<pair<ll,ll>> katana(n);
  for(int i=0;i<n;i++){
    ll a,b;
    cin >> a >> b;
    katana[i] = make_pair(b,a);
  }

  sort(katana.begin(),katana.end());

  ll a_max = 0,itr_a_max = 0;
  for(int i=0;i<n;i++){
    if(katana[i].second > a_max){
      a_max = katana[i].second;
      itr_a_max = i;
    }
  }

  ll cnt = 0;
  int k = n-1;
  while(h > 0){
    if(k >= 0){
      if(katana[k].first > a_max){
        h -= katana[k].first;
      }else{
        h -= a_max;
      }
      k--;
      cnt++;
    }else{
      ll div = h/a_max;
      if(h%a_max != 0){
        div++;
      }
      h -= a_max*div;
      cnt += div;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdint>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>

int main() {
  char buf[262144];
  scanf("%s", buf);
  std::string s = buf;

  intmax_t res = 0;
  size_t n = s.length();
  intmax_t an = 0;
  char last = 0;
  for (size_t i = 0; i < n; ++i) {
    if (s[i] == 'A') {
      if (last != 'A') an = 0;
      ++an;
    } else if (s[i] == 'B') {
      if (last == 'A') {
        // ok
      } else {
        an = 0;
      }
    } else if (s[i] == 'C') {
      if (last == 'B') {
        if (an == 0) {
          // ok
        } else {
          s[i] = 'A';
          res += an;
        }
      } else {
        an = 0;
      }
    }
    last = s[i];
  }

  printf("%jd\n", res);
}


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

    string str;
    cin>>str;
    
    bool existC=false,headA=false,komoji=true;
    for(int i=0;i<str.size();i++){
        if(i==0&&str[i]=='A') {headA=true; continue;}
        if(i>=2&&i<str.size()-1&&str[i]=='C'&&existC==false) {existC=true; continue;}
        if(str[i]>='A'&&str[i]<'Z') komoji=false;
    }
    //cout << existC << headA<<komoji<<endl;
    if(existC&&headA&&komoji) cout<<"AC"<<endl;
    else cout <<"WA"<<endl;
}

Measured memory_bytes: 256
gets
a = gets.split.map{|x| x.to_i << 50}.sort!
i = [nil ,f = [nil, nil]]
a.each { |x|
  i = i[1]
  i[0] = x
  i[1] = [nil,nil]
}
i[1] = nil
while i = f[1]
  i[0] = x = (f[0]+i[0]) / 2
  f = i
end
p f[0] / (1<<50).to_f

Measured memory_bytes: 1788
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int a[200];
int main()
{
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]%2==1&&i%2==1) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3564
#include <stdio.h>
int main(void){
    long long int n;
    scanf("%lld", &n);

    long long int sum = 0, sumall = 0;
    for(long long int i = 1; i <= n; i++){
        if(i%3 == 0 || i%5 == 0){
            sum = sum + i;
        }
    }

    for(long long int i = 1; i <= n; i++){
        sumall = sumall + i;
    }

    sum = sumall - sum;
    printf("%lld", sum);
    return 0;
}

Measured memory_bytes: 1728
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

    def nums(self,x):
        return abs(self.parents[self.find(x)])

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

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

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i],B[i] = map(int, input().split())
ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if j!=i:
            uf.union(A[j]-1,B[j]-1)
    if len(uf.roots())>1:
        ans += 1
print(ans)

Measured memory_bytes: 40944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
int main()
{
	int k, a, b;
	cin >> k;
	cin >> a >> b;
	bool ok = false;
	for (int i = a; i <= b; ++i) {
		if (i % k == 0) {
			ok = true;
			break;
		}
	}
	if (ok)	cout << "OK" << endl;
	else {
		cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define foi(i,a,n) for(int i=a;i<n;i++)
#define el "\n"
void solve(){
 	int n;cin>>n;
  	vector<int> h(n), c(n,0);rep(i,n) cin>>h[i];
  	c[0]=0,c[1]=abs(h[1]-h[0]);
  	foi(i,2,n) c[i]=min(c[i-2]+abs(h[i-2]-h[i]),c[i-1]+abs(h[i-1]-h[i]));
  	cout<<c[n-1]<<" ";
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 4028
/**
 * C - City Savers
 * https://atcoder.jp/contests/abc135/tasks/abc135_c
 **/
#include<iostream>
using namespace std;

/**
 * i 番目の街担当の勇者の行動方針
 * i 番目の街に全力を出す
 * i 番目の街のモンスターを全て倒して余力があれば
 * i+1 番目の街で戦う
 **/

const int MAX_N = 100000;

int N;
int A[MAX_N+2];
int B[MAX_N+1];

long ans = 0;

void fight(int i, int power) {
    if (i == N+1) {
        return;
    }
    if (i == 0) {
        ans += min(A[i], B[i]);
        if (A[i] > B[i]) {
            fight(i+1, 0);
        } else {
            fight(i+1, B[i] - A[i]);
        }
    } else {
        if (A[i] <= power) {
            ans += A[i];
            fight(i+1, B[i]);
        } else {
            if (A[i] - power <= B[i]) {
                ans += A[i];
                fight(i+1, B[i] - A[i] + power);
            } else {
                ans += (B[i] + power);
                fight(i+1, 0);
            }
        }
    }
    return;
}

void solve() {
    fight(0, 0);
    cout << ans << endl;
}

int main() {
    cin >> N;
    for (int i = 0; i < N + 1; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    solve();
}

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

int n;
long a[2000];
long dp[2001][2001];

int main() {
  using PP = pair<long, long>;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<PP> v;
  for (int i = 0; i < n; ++i) {
    v.push_back(PP(a[i], i));
  }
  sort(v.begin(), v.end(), greater<PP>());
  
  for (int k = 0; k < n; ++k) {
    int pos = v[k].second;
    long val = a[pos];
    for (int i = 0; i <= k; ++i) {
      int j = k - i;
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + val * abs(pos - i));
      dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + val * abs(pos - (n - 1 - j)));
    }
  }
  
  long mx = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      mx = max(mx, dp[i][j]);
    }
  }
  
  cout << mx << endl;
}

Measured memory_bytes: 26240
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
int eval(const string& s, int& pos){
  if(s[pos]=='0'){
    ++pos;
    return 0;
  }
  if(s[pos]=='1'){
    ++pos;
    return 1;
  }
  if(s[pos]=='2'){
    ++pos;
    return 2;
  }
  if(s[pos]=='-'){
    ++pos;
    int v = eval(s,pos);
    return 2-v;
  }
  if(s[pos]=='('){
    ++pos;
    int a = eval(s,pos);
    char c = s[pos++];
    int b = eval(s,pos);
    ++pos;
    if(c == '*'){
      return (a*b+1)/2;
    }
    if(c == '+'){
      return max(a,b);
    }
    abort();
  }
}
int main(){
  string input;
  while(cin>>input){
    int ans = 0;
    if(input==".") break;
    REP(p,3)REP(q,3)REP(r,3){
      int s[3];
      s[0] = p;
      s[1] = q;
      s[2] = r;
      string calcstr = input;
      REP(i,calcstr.size()){
        if('P'<=calcstr[i]&&calcstr[i]<='R'){
          calcstr[i] = s[calcstr[i]-'P'] + '0';
        }
      }
      int pos = 0;
      if(eval(calcstr,pos)==2){
        ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = NextInt();
        int M = NextInt();
        Dictionary<int, int> c = new Dictionary<int, int>();
        for (int i = 0; i < N; i++) {
            int K = NextInt();
            for (int j = 0; j < K; j++) {
                int a = NextInt();
                if (!c.ContainsKey(a)) c[a] = 0;
                c[a]++;
            }
        }
        int ans = 0;
        foreach (var t in c) {
            if (t.Value == N) ans++;
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

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

typedef long long ll;
vector <ll> divisor(ll n);

int main(){
    ll n; cin >> n;

    auto div_list = divisor(2 * n);
    vector <ll> n_div_list;

    for(auto &div: div_list){
        n_div_list.push_back(2 * n / div);
    }

    ll ans = n; vector <ll> r = {-1, 0};
    for(int i = 0; i < div_list.size(); i ++){
        vector <ll> m(0);
        m.push_back(n_div_list.at(i));
        m.push_back(div_list.at(i));
        pair <ll, ll> ans1 = crt(r, m);
        if(ans1.first == 0) ans1.first = ans1.second;
        if(ans1.first == 0) continue;
        if(ans1.first % div_list.at(i) != 0) continue;
        if(ans1.first + 1 < int(2 * n / ans1.first)) continue;
        ans = min(ans, ans1.first);
    }
    cout << ans << endl;
}

vector <ll> divisor(ll n){
    vector <ll> arr;
    for(ll i = 1; i * i <= n; i ++){
        if(n % i == 0){
            arr.push_back(i);
            if(i * i == n) continue;
            arr.push_back(n / i);
        }
    }
    return arr;
}

Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c;
  cin >> n >> m >> c;
  int a[n][m];
  int b[m];
  for(int i = 0; i < m; i++) cin >> b[i];
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  int co = 0;
  int x = 0;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      x += a[i][j] * b[j];
    }
    x += c;
    if(x > 0) co ++;
    x = 0;
  }
  cout << co << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int d[7];
int dtoi(int n){for(int i=1;i<=6;i++)if(d[i]==n)return i;}
int itod(int i){return d[i];}

int main(){
	for(int i=1;i<=6;i++)scanf("%d",d+i);
	int n;
	scanf("%d",&n);
	while(n--){
		int a,b;
		scanf("%d%d",&a,&b);
		a=dtoi(a);
		b=dtoi(b);
		if(a==1&&b==2)printf("%d\n",itod(3));
		if(a==1&&b==3)printf("%d\n",itod(5));
		if(a==1&&b==4)printf("%d\n",itod(2));
		if(a==1&&b==5)printf("%d\n",itod(4));
		if(a==2&&b==1)printf("%d\n",itod(4));
		if(a==2&&b==3)printf("%d\n",itod(1));
		if(a==2&&b==4)printf("%d\n",itod(6));
		if(a==2&&b==6)printf("%d\n",itod(3));
		if(a==3&&b==1)printf("%d\n",itod(2));
		if(a==3&&b==2)printf("%d\n",itod(6));
		if(a==3&&b==5)printf("%d\n",itod(1));
		if(a==3&&b==6)printf("%d\n",itod(5));
		if(a==4&&b==1)printf("%d\n",itod(5));
		if(a==4&&b==2)printf("%d\n",itod(1));
		if(a==4&&b==5)printf("%d\n",itod(6));
		if(a==4&&b==6)printf("%d\n",itod(2));
		if(a==5&&b==1)printf("%d\n",itod(3));
		if(a==5&&b==3)printf("%d\n",itod(6));
		if(a==5&&b==4)printf("%d\n",itod(1));
		if(a==5&&b==6)printf("%d\n",itod(4));
		if(a==6&&b==2)printf("%d\n",itod(4));
		if(a==6&&b==3)printf("%d\n",itod(2));
		if(a==6&&b==4)printf("%d\n",itod(5));
		if(a==6&&b==5)printf("%d\n",itod(3));
	}
}


Measured memory_bytes: 2052
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto abk = readln.split.to!(long[]);
    auto A = abk[0];
    auto B = abk[1];
    auto K = abk[2];

    if (A > K) {
        writefln("%d %d", A - K, B);
    } else if (A+B > K) {
        writefln("0 %d", A + B - K);
    } else {
        writeln("0 0");
    }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int k = in.nextInt();

			int gu = k/2;
			int ki = k-gu;

			out.println(gu * ki);

		}
	}

	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 int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

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

	static long max(long... n) {
		long ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.max(ret, n[i]);
		}
		return ret;
	}

	static int max(int... n) {
		int ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.max(ret, n[i]);
		}
		return ret;
	}

	static long min(long... n) {
		long ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.min(ret, n[i]);
		}
		return ret;
	}

	static int min(int... n) {
		int ret = n[0];
		for (int i = 0; i < n.length; i++) {
			ret = Math.min(ret, n[i]);
		}
		return ret;
	}

}


Measured memory_bytes: 22868
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
    ll n;cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    map<ll,ll>M1;
    map<ll,ll>M2;
    rep(i,n)M1[i-a[i]]++;
    rep(i,n)M2[i+a[i]]++;
    ll ans=0;
    for(auto p:M1){
        ans+=p.second*M2[p.first];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 38996
#include <iostream>
using namespace std;
int main(void)
{
	int n,y,h=0,high=0;
	int b[100]={0},r[100]={0},t[100]={0};
	double k[100]={0};
	cin >> n ;
	while(n != 0){
		cin>> y;
		
		for(int i=0;i<n;i++){
			cin >> b[i] >> r[i] >> t[i];
			if(t[i] == 1){
				k[i] = 10000.0*(1.0+y*(r[i]/100.0));
			}
			else{
				k[i] += 1;
				for(int j=0;j<y;j++){
					k[i] = k[i]*(1.0+(r[i]/100.0));
				}
				k[i] = 10000.0*k[i];
			}
			if(high < k[i]){
				high=k[i];
				h=b[i];
			}
		}
		cout << h << endl;
		h=0;
		high=0;
		for(int i=0;i<100;i++){
			b[i]=0;
			t[i]=0;
			r[i]=0;
			k[i]=0;
		}
		cin >> n;
	}
	
	return 0;
}

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int ab = Integer.parseInt(scan.next());
		int bc = Integer.parseInt(scan.next());
		int ca = Integer.parseInt(scan.next());

		System.out.println(ab * bc / 2);
	}
}


Measured memory_bytes: 22612
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int A, B, C;
    cin >> A >> B >> C;
    vector<int> xs;
    xs.push_back(A);
    xs.push_back(B);
    xs.push_back(C);
    sort(xs.begin(), xs.end());
    reverse(xs.begin(), xs.end());

    cout << xs[0] * 10 + xs[1] + xs[2] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
typedef long long ll;

int main(void) {
  ll i, n, now = 0;
  scanf("%lld", &n);
  ll x[n], be[n * n], af[n * n], ans[n * n], cnt[n], tmp[n * n];
  for(i = 0; i < n * n; ++i) be[i] = af[i] = 0, ans[i] = tmp[i] = -1;
  for(i = 0; i < n; ++i) {
    scanf("%lld", &x[i]);
    be[--x[i]] = i + 1;
    af[x[i]] = n - i;
    ans[x[i]] = tmp[x[i]] = i;
    cnt[i] = 0;
  }
  if(be[0] > 1) {
    printf("No");
    return 0;
  }
  for(i = 1; i < n * n; ++i) {
    be[i] += be[i - 1];
    if(be[i] > i + 1) {
      printf("No");
      return 0;
    }
  }
  now = 0;
  for(i = n * n - 1; i >= 0; --i) {
    now += af[i];
    if(now > n * n - i) {
      printf("No");
      return 0;
    }
  }
  now = be[n * n - 1];
  std::queue<ll> q;
  for(i = n * n - 1; i >= 0; --i) {
    if(ans[i] != -1) {
      if(ans[i]) q.push(ans[i]);
      now--;
    }
    else if(!q.empty() && now == i + 1) {
      ans[i] = q.front();
      cnt[q.front()]++;
      if(cnt[q.front()] != q.front()) q.push(q.front());
      q.pop();
      now--;
    }
  }
  for(i = 0; i < n; ++i) cnt[i] = 0;
  for(i = 0; i < n * n; ++i) {
    if(tmp[i] != -1) {
      if(tmp[i] != n - 1) q.push(tmp[i]);
    }
    else if(ans[i] == -1) {
      ans[i] = q.front();
      cnt[q.front()]++;
      if(cnt[q.front()] != n - q.front() - 1) q.push(q.front());
      q.pop();
    }
  }
  printf("Yes\n");
  for(i = 0; i < n * n; ++i) printf("%lld ", ans[i] + 1);
  return 0;
}

Measured memory_bytes: 8960
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

S = sum(B)
for i in range(N - 1):
    if A[i + 1] == A[i] + 1:
        S += C[A[i] - 1]
print(S)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	
	static final int INF = (int)Math.pow(10, 9);
	
	static int N;
	static int A;
	static int B;
	static int C;
	static int[] l;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		
		l = new int[N];
		
		for (int i = 0; i < N; i++) {
			l[i] = sc.nextInt();
		}
		
		System.out.println(dfs(0, 0, 0, 0));
	}
	
	static int dfs(int cur, int a, int b, int c) {
		if (cur == N) {
			if (Math.min(Math.min(a, b), c) > 0) {
				return Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C) - 30;
			} else {
				return INF;
			}
		}
		
		int ret0 = dfs(cur + 1, a, b, c);
		int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
		int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
		int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
		
		return Math.min(Math.min(ret0, ret1), Math.min(ret2, ret3));
	}
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int x, a, b; cin >> x >> a >> b;
  cout << (x - a) % b << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String line = scan.nextLine();

        String ans = "";
        for (int i=0; i < line.length(); i++) {
            char ch = line.charAt(i);

            if (ch == 'B') {
                if (! ans.isEmpty()) ans = ans.substring(0, ans.length() - 1);
            } else if (ch == '1') {
                ans = ans + '1';
            } else {
                ans = ans + '0';
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;cin>>n>>k;
  ll a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  ll ans=n;
  for(int i=0;i<n;i++){
    ll sum=a[i];
    ll sta=n-1;
    for(int j=n-1;j>=0;j--){
      if(j!=i)
      sum+=a[j];
      if(sum>=k&&sum-a[i]<k){
        sum=-1;
        break;
      }
      
        while(sta>=j&&sum>=k){
          if(sta==i){
            sta--;
            continue;
          }
          sum-=a[sta];
          sta--;
        }
    }
    if(sum==-1)ans--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
from time import time
import random
random.seed(0)

now = time()

MAX = 26

d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [i % MAX + 1 for i in range(d)]

last = [0] * MAX

score = 0
for day, e in enumerate(t, 1):
    score += s[day-1][e-1]
    last[e-1] = day

    for ec, elast in zip(c, last):
        score -= ec * (day - elast)

di = 1
while time() - now <= 1.85:
    prev_score = score

    di -= 1
    ed = (di + d - 1) % d + 1
    eq = random.randint(1, MAX)

    q_old = t[ed-1]
    d_prev = {q_old: 0, eq: 0}

    c_old = c[q_old-1]
    c_new = c[eq-1]

    for day, e in enumerate(t, 1):
        if e in d_prev.keys():
            d_prev[e] = day

        score += c_old * (day - d_prev[q_old])
        score += c_new * (day - d_prev[eq])

    score -= s[ed-1][q_old-1]
    score += s[ed-1][eq-1]

    t[ed-1] = eq

    d_prev = {q_old: 0, eq: 0}

    for day, e in enumerate(t, 1):
        if e in d_prev.keys():
            d_prev[e] = day

        score -= c_old * (day - d_prev[q_old])
        score -= c_new * (day - d_prev[eq])

    if prev_score > score:
        t[ed-1] = q_old
        score = prev_score

print(*t, sep="\n")


Measured memory_bytes: 85236
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s;
    cin >> s;
    ll rs=0;

    if(s.at(0) == '1'){
        for(int i = 0;i < s.size();i++){
            if(i % 2 == 0 and s.at(i) == '0')
                rs++;
            if(i % 2 == 1 and s.at(i) == '1')
                rs++;
        }
    }else{
        for(int i = 0;i < s.size();i++){
            if(i % 2 == 0 and s.at(i) == '1')
                rs++;
            if(i % 2 == 1 and s.at(i) == '0')
                rs++;
        }
    }

    cout << rs << endl;



}

Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize
    }
    let mut ans = 0;
    let ps = vec![2,3,5,7,11,13,17,19,23,29,31,37,41,43,47];
    let mut pps = vec![0; 15];
    for i in 0..15 {
        let mut m = n;
        while m > 0 {
            m /= ps[i];
            pps[i] += m;
        }
    }
    for i in 0..15 {
        if pps[i] >= 74 {
            ans += 1;
        }
    }
    for i in 0..15 {
        for j in 0..15 {
            if i == j {
                continue;
            }
            if pps[i] >= 2 && pps[j] >= 24 {
                ans += 1;
            }
            if pps[i] >= 4 && pps[j] >= 14 {
                ans += 1;
            }
        }
    }
    for i in 0..15 {
        for j in 0..15 {
            if i == j {
                continue;
            }
            for k in j + 1..15 {
                if k == i {
                    continue;
                }
                if pps[i] >= 2 && pps[j] >= 4 && pps[k] >= 4 {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#define LEN 100005
 
typedef struct pp{
  char name[100];
  int t;
}P;
 
P Q[LEN+1];
int head, tail, n;
 
void enqueue(P x){
     Q[tail] = x;
     if(tail + 1 == LEN){
       tail = 0;
     } else {
       tail++;
     }
}     
 
P dequeue(){
     P tmp = Q[head];
     if(head + 1 == LEN){
       head = 0;
     } else {
       head++;
     }
return tmp;
}
 
 
int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
 
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  tail = n+1;
  head = 1;
 
  while(tail != head){    
    if(Q[head].t > q){
      elaps += q;
      Q[head].t -= q; 
      enqueue(dequeue());
 
    } else {
      elaps += Q[head].t;
      dequeue();
      printf("%s %d\n", Q[head-1].name, elaps);
    }
  }
   
  return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll mod_pow(ll x,ll n,ll mod){
  if(!n)return 1;
  ll res=mod_pow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}

void Main() {
  ll m;
  string s;
  cin >> m >> s;
  ll c[10];
  mem(c);
  rep(i,s.size()) {
    c[s[i]-'0']+=mod_pow(10,s.size()-i-1,MAX);
    c[s[i]-'0']%=MAX;
  }
  int a[10];
  rep(i,10) a[i]=i;
  do {
    ll x=0;
    rep(i,10) {
      x+=c[i]*a[i];
      x%=MAX;
    }
    if(x==m) {
      if(s.size()>=2&&a[s[0]-'0']==0) continue;
      string t="";
      rep(i,s.size()) t+=a[s[i]-'0']+'0';
      pr(t);
      return;
    }
  } while(next_permutation(a,a+10));
  pr(-1);
}

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



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

public class Main {
	public static void solveColorfulLeaderboard() throws IOException {
		int n;
		int cntColor = 0;
		int cntOverRed = 0;
		boolean red = false;
		boolean orange = false;
		boolean yellow = false;
		boolean blue = false;
		boolean sky = false;
		boolean green = false;
		boolean brown = false;
		boolean grey = false;
		int ai;

		String line;
		String[] split;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		line = br.readLine();
		n = Integer.parseInt(line);
		line = br.readLine();
		split = line.split(" ");

		for (int i = 0; i < n; i++) {
			ai = Integer.parseInt(split[i]);
			if (1 <= ai && ai <= 399 && grey == false) {
				grey = true;
				cntColor++;
			} else if (400 <= ai && ai <= 799 && brown == false) {
				brown = true;
				cntColor++;
			} else if (800 <= ai && ai <= 1199 && green == false) {
				green = true;
				cntColor++;
			} else if (1200 <= ai && ai <= 1599 && sky == false) {
				sky = true;
				cntColor++;
			} else if (1600 <= ai && ai <= 1999 && blue == false) {
				blue = true;
				cntColor++;
			} else if (2000 <= ai && ai <= 2399 && yellow == false) {
				yellow = true;
				cntColor++;
			} else if (2400 <= ai && ai <= 2799 && orange == false) {
				orange = true;
				cntColor++;
			} else if (2800 <= ai && ai <= 3199 && red == false) {
				red = true;
				cntColor++;
			} else if (3200 <= ai) {
				cntOverRed++;
			}
		}
		System.out.println(Math.max(cntColor, 1) + " " + (cntColor + cntOverRed));

		br.close();
	}

	public static void main(String[] args) {
		try {
			solveColorfulLeaderboard();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 21332
// include
#include <bits/stdc++.h>
using namespace std;
// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;
////////////////////////////////////////////////////////////////////////////////////////////////////


int main(int argc, char const* argv[]) 
{
    int N; cin >> N;
    string S; cin >> S;
    UNIQUE(S);
    cout << sz(S) << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

int lg(LL x, int p)
{
	int res = 0;
	while(x % p == 0)
	{
		res++;
		x /= p;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	map<pair<int, int>, int > cnt;
	LL ans = 0;
	while(n--)
	{
		double x;
		cin >> x;
		LL b = 1000 * 1000 * 1000;
		LL a = x * 1e9 + 0.5;
		int g = __gcd(a, b);
		a /= g;
		b /= g;
		int c = lg(a, 2) - lg(b, 2);
		int d = lg(a, 5) - lg(b, 5);
		for(auto [y, z]: cnt)
		{
			if(c + y.first >= 0 && d + y.second >= 0)
				ans += z;
		}
		cnt[{c, d}]++;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3712
n, m = map(int, input().split())


def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    k = min(k, n - k)
    ans = 1
    for i in range(1, k + 1):
        ans *= n - i + 1
        ans //= i
    return ans


ans = comb(n, 2) + comb(m, 2)

print(ans)


Measured memory_bytes: 2940
main() {
  int v[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; scanf("%d", &k); printf("%d\n", v[--k]);
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
 
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
 
string a, b;
int main() {
    while (cin >> a >> b) {
        reverse(a.begin(), a.end());
        if (a == b) puts("YES");
        else puts("NO");
    }
}
 

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    ll A, B, K;
    ll resA, resB;
    cin >> A >> B >> K;

    if(A > K){
        resA = A - K;
        resB = B;
    }
    else{
        resA = 0;
        if(B >= (K-A))
            resB = B - (K-A);
        else
            resB = 0;
    }

    cout << resA << ' ' << resB << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int number;
int sum=0;
int time[100000]={0};
int newtime[100000]={0};
int drinks;
int problem[100]={0};
int temp[100000]={0};
cin>>number;
for(int i=0;i<number;i++){
    cin>>time[i];
}
cin>>drinks;
for(int j=0;j<drinks;j++){
    cin>>problem[j];
    cin>>newtime[j];
}
for(int k=0;k<drinks;k++){
    for(int l=0;l<100000;l++){
        temp[l]=time[l];
    }
    temp[problem[k]-1]=newtime[k];
    for(int n=0;n<number;n++){
        sum+=temp[n];
    }
    cout<<sum<<endl;
    sum=0;
}
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int S(int N) {
    int res = 0;
    while(N) {
        res += N % 10;
        N /= 10;
    }
    return res;
}

int main(void) {
    int N;
    cin >> N;
    if(N % S(N) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
x1,y1,x2,y2 = gets.split(' ').map(&:to_i)

x3,y3,x4,y4 = 0

x3 = x2 - (y2 - y1)
y3 = (x2 - x1) + y2
x4 = x3 - (y3 - y2)
y4 = y3 - (x2 - x3)

ans = []
ans[0] = x3
ans[1] = y3
ans[2] = x4
ans[3] = y4

puts ans.join(' ')

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int n,p;
 	float a;
 	cin>>n;
 	if(n%2==0)
 		p=n/2;
 	else
 		p=n/2+1;
 	a=float(p)/float(n);
	 cout << fixed << setprecision(6) <<a<<endl; 	
 	return 0;
}
 	
 					

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int main()
{  ios::sync_with_stdio(false);
   cin.tie(0);  
   string a,b;
   cin>>a>>b;
   int m=a.length(),n=b.length();
   for(int i=0;i<=m;i++) dp[i][0]=0;
   for(int j=0;j<=n;j++) dp[0][j]=0;

   for(int i=1;i<=m;i++){
     for(int j=1;j<=n;j++){
        if(a[i-1]==b[j-1])
          dp[i][j]=1+dp[i-1][j-1];
          else 
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
     }
   }
   string lcs;
    int i=m,j=n;
    while(i>0 && j>0){
      if(a[i-1]==b[j-1]){
        lcs=a[i-1]+lcs;
        i--;
        j--;
       } else if(dp[i-1][j]>dp[i][j-1]){
         i--;
       }else{
         j--;
       }
    }
    cout<<lcs;
     return 0;
}


Measured memory_bytes: 38824
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    if A[0] > 0: print(-1)
    else:
        count = 0
        for i in range(1, N):
            a = A[i]
            if a <= A[i-1]: count += a
            elif a > A[i-1]:
                if a == A[i-1] + 1: count += 1
                else: 
                    print(-1)
                    break
        else: print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 11052
using System;

namespace abc105A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            if (A % B == 0)
                Console.WriteLine(0);
            else
                Console.WriteLine(1);
        }
    }
}


Measured memory_bytes: 11092