akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N,K;
	cin>>N>>K;
	cout<<N-K+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

lint a_memo[51] = {0};
lint a( lint l ) {
    if( a_memo[l] ) return a_memo[l];
    if( l == 0 ) return 1;
    return a_memo[l] = a(l-1) * 2 + 3;
}

lint p_memo[51] = {0};
lint p( lint l ) {
    if( p_memo[l] ) return p_memo[l];
    if( l == 0 ) return 1;
    return p_memo[l] = p(l-1) * 2 + 1;
}

lint f( lint n, lint x ) {
    if( x == 0 ) return 0;
    if( x == a(n) ) return p(n);
    if( x <= a(n)/2 ) return f(n-1, x-1);
    if( x == a(n)/2 +1) return p(n-1) + 1;
    return p( n-1 ) + 1 + f(n-1, x - a(n) / 2 -1 );
}

int main(){ cin.tie(0); ios::sync_with_stdio(false);
    int N = in; //  ←[1,50]
    lint X = in;//  ←[1, a(N)]
    cout << f(N, X) << "\n";
}


Measured memory_bytes: 256
NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
ks = []
k = []
s = []
for ind in range(M):
    ks.append(list(map(int,input().split())))
    k.append(ks[ind][0])
    s.append(ks[ind][1:])
p = list(map(int, input().split()))

count = 0
onoff = [0 for _ in range(N)]
for switch in range(1<<N):
    res = switch
    for ind in range(N):
        onoff[ind] = res&1
        res = res>>1
    
    on = 0
    for denkyu in range(M):
        su = 0
        for sw in s[denkyu]:
            su = su + onoff[sw-1]
        if p[denkyu] == (su % 2):
            on = on + 1
    
    if on == M:
        count = count + 1

print(count)


Measured memory_bytes: 3064
class Sieve:
    """区間[2,n]の値を素因数分解する"""

    def __init__(self, n=1):
        primes = []
        f = [0] * (n + 1)
        f[0] = f[1] = -1
        for i in range(2, n + 1):  # 素数を探す
            if f[i]: continue
            primes.append(i)
            f[i] = i  # 素数には自身を代入
            for j in range(i * i, n + 1, i):  # 合成数に素因数を書き込む
                if not f[j]:
                    f[j] = i  # 最小の素因数を代入
        self.primes = primes
        self.f = f

    def is_prime(self, x) -> bool:  # 素数判定
        return self.f[x] == x

    def factor_list(self, x) -> list:  # 素因数分解の昇順リスト, [2,2,3,5,...]
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res

    def factor(self, x) -> list:  # 素因数分解の頻度リスト, [[2,x],[3,y],[5,z],...]
        fl = self.factor_list(x)
        if not fl: return []
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res


def main():
    from collections import Counter

    MOD = 10 ** 9 + 7

    N = int(input())

    sv = Sieve(n=N)

    ctr = Counter()
    for x in range(1, N + 1):
        ctr.update(sv.factor_list(x))

    ans = 1
    for cnt in ctr.values():
        ans = ans * (cnt + 1) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1e4+5;
int ans[MAX];
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
  int x=n;
  for (n=1;n<=x;n++)
  {
  	int ans=0;
	  for (int i=1;i<=n;i++)
	   for (int j=1;j*j+i*i+j*i<=n;j++)
	     for (int k=1;i*i+j*j+k*k+i*j+i*k+k*j<=n;k++)
	     {
	     	 if (i*i+j*j+k*k+i*j+i*k+k*j==n)ans++;
	     }
	  cout<<ans<<"\n";
  }
  return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
