akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );

ll K;
vector< vector<LP> > G(100005);
vector<ll> D(100005);
vector<bool> B(100005);
stack<ll> s;
ll a;

void dfs(){
    if(s.empty()==false){
        a=s.top();
        B[a]=true;
        if(G[a].size()==0){
            s.pop();
        }else{
            if(B[G[a].back().first]==false){
                B[G[a].back().first]=true;
                s.push(G[a].back().first);
                D[G[a].back().first]=D[a]+G[a].back().second;
                G[a].pop_back();
            }else if(G[a].size()>1){
                swap(G[a].back(),G[a].front()); //親を消すのを後回しにする
            }else{
                G[a].pop_back(); //aに繋がるノードが１つになったらそれは親なので消す
            }

        }
        dfs();

    }

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin>>N;
    
    ll a,b,c;
    FOR(i,0,N-1){
        cin>>a>>b>>c;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    ll Q;
    cin>>Q>>K;
    s.push(K);
    D[K]=0;
    
    dfs();

    ll x,y;
    FOR(i,0,Q){
        cin>>x>>y;
        cout<<D[x]+D[y]<<endl;
    }  
    
    /*FOR(i,0,6){
        cout<<i<<D[i]<<endl;
    }*/
    
}
//r

Measured memory_bytes: 10268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
int n;cin>>n;
n=n%10;
if(n==3){
    cout << "bon" << endl;
}else if((n==0||n==1)||(n==6||n==8)){
    cout << "pon" << endl;
}else{
    cout << "hon" << endl;
}

}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
using namespace std;
#define MIRROR 1

int main()
{
    string ss;
    int ans = 0;
    while(cin>>ss)
    {
        int f = 1;
        for(int i=0;i<ss.length();++i)
        {
            if(ss[i]!=ss[ss.length()-i-1] ){f = 0;}

        }

        if(f==1) {ans += 1; }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,h,m=0,s=0,c=0;
  cin>>n>>h;
  vector<ll> a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    if(m<a[i]) m=a[i];
  }
  for(int i=n-1;i>=0;i--){
    if(b[i]>=m){
      s+=b[i];
    }else{
      b.erase(b.begin()+i);
    }
  }
  if(s>=h){
    sort(b.begin(),b.end(),greater<ll>());
    for(int i=0;i<b.size();i++){
      h-=b[i];
      c++;
      if(h<=0){
        cout<<c;
        return 0;
      }
    }
  }else{
    h-=s;
    c+=b.size();
    if(h%m!=0) c++;
    c+=h/m;
    cout<<c;
  }
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		long A=sc.nextLong();
		long B=sc.nextLong();
		long C=sc.nextLong();
		long D=sc.nextLong();
		long tmp=A-1;
		long miman=0;
		miman=tmp/C+tmp/D-tmp/(lcm(C,D));
		long max=B/C+B/D-B/lcm(C,D);
		pl((B-A+1)-(max-miman));
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	public static long lcm(long m, long n) {
		return m / gcd(m, n)*n;
	}
	public static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
		if(n == 0) return m;
		return gcd(n, m % n);
	}
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  ll c0 = 0LL;
  ll c1 = 0LL;
  ll c2 = 0LL;
  ll c3 = 0LL;
  rep(i,n) {
    string s;
    cin >> s;
    if(s=="AC") c0++;
    if(s=="WA") c1++;
    if(s=="TLE") c2++;
    if(s=="RE") c3++;
  }
  cout << "AC x " << c0 << endl;
  cout << "WA x " << c1 << endl;
  cout << "TLE x " << c2 << endl;
  cout << "RE x " << c3 << endl;
  return 0;
}

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


Measured memory_bytes: 2120
#include <iostream>
#include <algorithm>
using namespace std;
    int c[1005],s[1005],f[1005];
    int dp[505][505];
    int ans[1005];
int main()
{
    int n,i,j;
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>c[i]>>s[i]>>f[i];
    for(i=1;i<=n-1;i++)
    {
        for(j=i+1;j<=n;j++)
        {//cout<<i<<" "<<j<<endl;
            if(dp[i][j-1]<s[j])
                dp[i][j]=s[j]+c[j];
            else
            {
                int temp=dp[i][j-1]/f[j];
                if(dp[i][j-1]%f[j])
                    temp++;
                dp[i][j]=temp*f[j]+c[j];
            }
        }
    }
    for(i=1;i<=n;i++)
        cout<<dp[i][n]<<endl;
    return 0;
}


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

if S != 10 ** 9:
    print(' '.join(map(str, [S] * K)),' '.join(map(str, [10 ** 9] * (N - K))))
else:
    print(' '.join(map(str, [S] * K)), ' '.join(map(str, [1] * (N - K))))

