akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
// #define double long double
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N   100005
#define MAX 300005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
//#define endl "\n"
#define inf 1e+15
map<string ,int> m;
set<string> se;
vector<pair<pii,int>> a;
vector<pair<string,int>>v;
bool cmp(pair<pii,int> x,pair<pii,int> y){
	if(x.ff.ff==y.ff.ff)
		return (x.ff.ss>y.ff.ss);
	return (x.ff.ff < y.ff.ff);
}
signed main(){
  fast;
   int n,x,y;
   string s;
   cin>>n;
   for(int i=1;i<=n;i++){
   	  cin>>s>>y;
   	  se.insert(s);
   	  v.pb(mp(s , y));
   }
   int cnt = 1;
  while(se.size()>0){
     s = *se.begin();
     m[s]=cnt;
     cnt++;
     se.erase(se.begin());
  }
  for(int i=0;i<n;i++){
  	 a.pb({{m[v[i].ff] , v[i].ss} , i+1});
  }
  sort(a.begin(),a.end(),cmp);
  for(int i=0;i<n;i++)
  	cout<<a[i].ss<<endl;
}
  


Measured memory_bytes: 256
import sys

N, M = [int(x) for x in input().split()]
nums = list(set([int(x) for x in input().split()]))

if not nums:
    print(0)
    sys.exit()

if N >= M:
    print(0)
    sys.exit()

nums.sort()

rank = [(abs(nums[i] - nums[i-1]), (i-1, i)) for i in range(1, len(nums))]
rank = sorted(rank, reverse=True)[:N-1]

pos = [0] + [pos[1] for dis, pos in rank]
pos.sort()
ans = 0
for i in range(len(pos)):
    if i == len(pos)-1:
        ans += abs(nums[pos[i]] - nums[-1])
    else:
        ans += abs(nums[pos[i]] - nums[pos[i+1]-1])

print(ans)




Measured memory_bytes: 28128
N, = map(int, input().split())
R = [0] * (N**2+1)
V = [0] * (N**2+1)
X = list(map(int, input().split()))
for ai in range(N**2):
    i, j = divmod(ai, N)
    R[ai+1] = min([i, N-i-1, j, N-j-1])
r = 0
for a in X:
    r += R[a]
    V[a] = 1
    stack=[a]
    while stack:
        v = stack.pop()
        if v>N and (R[v]<R[v-N] and (V[v] or R[v]+1<R[v-N])):
            R[v-N] -= 1
            stack.append(v-N)
        if v<N**2+1-N and (R[v]<R[v+N] and (V[v] or R[v]+1<R[v+N])):
            R[v+N] -= 1
            stack.append(v+N)
        if v%N and (R[v]<R[v+1] and (V[v] or R[v]+1<R[v+1])):
            R[v+1] -= 1
            stack.append(v+1)
        if v%N-1 and (R[v]<R[v-1] and (V[v] or R[v]+1<R[v-1])):
            R[v-1] -= 1
            stack.append(v-1)
print(r)


Measured memory_bytes: 158944
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = Long.MAX_VALUE;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n   = in.nextInt();
        int m   = in.nextInt();
        List<E> edges = new ArrayList<>();
        for(int i = 0; i < m; i++) {
            int a = in.nextInt()-1;
            int b = in.nextInt()-1;
            long c = -in.nextInt();
            E e = new E(a, b, c);
            edges.add(e);
        }

        long[] dist = new long[n];
        Arrays.fill(dist, inf);
        dist[0] = 0;
        for(int i = 0; i < n-1; i++) {
            for(E e : edges) {
                if(dist[e.from] != inf && dist[e.from] + e.w < dist[e.to]) {
                    dist[e.to] = dist[e.from] + e.w;
                }
            }
        }

        long ans = -dist[n-1];

        for(int i = 0; i < n; i++) {
            for(E e : edges) {
                if(dist[e.from] != inf && dist[e.from] + e.w < dist[e.to]) {
                    dist[e.to] = dist[e.from] + e.w;
                }
            }
        }

        if(ans < -dist[n-1]) {
            print("inf");
        }else{
            print(ans);
        }

    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(int i) {
        System.out.println(i);
    }

    static void print(long i) {
        System.out.println(i);
    }
}

class E {
    int from, to;
    long w;
    E(int from, int to, long w) {
        this.from = from;
        this.to = to;
        this.w = w;
    }
}

Measured memory_bytes: 30548
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(n+1):
  dp[i][0]=1
for i in range(m+1):
  dp[0][i]=1
mod=pow(10,9)+7
for i in range(n):
  for j in range(m):
    dp[i+1][j+1]=sum((dp[i][j+1],dp[i+1][j],-dp[i][j]))%mod
    if s[i]==t[j]:dp[i+1][j+1]+=dp[i][j]
    dp[i+1][j+1]%=mod
