akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

int main() {
    string s;
    cin >> s;
    string t(s);
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
    cout << (s == t ? "yes" : "no") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <utility>
#include <set>
using namespace std;
typedef pair<int,int> P_;
typedef pair<P_,P_> _P;
typedef pair<_P,int> P;
int M[50][50];
int dx1[]={1,0,-1,0},dy1[]={0,1,0,-1};
int dx2[]={-1,0,1,0},dy2[]={0,-1,0,1};
int main() {
	int X,Y;
	while(scanf("%d %d",&X,&Y),X) {
		int tx,ty,kx,ky;
		scanf("%d %d %d %d",&tx,&ty,&kx,&ky);
		tx--;ty--;kx--;ky--;
		for(int y=0;y<Y;y++) {
			for(int x=0;x<X;x++) {
				scanf("%d",&M[x][y]);
			}
		}
		set<_P> ST;
		ST.insert(_P(P_(tx,ty),P_(kx,ky)));
		queue<P> Q;
		Q.push(P(_P(P_(tx,ty),P_(kx,ky)),0));
		bool OK=false;
		while(!Q.empty()) {
			P p=Q.front();Q.pop();
			P_ T=p.first.first,K=p.first.second;
			if(p.second>=100)break;
			if(T.first==K.first&&T.second==K.second) {
					printf("%d\n",p.second);
					OK=true;
					break;
			}
			for(int i=0;i<4;i++) {
				int ntx=T.first+dx1[i],nty=T.second+dy1[i];
				int nkx=K.first+dx2[i],nky=K.second+dy2[i];
				if(0>ntx||ntx>=X||0>nty||nty>=Y||M[ntx][nty])
					ntx=T.first,nty=T.second;
				if(0>nkx||nkx>=X||0>nky||nky>=Y||M[nkx][nky])
					nkx=K.first,nky=K.second;
				if(ST.find(_P(P_(ntx,nty),P_(nkx,nky)))==ST.end()) {
					ST.insert(_P(P_(ntx,nty),P_(nkx,nky)));
					Q.push(P(_P(P_(ntx,nty),P_(nkx,nky)),p.second+1));
				}
			}
		}
		if(!OK)printf("NA\n");
	}
}

Measured memory_bytes: 12156
<?php
  list($n, $a, $b) = explode(" ", trim(fgets(STDIN)));

  $x = array_map('intval', explode(" ", trim(fgets(STDIN))));

  $ans = 0;
  for ($i=1; $i<$n; $i++) {
    if($a*($x[$i]-$x[$i-1]) > $b){
      $ans += $b;
    }else{
      $ans += $a*($x[$i]-$x[$i-1]);
    }
  }
  echo $ans;

Measured memory_bytes: 27228
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vi;
struct edge { int v; ll w; };

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
ll INF = INT_MAX;

struct binary_heap {
	int N;
	vector<int> a;
	binary_heap() : N(0) {}
	void push(int x) {
		a.pb(x); N++;
		for (int i = N - 1; i;) {
			int p = (i - 1) / 2;
			if (a[p] >= a[i]) break;
			swap(a[i], a[p]);
			i = p;
		}
	}
	int pop() {
		int x = a[0];
		swap(a[0], a[N - 1]);
		a.pop_back(); N--;
		for (int i = 0; i * 2 + 1 < N;) {
			int l = i * 2 + 1, r = i * 2 + 2;
			if (r < N && a[l] < a[r]) swap(l, r);
			if (a[l] <= a[i]) break;
			swap(a[i], a[l]);
			i = l;
		}
		return x;
	}
};

int main() {
	binary_heap q;
	for (;;) {
		char s[10]; scanf("%s", s);
		if (s[2] == 's') {
			int x; scanf("%d", &x);
			q.push(x);
		}
		if (s[2] == 't') {
			int x = q.pop();
			printf("%d\n", x);
		}
		if (s[2] == 'd') break;
	}
}

Measured memory_bytes: 6928
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        for(int i = 0; i < N; i++)
        {
            string a = s.Substring(i);
            string b = t.Substring(0, N  - i);
            //Console.WriteLine(a + " " + b);
            if (a == b)
            {
                Console.WriteLine(N * 2 - a.Length);
                return;
            }
        }
        Console.WriteLine(N * 2);
    }

}


Measured memory_bytes: 2648
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.equals("Sunny")) {
            System.out.println("Cloudy");
        } else if (s.equals("Cloudy")) {
            System.out.println("Rainy");
        } else {
            System.out.println("Sunny");
        }
    }
}

