akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N; cin >> N;
    string ans = "";
    while (N) {
        int k = (N-1)%26;
        ans += char('a'+k);
        N = (N-1)/26;
    }
    reverse(all(ans));
    cout << ans << ln;

}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin>>n;
  int ans;
  for(int i=1;i<=n;i++){
    ans=0;
    for(int x=1;x<sqrt(n);x++){
      if(x*x+1+1+x+1+x>i){
        break;
      }
      for(int y=1;y<sqrt(n);y++){
        if(x*x+y*y+1+x*y+y+x>i){
          break;
        }
        for(int z=1;z<sqrt(n);z++){
          if(x*x+y*y+z*z+x*y+y*z+z*x==i){
            ans++;
          }
          else if(x*x+y*y+z*z+x*y+y*z+z*x>i){
            break;
          }
        }
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3556
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int D=stdIn.nextInt();
		int ans=N/(D*2+1);
		if(N%(D*2+1)!=0)
			ans++;
		System.out.println(ans);
	}
}

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

int main() {
    int N,K;
    cin >> N>>K;
    vector<ll>A(N);
    for(ll &i:A)cin >> i;
    
    for(ll i=K;i<N;i++){
        if((long double)A[i]/A[i-K]>1.0)cout << "Yes"<<endl;
        else cout << "No"<<endl;
        
    }
    
}

Measured memory_bytes: 4848
#include <stdio.h>
#include <math.h>
int main()
{
    int a,b[2][200],max,m,i,j;
    scanf("%d",&a);
    for(i=0; i<2; i++)
        for(j=0; j<a; j++)
            scanf("%d",&b[i][j]);
    max=0;
    for(i=0; i<a; i++)
    {
        m=b[1][i];

        for(j=0; j<a; j++)
        {
            if(j<=i)
                m+=b[0][j];
            else m+=b[1][j];
        }
        if(m>max)
            max=m;
    }

    printf("%d",max);
    return 0;
}


Measured memory_bytes: 128
s=input()
q=int(input())
q_=[input() for i in range(q)]
l=[]
r=list(s)
reverse=False
for i in q_:
  if i=="1":
    reverse=not reverse
  elif (i.split()[1]=="1" and not reverse) or (i.split()[1]=="2" and reverse):
    l.append(i.split()[2])
  else:
    r.append(i.split()[2])
#print(l)
#print(r)
if reverse:
  print(''.join(r[::-1]+l))
else:print(''.join(l[::-1]+r))

Measured memory_bytes: 95064
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,m,a[109],num=0;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i],num+=a[i];
	sort(a,a+n);
	for(int i=n-1;i>=n-m;i--)
		if((num%(4*m)==0)?a[i]<num/(4*m):a[i]<=num/(4*m)) {
			cout<<"No\n";
			return 0;
		}
	cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n; ll a, b; cin >> n >> a >> b;
    vector<ll>X(n); rep(i, n) cin >> X[i];

    ll res = 0;
    rep(i, n-1){
        ll walk = (X[i+1] - X[i]) * a;
        res += min(walk, b);
    }
    cout << res << ln;
    }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define ld long double
#define vii vector<ii>
#define vll vector<ll>
#define maxn 111

template<typename T>
void trace(T a){ cout << a << '\n';}
template<typename T, typename... Args>
void trace(T a, Args ...args){ cout << a << ' '; trace(args...);}

ii a[maxn];
ii op = {0, 10000000};

int quad(ii a) {
	if (a.fi >= 0) 
		return a.se >= 0 ? 1 : 4;
	return a.se >= 0 ? 2 : 3;
}

int cross(ii a, ii b) {
	if (quad(a) != quad(b))
		return quad(a) < quad(b);
	else return cross(a, b) > 0;
}

bool cmp (ii x, ii y) {
	return atan2(x.second, x.first) < atan2(y.second, y.first);
}

int32_t main(){
	int n,x,y;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> x >> y;
		a[i] = {y, x};
	}
	sort(a,a+n, cmp);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int j = i, left = n, dx = 0, dy = 0;
		while (left--) {
			dx += a[j].fi;
			dy += a[j].se;
			ans = max(ans, dx*dx + dy*dy);
			j = (j+1) % n;
		}
	}
	cout << fixed << setprecision(40) << sqrt(ans) << '\n';
 	return 0;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define li long int