print(dp[-1][-1])
#print(dp)

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

int main() {
	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	vector<vector<int>> s(d, vector<int>(n));
	rep(i, n) cin >> c[i];
	rep(i, d) rep(j, n) cin >> s[i][j];
	vector<int> t(d), last(n);
	
	ll ans = 0;
	rep(i, d) {
		ll mx = -1001001001;
		int now = 0;
		
		rep(j, n) {
			ll tmp = ans;
			tmp += s[i][j];
			rep(k, n) {
				if(j == k) continue;
				tmp -= c[k] * (i+1-last[k]);
			}
			if(mx < tmp) {
				mx = tmp;
				now = j;
			}
		}
		ans = mx;
		last[now] = i+1;
		t[i] = now+1;
	}
	// int cnt = 0;
	// while(1) {
	// 	cnt++;
	// 	if(cnt > 100000000) break;
	// 	int nd = rand()%d;
	// 	int nq = rand()%n;
	// 	int old = t[nd];
	// 	t[nd] = nq;
		
	// 	vector<int> nlast(n);
	// 	ll now = 0;
	// 	rep(i, d) {
	// 		now += s[i][t[i]];
	// 		nlast[t[i]] = i+1;
	// 		rep(j, n) {
	// 			ans -= c[j] * (i+1-last[j]);
	// 		}
	// 	}
	// }
	
	rep(i, d) printf("%d\n", t[i]);
	return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define in              insert
#define pb              push_back
#define mp              make_pair
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n]
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n, w; cin >> n >> w;

	int wt[n + 1], val[n + 1];
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		cin >> wt[i] >> val[i];
		sum += val[i];
	}

	int dp[n + 1][sum + 1];
	int ans = 0;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= sum; j++) {
			if (j == 0)
				dp[i][j] = 0;
			else if (i == 0)
				dp[i][j] = inf;

			else {
				if (val[i] > j)
					dp[i][j] = dp[i - 1][j];
				else
					dp[i][j] = min(dp[i - 1][j], wt[i] + dp[i - 1][j - val[i]]);
			}
		}
	}

	for (int i = 0; i <= sum; i++)
		if (dp[n][i] <= w)
			ans = max(ans, i);

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main() {

	char c;
	cin >> c;

	if (c =='a' || c =='e'|| c =='i'|| c =='o'  || c =='u'){
		cout << "vowel" << endl;
	}

	else {
		cout << "consonant" << endl;
	
	}

}


Measured memory_bytes: 3612
/// Date:28-May-2018
/// MD:NUR ALAM
#include <bits/stdc++.h>
using namespace std;

int main(){

    int n; cin>>n;
    string s; cin>>s;

	int ans=0;
	for(int i=1;i<n;i++){
		int cnt=0;

		for(char c='a';c<='z';c++){
			bool left=false,right=false;

			for(int j=0;j<i;j++)
				if(s[j]==c)
					left=true;

			for(int j=i;j<n;j++)
				if(s[j]==c)
					right=true;

			if(left&&right)
				cnt++;
		}

		if(ans<cnt)
			ans=cnt;
	}

	cout<<ans<<endl;
}


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

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    if((A<C&&C<B)||(B<C&&C<A)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, k = map(int, input().split())
    dl = set(map(int, input().split()))

    for i in range(n, 100000):
        if i < n:
            continue
        candi = list(map(int, list(str(i))))
        available = True
        for c in candi:
            if c in dl:
                available = False
                break
        if available:
            print(i)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 40940
#include<stdio.h>
using namespace std;
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a,b,c >=1 && a,b,c <=100){
        if((b-a) == (c-b)){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }

   return 0;
}

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

int main() {
  long double a,b,x;
  cin >> a >> b >> x;
  x/=a;
  if(a*b>=2*x){
      long double y=2*x/b;
      long double ans=atan(b/y);
      ans=ans*180/pi;
      cout << fixed << setprecision(10) << ans;
  }
  else{
      long double y=(a*b-x)*2/a;
      long double ans=atan(y/a);
      ans=ans*180/pi;
      cout << fixed << setprecision(10) << ans;
  }
}

Measured memory_bytes: 3848
#include "bits/stdc++.h"
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INF 100000000
typedef long long ll;

using namespace std;


