akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline

    inf = 1 << 60

    N, M, L = map(int, input().split())

    dist = [[inf] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        A -= 1
        B -= 1
        dist[A][B] = dist[B][A] = C

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(
                    dist[i][j],
                    dist[i][k] + dist[k][j]
                )

    g = [[inf] * N for _ in range(N)]  # 到達に必要な補充回数
    for A in range(N):
        for B in range(N):
            if dist[A][B] <= L:
                g[A][B] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                g[i][j] = min(
                    g[i][j],
                    g[i][k] + g[k][j]
                )

    Q = int(input())
    for _ in range(Q):
        s, t = (int(x) - 1 for x in input().split())
        d = g[s][t]
        if d == inf:
            print(-1)
        else:
            print(d - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 56284
import java.util.*;

public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		String t=sc.next();
		int a=sc.nextInt();
		int b=sc.nextInt();
		String u=sc.next();
		if(u.equals(s))
			System.out.println((a-1)+" "+b);
		else 
			System.out.println(a+" "+(b-1));
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,m,p,sum,x,y,i,k,h;
	int b[100002],a[100002],c[100002];
	scanf("%d %d %d",&n,&m,&p);
	for(i=0;i<m;i++) scanf("%d",&a[i]),c[i]=a[i];
	a[m]=p,a[m+1]=p;
	sort(a,a+m+2);
	c[m]=0;
	sort(c,c+m+1);
	c[0]=c[m];
	c[m+1]=c[1];
	for(i=0;i<=m+1;i++){
		x=abs(a[i]-p);
		y=abs(a[i]-(p+n));
		if(x>y) x=y;
		b[i]=x;
	}
	sum=b[0]*100+(c[0]-a[0])*100;
	if(sum>b[m+1]*100+(a[m+1]-c[m+1])*100) sum=b[m+1]*100+(a[m+1]-c[m+1])*100;
	for(i=1;i<=m;i++){
		if(a[i]>c[i]) c[i]+=n;
		else a[i]+=n;
		x=b[i]*100+abs(a[i]-c[i])*100;
		if(sum>x) sum=x;
		//printf("%d %d %d %d\n",i,a[i],c[i],a[i]-c[i]);
	}
	printf("%d\n",sum);
	return 0;
}


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

#define MOD 1000000007ll
#define all(v) v.begin() , v.end()
#define allr(v) v.rbegin(), v.rend()
#define for0(i,n) for(__typeof(n) i = 0; i < n ; i++) 
#define forab(i,a,b) for(__typeof(a) i = a ; i < b ; i++) 
#define forba(i,b,a) for(__typeof(a) i = b ; i > a ; i--) 
#define forc(c,it) for(__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define pb     push_back
#define mp     make_pair
#define MAX 100005
template<typename T, template<typename ELEM, typename ALLOC=std::allocator<ELEM> > class Container>
std::ostream& operator<< (std::ostream& o, const Container<T>& container)
{ typename Container<T>::const_iterator beg = container.begin();
  /*o << "[";*/ while(beg != container.end()) o << " " << *beg++; /*o << " ]";*/ return o; }

int n, ans, d;
vector<int> a;

int main(int argc, char const *argv[])
{
  ios_base::sync_with_stdio(false);
  cin >> n;

  for0(i , n)
  {
  	cin >> d;
  	a.pb(d);
  }

  if(n < 3)
  	cout << "1";
  else
  {
      int last = a[0];
      int inc = 0;

	  for(int i = 1 ; i < n ; i++)
	  {
	  	if(a[i] >= last && (inc == 0 || inc == 1))
	  	{
	  		if(a[i] > last)
	  			inc = 1;
	  		last = a[i];
	  	}
	  	else if(a[i] <= last && (inc == 0 || inc == -1))
	  	{
	  		if(a[i] < last)
	  			inc = -1;
	  		last = a[i];
	  	}
	  	else
	  	{
	  		last = a[i];
	  		inc = 0;
	  		ans++;
	  	}
	  }
	  ans++;
	  cout << ans;
  	
  }




  return 0;
} 

Measured memory_bytes: 892
#include <iostream>
#include <list>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    list<int> answerList = list<int>{1, 2, 3};
    answerList.remove(a);
    answerList.remove(b);

    cout << answerList.front() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define ll long long
using namespace std;
void deb(){
    cout<<"a";
    exit(0);
}
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    int w=0,r=0,R=0;
    rep(i,0,n){
        if(s[i]=='W')w++;
        else r++;
    }
    rep(i,0,r)if(s[i]=='W')R++;
    int ans=min(w,min(r,R));
    cout<<ans<<endl;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  dsu d(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    d.merge(a,b);
  }
  vector<vector<int>> a=d.groups();
  cout << (int)a.size()-1 << endl;
}

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

