akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int n, x; cin >> n >> x;
        int ans = 0;
        if (n == 0 && x == 0) return 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) ans++;
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=5005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A,B,C,K;cin>>A>>B>>C>>K;
    int ans=0;
    ans+=min(A,K);
    K-=min(A,K);
    K-=min(B,K);
    ans-=min(C,K);
    
    cout<<ans<<endl;
}



Measured memory_bytes: 3652
#include<iostream>
#include<iomanip>
#include<memory>
#include<array>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

double rad( double x )
{
  return x * 3.14159265358979 / 180;
}

int main()
{
  double r, t, g, x, y;
  char c;
  x = y = 0;
  g = 90;

  while( cin >> r >> c >> t )
    {
      x += r * cos( rad( g ) );
      y += r * sin( rad( g ) );
      g -= t;
    }

  cout << trunc(x) << endl;
  cout << trunc(y) << endl;
  
  return 0;
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    if(n==0){
        cout<<0<<endl;
        return 0;
    }
    ll now=33;
    vector<ll>ma(33),mi(33);
    ma[0]=1;
    mi[1]=-2;
    ma[1]=1;
    REP(i,2,33){
        if(i%2==0){
            ma[i]=ma[i-1]+(1LL<<i);
            mi[i]=mi[i-1];
        }else{
            mi[i]=mi[i-1]-(1LL<<i);
            ma[i]=ma[i-1];
        }
        //cout<<i<<' '<<ma[i]<<' '<<mi[i]<<endl;
    }
    string s="";
    while(now>0){
        ll k=(1LL<<now);
        if(now%2)k=-k;
        if(n>=mi[now-1]&&n<=ma[now-1]){
            s+='0';
        }else{
            n-=k;
            s+='1';
        }
        now--;
        //cout<<now<<' '<<n<<endl;
    }
    if(n==1){
        s+='1';
    }else{
        s+='0';
    }
    bool f=0;
    rep(i,s.size()){
        if(f)cout<<s[i];
        else{
            f=(s[i]=='1');
            if(f)cout<<s[i];
        }
    }
    cout<<endl;
}

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

int main() {
	// your code goes here
	string s;
	cin>>s;
	if(s[0]=='R' && s[1]=='R' && s[2]=='R')
	   cout<<3<<endl;
	else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R'))   
	   cout<<2<<endl;
	else if(s[0]=='R' || s[1]=='R' || s[2]=='R')   
	   cout<<1<<endl;
	else
	   cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 3620
n, m = map(int, input().split())
swi = []
for _ in range(m):
    k, *sss = list(map(int, input().split()))
    t = 0
    for s in sss:
        t += 1 << (s - 1)
    swi.append(t)
ppp = list(map(int, input().split()))

ans = 0
for i in range(1 << n):
    for s, p in zip(swi, ppp):
        t = i & s
        c = bin(t).count('1') % 2
        if c != p:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	double x[N], y[N], ans = 0, k = 1;
	int runs[N];
	for (int i = 0; i < N; ++i) runs[i] = i;
	for (int i = 0; i < N; ++i) scanf("%lf %lf", &x[i], &y[i]);
	for (int i = 1; i < N; ++i) ans += sqrt((x[i] - x[i - 1]) * (x[i] - x[i - 1]) + (y[i] - y[i - 1]) * (y[i] - y[i - 1]));
	while (next_permutation(runs, runs + N)) {
		for (int i = 1; i < N; ++i) ans += sqrt((x[runs[i]] - x[runs[i - 1]]) * (x[runs[i]] - x[runs[i - 1]]) + (y[runs[i]] - y[runs[i - 1]]) * (y[runs[i]] - y[runs[i - 1]]));
		++k;
	}
	printf("%.9lf", ans / k);
	return 0;
}

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

typedef pair<int,int> P;
typedef pair<int, P> pp;
struct edge{P to; int cost;};

int N, M;
map<P, vector<edge>> G;
map<P, int> d;