using namespace std;

void FAST()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}

int main()
{
    FAST();
    int i,n,k,j;cin>>n>>k;
    int h[n];
    int dp[n];
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(i=0;i<n;i++)	cin>>h[i];
    for(i=1;i<n;i++)
    {
    	for(j=1;j<=k;j++)
    	{
    		int a;
    		if(i>=j)
    			a=dp[i-j]+abs(h[i]-h[i-j]);
    		else	break;
    		if(dp[i]==-1)	dp[i]=a;
    		else
    			dp[i]=min(a,dp[i]);
		}
	}
	cout<<dp[n-1];
    
}

Measured memory_bytes: 4376
inputNum = list(map(int, input().split()))

A = inputNum[0]
B = inputNum[1]

plusAnswer = A + B
minusAnswer = A - B
multiAnswer = A * B

maxAnswer = plusAnswer
if (maxAnswer < minusAnswer):
    maxAnswer = minusAnswer
if (maxAnswer < multiAnswer):
    maxAnswer = multiAnswer

print(maxAnswer)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


const int N = 50005;
bool prime[N];
vector<int> primes;
void hurui()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;

	for (int i = 2; i*i < N; i++)
	{
		for (int j = 2; i*j < N; j++)
		{
			prime[i*j] = false;
		}
	}
	REP(i, N + 1)
	{
		if (prime[i]) primes.push_back(i);
	}
}


int main()
{
	hurui();
	int m, a, b;
	while (cin >> m >> a >> b, m)
	{
		struct ans{ int m, p, q; };
		ans t = { -1, -1, -1 };
		REP(i, primes.size())
		{
			if (primes[i] > m / 2) break;
			FOR(j, i, primes.size())
			{
				if (primes[i] * primes[j] > m||a*primes[j]>b*primes[i]) break;

				if (primes[i] * primes[j] <= m&&a*primes[j] <= b*primes[i])
				{
					if (primes[i] * primes[j] > t.m) t = { primes[i] * primes[j], primes[i], primes[j] };
				}
			}
		}
		cout << t.p << " " << t.q << endl;
	}

}

Measured memory_bytes: 1324
n, m = map(int, input().split())
x = []
for _ in range(m):
    x.append(list(map(int, input().split())))
lst = []

for i in range(1,n+1):
    cnt = 0
    for j in range(m):
        cnt += x[j].count(i)
    lst.append(cnt)

for i in range(n):
    print(lst[i])

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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a;
    cin >> a;
    
    cout << a*(1 + a + a*a) << endl;

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  if (s.back() == 's') s += "es";
  else s += 's';
  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 3592
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] d = new int[N];
		
		for(int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
		
		Arrays.sort(d);
		int count = 1;
		
		for(int i = N - 1; i > 0; i--) {
			if(d[i] > d[i - 1]) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

// 約数の列挙O(√n)
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) {
        res.push_back(n / i);
      }
    }
  }
  return res;
}

