akhauriyash/Code-Regression huggingface dataset:
// Polygon

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int n;

int main() {
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += l[i];
    }

    if (l[n-1] < sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    ll A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll mod = 1000000007;
    
    ll B[N + 1]{};
    for (int i = 0; i < N; i++) {
        B[i + 1] = (B[i] + A[i]) % mod;
    }
    ll ans = 0;
    for (int i = 0; i < N - 1; i++) {
        ans += A[i] * (B[N] - B[i + 1] + mod);
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6768
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    int a,b,c,d,e;
    cin>>a>>b;
    c=a+b;
    d=a-b;
    e=a*b;
    int ans= max(c,d);
    ans=max(ans,e);
    cout << ans <<endl;
}

Measured memory_bytes: 256
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define len(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}


void solve(){
  COMinit();
  ll S;
  cin >> S;
  ll ans = 0;
  rep(i, 2010){
    ll rest = S - 3 * i;
    if(rest < 0) continue;
    ans += comb(rest + i - 1, rest);
    ans %= MOD;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 50524
import java.util.*;

class Main {
    public static void main(String[] args) {
        solve();
    }
    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i=0;i<n;i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int maxim = 1000000001;

        int ans = bSearch(0, maxim, a);
        
        System.out.println(ans);      
    }
    
    /*
    条件を満たすxの最大値をにぶたんで求める
    */
    public static int bSearch(int ok,int ng,int[] numbers){
        if(ng == ok + 1){
            return(ok);
        } else {
            int mid = (ok+ng)/2;
            if(judge(mid, numbers)) {
                return(bSearch(mid, ng, numbers));
            } else {
                return(bSearch(ok, mid, numbers));
            }
        }
    }

    public static boolean judge(int x, int[] numbers){
        /*
        int xが条件を満たすかどうか判定する
        条件：x以上のmedian yが半数以上存在する
        */
        int n = numbers.length;
        int cumsum = 0;
        long m = n;
        long intervals = m*(m+1)/2;
        long half = intervals/2;
        long y = 0;
        BIT bit = new BIT(2*n+1);
        bit.add(n+1,1);
        for(int i = 0; i<n; i++){
            if(numbers[i]>=x){
                cumsum++;
            } else {
                cumsum--;
            }
            y += bit.sum(cumsum+n+1);
            bit.add(cumsum+n+1,1);
        }
        return(y >= intervals - half);
    }
}

class BIT {
    private int[] values;
    private int length;

    public BIT(int length) {
        this.length = length;
        values = new int[length+1];
    }

    public void add(int location, int value){
        for(int x = location; x <= this.length; x += x & -x){
            values[x] += value;
        }
    }

    public int sum(int right){
        int ans = 0;
        for(int x = right; x > 0; x -= x & -x){
            ans += values[x];
        }
        return ans;
    }

    public int sum(int left, int right){
        if(left > 1)
            return(sum(right)-sum(left-1));
        else
            return(sum(right));
    }
}

Measured memory_bytes: 63432
M, D = gets.strip.split.map(&:to_i)
ans=0
(1..M).each do |m|
    (1..D).each do |d|
        d1=d/10
        d2=d%10
        if d1>=2 && d2>=2 && m==d1*d2
            ans+=1
        end
    end
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
template <class T1, class T2>void print(T1 a[], T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " ";} cout << endl;}
template <class T1, class T2>void print(vector<T1> a, T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl;}
ll modexpo(ll a, ll b, ll m) {if (b == 0) {return 1;} else if (a == 1) {return 1;} if (b % 2 == 0) {ll t = modexpo(a, b / 2, m); t = (t * t) % m; return t;} else {ll t = modexpo(a, b / 2, m); t = (t * t) % m; t = (t * a) % m; return t;}}




int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
*/

	ll k;
	cin >> k;
	ll y = 0;
	ll t = 100;
	//cout<<k<<endl;
	while (true) {
		if (t >= k) {
			cout << y << endl;
			break;
		}
		t = t+ t*(0.01);
		y++;
	}
}


Measured memory_bytes: 3608
import math
n=int(input())
l=[1,2,4,8,16,32,64,128,256,512]
for i in range(len(l)):
  if n>l[i]:
    N=l[i+1]
    y=i+1
ANS=[]
L=[]
for i in range(1,y+1):
  L.append([str(i) for j in range(1,2**(i-1)+1)])
L.reverse()
for i in range(N-1):
  x=format(N-i-1,'0'+str(y)+'b')
  ans=[]
  for j in range(len(x)):
    if x[j]=='1':
      ans=L[j]+ans
  if i>=N-n:
    print(' '.join(ans))

Measured memory_bytes: 3316
import java.util.*;

class Main{
    public static void main(String[] args){
    	Scanner sc= new Scanner(System.in);
    	String s,w;int ans=0; 
    	w=sc.nextLine().toLowerCase();
    	for(;;){
    		s=sc.next();if(s.equals("END_OF_TEXT")) break; 
    		s=s.toLowerCase();
    		if(w.equals(s)) ans++;
}
System.out.println(ans);
    }
}