void dijkstra(int s) {
    priority_queue<pp, vector<pp>, greater<pp> > que;
    d[P(s, 0)] = 0;
    que.push(pp(0, P(s, 0)));

    while(!que.empty()) {
        pp p = que.top(); que.pop();
        P v = p.second;
        if(d[v] < p.first) continue;
        for(edge e : G[v]) {
            if(d.find(e.to) == end(d) || d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pp(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> N >> M;
    for(int i=0; i<M; ++i) {
        int p, q, c;
        cin >> p >> q >> c;
        --p; --q;
        if(G.find(P(p, c)) == end(G)) {
            G[P(p, 0)].push_back({P(p, c), 1});
            G[P(p, c)].push_back({P(p, 0), 1});
        }
        if(G.find(P(q, c)) == end(G)) {
            G[P(q, 0)].push_back({P(q, c), 1});
            G[P(q, c)].push_back({P(q, 0), 1});
        }
        G[P(p, c)].push_back({P(q, c), 0});
        G[P(q, c)].push_back({P(p, c), 0});
    }

    dijkstra(0);
    if(d.find(P(N - 1, 0)) == end(d)) cout << -1 << endl;
    else cout << d[P(N - 1, 0)] / 2 << endl;
}

Measured memory_bytes: 91572
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#define ll long long
#define inf 20021225
#define ull unsigned long long
#define bs 31
#define N 200010
#define mp make_pair
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int n; char ch[1000100];
struct node{int son[26],fa,c[26];}t[1000100];
int tot=1,rt=1,ed[N],Len[N];
int insert(char *s,int len)
{
	int pos=rt;
	for(int i=1;i<=len;i++)
	{
		if(!t[pos].son[ch[i]-'a'])	t[pos].son[ch[i]-'a']=++tot,t[tot].fa=pos;
		pos=t[pos].son[ch[i]-'a'];
	}
	int rem=pos;
	int st=0;
	for(int i=len;i;i--)
	{
		st|=1<<s[i]-'a'; pos=t[pos].fa;
		for(int c=0;c<26;c++)	if(st>>c&1)	t[pos].c[c]++;
	}
	return rem;
}
int cc[N];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		scanf("%s",ch+1); Len[i]=strlen(ch+1); reverse(ch+1,ch+Len[i]+1);
		ed[i]=insert(ch,Len[i]); cc[i]=ch[Len[i]]-'a';
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		int pos=ed[i]; pos=t[pos].fa; ans+=t[pos].c[cc[i]];
	}
	printf("%lld\n",ans-n);
	return 0;
}


Measured memory_bytes: 210464
import math

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def factorize(n):
    primes = set()
    for p in Ps:
        if p * p > n:
            break
        while n % p == 0:
            n //= p
            primes.add(p)
    if n > 1:
        primes.add(n)
    return primes

Ps = primes(10 ** 6)
n = int(input())
As = list(map(int, input().split()))

# setwiseFlag
gcd = As[0]
for a in As:
  gcd = math.gcd(gcd, a)
setwiseFlag = (gcd == 1)

# pairwiseFlag
pairwiseFlag = True
target = set()
for a in As:
  primes = factorize(a)
  if len(primes & target) > 0:
    pairwiseFlag = False
  target |= primes

if pairwiseFlag:
  print('pairwise coprime')
elif setwiseFlag:
  print('setwise coprime')
else:
  print('not coprime')


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

using namespace std;

int main()
{
    int n,t;
    cin >> n >> t;
    int cost = INT_MAX;
    for(int i= 0;i<n;i++)
    {
        int a,b;
        cin >> a>> b;
        if(b <= t)
        {
            cost = min(cost, a);
        }
    }
    if(cost == INT_MAX)
    {
        cout << "TLE";
    }
    else
    {
        cout << cost;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){

    int num;
    int max,min;
    int n;
    int i;

    max = -1000000000;


    scanf("%d",&num);
    scanf("%d",&min);

    for( i = 1 ; i < num ; i++ ){

      scanf("%d",&n);

      if( max < n-min )
        max = n-min;

      if( min > n )
        min = n;

    }

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


    return 0;

}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr ll mod998=998244353;

int N,A[100001];
ll M[100002];
ll res;


int main(){
	cin>>N;
	for(int i=0;i<=N;i++){
		cin>>A[i];
		M[i]=A[i];
	}
	for(int i=N-1;i>=0;i--){
		M[i]+=M[i+1];
	}
	ll t=1;
	for(int i=0;i<=N;i++){
		t=min(t,M[i]);
		res+=t;
		t-=A[i];
		if(t<0){
			puts("-1");
			return 0;
		}
		t*=2;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 4792
# ABC084 C - Not so Diverse
import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))

c = collections.Counter(A)
c.most_common()
values, counts = zip(*c.most_common())
L = list(counts)
L.sort()

ans = 0

for i in range(len(c)-K):
    ans += L[i]

if len(c) <= K:
    print(0)
else:
    print(ans)


Measured memory_bytes: 53680
#include <iostream>
#include <cstring>


using namespace std;


int cards[51];
int N;

//  use cards upto, left, sum
unsigned long dp[51][51][50*50+1];
int main(void)
{
    int A;
    int N;

    cin >> N >> A;

    memset(dp, 0, sizeof(dp));

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

    for (int j = 0; j <= N; j++) {
        for (int k = 0; k <= N; k++) {
            for (int s = 0; s <= 50 * 50; s++) {
                if (j == 0 && k ==0 && s == 0) {
                    dp[j][k][s] = 1;
                } else if (s < cards[j] && j > 0) {
                    dp[j][k][s] = dp[j - 1][k][s];
                } else if (s >= cards[j] && k > 0 && j > 0) {
                    dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - cards[j]];
                } else {
                    dp[j][k][s] = 0;
                }
            }
        }
    }

    unsigned long ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += dp[N][i][i * A];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 51072
#include <stdio.h>          // printf(), fprintf(), scanf()
#include <stdlib.h>         // exit()
#include <string.h>         // strlen(), strcpy()

#define QUE_SIZE 80000
#define L_STRINGS 500000

typedef struct que_tbl
{
	const char* name;
	int time;
} que_t;

int que_in;
int que_out;
que_t queue[QUE_SIZE];
char strings[L_STRINGS];
int ix;

void
cleanup(int ecode)
{
	exit(ecode);
}

int
que_size()
{
	if (que_in >= que_out)
		return que_in - que_out;

	return que_in + QUE_SIZE - que_out;
}

void
que_push(que_t* que)
{
	queue[que_in].name = que->name;
	queue[que_in].time = que->time;
	que_in++;
	if (que_in >= QUE_SIZE)
		que_in = 0;

	if (que_in == que_out)
	{
		fprintf(stderr, "Queue area overflow. size:%d\n", QUE_SIZE);
		cleanup(1);
	}
}

void
que_pop()
{
	if (que_out != que_in)
	{
		que_out++;
		if (que_out >= QUE_SIZE)
			que_out = 0;
	}
}

void
que_front(que_t* que)
{
	que->name = queue[que_out].name;
	que->time = queue[que_out].time;
}

int
main(int argc, char** argv)
{
	char name[11];
	int time;
	que_t que;
	int q;
	int n, i;
	char* s;
	int t;

	ix = 0;
	que_in = 0;
	que_out = 0;

	scanf("%d %d", &n, &q);
	for (i = 0; i < n; ++i)
	{
		scanf("%s %d", name, &t);
		s = &strings[ix];
		strcpy(s, name);
		ix += strlen(name) + 1;

		que.name = s;
		que.time = t;
		que_push(&que);
	}

	time = 0;
	while (que_size() > 0)
	{
		que_front(&que); que_pop();
		if (que.time <= q)
		{
			time += que.time;
			printf("%s %d\n", que.name, time);
		}
		else
		{
			que.time -= q;
			time += q;
			que_push(&que);
		}
	}

	return 0;
}

Measured memory_bytes: 2192
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define translow transform(s.begin(),s.end(),s.begin(),::tolower);
#define transup transform(s.begin(),s.end(),s.begin(),::toupper);
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;
 
 
int main() {
                fast
                // #ifndef ONLINE_JUDGE
                // freopen("input.txt","r",stdin);
                // freopen("output.txt","w",stdout);
                // #endif
                   ll n;
                   cin>>n;
                   ll ans =1000*(n/500);
                   n%=500;
                   ans+=5*(n/5);
                   cout<<ans;

                return 0;
            }

Measured memory_bytes: 256
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
#include<cmath>
using namespace std;
bool ys(int n){
	int sum=0;
	for(int i=1;i<=n;i++)
		if(n%i==0)
			sum++;
	return sum==8;
}
int main(){
	int n,s=0;
	cin>>n;
	for(int i=1;i<=n;i+=2)
		s+=ys(i);
	cout<<s;
	return 0;
}

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

typedef long long ll;

int n,x[15],y[15],p[15],D[15],d[15];
ll ans[16];

int main(){

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

    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>p[i];
    memset(ans,0x3f,sizeof(ans));
    ans[0]=0;
    for(int i=0;i<n;i++){
        D[i]=min(abs(x[i]),abs(y[i]));
        ans[0]+=(ll)p[i]*D[i];
    }
    for(int s=0;s<1<<n;s++){
        for(int t=s;t;t=(t-1)&s){
            memcpy(d,D,sizeof(d));
            for(int i=0;i<n;i++){
                if(s>>i&1){
                    if(t>>i&1){
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(x[i]-x[j]));
                        }
                    }else{
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(y[i]-y[j]));
                        }
                    }
                }
            }
            ll cur=0;
            for(int i=0;i<n;i++){
                cur+=(ll)d[i]*p[i];
            }
            ans[__builtin_popcount(s)]=min(ans[__builtin_popcount(s)],cur);
        }
        {
            int t=0;
            memcpy(d,D,sizeof(d));
            for(int i=0;i<n;i++){
                if(s>>i&1){
                    if(t>>i&1){
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(x[i]-x[j]));
                        }
                    }else{
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(y[i]-y[j]));
                        }
                    }
                }
            }
            ll cur=0;
            for(int i=0;i<n;i++){
                cur+=(ll)d[i]*p[i];
            }
            ans[__builtin_popcount(s)]=min(ans[__builtin_popcount(s)],cur);
        }
    }
    for(int i=0;i<=n;i++)cout<<ans[i]<<'\n';

    return 0;
}