void solve(long long N, std::vector<long long> A) {
  unordered_set<ll> hashmap;
  unordered_set<ll> dup;
  REP(i, N) {
    if (hashmap.find(A[i]) != hashmap.end()) {
      dup.emplace(A[i]);
    }
    hashmap.emplace(A[i]);
  }
  ll ans = 0;
  REP(i, N) {
    if (dup.find(A[i]) != dup.end()) {
      continue;
    }
    auto v = divisor(A[i]);
    bool ok = true;
    REP(j, v.size()) {
      if (v[j] == A[i]) {
        continue;
      }
      if (hashmap.find(v[j]) != hashmap.end()) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 13320
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int n;
int d;
int maxd;
int cnt[100001];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) {
		cin >> d;
		if (i == 0 && d != 0) { cout << 0 << endl; return 0; }
		if (i != 0 && d == 0) { cout << 0 << endl; return 0; }
		maxd = max(maxd, d);
		cnt[d]++;
	}
	if (cnt[0] == 0 || cnt[0] >= 2) { cout << 0 << endl; return 0; }
	
	int mod = 998244353;
	int ans = 1;
	rep(i, maxd) {
		if (cnt[i] == 0) { cout << 0 << endl; return 0; }
		ans *= powmod(cnt[i], cnt[i + 1], mod);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

#pragma GCC optimize("O3")
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define fr front()
#define ba back()
#define tp top()
#define mem(x,n) memset(x,n,sizeof(x));
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,l) for(auto it=l.begin();it!=l.end();it++)
#define pnl printf("\n")
#define len(x) x.length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> pii;
typedef pair<pii,int> piii;
const int inf=(1<<30);
const LL llinf=(1ll<<60);
const double eps=(1e-10);
//const double pi=2*acos(0.0);
//const double GOLD=((1+sqrt(5))/2);
const int xx[8]={1,0,-1,0,1,-1,1,-1};
const int yy[8]={0,1,0,-1,-1,1,1,-1};
const int kx[8]={1,1,2,2,-1,-1,-2,-2};
const int ky[8]={2,-2,1,-1,2,-2,1,-1};

/* \( Â·wÂ·)~ Clapie ~(Â·wÂ· )/ */

LL n,arr[200005],BIT[200005],val[200005];
pair<LL,LL> ar[200005];

void updet(int i,LL vall){
	for(;i<=200005;i+=(i&(-i))){
		BIT[i]=max(vall,BIT[i]);
	}
}

LL query(int i){
	LL maxi=0;
	for(;i>0;i-=(i&(-i))){
		maxi=max(maxi,BIT[i]);
	}
	return maxi;
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&arr[i]);
		ar[i].first=arr[i];
		ar[i].second=i;
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&val[i]);
	}
	sort(ar+1,ar+n+1);
	
	LL ans=0;
	for(int i=1;i<=n;i++){
		LL temp=query(ar[i].second-1);
		updet(ar[i].second,val[ar[i].second]+temp);
		ans=max(ans,val[ar[i].second]+temp);
	}
	
	printf("%lld\n",ans);
}

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

long long gcd(long long a, long long b){
  while(a>0){
    return gcd(b%a, a);
  }
  return b;
}

int main() {
  long long a,b,c,d,cok, dok,gc,two;
  cin>>a>>b>>c>>d;
  cok=b/c-(a-1)/c;
  dok=b/d-(a-1)/d;
  gc=c/gcd(c,d)*d;
  two=b/gc-(a-1)/gc;
  
  
  
  
      cout<<b-a+1-cok-dok+two<<endl;
      
      
  
}

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

int main() {
  int max = 0, sum=0;
  int n;
  cin >> n;
  vector <int> vec(n);
  cin >> vec[0];
  sum = max = vec[0];
  for(int i=1; i < n; i++)
  {
    cin >> vec[i];
    sum = sum + vec[i];
    if(max < vec[i])
      max = vec[i];
  }
  if(sum - max*2 > 0)
    cout << "Yes";
  else 
    cout <<"No";
  return 0;

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin >> n >> k;
    vector<ll> a(n),sum(n+1);
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum[i+1]=sum[i]+a[i];
    }
    map<ll,ll> mp;
    for(int i=0;i<=n;i++){
        (sum[i]+=n-i)%=k;
    }
    ll ans=0;
    for(int i=0;i<=n;i++){
        ans+=mp[sum[i]];
        mp[sum[i]]++;
        if(i>=k-1){
            mp[sum[i-k+1]]--;
        }
    }
    cout << ans << endl;
}

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