int main() {
  int N,M;
  cin>>N>>M;

  vector<vector<long>> x(M);
  vector<long> p(N);
  for(int i=0;i<M;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int s;
      cin>>s;
      x[i].push_back(s);
    }
  }

  for(int i=0;i<M;i++) cin>>p[i];

  int ans=0;
  for(int bit=0;bit<(1<<N);bit++){
    vector<long> b(N);
    for(int i=0;i<N;i++){
      if(bit&(1<<i)) b[i]=1;
    }
    int l=0;
    for(int i=0;i<M;i++){
      int c=0;
      for(int j=0;j<x[i].size();j++){
        if(b[x[i][j]-1]==1) c++;
      }
      if(c%2==p[i]) l++;
    }
    if(l==M) ans++;
  }
cout<<ans<<endl;
}


Measured memory_bytes: 256
def s():
  from sys import stdin
  read=stdin.buffer.readline
  n=int(read())
  l=list(map(int,read().split()))
  f=l[0]
  mod=10**9+7
  def gcd(s,d):
    return gcd(d,s%d) if d else s
  for i in l:
    f=i*f//gcd(i,f)
  ans=0
  for iu in l:
    ans+=(f*pow(iu,mod-2,mod))%mod
    ans%=mod
  print(ans)
  
if __name__=="__main__":s()


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

int main(){ 
  int q;
  string s;
  cin >> s >> q;
  
  deque<char> que;
  int n = sz(s);
  for (int i = 0; i < n; i++) {
    que.push_back(s[i]);
  }
  int now = 0;
  while (q--) {
    int t;
    cin >> t; 
    if (t == 1) {
      now++;
      now %= 2;
    } else {
      int f;
      char c;
      cin >> f >> c;

      if (now == 0) {
        if (f == 1) {
          que.push_front(c);
        } else {
          que.push_back(c);
        }
      } else {
        if (f == 1) {
          que.push_back(c);
        } else {
          que.push_front(c);
        }
      }   
    }
  }
  string res = "";
  while (!que.empty()) {
    char c = que.front();
    que.pop_front();
    res += c;
  }
  if (now) reverse(res.begin(), res.end());
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 1412
#!/usr/bin/env python
n = int(input())
given_a = list(map(int, input().split()))

a = []
for k in given_a:
    if len(a) > 0 and a[-1] == k:
        continue
    else:
        a.append(k)

money = 1000
kabu = 0 

n = len(a)

if n == 1:
    print(money)
    exit()

for i in range(n):
    if i == 0:
        if a[i] > a[i+1]:
            continue
        else:
            kabu += money//a[i]
            money %= a[i]
    elif i == n-1:
        money += kabu*a[i]
        kabu = 0 
    else:
        if a[i] > a[i-1] and a[i] > a[i+1]:
            money += kabu*a[i]
            kabu = 0 
        elif a[i] < a[i-1] and a[i] < a[i+1]:
            kabu += money//a[i]
            money %= a[i]

print(money)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define mp make_pair
#define pb push_back
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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; }

template <class T> inline auto __lcm(T &a, T &b)
{ return a * b / __gcd(a, b); }


int main() {
    int N, K;  cin >> N >> K;
    string S;  cin >> S;

    S[K-1] = S[K-1] + 32;
    print(S);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>

using namespace std;

struct Data {
	string name;
	int time;
};

int main() {

	int n, q;
	cin >> n >> q;

	queue<Data> Q;
	Data *Input = new Data[n];

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

		cin >> Input[i].name >> Input[i].time;
		Q.push(Input[i]);

	}

	int cost_time = 0;

	while (!Q.empty()) {

		Data current = Q.front();
		Q.pop();

		if (current.time <= q) {

			cost_time += current.time;
			cout << current.name << " " << cost_time << "\n";

		}

		else {

			cost_time += q;
			current.time -= q;
			Q.push(current);

		}

	}
	
	return 0;

}


Measured memory_bytes: 7156
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program
{
    static void Main()
    {
        Console.WriteLine(string.Concat('A', new string(Console.ReadLine().Where(elem => char.IsUpper(elem)).Skip(2).ToArray())));
    }
}


Measured memory_bytes: 3156
import math
n = int(input())
ans = [0] * n
a = math.floor(n**0.5)
b = 0
for x in range(1, a):
    for y in range(1, a):
        for z in range(1, a):
            m = x * x + y * y + z * z + x * y + y * z + z * x
            if m <= n:
                ans[m - 1] += 1

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


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