Measured memory_bytes: 3584
N, K = map(int, input().split())

count = 0
for m in range(K, N+2):
    #print(N, m)
    ans = m * N - (m * (m - 1) - 1)
    #print(ans)
    if ans > 0:
        count += ans

print(count % (10**9+7))

Measured memory_bytes: 9176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 3011

int n, i, x, y;
int a[maxN];
vector<int> list[maxN];
int st[maxN];

void dfs(int node, int root) {
    st[node] = 0;
    for (auto to : list[node]) {
        if (to == root) continue;
        dfs(to, node);

        if (st[to] == 0 && a[node] > a[to])
            st[node] = 1;
    }
}

int main()
{
 //   freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (i = 1; i < n; i++) {
        scanf("%d%d", &x, &y);
        list[x].pb(y);
        list[y].pb(x);
    }

    for (i = 1; i <= n; i++) {
        dfs(i, 0);
        if (st[i] == 1) printf("%d ", i);
    }



    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl


signed main(void){
    int X,A;
    cin >> X >> A;
    if(X>=A){
        cout << 1;
    }
    cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------
func rev(a []int) []int {
	n := len(a)
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

func main() {
	defer stdout.Flush()
	n, a := readLengthAndSlice()
	c := make([][]int, 2)
	i := 1
	for j := 0; j < n; j++ {
		c[i] = append(c[i], a[j])
		i = 1 - i
	}
	var b []int
	if n%2 == 0 {
		b = rev(c[0])
		b = append(b, c[1]...)
	} else {
		b = rev(c[1])
		b = append(b, c[0]...)
	}
	sp := ""
	for _, v := range b {
		printf("%s%d", sp, v)
		sp = " "
	}
	println()
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int main(){	
  long long n;
  cin >> n;
  for(long long i=1;i<=3500;i++){
  	for(long long j=i;j<=3500;j++){
  	  long long a=4*i*j-n*i-n*j;  	  
  	  if(a>0&&(n*i*j)%a==0){
  	  	long long k=(n*i*j)/a;
  	  	cout << i << ' ' << j << ' ' << k << endl;
  	  	return 0;
  	  }
  	}
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
 vector<int> a(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
   vector<int> b(N);
  for(int i=0;i<N;i++)
    b.at(a.at(i)-1)=i;
  for(int i=0;i<N;i++)
    cout<<b.at(i)+1<<' ';
}

Measured memory_bytes: 4016
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int main(){
    int n,m; cin >> n >> m;
    int ans = 0;
    for(int i = 1 ; i*i <= m ; i++){
        if(m%i == 0 ){
            if(m/i >= n) ans = max(ans,i);
            if(i >= n) ans = max(ans,m/i);
        
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python
"""AtCoder Beginner Contest 169: A - Multiplication 1 
https://atcoder.jp/contests/abc169/tasks/abc169_a
"""

__author__ = 'bugttle <bugttle@gmail.com>'


def main():
    A, B = list(map(int, input().split()))
    print(A * B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
use proconio::*;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    };

    let mut money = 1000;
    for i in 0..a.len() - 1 {
        let mut stock = 0;
        if a[i] < a[i + 1] {
            stock += money / a[i];
            money %= a[i];
            money += a[i + 1] * stock;
        }
    }

    println!("{}", money);
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000001
#define r(i,a,b)    for(i=a;i<b;i++)
#define ra(i,a,b)   for(i=a;i<=b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ss          set<ll int>
using namespace std;
 
#define N 1000000
#define M 100000000

struct unit {
  ll int a[N];  
};

ll fact (ll int x)
{if(x==1 || x==0)return 1;
else return x*fact(x-1);}

ll power(ll int x,ll int n)
{if(n==0)return 1;
else if(n%2 == 0)return power(x*x,n/2);
else return x*power(x*x,(n-1)/2);}

bool cmp (const pii&a,const pii&b)
{ return((a.F-a.S) > (b.F-b.S));
/*if(a.S<=b.S){if(a.S==b.S)return a.F<b.F;else return a.S<b.S;}
else return a.S<b.S;*/}


int main()
{
    cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
    ll i,j,k,l,m,n;
    cin>>n;
    k=n%10;
    if(k==2||k==4||k==9||k==5||k==7)
    cout<<"hon";
    else
    if(k==0||k==1||k==6||k==8)
    cout<<"pon";
    else
    if(k==3)
    cout<<"bon";
}



Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

ll INF = (ll) 1e20;
int iINF = (int) 1e20;
ll mod = (ll) 1e9 + 7;
ll mod2 = (ll) 1e9 + 9;

signed main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    if(n < 3200) {
        puts("red");
    }
    else {
        cout << s;
    }
}



Measured memory_bytes: 256
from collections import deque

def main():
    N = int(input())
    path = [[] for _ in range(N)]
    ab = []
    ans = {}
    visited = [False] * N
    visited[0] = True
    for _ in range(N-1):
        a, b = map(int, input().split())
        path[a-1].append(b-1)
        ab.append((a-1, b-1))
    
    que = deque([(0, 0)])
    while que:
        k = 1
        pre, c = que.popleft()
        for node in path[pre]:
            if visited[node]:
                continue
            if c == k:
                k += 1
            visited[node] = True
            ans[(pre, node)] = k
            que.append((node, k))
            k += 1

    print(max(ans.values()))
    print('\n'.join([str(ans[key]) for key in ab]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 49444
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,X = LI()
CA = np.array([LI() for _ in range(N)])
ans = float('INF')
for i in range(2**N):
    bit = np.array([[i>>j&1 for j in range(N)]]).T
    t = np.sum(CA*bit,axis=0)
    if np.all(t[1:]>=X):
        ans = min(ans,t[0])
print(ans if ans !=float('INF') else -1)

Measured memory_bytes: 27372
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger a = scanner.nextBigInteger();
		BigInteger b = scanner.nextBigInteger();
		
		BigInteger modValue = a.mod(b);
		
		BigInteger res1 = modValue.subtract(b).abs();
		
		if (res1.compareTo(modValue) == -1) {
			System.out.println(res1);
		} else {
			System.out.println(modValue);
		}
	}

}


Measured memory_bytes: 27176
import java.util.Scanner;

class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner (System.in);
		final int n = scan.nextInt();
		scan.close();
		
		printCoordinate (0.0, 0.0);
		kock (n, 0.0, 0.0, 100.0, 0.0);
		printCoordinate (100.0, 0.0);
		
	}
	
	static void kock (int n, double p1_x, double p1_y , double p2_x, double p2_y) {
		
		if (n == 0) return;
		
		double s_x = (2 * p1_x + 1 * p2_x) / 3;
		double s_y = (2 * p1_y + 1 * p2_y) / 3;
		
		double t_x = (1 * p1_x + 2 * p2_x) / 3;
		double t_y = (1 * p1_y + 2 * p2_y) / 3;
		
		double u_x = (t_x - s_x) * Math.cos(60 * (Math.PI / 180))
				- (t_y - s_y) * Math.sin(60 * (Math.PI / 180)) + s_x;
		double u_y = (t_x - s_x) * Math.sin(60 * (Math.PI / 180))
				+ (t_y - s_y) * Math.cos(60 * (Math.PI / 180)) + s_y;
				
		kock ( n - 1, p1_x, p1_y, s_x, s_y);
		printCoordinate (s_x, s_y);
		
		kock ( n - 1, s_x, s_y, u_x, u_y);
		printCoordinate (u_x, u_y);
		
		kock (n - 1, u_x, u_y, t_x, t_y);
		printCoordinate (t_x, t_y);
		
		kock ( n - 1, t_x, t_y, p2_x, p2_y);
		
		
	}
	
	static void printCoordinate (double x, double y) {
		System.out.println (x + " " + y);
	}
}



Measured memory_bytes: 32200
use proconio::input;
use std::collections::HashMap;
use std::cmp::max;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize,
        a: [usize; n],
        b: [usize; m],
    }

    let mut a_sum: Vec<usize> = vec![];
    let mut b_sum: Vec<usize> = vec![];
    a_sum.push(0);
    b_sum.push(0);
    for i in 0 .. n {
        a_sum.push(a_sum[i] + a[i]);
    }
    for i in 0 .. m {
        b_sum.push(b_sum[i] + b[i]);
    }

    let mut ans = 0;
    for i in 0 .. n + 1 {
        let mut sum = a_sum[i];
        if sum > k { break }
        let mut ok: i64 = -1;
        let mut ng: i64 = (m + 1) as i64;
        while (ok - ng).abs() > 1 {
            let mid = (ok + ng) / 2;
            if sum + b_sum[mid as usize] <= k {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ans = max(ans, i + ok as usize);
    }

    println!("{}", ans);


}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<char, int>;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, M;
int K[31];
int A[31][31];
set<int> like[31];

int main(){

    cin >> N >> M;
    for(int i = 0; i < N; i++){
        cin >> K[i];
        for(int j = 0; j < K[i]; j++){
            cin >> A[i][j];
            like[A[i][j]].insert(i);
        }
    }
    int cnt = 0;
    for(int i = 1; i <= M; i++){
        if((int)like[i].size() == N) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun Int.bit(i: Int) = 1 shl i and this > 0

fun main(A: Array<String>) {
    val s = Scanner(System.`in`)
    val n = s.nextInt()
    if (n > 24) {
        println(0)
        return
    }
    val a = IntArray(n) { Integer.parseInt(s.next()) }
    val b = BitSet(25)
    b.set(0)
    b.set(24)

    var r = 0
    outer@ for (f in 0..(1 shl n)) {
        b.clear(1, 24)
        for (i in 0 until n) {
            val j = if (1 shl i and f > 0) 24 - a[i] else a[i]
            if (b[j])
                continue@outer
            b.set(j)
        }
        var q = 24
        var i = 24
        while (i > 0) {
            val j = b.previousSetBit(i - 1)
            q = Math.min(q, i - j)
            i = j
        }
        r = Math.max(r, q)
    }
    println(r)
}


Measured memory_bytes: 111964
combination=list()
counter=0
garbage=0
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        for i in range(len(combination)):
            print(combination[i])
        break
    else:
        for i in range(1,n+1):
            for j in range(1,n+1):
                for k in range(1,n+1):
                    if i+j+k==x:
                        if i>=j or j>=k or i>=k:
                            garbage+=1
                        else:
                            counter+=1
        combination.append(counter)
        counter=0



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

#define _USE_MATH_DEFINES
#define reb(i,b,n)         for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n)           reb(i,0,n)
#define each(it,v)         for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v)        for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vsort(v)           sort((x).begin(), (x).end()
#define rvsort(v)          sort((x).rbegin(), (x).rend()
#define mp(a, b)           make_pair(a, b)
#define fi                 first
#define se                 second
#define pb                 push_back
#define dbg(x)             cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;
#define dbgArr(table, n)   rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define dbg2Arr(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}

using namespace std; using std::stringstream;

typedef long long       ll; typedef unsigned long long ull; typedef long double     ld;
typedef pair <int, int> P;  typedef pair <int, P>      PP;
typedef vector<int>     vi; typedef vector<vi>         vvi; typedef vector<ll>      vl;
typedef vector<P >      vP; typedef vector<char>       vc;  typedef vector<string>  vs;

static const int    INF  = 0x3f3f3f3f;
static const ll     INFL = 0x3f3f3f3f3f3f3f3fLL;
static const double EPS  = 1e-9;
static const ll     MOD  = 1000000007LL;

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

int main(int argc, char *argv[])
{
    ll N, M;
    cin >> N >> M;

    vl H(N);
    rep(i, N) { cin >> H[i]; }

    vvi g(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;b--;

        g[a].pb(b);
        g[b].pb(a);
    }

    int ans=0;
    rep(i, N) {
        bool is_good = true;
        rep(j, g[i].size()) {
            if (H[g[i][j]] >= H[i]) is_good = false;
        }
        if (is_good) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8984
N = int(input())
S = list(map(int, list(input())))
ans = 0

for i in range(10):
    first = False
    second = False
    for j in range(N):
        if not first:
            if S[j] == 0:
                first = True
                continue
        elif not second:
            if S[j] == 0:
                second = True
                continue
        else:
            if S[j] == i:
                ans += 1
                break

for i in range(10, 100):
    first = False
    second = False
    second_v = i // 10
    third_v = i % 10
    for j in range(N):
        if not first:
            if S[j] == 0:
                first = True
                continue
        elif not second:
            if S[j] == second_v:
                second = True
                continue
        else:
            if S[j] == third_v:
                ans += 1
                break

for i in range(100, 1000):
    first = False
    second = False
    first_v = i // 100
    second_v = i // 10 % 10
    third_v = i % 10
    for j in range(N):
        if not first:
            if S[j] == first_v:
                first = True
                continue
        elif not second:
            if S[j] == second_v:
                second = True
                continue
        else:
            if S[j] == third_v:
                ans += 1
                break

print(ans)


Measured memory_bytes: 45788
N = int(input())
A = list(map(int, input().split()))
s = 0
p = 0
m = 1000000001
for i in A:
    s += abs(i)
    if i <=0:
        p += 1
    m = min(m, abs(i))
if p % 2 == 1:
    s = s - 2 * m
print(s)

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

namespace ConsoleApp1
{
    static class ANovember30
    {
        static void Main(string[] args)
        {
            var m1d1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var m2d2 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            int m1 = m1d1[0];
            int d1 = m1d1[1];
            int m2 = m2d2[0];
            int d2 = m2d2[1];

            Console.WriteLine(m1 == m2 ? "0" :"1");
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13268
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n;
	while (n = in()) {
		vector<vector<ll>>mag(n, vector<ll>(n, 0));
		ll x = n / 2 - 1, y = n / 2;
		REP1(i, n * n) {
			x++; x %= n;
			y++; y %= n;
			while (mag[y][x] != 0) {
				x += n - 1; x %= n;
				y++; y %= n;
			}
			mag[y][x] = i;
		}
		REP(i, n) {
			REP(j, n) {
				printf("%4lld", mag[i][j]);
			}
			cout << endl;
		}
	}
}


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

int gcd(int a, int b){
    if (b == 0) return a;
    return gcd(b, a%b);
}

int main(){
    int N, A[100010], L[100010], R[100010];
    cin >> N;
    for (int i = 1; i <= N; ++i){
        cin >> A[i];
    }
    L[0] = 0;
    for (int i = 1; i <= N; ++i){
        L[i] = gcd(L[i-1], A[i]);
    }
    
    R[N+1] = 0;
    for (int i = N; i >= 1 ; --i){
        R[i] = gcd(R[i+1], A[i]);
    }
    
    int ans = 0;
    for (int i = 1; i <= N; ++i){
        ans = max(ans, gcd(L[i-1], R[i+1]));
    }
    cout << ans << endl;    
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> store,ans;
    int N,stick,count=0;
    cin>>N;
    if(N<4||N>100000)return 0;
    for(int i=0;i<N;i++)
    {
        cin>>stick;
        store.push_back(stick);
        if(stick<1||stick>1000000000)return 0;
    }
    sort(store.begin(),store.end());
    reverse(store.begin(),store.end());
    for(int i=0;count<2&&i<N-1;i++)
    {
        if(store[i]==store[i+1])
        {
            count++;
            ans.push_back(store[i]);
            i++;
        }
    }
    if(count==2)
        cout<<(long long int)ans[0]*ans[1];
    else
        cout<<'0';
    return 0;
}

Measured memory_bytes: 892
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[51000];
int e[51000];
int f[51000];
int row[51000];
int col[51000];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		for(int i=0;i<a;i++)row[i]=1;
		for(int j=0;j<b;j++)col[j]=1;
		for(int i=0;i<c;i++)scanf("%d%d%d",d+i,e+i,f+i);
		int R=a;
		int C=b;
		long long ret=0;
		for(int i=c-1;i>=0;i--){
			if(d[i]){
				if(!col[e[i]])continue;
				col[e[i]]=0;
				C--;
				if(f[i])ret+=R;
			}else{
				if(!row[e[i]])continue;
				row[e[i]]=0;
				R--;
				if(f[i])ret+=C;
			}
		}
		printf("%lld\n",ret);
	}
}

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

int main(){
  ll n,m;
  cin >> n >> m;
  if(n==m){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,x;
	for(a=1;a<=9;a++){
		for(b=1;b<=9;b++){
			c=a*b;
		printf("%dx%d=%d\n",a,b,c);
			}
		}
	return 0;
}


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

int main()
{
    int a, b;
    int sum = 1;
    cin >> a >> b;
    if (b == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    rep(i, 50000)
    {
        sum += a - 1;
        if (sum >= b)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

void chmax(long &target, long const &value) {
  if (target < value) {
    target = value;
  }
}

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

  string s, t;
  cin >> s >> t;

  vector<vector<long>> chars_index(26);
  for (size_t i = 0; i < s.size(); ++i) {
    chars_index[s[i] - 'a'].push_back(i + 1); // 1 始まりにしておく
  }

  size_t result = 0, last = 0;

  for (size_t i = 0; i < t.size(); ++i) {
    char t_i = t[i];
    auto &chars = chars_index[t_i - 'a'];

    if (chars.empty()) { // t の文字が s に含まれていないので
      cout << "-1\n";
      return 0;
    }
    auto next = upper_bound(chars.begin(), chars.end(), last);
    if (next == chars.end()) { // 今のループにはもうないので
      result += s.size();      // 次のループへ
      next = chars.begin();
    }
    last = *next;
  }
  result += last;
  cout << result << "\n";
}


Measured memory_bytes: 1736
#include <stdio.h>
int main() {
  int apart[4][3][10] = {{{}}};
  int n, a, b, c, d;
  scanf("%d", &n);
  for (int p = 0; p < n; p++) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    apart[a - 1][b - 1][c - 1] += d;
  }   

  
  for (int l = 0; l < 4; l++){
    for (int m = 0; m < 3; m++) {
      for (int n = 0; n < 10; n++) printf(" %d", apart[l][m][n]);
      printf("\n");
    }
    if (l < 3) {
      for (int o = 0; o < 20; o++) printf("#");
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2756
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <iterator>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 100010;
const LL mod = 1e9 + 7;
const LL INF = 100000000000000LL;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define FOR(c,a,b) for(int c=a;c<=b;++c)
const double PI = acos(-1.0);

int solve() {
	int a, b;
	cin >> a >> b;
	if(a > b) {
		cout << a - 1 << endl;
	}
	else cout << a << endl;
	return 0;
}

int main() {
	LL t = 1e18;
	//cin >> t;
	while(t--) {
		if(!solve())break;
	}
	int mark_EOF;
	if(scanf("%d", &mark_EOF) == EOF) return 0;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int Henkan(char *);
int main()
{
  int N,i,j,k,ST,n,NN;
  char S[100],T[100];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s",S,T);
    ST=Henkan(S)+Henkan(T);
    for(j=3;j>=0;j--){
      NN=1;
      for(k=0;k<j;k++)NN*=10;
      N=ST/NN;
      if(N!=0 &&N!=1)printf("%d",N);
      if(j==0 && N!=0)printf("i"); 
      if(j==1 && N!=0)printf("x"); 
      if(j==2 && N!=0)printf("c"); 
      if(j==3 && N!=0)printf("m");
      ST=ST%NN;
    }
    printf("\n");
  }
  return 0;
}

int Henkan(char *ST)
{
  int i,sum=0,S[8]={0,1000,0,100,0,10,0,1};
  for(i=0;i<strlen(ST);i++){
    if(ST[i]=='m'){
      if(ST[i-1]>=49 &&ST[i-1]<=57){
	S[0]=ST[i-1]-'0';
      }
      else S[0]=1;
    }
    if(ST[i]=='c'){
      if(ST[i-1]>=49 &&ST[i-1]<=57){
	S[2]=ST[i-1]-'0';
      }
      else S[2]=1;
    }
    if(ST[i]=='x'){
      if(ST[i-1]>=49 &&ST[i-1]<=57){
	S[4]=ST[i-1]-'0';
      }
      else S[4]=1;
    }
    if(ST[i]=='i'){
      if(ST[i-1]>=49 &&ST[i-1]<=57){
	S[6]=ST[i-1]-'0';
      }
      else S[6]=1;
    }
  }
    
  for(i=0;i<8;i+=2)sum+=(S[i]*S[i+1]);
  return sum;
}
    

Measured memory_bytes: 612
N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = sum(b)
for i in range(N-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]

print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int mini(int h[],int n) {
    int dp[n+1],i,j;
     dp[1] = 0;
     dp[2] = abs(h[1]-h[0]);
    for(i=3;i<=n;i++) {
        dp[i] =  min(dp[i-1] + abs(h[i-2]-h[i-1]),dp[i-2]+abs(h[i-3]-h[i-1]));
    }
    return dp[n];
}
int main() {
     int n;
    cin>>n;
    int a[n],i;
    for(i=0;i<n;i++) {
        cin>>a[i];
    }
    cout<<mini(a,n)<<"\n";
}

Measured memory_bytes: 4272
import sys

MOD = 10 ** 9 + 7


def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


def main():
    input = sys.stdin.buffer.readline
    s = int(input())
    max_m = s // 3
    factorials, invs = prepare(max_m * 5, MOD)
    ans = 0
    for m in range(1, max_m + 1):
        n = s - 3 * m
        ans += factorials[n + m - 1] * invs[n] * invs[m - 1] % MOD
        ans %= MOD
    print(ans % MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9372
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = 0;
        boolean[] isColor = new boolean[8];
        int min = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            a = scanner.nextInt();
            if (a >= 3200){
                count++;
            }else {
                isColor[a/400] = true;
            }
        }
        for (boolean ic:isColor) {
            if (ic){
                min++;
            }
        }
        System.out.println(Math.max(min, 1) + " " + (min+count));

    }
}


Measured memory_bytes: 21588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false;   
    return true; 
} 
int main()
{
	ll x,f=0,p;
	cin>>x;
	for(ll i=x;f=1;i++)
	{
		if(isPrime(i))
		{
			p=i;
			break;
		}
	}
	cout<<p;
}

Measured memory_bytes: 256
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *STOI GDOI APIO CTS NOIP 2019 RP++                        *
 ***********************************************************/
#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) ((x>y)?x:y)
#define Min(x,y) ((x<y)?x:y)
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (int)(1<<30)
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register ll a=b;a<=c;a++)
#define FORD(a,b,c) for (register ll a=b;a>=c;a--)
using namespace std;
inline ll read(){
    ll x=0,f=1;char c;
    for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());return x*f;
}

template<typename T>
inline void write(T a){
    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}

inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//
#define int ll
ll n,ga,sa,ba,gb,sb,bb,ans;
inline void dfs(int d,int a,int g,int s){
	if(d>2){
		if(bb>ba){
			int b=a/ba;
			a-=b*ba;
			ans=Max(ans,g*gb+s*sb+b*bb+a);
		}else ans=Max(ans,g*gb+s*sb+a);
		return;
	}
	if(d==1){
		if(gb>ga){
			FOR(i,0,a/ga)dfs(d+1,a-i*ga,i,0);
		}else dfs(d+1,a,0,0);
	}else{
		if(sb>sa){
			FOR(i,0,a/sa)dfs(d+1,a-i*sa,g,i);
		}else dfs(d+1,a,g,0);
	}
}
signed main(){
    #ifdef _WIN32
        freopen("1.in","r",stdin);
//        freopen("1.out","w",stdout);
        long double be=clock();
    #endif
    n=read(),ga=read(),sa=read(),ba=read(),gb=read(),sb=read(),bb=read(); 
    dfs(1,n,0,0);
    n=ans;swap(ga,gb);swap(sa,sb);swap(ba,bb);
    if(ga<sa)swap(ga,sa),swap(gb,sb);
    if(ga<ba)swap(ga,ba),swap(gb,bb);
    if(sa<ba)swap(sa,ba),swap(sb,bb);
//    writeln(ans);
    dfs(1,n,0,0);
    writeln(ans);
    #ifdef _WIN32
        long double en=clock();
        printf("Time: %.0Lfms",en-be);
        fclose(stdin);fclose(stdout);
    #endif
    return 0;
}


Measured memory_bytes: 256
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import sys
#####################################
n=int(input())
A=INPUT()
s=0
for i in range(n):
    for j in range(i+1,n):
        s+=A[i]*A[j]
print(s)


Measured memory_bytes: 63444