Measured memory_bytes: 26204
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#define N 7
#define ONE '1'
#define ZERO '0'

using namespace std;

char data[N][N][N], data_[N][N][N];

void input_init(){
  string s;
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      if(i!=0 && i!=N-1 && j!=0 && j!=N-1) cin >> s;
      for(int k=0; k<N; ++k){
	if(i!=0 && i!=N-1 && j!=0 && j!=N-1 && k!=0 && k!=N-1)
	  data[i][j][k] = s[k-1];
	else
	  data[i][j][k] = ZERO;
	data_[i][j][k] = ZERO;
      }
    }
  }
}

void input_map(set<int>* a){
  a->clear();
  int m, x;
  cin >> m;
  for(int i=0; i<m; ++i){
    cin >> x;
    a->insert(x);
  }
}

void output(){
  for(int i=1; i<N-1; ++i){
    for(int j=1; j<N-1; ++j){
      for(int k=1; k<N-1; ++k){
	cout << data[i][j][k];
      }
      cout << endl;
    }
    if(i != N-2) cout << endl;
  }
}

void copy(){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      for(int k=0; k<N; ++k){
	data[i][j][k] = data_[i][j][k];
      }
    }
  }
}

int counter(int n, int m, int l){
  int num=0;
  for(int i=n-1; i<=n+1; ++i){
    for(int j=m-1; j<=m+1; ++j){
      for(int k=l-1; k<=l+1; ++k){
	if(i==n && j==m && k==l) continue;
	if(data[i][j][k] == ONE) ++num;
      }
    }
  }
  return num;
}

void solve(set<int>& a, set<int>& b){
  int num;
  for(int i=1; i<N-1; ++i){
    for(int j=1; j<N-1; ++j){
      for(int k=1; k<N-1; ++k){
	num = counter(i, j, k);
	if(data[i][j][k] == ZERO){
	  if(a.find(num) != a.end()) data_[i][j][k] = ONE;
	  else data_[i][j][k] = ZERO;
	}else{
	  if(b.find(num) != b.end()) data_[i][j][k] = ONE;
	  else data_[i][j][k] = ZERO;
	}
      }
    }
  }
  copy();
}

int main(){
  int n, num=1;
  set<int> a, b;
  while(1){
    cin >> n;
    if(!n) break;
    input_init();
    input_map(&a);
    input_map(&b);
    for(int i=0; i<n; ++i) solve(a, b);
    if(num != 1) cout << endl;
    cout << "Case " << num << ":" << endl;
    output();
    ++num;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
using namespace std;

signed main(){
    int n;
    while(true){
        scanf("%d",&n);
        if(!n) break;
        int l = 1, r = 1, sum = 0;
        while(sum!=n){
            if(sum > n){
                sum -= l++;
            }
            if(sum < n){
                sum += r++;
            }
            
        }
        printf("%d %d\n",l,r - l);
    }
    return 0;
}



Measured memory_bytes: 3184
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))



def main():
    m = {'A':'a', 'B':'b', 'C':'c'}
    n, k = rli()
    s = list(input())
    s[k-1] = m[s[k-1]]
    print("".join(s))


if __name__ == '__main__':
    main()


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