int main()
{
    string s,t;
    int a,b;
    string u;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s) cout<<a-1<<" "<<b<<endl;
    else cout<<a<<" "<<b-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a, b, c;
    int cnt = 0;
    
    scanf("%d %d %d",&a, &b, &c);

    if((a!=b) && (b!=c) && (c!=a)){
        printf("3\n");
    }else if((a==b)&&(b==c)&&(c==a)){
        printf("1\n");
    }else{
        printf("2\n");
    }


    return 0;
}

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

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define min(a, b) (a < b ? a : b)
#define max(a, b) (b < a ? a : b)
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define read() Read<int>()
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef double db;

namespace IO {
#define getc() ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), S_ == T_) ? 0 : *S_ ++)
	const uint Buffsize = 1 << 15, Output = 1 << 23;
	static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;
	static char Out[Output], *nowps = Out;
	inline void flush(){fwrite(Out, 1, nowps - Out, stdout); nowps = Out;}
	template<typename T >inline T Read() {
		T _ = 0; static char __; T ___ = 1;
		for(__ = getc(); !isdigit(__); __=getc()) if(__ == '-') ___ = -1;
		for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
		return _ *= ___;
	}
	template<typename T>inline void write(T _, char __ = '\n') {
		if(!_) *nowps ++ = '0';
		if(_ < 0) *nowps ++ = '-', _ = -_;
		static uint sta[111], tp;
		for(tp = 0; _; _ /= 10) sta[++ tp] = _ % 10;
		for(; tp; *nowps ++ = sta[tp --] ^ 48); 
		(*nowps ++) = __;
	}
	template<class T>inline bool chkmax(T &_, T __) {return _ < __ ? _ = __, 1 : 0;}
	template<class T>inline bool chkmin(T &_, T __) {return _ > __ ? _ = __, 1 : 0;}
}

using namespace std;
using namespace IO;
const int N = 1100;
int n, m;
struct Point {
	int x,y;
}A[N];
void Solve(int x,int y) {
	FOR(i, 30, 0) {
		int move = 1 << i;
		if(abs(x) >= move) {
			if(x > 0) x -= move,putchar('R');
			else x += move,putchar('L');
		}
		else if(abs(y) >= move) {
			if(y > 0) y -= move,putchar('U');
			else y += move,putchar('D');
		}
		else {
			if(abs(x) > abs(y)) {
				if(x >= 0) x -= move,putchar('R');
				else x += move,putchar('L');
			}
			else {
				if(y >= 0) y -= move,putchar('U');
				else y += move,putchar('D');
			}
		}
	}
}
		