Measured memory_bytes: 21716
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = list(map(int, input().split()))
asort = sorted(a, key=lambda x: x[1])

sum = 0
for i in range(n):
    sum += asort[i][0]
    if sum > asort[i][1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 55252
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,W;
  cin>>n>>W;
  vector<int> w(n);
  vector<ll> v(n);
  rep(i,n)cin>>w[i]>>v[i];
  vector<vector<bool>> can(n,vector<bool>(W+1));
  vector<vector<ll>> dp(n,vector<ll>(W+1));
  can[0][0]=true;
  can[0][w[0]]=true;
  dp[0][w[0]]=v[0];
  repeat(i,1,n) {
    can[i][0]=true;
    repeat(ww,1,W+1) {
      dp[i][ww]=dp[i-1][ww];
      can[i][ww]=can[i-1][ww];
      if(ww-w[i]>=0&&can[i-1][ww-w[i]]) {
        can[i][ww]=true;
        dp[i][ww]=max(dp[i][ww],dp[i-1][ww-w[i]]+v[i]);
      }
    }
  }
  ll ans=0;
  repeat(ww,1,W+1) {
    ans=max(ans,dp[n-1][ww]);
  }
  cout << ans << endl;
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

bool is_prime(long long N)
{
    if (N <= 1)
        return false;
    if (N == 2)
        return true;
    long long ub = std::sqrt(N);
    if (ub * ub == N)
        return false;
    for (long long i = 3; i <= ub; i += 2)
    {
        if (N % i == 0)
            return false;
    }
    return true;
}

vector<LL> divisor(LL n)
{
    vector<LL> ret;
    for (LL i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

// 素因数
int divisors[100];

int num(int k)
{
    int ret = 0;
    REP1 (i, 100)
    {
        if (divisors[i] >= k - 1)
            ret++;
    }
    return ret;
}

void solve()
{
    int N;
    cin >> N;

    for (int i = 2; i <= N; i++)
    {
        int cur = i;
        for (int j = 2; j <= i; j++)
        {
            while (cur % j == 0)
            {
                divisors[j]++;
                cur /= j;
            }
        }
    }

    cout << num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) * (num(5) - 1) * (num(3) - 2) / 2 << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
import collections

n = int(input())

ss = []
for _ in range(n):
	ss.append(input())

c = collections.Counter(ss)

mc = c.most_common()
max_cnt = max([x[1] for x in mc])
ans = [x[0] for x in mc if x[1] == max_cnt]

ans.sort()
for x in ans:
	print(x)


Measured memory_bytes: 120528
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

typedef pair<P,Ps> PIS;
PIS team[10];

int main(){
	int a, b;
	while(cin >> a >> b && (a || b)){
		int cnt = 0;
		while(a > 0){
			if(b > a) swap(a, b);
			cnt++;
			a %= b;
		}
		cout << b << " " << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int> a(n);
    map<int, int> b;
    rep(i, n)
    {
        cin >> a[i];
        b[a[i]]++;
    }

    rep(i, n)
    {
        if (b[a[i]] < 2) {
            b.erase(a[i]);
        }
    }

    if (b.size() == 0) {
        cout << 0 << endl;
    } else {
        int a0, n;
        tie(a0, n) = *b.rbegin();
        if (n >= 4) {
            cout << (int64_t)a0 * a0 << endl;
        } else if (b.size() == 1) {
            cout << 0 << endl;
        } else {
            int a1;
            tie(a1, ignore) = *next(b.rbegin());
            cout << (int64_t)a0 * a1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 5376
line = gets.split(" ").map(&:to_i)
K = line[0]
X = line[1]

nums = []

i = 0
while i <= K-1
  a = X + i
  i += 1
  nums.push(a)
end

j = 0
while j <= K-2 
  b = X - j - 1
  j += 1
  nums.push(b)
end

nums.sort.each do |n|
  print "#{n} "
end

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

vector<bool> IsPrime;

// vector<pair<ll,int>> factorize(ll n) {
//     vector<pair<ll,int>> res;
//     for(ll i = 2; i*i <= n; ++i) {
//         if (n%i) continue;
//         res.emplace_back(i,0);
//         while (n%i == 0) {
//         n /= i;
//         res.back().second++;
//         }
//     }
//     if (n != 1) res.emplace_back(n,1);
//     return res;
// }

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

// void sieve(ll max){
//     if(max+1 > IsPrime.size()){  
//         IsPrime.resize(max+1,true); 
//     } 
//     IsPrime[0] = false;
//     IsPrime[1] = false;

//     for(ll i=2; i*i<=max; ++i)
//         if(IsPrime[i])
//             for(ll j=2; i*j<=max; ++j)
//                 IsPrime[i*j] = false;     
// }

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

    ll ans = 1;

    ll n = min(a,b);
    if(n == 1){
        cout << ans << endl;
        return 0;
    }

    ll x,y;
    ll d = extGCD(min(a,b),max(a,b),x,y);
    // cout << "gcd:" << d << endl;
    if(d == 1){
        cout << ans + 1 << endl;
        return 0;
    }
    
    for(ll i = 2; i*i <= d; ++i) {
        if (d%i) continue;
        while (d%i == 0) {
            d /= i;
        }
        // cout << "i:" << i << endl;
        ans++;
    }
    if(d != 1){
        // cout << "i:" << d << endl;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,k,r,s,p; cin>>n>>k>>r>>s>>p;
    string t; cin>>t;

    char dp[n+1];
    for(int i=0;i<=n;i++){
        dp[i]='q';
    }

    for(int i=0;i<k;i++){
        char ch=t[i];
        if(ch=='r')
            dp[i]='p';
        else if(ch=='p')
            dp[i]='s';
        else
            dp[i]='r';
    }

    for(int i=k;i<t.length();i++)
    {
        char ch=t[i];
        if(ch=='r'){
            if(dp[i-k]!='p')
                dp[i]='p';
        }
        else if(ch=='p'){
            if(dp[i-k]!='s')
                dp[i]='s';
        }
        else{
            if(dp[i-k]!='r')
                dp[i]='r';
        }
    }
    ll res=0;
    for(int i=0;i<n;i++){
        if(dp[i]=='r')
            res+=r;
        else if(dp[i]=='s')
            res+=s;
        else if(dp[i]=='p')
            res+=p;
    }
    cout<<res;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
          

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int n , m;
    cin >> n >> m;
    vector<int> v;
    for(int i = 0; i < n; ++i){
        int x;cin >> x;
        v.pb(x);
    }
    sort(all(v));
    int sum = 0;
    for(int i = n - m; i < n; ++i){
        sum += v[i];
    }
    cout << sum ;
}


Measured memory_bytes: 256
from collections import OrderedDict 
def main():
    n = int(input())
    arr = [int(e) for e in input().split(' ')]
    mp = OrderedDict({k: 0 for k in range(n)})
    for i in range(0, n - 1):
        mp[arr[i] - 1] += 1
    
    for k in mp:
        print(mp[k])

    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 149828
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
using namespace std;
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
int main() {
	int n,ans=0; cin >> n;
	int v[100010]; bool chec[100010] = {};
	TFOR(i, n) {
		cin >> v[i];
		v[i] --;
	}
	TFOR(i, n) {
		if (!chec[v[i]])if (v[v[i]] == i) { ++ans; chec[v[i]] = 1; chec[i] = 1; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
	int n,k;
	while(1){
		cin>>n>>k;ll a[n],s[n+1]={0};
		if(n==0&&k==0) break;
		for(int i=0;i<n;i++){
			cin>>a[i];
			s[i+1]=s[i]+a[i];
		}
		ll ans=0;
		for(int i=0;i<=n-k;i++){
			ans=max(ans,s[i+k]-s[i]);
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 4552
data = input()

if data == 'SUN':
    print(7)
elif data == 'MON':
    print(6)
elif data == 'TUE':
    print(5)
elif data == 'WED':
    print(4)
elif data == 'THU':
    print(3)
elif data == 'FRI':
    print(2)
elif data == 'SAT':
    print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, m;
    while(scanf("%d%d", &n, &m) && n){
        tuple<int, int, int> tp[m];
        rep(i, m){
            int t, s, d;
            scanf("%d%d%d", &t, &s, &d);
            --s; --d;
            tp[i] = make_tuple(t, s, d);
        }
        sort(tp, tp+m);
        int flag[n];
        rep(i, n) flag[i] = 0;
        flag[0] = 1;
        int ans = 1;
        rep(i, m){
            int t, s, d;
            tie(t, s, d) = tp[i];
            if(flag[s]){
                ans += !flag[d];
                flag[d] = 1;
            }
        }
        printf("%d\n", ans);
    }
}


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


void solve(){
    ll n,k;
    cin>>n>>k;
    vector<ll> vec(n);
    for(ll i=0; i<n ;++i){
        cin>>vec[i];
    }
    sort(vec.begin(), vec.end());
    ll sum=0;
    for(ll i=0; i<k; ++i){
        sum += vec[i];
    }
    cout<<sum<<endl;

}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, D; cin >> N >> D;
    int cnt = 0;
    int tmp = 2 * D + 1;
    while(N > 0) {
        N -= tmp;
        cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){

int H, W, i;
string a;

cin >> H >> W;


for(i = 0; i < W + 2; i++){
    cout << "#" ;
}
cout << endl;


for(i = 0; i < H; i++){
    
    cin >> a;
    
    cout << "#" << a << "#" << endl;
    
}

for(i = 0; i < W + 2; i++){
    cout << "#" ;
}
cout << endl;
    
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    bool flg = false;

    int n = abs(a - b);
    int d = abs(a - b);

    while (n != 0)
    {
        // cout << n << endl;
        if (n == c)
        {
            flg = true;
            break;
        }
        if (n >= a)
        {
            n = (n - a) % b;
        }
        else
        {
            n = (n + d) % b;
        }
    }

    if (flg)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
    int x,n;cin>>x>>n;
    unordered_set<int> P;
    rep(i,n){
        int a;cin>>a;
        P.insert(a);
    }
    int t=x;
    int r=x;
    int maxt=0;
    int maxr=0;
    while(1){
        if(P.count(t)){
            t++;
        }else{
            maxt=t;break;
        }
    }
    while(1){
        if(P.count(r)){
            r--;
        }else{
            maxr=r;break;
        }
    }
    if(x-r<=t-x){
        cout<<r<<endl;
    }else{
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

long long count(string S)
{
  long long N = S.size();
  long long A_count = 0;
  long long rst = 0;
  rep(i, N)
  {
    if (S[i] == 'A')
      A_count++;
    else
      rst += A_count;
  }

  return rst;
}

int main()
{
  string s;
  cin >> s;
  long long N = s.size();
  rep(i, N - 1)
  {
    if (s.substr(i, 2) == "BC")
    {
      s[i] = 'D';
      s[i + 1] = 'X';
    }
  }
  string SS;
  rep(i, s.size())
  {
    if (s[i] != 'X')
      SS.push_back(s[i]);
  }

  long long ans = 0;
  rep(l, SS.size())
  {
    if (SS[l] == 'A' || SS[l] == 'D')
    {
      long long r = l;
      while (r + 1 < SS.size())
      {
        if (SS[r + 1] == 'A' || SS[r + 1] == 'D')
          r++;
        else
          break;
      }
      ans += count(SS.substr(l, r - l + 1));
      l = r;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 904
// abc123_b
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define FOR(i, a) for (auto i : a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define show1d(v)                                                              \
  rep(i, v.size()) cout << " " << v[i];                                        \
  cout << endl << endl;
#define show2d(v)                                                              \
  rep(i, v.size()) {                                                           \
    rep(j, v[i].size()) cout << " " << v[i][j];                                \
    cout << endl;                                                              \
  }                                                                            \
  cout << endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int func(int n) {
  if (n % 10 != 0) {
    n = n - n % 10 + 10;
  }
  return n;
}

int main(int argc, char *argv[]) {
  vi v(5), p = {0, 1, 2, 3, 4};
  int fAns = inf;
  rep(i, 5) { cin >> v.at(i); }
  do {
    int ans = 0;
    rep(i, 5) {
      while (ans % 10 != 0)
        ans++;
      ans += v.at(p.at(i));
    }
    fAns = min(fAns, ans);
  } while (next_permutation(p.begin(), p.end()));
  cout << fAns << endl;
  return 0;
}


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

#define ll long long

void exgcd(int a, int b, int& x, int& y) {
	if (!b) {
		x = 1, y = 0;
	} else {
		exgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
}

int inv(int a, int n) {
	int x, y;
	exgcd(a, n, x, y);
	return (x < 0) ? (x + n) : (x);
}

const int Mod = 998244353;

template <const int Mod = :: Mod>
class Z {
	public:
		int v;

		Z() : v(0) {	}
		Z(int x) : v(x){	}
		Z(ll x) : v(x % Mod) {	}

		Z operator + (Z b) {
			int x;
			return Z(((x = v + b.v) >= Mod) ? (x - Mod) : (x));
		}
		Z operator - (Z b) {
			int x;
			return Z(((x = v - b.v) < 0) ? (x + Mod) : (x));
		}
		Z operator * (Z b) {
			return Z(v * 1ll * b.v);
		}
		Z operator ~() {
			return inv(v, Mod);
		}
		Z operator - () {
			return Z(0) - *this;
		}
		Z& operator += (Z b) {
			return *this = *this + b;
		}
		Z& operator -= (Z b) {
			return *this = *this - b;
		}
		Z& operator *= (Z b) {
			return *this = *this * b;
		}
};

Z<> qpow(Z<> a, int p) {
	Z<> rt = Z<>(1), pa = a;
	for ( ; p; p >>= 1, pa = pa * pa) {
		if (p & 1) {
			rt = rt * pa;
		}
	}
	return rt;
}

typedef Z<> Zi;

const int N = 405;

int n;
int A[N], B[N];
Zi f[2][N][N];
Zi comb[N][N];

int main() {
	scanf("%d", &n);
	int suma = 0, sumb = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", A + i, B + i);
		suma += A[i];
		sumb += B[i];
	}
	comb[0][0] = 1;
	for (int i = 1; i <= sumb; i++) {
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j < i; j++) {
			comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
		}
	}
	int cur = 0;
	suma = sumb = 0;
	f[cur][0][0] = 1;
	for (int i = 1; i <= n; i++) {
		memset(f[cur ^= 1], 0, sizeof(f[0]));
		for (int sa = 0; sa <= suma; sa++) {
			for (int sb = 0; sb <= sumb; sb++) {
				Zi v = f[cur ^ 1][sa][sb];
				if (!v.v) continue;
				Zi pw = 1;
				f[cur][sa][sb] += v;
				for (int j = 0; j < B[i]; j++, pw *= A[i]) {
					f[cur][sa + A[i]][sb + j] -= comb[sb + j][j] * pw * v;
				}
			}
		}
		suma += A[i];
		sumb += B[i];
	}
	Zi ans = 0;
	for (int sa = 1; sa <= suma; sa++) {
		Zi inva = ~Zi(sa), pw = 1;
		for (int sb = 1; sb <= sumb + 1; sb++, pw *= inva) {
			Zi v = f[cur][sa][sb - 1] * pw - f[cur][sa][sb] * (pw * inva);
			if (v.v) {
				ans -= v * sb * inva * suma;
			}
		}
	}
	printf("%d\n", ans.v);
	return  0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(void)
{
	int x,n,p[100],flg,w,y,i,c,t;
	scanf("%d %d",&x,&n);
	flg=0;
	w=x;
	y=x;
	if(n==0){
		printf("%d\n",x);
		flg=1;
	}
	else if(flg==0){
		for(i=0;i<n;i++){
			scanf("%d",&p[i]);
		}
		while(1){
			c=0;
			t=0;
			for(i=0;i<n;i++){
				if(w==p[i]) {
					c++;
				}
				if(y==p[i]){
					t++;
				}
			}
			if(c==0&&t==0){
				printf("%d\n",y);
				break;
			}
			else if(c==0){
				printf("%d\n",w);
				break;
			}
			else if(t==0){
				printf("%d\n",y);
				break;
			}
			w=w+1;
			y=y-1;
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  while(true) {
    int m, t, p, r;
    cin >> m >> t >> p >> r;
    if(!m && !t && !p && !r) break;
    VVI rec;
    REP(i, r) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      rec.PB({a, b, c, d});
    }
    int wa[55][15] = {0};
    VVI ac;
    REP(i, t) ac.PB({0, 0, (int)i+1});
    REP(i, r) {
      //??£?§£
      if(!rec[i][3]) {
        ac[rec[i][1]-1][0]++;
        ac[rec[i][1]-1][1] += wa[rec[i][1]-1][rec[i][2]] * 20 + rec[i][0];
      } else {
        wa[rec[i][1]-1][rec[i][2]]++;
      }
    }
    REP(i, t) {
      ac[i][0] *= -1;
      ac[i][2] *= -1;
    }
    sort(ALL(ac));/*
    cout << endl;
    REP(i, t) {
      REP(j, 3) {
        cout << ac[i][j] << " ";
      }
      cout << endl;
    }*/
    cout << -1*ac[0][2];
    FOR(i, 1, t) {
      if(ac[i][0] == ac[i-1][0] && ac[i][1] == ac[i-1][1]) {
        cout << "=";
      } else {
        cout << ",";
      }
      cout << -1*ac[i][2];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;

int main() {
    int x,y,ans=0;
    cin >> x >> y;
    if (x==1) ans+=300000;
    if (y==1) ans+=300000;
    if (x==2) ans+=200000;
    if (y==2) ans+=200000;
    if (x==3) ans+=100000;
    if (y==3) ans+=100000;
    if (x==1 && y==1) ans+=400000;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] a = new int[n][m];
        int[] b = new int[m];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = scan.nextInt();
            }
        }

        for (int i = 0; i < m; i++) {
            b[i] = scan.nextInt();
        }

        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
               c[i] += a[i][j] * b[j];
            }
        }

        for (int i = 0; i < c.length; i++) {
            System.out.println(c[i]);
        }
    }
}

Measured memory_bytes: 40224
# include <iostream>
# include <cstdio>
# include <string>
# include <cstring>
using namespace std;
int main(){
    char str1[20],str2[20];
    while(scanf("%s",str1)!=EOF){
        int len = 0;
        for(int i = 0;i < strlen(str1);++i){
            if(str1[i] == '0') str2[len ++] = '0';
            if(str1[i] == '1') str2[len ++] = '1';
            if(str1[i] == 'B'){
                if(len != 0) len --;//00B
            }
        }
      //  cout << "len " << len << endl;
        str2[len] = '\0';
        printf("%s\n",str2);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    sort(all(A));
    int ans = 0;
    ll sum = A[0];
    repd(i, 1, N) {
        if (sum * 2LL >= A[i]) {
            ans++;
        }
        else {
            ans = 0;
        }
        sum += A[i];
    }

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

Measured memory_bytes: 1024
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a,b,c,d;
    string ans;
    cin >>a>>b>>c>>d;

    if(a+b>c+d)ans="Left";
    else if(a+b<c+d)ans="Right";
    else ans="Balanced";

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;
typedef long long ll;
int n,K,a[N];
int main(){
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<n;i++)if(a[i]+a[i+1]>=K){
		puts("Possible");
		for(int j=1;j<i;j++)printf("%d ",j);
		for(int j=n-1;j^i;j--)printf("%d ",j);
		return printf("%d",i),0;
	}
	puts("Impossible");
	return 0;
}

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


namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {

            //var str1 = Console.ReadLine();
            var str2 = Console.ReadLine()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => int.Parse(x))
                .ToArray();

            var str3 = int.Parse(Console.ReadLine());
            var a = (int)(str2[0] * Math.Pow(2, str3) + str2[1] + str2[2]);
            var b = (int)(str2[0]  + str2[1]* Math.Pow(2, str3) + str2[2]);
            var c = (int)(str2[0]  + str2[1] + str2[2] *Math.Pow(2,str3));

            var lists = new List<int>(new int[] { a, b, c });
            lists.Sort();
            lists.Reverse();
            Console.WriteLine(lists.First());
            Console.ReadLine();

        }
    }

}

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

typedef long long ll;
using namespace std;

int main() {
    int d;
    ll g;
    cin >> d >> g;
    g /= 100;
    vector<pair<int, int>> qs(d);
    for (int i = 0; i < d; i++) {
        cin >> qs[i].first >> qs[i].second;
    }
    int ans = 1e9;
    for (int i = 0; i < 1 << d; i++) {
        ll cur_point = 0;
        int cur_count = 0;
        int mx = -1;
        for (int k = 0; k < d; k++) {
            if (i >> k & 1) {
                cur_point += qs[k].first * (k + 1) + qs[k].second / 100;
                cur_count += qs[k].first;
            } else {
                mx = k;
            }
        }
        if (cur_point >= g) {
            ans = min(ans, cur_count);
            continue;
        }
        if (mx < 0) {
            continue;
        }
        for (int k = 0; k < qs[mx].first; k++) {
            cur_point += mx + 1;
            cur_count++;
            if (cur_point >= g) {
                ans = min(ans, cur_count);
                break;
            }
        }
    }
    cout << ans;
    return 0;
}


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

using namespace std;

char a[11],b[11],c[11];
int main(){
		cin>>a>>b>>c;
		char d=a[0]-'a'+'A';
		char e=b[0]-'a'+'A';
		char f=c[0]-'a'+'A';
		cout<<d<<e<<f<<endl;
	   }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 5e3+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
string s;
int ans = 0;
void Zfunction(string s){
	int n = s.length();
	vector<int> z(n,0);
	int x = 0, y = 0;
	for(int i=1; i<n; i++){
		z[i] = max(0, min(z[i-x], y-i+1));
		while(i+z[i]<n && s[i+z[i]] == s[z[i]]){
			x = i; y = i+z[i]; z[i]++;
		}
		ans = max(ans, min(z[i],i));
	}
}
int main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> n >> s;
	string tmp = "";
	for(int i=n-1; i>=0; i--){
		tmp = s[i] + tmp;
		Zfunction(tmp);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()
sum_A = sum(A)
if sum([x >= sum_A/(4*M) for x in A]) >= M:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 5712
//
// Created by 中野誠大 on 2019-03-03.
//

#include<iostream>

#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
const long long INF = 1LL << 60;
typedef pair<int, int> P;

int main(){
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int l[Q];
    int r[Q];
    rep(i,Q) cin >> l[i] >> r[i];
    int count[N];
    int count_=0;
    rep(i,N-1){
        if (S[i]=='A' and S[i+1]=='C'){
            count_ ++;
        }
        count[i+1]=count_;
    }
    count[0]=0;

    //rep(i,Q) cout << l[i]<<r[i] << endl;

    rep(i,Q){
        cout << count[r[i]-1]-count[l[i]-1]<< endl;
    }

    //rep(i,N) cout << count[i] << " ";

    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string o, e;
    cin >> o >> e;
    int a=0, b=0;
    rep(i, o.size()+e.size()) {
        if (i%2==0) cout << o[a++];
        else cout << e[b++];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const ll MOD=1e9+7;

int m,n;

int now_depth(vector<vector<int>> p,int x,int y) {
    vector<int> dx={0,1,0,-1},dy={1,0,-1,0};
    int res=0;
    rep(i,4) {
        int nx=x+dx[i],ny=y+dy[i];
        if (nx>=0 && nx<n && ny>=0 && ny<m) {
            if (p[nx][ny]==1) {
                p[nx][ny]=0;
                res=max(res,now_depth(p,nx,ny));
                p[nx][ny]=1;
            }
        }
    }
    return res+1;
}



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

    
    int n,k;
    cin >> n >> k; 
    vector<int> b(n);
    rep(i,k) {
        int d;
        cin >> d;
        rep(j,d) {
            int a;
            cin >> a;
            ++b[a-1];
        }
    }
    ll ans=0;
    rep(i,n) {
        if (b[i]==0) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n;
    cin >> n;
    pair<pair<string,int>,int> freq[105];
    rep(i,n) {
        string s;
        int p;
        cin >> s >> p;
        freq[i] = make_pair(make_pair(s,-p),i);
    }
    sort(freq,freq+n);
    rep(i,n) cout << freq[i].second+1 << endl;
}

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

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

    if(a>b)
        cout<<"a > b"<<endl;
    else if(a<b)
        cout<<"a < b"<<endl;
    else
        cout<<"a == b"<<endl;

    return 0;
}



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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << 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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line
vector<int> G[10] ;
int main()
{
	int n , m ;
	cin >> n >> m ;
	rep(i,m){
		int a , b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int B[n-1];
	rep(i,n-1) B[i] = i+1;
	ll ans = 0 ;
	do {
		bool can = true; 
		//頂点0から初めて0 -> B[0] -> B[1] -> .. -> B[n-2] と行けるか.
		int count = 1 ;//通った頂点の数
		int from = 0 ;
		int to ;
		while(count < n){
			to = B[count-1];
			//G[from]の中にtoがあればok
			for(int i = 0 ; i < G[from].size() ; i ++){
				if ( G[from][i] == to) {
					//ok
					count ++ ;
					from = to;
					break ;
				} 
			}
			if( to != from ){
				break ;
			}
		}
		if( count == n ){
			ans ++ ;
		}
	} while(next_permutation(B,B+n-1));
	cout << ans << endl;
}


Measured memory_bytes: 256
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] % mod * ifac[n-k] % mod if n >= k >= 0 else 0


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac


N = int(input())
A = list(map(int,input().split()))

MOD = 10**9 + 7
fac, ifac = make_tables(MOD,N+1)

ans = 0
INF = 10**9
x,y = 0,0
l = [INF]*(N+1)
for i in range(N+1):
  if l[A[i]-1] != INF:
    x = l[A[i]-1]
    y = i+1
    break
  l[A[i]-1] = i+1

for i in range(1,N+2):
  print((cmb(N+1,i,MOD,fac,ifac) - cmb(N+x-y,i-1,MOD,fac,ifac))%MOD)

Measured memory_bytes: 27112
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
#define ll long long 
const int maxn = 500000 + 5;

struct Node
{
	ll id = -1;
	ll key = -1;
	ll parent = -1;
	ll l = -1;
	ll r = -1;
};

int m;
ll key;
ll root;
int cnt = -1;
string str;
vector<Node> tree;

void insert(int id, int now)
{
	int v = tree[now].key;
	if(id < v) 
	{
		if(tree[now].l == -1)
		{
			tree[now].l = cnt;
			tree[cnt].parent = now;
		}
		else insert(id, tree[now].l);
	}
	else 
	{
		if(tree[now].r == -1)
		{
			tree[now].r = cnt;
			tree[cnt].parent = now;
		}
		else insert(id, tree[now].r);
	}
}

void Inorder(int num)
{
    if(num == -1) return;
    Inorder(tree[num].l);
    cout << " " << tree[num].key;
    Inorder(tree[num].r);
}

void Preorder(int num)
{
    if(num == -1) return;
    cout << " " << tree[num].key;
    Preorder(tree[num].l);
    Preorder(tree[num].r);
}

void print(int id)
{
	Inorder(id);
	cout << endl;
	Preorder(id);
	cout << endl;
}

int main()
{
	cin >> m;
	int flag = 0;
	rep(i,m)
	{
		cin >> str;
		if(str == "insert") 
		{
			cin >> key;
			cnt++;
			Node node; node.key = key; node.id = cnt;
			tree.pb(node);
			if(!flag) { flag = 1; continue; }
			insert(key, 0);
		}
		else print(root);
	}

	// rep(i,cnt+1)
	// {
	// 	printf("id:%d key:%d l:%d r:%d\n", tree[i].id, tree[i].key, tree[i].l, tree[i].r);
	// }

}


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

const long long MOD = 1000000007;

long long ans[300000] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> input;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        a--;
        input.push_back(a);
    }
    ans[input[0]]++;
    for(int i = 0; i < n-1; i++){
        if(input[i] != input[i+1]){
            ans[input[i+1]] += ans[input[i]];
            ans[input[i+1]] %= MOD;
        }
    }
    cout << ans[input[n-1]] << endl;
    return 0;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

bool cmp(pii a,pii b){
	return a.S<b.S;
}

int find(vector<int> &dp,int t){
	int hi=sz(dp)-1,lo=-1;
	while(hi-lo>1){
		int m=(hi+lo)/2;
		if(dp[m]<=t) lo=m;
		else hi=m;
	}
	return hi;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	int cnt=0;
	For(i,1,min(9ll,n)) cnt++;
	For(i,100,min(999ll,n)) cnt++;
	For(i,10000,min(99999ll,n)) cnt++;
	cout<<cnt<<"\n";
	return 0;
}



























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

class union_find{
private:
	vector<int> parents;
	vector<int> rank;
	vector<int> weight;
public:
	union_find(int n){
		for(int i=0;i<n;i++){
			parents.push_back(i);
			rank.push_back(0);
			weight.push_back(0);
		}
	}
	int find(int x){
		if(parents[x]==x){
			return x;
		}else{
			int tmp=find(parents[x]);
			weight[x]=weight[x]+weight[parents[x]];
			return parents[x]=tmp;
		}
	}
	void unite(int x,int y,int w){
		int tmpx=find(x);
		int tmpy=find(y);
		if(tmpx==tmpy)return;
		if(rank[tmpx]<rank[tmpy]){
			weight[tmpx]=w-weight[x]+weight[y];
			parents[tmpx]=tmpy;
		}else{
			weight[tmpy]=-w-weight[y]+weight[x];
			parents[tmpy]=tmpx;
			if(rank[tmpx]==rank[tmpy])rank[tmpx]++;
		}
	}
	int get_weight(int x,int y){
		if(find(x)==find(y)){
			return weight[x]-weight[y];
		}else{
			return -2000000;
		}
	}
};
int main(){
	char c;
	int a,b,w;
	int n,m;
	while(cin>>n>>m,n!=0||m!=0){
		union_find uf(n+1);
		for(int i=0;i<m;i++){
			cin>>c;
			if(c=='!'){
				cin>>a>>b>>w;
				uf.unite(a,b,w);
			}else if(c=='?'){
				cin>>a>>b;
				int tmp=uf.get_weight(a,b);
				if(tmp!=-2000000){
					cout<<tmp<<endl;
				}else{
					cout<<"UNKNOWN"<<endl;
				}
			}
		}
	}
}

Measured memory_bytes: 2920