int main()
{
    string str1, str2;
    bool flag = false;
    cin >> str1;
    cin >> str2;
    sort(all(str1));
    sort(all(str2));
    reverse(all(str2));
    REP(i, min(str1.size(),str2.size())) {
        if (str1[i] < str2[i]) {
            flag = true;
            break;
        }
        else if (str1[i] > str2[i]) {
            flag = false;
            break;
        }
        else if (i == min(str1.size(), str2.size())-1) {
            flag = (str1.size() < str2.size() ? true : false);
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int D[3000][3000];
pair<int,int> P[3000][3000];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	string s, t;
	int x, y;
	stack<char> ans;
	cin>>s>>t;
	if(s[0]==t[0]) {
		D[0][0]=1;
	}
	else {
		D[0][0]=0;
	}
	P[0][0]={0,0};
	for(int j=1;j<t.size();j++) {
		if(D[0][j-1]<(s[0]==t[j])) {
			D[0][j]=1;
			P[0][j]={0,j};
		}
		else {
			D[0][j]=D[0][j-1];
			P[0][j]={0,j-1};
		}
	}
	for(int i=1;i<s.size();i++) {
		if(D[i-1][0]<(s[i]==t[0])) {
			D[i][0]=1;
			P[i][0]={i,0};
		}
		else {
			D[i][0]=D[i-1][0];
			P[i][0]={i-1,0};
		}
		for(int j=1;j<t.size();j++) {
			D[i][j]=D[i-1][j];
			P[i][j]={i-1,j};
			if(D[i][j]<D[i][j-1]) {
				D[i][j]=D[i][j-1];
				P[i][j]={i,j-1};
			}
			if(D[i][j]<D[i-1][j-1]+(s[i]==t[j])) {
				D[i][j]=D[i-1][j-1]+(s[i]==t[j]);
				P[i][j]={i-1,j-1};
			}
		}
	}
	x=s.size()-1, y=t.size()-1;
	while(D[x][y]) {
		int nx, ny;
		tie(nx,ny)=P[x][y];
		if(D[x][y]!=D[nx][ny]) {
			ans.push(s[x]);
		}
		if(tie(x,y)==tie(nx,ny)) {
			ans.push(s[x]);
			break;
		}
		tie(x,y)=tie(nx,ny);
	}
	while(!ans.empty()) {
		cout<<ans.top();
		ans.pop();
	}
	return 0;
}

Measured memory_bytes: 105728
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define zero(x) (((x)>0?(x):-(x))<eps)
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int>PII;
typedef pair<int,string>PIS;
const double eps=1e-6;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
//LL powmod(LL a,LL b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int n;
bool ok(int x){
    int m=n;
    if(x>=n) return 1;
    while(m&&x){
        if(m>=x) m-=x;
        x--;
    }
    return m==0;
}
int main(){
//    freopen("in.in","r",stdin);
//    freopen("out.out",";w",stdout);
    cin>>n;
    int l=1,r=44721;
    int ans=44721;
    while(l<=r){
        int m=(l+r)>>1;
        if(ok(m)){
            r=m-1;
            ans=m;
        }
        else l=m+1;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main() {
	// your code goes here
	int n,k;
	cin>>n;
	map<int,int> m;
	for(int i=0;i<n;i++){
	    cin>>k;
	    m[k]=i+1;
	}
	
	for(auto it=m.begin();it!=m.end();it++){
	    cout<<it->second<<' ';
	}
	return 0;
}


Measured memory_bytes: 8268
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

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

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
LL n,x;
VL arr;
VL prr;
LL rec(LL n, LL x){
	if(x == 1)
		return (n == 0) ? 1 : 0;
	if(x > 1 && x <= 1 + arr[n-1])
		return rec(n-1, x-1);
	if(x == 2 + arr[n-1])
		return 1 + prr[n-1];
	if(x > 2 + arr[n-1] && x <= 2 + 2*arr[n-1])
		return 1 + prr[n-1] + rec(n-1, x - 2 - arr[n-1]);
	if(x == 3 + arr[n-1])
		return prr[n];
}
int main() {
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	cin>>n>>x;
	arr.resize(n+1);
	prr.resize(n+1);
	// length of burger of level i
	arr[0] = 1;
	// number of P in burger of level i
	prr[0] = 1;
	rep(i,1,n+1){
		arr[i] = 2*arr[i-1] + 3;
		prr[i] = 2*prr[i-1] + 1;
	}
	cout<<rec(n, x);
  	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int d[5] = {-2,-1,0,1,2};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
int h,w;
int ch,cw,dh,dw;
vector<vector<int>> v(1001,vector<int>(1001,0));
vector<vector<int>> miti(1001,vector<int>(1001,MOD));

int main(){
    cin>>h>>w;
    cin>>ch>>cw>>dh>>dw;
    ch--;cw--;dh--;dw--;
    rep(i,h){
        rep(j,w){
            char s;
            cin>>s;
            if(s=='#')v[i][j]=1;
        }
    }

    miti[ch][cw] = 0;
    deque<P> q;
    q.push_front({ch,cw});
    while(!q.empty()){
        P now = q.front();
        q.pop_front();
        rep(i,4){
            int ny = now.first+dy[i];
            int nx = now.second+dx[i];
            if(ny<0||nx<0||ny>=h||nx>=w||v[ny][nx]!=0)continue;
            if(miti[ny][nx]>miti[now.first][now.second] ){
                miti[ny][nx] = miti[now.first][now.second];
                q.push_front({ny,nx});
            }
        }
        rep(i,5){
            rep(j,5){
                int ny = now.first+d[i];
                int nx = now.second+d[j];
                if(ny<0||nx<0||ny>=h||nx>=w||v[ny][nx]!=0)continue;
                if(miti[ny][nx]>miti[now.first][now.second]+1 ){
                    miti[ny][nx] = miti[now.first][now.second]+1;
                    q.push_back({ny,nx});
                }
            }
        }
    }

//    rep(i,h){
//        rep(j,w){
//            cout<<miti[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    cout<<(miti[dh][dw]==MOD?-1:miti[dh][dw])<<endl;



    return 0;
}


Measured memory_bytes: 11532
#include <cstdio>
#include <algorithm>
using namespace std;
int N, H, a[100001], b[100001], ans;
int main() {
  scanf("%d %d", &N, &H);
  for(int i = 1; i <= N; ++i) {
    scanf("%d %d", &a[i], &b[i]);
  }
  sort(a+1, a+N+1);
  sort(b+1, b+N+1);
  for(int i = N; i > 0; --i) {
    if(b[i] <= a[N]) break;
    H -= b[i]; ++ans;
    if(H <= 0) break;
  }
  if(H > 0) ans += (H+a[N]-1)/a[N];
  printf("%d\n", ans);
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
ll count=0;
  for(ll i=0;i<N;i++) {
ll A,B;
    cin>>A>>B;
    if(A==B) {
count++;
    }
    if(count>2) {
cout<<"Yes"<<endl;
      return 0;
    }
    if(A!=B) {
count=0;
    }
  }
  
  cout<<"No"<<endl;
}
  
  

    
        
        
        
        
        


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll h,w,p,q;cin>>h>>w>>p>>q;
  ll g[h][w];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(i%p==0&&j%q==0)g[i][j]=3000*(p*q-1)-1;
      else g[i][j]=-3000;
      res+=g[i][j];
    }
  }
  if(res<=0)cout<<"No"<<endl;
  else{
    cout<<"Yes"<<endl;
    for(i=0;i<h;i++){
      cout<<g[i][0];
      for(j=1;j<w;j++){
        cout spa g[i][j];
      }
      cout<<endl;
    }
  }


  return 0;
}

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

int main()
{
    int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
    vector<vector<double>> mp(31,vector<double>(1501,-1));
    int i,j,k;
    for(i=0;i<=1500;i++)
    {
        for(j=0;j<=1500;j++)
        {
            if(i*c+j*d<=1500)mp.at(0).at(i*c+j*d)=0;
        }
    }
    for(k=0;k<=1500;k++)
    {
        for(i=0;i<=30;i++)
        {
            for(j=0;j<=30;j++)
            {
                if(mp.at(0).at(k)>=-0.5&&(i*a+j*b)*100+k<=f&&k<=(i*a+j*b)*e&&(i+j)>=1)
                {
                    mp.at(i*a+j*b).at(k)=(double)(100*k)/((i*a+j*b)*100+k);
                }
            }
        }
    }
    int maxx,maxy;
    double maxvalue=-0.5;
    for(i=0;i<=30;i++)
    {
        for(j=0;j<=1500;j++)
        {
            if(mp.at(i).at(j)>maxvalue)
            {
                maxvalue=mp.at(i).at(j);
                maxx=i;
                maxy=j;
            }
        }
    }
    if(maxy==0)maxx=a;
    cout<<maxx*100+maxy<<' '<<maxy<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
using pl = pair<ll,ll>;
#define ci(n,a)   ll a[n]; rep(i,(n)) cin>>a[i];
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define mp(a,b)   make_pair(a,b)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;


int main(int argc,char* argv[]) 
{
    int n,m,c,ans=0;
    cin>>n>>m>>c;
    ci(m,b);
    rep(i,n){
        int a[m],sum=0;
        rep(i,m)cin>>a[i],sum+=a[i]*b[i];
        if(sum+c>0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
M = 1000000007
x = [ 0 for i in range(w)]
x[0] = 1
for i in range(1, w):
    for j in range((1<<i)):
        f = 0
        for l in range(i-1):
            if ((j>>l)&1) == 1 and ((j>>(l+1))&1) == 1:
                f = 1
                break
        if f == 0:
            x[i] += 1
    x[i] %= M
    #print(x[i])

def g(a):
    if a < 0: return 1
    return x[a]

dp = [[0 for j in range(w)] for i in range(h+1)]
dp[0][0] = 1
for i in range(1, h+1):
    for j in range(w):
        dp[i][j]  = dp[i-1][j]   * g(j-1) * g(w-j-2)
        if j-1 >= 0:dp[i][j] += dp[i-1][j-1] * g(j-2) * g(w-j-2)
        if j+1 <  w:dp[i][j] += dp[i-1][j+1] * g(j-1) * g(w-j-3)
        dp[i][j] %= M
        #print(i, j, dp[i][j])

print(dp[h][k-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n; 
int main()
{
    scanf("%d",&n);
    switch(n%10){
    	case 2: 
		case 4:
		case 5:
		case 7:
		case 9:	printf("hon");break;
		case 0:
		case 1:
		case 6:
		case 8:	printf("pon");break;
		case 3:	printf("bon");break;
	}


return 0;
}


Measured memory_bytes: 3824
let () =
  let open Queue in
  let (que : (string * int) Queue.t) = create () in
  let (n, q) = Scanf.scanf "%d %d\n" (fun n q -> (n, q)) in
  for _ = 0 to n - 1 do
    add (Scanf.scanf "%s %d\n" (fun s t -> s, t)) que;
  done;
  let cnt = ref 0 in
  while not (is_empty que) do
    let (s, t) = take que in
    let rest = t - q in
    if rest <= 0 then begin
      cnt := !cnt + t;
      Printf.printf "%s %d\n" s !cnt;
    end else begin
      add (s, rest) que;
      cnt := !cnt + q;
    end
  done

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

#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    bool has_odd = false;
    for (auto _ : irange(0L, n)) {
        int64_t a;
        cin >> a;

        if (a % 2 == 1) {
            has_odd = true;
        }
    }

    if (has_odd) {
        cout << "first" << endl;
    } else {
        cout << "second" << endl;
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int snuke[N] = {0};
  
  int d;
  int A;
  
  for(int i = 0; i < K; i++){
    cin >> d;
    for(int j = 0; j < d; j++){
      cin >> A;
      snuke[A-1] = 1;
    }
  }
  
  int count = 0;
  
  for(int i = 0; i < N; i++){
    if(snuke[i] == 0){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int T;cin>>T;
	while(T--){
		int i,n;cin>>n;
		vector<llint>A(n);
		for(i=0;i<n;i++){cin>>A[i];}
		string S;cin>>S;
		int ans=0;
		vector<llint>aaa;
		for(i=n-1;i>=0;i--){
			if(S[i]=='0'){
				llint B=A[i];
				for(auto it:aaa){chmin(B,it^B);}
				if(B==0){continue;}
				aaa.pub(B);
				SO(aaa);REV(aaa);
			}else{
				llint B=A[i];
				for(auto it:aaa){chmin(B,it^B);}
				
				if(B>0){ans=1;break;}
			}
			
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3136
#include <cstdio>
#include <cstring>
#define MAXN 1000010
bool is_prime[MAXN];
int prime[MAXN];

void find(int n) {
    memset(is_prime,1,sizeof(is_prime));
    is_prime[0]=is_prime[1]=false;
    prime[0]=0;
    for(int i=2;i<=n;i++) {
        if(is_prime[i]) {
            prime[++prime[0]]=i;
            for(int j=2*i;j<=n;j+=i) is_prime[j]=false;

        }
    }
}


int bifind(int n) {
    int b=1,e=prime[0],mid;
    while(b<=e) {
        mid=(b+e)>>1;
        if(n==prime[mid]) return mid;
        //printf("%d %d %d\n",b,mid,e);
        else if(n>prime[mid]) {b=mid+1;}
        else {e=mid-1;}
    }
    return b-1;
}
int main() {
    int n;
    find(999999);
    //printf("%d\n",prime[0]);
    //printa(prime,prime[0]);
    while(scanf("%d",&n)!=EOF) {
         int pos=bifind(n);
         printf("%d\n",pos);
    }
}

Measured memory_bytes: 4172
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
C.count(0)>1 and S.each {|s|
  26.times {|i| if s[i]==0 && i!=(z||=i); s[z]<s[i] ? (s[z]=0; z=i) : (s[i]=0) end }
}
L,M,N = [-1]*27,4,4
def calc(d,n)
  s = S[d]
  t = (0..25).map {s[_1] > 0 ? C[_1]*(d-L[_1])+s[_1] : 0}
  i = (0..25).max_by(M){t[_1]}.max_by {|i|
    next t[i]  if n == 0 || d+1 >= D || t[i] == 0
    l,L[i] = L[i],d
    calc(d+1,n-1)[1].tap {L[i]=l}
  }
  [i, t[i]]
end
D.times { p 1 + i=calc(_1,N)[0]; L[i]=_1 }

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

map<ll,ll>di;


int main()
{
    ll x,y,z;
    cin>>x>>y>>z;
    ll a=x/(y+z);
    if(x-a*(y+z)>=z)cout<<a;
    else cout<<a-1;
}


Measured memory_bytes: 3636
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    h=I()
    w=I()
    n=I()
    ver=0
    hor=0
    ans=0
    while n>0:
        if h-hor>=w-ver:
            n-=(h-hor)
            ver+=1
            ans+=1
        else:
            n-=w-ver
            hor+=1
            ans+=1
    print(ans)



        
        
        
        
        
    
if __name__=="__main__":
    main()



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

int main(){
  int N;
  vector<int64_t> H(100010);
  cin >> N;
  for(int i=0; i<N; i++) cin >> H[i];

  priority_queue<int64_t> q;

  q.push(H[0]);

  for(int i=1; i<N; i++){
    if (H[i] + 1 < q.top()){
      cout << "No" << endl;
      return 0;
    }
    q.push(H[i]);
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define MAX 200000

int main() {
    int N;
    cin >> N;
    vector<int> A(MAX + 1, 0);
    for (int i = 1; i <= N; i++) {
        scanf("%d", &A[i]);
    }

    vector<int> left(MAX + 1, 0);
    vector<int> right(MAX + 1, 0);
    for (int i = 1; i <= N - 1; i++) {
        left[i] = max(left[i - 1], A[i]);
    }
    for (int i = N; i >= 2; i--) {
        right[i] = max(right[i + 1], A[i]);
    }

    for (int i = 1; i <= N; i++) {
        int ans = max(left[i - 1], right[i + 1]);
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	cin >> n;
	while(n--){
		int num[9], red[10] = { 0 }, green[10] = { 0 }, blue[10] = { 0 };
		for(int i = 0; i < 9; ++i){ cin >> num[i]; }
		for(int i = 0; i < 9; ++i){
			string str;
			cin >> str;
			if(str == "R"){
				++red[num[i]];
			}else if(str == "G"){
				++green[num[i]];
			}else if(str == "B"){
				++blue[num[i]];
			}
		}
		int answer = 1;
		for(int i = 1; i <= 7; ++i){
			while(red[i] > 0 && red[i + 1] > 0 && red[i + 2] > 0){
				--red[i]; --red[i + 1]; --red[i + 2];
			}
			while(green[i] > 0 && green[i + 1] > 0 && green[i + 2] > 0){
				--green[i]; --green[i + 1]; --green[i + 2];
			}
			while(blue[i] > 0 && blue[i + 1] > 0 && blue[i + 2] > 0){
				--blue[i]; --blue[i + 1]; --blue[i + 2];
			}
		}
		for(int i = 1; i <= 9; ++i){
			if(red[i] % 3 != 0){ answer = 0; break; }
			if(green[i] % 3 != 0){ answer = 0; break; }
			if(blue[i] % 3 != 0){ answer = 0; break; }
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
int main() {
    ll AA;
    cin>>AA;
	int A,B,C,D;
	A=AA/1000;
	B=(AA/100)%10;
	C=(AA/10)%10;
	D=AA%10;
	int ans=0;
	int q=0,w=0,e=0;
	for(int i=0; i<2; i++){
		for(int j=0; j<2; j++){
			for(int k=0; k<2; k++){
				ans+=A;
				if(i==0){
					ans-=B;
				}
				else{
					ans+=B;
				};
				
				if(j==0){
					ans-=C;
				}
				else{
					ans+=C;
				};
				
				if(k==0){
					ans-=D;
				}
				else{
					ans+=D;
				};
				
				if(ans==7){
				    e=k;
					break;
				}
				else{
					ans=0;
				}
			}
		if(ans==7){
		    w=j;
					break;
		}
		}
	if(ans==7){
	    q=i;
					break;
	}
	}
	cout<<A;;
	if(q==0){
		cout<<'-';
	}
	else{
		cout<<'+';
	};
	cout<<B;
	if(w==0){
		cout<<'-';
	}
	else{
		cout<<'+';
	};
	cout<<C;
	if(e==0){
		cout<<'-';
	}
	else{
		cout<<'+';
	};
	cout<<D<<'='<<7<<endl;

	
}

Measured memory_bytes: 256
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			int[] x = new int[6];
			for(int i=1;i<=5;i++) {
				x[i]=sc.nextInt();
				if(x[i]==0) {
					System.out.println(i);
					return;
				}
			}
			
		}
	}


Measured memory_bytes: 35760
def solve(n):
    for i in range(n + 1):
        if int(i * 1.08) == n:
            return i
    return ":("


def main():
    n = int(input())
    res = solve(n)
    print(res)


def test():
    assert solve(432) == 400
    assert solve(1079) == ":("
    assert solve(1001) == 927


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,n;
    cin>>d >>n;

    if( d == 0) {if(n!=100)cout<<n<<endl;else cout<<n+1<<endl;}
    else if( d == 1) {if(n!=100)cout<<n<<"00"<<endl;else cout<<n+1<<"00"<<endl;}
    else if( d == 2) {if(n!=100)cout<<n<<"0000"<<endl;else cout<<n+1<<"0000"<<endl;}

    return 0;
}


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

long long mod = (1e+9) + 7;

int main() {

    string s;
    cin >> s;

    vector< vector< long long > > dp(s.size() + 1, vector< long long >(13, 0LL));

    dp[0][0] = 1;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '?') {
            for(int j = 0; j < 10; j++) {
                for(int k = 0; k < 13; k++) {
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k] % mod;
                }
            }
        } else {
            for(int j = 0; j < 13; j++) {
                dp[i + 1][(j * 10 + (s[i] - '0')) % 13] += dp[i][j] % mod;
            }
        }
    }
    cout << dp[s.size()][5] % mod << endl;
}


Measured memory_bytes: 13696
use proconio::input;
use std::io::{stdout, BufWriter, Write};

fn main() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    for i in 0..5 {
        input! {x: usize}
        if x == 0 {
            writeln!(out, "{}", i + 1);
        }
    }
}

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

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

const int MAXN = (int) 2e5 + 10;
int n, side[MAXN];
char S[MAXN];
vector<int> pos[26];
II a[MAXN];

void Compress() {
    vector<int> rar[2];
    for (int i = 1; i <= n; ++i)
        if (side[i] > 0) rar[side[i] - 1].push_back(i);
    for (int i = 0; i < 2; ++i) {
        sort(rar[i].begin(), rar[i].end());
        rar[i].resize(unique(rar[i].begin(), rar[i].end()) - rar[i].begin());
    }
    for (int i = 1; i <= n; ++i) {
        if (side[i] == 0) {
            continue;
        }
        int w = side[i] - 1;
        side[i] = lower_bound(rar[w].begin(), rar[w].end(), i) - rar[w].begin() + 1;
    }
}

bool cmp(II a, II b) {
    int fa = min(side[a.first], n / 2 + 1 - side[a.second]);
    int fb = min(side[b.first], n / 2 + 1 - side[b.second]);
    if (fa != fb) return fa < fb;
    fa = max(side[a.first], n / 2 + 1 - side[a.second]);
    fb = max(side[b.first], n / 2 + 1 - side[b.second]);
    return fa < fb;
}

struct FenwickTree {
    int n, ft[MAXN];
    void Init(int _n) {
        n = _n;
        for (int i = 1; i <= n; ++i) ft[i] = 0;
    }
    void Update(int i) {
        while (i > 0) {
            ft[i] += 1;
            i -= i & -i;
        }
    }
    int Query(int i) {
        int ans = 0;
        while (i <= n) {
            ans += ft[i];
            i += i & -i;
        }
        return ans;
    }
} FT[2];

int main() {
    scanf("%s", S + 1);
    n = strlen(S + 1);

    int sum = 0;
    for (int i = 1; i <= n; ++i) pos[S[i] - 'a'].push_back(i);
    for (int i = 0; i < 26; ++i) sum += (int) pos[i].size() % 2;
    if (sum > 1) {
        puts("-1");
        return 0;
    }

    int k = 0;
    for (int i = 0; i < 26; ++i) {
        for (int j = 0; j < (int) pos[i].size() / 2; ++j) {
            int x = pos[i][j];
            int y = pos[i][(int) pos[i].size() - j - 1];
            a[++k] = II(x, y);
            side[x] = 1;
            side[y] = 2;
        }
    }
    Compress();
    sort(a + 1, a + 1 + k, cmp);

    LL ans = 0;
    FT[0].Init(n);
    FT[1].Init(n);
    for (int i = 1; i <= k; ++i) {
        ans += FT[0].Query(a[i].first + 1);
        ans += FT[1].Query(1) - FT[1].Query(a[i].second);
        FT[0].Update(a[i].first);
        FT[1].Update(a[i].second);
    }
    for (int i = 1; i <= k; ++i) ans += FT[0].Query(a[i].second + 1);
    if (n % 2 == 1) {
        int p = -1;
        for (int i = 0; i < 26; ++i) {
            if (pos[i].size() % 2 == 0) continue;
            p = pos[i][(int) pos[i].size() / 2];
        }
        ans += FT[0].Query(p + 1) + FT[1].Query(1) - FT[1].Query(p);
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 5744
/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Hemant Malviya

//It’s just pathetic to give up on something before you even give it a shot.
//Knowing you’re different is only the beginning. If you accept these differences 
you’ll be able to get past them and grow even closer.
//You can die anytime, but living takes true courage.
//Every journey begins with a single step. We just have to have patience.
//Life is not a game of luck. If you wanna win, work hard.
//It’s more important to master the cards you’re holding 
than to complain about the ones your opponent was dealt.
//If you just submit yourself to fate, then that’s the end of it.
//Whatever you do, enjoy it to the fullest. That is the secret of life.
//I too will obtain everything that I desire. Not because someone asked me to do it, 
//but because I know in my heart that I have something worth fighting for.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/   
#include<bits/stdc++.h>
 
#define lld long long int 
#define vint vector<int>
#define vlld vector<long long int>
#define vst vector<string>
#define ps push_back
#define pii pair<int,int>
#define mk make_pair
#define le length
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define sv()                  int t; scanf("%d",&t); while(t--)
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
int main()
{
   int  n;
   cin>>n;
   lld sm=0;
   for( int i =1;i<=n;i++){
       if(i % 3 != 0 && i % 5 != 0){
           sm += i;
           }
   }
   cout<<sm;
 return 0;   
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K;
  cin >> K;
  int sum=0;
  
  for(int i=1;i<=K;i++){
    if(i%2 == 0) continue;
    for(int j=1;j<=K;j++){
      if(j%2 == 1) continue;
      sum++;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
const int MOD = 1e9+7;
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
vector<int> g[10];
vector<bool> vis;
int n,m,ans=0;
void dfs(int u,int cnt)
{
  if(cnt==n){
    ans++;
    return;
  }
  vis[u]=true;
  for(auto it:g[u])
    if(!vis[it])dfs(it,cnt+1);
  vis[u]=false;
}
signed main()
{
    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    int T=1;
    //cin>>T;
    vis.assign(10,false);
    while(T--)
    {
        
        cin>>n>>m;
        for(int i=0;i<m;i++)
        {
          int x,y;
          cin>>x>>y;
          g[x].pb(y);
          g[y].pb(x);

        }
        dfs(1,1);
        cout<<ans<<"\n";
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

vector<int> ans(100100, -1);
vector<int> graph[100100];

int main(){
	int n, m; cin >> n >> m;
	for( int i = 0; i < m; ++i ){
		int a, b; cin >> a >> b;
		--a; --b;
		graph[a].push_back(b), graph[b].push_back(a);
	}
	queue<int> q;
	q.push(0);
	while( !q.empty() ){
		int x = q.front();
		q.pop();
		for( auto next : graph[x] ){
			if( ans[next] == -1 ){
				ans[next] = x;
				q.push(next);
			}
		}
	}
	cout << "Yes" << endl;
	for( int i = 1; i < n; ++i ){
		cout << ans[i]+1 << endl;
	}
}

Measured memory_bytes: 10164
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let s = get!(String);
    let t = get!(String);
    let mut count = 0;
    for (e,f) in s.chars().zip(t.chars()) {
        if e == f {
            count += 1;
        }
    }
    println!("{}", count);
}


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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

ll  f[105][N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    int W;  cin >> W;

    fill(f[0] + 1,f[0] + N,1e18);

    for(int i = 1 ; i <= n ; ++i)   {
        int w;  cin >> w;
        int v;  cin >> v;

        for(int j = 0 ; j < N ; ++j)    f[i][j] = f[i - 1][j];
        for(int j = v ; j < N ; ++j)    f[i][j] = min(f[i][j],f[i - 1][j - v] + w);

        for(int j = N - 1 ; j ; --j)    f[i][j - 1] = min(f[i][j - 1],f[i][j]);
    }
    cout << (upper_bound(f[n],f[n] + N,W) - f[n] - 1) << endl;
}

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

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

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


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, m = MI()
    cities = []
    prefes = [1]*(n+1)
    for i in range(m):
        a, b = MI()
        cities.append([b, a,  i])

    cities.sort()

    for i in range(m):
        city = cities[i]
        pref = city[1]
        pref_id = str(pref).zfill(6)
        sequence_id = str(prefes[pref]).zfill(6)
        prefes[pref] += 1
        res_id = pref_id + sequence_id
        cities[i].append(res_id)

    cities.sort(key=lambda x: x[2])

    for i in range(m):
        print(cities[i][-1])


main()


Measured memory_bytes: 111708
n = gets.to_i
a = gets.chomp.split.map(&:to_i)

s = []

t = 0
a.each do |x|
  t += x
  s.push t
end

m = 10 ** 9 + 7

res = 0
(n-1).times do |i|
  res += a[i] * (s[-1] - s[i])
  res %= m
end

puts res


Measured memory_bytes: 37484
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
	// your code goes here
     long long int n,k;
     cin>>n>>k;
     vector<long long int> a;
     for(long long int i=0; i<n; i++)
     {
         long long int temp;cin>>temp;
         a.push_back(temp);
     }
     vector<long long int> b(n,INF);
     b[0] = 0;
     for(long long int i=0; i<n; i++)
     {
         for(long long int j=i+1; j<=i+k; j++)
         {
                if(j<n)
                    b[j] = min(b[j],b[i]+abs(a[j]-a[i]));
         }
     }
     cout<<b[n-1];

}



Measured memory_bytes: 4828