int main(){
    int n;
    int a[100005];
    int cnt[100005];
    MEM(cnt);
    scanf("%d",&n);
   // for(int i = 0;i<100;i++){
    if(n==2){
        printf("-1\n");
        return 0;
    }
    for(int i = 1;i<=n;i++){
        scanf("%d",&a[i]);
       // a[i]=rand()%n+1;
      //  while(a[i]==i)a[i]=rand()%n+1;
      //  printf("%d ",a[i]);
        cnt[a[i]]++;
    }
   // printf("\n");
    priority_queue<pii> pq;
    for(int i = 1;i<=n;i++){
        pq.push(mp(cnt[i],i));
    }
    set<int> s;
    for(int i = 1;i<=n;i++){
        s.insert(i);
    }
    int ans[100005];
    for(int i = 1;i<=n;i++){
        ans[i]=0;
        while(!pq.empty()&&pq.top().x==n-i){
            if(s.find(pq.top().y)==s.end()){
                pq.pop();
            }
            else if(cnt[pq.top().y]==n-i){
                assert(ans[i]==0);
                ans[i]=pq.top().y;
                pq.pop();
            }
            else{
                pq.pop();
            }
        }
        if(!ans[i]){
            int x=*s.begin();
            s.erase(s.begin());
            if(a[ans[i-1]]!=x){
                ans[i]=x;
                if(i==n-2){
                    vector<int> v(s.begin(),s.end());
                    if(a[v[0]]==v[1]&&a[v[1]]==v[0]){
                        if(a[ans[i-1]]!=v[0]){
                            ans[i]=v[0];
                        }
                        else{
                            ans[i]=v[1];
                        }
                    }
                }
                s.insert(x);
                
            }
            else{
                ans[i]=*s.begin();
                s.insert(x);
                if(i==n-2){
                    s.erase(ans[i]);
                    int tmp=ans[i];
                    vector<int> v(s.begin(),s.end());
                    if(a[v[0]]==v[1]&&a[v[1]]==v[0]){
                        ans[i]=v[1];
                        //s.insert(ans[i])
                    }
                    s.insert(tmp);
                }
                
            }
        }
        s.erase(ans[i]);
        cnt[a[ans[i]]]--;
        pq.push(mp(cnt[a[ans[i]]],a[ans[i]]));
    }
    for(int i= 1;i<=n;i++)
        printf("%d ",ans[i]),assert(ans[i]);
    printf("\n");
   // }
}