int main()
{
    int n, m, q;
    cin >> n >> m >> q;
    int aa[100005]{0};
    for(int i = 0; i < q; i++){
        cin >> aa[i];
        aa[i]--;
    }
    int b[100005]{0};
    int d[100005];
    int e[100005];
    int c = 0;
    vector<int> v[100005];
    for(int i = q - 1; i >= 0; i--){
        int a = aa[i];
        if(b[a] == 0){
            d[a] = c;
            e[c] = a;
            c++;
        }
        if(b[a] < n){
            if(d[a] == 0 || b[a] < b[e[d[a] - 1]]){
                v[b[a]].push_back(a);
                b[a]++;
            }
        }
    }
    bool f[100005]{0};
    for(int x : v[0]) f[x] = true;
    for(int i = 0; i < m; i++){
        if(!f[i]) v[0].push_back(i);
    }
    fill(f, f + m, false);
    for(int x : v[n - 1]) f[x] = true;
    for(int i = 0; i < m; i++){
        if(!f[i]) v[n - 1].push_back(i);
    }
    if(v[0] == v[n - 1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 8568
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  n; cin>>n;
   long long  arr[n];
   for(long long  i=0;i<n;i++)
    cin>>arr[i];
   bool dp[2][n];
   dp[0][0]=true;
   dp[1][0]=true;
   for(long long  i=1;i<n;i++)
   {
       if(arr[i]>=arr[i-1]  and dp[0][i-1]==true)
       {
           dp[0][i]=true;
       }
       else if(arr[i]>=arr[i-1]-1 and dp[1][i-1]==true)
       {
           dp[0][i]=true;
       }
       else
        dp[0][i]=false;
       if(arr[i]-1>=arr[i-1]  and dp[0][i-1]==true)
       {
           dp[1][i]=true;
       }
       else if(arr[i]-1>=arr[i-1]-1 and dp[1][i-1]==true)
       {
           dp[1][i]=true;
       }
       else
        dp[1][i]=false;
   }
   if(dp[0][n-1]==true or dp[1][n-1]==true)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
char n;
int a,b;
int main()
{
    cin>>a>>b;//输入
    for(int s=0;s<a;s++)
    {
        cin>>n;
        if(n<'0'||n>'9')//判断前a个
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cin>>n;
    if(n!='-')//判断第a+1
    {
        cout<<"No"<<endl;
        return 0;

    }
    for(int s=0;s<b;s++)
    {
        cin>>n;
        if(n<'0'||n>'9')//判断判断从右往左的b个
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl; //排除完了，只能输出Yes
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int prime[1000001],i,j,n;

  for(i=0;i<1000001;i++)
    prime[i]=0;
  
  prime[0]=prime[1]=1;

  for(i=2;i*i<1000001;i++){
    if(prime[i]==0){
      for(j=2*i;j<1000001;j+=i){
	prime[j]=1;
      }
    }
  }
  
  while(scanf("%d",&n),n){
    int count=0;
    for(i=2;i<=n/2;i++)
      if(prime[i]==0 && prime[n-i]==0)count++;

    printf("%d\n",count);
}

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>

int main(void){

    std::string str,p;
    std::cin>>str;
    std::cin>>p;
    str+=str;
    if(str.find(p)!=std::string::npos) std::cout<<"Yes"<<std::endl;
    else std::cout<<"No"<<std::endl;
    return 0;
}

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

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

    bool ans[1000] = {};
    while (n != 0) {
        int bit;
      	long long sum;
        if (n > 0) {
            sum = 0b01;
            for (bit = 0; n > sum; bit += 2) sum = (sum << 2) | 0b01;
            n -= (1 << bit);
        } else {
            sum = 0b10;
            for (bit = 0; abs(n) > sum; bit += 2) sum = (sum << 2) | 0b10;
            bit++;
            n -= -1 * (1 << bit);
        }
        ans[bit] = true;
    }

    int i = 1000 - 1;
    while (ans[i] == false && i > 0) i--;
    for (; i >= 0; i--) cout << (ans[i] ? 1 : 0);
    cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <queue>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

struct Edge {
  int dst, dist;
  Edge(int dst, int dist): dst(dst), dist(dist) {}
};

struct State {
  int city, rest, cost;
  State(int city, int rest, int cost): city(city), rest(rest), cost(cost) {}
  bool operator<(const State& rhs) const { return cost > rhs.cost; }
};

inline int add_name(map<string, int>& name2id, const string& name) {
  if (name2id.count(name)) {
    return name2id[name];
  } else {
    int id = name2id.size();
    return name2id[name] = id;
  }
}

const int INF = 0x0f0f0f0f;

vector<Edge> edges[6010];
bool has_lpg[6010];
bool visit[6010][2010];
int cost[6010][2010];

int main() {
  int N, M, cap;
  while (scanf("%d%d%d", &N, &M, &cap), N|M|cap) {
    map<string, int> name2id;
    string src_name, dst_name;

    memset(has_lpg, false, sizeof(has_lpg));
    memset(visit, false, sizeof(visit));
    memset(cost, INF, sizeof(cost));

    cin >> src_name >> dst_name;
    int src = add_name(name2id, src_name);
    int dst = add_name(name2id, dst_name);
    REP(i, N) {
      int dist;
      cin >> src_name >> dst_name >> dist;
      int s = add_name(name2id, src_name);
      int t = add_name(name2id, dst_name);
      edges[s].push_back(Edge(t, dist));
      edges[t].push_back(Edge(s, dist));
    }
    REP(i, M) {
      cin >> src_name;
      has_lpg[name2id[src_name]] = true;
    }

    priority_queue<State> Q;
    Q.push(State(src, 10 * cap, 0));
    cost[src][10 * cap] = 0;
    while (!Q.empty()) {
      int city = Q.top().city;
      int rest = Q.top().rest;
      Q.pop();

      if (visit[city][rest]) { continue; }
      visit[city][rest] = true;

      FOREACH(it, edges[city]) {
        int new_city = it->dst;
        if (rest < it->dist) { continue; }
        int new_rest = has_lpg[new_city] ? 10 * cap : rest - it->dist;
        int new_cost = cost[city][rest] + it->dist;
        if (new_cost >= cost[new_city][new_rest]) { continue; }
        cost[new_city][new_rest] = new_cost;
        Q.push(State(new_city, new_rest, new_cost));
      }
    }

    int ans = *min_element(cost[dst], cost[dst] + 10 * cap + 1);
    cout << (ans < INF ? ans : -1) << endl;

    REP(i, name2id.size()) { edges[i].clear(); }
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define y1 DCXISSOHANDSOME

struct node { int x,y; }a[100010];

int mx[800010];
int h[200010],r,c,n,m,tt,tot;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void modify(int o,int l,int r,int x,int y)
{
	if (l==r) { mx[o]=max(mx[o],y);return; }
	int mid=(l+r)>>1;
	if (x<=mid) modify(o<<1,l,mid,x,y);
	else modify(o<<1|1,mid+1,r,x,y);
	mx[o]=max(mx[o<<1],mx[o<<1|1]);
}

inline int query(int o,int l,int r,int x,int y)
{
	if (l>=x&&r<=y) return mx[o];
	int mid=(l+r)>>1,res=0;
	if (x<=mid) res=max(res,query(o<<1,l,mid,x,y));
	if (y>mid) res=max(res,query(o<<1|1,mid+1,r,x,y));
	return res;
}

int main()
{
	r=rd();c=rd();n=rd();
	m=(r+c)<<1;tt=0;
	for (int i=1;i<=n;i++)
	{
		int x1=rd(),y1=rd(),x2=rd(),y2=rd();
		bool b1=(x1==0||x1==r||y1==0||y1==c),b2=(x2==0||x2==r||y2==0||y2==c);
		if (b1&&b2)
		{
			int x,y;
			if (x1==0) x=y1+1;
			else if (y1==c) x=c+1+x1;
			else if (x1==r) x=r+c+1+(c-y1);
			else x=r+c*2+1+(r-x1);
			if (x2==0) y=y2+1;
			else if (y2==c) y=c+1+x2;
			else if (x2==r) y=r+c+1+(c-y2);
			else y=r+c*2+1+(r-x2);
			if (x>y) swap(x,y);
			a[++tt].x=x;a[tt].y=y;
		}
	}
	if (tt<=1) { puts("YES");return 0; }
	tot=0;
	for (int i=1;i<=tt;i++) h[++tot]=a[i].x,h[++tot]=a[i].y;
	sort(h+1,h+tot+1);
	tot=unique(h+1,h+tot+1)-h-1;
	for (int i=1;i<=tt;i++) a[i].x=lower_bound(h+1,h+tot+1,a[i].x)-h,a[i].y=lower_bound(h+1,h+tot+1,a[i].y)-h;
	for (int i=1;i<=tt;i++) modify(1,1,tot,a[i].x,a[i].y);
	for (int i=1;i<=tt;i++) if (query(1,1,tot,a[i].x,a[i].y)>a[i].y) { puts("NO");return 0; }
	puts("YES");
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long LL;
const int N = 2005;

LL K;
char str[N];
int f[N][N];
LL g[N][N];

void getg(int l, int r) {
    if (g[l][r] != -1) return ;
    if (r - l + 1 + f[l][r - l + 1] == 0) {
        g[l][r] = 1;
        return ;
    }
    if (l == r) {
        g[l][r] = 1;
        return ;
    }
    g[l][r] = 0;
    for (char pos = 'a'; pos <= 'z'; ++pos) {
        int l1 = l, r1 = r;
        if (str[l1] == pos) ++l1;
        if (str[r1] == pos) --r1;
        if (f[l1][r1 - l1 + 1] + r1 - l1 + 1 + 2 == f[l][r - l + 1] + r - l + 1) {
            getg(l1, r1);
            g[l][r] += g[l1][r1];
            if (g[l][r] > K) g[l][r] = K + 1;
        }
    }
}

char str1[100000];

void solve(int l, int r, int L, int R) {
    if (L > R) return ;
    if (l == r) {
        str1[L] = str[l];
        return ;
    }
    for (char pos = 'a'; pos <= 'z'; ++pos) {
        int l1 = l, r1 = r;
        if (str[l1] == pos) ++l1;
        if (str[r1] == pos) --r1;
        if (f[l1][r1 - l1 + 1] + r1 - l1 + 1 + 2 == f[l][r - l + 1] + r - l + 1) {
            //if (l == 1 && r == 5)
            //    cout << g[l1][r1] << endl;
            if (g[l1][r1] < K) {
                K -= g[l1][r1];
                continue;
            }
            // cout << 1 << endl;
            str1[L] = str1[R] = pos;
            solve(l1, r1, L + 1, R - 1);
            return ;
        }
    }
}

int main() {
    gets(str + 1);
    int n = strlen(str + 1);
    scanf("%lld", &K);
    for (int len = 2; len <= n; ++len)
        for (int s = 1; s + len - 1 <= n; ++s) {
            f[s][len] = 1 << 30;
            f[s][len] = min(f[s][len], f[s][len - 1] + 1);
            f[s][len] = min(f[s][len], f[s + 1][len - 1] + 1);
            if (str[s] == str[s + len - 1])
                f[s][len] = min(f[s][len], f[s + 1][len - 2]);
        }
    memset(g, -1, sizeof(g));
    getg(1, n);
    if (g[1][n] < K) {
        puts("NONE");
        return 0;
    }
    solve(1, n, 1, f[1][n] + n);
    puts(str1 + 1);
}
/*
thdstodxtksrnfacdsohnlfuivqvqsozdstwaszmkboehgcerwxawuojpfuvlxxdfkezprodnettawsyqazekcftgqbrrtkzngaxzlnphynkmsdsdleqaxnhehwzgzwtldwaacfczqkfpvxnalnnhfzbagzhqhstcymdeijlbkbbubdnptolrmemfxlmmzhfpshykxvzbjmcnsusllpyqghzhdvljdxrrebeef
11469362357953500
 */

Measured memory_bytes: 48372
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
set<ll> st;
void enum_divisors(long long N) {
    
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            st.insert(i);
            if(N / i != i)
            st.insert(N / i);
        }
    }
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,m;
cin >> n >> m;
ll ans = 0;
enum_divisors(m);
for(auto v :st){
    if(v * n <= m)
    ans = v;
}
cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b =[0]*n
count = 0
ans = []

for i in reversed(range(n)):
  if n/2 > i :
    tmp = 2
    sum_num = 0
    while (tmp*(i+1) - 1) < n:
      sum_num += 1 if b[tmp*(i+1)-1] == 1 else 0
      tmp += 1
      
    b[i] = 0 if sum_num %2 == a[i] else 1
  else:
    b[i] = a[i]
  
  if b[i] == 1:
    count += 1
    ans.append(str(i+1))
    
list.sort(ans)
print(count)
print(' '.join(ans))

Measured memory_bytes: 17592
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1000000000

int main(){

    int N, M;
    vector<tuple<int, int, int>> city;
    cin >> N >> M;
    for (int i = 0; i < M; i++){
        int temp1, temp2;
        cin >> temp1 >> temp2;
        city.push_back(make_tuple(temp1, temp2, i));
    }
    sort(city.begin(), city.end());

    vector<tuple<int, int, int>> name;
    int pKind = 0;
    int cnt = 0;
    for (int ii = 0; ii < M; ii++){
        if (pKind != get<0>(city[ii])){
            pKind = get<0>(city[ii]);
            cnt = 1;
        }else{
            cnt++;
        }
        name.push_back(make_tuple(get<2>(city[ii]), pKind, cnt));
    }
    sort(name.begin(), name.end());
    for (int i = 0; i < M; i++){
        std::cout << setfill('0') << setw(6) << right << get<1>(name[i]);
        std::cout << setfill('0') << setw(6) << right << get<2>(name[i]) << endl;
    }
    return 0;
}


Measured memory_bytes: 3956
using System;
					
public class Program
{	
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		
		for(int i = 0; i < n ; i++) {
			string X = Console.ReadLine();
			string Y = Console.ReadLine();
			
			int[,] DP = new int[X.Length + 1, Y.Length + 1];
			
			for(int j = 1; j < (X.Length + 1); j++) {
				for(int k = 1; k < (Y.Length + 1); k++) {
					DP[j,k] = LCS(DP, j, k, X, Y);
				}
			}
			
			Console.WriteLine(DP[X.Length, Y.Length]);
		}
	}
	
	public static int LCS(int[,] DP, int i, int j, string X, string Y)
	{
		if(X.Substring(i-1,1) == Y.Substring(j-1,1)) return DP[i-1, j-1] + 1;
		else return Math.Max(DP[i-1,j], DP[i,j-1]);
	}
}

Measured memory_bytes: 23004
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Remaining Balls
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

char s[16], t[16], u[16];

/* subroutines */

/* main */

int main() {
  int a, b;
  scanf("%s%s%d%d%s", s, t, &a, &b, u);

  if (strcmp(s, u) == 0) a--;
  else b--;

  printf("%d %d\n", a, b);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int MOD = 1e9 + 7;
 
map<ll,ll> ma;
ll b(ll n)
{
	if(n<2) return n;
	if(ma[n]!=0) return ma[n];
	if(n%2==0)
	{
		return (ma[n]=b(n/2));
	}
	else
	{
		ll x = n-1;
		ll y = n+1;
		while(x%2==0) x>>=1;
		while(y%2==0) y>>=1;
		return (ma[n]=(b(x)+b(y))%MOD);
	}
}
 
ll a(ll n)
{
	if(n==1) return 1;
	if(n==2) return 2;
	if(n&1)
	{
		ll k = (n-1)/2;
		ll ans = ((a(k)*3LL)%MOD + b(k+1))%MOD;
		if(ans<0) ans+=MOD;
		return ans;
	}
	else
	{
		ll k = n/2;
		ll ans = ((a(k)*3LL)%MOD - b(k))%MOD;
		if(ans<0) ans+=MOD;
		return ans;
	}
}
 
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n; cin>>n;
	cout<<a(n+1);
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
//#include <bits/stdc++.h>//atcoderでsqrtを使うときに必要
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

bool sosu(ll num)
{

	if (num == 2) {
		return true;
	}
	else if (num % 2 == 0) {
		return false;
	}

	double sq = sqrt(num);
	for (int i = 3; i <= sq; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}
	return true;


}

void solve() {
	ll a,b,k;
	cin >> a;

	bool judge = false;
	while (judge==false) 
	{
		judge = sosu(a);
		a++;
	}

	ce(a-1);

	
}




int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 3192
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int, K: int):

    if A <= K:
        a = 0
        b = max(B-(K-A), 0)
    else:
        a = A-K
        b = B
    print(a, b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, combinations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from operator import itemgetter
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
DEBUG = sys.argv[-1]!='ONLINE_JUDGE'

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def dprint(*args, **kwargs):
    pass
    # if DEBUG:
    #     print(*args, **kwargs)

def main():
    X,K,D=mis()
    X = abs(X)
    ZP = X%D
    if abs(X - ZP)//D > K:
        dprint('too far')
        print(X - D*K)
        return
    ZN = ZP - D
    X, K = ZP, K - abs(X - ZP)//D
    if K&1:
        dprint('odd')
        print(abs(ZN))
    else:
        dprint('even')
        print(abs(ZP))


main()



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

int main() {
	string ans;
	int a,b,ab;
	cin >> a>>b;
	ab = a + b;
	if (a % 3 == 0 || b % 3 == 0 || ab % 3 == 0) {
		ans = "Possible";
	}
	else {
		ans = "Impossible";
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++)
  {
    cin >> W[i];
  }
  int ans = 10000000;
  for (int i = 0; i < N - 1; i++)
  {
    int sum1 = 0;
    int sum2 = 0;
    for (int j = 0; j < N; j++)
    {
      if (j <= i)
        sum1 += W[j];
      else
        sum2 += W[j];
    }
    ans = min(ans, abs(sum1 - sum2));
  }
  cout << ans << endl;
}


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

template<typename T> T changeMax(T& a, T b){
    if(a < b)a = b;
    return 0;
}
int main()
{
    int n;
    int a[100010][3];
    vector<vector<ll> > dp(100010, vector<ll>(3));
    cin >> n;
    rep(i, n) rep(j, 3) cin >> a[i][j];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k)continue;
                changeMax(dp[i+1][k], dp[i][j]+a[i][k]);
            }
        }
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
    system("pause");
}

Measured memory_bytes: 7160
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;

int main(){
    string s;
    cin >> s;
    rep(i,3){
        if(s[i] == s[i+1]){
            cout << "Bad" <<endl;
            return 0;
        }
    }
    cout << "Good" <<endl;
    

}

Measured memory_bytes: 256
S = input()

n_01 = 0
S_0 = S[0::2]
S_1 = S[1::2]
n_01 = S_0.count("1") + S_1.count("0")
n_10 = S_0.count("0") + S_1.count("1")
print(min(n_01, n_10))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define For(i , j , k) for (LL i = (j) , _##end_ = (k) ; i <= _##end_ ; ++ i)
#define Fordown(i , j , k) for (LL i = (j) , _##end_ = (k) ; i >= _##end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define pb push_back
#define INF (0x3f3f3f3f)
#define Mod (1000000007)
#ifdef hany01
#define debug(...) fprLLf(stderr , __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;
typedef long long LL;

inline void file()
{
#ifdef hany01 
	freopen("a1.in" , "r" , stdin);
    freopen("a1.out" , "w" , stdout);
#endif
}

char c_;
LL _ , __;
inline LL read()
{
    for(_=0,__=1,c_=getchar();!isdigit(c_);c_=getchar())if(c_=='-')__=-1;
    for(;isdigit(c_);c_=getchar())_=(_<<1)+(_<<3)+(c_^ 48);
    return _ * __;
}

const int maxn = 310;
LL a[maxn][maxn] , Sum  , n;
bool flag;

int main()
{
    file();
    n = read();
    For(i , 1 , n)
        For(j , 1 , n)
            a[i][j] = read();
    For(i , 1 , n)
    {
        For(j , i + 1 , n)
        {
            flag = false;
            For(k , 1 , n)
            {
                if (k == i || k == j)
                    continue;
                if (a[i][j] == a[i][k] + a[k][j])
                    flag = true;
                if (a[i][j] > a[i][k] + a[k][j])
                {
                    puts("-1");
                    return 0;
                }
            }
            if (!flag)
                Sum += a[i][j];
        }
    }
    cout << Sum << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define T 1
#define S 2
#define E 3
#define W 4
#define N 5
#define B 6

int main(void){
	int dice[7],buf[7];
	char hoko[101]={NULL};
	int i,j;
	for(i=1;i<=6;i++){
		scanf("%d",&dice[i]);
	}
	scanf("%s",hoko);
	for(i=0;(int)hoko[i];i++){
		for(j=1;j<=6;j++) buf[j]=dice[j];
		if (hoko[i]=='S'){
			dice[T]=buf[N];
			dice[S]=buf[T];
			dice[E]=buf[E];
			dice[W]=buf[W];
			dice[N]=buf[B];
			dice[B]=buf[S];
		}
		else if (hoko[i]=='E'){
			dice[T]=buf[W];
			dice[S]=buf[S];
			dice[E]=buf[T];
			dice[W]=buf[B];
			dice[N]=buf[N];
			dice[B]=buf[E];
		}
		else if (hoko[i]=='W'){
			dice[T]=buf[E];
			dice[S]=buf[S];
			dice[E]=buf[B];
			dice[W]=buf[T];
			dice[N]=buf[N];
			dice[B]=buf[W];
		}
		else if (hoko[i]=='N'){
			dice[T]=buf[S];
			dice[S]=buf[B];
			dice[E]=buf[E];
			dice[W]=buf[W];
			dice[N]=buf[T];
			dice[B]=buf[N];
		}
	}
	printf("%d\n",dice[T]);
	return 0;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll N = 1e6 + 10;

bool f = 0;
str s;
int main(){
	cin >> s;
	for (int i = 0; i < s.size() - 1; i++){
		if (s[i] == s[i + 1]){
			return cout << i + 1<< ' ' << i + 1 + 1<< '\n', 0;
 		}
	}
	for (int i = 0; i < (ll)s.size() - 2; i++){
		if (s[i] == s[i + 2]){
			return cout << i + 1<< ' ' << i + 2 + 1<< '\n',0;
		}
	}
	cout << -1 << ' '  << -1;


	return 0;
}


Measured memory_bytes: 512
import bisect
import sys
input=lambda : sys.stdin.readline().rstrip()
a,b,q=map(int,input().split())
s=sorted([int(input()) for i in range(a)])
t=sorted([int(input()) for i in range(b)])
for i in range(q):
    ans=999999999999
    x=int(input())
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    sys.stdout.write("%d"%ans+'\n')

Measured memory_bytes: 12820
#include <stdio.h>
int main(void){
    
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    if(a<b&&b<c){
        printf("Yes\n");
    }else{
        printf("No\n");    
    }
    
return 0;

}



Measured memory_bytes: 2048
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]
        S[i+1]%=m

    ans=0
    C=defaultdict(int)
    for s in S:
        ans+=C[s]
        C[s]+=1
    print(ans)
resolve()

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

#define MAXN 100010

int n,m,a[MAXN],ans[MAXN],res[MAXN],tmp[MAXN];
long long k;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	for(int i=1;i<n;++i)ans[i]=i;
	scanf("%d%lld",&m,&k);
	for(int i=1;i<=m;++i)
	{
		int x;
		scanf("%d",&x);
		swap(ans[x],ans[x-1]);
	}
	for(int i=1;i<n;++i)res[i]=i;
	while(k)
	{
		if(k&1)
			for(int i=1;i<n;++i)res[i]=ans[res[i]];
		for(int i=1;i<n;++i)tmp[i]=ans[ans[i]];
		for(int i=1;i<n;++i)ans[i]=tmp[i];
		k>>=1;
	}
	long long sum=a[1];
	for(int i=1;i<=n;++i)
	{
		printf("%lld.0\n",sum);
		sum+=a[res[i]+1]-a[res[i]];
	}
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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 (b<a) { a=b; return 1; } return 0; }

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll n,m; cin>>n>>m;
    vint a(n); rep(i,n) cin>>a[i];

    vint rui(n+1,0);
    rep(i,n){
        rui[i+1] = (rui[i]+a[i])%m;
    }

    map<ll,ll> cnt;

    for(auto e:rui) cnt[e]++;
    ll ans = 0;
    for(auto p:cnt) ans += p.se*(p.se-1)/2;
    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n, a[5];

int main(void)
{
    cin >> n;
    rep(i,5)
    {
        cin >> a[i];
    }

    sort(a, a + 5);

    lin res = (n - 1) / a[0] + 1 + 4;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int count = 0;

void init(void)
{
	count = 0;
}

int gcd(int x, int y)
{
	count++;
	return (y ? gcd(y, x % y) : x);
}

int main(void)
{
	int x, y;
	int res;

	while (scanf("%d %d", &x, &y), x){
		init();
		if (x > y){
			res = gcd(x, y);
		}
		else {
			res = gcd(y, x);
		}
		printf("%d %d\n", res, count - 1);
	}

	return (0);
}

Measured memory_bytes: 600
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long C = sc.nextLong();
        long K = sc.nextLong();
        long[] T = new long[N];
        for (int i = 0; i < N; i++) {
            T[i] = sc.nextLong();
        }
        Arrays.sort(T);
        long ans = 0;
        int count = 0;
        for (int i = 0; i < N; i++) {
            count = 1;
            for (int j = i + 1; j < N; j++) {
                if (count + 1 <= C && T[j] <= T[i] + K) {
                    count++;
                } else {
                    i = j - 1;
                    ans++;
                    break;
                }
            }
        }
        if (count >= 0) {
            ans++;
        }
        System.out.println("\n" + ans);
    }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
int dy[4] = {-1,0,0,1};
int dx[4] = {0,1,-1,0};


int main(){

  ll n,m;
  cin >> n >> m;
  ll sum = 0;
  map<ll,ll> mp;
  mp[sum]++;
  rep(i,n){
    ll x;cin >> x;
    (sum += x)%= m;
    mp[sum]++;
  }
  ll res =0;
  for(auto itr = mp.begin();itr != mp.end();itr++)res += (*itr).second*((*itr).second-1ll)/2;
  cout << res << endl;





  

  return 0;
}

Measured memory_bytes: 4224
# リストに格納する
l = []
lk = []
lv = []
n = int(input())
for _ in range(n):
    s, p = input().split()
    l.append(f"{s} {p}")
    lk.append(s)
    lv.append(int(p))


# リストを辞書に変換する
d = {}
for i in range(n):
    s, p = lk[i], lv[i]
    if s in d:
        d[s].append(p)
    else:
        d[s] = []
        d[s].append(p)


# 辞書をソートする・答えを出力する
d = dict(sorted(d.items()))
for k, v in d.items():
    d[k] = sorted(v, reverse=True)
    for i in d[k]:
        print(l.index(f"{k} {i}") + 1)

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

int main()
{
    int h, w, distance[10], c[10][10];
    std::fill(distance, distance + 10, 100000);
    scanf("%d%d", &h, &w);
    for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++)
            scanf("%d", c[i] + j);

    distance[1] = 0;
    int pre_min{1};
    bool visited[10]{};
    visited[1] = true;
    for (int i = 1; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
            distance[j] = std::min(distance[j], distance[pre_min] + c[j][pre_min]);

        int min_j = 5000000, min = 10000000;
        for (int j = 0; j < 10; j++)
            if (!visited[j] && distance[j] < min)
            {
                min_j = j;
                min = distance[j];
            }
        pre_min = min_j;
        visited[min_j] = true;
    }

    int num[10]{}, ans{};
    for (int i = 0; i < h * w; i++)
    {
        int a;
        scanf("%d", &a);
        if (a >= 0)
            num[a]++;
    }
    for (int i = 0; i < 10; i++)
        ans += num[i] * distance[i];

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
a = A[0]
for i in range(1, n):
  a ^= A[i]
c = Counter(A)
if a == 0:
  if len(c) == 3 and all(v == n // 3 for v in c.values()):
    print('Yes')
  elif len(c) == 2 and c.get(0) > 0 and n - c[0] == 2 * c[0]: 
    print('Yes')
  elif len(c) == 1 and c.get(0) == n:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 14468
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	var ans int
	for i := 0; i < 5; i++ {
		x := scanInt()
		if x == 0 {
			ans = i + 1
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1756
#include<stdio.h>
#include<string>
using namespace std;

int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if ((c-a <= d && c-a >= -d) || (b-a <= d && b-a >= -d && c-b <=d && c-b >=-d)) printf("%s\n", "Yes");
  else printf("%s\n", "No");
}

Measured memory_bytes: 128
#include<iostream>
 
using namespace std ;
int main()
{
    int a,b;
    cin>>a>>b;
 
    if(a>=13){
        cout<<b<<endl;
    }
    else if(a<=12&&a>=6){
        cout<<b/2<<endl;
    }
    else if(a<=5){
        cout<<0<<endl;
    }
 
    return 0;
}

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

int main() {
    long long N,M;
    cin >> N >> M;
    long long b = 0;
    unordered_map<long long, long long> B;
    B[0] = 1;
    for(int i=0; i<N; ++i) {
        long long tmp; cin >> tmp;
        b += tmp;
        B[b % M] += 1;
    }
    long long ans = 0;
    for(auto itr = B.begin(); itr != B.end(); ++itr) {
        ans += itr->second * (itr->second-1) / 2LL;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<ll> p, q, r;
  for (int i = 0; i < a; i++) {
    ll t;
    cin >> t;
    p.push(t);
  }
  for (int i = 0; i < b; i++) {
    ll t;
    cin >> t;
    q.push(t);
  }
  for (int i = 0; i < c; i++) {
    ll t;
    cin >> t;
    r.push(t);
  }

  for (int i = 0; i < x; i++) {
    r.push(p.top());
    p.pop();
  }
  for (int i = 0; i < y; i++) {
    r.push(q.top());
    q.pop();
  }

  ll ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += r.top();
    r.pop();
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 8048