akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
const int maxn = 85;
#define int long long
int a[maxn];

signed main(){
    // #ifdef LOCAL
    //     freopen("in.txt", "r", stdin);
    //     freopen("out.txt", "w", stdout);
    // #endif
    ll n;
    sf(n);
    rep(i, 1, n) sf(a[i]);
    int tot = 1000;
    for (int i = 2; i <= n; ++i) {
        if (a[i] >= a[i - 1]) {
            int num = tot / a[i - 1];
            int dif = a[i] - a[i - 1];
            tot += num * dif;
        }
    }
    out(tot);
    return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n;
    cin>>n;
    ll r = n%1000;
    ll q = n/1000;
    if(r!=0){
        q++;
    }
    ll t1 = q*1000;
    cout<<t1-n<<endl;

    return 0;
}

Measured memory_bytes: 3648
package main

import (
	"fmt"
)

func main() {
	var input string
	fmt.Scan(&input)

	v := make([]int, len(input))
	for i, r := range input {
		v[i] = int(r - '0')
	}

	n := 3
	for bit := 0; bit < (1 << uint(n)); bit++ {
		ans := v[0]
		ansStr := fmt.Sprint(v[0])
		for i := 0; i < n; i++ {
			if bit&(1<<uint(i)) == (1 << uint(i)) {
				ans += v[i+1]
				ansStr = fmt.Sprintf("%s+%d", ansStr, v[i+1])
			} else {
				ans -= v[i+1]
				ansStr = fmt.Sprintf("%s-%d", ansStr, v[i+1])
			}
		}
		if ans == 7 {
			ansStr = fmt.Sprintf("%s=%d", ansStr, ans)
			fmt.Println(ansStr)
			return
		}
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <set>
#define MAX 100000
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int main(void)
{
	int A, B; cin >> A >> B;

	int ans = 0;
	rep(i, A, B + 1) {
		string x = to_string(i);
		string y = x;
		reverse(x.begin(), x.end());
		if (y == x)ans++;
	}
	
	cout << ans << endl;

	return 0;
}

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

typedef long long ll;

int main()
{
    int n, k;
    int ans = 1;

    scanf("%d %d", &n, &k );

    for ( int i = 0; i < n; ++i ) {
        if ( ans * 2 >= ans + k ) {
            ans += k;
        } else {
            ans *= 2;
        }
    }

    printf("%d\n", ans );

    return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define inf 0x7f7f7f7f7f7f7f7f 
#define maxn 300010
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define db(x) cout << x << endl;
const int mod = 10e8+7;
const int eps = 1e-6;
using namespace std;
int a[maxn],b[maxn];
char s[maxn];
int v[maxn],si[maxn];
vi e[maxn];
signed main()
{
	ios::sync_with_stdio(0);
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin >> u >> v;
		e[u].pb(v);
		e[v].pb(u);
	}
	queue<int>q;;
	q.push(1);
	while(q.size())
	{
		int p = q.front();
		q.pop();
		for(auto i:e[p])
			if(!v[i])
			{
				v[i] = p;
				q.push(i);
			}
	}
	for(int i=2;i<=n;i++)
		if(!v[i])
		{
			cout << "No";
			return 0;
		}
		cout << "Yes\n";
	for(int i=2;i<=n;i++)
		cout << v[i]<<endl;
	return 0;
}

Measured memory_bytes: 17748
#include <bits/stdc++.h>
//#pragma GCC diagnostic warning "-std=c++11"
using namespace std;
#define ll long long 
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define MAX ((ll)(1e18+100))
#define MX ((ll)(1e6+90))
#define ARRS ((ll)(1e5+100))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define EPS ((double)(1e-8))
#define pb push_back
#define PI ((double)3.141592653)
#define LG 16

ll n,m;
ll pas[ARRS];
ll f[ARRS];
vector<ll> v[ARRS];
vector<ll> g[ARRS];

int main(){

	cin>>n;
	if(n==2){
		cout<<"1 2";
		return 0;
	}
	for(int i=0; i<n-1; i++){
		ll k,p;
		cin>>k>>p;
		v[k].pb(p);
		v[p].pb(k);
		f[k]++;
		f[p]++;
	}
	for(int i=1; i<=n; i++){
		if(f[i]>1){
			for(auto x:v[i]){
				if(f[x]>1)
					g[i].pb(x);
			}
			if(g[i].size()>2){
				cout<<-1;
				return 0;
			}
		}
	}
	vector<ll> t;
	for(int i=1; i<=n; i++){
		if(g[i].size()==1){
			ll l=-1;
			ll x=i;
			while(1){
				t.pb(f[x]-g[x].size());
				if(l!=-1&&g[x].size()==1)
					break;
				for(auto y:g[x]){
					if(y==l)continue;
					l=x;
					x=y;
					break;
				}
			}
			break;
		}
	}
	if(t.size()==0){
		t.pb(n-1);
	}
	vector<ll> bk=t;
	ll m=t.size();
	if(t[0]){
		t[0]--;
		reverse(t.begin(),t.end());
		t.pb(0);
		reverse(t.begin(),t.end());
	}
	if(t[t.size()-1]){
		t[t.size()-1]--;
		t.pb(0);
	}
	ll c=1;
	vector<ll> pas;
	for(auto x:t){
		ll k=c++;
		while(x--)
			pas.pb(c++);
		pas.pb(k);
	}


	reverse(bk.begin(),bk.end());
	t=bk;
	if(t[0]){
		t[0]--;
		reverse(t.begin(),t.end());
		t.pb(0);
		reverse(t.begin(),t.end());
	}
	if(t[t.size()-1]){
		t[t.size()-1]--;
		t.pb(0);
	}
	c=1;
	vector<ll> pas1;
	for(auto x:t){
		ll k=c++;
		while(x--)
			pas1.pb(c++);
		pas1.pb(k);
	}
	for(int i=0; i<pas.size(); i++){
		if(pas[i]>pas1[i]){
			pas=pas1;
			break;
		}
		else if(pas[i]<pas1[i]){
			break;
		}
	}
	for(auto x:pas){
		cout<<x<<" ";
	}


}


Measured memory_bytes: 16504
program atcoder;
var
a,b,c,e,f : integer;
x,y,z,d : string;
begin
readln(a,b,c);
str(a,x);
str(b,y);
str(c,z);
d :=concat(x,y,z);
val(d,f,e);
if f mod 4 = 0 then writeln('YES')
			   else writeln('NO');
end.

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

int main()
{
    int r, c, sum = 0;
    cin >> r >> c;

    int x[c] = {};

    while (r--) {
        int sum = 0;

        for (int i = 0; i < c; ++i) {
            int t;
            cin >> t;
            x[i] += t;
            sum += t;
            cout << t << " ";
        }

        cout << sum << endl;
    }

    for (int i = 0; i < c; ++i) {
        sum += x[i];
        cout << x[i] << " ";
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
char a[100010],s2[100010];
int len;
int main()
{
    cin>>a;
    for(int i=strlen(a)-1; i>=0; i--)
    {
        s2[len++]=a[i];
    }
    for(int i=0; i<strlen(a); i++)
    {
       if(a[i]=='b')
       {
       	a[i]='d';
       	continue;
	   }
	   if(a[i]=='d')
       {
       	a[i]='b';
       	continue;
	   }
	   if(a[i]=='q')
       {
       	a[i]='p';
       	continue;
	   }
	   if(a[i]=='p')
       {
       	a[i]='q';
       	continue;
	   }
    }
    if(strcmp(a,s2)==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

int main(){
    int h, w; cin >> h >> w;
    vector<string> lis(h);
    REP(i, 0, w){cin >> lis[i];}
    REP(i, 0, h){
        REP(l, 0, w){
            if(lis[i][l] == '#'){
                int f = 0;
                REP(k, 0, 4){
                    int x = i + dx[k];
                    int y = l + dy[k];
                    if(x >= 0 && y >= 0 && x < h && y < w){
                        if(lis[x][y] == '#'){
                            f = 1;
                        }
                    }
                }
                if(f == 0){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
//Weather Forecaster
#include <iostream>

using namespace std;

static const int NIL = -1;

enum WEATHER {
    SUNNY,
    CLOUDY
};

int main() {
    int H, W;
    cin >> H >> W;
    int A[H][W], T[H][W];
    char c;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> c;
            if(c == '.') {
                A[i][j] = SUNNY;
                T[i][j] = NIL;
            }
            else if(c == 'c') {
                A[i][j] = CLOUDY;
                T[i][j] = 0;
            }
        }
    }

    for(int i = 0; i < H; i++) {
        for(int j = 1; j < W; j++) {
            if(A[i][j] == CLOUDY) continue;
            if(T[i][j - 1] == NIL) continue;
            T[i][j] = T[i][j - 1] + 1;
        }
    }

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(j != 0) cout << " ";
            cout << T[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3168
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <iterator>
#include <math.h>
#include <list>
#include <bits/stdc++.h>

using namespace std;

int main(void){
  long long a,b,c;
  cin >> a >> b >> c;
  if( c-a-b > 0 &&  4*a*b < (c-a-b)*(c-a-b)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L+5;
const int LG = 20;
const int N = 1e5+9;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int power(int x,int y){if(x==0)return 0;int res=1;while(y>0){if(y%2==1)res=(res*x)%M;x=(x*x)%M;y=y/2;}return res;}
bool isvowel(char c){if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U')return true;return false;}
int32_t main()
{
	//cout.precision(15);
	//cout.setf(ios::fixed,ios::floatfield);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int T=1;
	//cin>>T;
	while(T--)
	{
		string s,t;
		cin>>s>>t;
		for(int i=0;i<s.size()-1;i++)
		{
			if(s[i]!=t[i]){
			cout<<"No"<<endl;
			return 0;}
		}
		if(s.size()==1)
		{
			if(s[0]!=t[0])
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		cout<<"Yes"<<endl;
	}
}



Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;

int N;
string S[2];
vector<long long> dp[3][3];
int MOD = 1e9 + 7;

void solve() {
	cin >> N >> S[0] >> S[1];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			dp[i][j].clear();
			dp[i][j].resize(N,0);
		}
	}
	if (S[0][0] == S[1][0]) {
		for (int c = 0; c < 3; c++) {
			dp[c][c][0] = 1;
		}
	}
	else {
		for (int c0 = 0; c0 < 3; c0++) {
			for (int c1 = 0; c1 < 3; c1++) {
				if (c0 == c1)continue;
				dp[c0][c1][0] = 1;
			}
		}
	}
	for (int n = 1; n < N; n++) {
		if (S[0][n] == S[1][n]) {
			for (int c = 0; c < 3; c++) {
				for (int c0 = 0; c0 < 3; c0++) {
					for (int c1 = 0; c1 < 3; c1++) {
						if (c0 == c || c1 == c)continue;
						dp[c][c][n] += dp[c0][c1][n - 1];
					}
				}
			}
		}
		else if (S[0][n] == S[0][n - 1] && S[1][n] == S[1][n - 1]) {
			for (int c1 = 0; c1 < 3; c1++) {
				for (int c2 = 0; c2 < 3; c2++) {
					if (c1 == c2)continue;
					dp[c1][c2][n] = dp[c1][c2][n - 1];
				}
			}
		}
		else if (S[0][n] != S[0][n - 1] && S[1][n] == S[1][n - 1]) {
			for (int c1 = 0; c1 < 3; c1++) {
				for (int c2 = 0; c2 < 3; c2++) {
					for (int c = 0; c < 3; c++) {
						if (c == c1 || c == c2)continue;
						dp[c1][c2][n] = dp[c][c2][n - 1];
					}
				}
			}
		}
		else if (S[0][n] == S[0][n - 1] && S[1][n] != S[1][n - 1]) {
			for (int c1 = 0; c1 < 3; c1++) {
				for (int c2 = 0; c2 < 3; c2++) {
					for (int c = 0; c < 3; c++) {
						if (c == c1 || c == c2)continue;
						dp[c1][c2][n] = dp[c1][c][n - 1];
					}
				}
			}
		}
		else {
			for (int c1 = 0; c1 < 3; c1++) {
				for (int c2 = 0; c2 < 3; c2++) {
					for (int c11 = 0; c11 < 3; c11++) {
						for (int c22 = 0; c22 < 3; c22++) {
							if (c11 == c1 || c22 == c2)continue;
							dp[c1][c2][n] += dp[c11][c22][n - 1];
						}
					}
				}
			}
		}
		for (int c1 = 0; c1 < 3; c1++) {
			for (int c2 = 0; c2 < 3; c2++) {
				dp[c1][c2][n] %= MOD;
			}
		}
	}
	long long ans = 0;
	for (int c1 = 0; c1 < 3; c1++) {
		for (int c2 = 0; c2 < 3; c2++)ans += dp[c1][c2][N - 1];
	}
	ans %= MOD;
	cout << ans << endl;
	return;
}

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

int main() {
#ifdef DEBUGTIME
	for (int time = 0; time < DEBUGTIME; time++) {
		solve();
		cout << "####################" << endl;
	}
#else
	solve();
#endif
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  string S;
  cin>>S;
  
 int s=0;
  for(int i=0;i<4;i++){
    int count=0;
    for(int j=0;j<4;j++){
    if(S.at(i)==S.at(j)){
       count++;
      }
    }
	 if(count==2){
       s++;
     }
  }
  if(s==4){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
n = int(input())
li_a = list(map(int, input().split()))
q = int(input())
sum_ = sum(li_a)
di = {}
for i in range(1, 10**5+1):
    di[i] = 0
for i in li_a:
    di[i] += 1
for _ in range(q):
    b, c = map(int, input().split())
    tmp = di[b]
    di[b] = 0
    di[c] += tmp
    sum_ = sum_ + c*tmp - b*tmp
    print(sum_)

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

#define task "B"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
string s;
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> s;
    if (s[0] == s.back()) cout << ((SZ(s) & 1) ? "Second" : "First");
    else cout << ((SZ(s) & 1) ? "First" : "Second");
    return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;

//prime[i]はi番目の素数
//isp[j]はjが素数か判定
//エラトステネスの篩を用いる
int prime[MAX];
bool isp[MAX];
bool like[MAX];
int sum[MAX];

int main(){
	//入力
	int N=MAX;
	
	int p = 0;
	//初期化
	for(int i=0;i<=N;i++)
		isp[i]=true;
	isp[0]=isp[1]=false;
	//2以上で素数ならふるい落とす
	for(int i=2;i<=N;i++){
		if(isp[i]){
			p++;
			prime[p]=i;
			for(int j=2*i;j<=N;j+=i) isp[j]=false;
		}
	}
	rep1(i,N){
		if(isp[i]&&isp[(i+1)/2])like[i]=true;
	}
	rep1(i,N){
		if(like[i])sum[i]=sum[i-1]+1;
		else sum[i]=sum[i-1];
	}
	int Q;
	cin>>Q;
	rep(i,Q){
		int l,r;
		cin>>l>>r;
		cout<<sum[r]-sum[l-1]<<endl;
	}
}

Measured memory_bytes: 1280
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int a,b,x; cin >> a >> b >> x;
    int ans = 0;
    ans += b / x;
    ans -= a / x;
    ans += (a % x == 0);

    cout << ans << endl;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int n[4];
    REP(i,4)cin>>n[i];
    sort(n,n+4);
    if(n[0]==1&&n[1]==4&&n[2]==7&&n[3]==9){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

long solve(int n, std::vector<int>& lengths)
{
  long result = 0;
  std::sort(lengths.begin(), lengths.end());
  for (int i = 0; i < n - 2; ++i) {
    for (int j = i + 1; j < n - 1; ++j) {
      for (int k = j + 1; k < n; ++k) {
        const auto a = lengths[i];
        const auto b = lengths[j];
        const auto c = lengths[k];
        if (a + b > c && a != b && b != c && c != a) {
          ++result;
        }
      }
    }
  }
  return result;
}

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> lengths(n);
  for (auto& len : lengths) {
    std::cin >> len;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, lengths) << std::endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<int>l(n),r(n);
    int c = 0;
    rep(i,n){
        if(s[i]=='W')l[i] = ++c;
        else l[i] = c;
    }
    c = 0;
    for(int i = n-1;i>=0;--i){
        if(s[i]=='E')r[i] = ++c;
        else r[i] = c;
    }
    ll mini = INF;
    // rep(i,n){
    //     cout << l[i] << " ";
    // }
    // cout << endl;
    // rep(i,n){
    //     cout << r[i] << " ";
    // }
    // cout << endl;
    rep(i,n){
        ll cost = l[i] + r[i] -1;
        // cout << cost << endl;
        mini = min(cost,mini);
    }
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <algorithm>
#include <array>
#include <iostream>
#include <limits>

using namespace std;

int main()
{
    array<int, 1000001> dp = {};
    fill(begin(dp), end(dp), numeric_limits<int>::max());
    dp[0] = 0;
    auto dp2 = dp;
    auto tetrahedral = [](int n) { return n * (n + 1) * (n + 2) / 6; };
    for (int i = 1; tetrahedral(i) < dp.size(); ++i) {
        const auto t = tetrahedral(i);
        for (int j = 0; j + t < dp.size(); ++j) {
            dp[j + t] = min(dp[j + t], dp[j] + 1);
        }
        if (t % 2 == 1) {
            for (int j = 0; j + t < dp2.size(); ++j) {
                dp2[j + t] = min(dp2[j + t], dp2[j] + 1);
            }
        }
    }

    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            return 0;
        }

        cout << dp[n] << ' ' << dp2[n] << endl;
    }
}

Measured memory_bytes: 10840
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        string s = sc.Next();

        bool ok = s.Where(c => c == 'R').Count() > s.Where(c => c == 'B').Count();

        string answer = ok ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

int main() {
    int n; cin >> n;
    vector<int> h(n, 0);

    for (int i = 0; i < n; i += 1) 
        cin >> h[i];
        
    vector<int> dp(n, 0);

    dp[0] = 0;

    for (int i = 1; i < n; i += 1) {
        dp[i] = numeric_limits<int> :: max();
        for (int delta = 1; delta <= 2 and i - delta >= 0; delta += 1)
            dp[i] = min(dp[i], dp[i - delta] + abs(h[i] - h[i - delta]));
    }
    
    cout << dp[n - 1] << "\n";
}

Measured memory_bytes: 1024
'use strict'

function main(input) {
  input = input.split('\n')
  const length = input[0]
  let res = 0;
  let list = [0];
  const text = input[1].split('')
  for (let i = 0;i < length;i++) {
    if (text[i] == 'I') {
      res++;
    } else {
      res--;
    }
    list.push(res);
  }
  console.log(Math.max(...list));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e5+5;
int A[3][maxn], dp[3][maxn];

int dfs(const int i, const int j)
{
    if (j == 0)
        return A[i][0];
    int& ans = dp[i][j];
    if (-1 == ans) {
        ans = 0;
        FOR(k,0,3) if (k != i) {
            const int res = dfs(k,j-1) + A[i][j];
            ans = max(ans,res);
        }
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        memset(dp,-1,sizeof(dp));
        FOR(j,0,n) FOR(i,0,3)
            cin >> A[i][j];
        int ans = 0;
        FOR(i,0,3) {
            const int res = dfs(i,n-1);
            ans = max(ans,res);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
vector<int> prime(100001);
void sieve(){
  for(int i = 0;i < prime.size();i++)prime[i] = 1;
  prime[0] = 0;
  prime[1] = 0;
  for(int i = 2;i < prime.size();i++){
    if(prime[i] == 0)continue;
    int now = 2;
    for(int j = i * 2;j < prime.size();j++){
      prime[j] = 0;
      j += i - 1;
    }
  }
}
int main(){
  sieve();
  //for(int i = 0;i < prime.size();i++)cout << i << " " << prime[i] << endl;
  vector<int> count(100001);
  count[0] = 0;
  for(int i = 1;i < count.size();i++){
    count[i] = count[i - 1];
    if(i % 2 == 1){
      if(prime[i] == 1 && prime[(i + 1) / 2] == 1)count[i]++;
    }
  }
  int q = 0;
  cin >> q;
  for(int i = 0;i < q;i++){
    int l,r;
    cin >> l >> r;
    cout << count[r] - count[l - 1] << endl;
  }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B,p=0,q=0;cin>>N>>A>>B;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  
  for(int i=0;i<N;i++){
    if(a.at(i)<=A)p++;
    else if(a.at(i)>B)q++;
  }
  
  int ans=min(p,q);
  ans=min(ans,N-p-q);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int A[MAXN];
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int X, Y, Z; cin >> X >> Y >> Z;
	cout << Z << " " << X << " " << Y << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
 int i;
 char a[4];
 
 scanf("%s",a);
 if(a[2]=='\0'){
     printf("%s",a);
 return 0;
 }
 
     printf("%c%c%c",a[2],a[1],a[0]);
 
 
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
int dp[200001];
int h[200001];
int dpf(int n)
{
       if (dp[n]!=-1) {return dp[n];                 }
  else if (n==0     ) {return dp[n]=INT_MAX;         }
  else if (n==1     ) {return dp[n]=0;               }
  else if (n==2     ) {return dp[n]=abs(h[n]-h[n-1]);}
  else                {return dp[n]=min(abs(h[n]-h[n-1])+dpf(n-1),abs(h[n]-h[n-2])+dpf(n-2)); }
  return 0;
}
int main()
{  ios_base::sync_with_stdio(false); cin.tie(NULL);
   memset(dp,-1,sizeof(dp));
   int n;cin>>n;
   for(int i=1;i<=n;i++)
   {
    cin>>h[i];
   }
   int ans=dpf(n);
   cout<<ans;
   return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int A, P;
	cin >> A >> P;
	ce((A*3+P)/2)
    return 0;
}



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

int main()
{
  ll n,a[200005],k;
  cin>>n>>k;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  ll dp[200005];
   dp[0]=0;
   ll ans=INT_MAX;
  for(int i=1;i<n;i++)
  {
    dp[i]=INT_MAX;
    for(int j=i-1;j>=0 && j>=(i-k);j--)
    {
      ll v1=dp[j]+abs(a[i]-a[j]);
     dp[i]=min(v1,dp[i]);
    }  
  } 
  cout<<dp[n-1]<<"\n";
  return 0;
}

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

int n;
int c[200000];
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a;
    cin >> a;
    --a;
    ++c[a];
  }
  
  for (int i = 0; i < n; ++i) {
    cout << c[i] << endl;
  }
}

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    string s; 
    cin>>s;
    int p_count = 0;
    REP(i, 0, s.size()){
        if(s[i] == 'p') p_count++;
    }
    int p_max = (int)s.size()/2;
    cout << p_max - p_count << endl;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] size = Console.ReadLine().Split(' ');
            int n = int.Parse(size[0]);
            int m = int.Parse(size[1]);

            int[,] a = new int[n, m];
            int[] b = new int[m];

            for(int i=0;i<n;i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                int[] num = Array.ConvertAll(str, new Converter<string, int>(s => int.Parse(s)));
                for (int j = 0; j < m; j++) a[i, j] = num[j];
            }
            for(int i=0;i<m;i++)
            {
                int num = int.Parse(Console.ReadLine());
                b[i] = num;
            }

            for(int i=0;i<n;i++)
            {
                int x = 0;
                for(int j = 0; j < m; j++) x += a[i, j] * b[j];
                Console.WriteLine(""+x);
            }
        }
    }
}

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

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<unsigned long long int>;

int main(void) {
    char c[9];
    for (Int i = 0; i < 9; ++i) {
        cin >> c[i];
    }
    cout << c[0] << c[4] << c[8] << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){	
	int n;cin>>n;
	int x=n*800,y=n/15*200;
	cout<<x-y;
	return 0;
}

Measured memory_bytes: 3644
a1,b1 = map(int,input().split())
a2,b2 = map(int,input().split())
a3,b3 = map(int,input().split())

counter = 0
for i in range(1,5):
	counter = 0
	if a1 == i or b1 == i:
		counter += 1
	if a2 == i or b2 == i:
		counter += 1
	if a3 == i or b3 == i:
		counter += 1
	if counter == 3:
		print("NO")
		exit()
		
print("YES")




Measured memory_bytes: 3060
#include <stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK -1
typedef struct ver{
    int id;
    int d;
    int f;
}ver;
ver V[110];
int A[110][100], n, d[110], color[110], f[110];
void visit(int u){
    int v=1;
    int static time=0;
    color[u] = GRAY;
    d[u] = ++time;
    while(A[u][v] != 0){ // Explore edge (u,v)
        if(color[A[u][v]] == WHITE)
            visit(A[u][v]);
        v++;
    }
    color[u] = BLACK;
    f[u] = ++time;
}

void dfs(){
    int i;
    for(i = 1; i < n; i++)
        color[i]= WHITE;
    for(i = 1; i < n; i++){
        if(color[i] == 0) visit(i);
    }
}

int main(){
    int i, j, k, u, v;
    scanf("%d",&n);
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++)
            A[i][j] = 0;
    }
    for(i = 1; i <= n; i++){
        scanf("%d",&u);
        V[i].id = u;
        scanf("%d", &k);
        for(j = 1; j <= k; j++){
            scanf("%d",&v);
            A[u][j] = v;
        }
    }
    dfs();
    for(i = 1; i <= n; i++)
        printf("%d %d %d\n",V[i].id, d[i], f[i]);
    return 0;
}

Measured memory_bytes: 636
def jisuan():
    global s
    s1=0
    for i in range(q):
        if A[b[i]-1]-A[a[i]-1]==c[i]:
            s1+=d[i]
    s=max(s,s1)


def dg1(w):
    if w==n:
        jisuan()
        return
    for i in range(A[w-1],m+1):
        A[w]=i
        dg1(w+1)


def dg():
    for i in range(1,m+1):
        A[0]=i
        dg1(1)


n,m,q=map(int,input().split())
s=0
# ai<=m
# A一共n个
a,b,c,d=[],[],[],[]
for i in range(q):
    x=list(map(int,input().split()))
    a.append(x[0])
    b.append(x[1])
    c.append(x[2])
    d.append(x[3])
A=[0]*n
dg()
print(s)


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

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

    vs32 r(R);
    rep (i, R) { cin >> r[i]; --r[i]; }

    int d[N][N];
    rep (i, N) rep (j, N) d[i][j] = 1e9;
    rep (i, N) d[i][i] = 0;

    rep (i, M)
    {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep (k, N)
    {
        rep (i, N)
        {
            rep (j, N)
            {
                d[i][j] = MIN(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    vs32 v(R);
    rep (i, R) v[i] = i;

    int ans = 1e9;
    do {
        int temp = 0;
        rep (i, R - 1)
        {
            int from = r[v[i]];
            int to = r[v[i + 1]];
            temp += d[from][to];
        }
        ans = MIN(ans, temp);
    } while (next_permutation(v.begin(), v.end()));

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



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x/gcd(x,y)*y;
}
 
signed main(){
	int n;
	cin>>n;
	int t[n];
	for(int i=0;i<n;i++){
		cin>>t[i];
	}
	for(int i=1;i<n;i++){
			t[i]=lcm(t[i-1],t[i]);
	}
	cout<<t[n-1]<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char str[1050];
char word[15];
char end[] = "END_OF_TEXT";
int main(){

scanf("%s",word);

int word_count = 0;
int end_count = 0;
int len_word = strlen(word);
int len_end = strlen(end);


while(1){
int p=0;
scanf("%s",str);
int len_str = strlen(str);
int checker = strcmp(str,end);
if(checker == 0)
break;
if(len_word== len_str){
for(int i=0;i<len_str;i++){
if(str[i] >= 'A' && str[i] <= 'Z'){
    str[i] = 'a' + str[i] - 'A';
}

if(str[i]==word[p]){
    p++;
    if(p==len_word){
        word_count++;
    }
}
else {
    break;
}
}

}

}
printf("%d\n",word_count);


}



Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n; cin >> n;
  vector<int> x(n);
  for(int i=0;i<n;++i) cin >> x[i];
  vector<int> y(x);
  sort(x.begin(), x.end());
  int left = x[n/2-1];
  int right = x[n/2];
  for(int i=0;i<n-1;++i){
    if(y[i] <= left) cout << right << endl;
    else cout << left << endl;  
  }
  if(y[n-1] <= left){
    cout << right;
  }else{
    cout << left;
  }
  return 0;
}

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

int n;
char c[11];

void f2(int k, int character) {
  if (k == n) {
    cout << c << endl;
    return;
  }

  rep(i, 0, character) {
    c[k] = 'a' + i;
    f2(k+1, character);
  }

  c[k] = 'a' + character;
  f2(k+1, character+1);
}

int main() {
  cin >> n;
  // n = 4;

  f2(0,0);
  return 0;
}


Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

import numpy as np

def solve():
    n, m, x = MI()
    C = [0] * n
    A = [None] * n
    for i in range(n):
        tmp = LI()
        c = tmp[0]
        a = tmp[1:]
        C[i] = c
        A[i] = a
    # print(C)
    # print(A)

    ans = INF
    for i in range(pow(2, n)):
        bag = []
        for j in range(n):
            if 1 & (i >> j):
                bag.append(j)

        a = np.array([0] * m)
        c = 0
        for b in bag:
            a += np.array(A[b])
            c += C[b]

        # print(a, all(a >= x))
        if all(a >= x):
            ans = min(ans, c)

    if ans == INF:
        print(-1)
    else:
        print(ans)



if __name__ == '__main__':
    solve()


Measured memory_bytes: 27312
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd seocnd

using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll a[n];
    fr(i, 0, n) cin >> a[i];

    fr(i, 0, n) a[i] -= (i + 1);

    sort(a, a + n);
    ll b = a[n / 2];
    ll sum = 0;
    fr(i, 0, n){
        sum += abs(a[i] - b);
    }
    cout << sum << endl;




    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String S=sc.next();
		String[] S2=S.split("");
		int N=S2.length;
		for(int i=0;i<N/2;i++) {
			if(!S2[0+i].equals(S2[N-1-i])) {
				System.out.println("No");
				System.exit(0);}
		}
		for(int i=0;i<((N-1)/2)-1;i++) {
			if(!S2[0+i].equals(S2[(N-1)/2-1-i])||!S2[(N+3)/2-1+i].equals(S2[N-1-i])) {
				System.out.println("No");
				System.exit(0);}

	}System.out.println("Yes");
		}
}


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

int main() {
    int r,g,b;
    cin >> r >> g >> b;
    int x;
    x = 100*r + 10*g + b;
    if(x%4 == 0) 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)
typedef long long ll;

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

using namespace std;

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

  int nx[n];
  int ny[n];
  int mx[m];
  int my[m];

  rep(i, n) {
    cin >> nx[i];
    cin >> ny[i];
  }

  rep(i, m) {
    cin >> mx[i];
    cin >> my[i];
  }

  rep(i, n) {
    int x = nx[i];
    int y = ny[i];
    int min = 1 << 30;
    int minIndex = -1;
    rep(j, m) {
      int distance = abs(x - mx[j]) + abs(y - my[j]);
      if (min > distance) {
        minIndex = j;
        min = distance;
      }
    }
    cout << minIndex + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;

const int M = 3;

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

    vvi a(M, vi(M));
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
            cin >> a.at(i).at(j);
        }
    }

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

        for (int j = 0; j < M; j++) {
            for (int k = 0; k < M; k++) {
                if (a.at(j).at(k) == b) {
                    a.at(j).at(k) = 0;
                }
            }
        }
    }

    bool ans = false;
    for (int i = 0; i < M; i++) {
        if (a.at(i).at(0) == 0 && a.at(i).at(1) == 0 && a.at(i).at(2) == 0) {
            ans = true;
        }
        if (a.at(0).at(i) == 0 && a.at(1).at(i) == 0 && a.at(2).at(i) == 0) {
            ans = true;
        }
    }
    if (a.at(0).at(0) == 0 && a.at(1).at(1) == 0 && a.at(2).at(2) == 0) {
        ans = true;
    }
    if (a.at(0).at(2) == 0 && a.at(1).at(1) == 0 && a.at(2).at(0) == 0) {
        ans = true;
    }

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  int c[3][3];
  rep(i, 3) rep(j, 3) cin >> c[i][j];

  string res = "No";
  rep(k, 101) rep(m, 101) rep(n, 101) {
    int a[3], b[3];
    a[0] = k, a[1] = m, a[2] = n;
    b[0] = c[0][0] - a[0], b[1] = c[1][1] - a[1], b[2] = c[2][2] - a[2];
    bool skip = false;
    rep(i, 3) if (b[i] < 0) skip = true;
    if (skip) continue;
    int cnt = 0;
    rep(i, 3) rep(j, 3) {
      if (c[i][j] != a[i] + b[j]) continue;
      cnt++;
    }
    if (cnt == 9) {
      res = "Yes";
      goto RES;
    }
  }

RES:
  cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n;
  int *p;
  scanf("%d", &n);
  p = (int *)malloc(sizeof(int)*n);
  
  for(int i = 0; i < n; i++){
  	scanf("%d ", &p[i]);
  }
  int pi;
  int count=0;
  int min = p[0];
  for(int i = 0; i < n; i ++){
    if(min >= p[i]) min = p[i];
    if(p[i] == min){
      count ++;
    }
  }
  printf("%d", count);
 return 0;
}

Measured memory_bytes: 896