akhauriyash/Code-Regression huggingface dataset:
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>
using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
typedef long long Long;
typedef long double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

template <class T>
void ms_erase_one(multiset<T>& ms, const T value) {
  ms.erase(ms.find(value));
}

const int N = 1e6 + 5;

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

int h, w;
int k;
struct Cell {
  int x, y;
  int getInd() const { return x * w + y; }
  bool valid() const {
    return min(x, y) >= 0 && x < h && y < w && grid[getInd()] == '.';
  }
  bool operator==(const Cell& other) const {
    return x == other.x && y == other.y;
  }
};

struct Dist {
  int cost = INT_MAX, k = 0;
  bool operator<(const Dist& other) const {
    return make_pair(cost, -k) < make_pair(other.cost, -other.k);
  }
  const static Dist OO;
};
const Dist Dist::OO;

struct State {
  Cell cell;
  Dist dist;
  int dir;
  bool operator<(const State& other) const { return other.dist < dist; }
  int getInd() const { return dir * N + cell.getInd(); }
};

Dist dist[4 * N];
bool vis[4 * N];

int dijkstra(const Cell& start, const Cell& goal) {
  fill(dist, dist + 4 * N, Dist::OO);
  priority_queue<State> pq;

  for (int i = 0; i < 4; ++i) {
    State nxt;
    nxt.dist.cost = 1, nxt.dist.k = k - 1;
    nxt.cell = start;
    nxt.cell.x += dx[i], nxt.cell.y += dy[i];
    if (!nxt.cell.valid()) continue;
    nxt.dir = i;
    pq.emplace(nxt);
  }

  while (!pq.empty()) {
    auto curr = pq.top();
    pq.pop();
    if (vis[curr.getInd()]) continue;
    if (curr.cell == goal) return curr.dist.cost;
    vis[curr.getInd()] = true;
    for (int i = 0; i < 4; ++i) {
      State nxt = curr;
      nxt.cell.x += dx[i], nxt.cell.y += dy[i];
      if (!nxt.cell.valid()) continue;
      nxt.dir = i;
      if (nxt.dir != curr.dir || nxt.dist.k == 0) {
        nxt.dist.k = k - 1;
        ++nxt.dist.cost;
      } else {
        --nxt.dist.k;
      }
      if (nxt.dist < dist[nxt.getInd()]) {
        dist[nxt.getInd()] = nxt.dist;
        pq.emplace(nxt);
      }
    }
  }
  return -1;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> h >> w >> k;
  Cell start, goal;
  cin >> start.x >> start.y >> goal.x >> goal.y;
  --start.x, --start.y, --goal.x, --goal.y;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      Cell cell;
      cell.x = i, cell.y = j;
      cin >> grid[cell.getInd()];
    }
  }

  cout << dijkstra(start, goal) << endl;
  return 0;
}