Measured memory_bytes: 11284
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long int ll;
const int N=1e5+5;
int n,a[3][N],memo[4][N];
int solve(int ind, int prev){
    if(ind==n)
        return 0;
    if(~memo[prev][ind])
        return memo[prev][ind];
    int ret=0;
    for(int i=0;i<3;i++){
        if(i==prev&&ind)
            continue;
        ret=max(ret,(a[i][ind]+solve(ind+1,i)) );
    }
    return memo[prev][ind]=ret;
}
int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    memset(memo,-1,sizeof memo);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[0][i]>>a[1][i]>>a[2][i];
    cout<<solve(0,0)<<'\n';
    return 0;
}


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

struct BIT{
    int N;
    vector<int> dat;
    public:
    BIT(int n):N(n),dat(n+1,0){}
    void add(int pos,int val){
        pos++;
        while(pos<=N){
            dat[pos]+=val;
            pos+=pos&-pos;
        }
    }
    //sum of [0,pos) (dat[1..pos])
    int sum(int pos){
        int res=0;
        while(pos>0){
            res+=dat[pos];
            pos-=pos&-pos;
        }
        return res;
    }
    void debug(){
        for(int i=0;i<dat.size();i++){
            cout<<"#"<<i<<": "<<dat[i]<<endl;
        }
        return;
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    BIT bit(m+3);
    vector<pair<int,int>> lr(n);
    for(int i=0;i<n;i++){
        cin>>lr[i].first>>lr[i].second;
        lr[i].second++;
        bit.add(lr[i].second,1);
    }
    sort(lr.begin(),lr.end());
    vector<vector<int>> events(m+3);
    for(int i=0;i<m;i++) events[0].push_back(i);
    vector<int> ans(m,n);
    int inde=0;
    for(int i=0;i<=m;i++){
        while(inde<n && lr[inde].first<=i){
            bit.add(lr[inde].second,-1);
            inde++;
        }
        for(int j=0;j<events[i].size();j++){
            int l=i+1,r=i+events[i][j]+1;
            if(r>m+2) r=m+2;
            ans[events[i][j]]-=(bit.sum(r+1)-bit.sum(l));
            if(r<m) events[r].push_back(events[i][j]);
        }
    }
    for(int i=0;i<m;i++) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 14840
#include <iostream>

using namespace std;

// return x^n % mod
// It take O(log{n})
long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    // 最下位bitが立っていたら x^{2^i}を掛ける
    if (n & 1) { res = res * x % mod; }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

// return x^{-1} % mod
// it take O(log{mod})
long long mod_inverse(long long x, long long mod) {
  return mod_pow(x, mod-2, mod);
}

// return nCk % mod
// It take O(k)
long long mod_comb(long long n, long long k, long long mod) {
  long long numer = 1, denom = 1;
  for (long long i = 0; i < k; i++) {
    // numer: 分子, denom: 分母
    numer = numer * ((n-i) % mod) % mod;
    denom = denom * ((i+1) % mod) % mod;
  }
  return numer * mod_inverse(denom, mod) % mod;
}

int main() {
  long long n, a, b;
  long long mod = 1000000007;

  cin >> n >> a >> b;

  long long ans = mod_pow(2, n, mod)-1;
  ans -= mod_comb(n, a, mod);
  ans %= mod;
  ans -= mod_comb(n, b, mod);
  ans %= mod;
  cout << (ans + mod) % mod << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
    
    int n, m;

    std::cin >> n >> m;
    std::vector<int> cnt(m, 0);

    for(int i = 0; i < n; i++){
        int k;
        std::cin >> k;
        for(int j = 0; j < k; j++){
            int tmp;
            std::cin >> tmp;
            cnt[tmp-1]++;
        }
    }

    std::cout << std::count(cnt.begin(), cnt.end(), n) << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	int n, k;
	int a[100000];
	for(;;){
		cin >> n >> k;
		if(n == 0 && k == 0) break;
		for(int i = 0; i < n; i++) scanf("%d", &a[i]);
		ll ans = 0;
		for(int i = 0; i < k; i++){
			ans += a[i];
		}
		ll sum = ans;
		for(int i = k; i < n; i++){
			sum -= a[i - k];
			sum += a[i];
			if(sum > ans) ans = sum;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAs[i]
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define ar array
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void init() {
  string s;
  cin >> s;
  stack<char> st;
  int ans = 0;
  for (int i = 0; i < (int)s.size();) {
    if (!st.empty() and (s[i] - '0') ^ (st.top() - '0')) {
      while (i < (int)s.size() and !st.empty() and
             (s[i] - '0') ^ (st.top() - '0'))
        st.pop(), ++ans, i++;
    } else
      st.push(s[i]), i++;
  }
  cout << 2 * ans << endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 3820
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
menu=[a,b,c,d,e]
time=0
for i in ["1","2","3","4","5","6","7","8","9","0"]:
    if i in [str(a)[-1],str(b)[-1],str(c)[-1],str(d)[-1],str(e)[-1]]:
        mi=[str(a)[-1],str(b)[-1],str(c)[-1],str(d)[-1],str(e)[-1]].index(i)
        break
minu=menu[mi]
for i in range(len(menu)):
    if i!=mi:
        time+=menu[i]
        while time%10!=0:
            time+=1
time+=minu
print(time)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD = 1000000007;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

int get_digit(ll x){
    int ret = 0;
    while(x > 0){
        x /= 10;
        ret++;
    }
    return ret;
}

int main(){
    ll N;
    cin >> N;
    int i = sqrt(N);
    while(i > 1){
        if(N%i == 0) break;
        i--;
    }
    cout << max(get_digit(i),get_digit(N/i)) << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new A().doIt();
//		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	}
	class A{
		void doIt() {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int h = sc.nextInt();
			System.out.println((a + b)*h/2);
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[1010];
bool ok[1000010];

int main(){
    ll n, k;
    cin >> n >> k;
    rep(i, n) cin >> a[i];

    vector<ll> v;
    
    rep(i, n){
        ll now = 0;
        for(int j = i; j < n; j++){
            now += a[j];
            v.push_back(now);
        }
    }

    int m = v.size();
    rep(i, m) ok[i] = 1;

    ll ans = 0;
    rrep(d, 60){
        ll mask = 1ll << d;
        int cnt = 0;
        rep(i, m) if((v[i]&mask) && ok[i]) cnt++;
        if (cnt >= k){
            ans += mask;
            rep(i, m) if (!(v[i] & mask) and ok[i]) ok[i] = 0;
        }
    }

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


Measured memory_bytes: 7696
import heapq

pq = []
# 

W, H = map(int, input().split())
for i in range(W):
	heapq.heappush(pq, (int(input()), 'W'))
for i in range(H):
	heapq.heappush(pq, (int(input()), 'H'))

W += 1
H += 1

ans = 0
while pq:
	(num, dire) = heapq.heappop(pq)
	if dire == 'W':
		ans += num * H
		W -= 1
	else:
		ans += num * W
		H -= 1

print(ans)


Measured memory_bytes: 81624
#include <iostream>
using namespace std;
int main(){
string a,b,u;
int s,t;
cin >> a >> b ;
cin >> s >> t ;
cin >> u ;
if (u==a){
    s--;
    cout << s << " " << t ;
}
else if (u==b){
    t--;
    cout << s << " " << t ;
}
return 0;
}


Measured memory_bytes: 256
while True:
    HW = input()
    HW_list = HW.split(" ")
    H = int(HW_list[0])
    W = int(HW_list[1])
    if H == 0 and W == 0:
        break
    print("#" * W)
    for _ in range(H - 2):
        print("#" + "." * (W - 2) + "#")
    print("#" * W)
    print()



Measured memory_bytes: 5612
#include <stdio.h>

typedef struct{
    char name[10];
    int time;
}process_t;

int n = 0, head = 0, tail = 0;

void enqueue(process_t Q[], process_t a){
    Q[tail] = a;
    if(tail == n - 1){
        tail = 0;
    }
    else{
        tail += 1;
    }
}

process_t dequeue(process_t Q[]){
    if(head == n - 1){
        head = 0;
        return Q[n - 1];
    }
    else{
        head += 1;
        return Q[head - 1];
    }
}

int main( void ){
    int q, i, sum = 0;
    scanf("%d %d", &n, &q);
    process_t Q[n];
    for(i = 0; i < n; i++){
        scanf("%s %d", Q[i].name, &Q[i].time);
    }
    i = 0;
    while(i < n){
        if(Q[head].time <= q){
            sum += Q[head].time;
            printf("%s %d\n", Q[head].name, sum);
            dequeue(Q);
            i++;
        }
        else{
            sum += q;
            Q[head].time -= q;
            enqueue(Q, Q[head]);
            dequeue(Q);
        }
    }
    return 0;
}



Measured memory_bytes: 2520
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  int p = 0;
  int n = s.size();
  rep(i, n) if(s[i] == 'p') p++;
  cout << n / 2 - p << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<functional>
#include<cmath>
#include<list>

using namespace std;

int main() {
   int N, M;
   cin >> N >> M;
   bool visited[ N ] = { false };
   int dp[ N ];
   for( int i = 0; i < N; i++ ) {
      dp[ i ] = -1;
   }

   list<int> adjList[ N ];
   for( int i = 0; i < M; i++ ) {
      int a, b;
      cin >> a >> b;
      adjList[ a - 1 ].push_back( b - 1 );
   }

   function< int ( int ) > dfs;
   dfs = [ & ] ( int i ) -> int {
      if( dp[ i ] != - 1 ) {
         return dp[ i ];
      }
      int max = 0;
      for( auto iter : adjList[ i ] ) {
         auto m = dfs( iter );
         max = max > m + 1 ? max : m + 1;
      }
      dp[ i ] = max;
      visited[ i ] = true;
      return max;
   };

   int max = 0;
   for( int i = 0; i < N; i++ ) {
      if( visited[ i ] == 0 ) {
         auto m = dfs( i );
         max = max > m? max : m;
      }
   }
   cout << max;

   return 0;
}


Measured memory_bytes: 8192
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



map<vector<int>,ll> solved;

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

ll GCD(vector<int> arr, int n)
{
    
    int result = arr[0];
    for (int i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);
  
        if(result == 1)
        {
           return 1;
        }
    }
    return result;
}

int main(){
    int k;
    cin >> k;
    
    
    ll ans = 0;
    FOR(i,1,k+1){
        FOR(j,1,k+1){
            FOR(ij,1,k+1){
                ll a = GCD({i,j,ij},3);
                ans += a;
            }
        }
    }
    cout << ans;
    rn 0;
}

















Measured memory_bytes: 3636
import re

n,a,b,c,d = map(int, input().split())
li = input()

pat1 = '##'
pat2 = r'\.\.\.'

ret = ''

a2c = li[a:c]
b2d = li[b:d]
if re.search(pat1, a2c) or re.search(pat1, b2d):
    ret = 'No'
else:
    if c > d:
        carea = li[b-2:d+1]
        if re.search(pat2, carea):
            ret = 'Yes'
        else:
            ret = 'No'
    else:
        ret = 'Yes'


print(ret)

Measured memory_bytes: 3764
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int x;
	cin >> x;

	if (x == 3 || x == 5 || x == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

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

int N;

int digit_num(int x) {
  int d = 0;
  while (x > 0) {
    x /= 10; d++;
  }
  return d;
}

int main() {
  cin >> N;
  int c = 0;
  for (int i = 1; i <= N; i++) {
    c += digit_num(i) % 2;
  }
  cout << c << endl;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
typedef long long LL;
const int N = 500+5;
LL a[N];
LL b[N];

int check(int n,LL mod,LL k){
    //printf("mod = %lld\n",mod);
    LL total = 0;
    for(int i = 1; i <= n; i++){
        LL add = a[i]%mod;
        total += add;
        b[i] = add;
        //printf("%lld ",b[i]);
    }
    //printf("\n");
    std::sort(b+1,b+1+n);
    int c = total/mod;
    LL need = 0;
    for(int i = n; i >= n-c+1; i--){
        need += (mod-b[i]);
    }
    if(total%mod || need>k) return 0;
    else return 1;
}

LL max(LL a,LL b){ return a>b?a:b; }

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    LL ans = 1;
    LL sum = 0;
    for(int i = 1; i <= n; i++) scanf("%lld",&a[i]), sum += a[i];
    /*for(int i = 1e6; i >= 1; i--) {
        if(check(n,i,k)){ 
            printf("%d\n",i);
            break;
        }
    }*/
    for(int i = 1; i*i<=sum; i++){
        if(sum%i==0){
            //printf("i = %d, sum/i = %lld\n",i,sum/i);
            if(check(n,i,k)) ans = max(ans,i);
            if(check(n,sum/i,k)) ans = max(ans,sum/i);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
//using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 998244353;
const double eps = DBL_EPSILON;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL_DEBUG
    freopen("input.txt", "r", stdin);
#endif
    ll x;
    cin >> x;
    ll ans = 1000 * (x / 500);
    x %= 500;
    cout << ans + 5 * (x / 5) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;
const ll MOD = 1000000007;


ll fac[200000+10];
ll inv(ll a, ll p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }

inline ll calc(int h, int w) {
  return fac[h+w-2] * inv(fac[h-1], MOD) % MOD * inv(fac[w-1], MOD) % MOD;
}

int main(void) {
  fac[0] = 1;
  for(int i = 1; i <= 200000; ++i) {
    fac[i] = fac[i-1] * i % MOD;
  }

  int H, W, A, B;
  scanf("%d%d%d%d", &H, &W, &A, &B);
  
  ll res = 0;
  for(int i = 1; i <= H - A; ++i) {
    res += calc(i, B) * calc(H-i+1, W-B) % MOD;
    res %= MOD;
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNextInt()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int n = sc.nextInt();
			char[] c = Double.toString((double) a / b).toCharArray();
			int i = 0;
			int s = 0;
			for (i = 0; i < c.length; i++)
				if (c[i] == '.')
					break;
			if (i == c.length)
				System.out.println(0);
			for (int j = i + 1; j < c.length && n-- > 0; j++) {
				s += (c[j] - '0');
			}
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
using namespace std;
#define N 1001
int ans[N];
int sum[N];
int sumn(int n){
  return (n*(n-1))/2;
}
int sumsub(int s, int e){
  return sum[e] - sum[s];
}
int main(){
  for(int i = 0; i < N; ++i){
    sum[i] = sumn( i );
  }
  for(int i = 1; i < N; ++i){
    for(int j = i+2; j < N; ++j){
      if(sumsub(i,j)<1||sumsub(i,j)>=N)continue;
      ans[ sumsub(i,j) ]++;
    }
  }
  while(true){
    int q;
    cin >> q;
    if(q==0)break;
    cout << ans[q] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
	long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
  long memo = 0;
  long a = 0;
  long answer = long.MaxValue;

  for(long i = 1; i <= n-1; i++)
  {
    memo = 0;
    memo += i/100000 + (i/10000)%10 + (i/1000)%10 +(i/100)%10 +(i/10)%10 + i%10;
    a = n - i;
    memo += a/100000 + (a/10000)%10 + (a/1000)%10 +(a/100)%10 +(a/10)%10 + a%10;
    answer = Math.Min(answer, memo);
  }
  
	Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 13140
def GCD(a, b):
    if b == 0:
        return a
    else:
        return GCD(b, a % b)

def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))

    ans = 0
    for i in x:
        ans = GCD(ans, abs(X - i))
    print(ans)

    return 0


if __name__ == '__main__':
    main()

Measured memory_bytes: 15020
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a  

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start

// ModInt
type ModInt = MVal of int64

[<RequireQualifiedAccess>]
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module ModInt =
  let modulo = (int64 1e9)+7L

  let inline init (x: ^a): ModInt =
    let x = (int64 x) % modulo
    match x with
    | _ when x < 0L -> MVal (x + modulo)
    | _ -> MVal x
  
  let value (MVal x) = x
  
type ModInt with
  static member inline ( + ) (lhs: ModInt, rhs: ModInt) =
    let (MVal x), (MVal y) = (lhs, rhs)
    ModInt.init (x+y)
  static member inline ( - ) (lhs: ModInt, rhs: ModInt) =
    let (MVal x), (MVal y) = (lhs, rhs)
    ModInt.init (x-y)
  static member inline ( * ) (lhs: ModInt, rhs: ModInt) =
    let (MVal x), (MVal y) = (lhs, rhs)
    ModInt.init (x*y)
  static member inline ( / ) (lhs: ModInt, rhs: ModInt) =
    let rec pow n m = (if (m&&&1L)=1L then n else ModInt.init 1) * (if m=0L then ModInt.init 1 else (pow (n*n) (m>>>1)))
    let invB = pow rhs (ModInt.modulo-2L)
    lhs * invB
// ModInt

let rec pow n m = 
  (if (m&&&1L)=1L then n else ModInt.init 1) * (if m=0L then ModInt.init 1 else (pow (n*n) (m>>>1)))
 
let C n r =
  let rec P n r =
    seq { (n-r+1L)..n }
    |> Seq.map ModInt.init
    |> Seq.fold ( * ) (ModInt.init 1)
  (P n r) / (P r r)

let (n, a, b) = readStr().Split() |> Array.map (int64) |> triple
let r =
  pow (ModInt.init 2) n
  - C n a
  - C n b
  - ModInt.init 1

printfn "%d" (ModInt.value r)

Measured memory_bytes: 18232
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = input()
    l = len(S)
    m = l - 7

    def judge():
        for i in range(l - m + 1):
            first = S[:i]
            second = S[i + m:]
            if first + second == "keyence":
                return True
        return False

    print("YES" if judge() else "NO")


if __name__ == '__main__':
    main()


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;
const ll inf = 1e18;

template<typename T> struct segtree {
    
    T merge(T x, T y) {
	return min(x, y);
    }
    int n;
    vector<ll> t;
    void init(int n) {
	n += 10;
	this->n = n;
	t.resize(n*4, inf);
    }

    void upd(int v, int tl, int tr, int i, T val) {
	if (tl == tr) {
	    t[v] = merge(t[v], val);
	} else {
	    int tm = (tl+tr)/2;
	    if (i<=tm) {
		upd(2*v,tl,tm,i,val);
	    } else {
		upd(2*v+1,tm+1,tr,i,val);
	    }
	    t[v] = merge(t[2*v], t[2*v+1]);
	}
    }

    T qry(int v, int tl, int tr, int l, int r) {
	if (l>tr || r<tl) {
	    return inf;
	}
	if (l <= tl && tr <= r) {
	    return t[v];
	}
	int tm = (tl+tr)/2;
	return merge(qry(2*v,tl,tm,l,r), qry(2*v+1,tm+1,tr,l,r));
    }
};

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n, m;
vector<pair<ll,int>> ev[maxn]; //(cost, to)

segtree<ll> dp;

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

    cin>>n>>m;
    while (m--) {
	int l,r,c;
	cin>>l>>r>>c;
	ev[l].push_back({c,r});
    }

    dp.init(n+10);
    dp.upd(1,1,n,n,0);


    for (int i=n-1; i>=1; i--) {
	for (auto p: ev[i]) {
	    ll cost = p.first;
	    int to = p.second;
	    ll cur = dp.qry(1,1,n,i+1,to);
	    dp.upd(1,1,n,i,cost+cur);
	}
    }

    ll ans = dp.qry(1,1,n,1,1);
    if (ans == inf) ans = -1;
    cout<<ans<<endl;    
    return 0;
}


Measured memory_bytes: 32640
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline long long read()
{
	long long kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
LL n;
struct zj
{
	LL val,od;
}cun[2022];
bool cmp(zj a,zj b){return a.val>b.val;}
LL dp[2][2002];
int main()
{
	n=read();
	for(int i=1;i<=n;++i)
	{
		cun[i].val=read();cun[i].od=i;
	}
	sort(cun+1,cun+1+n,cmp);
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	for(int i=1;i<=n;++i)
	{
		int now=i&1,per=now^1;
		memset(dp[now],-1,sizeof(dp[now]));
		for(int j=0;j<=i;++j)
		{
			if(dp[per][j]!=-1)
			{
				dp[now][j+1]=
				max(dp[now][j+1],dp[per][j]+cun[i].val*abs(cun[i].od-(j+1)));
				dp[now][j]=
				max(dp[now][j],dp[per][j]+cun[i].val*abs(cun[i].od-(n-i+j+1)));
			}	
		}
	}
	LL asd=0;
	for(int i=0;i<=n;++i)asd=max(asd,dp[n&1][i]);
	printf("%lld\n",asd);
}

Measured memory_bytes: 3796
A,B,C,D = list(input())
import itertools
for ops in itertools.product(['+','-'],repeat=3):
  eq = A+ops[0]+B+ops[1]+C+ops[2]+D
  x = eval(eq)
  if x == 7:
    break
    
answer = eq + '=7'
print(answer)

Measured memory_bytes: 3060
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

A4 = []
A5 = []
A6 = []
A7 = []
A8 = []

A4.append(A1[0])
A4.append(A2[0])
A4.append(A3[0])

A5.append(A1[1])
A5.append(A2[1])
A5.append(A3[1])

A6.append(A1[2])
A6.append(A2[2])
A6.append(A3[2])

A7.append(A1[0])
A7.append(A2[1])
A7.append(A3[2])

A8.append(A1[2])
A8.append(A2[1])
A8.append(A3[0])

if b.count(A1[0]) + b.count(A1[1]) + b.count(A1[2]) == 3:
    print ("Yes")
    exit (0)
if b.count(A2[0]) + b.count(A2[1]) + b.count(A2[2]) == 3:
    print ("Yes")
    exit (0)
if b.count(A3[0]) + b.count(A3[1]) + b.count(A3[2]) == 3:
    print ("Yes")
    exit (0)
if b.count(A4[0]) + b.count(A4[1]) + b.count(A4[2]) == 3:
    print ("Yes")
    exit (0)
if b.count(A5[0]) + b.count(A5[1]) + b.count(A5[2]) == 3:
    print ("Yes")
    exit (0)
if b.count(A6[0]) + b.count(A6[1]) + b.count(A6[2]) == 3:
    print ("Yes")
    exit (0)
if b.count(A7[0]) + b.count(A7[1]) + b.count(A7[2]) == 3:
    print ("Yes")
    exit (0)
if b.count(A8[0]) + b.count(A8[1]) + b.count(A8[2]) == 3:
    print ("Yes")
    exit (0)

print ("No")

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

using namespace std;

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  int a, b;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (h <= a && w <= b) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

gcd = 1
for k, v in factorization(p):
    if v // n > 0:
        gcd *= k ** (v // n)
print(gcd)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int n, x, a[110], cnt=0;
    cin>>n>>x;
    for (int i=0; i<n; i++) cin>>a[i];
    sort(a, a+n);
    for (int i=0; i<n; i++)
    {
        if (i<n-1) if (x-a[i]>=0) { x-=a[i]; cnt++; }
        if (i==n-1) if (x-a[i]==0) {x-=a[i]; cnt++; }
    }
    cout<<cnt<<endl;
    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {
  string s, t;
  int a, b, c, x, y, z, N;

  cin >> s;
  rep(i, 4) {
    cout << s[i];
  }

  cout << " ";

  REP(i, 4, s.size()) {
    cout << s[i];
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

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

    ll sum = 0;
    for(ll i = 1; i <= number; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            sum += i;
        }
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <bitset>
#define MAX_N 1010

using namespace std;
class BIT2D{
  /*binary indexed tree*/
 private:
  long long data[MAX_N][MAX_N];
  int xsize;
  int ysize;
 public:
  void init(int x, int y){
    memset(data,0,sizeof(data));
    xsize = x;
    ysize = y;
  }
  long long sum( int x1, int y1, int x2, int y2 ){
    // return sum ((x1,y1), (x2,y2)] ... means [(x1+1,y1+1),(x,y)]
    return sum_(x2,y2)-sum_(x1,y2)-sum_(x2,y1)+sum_(x1,y1);
  }
  long long sum_(int x, int y){
    // return sum ((0,0), (x,y)] ... means [(1,1),(x,y)]
    long long ans = 0;
    for( int i = x ; 0 < i; i -=i&-i ){
      for( int j = y;  0 < j; j -= j&-j ){
        ans += data[i][j];
      }
    }
    return ans;
  }
  void add(int x, int y, int v){
    // add v to (x,y)
    for( int i = x ;  i <= xsize; i += i&-i ){
      for( int j = y ; j <= ysize; j+= j&-j ){
        data[i][j] += v;
      }
    }
    return;
  }
};
typedef struct info{
   int x,y,c;
}info;
int main(){
   int N,K;
   cin >> N>>K;
   vector<info> v;
   for(int i = 0 ; i < N; i++){
      info d;
      char c;
      cin >> d.x >> d.y; 
      cin >> c;
      if( c =='B' ) d.c=1;
      else d.c=0;
      v.push_back(d);
   }
   //cout <<"input finished"<<endl;
   BIT2D bit[2];
   bit[0].init(K+2,K+2);
   bit[1].init(K+2,K+2);
   int sum[2];
   sum[0]=sum[1]=0;
   for( int i = 0 ; i < N; i++){
      int nx = v[i].x/K;
      int ny = v[i].y/K;
      if( (nx+ny)%2 !=0 ){
         v[i].c = 1-v[i].c;
      }
      v[i].x%=K;
      v[i].y%=K;
      sum[v[i].c]++;
      //cout << v[i].x << ", "<< v[i].y <<", "<< v[i].c<<endl;
      bit[v[i].c].add(v[i].x+1,v[i].y+1,1);
   }
   int ans =0;
   for( int x = 1; x <= K+1; x++){
      for( int y = 1 ; y <= K+1; y++){
         for( int c =0; c<2; c++){
            int curAns = bit[c].sum_(x,y)+bit[c].sum(x,y,K+2,K+2)+sum[1-c]-bit[1-c].sum_(x,y)- bit[1-c].sum(x,y, K+2, K+2);
            ans=max(ans,curAns);
         }
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 17524
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int n, d, x;
  cin >> n >> d >> x;
  int ans = x;
  int a;
  REP(i,n){
    cin >> a;
    ans += (d - 1)/a + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def bubble_sort(c):
    c = list(c)
    for i in range(len(c)):
        for j in range(len(c)-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j]
    return c

def selection_sort(c):
    c = list(c)
    for i in range(len(c)):
        minj = i
        for j in range(i+1, len(c)):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c

input_num = int(input())
input_list = input().split()
bubble_list = bubble_sort(input_list)
selection_list = selection_sort(input_list)
for c in bubble_list:
    print(c, end='')
    if c != bubble_list[len(bubble_list)-1]:
        print(' ', end='')
print("\nStable")
stable_flg = True
for i in range(len(input_list)):
    if bubble_list[i] != selection_list[i]:
        stable_flg = False
    print(selection_list[i], end='')
    if i < len(input_list)-1:
        print(" ", end='')
if stable_flg:
    print("\nStable")
else:
    print("\nNot stable")

Measured memory_bytes: 7760
n = int(input())
s = input()
 
answer = s.count('R') * s.count('G') * s.count('B')

for i in range(n - 2):
  j = i + 1
  while((i + 1) + (j - i) * 2 <= n):
    if s[i] != s[j] and s[j] != s[i + (j - i) * 2] and s[i] != s[i + (j - i) * 2]:
      answer -= 1
    j += 1
 
print(answer)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n,m,ans=0;cin>>n>>m;
    vi v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    ll ok=inf,ng=0;
    while(ok-ng>1){
        ll mid=(ng+ok)/2;
        ll sum=0;
        rep(i,n)sum+=n-ub(v,mid-v[i]);
        if(sum<=m)ok=mid;
        if(sum>m)ng=mid;
        if(sum==m)break;
    }
    ll sum=0;vi num(n);
    rep(i,n){
        ll k=lb(v,ok-v[i]);
        num[k]++;
        ans+=(n-k)*v[i];
        sum+=n-k;
    }
    if(sum>m)ans-=ok*(sum-m);
    rep(i,n-1)num[i+1]+=num[i];
    rep(i,n)ans+=v[i]*num[i];
    cout<<ans<<endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;
int k;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &k);

  printf("%d\n", n - k + 1);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<sstream>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define strep(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<int,int>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<int>
#define rs resize
int main()
{
   std::ios::sync_with_stdio(false);
   int n,i,ans = 0;
   cin>>n;
   bool visit[n+1];
   int a[n+1];
   rep(i,1,n+1)
   {
     cin>>a[i];
     visit[i] = false;
   }
   i = 1;
   bool flag = false;
   while(visit[i]== false)
   {
     if(i==2)
     {
       flag = true;
       break;
     }
     ans++;
     visit[i] = true;
     i = a[i];
   }
   if(flag)
    cout<<ans;
   else
    cout<<-1;
   return 0;
}


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

int dp[3000][3000];
int choice[3000][3000];

int main()
{
        string s,t;
        cin>>s;
        cin>>t;
        int n=s.size(),m=t.size();
        dp[0][0]=0;
        if(s[0]==t[0])
        {
            dp[0][0]=1;
            choice[0][0]=2;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(i>0)
                {
                    dp[i][j]=dp[i-1][j];
                    choice[i][j]=0;
                }
                if(j>0)
                {
                    if(dp[i][j-1]>dp[i][j])
                    {
                    dp[i][j]=dp[i][j-1];
                    choice[i][j]=1;
                    }
                }
                if(s[i]==t[j])
                {
                    int ans=1;
                    if(i>0 && j>0)
                    {
                        ans=1+dp[i-1][j-1];
                    }
                    if(ans>dp[i][j])
                    {
                        dp[i][j]=ans;
                        choice[i][j]=2;
                    }
                }
            }
        }

       int i=n-1,j=m-1;
       string subsequence;

       while(i>=0 && j>=0)
       {
            if(choice[i][j]==0)
            {
                i--;
            }
            else if(choice[i][j]==1)
            {
                j--;
            }
            else if(choice[i][j]==2){
                subsequence.push_back(s[i]);
                i--;
                j--;
            }
       }
        reverse(subsequence.begin(),subsequence.end());
       cout<<subsequence;
    return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int sam=0;
    for(int i=0;i<a;i++){
        sam += c;
    }
    if(a-b>0){
        for(int j=0;j<(a-b);j++){
            sam -= (c-d);
        }
    }
    cout << sam << endl;
    return 0;
}

Measured memory_bytes: 256
//
//  main.c
//  AIZU_ONLINE
//
//  Created by 郷田将 on 2018/02/07.
//  Copyright © 2018年 郷田将. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...

    int a;
    int b;
    int c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(c>b && b>a) printf("Yes");
    else printf("No");
    printf("\n");
    
    return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, M;
    cin >> N >> M;
    vector<set<int>> S(N);
    vector<bool> B(N, false);
    queue<int> que;
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        S[A - 1].insert(B - 1);
        S[B - 1].insert(A - 1);
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        int temp = 0;
        if(B[i]) continue;
        que.push(i);
        while(!que.empty()){
            if(!B[que.front()]){
                temp++;
                B[que.front()] = true;
                for(const int &s : S[que.front()]) {
                    if (!B[s])
                        que.push(s);
                }
            }
            que.pop();
        }
        ans = max(ans, temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 31564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;






int M;
vector<ll> h, a;

int N;
vector<ll> dp, tree;

void update(int k, ll x) {
    k += N;
    tree[k] = x;
    for (k /= 2; k >= 1; k /= 2) {
        tree[k] = max(tree[2*k], tree[2*k+1]);
    }
}

ll query(int a, int b, int k, int x, int y) {
    if (b < x || a > y) return 0;
    if (a <= x && y <= b) return tree[k];
    int d = (x + y) / 2;
    return max(query(a, b, 2*k, x, d), query(a, b, 2*k+1, d+1, y));
}

void Main() {
    cin >> M;
    h.resize(M);
    a.resize(M);
    for (int i = 0; i < M; ++i) {
        cin >> h[i];
        --h[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> a[i];
    }
    N = 1;
    while (N < M) N *= 2;
    tree.assign(2*N, 0);
    dp.assign(M, 0);
    ll ans = 0;
    // dp[i] = a[i] + max(dp[j]) for every j < i, h[j] < h[i]
    for (int i = 0; i < M; ++i) {
        dp[i] = a[i] + query(0, h[i] - 1, 1, 0, N-1);
        ans = max(ans, dp[i]);
        update(h[i], dp[i]);
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int ans = 1000 - n%1000;
	if( ans == 1000) ans = 0;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

signed main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif
  string s;
  cin >> s;
  map<int, int> d;
  d[0] = 0;
  int m = 0;
  for (auto c : s) {
    m ^= (1 << (c - 'a'));
    int res = 1e9;
    if (d.count(m))
      res = d[m];
    for (int i = 0; i < 26; ++i) {
      int from = m ^ (1 << i);
      if (d.count(from)) {
        res = min(res, d[from] + 1);
      }
    }
    assert(res != 1e9);
    d[m] = res;
  }
  cout << max(1, d[m]) << '\n';
}

Measured memory_bytes: 9860
unittest
{
	assert( [ "redcoder" ].parse.expand.solve == 1 );
	assert( [ "vvvvvv" ].parse.expand.solve == 0 );
	assert( [ "abcdabc" ].parse.expand.solve == 2 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	auto ans = 0L;
	for( auto l = ( s.length - 1 ) / 2, r = s.length / 2; r < s.length; l--, r++ )
	{
		ans += ( s[ l ] != s[ r ] );
	}
	return ans;
}


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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll d;
    cin >> d;
    ll a = 26;
    vector<ll> c(a);
    vector<vector<ll>> s(d, vector<ll>(a));
    for(auto &e: c) cin >> e;
    for(auto &l: s) for(auto &e: l) cin >> e;
    
    vector<ll> t(d);
    for(auto &e: t) cin >> e, e--;

    vector<ll> last(a, -1);
    ll score = 0;
    for(ll i=0; i<d; i++) {
        last[t[i]] = i;

        score += s[i][t[i]];
        for(ll j=0; j<a; j++)
            score -= c[j] * (i - last[j]);
        cout << score << endl;
    }
}

Measured memory_bytes: 3704