int main(void)
{
	int i,j;
	int h,w;
	
	while(1)
	{
		cin >> h >> w;
		
		if((h == 0) && (w == 0))
			break;
		for(i = 0; i < h; i++)
		{
			for(j = 0; j < w; j++)
			{
				if((i == 0) || (i == h - 1))
				{
					cout << "#";
				}
				else if((j == 0) || (j == w - 1))
				{
					cout << "#";
				}
				else
				{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


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

using namespace std;

int n;
vector<int> g[100001];
int to1[100001];
int ton[100001];

void solve(int v, int pre, bool t) {
  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if(u != pre) {
      if(t) ton[u] = ton[v] + 1;
      else to1[u] = to1[v] + 1;
      solve(u,v,t);
    }
  }
  return;
}

int main() {
  cin >> n;

  for(int i = 0; i < n-1; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;

    g[a].push_back(b);
    g[b].push_back(a);
  }

  solve(0,-1,false);
  solve(n-1,-1,true);

  int black = 0;
  int white = 0;
  for(int i = 0; i < n; i++) {
    if(to1[i] <= ton[i]) black++;
    else white++;
  }

  // for(int i = 0; i < n; i++) cout << to1[i] <<"  "<<ton[i] << endl;
  if(black > white) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
}
    
  

  


Measured memory_bytes: 14464
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n, a, b, c, d = geta(int)
    s = "#" + gete()

    if c < d:
        # no consecutive rocks between [a,c] and [b,d]
        if "##" in s[a:c + 1] or "##" in s[b:d + 1]:
            print("No")
        else:
            print("Yes")
    else:
        # no consecutive rocks between [a,c] and,
        # [b-1,d+1] contains "..."

        if (not "##" in s[a:c + 1]) and "..." in s[b - 1:d + 2]:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()

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

typedef long long ll;
typedef pair<int,int> pii;

ll mod = 1e9+7;

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

  int a,b;
  cin >> a >> b;
  int ret = a*b;
  if(a > 9 || b > 9)ret = -1;
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef pair<ll, ll> pll;

const int INF = 1000000010;
const ll MOD = 1000000007;

int main() {FIN
	
	int n,x,t;
	cin >> n >> x >> t;
	cout << (n/x * t) + (n%x == 0 ? 0 : t) << "\n";
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define piii pair<pii, int>
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R){int val=rng()%R;assert(val >= 0);return val;}

const long double PI = atan(1.0) * 4;
const int64_t INF64 = 3e18;
const int32_t INF32 = 2e9 + 7;
const int32_t LOG = 21;
const int32_t MOD = MOD1;

using namespace std;


//-------------------DEBUGGING-------------------------
void my_debugger(string s,int LINE_NUM){cerr<<endl;}
template<typename start,typename... end>
void my_debugger(string s,int LINE_NUM,start x,end... y) 
{
    if(s.back()!=',') {s+=',';cerr<<"LINE("<<LINE_NUM<<"): ";}
    int i=s.find(',');
    cerr<<s.substr(0,i)<<" = "<<x;
    s=s.substr(i+1);
    if(!s.empty()) cerr<<", ";
    my_debugger(s,LINE_NUM,y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__,__LINE__,__VA_ARGS__);
#else
#define debug(...) ;
#endif

//-----------------------------------------------------

vector<int> v[1000005];
bool prime[1000005];

void init(int n=1000002)
{
    fill(prime,prime+n+1,true);
    prime[1]=false;
    for(int i=2;i<=n;i++)
    {
        if(!prime[i])continue;
        v[i].push_back(i);
        for(int j=2*i;j<=n;j+=i)
        {
            prime[j]=false;
            v[j].push_back(i);
        }
    }
}


int32_t main()
{
      getFaster;
      //files_init();
      int tests = 1;
      //cin >> tests;
      rep(ii, 0, tests)
      {
           init();
           int n;
           cin>>n;
           int ans1=0;
           rep(c,1,n)
           {
               int rem=n-c;
               int ans=1;
               for(auto it:v[rem])
               {
                     int cnt=0;
                     int cur=rem;
                     while(cur%it==0)
                     {
                         cur/=it;
                         cnt++;
                     } 
                     ans*=(cnt+1);
               }
               //debug(c,rem,ans);
               ans1+=ans;
           }
           cout<<ans1<<endl;
      }
      return 0;
}


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

long long gcd(long long a, long long b){
  if(b==0)
    return a;
  return gcd(b, a%b);
}
    
int main() {
    long A, B, C, D;
    cin >> A >> B >> C >> D;
    long dif = B - A + 1;
    long divC1, divD1, divCD1, divC2, divD2, divCD2;
    divC1 = B / C;    
    divC2 = (A-1) / C;
    //if( (A+1)/C * C >= A && B - divC * C >= (A+1)/C * C) divC++;
    /*for (long i=A; i < B + 1 - divC * C; i++){
      if(i%C==0) divC++;
    }*/
    divD1 = B / D;
    divD2 = (A-1) / D;
    //if( (A+1)/D  * D >= A && B - divD * D >= (A+1)/D * D) divD++;
    /*for (long i=A; i < B + 1 - divD * D; i++){
      if(i%D==0) divD++;
    }*/
    
    long x = C * D;
    long tmp;
    if(C > D){
     tmp = C;
     C = D;
     D = tmp;
    }
    long r = D % C;
    while(r!=0){
     D = C;
     C = r;
     r = D % C;
    }
  
    divCD1 = B / (x/C);
    divCD2 = (A-1) / (x/C);
    //if( (A+1)/(x/C) * (x/C) >= A && B - divCD * (x/C) >= (A+1)/(x/C) * (x/C) ) divCD++;
	/*for (long i=A; i < B + 1 - divCD * (x/C); i++){
      if(i%(x/C)==0) divCD++;
    }*/
    cout << B - divC1 - divD1 + divCD1 - (A - 1 - divC2 - divD2 + divCD2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>

using namespace std;

#define ll long long

int main(void){
    ll n, k;
    cin >> n >> k;

    ll a,b;
    a = abs(n - (n/k)*k);
    b = abs(n - (n/k+1LL)*k);

    cout << min(a, b) << endl;

    return 0;
}

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

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


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N,class Tuple>
void out(ostream &os,const Tuple &t){}
template<int N,class Tuple,class H,class ...Ts>
void out(ostream &os,const Tuple &t){
   if(N)os<<" ";
   os<<get<N>(t);
   out<N+1,Tuple,Ts...>(os,t);
}
template<class ...Ts>
ostream& operator<<(ostream &os, const tuple<Ts...> &t){
   os<<"(";
   out<0,tuple<Ts...>,Ts...>(os,t);
   os<<")";
   return os;
}

// Debug
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
   int H, W; cin >> H >> W;
   vector<string> A(H);
   set<pair<int,int>> st, nst;
   for (int i = 0; i < H; ++i) {
      cin >> A[i];
      for (int j = 0; j < W; ++j) {
         if (A[i][j] == '#') {
            st.insert({i,j});
         }
      }
   }


   vector<int> dx{1,0,-1,0}, dy{0,1,0,-1};
   int ans = 0;
   while (!st.empty()) {
      for (auto p : st) {
         int i = p.first, j = p.second;
         for (int k = 0; k < 4; ++k) {
            if (0 <= i+dx[k] && i+dx[k] < H &&
                0 <= j+dy[k] && j+dy[k] < W &&
                A[i+dx[k]][j+dy[k]] == '.') {
               A[i+dx[k]][j+dy[k]] = '#';
               nst.insert({i+dx[k], j+dy[k]});
            }
         }
      }
      if (!nst.empty()) ++ans;
      st.clear();
      swap(st, nst);
   }

   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 48128
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <map>
#include <bitset>

using namespace std;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		string s, r;
		int q = -1, t, f, m = 0;
		cin >> s >> q;
		if (q < 0) return 0;
		for (int i = 0; i < q; ++i) {
			cin >> t;
			if (t == 1) {
				m = !m;
			} else {
				char c;
				cin >> f;
				cin >> c;
				if ((m == 0 && f == 2) || (m == 1 && f == 1)) {
					s += c;
				} else {
					r += c;
				}
			}
		}
		reverse(r.begin(), r.end());
		string ans = r + s;
		if (m) {
			reverse(ans.begin(), ans.end());
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1248
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

sum = 0
diff = 0
a_sum = a.sum
l = a.length - 1
a.each_with_index do |num, i|
  break if l == i

  diff += num
  sum += num * (a_sum - diff)
end

puts sum % (10 ** 9 + 7)


Measured memory_bytes: 35952
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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


    int N, M; cin >> N >> M;
    vi L(M), R(M); REP(i, M) cin >> L[i] >> R[i];

    int LMIN = INF, LMAX = 0;
    REP(i,M) {
        LMIN = min(LMIN, L[i]);
        LMAX = max(LMAX, L[i]);
    }

    int RMIN = INF, RMAX = 0;
    REP(i,M) {
        RMIN = min(RMIN, R[i]);
        RMAX = max(RMAX, R[i]);
    }

    int ans = RMIN - LMAX + 1;
    if (ans <= 0) ans = 0;

    cout <<  ans << endl;

    return 0;
}


Measured memory_bytes: 1024
from functools import reduce
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input().rstrip())
As = input().rstrip().split(" ")
As = [int(p) for p in As]

cand = lcm_list(As)

sum = 0

for num in As:
    sum = sum + cand // num

print(sum % int(1e9+7) )


Measured memory_bytes: 6084
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;

typedef tuple<string, int, int> mytuple;

bool mycompare( const mytuple &lhs, const mytuple &rhs )
{
    if (get<0>(lhs) != get<0>(rhs)) return get<0>(lhs) < get<0>(rhs);
    return get<1>(lhs) > get<1>(rhs);
}

void print_vector( std::vector<mytuple>& vec )
{
    for( auto& element : vec ) {
        std::cout << std::get<0>(element) << ", " << std::get<1>(element) << ", " << std::get<2>(element) << std::endl;
    }
    std::cout << std::endl;
}

int main() {
	int N;

	cin >> N;

	vector<mytuple> arr(N);
	string S;
	int P;
	for (size_t i=0; i<N; i++) {

		cin >> S >> P;
		auto tmp_tuple = make_tuple(S, P, i+1);
		arr.at(i) = tmp_tuple;
	}


	sort(arr.begin(), arr.end(), mycompare);
	// cout << "end sort" << endl;a
	// cout << get<0>(arr.at(0)) << endl;

	for (auto val: arr) {
		cout << get<2>(val) << endl;
		// cout << "hello" << endl;
	}

}

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

if X == 0:
  print(X)
  exit(0)

p = list(map(int, input().split()))

for i in range(102):
  a = X + i
  b = X - i
  if b not in p:
    print(b)
    exit(0)
  if a not in p:
    print(a)
    exit()


Measured memory_bytes: 61920
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

struct Edge {
	lli to, cost;
};

using Vertex = vector<Edge>;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli visited[100001] = {};
Vertex tree[100001] = {};

void solve(lli now = 0, lli total = 0) {
	if (visited[now] != -1)
		return;
	visited[now] = total % 2;
	for (int i = 0; i < tree[now].size(); i++) {
		solve(tree[now][i].to, (total + tree[now][i].cost) % 2);
	}
	return;
}


int main(void) {

	lli N;
	cin >> N;

	for (int i = 0; i < 100001; i++) {
		visited[i] = -1;
	}

	for (int i = 0; i < N - 1; i++) {
		lli v, u, w;
		cin >> v >> u >> w;
		v--; u--;
		tree[v].push_back(Edge{ u, w % 2 });
		tree[u].push_back(Edge{ v, w % 2 });
	}

	solve();

	for (int i = 0; i < N; i++) {
		COUT(visited[i]);
	}

	return 0;
}

Measured memory_bytes: 10240
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

vector<ll> p,all;
ll ans = 0;

void dfs(ll level, ll cnt){
  if(cnt) cnt--;
  if(level){
    if(all[level-1] <= cnt){
      cnt -= all[level-1];
      ans += p[level-1];
    }else{
      dfs(level-1,cnt);
      cnt = 0;
      level = 0;
    }
  }
  if(cnt){
    ans++;
    cnt--;
  }
  if(level){
    if(all[level-1] <= cnt){
      cnt -= all[level-1];
      ans += p[level-1];
    }else{
      dfs(level-1,cnt);
      cnt = 0;
      level = 0;
    }
  }
  if(cnt) cnt--;
}

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  ll n,x; cin >> n >> x;
  p = vector<ll>(n+1);
  all = vector<ll>(n+1);
  p[0] = all[0] = 1;
  rep(i,n){
    p[i+1] += p[i]*2+1;
    all[i+1] += all[i]*2+3;
  }
  dfs(n,x);
  cout << ans;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3624
import Control.Monad
import Data.List

main = do
    n <- read <$> getLine
    a <- forM [1 .. n] $ \_ -> do
        read <$> getLine
    forM (solve n a) $ \r -> do
        putStrLn $ show $ r

solve :: Int -> [Int] -> [Int]
solve n a = map (\a -> if a == f then s else f) a
  where
    (f : s : t) = reverse $ sort a

Measured memory_bytes: 107132
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		list.add(a);
		list.add(b);
		list.add(c);
		List<Integer> hashList = new ArrayList<Integer>(new HashSet<>(list));
		System.out.println(hashList.size());
		scan.close();
	}

}


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

string S;

signed main(){
	cin >> S;
	int N = S.size();

	int64 ans = 0;
	int m = 0;
	REP(i, 0, N)		if(S[i] == 'B')	m++;
	
//	int k = 0;
//	REP(i, 0, N)		if(S[i] == 'B') {
//		ans += N - (m - k) - i;
//		cout << "ans = " << ans << "  N = " << N << "  m = " 
//							<< m << "  k = " << k << "  i = " << i << endl;
//		k++;
//	}
    int64 ans2 = 0;
	REP(i, 0, N - m)	if(S[i] == 'B')	ans2 += (m - i);
	REP(i, N - m, N)	if(S[i] == 'W')	ans2 += (i - m);

//    cout << "ans = " << ans << "  ans2 = " << ans2 << endl;
    
    cout << ans2 << endl;
	
	return 0;
}


Measured memory_bytes: 640
import sys
import bisect
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())

    ans = 0
    min1, min2 = n-2, n-2
    judge1 = [-n-1]
    judge2 = [-n-1]
    dict1 = dict()
    dict2 = dict()
    dict1[-n-1] = n-2
    dict2[-n-1] = n-2

    for i in range(q):
        query, x = map(int, input().split())

        if query == 1:
            index = bisect.bisect(judge1, -x)-1
            key = dict1[judge1[index]]
            ans += key
            if min1 > x-2:
                min1 = x-2
                judge1.append(-x)
                dict1[-x] = key
                dict2[judge2[-1]] = min1
        else:
            index = bisect.bisect(judge2, -x)-1
            key = dict2[judge2[index]]
            ans += key
            if min2 > x-2:
                min2 = x-2
                judge2.append(-x)
                dict2[-x] = key
                dict1[judge1[-1]] = min2

    print((n-2)**2 - ans)
    
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 108264
MOD = 10**9+7
X, Y = map(int, input().split())
x, y = X, Y
while 0 <= y:
    if x == 2*y:
        break
    x += 1
    y -= 1
else:
    print(0)
    exit()


def com(n, r):
    X = Y = 1
    if r < 0 or n < r:
        return 0
    if n-r < r:
        r = n-r
    for i in range(1, r+1):
        Y = Y*i % MOD
        X = X*(n-i+1) % MOD
    Y = pow(Y, MOD-2, MOD)
    return X*Y


print(com(x//2, x-X) % MOD)


Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n;
    cin >> n;
    vl a(n);

    ll x, y;
    x = 0;
    y = 0;
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        y = max(y, a[i]);
        if (y > x) swap(y, x);
    }

    for (ll i = 0; i < n; ++i) {
        cout << (a[i] == x ? y : x) << "\n";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3200
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        char c[]=sc.nextString().toCharArray();
        int l[]=new int[c.length+2];
        int r[]=new int[c.length+2];
        
        for (int i = 0; i < c.length; i++) {
        	l[i+1]=l[i]+(c[i]=='.'?0:1);
        	r[n-i]=r[n-i+1]+(c[n-i-1]=='#'?0:1);			
		}
        r[0]=r[1];
        l[n+1]=l[n];
        int min=n+1;
        for (int i = 1; i <= c.length+1; i++) {
			min=min(min,l[i-1]+r[i]);
		}
        
//        db(l);
//        db(r);
               
        out.println(min);
        out.flush();
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int id,T;
//    P(int id, int T) {
//        this.id=id;
//        this.T=T;
//    }
//    public int compareTo(P p){
//        return id-p.id; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

using namespace std;

int main()
{
	int t;
	t=1;
	while(t--)
	{
		int i,j,k,n,m;
	 string s;
	 
	 cin>>n;
	 cin>>s;
	 
	 int w=0,r=0;
	 
	 for(i=0;i<n;i++)
	 {
	 	if(s[i]=='W')
	 	w++;
	 	
	 	else
	 	r++;
	 	
	 }
	if(w==0||r==0)
	cout<<0<<endl;
	
	else
	{
	j=0;
		
		for(i=r;i<n;i++)
		{
			if(s[i]!='W')
			j++;
			
			
		}
		
		cout<<j<<endl;
		
	}
	
	
	}



}


Measured memory_bytes: 3748
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()
rr = (list(map(int, input().split())) for _ in range(k))

from collections import Counter

dc = [0, 0]
c = 0
for i in range(1, len(s)):
  if s[i-1]+s[i] == 'AC':
    c += 1
  dc.append(c)
for a, b in rr:
  print(dc[b] - dc[a])

Measured memory_bytes: 6728
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 500005
#define lld_max 5000000000000000000
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        cin>>n;
        if(n==0) cout<<1<<endl;
        else cout<<0<<endl;
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


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

#define boost ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)


using namespace std;
using LL = long long;

constexpr int MAXN = 2e5 + 5;

template <typename T>
inline void read(T &x) {
    int f = 1;
    x = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

int n, m, q, sum;
int a[100], b[100], c[100], d[100], A[11];

inline void search(int cur, int cnt) {
    if (cnt == 11) {
        int tmp = 0;
        for (int i = 1; i <= q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) {
                tmp += d[i];
            }
        }
        sum = max(sum, tmp);
        return;
    }
    for (int i = cur; i <= m; i++) {
        A[cnt] = i;
        search(i, cnt + 1);
    }
}

int main() {
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    boost;
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    search(1, 1);
    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < (int) s.size(); ++i) {
        if (s[i] == '?')
            s[i] = 'D';
    }
    cout << s << "\n";
    return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;

int main(void){
  ll N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> vec(N); 
  int a, b;
  for (int i = 0; i<N; i++){
    cin >> a >> b;
    vec[i] = make_pair(a, b);
  }

  sort(vec.begin(), vec.end());
  /*
  for (int i = 0; i<N; i++){
     cout << vec[i].first  << " " << vec[i].second << endl; 
  }
  */
  ll sum = 0;
  ll ans;
  for (int i= 0; i<N; i++){
    //cout << vec[i].first  << " " << vec[i].second << endl; 
    sum += vec[i].second;
    if (sum>=K){
      ans = (ll)vec[i].first;
      break;
    }
   }
  cout << ans << endl;
}
  
  
  
  

Measured memory_bytes: 1792
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n,L;
    scanf("%d%d", &n, &L);

    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        if(i>0 && (ll)a[i-1]+a[i]>=L) {
            break;
        }
    }
    if(i<n) {
        printf("Possible\n");
        int k;
        for(k=1; k<n; k++) {
            if(k<i) printf("%d\n", k);
        }
        for(k=n-1; k>=0; k--) {
            if(k>i) printf("%d\n", k);
        }
        printf("%d\n", i);
    }
    else {
        printf("Impossible\n");
    }

    return 0;
}


Measured memory_bytes: 1152
#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>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    n -= k;
    int ans = 1;
    ans += n/(k-1);
    if ((n%(k-1)) > 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3744
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
res = [0]*(n+1)
for i in range(1,n+1):
    for j in range(1,n+1):
        if i*j > n: break
        res[i*j] += 1
print(sum(i*x for i,x in enumerate(res)))

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

const int MOD = 998244353, MAXN = 3e3 + 10;
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int sub(int x, int y) { return x < y ? x - y + MOD : x - y; }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / MOD * MOD; }

int A, B, C, D;
int dp[MAXN][MAXN];

int main() {
	scanf("%d%d%d%d", &A, &B, &C, &D);
	dp[A][B] = 1;
	for (int i = A; i <= C; ++i)
		for (int j = B; j <= D; ++j) if (i > A || j > B) dp[i][j] = sub(add(mul(dp[i - 1][j], j), mul(dp[i][j - 1], i)), mul(dp[i - 1][j - 1], mul(i - 1, j - 1)));
	printf("%d\n", dp[C][D]);
	return 0;
}

Measured memory_bytes: 39068
n = int(raw_input())
dic = {}
rank = {}
count = 0
now_rank = -1
prev = -1
for i in range(n):
    dic[i] = 0
for i in range(n*(n-1)/2):
    a, b, c, d = [int(i) for i in raw_input().split(" ")]
    if c > d: 
        dic[a-1] += 3
    elif c < d:
        dic[b-1] += 3
    else: 
        dic[a-1] += 1
        dic[b-1] += 1

l = dic.items()
l.sort(cmp=(lambda x,y: cmp(y[1], x[1])))
for i in range(len(l)):
    if prev == l[i][1]:
        count += 1
    else :
        now_rank += count + 1
        prev = l[i][1]
        count = 0
    rank.update({l[i][0]:now_rank+1})

for i in range(n):
    print rank[i]

Measured memory_bytes: 4416