Measured memory_bytes: 42684
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    vi v(n),c(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    int ans = 0;
    rep(i,n){
        if(v[i]-c[i] > 0) ans += v[i]-c[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
using namespace std;
const int N = 1e6 + 5;
const ll inf = -1e18;
const int MOD = 1e9 + 7;


std::vector<pair<ll, ll> > v;
int main(){
   fast;
   ll n, m, ct = 0, x, y;
   cin >> n >> m;
   for(int i = 1; i <= m; i++){
   	cin >> x >> y;
   	v.push_back({y, x});
   }
   sort(v.begin(), v.end());
   ll demolish = -1;
   for(auto i : v){
   	if(i.second <= demolish){
   		continue;
   	}
   	demolish = i.first - 1;
   	ct++;
   }
   cout << ct;




   return 0;
} 

Measured memory_bytes: 2420
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rep(i,a) for( int i = 0; i != (a); ++i ) 

const int INF = 1 << 30;

struct edge
{
	int from, to, cost;

	edge( int from, int to, int cost )
	:	from( from ), to( to ), cost( cost )
	{}
};

int v, e, r;
std::vector<edge> es;
int d[1000];

void bellman_ford()
{
	std::fill( d, d+v, INF );
	d[r] = 0;

	int cnt = 0;
	while( true )
	{
		bool update = false;

		rep( i, e )
		{
			edge &e = es[i];

			if( d[e.from] != INF && d[e.to] > d[e.from]+e.cost )
				d[e.to] = d[e.from]+e.cost, update = true;
		}

		if( !update )
			break;

		++cnt;

		if( cnt > v )
		{
			puts("NEGATIVE CYCLE");
			return;
		}
	}

	rep( i, v )
	{
		if( d[i] == INF )
			puts("INF");
		else
			printf( "%d\n", d[i] );
	}
}

int main()
{
	scanf( "%d%d%d", &v, &e, &r );
	rep( i, e )
	{
		int s, t, ds;
		scanf( "%d%d%d", &s, &t, &ds );
		es.push_back( edge( s, t, ds ) );
	}

	bellman_ford();

	return 0;
}

Measured memory_bytes: 1084
package main

import (
	"fmt"
)

func main() {
	var k int
	fmt.Scan(&k)

	q := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	for cnt := 1; ; cnt++ {
		a := q[0] // 先頭の要素を取り出す
		if cnt == k {
			fmt.Println(a)
			return
		}
		q = q[1:]   // 2番目以降の要素を切り出す
		i := a % 10 // 一桁目の値
		switch i {
		case 0:
			q = append(q, 10*a+i)
			q = append(q, 10*a+i+1)
		case 9:
			q = append(q, 10*a+i-1)
			q = append(q, 10*a+i)
		default:
			q = append(q, 10*a+i-1)
			q = append(q, 10*a+i)
			q = append(q, 10*a+i+1)
		}
	}
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f;
int tc;

int main()
{
    FIO
    ll n; cin>>n;
    ll ans = 0;
    for(ll i = 1 ; i<= n ; i++)
        ans += (i * (n-i+1));
    for(int i = 0 ; i< n -1 ; i++)
    {
        ll u, v; 
        cin>>u>>v;
        ans -= (min(u, v) * (n - max(u, v) + (ll) 1));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int n;
    long long sum=0;
    string s;
    cin >> n;
    cin >> s;
    vector<int> r_cnt(n);
    vector<int> g_cnt(n);
    vector<int> b_cnt(n);
    int r_num=0, g_num=0, b_num=0;
    for(int i=n-1; i>=0; i--){
        if(s[i]=='R') r_num+=1;
        if(s[i]=='G') g_num+=1;
        if(s[i]=='B') b_num+=1;
        r_cnt[i]=r_num;
        g_cnt[i]=g_num;
        b_cnt[i]=b_num;
    }
    bool flag;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            if(s[i]!=s[j]){
                if(2*j-i<n) flag=true;
                else flag=false;
                if((s[i]=='R' && s[j]=='G')||(s[i]=='G' && s[j]=='R')){
                    if(flag){
                        if(s[2*j-i]=='B') sum+=b_cnt[j+1]-1;
                        else sum+=b_cnt[j+1];
                    }else{
                        sum+=b_cnt[j+1];
                    }
                }else if((s[i]=='R' && s[j]=='B')||(s[i]=='B' && s[j]=='R')){
                    if(flag){
                        if(s[2*j-i]=='G') sum+=g_cnt[j+1]-1;
                        else sum+=g_cnt[j+1];
                    }else{
                        sum+=g_cnt[j+1];
                    }
                }else if((s[i]=='B' && s[j]=='G')||(s[i]=='G' && s[j]=='B')){
                    if(flag){
                        if(s[2*j-i]=='R') sum+=r_cnt[j+1]-1;
                        else sum+=r_cnt[j+1];
                    }
                    else{
                        sum+=r_cnt[j+1];
                    }
                }
            }
        }
    }
    // for(int i=0; i<n-2; i++){
    //     for(int j=i+1; j<n-1; j++){
    //         if(s[i]!=s[j]){
    //             for(int k=j+1; k<n; k++){
    //                 if(s[j]!=s[k] && s[k]!=s[i]){
    //                     if((j-i)!=(k-j)) sum += 1;
    //                 }
    //             }
    //         }
    //     }
    // }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3676
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
string s[2005];
int rwn[2005][2005];
int rwae[2005][2005], rwhe[2005][2005];

signed main() {
	int n, m, q; cin >> n >> m >> q;
	rep(i, n)cin >> s[i];
	rep(i, n) {
		rep(j, m) {
			if (s[i][j] == '1')rwn[i + 1][j + 1]++;
		}
	}
	rep(i, n) {
		rep(j, m - 1) {
			if (s[i][j] == '1'&&s[i][j + 1] == '1') {
				rwae[i + 1][j + 1]++;
			}
		}
	}
	rep(i, n - 1) {
		rep(j, m) {
			if (s[i][j] == '1'&&s[i + 1][j] == '1') {
				rwhe[i + 1][j + 1]++;
			}
		}
	}
	rep(i, n) {
		rep(j, m) {
			rwn[i + 1][j + 1] += rwn[i + 1][j];
			rwae[i + 1][j + 1] += rwae[i + 1][j];
			rwhe[i + 1][j + 1] += rwhe[i + 1][j];
		}
	}
	rep(i, n) {
		rep(j, m) {
			rwn[i + 1][j + 1] += rwn[i][j+1];
			rwae[i + 1][j + 1] += rwae[i][j+1];
			rwhe[i + 1][j + 1] += rwhe[i][j+1];
		}
	}
	rep(i, q) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		cout << rwn[c][d] - rwn[c][b - 1] - rwn[a - 1][d] + rwn[a - 1][b - 1]
			-( rwae[c][d - 1] - rwae[c][b - 1] - rwae[a - 1][d - 1] + rwae[a - 1][b - 1])
			-( rwhe[c - 1][d] - rwhe[c - 1][b - 1] - rwhe[a - 1][d] + rwhe[a - 1][b - 1]) << endl;
	}
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,P;
ll from[2500],to[2500];

vector<pair<int,int>> E[3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>P;
	FOR(i,M) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
	}
	
	FOR(i,N) from[i]=-(1LL<<60);
	from[0]=0;
	ll ma=-1LL<<60;
	FOR(i,10000) {
		FOR(j,N) to[j]=-(1LL<<60);
		FOR(x,N) if(from[x]>-(1LL<<60)) FORR(e,E[x]) {
			to[e.first]=max(to[e.first],from[x]+e.second-P);
		}
		
		if(i>=5100&&to[N-1]>ma) return _P("-1\n");
		ma=max(ma,to[N-1]);
		swap(from,to);
	}
	ma=max(ma,0LL);
	cout<<ma<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;

#define INF 1000000000

double l[20];
double a[20];
double b[20];
double dis[20][20];

int n;

bool use[20];

double calc(){
    double res=0;
    rep(i,n)rep(j,i)if(use[i] && use[j]){
        res += dis[i][j];
    }
    return res;
}

// from idx, use m numbers
double dfs(int idx, int m){
    if(m==0) return calc();

    use[idx]=true;
    double res = dfs(idx+1, m-1);
    use[idx]=false;
    if(n-idx > m){
        res = max(res, dfs(idx+1, m));
    }
    return res;
}

int main(){
    int m;
    cin>>n>>m;
    rep(i,n){
        scanf("%lf %lf %lf", &l[i], &a[i], &b[i]);
    }

    if(m<=1){
        printf("0.00000\n");
        return 0;
    }

    rep(i,n)rep(j,i){
        dis[i][j] = (l[i]-l[j])*(l[i]-l[j]) + (a[i]-a[j])*(a[i]-a[j]) + (b[i]-b[j])*(b[i]-b[j]);
    }

    fill(use, use+20, false);
    printf("%.6lf\n", dfs(0, m));

    return 0;
}

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

/*----------------------------- DEFINES ------------------------------*/

#define eps 1e-9
#define mod 1000000007
#define ump unordered_map // operations take less time compared to map
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define mp make_pair
#define ps(x) push(x) // for stack and queue
#define T top() //  for stack
#define FR front()// for queue
#define BA back()// for queue
#define PP pop()// for queue and stack
#define B begin()
#define E end()
#define F first
#define S second
#define tostr(x) to_string(x)
#define SZ(x) ((int)x.size())
#define ins insert
#define MAE max_element
#define MIE min_element
#define cnt(x) count(x)
#define lb(x) lower_bound(x) // returns an it ptng to the element >=x if no such returns end
#define ub(x) upper_bound(x) // returns an it ptng to the element >x if no such returns end
#define rep(i,x,y) for(int i=x;i<y;i++)
#define per(i,x,y) for(int i=x;i>y;i--)
#define repi(i,x,y) for(int i=x;i<=y;i++)
#define peri(i,x,y) for(int i=x;i>=y;i--)
#define reps(i,x,y,k) for(int i=x;i<y;i+=k)
#define sper(i,x,y,k) for(int i=x;i>y;i-=k) 
#define all(x) ((x.B),(x.E))
#define inf (ll)LLONG_MAX
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x) // easy method to iterate through a ds
#define sq(a) (a)*(a)
#define fib(n) ceil(pow((1+sqrt(5),n)-pow((1-sqrt(5),n)/(float)(pow(2,n)*sqrt(5)// compute fib(n) in O(1)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}// fast i/o
#define dig(n) (int)(log10(n)+1) // num of digits
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define f(x) find(x)
#define set(x,k) memset(x,k,sizeof x)

/*------------------------------ TYPEDEFS-----------------------------*/

typedef long long ll;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef ump<int,int> umpii;

/*-----------------------------START FROM HERE -----------------------*/

int main(){
	FIO
	
	int n;cin>>n;
	if(n<1200)cout<<"ABC";
	else cout<<"ARC";
	return 0;
}


Measured memory_bytes: 256
use proconio::marker::*;
use proconio::{fastout, input};

#[fastout]
fn main() {
  input! {
    n: usize,
  }
  
  let res = solve(n);
  println!("{}", res);
}

fn solve(n: usize) -> String {
  let mut ret = "".to_string();
  for _ in 0..n {
    ret.push_str("ACL");
  }
  ret
}

Measured memory_bytes: 2192
#include <stdio.h>

int main(void) {
    int a, b;
    int i = 0;
    
    while(1) {
    	scanf("%d %d", &a, &b);
    	i++;
    	
    	if(a == 0 && b == 0) {
    	    break;
    	}
    	
    	if(a <= b) {
    	    printf("%d %d\n", a, b);
    	} else {
    	    printf("%d %d\n", b, a);
    	}
    }
    
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
	stack<int> s1;
	stack<pair<int, int> > s2;
	char ch;
	int sum = 0;
	for(int i=0; cin>>ch; i++){
		if(ch == '\\') s1.push(i);
		else if(ch == '/' && s1.size()>0){
			int j = s1.top();
			s1.pop();
			sum += i - j;
			int a = i - j;
			while(s2.size()>0 && s2.top().first > j){
				a += s2.top().second;
				s2.pop();
			}
			s2.push(make_pair(j, a));
		}
	}
	vector<int> ans;
	while (s2.size()>0) {
		ans.push_back(s2.top().second);
		s2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for(int i=0; i<ans.size(); i++){
		cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3216
#include<iostream>
#include<vector>
using namespace std;
int dp[100005];
vector <int> v[100005];
int dfs(int x,int par) {
    //cout <<x<<" "<<dp[x]<<endl;
    for(int i=0;i<v[x].size();i++) {
        if(v[x][i]==par) continue;
        if(dp[v[x][i]]!=-1) dp[x]=max(dp[x],dp[v[x][i]]+1);
        else dp[x]=max(dp[x],dfs(v[x][i],x)+1);
    }
    //cout <<x<<" "<<dp[x]<<endl;
    return dp[x];
}
int main()
{
    int n,m,maxi=0;
    cin >> n >> m;
    for(int i=0;i<m;i++) {
        int x,y;
        cin >> x >> y;
        v[x-1].push_back(y-1);
    }
    for(int i=0;i<n;i++) {
        //cout <<i<<" "<<v[i].size()<<endl;
        int s=v[i].size();
        if(s>0) dp[i]=-1;
        else dp[i]=0;
        //cout <<dp[i]<<" ";
    }
    //cout <<endl;
    for(int i=0;i<n;i++) {
        if(dp[i]==-1) dfs(i,i);
    }
    for(int i=0;i<n;i++) {
        maxi=max(maxi,dp[i]);
    }
    cout <<maxi;
    return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int cnt=0;
    repi(i,1,n-1){
        if((a[i-1]<a[i]&&a[i]<a[i+1])||(a[i-1]>a[i]&&a[i]>a[i+1])) cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 3624
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using pii = std::pair<int, int>;
using namespace std;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  vec<int> L(N);
  vec<int> R(N);
  L[0] = R[N - 1] = 0;

  for (int i = 1; i < N; i++) {
    L[i] = L[i - 1] + (S[i - 1] == 'W' ? 1 : 0);
  }
  for (int i = N - 1; i >= 1; i--) {
    R[i - 1] = R[i] + (S[i] == 'E' ? 1 : 0);
  }

  int answer = min(L[N - 1], R[0]);
  for (int i = 1; i < N - 1; i++) {
    answer = min(answer, L[i] + R[i]);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 2964
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int n; string s; cin >> n >>s;
	for0(i, s.size()) { s[i] += n; if (s[i] > 'Z')s[i] -= 26; }
	cout << s << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;




vector<int> g2[3*112345];

int dists[3*112345];

int bfs(int from,int to) {
    int dist=0;
    queue<int> que;
    que.push(from);
    dists[from]=0;
    while(!que.empty()){
        int now=que.front();que.pop();
        int nowd=dists[now];
        rep(i,g2[now].size()){
            int nx=g2[now][i];
            if(dists[nx]==-1){
                dists[nx]=nowd+1;
                que.push(nx);
            }
        }
    }
       
    return dists[to];
}

signed main(){
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int u,v;
        cin>>u>>v;
        u--;v--;
       // g2[u].push_back(v);
        g2[u].push_back(v+n);
        g2[u+n].push_back(v+n*2);
        g2[u+n*2].push_back(v);
    }
    rep(i,3*112345){
        dists[i]=-1;
    }
    int s,t;
    cin>>s>>t;
    s--;t--;
    int dist=bfs(s,t);

    int ans=(dist==-1)?-1:dist/3;
    cout<<ans<<endl;

 
}

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

int main(){
	string s;
	cin>>s;
	int cnt=0;
	int res=0;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			if(s[i]=='0')cnt++;
			else if(s[i]=='1')res++;
		}
		else if(i%2==1){
			if(s[i]=='1')cnt++;
			else if(s[i]=='0')res++;
		}
	}
	cout<<min(res,cnt)<<endl;
	return 0;
}

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

#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
const double PI = 3.141592653589793;

int main(){
    int a,b;
    cin >> a>> b;
    rep(i, 1200){
        int za = i*8/100;
        int zb = i*10/100;
        if(a==za&&b==zb){
            cout << i <<endl;
            return 0;
        }
    }
    cout <<"-1"<<endl;
    return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int K; cin >> K;
	int A, B; cin >> A >> B;
	if (B - A > 2) {
		if (A > K) {
			cout << K+1 << endl;
		}
		else {
			int remain = K - A + 1;
			dump(remain);
			int n = A + (remain & 1) + remain / 2 * (B - A);
			dump(n);
			cout << n << endl;
		}
	}
	else {
		cout << K+1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N=int(input())
S=input()
s=list(S)

count=0

for i in range(1000):
    ss=s[:]
    st=str(i).rjust(3,"0")
    if st[0] in ss:
        del ss[0:ss.index(st[0])+1]
        if st[1] in ss:
            del ss[0:ss.index(st[1])+1]
            if st[2] in ss:
                count+=1

print(count)

Measured memory_bytes: 4044
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;


int n, m;
int dp[3003][3003],mx;
pair<int,int> last[3003][3003];
char l[3003][3003];
vector<int> pos[30];
string s, t,ans;
int main()
{
	cin >> s >> t;

	n = s.length();
	m = t.length();

	for (int i = 0; i < m; i++)
		pos[t[i] - 'a'].PB(i);

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			last[i][j] = MP(-1, -1);

	for (int i = 0; i <= n; i++)
	{
		if (pos[s[i] - 'a'].empty())
			continue;
		dp[i][pos[s[i] - 'a'][0]] = 1;
		l[i][pos[s[i] - 'a'][0]] = s[i];
	}


	for (int i = 0; i < n-1; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (dp[i + 1][j] < dp[i][j])
			{
				dp[i + 1][j] = dp[i][j];
				last[i + 1][j] = last[i][j];
				l[i + 1][j] = l[i][j];
			}
			if (pos[s[i+1] - 'a'].empty() || pos[s[i+1] - 'a'].back() <= j)
				continue;
			int p = pos[s[i+1] - 'a'][upper_bound(all(pos[s[i+1] - 'a']), j) - pos[s[i+1] - 'a'].begin()];
			if (dp[i][j] + 1 > dp[i+1][p])
			{
				dp[i + 1][p] = dp[i][j] + 1;
				last[i + 1][p] = MP(i, j);
				l[i + 1][p] = s[i + 1];
			}
		}
	}



	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			mx = max(mx,dp[i][j]);
	if (mx == 0)
	{
		cout << "" << endl;
		return 0;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (dp[i][j] == mx)
			{
				while (i >= 0)
				{
					ans += l[i][j];
					pair<int, int> lst = last[i][j];
					i = lst.first;
					j = lst.second;
				}
				i = n + 6;
				break;
			}
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}

/*

aaaaa
bbbbb

zzzzabzzzzzzgzzzzzzzzzzzzd
ayyyyyybyyyyyyyyygyyyyd


*/

Measured memory_bytes: 114688
#include <iostream>
using namespace std;
int main(void){
    int N, min, max, tmp;
    cin >> N;
    cin >> min;
    max = min;
    for(int i = 1; i < N; i++)
    {
        cin >> tmp;
        if(tmp < min)
        {
            min = tmp;
        }
        if(tmp > max)
        {
            max = tmp;
        }
    }
    cout << max - min << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int fun(int n)
{
	int s=0;
	while(n!=0)
	{
		s+=n%10;
		n/=10;
	}
	return s;
}
int main()
{
	int i,n,a,b,sum=0;
	scanf("%d %d %d",&n,&a,&b);
	for(i=1;i<=n;i++)
	{
		if(fun(i)>=a&&fun(i)<=b)
			sum+=i;
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,L=map(int,input().split())
    S=[input() for i in range(N)]
    S.sort()
    for s in S:
        print(s,end='')
    print('')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INF 1<<29
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= MOD;
	}
	return ret;
}

#pragma endregion 

class full_search {

};

class GRAPH {
private:
	int v, e;

};

/*****************************************************************************/
int n, m;
int ans = 0;

void dfs(int v) {
	bool all_visited = true;
	f(i, 0, n) {
		if (visited[i] != true) {
			all_visited = false;
		}
	}
	if (all_visited == true) {
		ans++;
		return;
	}
	f(i, 0, n) {
		if (graph[v][i] != true) {
			continue;
		}
		if (visited[i] == true) {
			continue;
		}
		visited[i] = true;
		dfs(i);
		visited[i] = false;
	}
	
	return;
}

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

	cin >> n >> m;
	vi a(m), b(m);
	link(a, b, m);
	visited[0] = true;
	dfs(0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,fail[200010];
ll ans[30],len[95],sum[95][30],cnt[200010][30];
char s[200010];
void kmp()
{
	fail[0]=-1;
	int p=-1;
	for (int i=1;i<n;i++)
	{
		while (p>=0 && s[i]!=s[p+1])
		{
			p=fail[p];
		}
		if (s[i]==s[p+1])
		{
			p++;
		}
		fail[i]=p;
	}
}
void solve(ll k,ll f)
{
	ll p=k/(ll)m;
	for (int i=0;i<26;i++)
	{
		ans[i]+=f*p*cnt[m][i];
	}
	ll q=k%(ll)m;
	for (int i=0;i<26;i++)
	{
		ans[i]+=f*cnt[q][i];
	}
}
void work(ll k,ll f)
{
	int i=1;
	while (len[i]<=k)
	{
		i++;
	}
	for (;i;i--)
	{
		if (k>len[i])
		{
			for (int j=0;j<26;j++)
			{
				ans[j]+=f*sum[i][j];
			}
			k-=len[i];
		}
	}
	for (i=0;i<26;i++)
	{
		ans[i]+=f*cnt[k][i];
	}
}
int main()
{
	scanf("%s",&s);
	n=strlen(s);
	n/=2;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<26;j++)
		{
			cnt[i][j]=cnt[i-1][j];
		}
		cnt[i][s[i-1]-'a']++;
	}
	kmp();
	m=n-1-fail[n-1];
	ll l,r;
	cin>>l>>r;
	if (n%m==0)
	{
		solve(r,1);
		solve(l-1,-1);
	}
	else
	{
		len[1]=n;
		len[2]=m+n;
		for (int i=0;i<26;i++)
		{
			sum[1][i]=cnt[n][i];
			sum[2][i]=cnt[m][i]+sum[1][i];
		}
		for (int i=3;i<=90;i++)
		{
			len[i]=len[i-2]+len[i-1];
			for (int j=0;j<26;j++)
			{
				sum[i][j]=sum[i-1][j]+sum[i-2][j];
			}
		}
		work(r,1);
		work(l-1,-1);
	}
	for (int i=0;i<26;i++)
	{
		printf("%lld ",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 27264
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    int c=0;
    int a[100000];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)if(a[a[i]-1]==i+1)c++;
    cout<<c/2<<endl;
    return 0;
}

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

using namespace std;

#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define DFOR(a, b, c) for (register int a = b, _n = c; a > _n; --a)
#define EREP(a, b) for (register int a = head[b]; a; a= edge[a].nxt)

inline int rd () {
	int x = 0; char IO = getchar();
	bool f = 0;
	while ((IO < '0' || IO > '9') && IO != '-') IO = getchar();
	if (IO == '-') f = 1, IO = getchar();
	while (IO >= '0' && IO <= '9') x = (x << 3) + (x << 1) + (IO ^ 48), IO = getchar();
	return f ? -x : x;
}
int n;

void _main () {
	cin >> n;
	double ans = 0;
	REP (i, 1, n) {
		int a;
		scanf ("%d", &a);
		ans += 1.0 / a;
	}

	cout << 1 / ans << endl;
}

int main () {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
#endif
	_main();
	return 0;
}


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

using namespace std;
typedef long long i64;

int main(int argc, const char *argv[]) {
	i64 N;
	cin >> N;
	vector<string> S(N);
	getchar();
	for(i64 i=0;i<N;++i) {
		getline(cin, S[i]);
	}

	vector<vector<i64>> D(N, vector<i64>(N, 1000));
	for(i64 i=0;i<N;++i) {
	  D[i][i] = 0;
		for(i64 j=0;j<N;++j) {
			if(S[i][j] == '1') {
				D[i][j] = 1;
			}
		}
	}

	for(int k=0;k<N;++k) {
		for(int i=0;i<N;++i) {
			for(int j=0;j<N;++j) {
				D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
			}
		}
	}

	bool ans1 = true;
	i64 ans2 = 0;
	for(int i=0;i<N-1;++i) {
		i64 mod = abs(D[i][0] - D[i+1][0]) % 2;
		for(int j=1;j<N;++j) {
			if (abs(D[i][j] - D[i+1][j]) % 2 != mod) {
				ans1 = false;
				break;
			}
		}
		if(!ans1) {
			break;
		}
	}
	for(int i=0;i<N;++i) {
	  for(int j=0;j<N;++j) {
	    if(D[i][j] != 1000) {
	      ans2 = max(ans2, D[i][j]);
	    }
	    else {
	      ans1 = false;
	    }
	    //cout << D[i][j] << " ";
	  }
	  //cout << endl;
	}
	  
	if(!ans1) {
		cout << -1 << endl;
	}
	else {
	  cout << ans2 + 1 << endl;
	}

	return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define INF INT_MAX - 10000

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() { int a; cin >> a; return a; }
char nextChar() { char a; cin >> a; return a; }
double nextDouble() { double a; cin >> a; return a; }
string nextString() { string a; cin >> a; return a; }

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

class Point {
public:
    int x, y;
    Point() {}
    Point(int x, int y) {
	this->x = x;
	this->y = y;
    }
};

signed main() {
    int H, W, K;
    cin >> H >> W >> K;

    vector<string> A;
    inputVector(A, H);

    int sx, sy;
    rep(y, H) rep(x, W) {
	if (A[y][x] == 'S') {
	    sx = x;
	    sy = y;
	    break;
	}
    }

    queue<Point> tq;
    tq.push(Point(sx, sy));
    bool visited[810][810];
    memset(visited, false, sizeof(visited));
    visited[sy][sx] = true;
    rep(i, K) {
	queue<Point> ttq;
	while (!tq.empty()) {
	    Point p = tq.front(); tq.pop();
	    rep(dir, 4) {
		int nx = p.x + dx[dir];
		int ny = p.y + dy[dir];
		if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
		if (visited[ny][nx]) continue;
		if (A[ny][nx] == '#') continue;
		visited[ny][nx] = true;
		ttq.push(Point(nx, ny));
	    }
	}
	tq = ttq;
    }

    queue<Point> q;
    rep(y, H) rep(x, W) {
	if (visited[y][x]) {
	    q.push(Point(x, y));
	}
    }

    int ret = INT_MAX;
    while (!q.empty()) {
	Point p = q.front(); q.pop();
	int dist = min(p.x, W - p.x - 1);
	dist = min(dist, p.y);
	dist = min(dist, H - p.y - 1);

	if (dist == 0) {
	    cout << 1 << endl;
	    return 0;
	}

	ret = min(ret, (dist - 1) / K + 2);
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 12048
S = input()
K = int(input())
cot = 0
before = ""
seq = []


for i in range(len(S)):
    c = S[i]
    if cot == 0:
        cot += 1
        before =c
    else:
        if c == before:
            cot += 1
        else:
            before = c
            seq.append(cot)
            cot = 1

seq.append(cot)
ans = 0
for temp in seq: #素の状態で連続してる文字列
    ans +=temp//2
ans *= K
if S[0] == S[-1]: #頭と尾で一緒→つなげたときに長い連続区間が発生
    ans += (seq[0] + seq[-1]) //2 * (K - 1) - (seq[0] //2 + seq[-1]//2 )* (K - 1)
if len(seq) == 1:
    ans = min(ans,seq[0] * K //2)
print(ans)

Measured memory_bytes: 38384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head) << " ";
  print(tail...);
}

int main() {
  ll N, L;
  cin >> N >> L;
  vector<ll> a(N);
  FOR(i, N) cin >> a[i];
  int index = -1;
  FOR(i, N - 1) {
    ll s = a[i] + a[i + 1];
    if (s >= L) {
      index = i;
    }
  }
  if (index < 0) {
    print("Impossible");
    return 0;
  }
  print("Possible");
  for (int i = 1; i < index + 1; ++i) {
    print(i);
  }
  for (int i = N - 1; i > index; --i) {
    print(i);
  }
  return 0;
}

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

using namespace std;

typedef long long lint;

const int N = 200010;

lint a[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    if (i) {
      a[i] += a[i - 1];
    }
  }
  lint ans = LLONG_MAX;
  for (int i = 0; i < n - 1; ++i) {
    lint x = a[i];
    lint y = a[n - 1] - x;
    ans = min(ans, abs(x - y));
  }
  return !printf("%lld\n", ans);
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
template<class T>
int print(T& x){ cout << x << '\n'; return 0;}
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n;
    cin >> n;
    int f[n][10];
    int p[n][10];

    rep(i,n)rep(j,10) cin >> f[i][j];
    rep(i,n)rep(j,11) cin >> p[i][j];

    ll ans = -1 * INF;
    
    for(int bit = 1; bit < (1<<10); bit++){
        int count[n];
        rep(j,n) count[j] = 0;
        rep(i, 10){
            if(bit & (1<<i)){
                rep(j,n){
                    if(f[j][i]) count[j]++;
                }
            }
        }

        ll temp = 0;
        rep(i,n) temp += p[i][count[i]];
        if(ans < temp){
            ans = temp;
        }
    }

    print(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int f(int x){
        int sum=0;
        for(;x>0;){
                sum=sum+x%10;
                x=x/10;
        }
return sum;
}
int main(){
        int n;
        cin>>n;
        if(n%f(n)==0){
                cout<<"Yes";
        }
        else{
        cout<<"No";
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll k;
    cin >> k;

    ll even = k / 2, odd = k - even;
    ll res = even * odd;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    a, b, c, d = map(int, input().split())
    left = a + b
    right = c + d
    if left > right:
        print('Left')
    elif left < right:
        print('Right')
    else:
        print('Balanced')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
n,k,l=map(int,input().split())
class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        news=[]
        p=self._parents
        y=p[x]
        while y>=0:
            news.append(x);x,y=y,p[y]
        if len(news)!=1:
            for P in news:p[P]=x
        return x

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum(1 for i in  self._parents if i<0)-self._first_idx
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size
road=UnionFind(1,n)
rail=UnionFind(1,n)

for i in range(k):
    road.unite(*map(int,input().split()))
for i in range(l):
    rail.unite(*map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)

for i in range(1,n+1):
    ap,op=rail.find(i),road.find(i)
    d[ap*(n+1)+op]+=1
print(*[d[road.find(i)+rail.find(i)*(n+1)]for i in range(1,n+1)])

Measured memory_bytes: 35948
a,b,c,d = input().strip().split()
a,b,c,d = [int(a),int(b),int(c),int(d)]
while a>0 and c>0:
    a = a-d
    c = c-b
    if (a<=0 and c<=0) or (a>0 and c<=0):
        print("Yes")
    if a<=0 and c>0:
        print("No")

Measured memory_bytes: 9132
import sys, re
from collections import deque, defaultdict, Counter
from math import log10, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, k = MAP()

lim = 10**6  # 必要そうな階乗の限界を入れる
factorial = [1]
for i in range(1, lim):
    factorial.append(factorial[i-1] * i % mod)

def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2)) ** 2 % mod
    else:
        return power(x, int((y-1)/2)) ** 2 * x % mod

def C(n, r):
    return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod
x_inv = [0] * lim
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(lim-2, -1, -1):
    x_inv[i] = x_inv[i+1] * (i+1) % mod

if k >= n-1:
	k = n-1
ans = 0
for m in range(k+1):
	ans = (ans+C(n, m)*C(n-1, m))%mod
print(ans)


Measured memory_bytes: 92796
#include<stdio.h>
int main(void)
{
	int A,B,C,D,E;
	scanf("%d%d%d%d%d",&A,&B,&C,&D,&E);
	if(A>0)
	{
		printf("%d\n",(B-A)*E);
	}
	else if(A<0)
	{
		printf("%d\n",C*(-A)+D+E*B);
	}
	else
	{
		printf("%d\n",D+(B-A)*E);
	}
	return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int n = 3;

    if(a==b && b==c) cout << 1;
    if(a==b && b!=c) cout << 2;
    if(a==c && b!=c) cout << 2;
    if(c==b && b!=a) cout << 2;
    if(c!=b && b!=a && a!=c) cout << 3;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)


int n, k;
bool card[100001];

int main() {
	while (true) {
		cin >> n >> k;
		if (n == 0 && k == 0) break;
		REP(i, n + 1) card[i] = false;

		REP(i, k) {
			int a;
			scanf("%d", &a);
			card[a] = true;
		}
		int l = 1, r = 1, ans = 0, magic = 0;

		while (true) {
			if (r > n) { ans = max(ans, r - l); break; }

			if (!card[r]) {
				if (magic == 0 && card[0]) {
					magic = r;
				} else if (magic != 0) {
					ans = max(ans, r - l);
					l = magic + 1;
					magic = r;
				} else {
					ans = max(ans, r - l);
					l = r + 1;
				}
			}
			r++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1340
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int main(){
	string s, t;
	int x, y;
	string u;

	cin >> s >> t;
	cin >> x >> y;
	cin >> u;

	if (s == u) x--;
	if (t == u) y--;

	cout << x << " " << y << endl;
	return 0;


}




Measured memory_bytes: 256
N, M = map(int, input().split())

left = 1
right = N

for i in range(M):
    L, R = map(int, input().split())
    if L > left :
        left = L
    if R < right:
        right = R

if right-left+1 > 0:
    print(right-left+1)
else:
    print(0)


Measured memory_bytes: 3060
matrix = []
vector = []

n, m = map(int, raw_input().split())

for i in xrange(n):
	matrix.append(map(int, raw_input().split()))

for i in xrange(m):
	vector.append(input())

for i in xrange(n):
	ans = 0
	for j in xrange(m):
		ans += matrix[i][j] * vector[j]
	print ans

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

const int N = 1e5 + 10;

int n, m;
multiset<int> available;
vector<int> job[N];

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    job[a].push_back(b);
  }

  int ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    for (int x : job[m - i])
      available.insert(x);
    if (!available.empty()) {
      ans += *prev(available.end());
      available.erase(prev(available.end()));
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(void) {
    int a, b;
    cin >> a >> b;
    string y = "Yay!", n = ":(";

    if (max(a, b) <= 8) {
        cout << y << endl;
    }
    else cout << n << endl;
}


Measured memory_bytes: 256