int main() {
	n = read();	
	int flag = -1;
	For(i, 1, n) {
		A[i].x = read(), A[i].y = read();
		if(flag != ((A[i].x + A[i].y) & 1)) {
			if(flag != -1) {flag = -1;break;}
			flag = (A[i].x + A[i].y) & 1;
		}
	}
	if(flag == -1) {puts("-1");return 0;}
	cout << (32 - flag) << endl;
	FOR(i, 30, 0) cout << (1 << i) << " " ;
	puts(flag ? " " : "1");
	if(!flag) for(int i = 1;i <= n;++i) ++A[i].y;
	for(int i = 1;i <= n;++i) {
		Solve(A[i].x,A[i].y);
		puts(flag ? "" : "D");
	}
	return flush(), 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    int sum = 0;
    int a;
    rep(i,1,n+1){
        sum += i;
        if(sum>=n){
            a=i;
            break;
        }
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

int main() {
	int n; cin >> n;
	map<int, int>a;
	for (int i = 0; i < n; i++) {
		int tmp; cin >> tmp;
		a[tmp]++; a[tmp - 1]++; a[tmp + 1]++;
	}

	int ans = 0;
	for (auto&& x : a) {
		ans = max(ans, x.second);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7984
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

int N,M;
vector<vector<int>> G;

bool vis[100000][2];

void dfs(int v,int c){
	vis[v][c] = 1;
	for(int u:G[v]) if(!vis[u][1-c]) dfs(u,1-c);
}

int main(){
	cin>>N>>M;
	G.resize(N);
	rep(i,M){
		int x,y;
		cin>>x>>y;
		x--,y--;
		G[x].pb(y);
		G[y].pb(x);
	}
	dfs(0,0);
	bool isb = 1;
	typedef long long ll;
	ll x = 0;
	rep(i,N){
		if(vis[i][0]&&vis[i][1]) isb = 0;
		x += vis[i][0];
	}
	if(!isb){
		ll ans = (ll)N*(N-1)/2 - M;
		cout<<ans<<endl;
	}else{
		ll ans = x*(N-x) - M;
		cout<<ans<<endl;
	}
}


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

using namespace std;

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

  vector<int> d;
  for (int i = 0; i < n; i++) {
    int di;
    cin >> di;
    d.push_back(di);
  }

  if (n % 2 != 0) {
    cout << "0" << "\n";
    return 0;
  }

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

  int cnt = d[(int)(n/2)] - d[(int)((n/2)-1)];

  cout << cnt << "\n";
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

int main() {
        string s, t;
        cin >> s >> t;

        cout << t + s << endl;

        return 0;
}


Measured memory_bytes: 256
// AOJ Volume 5 Problem 2406 Al dente

#include <stdio.h>

int main(void)
{
    int n, t, e;
    int x[10000];
    int i;
    int m;

    scanf("%d%d%d", &n, &t, &e);
    for (i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    
    for (i = 0; i < n; i++){
        m = t / x[i];
        
        if (t - e <= x[i] * m && x[i] * m <= t + e){
            break;
        }
        if (t - e <= x[i] * (m + 1) && x[i] * (m + 1) <= t + e){
            break;
        }

    }

    if (i != n){
        printf("%d\n", i + 1);
    }
    else {
        printf("-1\n");
    }

    return (0);
}

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

vector<vector<int> > G;
vector<int> INDEG;
vector<int> COLOR;

void topo() {
  for (int i = 0; i < G.size(); i++) {
    for (int j = 0; j < G[i].size(); j++) {
      INDEG[G[i][j]]++;
    }
  }

  int u;
  queue<int> Q;

  while (true) {
    u = -1;

    for (int i = 0; i < INDEG.size(); i++) {
      if (INDEG[i] == 0 && COLOR[i] == -1) {
        u = i;
        break;
      }
    }

    if (u == -1) break;
    Q.push(u);
    COLOR[u] = 1;

    for (int i = 0; i < G[u].size(); i++) {
      INDEG[G[u][i]]--;
    }
  }

  while (!Q.empty()) {
    cout << Q.front() << endl;
    Q.pop();
  }
}
    
int main() {
  int v, e; cin >> v >> e;

  G.resize(v, vector<int>());
  INDEG.resize(v, 0);
  COLOR.resize(v, -1);

  for (int i = 0; i < e; i++) {
    int s, t; cin >> s >> t;
    G[s].push_back(t);
  }

  topo();

  return 0;
}

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

int min(int a,int b){
	if(a<b) return a;
	else return b;
}

int main(void){
	int N,K;
	cin >> N >> K;
	
	int x=1;
	for(int i=0;i<N;i++){
		x=min(x*2,x+K);
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#define P pair<int, int>
int main (){ 
     int a = 1;
    
    while(a != 0){
        cin >> a ;
       if(a == 0){
           break;
       }
        a = 1000 - a ;
        int num = 0 ;
        num += a / 500 ;
        a -= 500 * (a / 500) ;
        num += a / 100 ;
        a -= 100 * (a / 100) ;
        num += a / 50 ;
        a -= 50 * (a / 50) ;
        num += a / 10 ;
        a -= 10 * (a / 10) ;
        num += a / 5 ;
        a -= 5 * (a / 5) ;
        num += a ; 
        cout << num << endl;
        a = 1 ;
    }
    

}

 



Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int INF = 1 << 30;

int main(){
  int M, N;
  cin >> M >> N;
  vector< int > P(M);
  for(int i = 0; i < M; i++){
    cin >> P[i];
  }
  sort( P.rbegin(), P.rend());
  vector< int > C(N), E(N);
  for(int i = 0; i < N; i++){
    cin >> C[i] >> E[i];
  }
  vector< int > dp(M + 1, INF);
  dp[0] = 0;
  for(int i = 0; i < N; i++){
    for(int j = M; j >= 0; j--){
      if(dp[j] == INF) continue;
      dp[min( M, j + C[i])] = min( dp[min( M, j + C[i])], dp[j] + E[i]);
    }
  }
  for(int i = M - 1; i >= 0; i--){
    dp[i] = min( dp[i + 1], dp[i]);
  }
  int ret = 0, calc = 0;
  for(int i = 1; i <= M; i++){
    calc += P[i - 1];
    ret = max( ret, calc - dp[i]);
  }
  cout << ret << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool allEven(vector<int> vn) {
    for (auto n : vn) {
        if (n % 2 == 1) {
            return false;
        }
    }
    return true;
}

void divide(vector<int> &vn) {
    for (int i = 0; i < vn.size(); i++) {
        vn[i] >>= 1;
    }
}

int main() {
    int num;
    cin >> num;

    vector<int> n;

    for (int i = 0; i < num; i++) {
        int input;
        cin >> input;
        n.push_back(input);
    }

    int count = 0;

    while (allEven(n)) {
        count++;
        divide(n);
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)

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

  multiset<int> s;
  s.insert(a[0]);

  for(int i=1; i<n; i++) {
    auto lb = s.lower_bound(a[i]);
    if(lb == s.begin()) {
      s.insert(a[i]);
    }
    else {
      s.erase(prev(lb));
      s.insert(a[i]);
    }
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 8200
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    bool flag = true;
    vl v;
    ll ans = 0;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        if(a != b) {
            flag = false;
        }
        if(a > b) {
            v.pb(b);
        }
        ans += a;
    }

    if(flag) {
        out(0);
        re0;
    }

    sort(all(v));
    ans -= v[0];

    out(ans);
    re0;
}

Measured memory_bytes: 512
N,A,B = [int(i) for i in input().split()]

l = B-A
count = 0

if l%2 == 1:
    if A-1>N-B:
        count+=N-B+1
        A,B =A+(N-B)+1,N
    else:
        count+=A
        A,B =1,B-A

l = B-A
count += l//2

print(count)

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

ll maxVec(vector<ll> &v) {
	ll ans = -INF;
	rep(i, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}


int main() {
	ll n;
	cin >> n;
	vector<double> p(n, 0);
	vector<vector<double>> dp(n + 1, vector<double>(n + 1,0));
	rep(i, n) {
		cin >> p[i];
	}

	dp[0][0] = 1;

	rep(i, n + 1) {
		if (i == 0)continue;
		rep(j, n + 1) {
			dp[i][j] += dp[i - 1][j] * (1 - p[i - 1]);
			if (j - 1 >= 0)dp[i][j] += dp[i - 1][j - 1] * p[i - 1];
		}
	}

	double ans = 0;
	for (ll i = (n + 1) / 2; i < n + 1; i++) {
		ans += dp[n][i];
	}
	printf("%.10g", ans);
}

Measured memory_bytes: 70656
N=int(input())
a=[int(x) for x in input().split()]
import collections
c=collections.Counter(a)
d=list(c.keys())
def nc2(x):
    return x*(x-1)//2
ans0=0
for i in d:
    ans0+=nc2(c[i])
for i in range(len(a)):
    print(ans0-(c[a[i]]-1))    

Measured memory_bytes: 26140
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    s,w = inpm()
    if s <= w:
        print('unsafe')
    else:
        print('safe')
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 72880
#include <iostream>
#include <deque>
#include <algorithm>

int main(){
    int n;
    std::cin>>n;
    std::deque<int> dq(3*n);
    for(int i=0;i < 3*n; ++i){
        std::cin>>dq[i];
    }
    std::sort(dq.begin(),dq.end());
    long long ans=0;
    while(dq.size()>=3){
        dq.pop_back();
        ans+=dq.back();
        dq.pop_back();
        dq.pop_front();
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 1408
N=int(input())
A=sorted([int(input()) for i in range(N)])
if N%2==0:
    K=N//2
    ans=0
    for i in range(K):
        ans+=2*(A[i+K]-A[i])
    ans+=A[K-1]-A[K]
    print(ans)
else:
    K=(N-1)//2
    ans1=0
    ans2=0
    for i in range(K):
        ans1-=2*A[i]
        ans2+=2*A[i+K+1]
    for i in range(K+1):
        ans1+=2*A[i+K]
        ans2-=2*A[i]
    ans1=ans1-(A[K]+A[K+1])
    ans2=ans2+A[K]+A[K-1]
    print(max(ans1,ans2))


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      s: chars,
      t: chars,
    }
    let n = s.len();

    for i in 0..n {
        let mut ok = true;
        for i1 in 0..n {
            let i2 = (i+i1)%n;
            if s[i1] != t[i2] {
                ok = false;
                break;
            }
        }
        if ok {
            println!("{}", "Yes");
            return;
        }
    }
    println!("{}", "No");
}


Measured memory_bytes: 4352
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
const int N = 3e5 + 500;
const int LN = 21;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;

long long n, m, u, v, k, t, q, a, h, x;


int arr[N];

vector <long long> neg, pos;

map <pair <long long, long long>, int> mp;
vector <pair <long long, long long> > sol;
int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n;
   bool hasNeg = false, hasPos = false;
   for (int i = 1; i <= n; ++i) {
      cin >> arr[i];
      if (arr[i] < 0) {
         neg.push_back(arr[i]);
         hasNeg = true;
      }
      else {
         pos.push_back(arr[i]);
         hasPos = true;
      }
   }
   
   sort(neg.begin(), neg.end());
   sort(pos.begin(), pos.end());
   
   
   
   if (!hasPos) {
      pos.push_back(neg.back() - neg[0]);
      sol.push_back(make_pair(neg.back(), neg[0]));
      neg.pop_back();
      reverse(neg.begin(), neg.end());
      neg.pop_back();
      reverse(neg.begin(), neg.end());
   }
   
   long long toAdd = pos.back();
   pos.pop_back();
   
   if (neg.size() == 0 and pos.size() >= 2) {
      neg.push_back(pos[0] - pos.back());
      sol.push_back(make_pair(pos[0], pos.back()));
      pos.pop_back();
      reverse(pos.begin(), pos.end());
      pos.pop_back();
      reverse(pos.begin(), pos.end());
   }
   
   while (pos.size() > 0) {
      if (neg.size() > 0) {
         sol.push_back(make_pair(neg[0], pos.back()));
         neg[0] -= pos.back();
         pos.pop_back();
      } else {
         sol.push_back(make_pair(toAdd, pos.back()));
         toAdd -= pos.back();
         pos.pop_back();
      }
   }
   
   while (neg.size() > 0) {
      sol.push_back(make_pair(toAdd, neg.back()));
      toAdd -= neg.back();
      neg.pop_back();
   }
   
   
   cout << toAdd << '\n';
   for (int i = 0; i < sol.size(); ++i) cout << sol[i].first << " " << sol[i].second << '\n';
}







Measured memory_bytes: 5488
s = input()

lst = [0 for i in range(2019)]
lst[0] = 1

amari = 0
tmp = 1
for i in range(1, len(s)+1):
    amari = (amari + int(s[-i])*tmp) % 2019
    lst[amari] += 1
    tmp = (tmp*10) % 2019

ans = 0
for i in range(2019):
    num = lst[i]
    ans += num * (num-1) // 2

print(ans)

Measured memory_bytes: 9308
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,x[3010],y[3010];
set<pi> S;

int main(){
	while(cin>>n&&n){
		rep(i,n)cin>>x[i]>>y[i],S.insert(pi(x[i],y[i]));
		int ans=0;
		rep(i,n)rep2(j,i+1,n){
			int dx=x[j]-x[i],dy=y[j]-y[i];
			int x3=x[j]-dy,y3=y[j]+dx;
			if(S.count(pi(x3,y3))){
				int x4=x3-dx,y4=y3-dy;
				if(S.count(pi(x4,y4)))ans=max(ans,dx*dx+dy*dy);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {

  int a,l,x;
  while(cin >> a >> l >>x) {

    double h = l*l-(a/2.0)*(a/2.0);
    h = sqrt(h);
    double s = a * h / 2.0;

    h = ((l+x)/2.0)*((l+x)/2.0)-(l/2.0)*(l/2.0);
    h = sqrt(h);
    s += l*h;
    // cout << h << endl;
    //cout << s << endl;
    printf("%.10f\n",s);
  }

  return 0;
}

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

int main()
{
    int k,a,b,flag=0;
    cin>>k>>a>>b;

    for(int i=a; i<=b; i++){
        if(i%k==0){
            flag=1;

        }
    }
    if(flag==1){
        cout<<"OK\n";
    }
    else
        cout<<"NG\n";
}


Measured memory_bytes: 3636
/* Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
#include<chrono>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define debug(x) cout << #x << " " << x <<endl;
#define set_bits __builtin_popcount
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > pbds;
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
/*--------------------------------------------------------------------------------------------------------------------------*/
void solve()
{
	int t;
	// cin >> t;
	int total = 0;
	t = 1;
	while (t--)
	{
		int r, g, b;
		cin >> r >> g >> b;
		int k;
		cin >> k;
		for (int i = 0; i <= k; i++)
		{
			for (int j = 0; j <= k; j++)
			{
				if (i + j <= k)
				{
					int g1 = g * pow(2, i);
					int b1 = b * pow(2, j);
					if (b1 > g1 && g1 > r)
					{
						cout << "Yes" << endl;
						return;
					}
				}
			}
		}
		cout << "No" << endl;
	}
}
int main()
{
	fastio();
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif
	auto start1 = high_resolution_clock::now();
	solve();
	auto stop1 = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop1 - start1);
#ifndef ONLINE_JUDGE
	cerr << "Time: " << duration.count() / 1000.0 << endl;
#endif
	return 0;
}

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

using namespace std;

int main() {
  
  int N;
  
  while(cin >> N && N != -1) {
    string s;
    
    if(N == 0) s = "0";
    while(N > 0) {
      s = (char)('0' + (N % 4)) + s;
      N /= 4;
    }
    
    cout << s << endl;
  }
  
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

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

	ll N=in<ll>(),K=in<ll>();
	
	ll ans = 1;
	REP(i,N){
		ans *= K;
		ans %= atcoder_mod;
	}
	out(ans);
	return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;

  ll ans = n;
  while (1) {
    ll tmp = ans;
    ll v = tmp % 10;

    bool match = true;
    while (tmp) {
      ll a = tmp % 10;
      if (v != a) {
        match = false;
        break;
      }
      tmp /= 10;
    }
    if (match)
      break;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int N, odd;
int main(){
    scanf("%d", &N);
    for (int i = 1; i <= N; i+=2) {
        odd++;
    }
    double ans = (odd+0.0)/N;
    printf("%lf\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int n, m, d;
	cin >> n >> m >> d;
	bool a[100][100];
	string b;
	for (int i = 0; i < n; i++) {
		cin >> b;
		for (int j = 0; j < m; j++) {
			if (b[j] == '.')
				a[i][j] = true;
			else
				a[i][j] = false;
		}
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[i][j]) {
				if (i >= d - 1) {
					bool c = true;
					for (int z = 0; z < d; z++)
						if (!a[i - z][j]) c = false;
					if (c) sum++;
				}
				if (i < n - d) {
					bool c = true;
					for (int z = 0; z < d; z++)
						if (!a[i + z][j]) c = false;
				}
				if (j >= d - 1) {
					bool c = true;
					for (int z = 0; z < d; z++)
						if (!a[i][j - z]) c = false;
					if (c) sum++;
				}
				if (j < m - d) {
					bool c = true;
					for (int z = 0; z < d; z++)
						if (!a[i][j + z]) c = false;
				}
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3152
//shan61916
	#include <bits/stdc++.h>
	  using namespace std;
	typedef   long long ll;
	typedef   unsigned long long ull ;
	typedef   double dll ;

	#define   mp make_pair
	#define   pb push_back
	#define   ff first 
	#define   ss second
	#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	#define   endl "\n" 
	#define   pll pair<ll, ll>
	#define   all(x) x.begin(), x.end()
	#define   vll vector<ll> 
	 string s; 
	const ll modd = (ll)(1e9 + 7);
	ll n;
	ll modadd(ll x, ll y) {
		return (x%modd + y%modd)%modd; 
	}
	ll dp[100005][18] ;
	ll recurse(ll idx, ll mod) {
		if(idx >= n) {
			if(mod == 5) return 1;
			else return 0 ; 
		}
	   ll &ans = dp[idx][mod] ;
	   if(ans != -1) return ans ;
	   ans = 0;
	   if(s[idx] != '?') {
	   	ll tt = s[idx] - '0' ;
	   	tt = (mod*10 + tt)%13 ;
	    ans = modadd( ans, recurse(idx+1, tt)) ;
	    return ans ;
	   } 
	   for(ll i = 0; i <= 9; i++) {
	   	ll tt = (mod*10 + i)%13 ;
	    ans = modadd(ans , recurse(idx+1, tt)) ;
	   }
	   return ans;
	}
	int main(){
	 IOS
	#ifdef SHAN
	    freopen("input.txt" , "r" , stdin);  
	#endif
	    cin >> s;
	    n = s.length(); 
	    memset(dp, -1, sizeof(dp)) ;
	    ll ans = recurse(0, 0) ;
	    cout << ans << endl;
	  return 0;
	} //good night.

Measured memory_bytes: 20816
loop{
input = gets.chomp
h = 20.0
y = 4.0
m,d = input.split(" ").map{|e| e.to_f}
exit if m==0 and d==0
if m==1 or m==2 then
  m+=12
  y-=1
end
w=y+(y/4).floor+(h/4).floor-2*h+(13*(m+1)/5).floor+d
w=w.to_i
r=w % 7

case r
when 1 then
  puts "Sunday"
when 2 then
  puts "Monday"
when 3 then
  puts "Tuesday"
when 4 then
  puts "Wednesday"
when 5 then
  puts "Thursday"
when 6 then
  puts "Friday"
when 0 then
  puts "Saturday"
end
}

Measured memory_bytes: 6136
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>
#include <iomanip>

using namespace std;

int main()
{
	
	string s;
	int N;
	cin >> N;
	cin >> s;
	int c = 0;
	
	for (int i =0; i<N-2; i++)
	{
		if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') c++;
		
	}
	cout << c <<endl;
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                while(true){
                        int N = sc.nextInt();
                        if (N == 0) {
                                break;
                        }
                        String[] Sinput = new String[N];
                        for (int i = 0; i < N; i++) {
                                Sinput[i] = sc.next();
                        }
                        boolean finish = false;
                        for (int q = 1; q <= 50; q++) {
                                String[] memo = new String[N];
                                boolean fx = false;
                                for (int x = 0; x < N; x++) {
                                        int count = 0;
                                        memo[x] += Sinput[x].charAt(0);
                                        count++;
                                        int idx = 0;
                                        while (idx < Sinput[x].length() - 1 && count < q) {
                                                switch (Sinput[x].charAt(idx)) {
                                                        case 'a':
                                                        case 'i':
                                                        case 'u':
                                                        case 'e':
                                                        case 'o':memo[x]+=Sinput[x].charAt(idx + 1);count++;break;
                                                }
                                                idx++;
                                        }
                                        boolean f = false;
                                        for (int y = 0; y < x; y++) {
                                                if (memo[x].equals(memo[y])) {
                                                        f = true;
                                                        break;
                                                }
                                        }
                                        if (f) {
                                                fx = true;
                                                break;
                                        }
                                }
                                if (fx) {
                                        continue;
                                }
                                System.out.println(q);
                                finish = true;
                                break;
                        }
                        if (!finish) {
                                System.out.println(-1);
                        }
                }
        }
}

Measured memory_bytes: 60980
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int left = 0;
        int right = N;
        for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        }

        if (left <= right) {
            System.out.println(right - left + 1);
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 63908
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
k=0
for i in range(n):
    a=(list(map(int,input().split())))
    ans=0
    for i in range(m):
        ans+=a[i]*b[i]
    if ans+c>0:
        k+=1
print(k)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(ll i=0;i<n;i++)
#define repp(i,a,b) for(ll i=a;i<=b;i++)
#define reff(i,a,b) for(ll i=a;i>=b;i--)
#define ll long long int
#define pll pair<ll,ll>
#define fill(a,x) memset(a,x,sizeof(a))
#define mb make_pair
#define pb push_back
#define F first
#define S second
#define M 1000000007
#define dbg(a)         std::cerr<<#a<<"="<<(a)<<"\n"
#define dbg1(a,b)       std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define dbg2(a,b,c)     std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define dbg3(a,b,c,d)   std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define co cout<<"fuck"<<endl;
const int INF = 2034567891;
const ll INF64 = 1234567890123456789ll;
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int main()
{
	ll n;
	cin>>n;
	ll a[3*n];
	rep(i,3*n)
	cin>>a[i];
	sort(a,a+3*n);
	ll cnt=0,sum=0;
	reff(i,3*n-2,0)
	{
		if(cnt==n) break;
		sum+=a[i];
		cnt++;
		i--;
	}
	cout<<sum;
}

Measured memory_bytes: 2560
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

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

int n;
vector<int> a;

void read_input()
{
    cin >> n;
    a.resize(n);
    for(auto&x: a) cin >> x;
    sort(a.begin(), a.end());
}

void solve()
{
    int ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = i + 1; j < n; ++j)
            for(int k = j + 1; k < n; ++k)
            {
                if(a[i] == a[j] || a[i] == a[k] || a[j] == a[k])
                    continue;
                if(a[i] + a[j] > a[k])
                    ++ans;
            }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 3624
from collections import Counter

n, k = map(int, input().split())
num_lists = list(map(int, input().split()))

num_counts = dict()
length = len(set(num_lists))
ans = 0

if length > k:
  d = Counter()
  d.update(num_lists)
  count_sorted = list(d.values())
  count_sorted.sort()
  for i in range(length - k):
    ans += count_sorted[i]

print(ans)

Measured memory_bytes: 39000
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#ifndef LOCAL
#define endl '\n'
#endif

const int mod = 1e9 + 7;

int pwr(int a,int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

int n, m;
const int N = 1e5 + 5;
int cnt[N];

ll f(ll x, ll n) {
	if(x == 0)
		return 0;
	if(n % x == 0) {
		return (2 * (n / x) - 2) * x;
	}
	ll val = ((2 * (n / x) - 1) * x + (n % x) + f(n % x, x));
	return val;
}

void solve() {
	ll n, x;
	cin >> n >> x;
	cout << x + f(n - x, n);
}

signed main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	// cin >> t;
	t = 1;
	for(int tt = 1; tt <= t; tt++) {
		// cout << "Case #" << tt << ": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 256