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

int main() {
    int n;
    cin >> n;
    //-1:証言無し、0:不親切、1:正直
    vector<vector<int>> test(n, vector<int>(n, -1));
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            test[i][x] = y;
        }
    }
    int ans = 0;
    // i:bit
    for (int i = 0; i < (1 << n); i++) {
        bool flag = true;
        // j:ビット立ってる人
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                // k番目の人の情報
                for (int k = 0; k < n; k++) {
                    bool t1 = (test[j][k] == 0);
                    bool t2 = (test[j][k] == 1);
                    bool t3 = ((i & (1 << k)) == 0);
                    bool t4 = ((i & (1 << k)) > 0);
                    // cout << t1 << " " << t2 << " " << t3 << " " << t4 <<
                    // endl;
                    if ((t1 && t3) || (t2 && t4)) {
                    } else if (test[j][k] == -1) {
                    } else {
                        flag = false;
                        break;
                    }
                }
            }
        }
        if (flag) {
            int temp = 0;
            for (int j = 0; j < n; j++) {
                if (i & (1 << j)) {
                    temp++;
                }
            }
            ans = max(ans, temp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

a = [0, 2,5,5,4,5,6,3,7,6]

def solve(n: int, m: int, A: "List[int]"):
    dp = [-1] * (n + 1)
    dp[0] = 0
    A.sort(reverse=True)
    for c in A:
        for i in range(n + 1):
            if i - a[c] >= 0 and dp[i - a[c]] >= 0:
                dp[i] = max(dp[i], dp[i - a[c]] * 10 + c)
    print(dp[n])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16492
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010,mod=998244353;
const char str[2][10]={"First","Second"};
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,a[maxn]; 
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main(){
	n=read();
	FOR(i,1,n) a[i]=read();
	int t=0;
	while(true){
		int cnt1=0,cnte=0;
		FOR(i,1,n){
			if(a[i]==1) cnt1++;
			if(a[i]%2==0) cnte++;
		}
		if(cnte!=n-1 || cnt1==1){puts(cnte%2?str[t]:str[t^1]);break;}
		FOR(i,1,n) if(a[i]%2!=0){a[i]--;break;}
		int g=0;
		FOR(i,1,n) g=gcd(g,a[i]);
		FOR(i,1,n) a[i]/=g;
		t^=1;
	}
}

Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int k,t,ans=0; cin>>k>>t;
    vector<int> a(t,0);
    rep(i,t) cin>>a[i];
    sort(al(a));
    int m=a[a.size()-1];
    if((k+1)/2<m) ans=(m-1)-(k-m);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    ll a,b,m;
    cin>>a>>b>>m;
    ll arra[a];
    ll arrb[b];
    f(i,0,a){
        cin>>arra[i];
    }
    f(i,0,b){
        cin>>arrb[i];
    }
    ll ans=300000;
    f(i,0,m){
        ll x,y,c;
        cin>>x>>y>>c;
        ll sum=arra[x-1]+arrb[y-1]-c;
        if(sum<ans){
            ans=sum;
        }
    }
    sort(arra,arra+a);
    sort(arrb,arrb+b);
    if(arra[0]+arrb[0]<ans){
        cout<<arra[0]+arrb[0]<<endl;
    }
    else{
        cout<<ans<<endl;
    }
}

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

using namespace std;

typedef long long int ll;


int main(void)
{
        ll N;
        cin>>N;
        ll A[N]={0},i=0;
        for(i=0;i<N;i++)
        {
            cin>>A[i];
        }
        ll stool_height=0, max=A[0];
        for(i=1;i<N;i++)
        {
            if(A[i]<=max)
            {
                stool_height+=max-A[i];
            }
            else
            {
                max=A[i];
            }
        }
        cout<<stool_height<<endl;
}

Measured memory_bytes: 5192
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,m;
Vi aa;
ll gcd(ll a, ll b){
    if(a < b)swap(a,b);
    return  b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b){
    return a * b / __gcd(a, b);
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    //std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>m;
    //rep(i,10000)rep(j,10000)dp[i][j]=0;
    //memset(dp,0,sizeof(dp));
    aa.resize(n);
    rep(i,n)cin>>aa[i];
    ll tmp = 1;
    bool flg = true;
    rep(i,n){
        tmp = lcm(tmp,aa[i]/2);
        if((tmp*2/aa[i]) %2 ==0){
            flg = false;
            break;
        }
    }
    ll ans = m/tmp;
    if(!flg){
        print(0);
    }else if(ans % 2 == 1){
        print((ans-1)/2 + 1);
    }else{
        print(ans/2);
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main() {
	long long int H;long long int W;
    long long int ans = 0;
	cin >> H >> W ;
 
	if(H==1||W==1){
        ans = 1;
    }else if(H%2==0){
        ans = (H/2)*W;
	}else if(W%2==0){
        ans = (W/2)*H;
    }else{
        ans = ((H-1)/2)*(W-1) + H/2 + W/2 + 1;
    }
	cout << ans;
	return 0;
}

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

#define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++)

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

    int64_t n, a, b;
    cin >> n >> a >> b;

    if (n < a + b - 1 or n > a * b) {
        cout << -1 << endl;
        return 0;
    }

    vector<int64_t> seq;
    map<int64_t, int> map;

    repeat (i, a) {
        int64_t e = a * b - a + i;
        seq.push_back(e);
        map[e] = 0;
    }

    int64_t num = n - (a + b - 1);

    for (int i = 1; i < b; i++) {
        int64_t e = a * b - a * (i + 1);
        seq.push_back(e);
        map[e] = 0;

        for (int j = 1; num > 0 and j < a; j++) {
            if (num > 0) {
                e++;
                num--;

                seq.push_back(e);
                map[e] = 0;
            }
        }
    }

    int id = 1;
    for (auto& mp : map) mp.second = id++;

    for (int64_t e : seq) {
        cout << map[e] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 24556
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	map<ll, ll> mp;
	ll n;
	cin >> n;
	for(ll i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			n /= i;
			mp[i]++;
		}
	}
	if(n > 1) mp[n]++;

	ll ans = 0;
	for(auto el: mp) {
		ll x = 1;
		while(x <= el.se) {
			el.se -= x;
			ans++;
			x++;
		}
	}
	cout << ans << '\n';
}



Measured memory_bytes: 3660
/*Problem A : Serval vs Monster*/
#include<stdio.h>

int main(void)
{
    int A,H;

    scanf("%d %d", &H,&A);

    int count = 1;

    while(H > A)
    {
        H = H - A;
        count++;
    }
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 128
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int H, W, A[80][80], B[80][80];

int dp[80][80][80*160+1];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    for (int i = 0; i < H; ++i)
        for (int j = 0 ; j < W; ++j)
            cin >> A[i][j];
    for (int i = 0; i < H; ++i)
        for (int j = 0 ; j < W; ++j)
            cin >> B[i][j];

    dp[0][0][abs(A[0][0]-B[0][0])] = 1;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (i > 0) {
                for (int k = 0; k <= 80*160; ++k) {
                    int k1 = abs(k - (A[i][j] - B[i][j]));
                    if (k1 <= 80*160 && dp[i-1][j][k1] == 1)
                        dp[i][j][k] = 1;
                    int k2 = abs(k + (A[i][j] - B[i][j]));
                    if (k2 <= 80*160 && dp[i-1][j][k2] == 1)
                        dp[i][j][k] = 1;
                }
            }
            if (j > 0) {
                for (int k = 0; k <= 80*160; ++k) {
                    int k1 = abs(k - (A[i][j] - B[i][j]));
                    if (k1 <= 80*160 && dp[i][j-1][k1] == 1)
                        dp[i][j][k] = 1;
                    int k2 = abs(k + (A[i][j] - B[i][j]));
                    if (k2 <= 80*160 && dp[i][j-1][k2] == 1)
                        dp[i][j][k] = 1;
                }
            }
        }
    }

    for (int k = 0; k <= 80*160; ++k) {
        if (dp[H-1][W-1][k] == 1) {
            cout << k << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 318720
n = int(input())
da = [list(map(int,input().split())) for i in range(n)]
ans = 0.0
for i in range(n):
    for j in range(i):
        ans += ((da[i][0]-da[j][0])**2 + (da[i][1]-da[j][1])**2)**(0.5)
print(ans*2/n)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
char c[110][110],d[150];
int n,l,i,j;
int main()
{
	
	scanf("%d%d",&n,&l);
	getchar();
	for(i=0;i<n;i++)
	scanf("%s",c[i]);
	for(i=0;i<n-1;i++)
	  {
	  for(j=0;j<n-i-1;j++)
	    if(strcmp(c[j],c[j+1])>0)
	    {
	    	strcpy(d,c[j]);
	    	strcpy(c[j],c[j+1]);
	    	strcpy(c[j+1],d);
			}
			}	
	    for(i=0;i<=n;i++)
		printf("%s",c[i]);	
		
	 } 
	 

Measured memory_bytes: 256
program ABC169C
    implicit none
    integer(8)::i
    integer(16)::A,B
    character(10)::S
    read*,A,S
    do i=1,len_trim(S)
        if(S(i:i)==".")then
            S=S(1:i-1)//S(i+1:len_trim(S))
            exit
        end if
    end do
    read(S,*)B
    print'(i0)',(A*B)/100
end program ABC169C

Measured memory_bytes: 2848
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K; string S;
  cin >> N >> K >> S;
  int score = 0;
  rep(i, N-1) {
    if(S[i] == S[i+1]) ++score;
  }
  cout << min(score+2*K, N-1) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char s[2020];
bool is(char *a, char *b)
{
    int n = b-a; if(n&1) return false;
    for(int i=0; i<n/2; ++i)
        if(a[i]!=a[i+n/2]) return false;
    return true;
    
}
int main()
{
    cin >> s; int N = strlen(s);
    for(int i=1; i<N; ++i)
    {
        if(is(s, s+N-i))
        {
            printf("%d\n", N-i);
            return 0;

        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[3][3],b[3][3],x,ans,p[12];
int main(){
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
            cin >> a[i][j];
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> x;
        for(int i = 0; i < 3; i++)
            for(int j = 0; j < 3; j++)
                if(x == a[i][j]) b[i][j] = 1;
    }
    p[0] = b[0][0] + b[0][1] + b[0][2];
    p[1] = b[1][0] + b[1][1] + b[1][2];
    p[2] = b[2][0] + b[2][1] + b[2][2];
    p[3] = b[0][0] + b[1][0] + b[2][0];
    p[4] = b[0][1] + b[1][1] + b[2][1];
    p[5] = b[0][2] + b[1][2] + b[2][2];
    p[6] = b[0][0] + b[1][1] + b[2][2];
    p[7] = b[0][2] + b[1][1] + b[2][0];
    for(int i = 0; i < 12; i++) if(p[i] == 3) ans = 1;
    if(ans)printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

class stack
{
private:
    int a[100];
    int p;

public:
    stack(): p(0) {}

    void push(int n){a[++p] = n;}

    const int top() const {
        return( a[p] );
    }
    const int pop(){
        return( a[p--] );
    }

    bool empty() const {
        return(p == 0);
    }
};

main()
{
    stack c;
    char s[512];

    while(~scanf("%s", s)){
        if(*s == '+'){
            c.push( c.pop() + c.pop());
        }
        else if(*s == '-'){
            int a = c.pop();
            int b = c.pop();
            c.push( b-a );
        }
        else if(*s == '*'){
            c.push( c.pop() * c.pop());
        }
        else {
            c.push( atoi(s) );
        }
    }
    printf("%d\n", c.top());

}

Measured memory_bytes: 2728
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmpstr(const void *x, const void *y) {
	return strcmp(x, y);
}
int main() {
	int n, l;
	char s[100][101];
	scanf("%d%d", &n, &l);
	for (int i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}
	qsort(s, n, sizeof(s[0]), cmpstr);
	for (int i = 0; i < n; i++) {
		printf("%s", s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,x,y,a[5005],f[5005];
ll dp[5005];
int main()
{
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),f[a[i]]=i;
    for(int i=1;i<=n;i++)
    {
        int pos=f[i];
        ll t=1e18;
        for(int j=1;j<=n;j++)
        {
            t=min(t,dp[j]);
            if(pos>j)
                dp[j]=t+y;
            else if(pos==j)
                dp[j]=t;
            else dp[j]=t+x;
        }
    }
    ll ans=1e18;
    for(int i=1;i<=n;i++)
        ans=min(ans,dp[i]);
    printf("%lld\n",ans);
}


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = input[0];
        var k = input[1];
        var ans = 1;

        for(var i = 1; i <= n; i++)
        {
            if (i + k -1 <= n)
            {
                ans = i;
            }
        }


        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int X[N];
  for (int i=0; i<N; i++) {
    cin >> X[i];
  }
  int M;
  cin >> M;
  int a[M];
  for (int i=0; i<M; i++){
    cin >> a[i];
    a[i]--;
  }
  for(int i=0; i<M; i++){
    if( (X[a[i]]+1)!=X[a[i]+1] && X[a[i]]!=2019) {
      X[a[i]]++;
    }
  }
  for (int i=0; i<N; i++) {
    cout << X[i] << endl;
  }
}


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

const int N = 200001;

int from[N] , to[N] , n , m , flag[N];

void read(void) {
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= m ;i ++) {
		scanf("%d%d",&from[i] , &to[i]);
		if(from[i] > to[i]) swap(from[i] , to[i]);
		if(from[i] == 1) {
			if(flag[to[i]]) {
				puts("POSSIBLE");return;
			}
			flag[to[i]] = 1;
		}
		if(to[i] == n) {
			if(flag[from[i]]) {
				puts("POSSIBLE");return;
			}
			flag[from[i]] = 1;
		}
	}
	puts("IMPOSSIBLE");
}

int main() {
	read();
}

Measured memory_bytes: 2560
K = int(input())
ans = 0
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

for i in range(1,K+1):
    for j in range(1,K+1):
        gcd_ij = gcd(i,j)
        for k in range(1,K+1):
            ans += gcd(gcd_ij, k)
print(ans)


Measured memory_bytes: 74952
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <algorithm>
#include <functional>
#include <utility>
#include <tuple>
#include <ctime>
#include <cmath>
#include <fstream>
#include <sstream>
using namespace std;
#define INF 1000000007
#define PB push_back
#define MP make_pair
#define X first
#define Y second

typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef queue<int> QI;
typedef queue<PII> QII;
typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef set<int> SI;
typedef set<PII> SII;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(0);
	int N;
	cin >> N;
	string S=to_string(N);
	int counter=0;
	for(char c: S)
	{
		counter+=(int) c-48;
	}
	if(N%counter==0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
return 0;
}


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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    set < int > q;
    for(int i = 0; i < 4; i++){
        int x;
        cin >> x;
        q.insert(x);
    }
    if(q.count(1) && q.count(7) && q.count(9) && q.count(4)) cout << "YES";
    else cout <<  "NO";
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

map<int, int> m;
vector<int> year[100010];
int y[100010];

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

	int N, M;
	cin >> N >> M;

	rep(i, 0, M) {
		int p, Y;
		cin >> p >> Y;
		y[i] = Y;
		m[Y] = p--;
		year[p].push_back(Y);
	}

	rep(i, 0, N) vsort(year[i]);

	rep(i, 0, M) {
		int city = m[y[i]] - 1;
		auto it = lower_bound(year[city].begin(), year[city].end(), y[i]);
		cout << setfill('0') << right << setw(6) << city + 1;
		cout << setfill('0') << right << setw(6) << it - year[city].begin() + 1<< endl;
	}

}


Measured memory_bytes: 12032
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a,b,c,d=0,e;
    cin >> a;
    e=a;
    cin >> c;
    while(a!=1)
    {
        cin >>b;
        if (a==e)
        {
            d=c+b;
        }
        else
        {
            d=d+b;
        }
        if(b>c)
        {
            c=b;
        }
        a=a-1;
    }
    c=c/2;
    d=d-c;
    cout << d;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
V=[int(a) for a in input().split()]
able=min(N,K)
ans=0
 
for a in range(able+1):
    for b in range(able+1-a):
        if b==0:
            have=V[:a]
        else:
            have=V[:a]+V[-b:]
        have.sort()

        for i in range(min(a+b,K-a-b)+1):
            val=sum(have[i:])
            if ans<val:
                ans=val
 
print(ans)


Measured memory_bytes: 3188
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B
s = S()
for i in range(len(s))[::-1]:
    if i%2 == 0:
        if s[:i//2] == s[i//2:i]:
            print(i)
            quit()
#C
"""
n = I()
a = LI()
b = [None for i in range(n)]
k = n//2
if n%2:
    for i in range(n):
        if i%2:
            b[k+(i+1)//2] = a[i]
        else:
            b[k-i//2] = a[i]
else:
    for i in range(n):
        if i%2:
            b[k-(i+1)//2] = a[i]
        else:
            b[k+i//2] = a[i]
print(*b)
"""

#D
"""
n = I()
a = LI()
fact = [1 for i in range(n+2)]
for i in range(1,n+2):
    fact[i]*= fact[i-1]*i
    fact[i] %= mod
inv_fact = [1 for i in range(n+2)]
inv_fact[n+1] = pow(fact[n+1],mod-2,mod)
for i in range(1,n+1)[::-1]:
    inv_fact[i] = inv_fact[i+1]*(i+1)
    inv_fact[i] %= mod
count = [None for i in range(n+1)]
for i in range(n+1):
    if count[a[i]] != None:
        l = count[a[i]]
        r = n-i
        break
    count[a[i]] = i
for i in range(1,n+2):
    ans = fact[n+1]*inv_fact[i]*inv_fact[n+1-i]%mod
    if l+r >= i-1:
        ans -= fact[l+r]*inv_fact[i-1]*inv_fact[l+r-i+1]%mod
        ans %= mod
    print(ans)
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

const int nm = 1e5, mod = 1e9 + 7;
int n, c[nm + 1], ans = 1;

int main() {
	c[0] = 3;
	cin >> n;
	for (int i = 0, a; i < n; i++) {
		cin >> a;
		ans = (long long) ans * c[a] % mod;
		c[a]--, c[a + 1]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int a,i;
  priority_queue<int> que; //宣言
  for(i=0;i<n;i++){
    cin >> a;
    que.push(a);
  }
  for(i=0;i<m;i++){
    int x=que.top();
    que.pop();
    x=x/2;
    que.push(x);
  }
  long long ans=0;
  for(i=0;i<n;i++){
    int x=que.top();
    que.pop();
    ans+=x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3936
#include<stdio.h>
#include<string.h>
int main()
{
    int n,rafi=0;
    scanf("%d",&n);
    char ara[n];
    scanf(" %[^\n]",ara);
    int k=strlen(ara);
    for(int i=0;i<k-2;)
    {
        if(ara[i]=='A' && ara[i+1]=='B'&& ara[i+2]=='C') {
                rafi++;
                i=i+3;
        }
        else i++;
    }
    printf("%d\n",rafi);
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

long long int gcd(long long int a, long long int b)
{
	return b != 0 ? gcd(b, a%b) : a;
}

long long int lcm(long long int a, long long int b)
{
	return a*b / gcd(a, b);
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);
	

	long long int A, B, C, D; scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
	long long int CD = lcm(C, D);

	long long int div = (B / C + B / D - B / CD) - ((A - 1) / C + (A - 1) / D - (A - 1) / CD);
	printf("%lld", B - A + 1 - div);

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<ull, ull> P; //ペア　タイプでふ
constexpr ll bigNum = 1000000007;

int main(void)
{
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    //ここから本体
    int N;
    int all = 0;
    cin >> N;
    string ans;
    array<int, 100000> vec;
    int x = 0;
    int index = 0;
    REP(i, N)
    {
        cin >> vec[i];
        all += vec[i];
    }
    all /= 2;
    for (int j = 0; j < (N - 1) / 2; j++)
    {
        index = 2 + 2 * j;
        if (index > N)
        {
            index = index - N;
        }
        x += vec[index - 1];
    }
    int x1 = (all - x);
    ans += to_string(2 * (all - x)) + " ";

    for (int i = 0; i < (N - 1); i++)
    {
        int index = i + 1;
        if (index > N)
        {
            index = index - N;
        }
        ans += to_string(2 * (vec[index - 1] - x1)) + " ";
        x1 = vec[index - 1] - x1;
    }
    cout << ans;
}

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

ll n,a[50],x;

int main(){
    cin>>n;
    ll num=0,ans;
    rep(i,n){
        cin>>a[i];
        num+=a[i]/n;
    }
    ans=num;
    while(num){
        rep(i,n){
            x=a[i]/n;
            a[i]%=n;
            a[i]+=num-x;
        }
        num=0;
        rep(i,n)num+=a[i]/n;
        ans+=num;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
s = sum(B)
for i in range(0,N-1):
    if A[i]+1 == A[i+1]:
        s = s+C[A[i]-1]
print (s)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
    char name[30];
    double cost;
}Crop;
Crop crop[50];
int comp(const void *a,const void *b){
    Crop c = *(Crop *)a;
    Crop d = *(Crop *)b;
    if(c.cost<d.cost) return 1;
    else if(c.cost>d.cost) return -1;
    else{
        int len1=strlen(c.name),len2=strlen(d.name);
        int len=((len1<len2)?len1:len2);
        for(int i=0;i<len;i++){
            if(c.name[i]-'a'<d.name[i]-'a') return -1;
            else if(c.name[i]-'a'>d.name[i]-'a') return 1;
        }
        if(len1<len2) return -1;
        else return 1;
    }
    return 0;
}
int main(void){
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0) break;
        for(int i=0;i<n;i++){
            int p,a,b,c,d,e,f,s,m;
            scanf("%s%d%d%d%d%d%d%d%d%d",
                  crop[i].name,&p,&a,&b,&c,&d,&e,&f,&s,&m);
            //printf("%s%d%d%d%d%d%d%d%d%d\n",crop[i].name,p,a,b,c,d,e,f,s,m);
            //printf("%s:%lu\n",crop[i].name,strlen(crop[i].name));
            int time=a+b+c+(d+e)*m;
            int income=f*s*m-p;
            crop[i].cost=1.0*income/time;
        }
        qsort(crop,n,sizeof(Crop),comp);
        for(int i=0;i<n;i++){
            printf("%s\n",crop[i].name);
            //printf("%s %f\n",crop[i].name,crop[i].cost);
        }printf("#\n");
    }
}



Measured memory_bytes: 2028
import java.util.*;

// 
// 

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		if (N == 1) {
			System.out.println("Hello World");
		} else {
			System.out.println(in.nextInt() + in.nextInt());
		}
	}
}

class TreeNode {
	int val;
	TreeNode left;
	TreeNode right;

	TreeNode(int x) {
		val = x;
	}
}

class TreeDrawer {
	public static String treeNodeToString(TreeNode root) {
		if (root == null) {
			return "[]";
		}

		String output = "";
		Queue<TreeNode> nodeQueue = new LinkedList<>();
		nodeQueue.add(root);
		while (!nodeQueue.isEmpty()) {
			TreeNode node = nodeQueue.remove();

			if (node == null) {
				output += "null, ";
				continue;
			}

			output += String.valueOf(node.val) + ", ";
			nodeQueue.add(node.left);
			nodeQueue.add(node.right);
		}
		return "[" + output.substring(0, output.length() - 2) + "]";
	}

	public static TreeNode stringToTreeNode(String input) {
		input = input.trim();
		input = input.substring(1, input.length() - 1);
		if (input.length() == 0) {
			return null;
		}

		String[] parts = input.split(",");
		String item = parts[0];
		TreeNode root = new TreeNode(Integer.parseInt(item));
		Queue<TreeNode> nodeQueue = new LinkedList<>();
		nodeQueue.add(root);

		int index = 1;
		while (!nodeQueue.isEmpty()) {
			TreeNode node = nodeQueue.remove();

			if (index == parts.length) {
				break;
			}

			item = parts[index++];
			item = item.trim();
			if (!item.equals("null")) {
				int leftNumber = Integer.parseInt(item);
				node.left = new TreeNode(leftNumber);
				nodeQueue.add(node.left);
			}

			if (index == parts.length) {
				break;
			}

			item = parts[index++];
			item = item.trim();
			if (!item.equals("null")) {
				int rightNumber = Integer.parseInt(item);
				node.right = new TreeNode(rightNumber);
				nodeQueue.add(node.right);
			}
		}
		return root;
	}

	public static void prettyPrintTree(TreeNode node, String prefix, boolean isLeft) {
		if (node == null) {
			System.out.println("Empty tree");
			return;
		}

		if (node.right != null) {
			prettyPrintTree(node.right, prefix + (isLeft ? "│   " : "    "), false);
		}

		System.out.println(prefix + (isLeft ? "└── " : "┌── ") + node.val);

		if (node.left != null) {
			prettyPrintTree(node.left, prefix + (isLeft ? "    " : "│   "), true);
		}
	}

	public static void draw(TreeNode node) {
		prettyPrintTree(node, "", true);
	}
}

Measured memory_bytes: 24276
#include <iostream>
using namespace std;
#define MAX 1000000
void sosu();

int prime[1000000]={0};

int main(){
    int n,cnter,cnt,ans;
    sosu();
    while(1){
        cnt=0;
        cnter=2;
        ans=0;
        cin >> n;
        if(n == 0) break;
        while(1){
            if(cnt == n) break;
            if(prime[cnter] == 0){
                ans += cnter;
                cnt++;
            }
            cnter++;
        }
        cout << ans << endl;
    }
}

void sosu(){
    for(int i=2;i<MAX/2;i++){
        for(int j=2;i*j <= MAX;j++){
            prime[i*j] = 1;
        }
    }
}

Measured memory_bytes: 5060
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
ll fact[1000005];
ll invfact[1000005];
ll power(ll x,ll y){
  if(y<=0) return 1;
  ll z=power(x,y/2);
  if(y%2) return ((z*z)%mod)*x%mod;
  return (z*z)%mod;
}
ll Cr(ll x, ll y){
  return (((fact[x]*invfact[x-y])%mod)*invfact[y])%mod;
}
void make_fact(ll n){
  fact[0]=1;
  rep(i,1,n+1) fact[i]=(i*fact[i-1])%mod;
  invfact[0]=1;
  rep(i,1,n+1) invfact[i]=(power(i,mod-2)*invfact[i-1])%mod;
}
void  solve(){
  int n,m;
  cin>>n>>m;
  vector<pii> factors;
  rep(i,2,sqrt(m)+1){
    ll c=0;
    while(m%i==0){
      c++;
      m/=i;
    }
    factors.pb({i,c});
  }
  if(m>1) factors.pb({m,1});
  ll ans=1;
  make_fact(200000L);
  rep(i,0,factors.size()){
    ans*=Cr(factors[i].s+n-1,factors[i].s);
    ans%=mod;
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 6772
import java.util.*;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    static int N;
    static long A;
    static long B;
    static long C;
    static long[] map;





    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        A = scanner.nextInt();
        B = scanner.nextInt();

        int temp = 0;
        for (int i = 0; i < 1000; i++) {
            temp += i;
            if(A < temp){
                if(temp + i + 1 - B == temp - A){

                    System.out.println(temp - A);
                    break;
                }
            }

        }


    }



}



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

using namespace std ;
#define pi 3.1415926535897932384626433832795
int main ()  { 
	
ios_base::sync_with_stdio(false) ; 
cin.tie(NULL) ; 
cout.tie(NULL) ;

long long n , m  ; 
cin >> n >> m ; 
vector<int> vect(m);  
for( int i = 0 ; i < m ; i ++ ) {
	cin >> vect[i] ;
	n-= vect[i] ; 
	if ( n < 0 ) {
		cout << -1 << endl ; 
		return 0 ; 
	} 
} 
cout << n << endl ; 

}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    int a,b;
    a = n / 10;
    b = n % 10;
    if(a == 9 || b == 9){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void){
	int H,W,t,y;
	while(1){
		scanf("%d %d",&H,&W);
		if(!(H==0&&W==0)){
			for(t=1;t<=H;t++){
				for(y=1;y<=W;y++){
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
		}
		else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;

int countt = 1, ans = 0;
string inp[maxn];
vector<int> vec;

int nCr(int n, int r) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1]); 
    } 
    return C[r]; 
} 


signed main() {

	int n; cin >> n;

	for(int i = 0; i < n; i++){
		cin >> inp[i];
		sort(inp[i].begin(), inp[i].end());
	}

	sort(inp, inp + n);

	//cout << inp[0] << " " << inp[1] << " " << inp[2] << endl; return 0;

	for(int i = 0; i < n-1; i++){
		if(inp[i] == inp[i + 1]){
			countt++;
			if(i == n-2) vec.push_back(countt);
		}
		else{
			vec.push_back(countt); countt = 1;
		}
	}

	//cout << vec.size() << endl; return 0;

	for(int i = 0; i < vec.size(); i++){

		ans += nCr(vec[i], 2);
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 15484
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll MOD = 1000000007;
ll INF =1<<30;

int main(){
    int k;
    cin >> k;
    vector<bool> ok (k+1,false);
    vector<int> a;
    int x = 7;
    for(int i = 0;;++i){
        int y = x%k;
        if(ok[y]==true) {
            cout << -1 <<endl;
            return 0;
        }
        a.push_back(y);
        if(y==0) {cout << a.size() <<endl;
        return 0;}
        ok[y]=true;
        x = y*10+7;
    }

}

Measured memory_bytes: 7464
def solve(line):
    a = line[0]
    b = line[1]
    c = line[2]
    c_divisors=[]
    count=0
    for i in range(1,c+1):
        if c%i==0:
            c_divisors.append(i)
    
    for x in range(a,b+1):
        if x in c_divisors:
            count+=1
    print(count)



    
def answer():
    line = list(map(int,input().split()))
    solve(line)

if __name__ =='__main__':
    answer()


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

int main(){
    int h,w;
    cin >> h >> w;
    
    vector<vector<char>> board(h,vector<char>(w));
    rep(i,h){
        rep(j,w) cin >> board[i][j];
    }
    
    vector<vector<char>> ans(2*h,vector<char>(w));
    int k = 0;
    for(int i = 0; i < 2*h; i+=2){
        for(int j = 0; j < w; j++){
            if(i==0){
                ans[i][j] = board[k][j];
                ans[i+1][j] = board[k][j];
            }
            else{
                ans[i][j] = board[k][j];
                ans[i+1][j] = board[k][j];
            }
        }
        k++;
    }
    
    rep(i,2*h){
        rep(j,w){
            cout << ans[i][j];
            if(j==w-1) cout << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long 
#define mod 1000000007

int main()
{
	string s;
	cin>>s;
	map<char,int>mp;
	for(int i=0;i<(int)s.size();i++)
	{
		mp[s[i]]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		if(it->second>1)
		{
			cout<<"no"<<endl;
			return 0;
		}
	}
	cout<<"yes"<<endl;
	return 0;
}

Measured memory_bytes: 892
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    ans = N * (N-1) // 2
    print(ans)

main()



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
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;}

#define D  double
typedef pair<D,int>T;
int N;
int X[1111],Y[1111],R[1111];
D dist[1111];
D INF=1e10;
D EPS=1e-9;

int table2[1111][1111];
D table[1111][1111];

signed main(){

    cin>>X[0]>>Y[0]>>X[1]>>Y[1];
    cin>>N;
    rep(i,N)cin>>X[i+2]>>Y[i+2]>>R[i+2];
    N+=2;

    rep(i,N)rep(j,N){
        table2[i][j]=(X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]);
        table[i][j]=sqrt(1.0*table2[i][j]);
    }

    fill_n(dist,1111,INF);
    dist[0]=0;
    priority_queue<T,vector<T>,greater<T>>que;
    que.push(make_pair(0,0));
    while(que.size()){
        D d;
        int idx;
        tie(d,idx)=que.top();
        que.pop();
        if(dist[idx]!=d)continue;
        rep(i,N){
            int foo=table2[i][idx];
            int bar=R[i]+R[idx];
            D cost=d;
            if(foo>bar*bar)cost+=sqrt(1.0*foo)-bar;
            if(cost<d)cost=d;
            if(dist[i]<=cost)continue;
            dist[i]=cost;
            que.push(T(dist[i],i));

        }
    }
    printf("%.20f\n",dist[1]);
    return 0;
}


Measured memory_bytes: 21872
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int n;
    string s;
    int k;
    cin >> n >> s >> k;
    char t;
    t = s[k-1];
    for (int i = 0; i < n; i++){
        if(t == s[i]);
        else s[i] = '*';
    }
    cout<< s<<endl;
    return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
  n <- (read :: String -> Int) <$> getLine
  s <- app <$> getLine
  print $ (\(a,b,c) -> a) $ ans s

ans :: (Int,Int,[Int]) -> (Int,Int,[Int])
ans (m,bn,[]) = (min m bn,bn,[])
ans (m,bn,w:b:ns) = ans (min m bn,bn+w-b,ns)

app :: String -> (Int,Int,[Int])
app str = finfunc $ foldl func initial str where
  initial = ('#',0,[],0)
  finfunc (c,i,is,n) = if c == '#' then (n,n,0:i:is) else (n,n,i:is)
  func a@(c,i,is,n) k
    | a == initial && k == '.' = (k,1,[0],0)
    | c == k = if k == '#' then (k,i+1,is,n+1) else (k,i+1,is,n)
    | c /= k = if k == '#' then (k,1,i:is,n+1) else (k,1,i:is,n)

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

using namespace std;

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

	int N;
	string S;
	cin >> N >> S;
	int64_t res{};
	vector<vector<int> > suf(N, vector<int>(3, 0));
	int r{}, g{}, b{};
	for(int i = N - 1; i >= 0; --i)
	{
		if(S[i] == 'R')
		{
			++r;
		}
		else if(S[i] == 'G')
		{
			++g;
		}
		else
		{
			++b;
		}
		suf[i][0] = r;
		suf[i][1] = g;
		suf[i][2] = b;
	}
	for(int i = 0; i < N; ++i)
	{
		for(int j = i + 1; j < N; ++j)
		{
			if(S[i] != S[j])
			{
				if((S[i] == 'R' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'R'))
				{
					// B
					res += suf[j][2];
					int k = j + (j - i);
					if(k < N and S[k] == 'B')
					{
						--res;
					}
				}
				else if((S[i] == 'G' and S[j] == 'B') or (S[i] == 'B' and S[j] == 'G'))
				{
					// R
					res += suf[j][0];
					int k = j + (j - i);
					if(k < N and S[k] == 'R')
					{
						--res;
					}
				}
				else
				{
					// G
					res += suf[j][1];
					int k = j + (j - i);
					if(k < N and S[k] == 'G')
					{
						--res;
					}
				}
			}
		}
	}
	cout << res << "\n";

	return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


struct edge{int to;ll cap;int rev;};
struct Dinic{
private:
    int n;
    vector<vector<edge>> v;
    vector<int> dist,iter;
public:
    Dinic(int sz):n(sz),v(sz),dist(sz),iter(sz){}
    
    void addedge(int from,int to,ll cap){
        int x=v[to].size(),y=v[from].size();
        v[from].push_back({to,cap,x});
        v[to].push_back({from,0,y});
    }
    
    void bfs(int s){
        fill(dist.begin(),dist.end(),-1);
        queue<int> q;
        dist[s]=0;
        q.push(s);
        while(q.size()){
            int x=q.front();q.pop();
            rep(i,v[x].size()){
                edge &e=v[x][i];
                if(e.cap>0&&dist[e.to]<0){
                    dist[e.to]=dist[x]+1;
                    q.push(e.to);
                }
            }
        }
    }
    
    ll dfs(int x,int t,ll f){
        if(x==t)return f;
        for(int& i=iter[x];i<(int)v[x].size();++i){
            edge& e=v[x][i];
            if(e.cap>0&&dist[x]<dist[e.to]){
                ll d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    v[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    ll max_flow(int s,int t){
        ll flow=0;
        while(1){
            bfs(s);
            if(dist[t]<0)return flow;
            fill(iter.begin(),iter.end(),0);
            ll f;
            while((f=dfs(s,t,1LL<<62))>0)flow+=f;
        }
    }
};
int main(){
    int n;
    cin>>n;
    Dinic dn(n+2);
    ll ans = 0;
    rep(i,n){
        int x;cin>>x;
        if(x>0){
            ans += x;
            dn.addedge(n, i, x);
        }
        else dn.addedge(i, n+1, -x);
    }
    rep(i,n){
        for(int j=2*i+2;j<=n;j+=i+1){
            dn.addedge(j-1, i,longinf);
        }
    }
    cout<<ans - dn.max_flow(n, n+1)<<endl;
    return 0;
}

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

int main (){
  int N,K,S=0;
  cin >> N >>K;
  for (int i=0;i<N;i++){
    int x;
    cin >> x ;
    if (x<(K-x)){
      S+=x*2;
    }
    else {
      S+=(K-x)*2;
    }
    
  }
  cout << S << endl;
}
      

Measured memory_bytes: 256
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def gutyocu():
    ans = 0
    for i, j in itertools.combinations_with_replacement(range(N), r=2):
        ans += min(A[i: j + 1])
    return ans


pos = list(range(N + 1))
pos[0] = -1
for i, a in enumerate(A):
    pos[a] = i

ans = 0
lefts = list(range(N + 1))
rights = list(range(N + 1))
for i in reversed(range(1, N + 1)):
    p = pos[i]
    if p + 1 < N and A[p + 1] > i:
        # 右とつながった
        right = rights[p + 1]
    else:
        right = p
    if p - 1 >= 0 and A[p - 1] > i:
        # 左とつながった
        left = lefts[p - 1]
    else:
        left = p
    lefts[right] = left
    rights[left] = right
    ans += (abs(left - p) + 1) * (abs(right - p) + 1) * i
print(ans)


Measured memory_bytes: 73424