Measured memory_bytes: 8176
#include <iostream>
#include<cmath>
using namespace std;
int main (){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(c-a)<=d||(abs(b-a)<=d&&abs(c-b)<=d)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    //B - Toll Gates
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int X = scanner.nextInt();
        int[] A = new int[100];
        for(int i = 0; i < M; i++) {
            int m = scanner.nextInt();
            A[m] = 1;
        }
        int cost1 = 0;
        for(int i = 0; i < X; i++) {
            cost1 += A[i];
        }

        int cost2 = 0;
        for(int i = X; i < N; i++) {
            cost2 += A[i];
        }
        System.out.println(Math.min(cost1, cost2));
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

unsigned rando() {
	static unsigned y = 2463534242;
    y ^= y << 13;y ^= y >> 17;y ^= y << 5;
    return y;
}

int d;

int c[26];
int s[365][26];

int score(vector<int>& t) {
	int score = 0;
	vector<int> last(26,0);
	rep(i, d) {
		score += s[i][t[i]];
		last[t[i]] = (i + 1);

		rep(j,26) {
			score -= ((i + 1) - last[j]) * c[j];
		}
		cout  << score << endl;

	} 


	return score;

}


int main() {
	cin >> d;
	rep(i, 26) {
		cin >> c[i];
	} 
	rep(i, d) {
		rep(j,26) {
			cin >> s[i][j];
		}
	}
	vector<int> t(d);

	rep(i, d) {
		//t[i] = rando() % 26 + 1;
		cin >> t[i];
		t[i]--; 
	}
	score(t);

	//cout << "score:" <<  << endl;

	return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  for(int i=0;i<n;i++){
    if(ans>=n-i){
      break;
    }
    int z;
    if(s[i]=='A'){
      for(int j=i+1;j<n;j++){
        z=0;
        if(s[j]=='Z'){
          z=j-i+1;
          if(ans<z){
            ans=z;
          }
        }
      }
      i+=z;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int r,d,x;
  cin >> r >> d >> x;
  rep(i,10){
    x = r*x-d;
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a , b) << endl;
    return 0;
}


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

const int MAX_N = 1e+5 + 1;

ll A[MAX_N];

int main() {
    ll N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> A[i];
    ll max_k = 0;
    ll tmp = K, c = 0;
    while (tmp > 0) {
        tmp /= 2;
        c++;
    }
    c--;
    for (ll i = c; i >= 0; i--) {
        int cnt = 0;
        for (int j = 0; j < N; j++) {
            if ((A[j] >> i) & 1) {
                cnt++;
            }
        }
        if (cnt * 2 < N && (max_k | (1LL << i)) <= K) {
            max_k |= (1LL << i);
        }
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += A[i] ^ max_k;
    }
    cout << ans << endl;
    return 0;
}

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

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

	int eat = N * 100;
	int eat_idx;
	vector<int> vec(N);
	for (int i = 0; i < N; ++i)
	{
		vec[i] = L + i;
		if (eat > abs(vec[i]))
		{
			eat = abs(vec[i]);
			eat_idx = i;
		}
	}

	vec.erase(vec.begin() + eat_idx);
	int ans = accumulate(vec.begin(), vec.end(), 0);

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >>S;
  int N=S.size();
  if (N%2==1){
    cout <<"No" <<endl;
  }
  else {
    int k=N/2;
    int A=1;
    cin >>k >>A;
    for (int j = 0; j < k; j++) {
      if (S.at(2*j)=='h'&&S.at(2*j+1)=='i'){
        A*=1;
        }
      else {
        A*=0;
      }
    }
    if (A==0){
      cout <<"No" <<endl;
    }
    else{
      cout <<"Yes"<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <cstdlib>
long long min4(long long x, long long y, long long z, long long w) {
    if (x > y) x = y;
    if (x > z) x = z;
    if (x > w) x = w;
    return x;
}
int main() {
    int a, b, q;
    std::cin >> a >> b >> q;
    std::vector<long long> s(a + 2), t(b + 2), st(a + 2), ts(b + 2);
    for (int i = 1; i <= a; i++) std::cin >> s[i];
    for (int i = 1; i <= b; i++) std::cin >> t[i];
    s[0] = t[0] = LLONG_MIN / 2;
    s[a + 1] = t[b + 1] = LLONG_MAX / 2;
    for (int i = 1, j = 1; i <= a || j <= b;) {
        if (s[i] < t[j]) {
            st[i] = std::min(t[j] - s[i], s[i] - t[j - 1]);
            i++;
        } else {
            ts[j] = std::min(s[i] - t[j], t[j] - s[i - 1]);
            j++;
        }
    }
    st[0] = ts[0] = st[a + 1] = ts[b + 1] = 0;
    for (int i = 0; i < q; i++) {
        long long x;
        std::cin >> x;
        int j = std::lower_bound(s.begin(), s.end(), x) - s.begin();
        int k = std::lower_bound(t.begin(), t.end(), x) - t.begin();
        std::cout << min4(
            std::abs(x - s[j - 1]) + st[j - 1],
            std::abs(x - s[j]) + st[j],
            std::abs(x - t[k - 1]) + ts[k - 1],
            std::abs(x - t[k]) + ts[k]
        ) << std::endl;
    }
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		int n = str.length(), tmp;
		long[] bef = new long[2019], aft = new long[2019];
		long ans = 0;
		for(int i = 0; i < n; i++){
			tmp = str.charAt(i)-'0';
			aft[tmp]++;
			for(int k = 0; k < 2019; k++){
				aft[(k*10+tmp)%2019] += bef[k];
			}
			ans += aft[0];
			for(int j = 0; j < 2019; j++){
				bef[j] = aft[j];
			}
			Arrays.fill(aft, 0);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 41172
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

string N, M;

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

    cout << M << N << endl;
    return 0;
}


Measured memory_bytes: 256
list_antennas = [int(input()) for i in range(5)]

k = int(input())

list_mutual_distance = []


for i in list_antennas:
	for j in list_antennas:
		if j <= i:
			continue
		else:
			dist_ij = j - i
			list_mutual_distance.append(dist_ij)

max_distance = max(list_mutual_distance)


if max_distance <= k:
	print("Yay!")
else:
	print(":(")

Measured memory_bytes: 3060
import std.stdio, std.array, std.conv, std.typecons, std.algorithm;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

void main() {
    immutable input = readln.split.to!(ulong[]);
    immutable r = input[0], d = input[1], x2k = input[2];

    ulong x = x2k;
    for(ulong i = 0; i < 10; i++) {
        x = r * x - d;
        writeln(x);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
string L;
ll dp[100005][2];
int main(){
    cin >> L;
    
    dp[1][0] = 2;
    dp[1][1] = 1;
    
    repi(i,2,sz(L)){
        if(L[i-1] == '1'){
            dp[i][1] = (dp[i-1][1]*3 + dp[i-1][0])%MOD;
            dp[i][0] = dp[i-1][0]*2%MOD;
        }else{
            dp[i][1] = dp[i-1][1]*3%MOD;
            dp[i][0] = dp[i-1][0]%MOD;
        }
    }
    
    pr((dp[sz(L)][0]+dp[sz(L)][1])%MOD);
    
}

Measured memory_bytes: 2000
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	int ans = 0;
	FOR(i,1,n){
		if(i<n-i) ans++;
	}

	cout << ans << '\n';
	return 0;
}



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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

int modpow(int a, int n, int m = MOD){
    ll ret = 1;
    while(n>0){
        if(n&1) ret = (ret*a) % m;
        a = (a*a) % m;
        n >>= 1;
    }
    return ret % m;
}

signed main() {
    int n; cin >> n;
    int ans = modpow(10, n);
    ans = mod(ans - 2 * modpow(9,n));
    ans = mod(ans + modpow(8,n));
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(){
    int s,l,r,flag1=1,flag2=1; cin >> s;
    l = s/100;
    r = s%100;
    if (1<=l && l<=12) flag1 = 0;
    if (1<=r && r<=12) flag2 = 0;
    
    if (flag1==0 && flag2==0) cout << "AMBIGUOUS" << endl;
    else if (flag1==1 && flag2==0) cout << "YYMM" << endl;
    else if (flag1==0 && flag2==1) cout << "MMYY" << endl;
    else cout << "NA" << endl;
}

Measured memory_bytes: 256
#define P(x) cout << #x" = " << x << endl
#define PP(x, y) cout << "("#x", "#y") = (" << x << ", " << y << ")" << endl
#define PPP(x, y, z) cout << "("#x", "#y", "#z") = (" << x << ", " << y << ", " << z << ")" << endl

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
using ll = long long;
int n, m;
int x[100000];
int dx[100000];
int main(){
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }
    sort(x, x + m);
    ll ans = 0;
    for (int i = 0; i < m - 1; ++i) {
        dx[i] = x[i + 1] - x[i];
        ans += dx[i];
    }
    sort(dx, dx + m - 1, greater<int>());
    for (int i = 0; i < min(m - 1, n - 1); ++i) {
        ans -= dx[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;


int str2num(const string& station,map<string,int>& dict){
  if(dict.find(station) == dict.end()){
    int idx = dict.size();
    dict[station] = idx;
    return idx;
  }
  return dict[station];
}

int dp[1001][1001];

int main(){
  int total_stations;
  int total_lines;

  while(~scanf("%d %d",
               &total_stations,
               &total_lines)){
    if(total_lines == 0) break;

    map<string,int> dict;
    string shirokuro_location;
    string R2d_location;
    string Aizu_location;

    cin >> shirokuro_location >> R2d_location >> Aizu_location;
    memset(dp,0x3f,sizeof(dp));

    for(int line_idx = 0; line_idx < total_lines; line_idx++){
      string from,to;
      int distance;
      int delay;
      cin >> from >> to >> distance >> delay;
      int cost = distance / 40 + delay;
      dp[str2num(from,dict)][str2num(to,dict)] = cost;
      dp[str2num(to,dict)][str2num(from,dict)] = cost;
    }

    for(int k=0;k<total_stations;k++){
      for(int i=0;i<total_stations;i++){
        for(int j=0;j<total_stations;j++){
          dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
        }
      }
    }

    printf("%d\n",dp[str2num(shirokuro_location,dict)][str2num(R2d_location,dict)]
           + dp[str2num(R2d_location,dict)][str2num(Aizu_location,dict)]);
  }
}

Measured memory_bytes: 5244
//Registration 

#include<bits/stdc++.h>
using namespace std;

int main()
{
	bool ok = true;
	string s , t ; int  lens , lent ;
	cin>>s;
	cin>>t;
	lens = s.size();
	lent = t.size();
	for(int i=0; i<(lent-1); i++)
	{
		if(s[i]==t[i])
		{
			ok = true;
		}
		else
		{
			ok = false;
			break;
		}
	}
	ok==true?cout<<"Yes\n":cout<<"No\n";
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
int main()
{
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int s = 0;
  re(i, a+1) {
    re(j, b+1) {
      re(k, c+1) {
        if (500 * i + 100 * j + 50 * k == x) s++;
      }
    }
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
ab = []

for _ in range(n):
	ab.append(list(map(int,input().split())))

ab.sort()

ans = 0
for i in range(n):
	if ab[i][1] >= m:
		ans += ab[i][0] * m
		break
	else:
		ans += ab[i][0] * ab[i][1]
		m -= ab[i][1]
print(ans)


Measured memory_bytes: 27760
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
//typedef pair<int, int> P;
struct P {
	int x, y;
	P(int x, int y):x(x), y(y){}
	P(){}
};

/** Problem2242 : Era Name **/
struct Era {
	int s, e;
	string name;
	Era(int _s, int _e, string _name):s(_s), e(_e), name(_name){}
	Era(){}
};

int main()
{
	int N, M;
	while (cin>>N>>M, N||M) {
	
		vector<Era> era(N);
		rep(i, N) {
			int a, b;
			cin>>era[i].name>>a>>b;
			era[i].e = b;
			era[i].s = b-a+1;
		}
	
		rep(i, M) {
			int a; cin>>a;
			bool ok=false;
			rep(j, N) {
				if (era[j].s <= a && a <= era[j].e) {
					cout << era[j].name << " " << a-era[j].s+1 << endl;
					ok=true;
					break;
				}
			}
			if (!ok)
				cout << "Unknown" << endl;
		}
	}
}

Measured memory_bytes: 1280
// C++ program to answer queries 
// of nCr in O(1) time. 
#include <bits/stdc++.h> 
#define ll long long 
const int N = 2700; 
using namespace std; 

// array to store inverse of 1 to N 
ll factorialNumInverse[N + 1]; 

// array to precompute inverse of 1! to N! 
ll naturalNumInverse[N + 1]; 

// array to store factorial of first N numbers 
ll fact[N + 1]; 

// Function to precompute inverse of numbers 
void InverseofNumber(ll p) 
{ 
	naturalNumInverse[0] = naturalNumInverse[1] = 1; 
	for (int i = 2; i <= N; i++) 
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; 
} 
// Function to precompute inverse of factorials 
void InverseofFactorial(ll p) 
{ 
	factorialNumInverse[0] = factorialNumInverse[1] = 1; 

	// precompute inverse of natural numbers 
	for (int i = 2; i <= N; i++) 
		factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; 
} 

// Function to calculate factorial of 1 to N 
void factorial(ll p) 
{ 
	fact[0] = 1; 

	// precompute factorials 
	for (int i = 1; i <= N; i++) { 
		fact[i] = (fact[i - 1] * i) % p; 
	} 
} 

// Function to return nCr % p in O(1) time 
ll Binomial(ll N, ll R, ll p) 
{ 
	// n C r = n!*inverse(r!)*inverse((n-r)!) 
	ll ans = ((fact[N] * factorialNumInverse[R]) 
			% p * factorialNumInverse[N - R]) 
			% p; 
	return ans; 
} 

// Driver Code 
int main() 
{ 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// Calling functions to precompute the 
	// required arrays which will be required 
	// to answer every query in O(1) 
	ll p = 1000000007; 
	InverseofNumber(p); 
	InverseofFactorial(p); 
	factorial(p); ll S;
    cin>>S;
    long int lim= S/3,ans=0;
    if(S<3)cout<<0;
    else{
      for(int i=0;i<lim;i++){
      	S-=3;
        ans=(ans+Binomial(i+S,i,p))%p;
      }
      cout<<ans;
    }
	
	return 0; 
} 


Measured memory_bytes: 3680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC087A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, a, b, c;

            x = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            c = (x - a) % b;

            Console.WriteLine(c);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11220
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPS(i,n) for(int i=0; i<(n); i++)
#define REPinit(a,n) for(int i=a; i<(n); i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

double eauclidDistance(pair<double, double>& x1, pair<double, double>& x2) {
  return sqrt((x1.first - x2.first) * (x1.first - x2.first) + (x1.second - x2.second) * (x1.second - x2.second));
}

void swap(int& a, int& b) {
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

int main(int argc, char const *argv[])
{
  int A,B;
  int ans = 0;

  cin >> A >> B;
  int u,v,l,m;
  REPinit(A,B+1){
    u = i / 10000 % 10;
    v = i / 1000 % 10;
    m = i % 10;
    l = i / 10 % 10;
    if(u == m && v == l) ans++;
  }
  cout << ans << endl;
  return 0;
}
	

Measured memory_bytes: 256
N = input()
W = []
for i in range(N):
	w = raw_input()
	W.append(w)

def calc():
	used = [W[0]]
	for i in range(N - 1):
		if W[i + 1] in used:
			return False
		if W[i][-1] != W[i + 1][0]:
			return False
		used.append(W[i + 1])
	return True

if calc():
	print "Yes"
else:
	print "No"


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x,y) fixed<<setprecision(y)<<x
#define ll long long
#define ld long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define lop(i,a,b) for(ll i=a;i<b;i++)
#define lopr(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define ff first
#define ss second
#define pi pair<int,int>
#define pll pair<ll, ll>
#define si set<int>
#define sll set<ll>
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define state tuple<int,int,int>
#define graph map<ll,list<ll>>

inline int sbt(int x){return __builtin_popcount(x);} //returns number of set bits

using namespace std;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

#define SIZE


int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    fast_io()
    
    int n;
    cin>>n;

    ld ans=0.0;
    while(n--){
    	ld val;
    	cin>>val;

    	string s;
    	cin>>s;

    	if(s=="JPY")
    		ans += val;
    	else
    		ans += (val*380000.0);
    }

    cout<<PSET(ans,12);
    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = []

for i in range(1,n+1):
    if i%3 == 0 or i%5== 0:
        pass
    else:
        lst1.append(i)
print(sum(lst1))

Measured memory_bytes: 103936
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new File("c:\\0520-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			if (n == 0)
				break;
			Player[] p = new Player[2];
			p[0] = new Player(n);
			p[1] = new Player(n);
			p[1].dealAll();
			for (int i = 0; i < n; i++) {
				int x = scan.nextInt();
				p[0].deal(x);
				p[1].remove(x);
			}
			game(p, 0, 0);
			System.out.println(p[1].remain());
			System.out.println(p[0].remain());
		}
		scan.close();
		System.exit(0);
	}

	private static void game(Player[] p, int tern, int card) {
		for (int i = 0; i < p.length; i++)
			if (p[i].isEmpty())
				return;
		int pay = p[tern].pay(card);
		int next = tern + 1;
		if (next == p.length)
			next = 0;
		game(p, next, pay);

	}
}

class Player {
	boolean[] card;
	int piece = 0;

	public Player(int n) {
		card = new boolean[2 * n + 1];
	}

	public int pay(int cur) {
		for (int i = cur + 1; i < card.length; i++)
			if (card[i]) {
				this.remove(i);
				return i;
			}
		return 0;
	}

	public boolean isEmpty() {
		if (piece == 0)
			return true;
		else
			return false;
	}

	public int remain() {
		/*
		 * int r = 0; for (int i = 1; i < card.length; i++) if (card[i]) r += i;
		 * return r;
		 */
		return piece;
	}

	public void remove(int x) {
		card[x] = false;
		piece--;
	}

	public void deal(int x) {
		card[x] = true;
		piece++;
	}

	public void dealAll() {
		for (int i = 1; i < card.length; i++) {
			card[i] = true;
			piece++;
		}
	}

}

Measured memory_bytes: 26240
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
int main()
{
	long long a = 0, b = 0, c = 0, hairetu[1000] = { }, mi = 0, ma = 0, ansa = 0, ansb = 0,count=1;
	using namespace std;
	int x=0,y=0,z=0;
	
		cin >> a;
	
	bool okada = true;
	for (int i = 1; i <=a; i++) {

		cin>>hairetu[i];
		if(hairetu[i]==hairetu[i-1]){
			count++;
		

			mi = count;
		}
		else{
			ansa += count / 2;
			count = 1;

		}
	
		
	
	}

	ansa += count / 2;

	cout <<ansa<<endl;

}







Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline
# import re
import itertools

def main():
    n = int(input())
    a = n % 1000
    if a > 0:
        print(1000 - a)
        exit()
    print(a)

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()



Measured memory_bytes: 61908
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  int count = 0;
  for (int i = 0; i < 4; i++) {
    if (a[i] == '+') {
      count++;
    }
    else {
      count--;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3548
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>
#include <set>
 
using namespace std;
 
int main( void ) {
    
    int a, b;
    cin >> a >> b;

    if (a > 9 || b > 9 || a < 1 || b < 1) {
        cout << "-1" << endl;
    } else {
        cout << a * b << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

string s;
ll ans=0;

void search(ll i,ll x,ll y){
    if(i==s.size()){
        ans+=x+y;
    }else{
        search(i+1,x,y*10+s[i]-'0');
        search(i+1,x+y,s[i]-'0');
    }
}

int main(){
    cin>>s;
    search(1,0,s[0]-'0');
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
const int MaxN = 1e5;
using namespace std;
int n;
int a[MaxN + 5]; // 1 - up , 2 - down
int main()
{
	while(~scanf("%d" , &n)){
		for(int i = 1;i <= n;i++) scanf("%d" , &a[i]);
		int ok = 1;
		for(int i = 2;i <= n;i++){
			if(a[i] > a[1]) { ok = 1; break;}
			if(a[i] < a[1]) { ok = 0; break;}
		}
		int ans = 1;
		for(int i = 2;i <= n;i++){
			if(ok){
				if(a[i] - a[i - 1] < 0){
					ans++;
					for(int j = i + 1;j <= n;j++){
						if(a[j] > a[i]) { ok = 1;break;}
						if(a[j] < a[i]) { ok = 0;break;}
					}
				}
			}
			else if(!ok){
				if(a[i] - a[i - 1] > 0){
					ans++;
					for(int j = i + 1;j <= n;j++){
						if(a[j] > a[i]) { ok = 1;break;}
						if(a[j] < a[i]) { ok = 0;break;}
					}
				}
			}
		}
		printf("%d\n" , ans);
	}
}

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

int main() {
    string S;//文字列型変数Sを宣言
    cin >> S;//変数Sに入力
    //文字列Sの4文字目を'８'に書き換え
    S[3] = '8';
    cout << S << endl;//文字列Sを出力
}

Measured memory_bytes: 256
n = int(input())
l  = list(map(int,input().split()))
import itertools
c=0
for i in list(itertools.combinations(l,3)):
    x = list(i)
    x.sort()
    if x[0]!=x[1] and x[1]!=x[2]:
        if x[0]+x[1]>x[2]:
            # print(x)
            c +=1
print(c)

Measured memory_bytes: 20616
#include<bits/stdc++.h>
using namespace std;
vector<long long>v;
int main()
{
    long long n,m,a,b,i,j,x,y,sum;

    while(scanf("%lld",&n)==1)
    {
        v.clear();
        sum = 0;
        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a);
            v.push_back(a);
        }

        sort(v.begin(),v.end());
        x = n-2;
        sum+=v[n-1];
        for(i=v.size()-2;i>=1;i--)
        {
            sum+=v[i];
            x--;
            if(x==0)break;
            sum+=v[i];
            x--;
            if(x==0)break;
        }

        printf("%lld\n",sum);


    }












return 0;
}


Measured memory_bytes: 5364
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int main(){
	int m;cin >> m;
	ll digit = 0;
	ll res = 0;
	rep(i,m){
		ll c;
		ll d;cin >> d >> c;
		digit += c;
		res += c*d;
	}
	ll ans = digit-1+res/9;
	if(res%9==0) ans--;
	cout << ans << endl;

}
 
 

Measured memory_bytes: 3600
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string T="CODEFESTIVAL2016";
	string S;
	scan(S);
	int ans=0;
	rep(i,S.size()){
		if(S[i]!=T[i]) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;
    int ans = 0;
    int tmp = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T')
        {
            tmp++;
        }
        else
        {
            ans = max(ans, tmp);
            tmp = 0;
        }
    }
    cout << max(ans, tmp) << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
sei=[0]*n
mai=0
zero=0
pr=0
for i in range(n):
  sei[i]=max(a[i],-a[i])
  pr+=sei[i]
  if a[i]<0:
    mai +=1
  elif a[i]==0:
    zero+=1
  else:
    pass
#ゼロと負の数を数える
if mai%2==0 or zero >=1:
    print(pr)
else:
    print(pr-2*min(sei))


Measured memory_bytes: 14412
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <bitset>
#define MAX_N 16005
#define MAX_R 17005
#define D 8010

using namespace std;

int n,x,y;
char s[MAX_N];
vector<int> v[2];
bitset<MAX_R> b[2];

void read()
{
	scanf("%s%d%d",s+1,&x,&y);
	n=strlen(s+1);
}

void cal_v()
{
	int k=0,cnt=0; s[n+1]='T';
	for(int i=1;i<=n+1;i++)
	{
		if(s[i]=='T') v[k].push_back(cnt),k^=1,cnt=0;
		else cnt++;
	}
}

void cal_b()
{
	b[0][v[0][0]+D]=1;
	for(int i=1;i<v[0].size();i++)
	{
		int len=v[0][i];
		b[0]=(b[0]<<len)|(b[0]>>len);
	}
	b[1][D]=1;
	for(int i=0;i<v[1].size();i++)
	{
		int len=v[1][i];
		b[1]=(b[1]<<len)|(b[1]>>len);
	}
}

void work()
{
	cal_v();
	cal_b();
	if(b[0][x+D] && b[1][y+D]) printf("Yes\n");
	else printf("No\n");
}

int main()
{
	read();
	work();
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";
#ifndef ONLINE_JUDGE
#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);
#else
#define freopen ios_base::sync_with_stdio(0);cin.tie(0); //Alperen_T
#endif

int main(){
	char arr[200001];
	cin >> arr;

	long long int len = strlen(arr);

	int mods[len + 1];
	mods[len - 1] = 1;
	mods[len - 2] = 10;
	for(int i = len - 3; i >= 0; i--){
		mods[i] = (mods[i + 1] * mods[len - 2]) % 2019;
	}

	long long int dp[200005] = {0}, j = 0;
	long long int nums[2050] = {0};
	int long long ans = 0;

	for(int i = strlen(arr) - 1; i >= 0; i--){
		dp[i] = (dp[i + 1] + ((arr[i] - '0') * mods[i])) % 2019;
	}

	for(int i = 0; i < strlen(arr) + 1; i++){
		nums[dp[i]]++;
	}

	for(int i = 0; i < 2021; i++){
		ans += (nums[i] * (nums[i] - 1)) / 2;
	}

	cout << ans;
} 

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    ll next = 1, ans = 0;

    for (auto x : xs)
    {
        if (x != next)
            ++ans;
        else
            ++next;
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    auto ans = solve(N, xs);

    cout << (ans == N ? -1 : ans) << '\n';

    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());
            int n = int.Parse(Console.ReadLine());

            Console.WriteLine((long)n * 3.1415926535 * 2);


            //ここまで
        }

        static long Max(long a, long b)
        {
            if (a >= b) return a;
            else return b;
        }
    }

}


Measured memory_bytes: 27376
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

void unti(string s1){
    rep(i,(int)s1.size()){
        if(s1[i]=='R')cout<<"L";
        if(s1[i]=='L')cout<<"R";
        if(s1[i]=='U')cout<<"D";
        if(s1[i]=='D')cout<<"U";
    }
}


//////////////////////////////////////
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    int aa=a,bb=b,cc=c,dd=d;
    string s1="",s2="",s3="";
    
    while(aa<cc){
        s1+="R";
        aa++;
    }
    while(aa>cc){
        s1+="L";
        cc++;
    }
    while(bb<dd){
        s1+="U";
        bb++;
    }
    while(bb>dd){
        s1+="D";
        dd++;
    }
    
    cout<<s1;
    if(a==c||b==d){
        string s4="";
        if(a==c){
            s2="L";
            s3="R";
        }
        else{
            s2="R";
            s3="L";
        }
        s1=s2+s1+s3;
        cout<<s1;
        unti(s1);
        s4="";
        s4+=s1[0];
        s4+=s2+s2;
        cout<<s4;
        unti(s1);
        if(s1[0]=='U')cout<<"DD";
        if(s1[0]=='D')cout<<"UU";
        if(s1[0]=='R')cout<<"LL";
        if(s1[0]=='L')cout<<"RR";
        cout<<s3<<s3<<s1[0];
        return 0;
    }
    unti(s1);
    
    if(a<c&&b<d){
        s2+="DR";
        s3+="UL";
    }
    else if(a<c&&b>d){
        s2+="UR";
        s3+="DL";
    }
    else if(a>c&&b<d){
        s2+="DL";
        s3+="UR";
    }
    else{
        s2+="UL";
        s3+="DR";
    }

    
    string s4;
    s4+=s2+s1+s3;
    cout<<s4;
    unti(s4);

    cout<<endl;
    return 0;
}

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

using namespace std;


string s;

int calc(int sm) {
  int ret = 0;
  for (int i = 0; i < (int)s.size(); ++i) {
    ret += ((int)(s[i]-'0') + sm)%2==i%2;
  }
  return ret;
}
int main() {
  cin >> s;
  cout << min(calc(0), calc(1))  << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N;
long long int K;

long long int A[200005], F[200005];

vector<long long int> VA, VF;

int IS_POSSIBLE(long long int W) {

	if (W < 0) { return -1; }

	long long int cnt = 0;

	for (int i = 0; i < N; i++) {
		cnt += max((long long int) 0, VA[i]- W / VF[i]);
	}

	//cout << "cnt= " << cnt <<  "K= " <<K << endl;

	if (cnt <= K) { return 1; }

	return -1;

}

long long int BINARY_SEARCH(void) {

	long long int left = -1;
	long long int right = 1000000000000000006;

	long long int med;

	while (right - left > 1) {
		med = (right + left) / 2;

		if (IS_POSSIBLE(med) == 1) { right = med; }
		else { left = med; }
	}

	return right;
}

int main(void) {

	cin >> N >> K;

	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		VA.push_back(A[i]);
	}

	for (int i = 1; i <= N; i++) {
		cin >> F[i];
		VF.push_back(F[i]);
	}


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

	sort(VF.rbegin(), VF.rend());

	/*for (auto y : VA) { cout << " " << y; }
	cout << endl;

	for (auto y : VF) { cout << " " << y; }
	cout << endl;
	*/

	

	cout << BINARY_SEARCH()<< endl;
	
	return 0;
}

Measured memory_bytes: 7408
import collections

n = int(input())
a = [ int(x) for x in input().split() ]

def count_elem(x):
    coll = collections.Counter(x)
    return coll.most_common()

b = count_elem(a[::2])
c = count_elem(a[1::2])

if b[0][0] != c[0][0]:
    print(len(a) - b[0][1] - c[0][1])
else:
    if b[0][1] > c[0][1]:
        if len(c) > 1:
            print(len(a) - b[0][1] - c[1][1])
        else:
            print(len(a) - b[0][1])
    elif b[0][1] < c[0][1]:
        if len(b) > 1:
            print(len(a) - b[1][1] - c[0][1])
        else:
            print(len(a) - c[0][1])
    elif b[0][1] == c[0][1]:
        if len(a)/2 == b[0][1]:
            print(int(len(a)/2))
        else:
            if b[1][1] >= c[1][1]:
                print(len(a) - b[1][1] - c[0][1])
            else:
                print(len(a) - b[0][1] - c[1][1])


Measured memory_bytes: 20700
#include <stdio.h>

int main(void)
{
    int x[10];
    int i,j;
    int top[10] = {0};

    for (i = 0; i < 10; i++){
        scanf("%d", &x[i]);
        if (x[i] >= top[0]){
            top[2] = top[1];
            top[1] = top[0];
            top[0] = x[i];
        }else if (x[i] >= top[1] && x[i] < top[0]){
            top[2] = top[1];
            top[1] = x[i];
        }else if (x[i] >= top[2] && x[i] < top[1]){
            top[2] = x[i];
        }
    }
    for (i = 0; i < 3; i++){
        printf("%d\n", top[i]);
    }

    return (0);
}


Measured memory_bytes: 2032