akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod=1000000007;
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int cutup(int a,int b){
    return (a+b-1)/b;
}
bool prime(int n){
    int cnt=0;
    for(int i=1;i<=sqrt(n);i++){
        if(n%1==0)cnt++;
    }
    if(cnt!=1) return false;
    else return n!=1;
}
struct UnionFind{
    vector<int> r;
    UnionFind(int N){
        r=vector<int>(N,-1);
    }
    int root(int x){
        if(r[x]<0) return x;
        return r[x]=root(r[x]);
    }
    bool unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(r[x]>r[y]) swap(x,y);
        r[x]+=r[y];
        r[y]=x;
        return true;
    }
    int size(int x){
        return -r[root(x)];
    }
};
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000],ab[220000];
pair<int,int> pp[220000];
string s,ss[220000];
queue<int> que;
signed main(){
    cin>>n;
    rep(i,n){
        cout<<"ACL";
    }
}

Measured memory_bytes: 10604
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
ans = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - ans.index(s))


Measured memory_bytes: 2940
//Counting sort

#include<stdio.h>
#define MAX 2000001
#define VMAX 10000

int Barr[MAX],Carr[VMAX + 1];

//work time
void counting(int arr[],int Barr[],int n,int k)
{
  int i,j;

  for(i = 0; i <= k; i++)
    {
      Carr[i] = 0;
    }

  for(j = 1; j <= n; j++)
    {
      Carr[arr[j]]++;
    }

  for(i = 1; i <= k; i++)
    {
      Carr[i] = Carr[i] + Carr[i - 1];
    }

  for(j = n; j >= 1; j--)
    {
      Barr[Carr[arr[j]]] = arr[j];
      Carr[arr[j]]--;
    }

  printf("%d",Barr[1]);
  for(i = 2; i <= n; i++)
    {
      printf(" %d",Barr[i]);
    }
  printf("\n");
  
}



int main()
{
  int arr[MAX];
  int i;
  int n = 0;
  int k = 0;


 
  //input data
  scanf("%d",&n);
  for(i = 1; i <= n; i++)
    {
      scanf("%d",&arr[i]);
      if(k < arr[i]) k = arr[i];
    }

  counting(arr,Barr,n,k);

  return 0;
}




Measured memory_bytes: 17400
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
int main(){
    int N;
    cin >> N;
    int d[N];
    int p[N];
    for(int i=0;i<N;i++)cin >> d[i];
    
    int sum = 0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3576
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

int main(){
	INIT;
	ll n;
	cin>>n;
	vector<ll> a(n);
	rep(i, n) cin>>a[i];
	vector<ll> b(a);
	sort(all(b));
	rep(i, n){
		if(a[i]<=b[n/2-1]) cout<<b[n/2]<<endl;
		else cout<<b[n/2-1]<<endl;
	}
	return 0;
}


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

int main() {
    string s, t;  cin >> s >> t;
    int a, b;  cin >> a >> b;
    map<string, int> mp;
    mp[s] = a;  mp[t] = b;
    string u;  cin >> u;
    --mp[u];
    cout << mp[s] << " " << mp[t] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n, k;
  cin >> k >> n;
  if (n == 1) {
    cout << 0 << nl;
  } else {
    cout << k-n << nl;
  }
  
  return 0;
}



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

int main() {

    long long int n;
    cin >> n;

    vector< long long int > v;
    long long int ans = 0;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        v.push_back( in );
        for ( long long int j = 0; j < i; j++ ) {
            ans += v[j] * in;
        }
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,s;
int main(){
    string str;
    cin>>str;
    for(int i=0;i<str.size();i++){
        if((i+1)%2==1){
            if(str[i]=='R'||str[i]=='U'||str[i]=='D'){
                s++;
            }
        }
        else{
            if(str[i]=='L'||str[i]=='U'||str[i]=='D'){
                s++;
            }
        }
    }
    if(s==str.size()){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
                
    divisors.sort()
    return divisors


a, b, c = map(int, input().split())

c_set = list(set(make_divisors(a))&set(make_divisors(b)))

c_set.sort()
# print(c_set)
print(c_set[-c])


Measured memory_bytes: 3188
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	ll X, Y;
	cin >> X >> Y;

	ll count = 0, Ai = X;
	do
	{
		count++;
		Ai *= 2;
	}
	while (Ai <= Y);
	cout << count << '\n';
	return 0;
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n & 1 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    IOS

    ll n,w;
    cin>>n>>w;

    ll v[n],wt[n];

    ll tot=0;

    for(ll i=0;i<n;i++)
    {
    	cin>>wt[i]>>v[i];
    	tot+=v[i];
    }

    ll ans=0;

    vector<ll> min(tot,-1);

    tot=0;
    min[0]=0;

    for(ll i=0;i<n;i++)
    {
    	tot+=v[i];

    	for(ll j=tot;j>=v[i];j--)
    	{
    		if(min[j-v[i]]!=-1)
    		{
    			ll req=min[j-v[i]]+wt[i];
    			if(req<=w)
    				ans=max(ans,j);
    			if(min[j]==-1||min[j]>req)
    				min[j]=req;
    		}
    	}
    }

    cout<<ans<<endl;


    
    return 0;
}

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

int main(){
	ll N,A,B;
	cin >> N >> A >> B;

	ll ball = A+B;
	ll blue = (N / ball)*A;
	ll res = N%ball;
	blue += min(res,A);

	cout << blue << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n; cin >> n;
  double d; cin >> d;
  double x,y;
  int count = 0;
  for(int i=0; i<n; i++){
    cin >> x >> y;
    double norm = sqrt(x*x+y*y);
    if(d >= norm) count++;
  }
  cout << count << "\n";
}

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

int main(){
  string S;
  vector<string> s = {"Sunny","Cloudy","Rainy"};
  cin >> S;
  if(S == s.at(0))
    cout << s.at(1);
  if(S == s.at(1))
    cout << s.at(2);
  if(S == s.at(2))
    cout << s.at(0);
  return 0;
    
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    ll x = pow(2, m);
    ll time = (n - m) * 100 + (m * 1900);
    cout << time * x << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<int,int>
#define iil pair<ll,ll>
#define se second
#define ld long double
#define mod 1000000007
#define popcount __builtin_popcountll
#define x0 zxcxzcsacasd
#define x1 ghfghujfgfg
#define y0 olkjhdnncvcv
#define y1 bhvgrewm345345435
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
#define all(x) x.begin(), x.end()
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int>a(n), b(n), amid(n);
	vector<int>cnt(n + 1, 0);
	for(auto &x:a)scanf("%d", &x), cnt[x]++;
	for(auto &x:b)scanf("%d", &x), cnt[x]++;
	for(int i = 1;i<=n;i++){
		if(cnt[i]>n){
			cout<<"No"<<endl;
			return 0;
		}
	}
	reverse(all(b));
	int l = 0, r = n-1;
	for(int i=0;i<n;i++){
		if(a[i]==b[i]){
			if(b[l]!=a[i] && a[l]!=a[i]){
				swap(b[l], b[i]);
				l++;
			}else{
				swap(b[r], b[i]);
				r--;
			}
		}
	}
	cout<<"Yes"<<endl;
	for(int i=0;i<n;i++){
		assert(a[i]!=b[i]);
		cout<<b[i]<<" ";
	}
}


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

#define N 1005
#define MP make_pair
typedef long long LL;
const int mod = 998244353;

int n, m;
int a[500][500];

int main()
{
	//freopen("in.txt", "r", stdin);
	
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			scanf("%d", &a[j][i]);
	
	swap(n, m); 
	int r = 1;
	for (int i = 1; i <= m; ++i)
	{
		int k = -1;
		for (int j = r; j <= n; ++j)
			if (a[j][i]) k = j;
		
		if (k == -1) continue;
		for (int j = 1; j <= m; ++j)
			swap(a[k][j], a[r][j]);
		for (int j = r + 1; j <= n; ++j)
		{
			if (!a[j][i]) continue;
			for (int l = i; l <= m; ++l)
				a[j][l] ^= a[r][l];
		}
		++r;
	}
	int t = 1;
	r--; r = m - r;
	while (r--) t = t * 2 % mod;
	
	LL ans = 1;
	int t1 = 1, t2 = 1;
	for (int i = 1; i <= m; ++i)
		t1 = t1 * 2 % mod;
	for (int i = 1; i < n; ++i)
		t2 = t2 * 2 % mod;
	
	ans = 1LL * (t1 - t) * t2 % mod;
	if (ans < 0) ans += mod;
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll             long long
#define Max(a,b)       ((a)>(b)?(a):(b))
#define Min(a,b)       ((a)<(b)?(a):(b))
#define si(a)          scanf("%d",&a)
#define pii            pair <int, int>
#define mp             make_pair
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define mem(a,v)       memset(a,v,sizeof(a))
#define MAX 2007
#define MOD 100000007
#define LG  16
using namespace std;
ll a[100005];
ll pos[100005];
ll neg[100005];
int main(){
    int n;
    ll sp,sn,addp,addn;
    sp=0;sn=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        pos[i]=pos[max(i-1,0)] + a[i];
        neg[i]=neg[max(i-1,0)] + a[i];
        if(i%2==0){

            if(pos[i]<=0){
                sp+=abs(pos[i])+1;
                pos[i]=1;
            }
            if(neg[i]>=0){
                sn+=abs(neg[i])+1;
                neg[i]=-1;
            }
        }
        else{

            if(pos[i]>=0){
                sp+=abs(pos[i])+1;
                pos[i]=-1;
            }
            if(neg[i]<=0){
                sn+=abs(neg[i])+1;
                neg[i]=1;
            }
        }
    }
    cout<<min(sn,sp);
}


Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS

//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 2e5 + 50, oo = 5e18 + 500;
const int mod = 998244353;
//const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-6, PI = 2 * acos(0.0);
int n, m, k;
int cnt = 0;
int lg = 18;
vi g[N];
vi rg[N];
vi visit(N, 0);



signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n;

	vi x(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}

	cin >> m >> k;

	vvi dp(n, vi(lg, oo));
	for (int i = 0; i < n - 1; i++)
	{
		dp[i][0] = upper_bound(all(x), x[i] + m) - x.begin() - 1;
	}

	for (int j = 1; j < lg; j++)
	{
		for (int i = 0; i < n - 1; i++)
		{
			if (dp[i][j - 1] == oo)
			{
				dp[i][j] = oo;
				continue;
			}
			dp[i][j] = dp[dp[i][j - 1]][j - 1];
		}
	}

	while (k--)
	{
		int l, r;
		cin >> l >> r;
		l--;
		r--;

		if (l > r)
			swap(l, r);

		cnt = 0;
		for (int j = lg - 1; j >= 0; j--)
		{
			if (dp[l][j] <= r)
			{
				l = dp[l][j];
				cnt += (1 << j);
			}
		}

		if (l < r)
			cnt++;

		cout << cnt << endl;
	}
}



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

const int MAX_N=100005;
int n,x;
int a[MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>x;
	for(int i=0;i<n;++i)
		cin>>a[i];
	a[n]=x;
	sort(a,a+n+1);
	int Min=1e9;
	for(int i=0;i<n;++i)
	{
		a[i]=a[i+1]-a[i];
		Min=min(Min,a[i]);
	}
	int ans=1;
	for(int i=Min;i>0;--i)
	{
		if(Min%i==0){
			bool boo=true;
			for(int j=0;j<n;++j)
				if(a[j]%i){
					boo=false;	break;
				}
			if(boo==true){
				ans=i;	break;
			}
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 640
n,c=gets.split.map(&:to_i)
d=[*0...c].map{gets.split.map(&:to_i)}
g=[*0...n].map{gets.split.map(&:to_i)}
l=[]
a=[0,0,0].map{Array.new(c,0)}
c.times{|q|
  n.times{|x|
    n.times{|y|
      a[(x+y)%3][q]+=d[g[y][x]-1][q]
    }
  }
}
[*0...c].permutation(3){|x,y,z|l.push(a[0][x]+a[1][y]+a[2][z])}
p l.min

Measured memory_bytes: 6268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  ll h;
  cin >>h;
  
  ll ans=0;
  ll i=1;
  while(h){
  	h/=2;
    ans+=i;
    i*=2;
  }
  cout << ans << endl;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int ans = 0;
    int index = 1;
    rep(i, N)
    {
        ans++;
        index = a[index - 1];
        if (index == 2)
        {
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 640
@S=map$|++,@p=@i=0..10**5;$\-=<>;sub f{my$U=pop;$p[$U]=$U-$p[$U]?f($p[$U]):$U}/ />${*a=-$'}||($v=f$`)-(f$a)&&($S[$p[$v]=f$a]+=$S[$v]),$a=$`for<>;$\+=$S[f${-$_}]for@i;print

Measured memory_bytes: 61184
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll i,x,bf=0,N,ans=1;
  cin>>N;
  vec m(N,1),M(N),sec(N);
  rep(i,N){
    cin>>M[i];
    if(i==0||M[i]!=M[i-1]){
      m[i]=M[i];
    }
  }
  rep(i,N)cin>>sec[i];
  brep(i,N){
    x=sec[i];
    if(x>bf||x==1||i==N-1){
      if(m[i]>x||M[i]<x){
        ans=0;
        break;
      }else{
        bf=m[i]=M[i]=x;
      }
    }else{
      if(m[i]==M[i]&&M[i]>x){
        ans=0;
        break;
      }else{
        chmin(M[i],x);
      }
    }
    ans=ans*(M[i]-m[i]+1)%mod;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
	
	int n; cin >> n;
	if (n == 2) {
		int o, e; cin >> o >> e;
		if (o == e) cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	const int p = n / 2;
	const int z = 100001;
	vector<int> o_num(z, 0), e_num(z, 0);
	for (int i = 0; i < n; i++) {
		int v; cin >> v;
		if (i % 2 == 0) o_num[v]++;
		else e_num[v]++;
	}
	int o_firstCnt = 0;
	int	o_secondCnt = 0;
	int o_firstCntValue = 0;
	int e_firstCnt = 0;
	int	e_secondCnt = 0;
	int e_firstCntValue = 0;
	for (int i = 0; i < z; i++) {
		if (o_firstCnt <= o_num[i]) {
			o_secondCnt = o_firstCnt;
			o_firstCnt = o_num[i];
			o_firstCntValue = i;
		}
		else {
			o_secondCnt = max(o_secondCnt, o_num[i]);
		}
		if (e_firstCnt <= e_num[i]) {
			e_secondCnt = e_firstCnt;
			e_firstCnt = e_num[i];
			e_firstCntValue = i;
		}
		else {
			e_secondCnt = max(e_secondCnt, e_num[i]);
		}
	}
	int ans;
	if (o_firstCntValue != e_firstCntValue) {
		ans = n - o_firstCnt - e_firstCnt;
	}
	else { // o_firstCntValue == e_firstCntValue
		ans = min(n - o_secondCnt - e_firstCnt, n - o_firstCnt - e_secondCnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4036
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  double a,b,c,PI=3.1415926535;
  cin >> a >> b >> c;
  printf("%.5f\n",a*b*sin(c*PI/180)/2);
  printf("%.5f\n",sqrt(a*a+b*b-2*a*b*cos(c*PI/180))+a+b);
  printf("%.5f\n",b*sin(c*PI/180));
  return 0;
}



Measured memory_bytes: 3400
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

typedef struct weightval{
  int64 w,v;
} node;

int cmp(const void *a,const void *b){
  node *x=(node *)a;
  node *y=(node *)b;
  if(x->w!=y->w) return x->w-y->w<0?-1:1;
  if(x->v!=y->v) return x->v-y->v<0?-1:1;
  return 0;
}

void enumerate(node *a,int64 *v,int64 *w,int n){
  a[0].v=0;
  a[0].w=0;
  int i;
  for(i=0;i<n;i++){
    int j;
    for(j=0;j<(1<<i);j++){
      int k=j+(1<<i);
      a[k].v=a[j].v+v[i];
      a[k].w=a[j].w+w[i];
    }
  }
  qsort(a,1<<n,sizeof(node),cmp);
  return;
}

void run(void){
  int n;
  int64 weight;
  scanf("%d%lld",&n,&weight);
  int64 v[40];
  int64 w[40];
  int i;
  for(i=0;i<n;i++) scanf("%lld%lld",v+i,w+i);
  const int alen=n/2;
  node *a=(node *)malloc(sizeof(node)*(1<<alen));
  const int blen=n-alen;
  node *b=(node *)malloc(sizeof(node)*(1<<blen));
  enumerate(a,v,w,alen);
  enumerate(b,v+alen,w+alen,blen);

  //printf("a\n");for(i=0;i<(1<<alen);i++) printf("%lld %lld\n",a[i].w,a[i].v);
  //printf("b\n");for(i=0;i<(1<<blen);i++) printf("%lld %lld\n",b[i].w,b[i].v);

  int64 *bmax=(int64 *)malloc(sizeof(int64)*(1<<blen));
  bmax[0]=b[0].v;
  for(i=1;i<(1<<blen);i++) bmax[i]=MAX(bmax[i-1],b[i].v);
  int64 max=0;
  for(i=0;i<(1<<alen);i++){
    if(a[i].w>weight) break;
    int l=0;
    int r=(1<<blen);
    while(l+1<r){
      int m=(l+r)/2;
      if(b[m].w<=weight-a[i].w){
	l=m;
      } else {
	r=m;
      }
    }
    max=MAX(max,a[i].v+bmax[l]);
  }
  printf("%lld\n",max);
  free(a);
  free(b);
  return;
}

int main(void){
  run();
  return 0;
}



Measured memory_bytes: 50832
n = int(input())
lired = [list(map(int,input().split())) for _ in range(n)]
liblue = [list(map(int,input().split())) for _ in range(n)]
lired = sorted(lired,key = lambda x:-x[1])
liblue = sorted(liblue,key = lambda x:x[0])
li = list(range(n))
cnt = 0
#print(lired)
#print(liblue)

for i in range(n):
  for j in li:
    if lired[i][0] < liblue[j][0] and lired[i][1] < liblue[j][1]:
      cnt += 1
      li.remove(j)
      break
print(cnt)

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

int main() {
 int a, b, k; cin >> a >> b >> k;
  int count = 0;
  int div;
  if(a>=b) div = b;
  else div = a;
  for(int i = div; count < k; i--){
    if(a%i ==0 && b%i == 0) count++;
    div = i;
  }
  cout << div << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("yes")  # type: str


def no():
    print("no")  # type: str


def solve(S: str):
    S = list(S)
    S.sort()
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            no()
            return
    yes()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <string>
#include <map>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <string.h>
#include <set>
#include <cstdlib>
#include <iostream>
#include <bits/stdc++.h>
#define pii pair<int,int> 
#define ll long long int 
#define sl(n) scanf("%lld",&n)
#define s(n) scanf("%d",&n)
#define f(i,n) for(int i=0;i<n;++i)
#define fo(i,n) for(int i=1;i<=n;++i)
#define fnm(n,m) for(ll i=n;i<m+1;++i)
#define pb push_back
#define pf printf
#define F first
#define S second
#define srt(v) sort(v.begin(),v.end());
#define srtc(v,cmp) sort(v.begin(),v.end(),cmp);
#define srta(v,n) sort(v,v+n);
const ll LL_INF=0x3f3f3f3f3f3f;
const ll MOD=1073741824;


using namespace std;


int T;
int n;
int arr[100005],dp[100005];

int gen(int i){
    if(i==n-1)return 0;
    int &ret = dp[i];
    if(~ret)return ret;
    ret=gen(i+1)+abs(arr[i]-arr[i+1]);
    if(i+2<n)ret=min(gen(i+2)+abs(arr[i]-arr[i+2]),ret);
    return ret;
}


int main(){
    // pf("\t\t\t***************************************************************************\n\n");
    // pf("\t\t\t***************************************************************************\n\n");
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    memset(dp,-1,sizeof dp);
    s(n);
    f(i,n)s(arr[i]);

    pf("%d\n",gen(0));

    return 0;
} 

Measured memory_bytes: 4096
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-15 10:45:30

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	int res = 0, cur = 0;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T'){
			cur++;
			res = max(res, cur);
		} else	cur = 0;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cstdio>
#define int long long
using namespace std;
int n,top,minn;
const int N=1000010;
int a[N],zhan[N],r[N],l[N];
long long ans;
signed main()
{
    cin>>n;
    for(int i=1;i<=n;++i)scanf("%lld",&a[i]);
    for(int i=1;i<=n;++i)r[i]=n+1,l[i]=0;
    for(int i=1;i<=n;++i)
    {
        while(top&&a[zhan[top]]>a[i])r[zhan[top--]]=i;
        l[i]=zhan[top];
        zhan[++top]=i;
    }
    for(int i=1;i<=n;++i)ans+=(r[i]-i)*(i-l[i])*a[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    if((s1.length()+1)==s2.length())
    {
        s1=s1+s2[s1.length()];
        if(s1==s2)
            cout<<"Yes";
        else
            cout<<"No";

    }
    else
        cout<<"No";

}


Measured memory_bytes: 3576
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
using ll = long long ;
using namespace std;
const ll maxn=2e5+5;
ll n,x,num[maxn];
int main(){
	ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0);
	cin>>n;
	for(int i=2;i<=n;i++){
		cin>>x;
		num[x]++;
	}
	for(int i=1;i<=n;i++){
		cout<<num[i]<<endl;
	}
}



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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

signed main() {
    int r;
    cin >> r;
    cout << 3*r*r << endl;
}

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

main(){
	int R,G,B,N;
	int ans=0;
	cin >> R >> G >> B >> N;
	for(int r=0;r<=N/R;r++){
		for(int g=0;g<=N/G;g++){
			if( (N-(r*R+g*G))%B==0 && (N-(r*R+g*G))>=0 ){
				ans++;
			}
		}
	}
	
	
	cout << ans <<endl;
}


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

using namespace std;

int h, w;
int field[100][100];

void deleteField(int x, int y, int fluit);
void Delete(int x, int y, int f);

int main() {
	int ans;
	string str;

	/*??\???*/
	cin >> h >> w;

	ans = 0;
	while (h && w) {
		for (int i = 0; i < h; i++) {
			/*????????¨?????\????????´??°???2?¬???????????????????*/
			cin >> str;

			for (int j = 0; j < w; j++) {
				switch (str[j]) {
					case '@':
						field[i][j] = 1;
						break;
					case '#':
						field[i][j] = 2;
						break;
					default:
						field[i][j] = 3;
				}
			}
		}

		/*???????????????????????????????????????????????????????????????????¶????*/
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (field[i][j] != 0) {
					ans++;
					deleteField(j, i, field[i][j]);

					/* Debug //
					for (int k = 0; k < h; k++) {
						for (int l = 0; l < w; l++) {
							cout << field[k][l];
						}
						cout << endl;
					}
					cout << "-----\n";

					getchar();
					//////////*/
				}

			}

		}

		cout << ans << endl;

		ans = 0;
		cin >> h >> w;
	}


}

void deleteField (int x, int y, int fruit) {
	field[y][x] = 0;

	if (x - 1 >= 0) {
		Delete(x-1, y, fruit);
	}
	if (x + 1 < w){
		Delete(x+1, y, fruit);
	}
	if (y - 1 >= 0) {
		Delete(x, y-1, fruit);
	}
	if (y + 1 < h) {
		Delete(x, y+1, fruit);
	}
}

void Delete(int x, int y, int f) {
	if (field[y][x] == f) {
		deleteField(x, y, f);
	}
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define mod 1000000007
int32_t main()
{
    int n,c5=0,i,z=0;
  	cin>>n;
  	if(n%2!=0)
      cout<<0<<endl;
  else
  {
    	//z=z+n/10;
    	i=10;
    int j;
    	while(i<=n)
        {
          	z=z+n/i;
          	i=i*5;
        }
    cout<<z<<endl;
  }
}

Measured memory_bytes: 256
n = int(input())
dp = [float('inf')]*(n+1)
dp[0] = 0
for i in range(n+1):
    for j in [6, 9]:
        cnt = 1
        while i+cnt <= n:
            if dp[i+cnt] > dp[i]+1:
                dp[i+cnt] = dp[i]+1
            cnt *= j
print(dp[-1])

Measured memory_bytes: 9492
#include <iostream>
#include <iomanip>

constexpr auto PI = 3.14159'26535'89793'23846'26433'83279'5028;

int main()
{
    int R;
    std::cin >> R;

    std::cout << std::setprecision(10) << 2 * R * PI << std::endl;

    return 0;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;


int main() {
    int n; cin >> n;
    int a,b;
    priority_queue<P,vector<P>, greater<P>> pq;
    rep(i,0,n){
        cin >> a >> b;
        pq.push({b,a});
    }
    ll t = 0;
    bool f = true;
    rep(i,0,n){
        P p = pq.top();
        if(p.first < t+p.second)
            f = false;

        t += p.second;
        pq.pop();
    }
    if(f) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 2420
n = int(input())
a = [int(i) for i in input().split()]
nC2 = [0 for i in range(n + 1)]
for i in range(2, n + 1):
    nC2[i] = i * (i - 1) // 2
cnt = [0]*n
for i in a:
    cnt[i - 1] += 1
res = 0
for i in cnt:
    res += nC2[i]
for i in a:
    print(res - nC2[cnt[i - 1]] + nC2[cnt[i - 1] - 1])


Measured memory_bytes: 24748
#include<stdio.h>
#include<stdlib.h>
#define N 10

struct Node
{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
};



struct Node *sum,*num;

void jastin(int hum)
{

  struct Node *a=sum;
  struct Node *b=num;
  struct Node *c;

  c=(struct Node *)malloc(sizeof (struct Node));
  c->key=hum;
  c->left=num;
  c->right=num;

  while(a!=num)
    {
      b=a;
      if(c->key<a->key)a=a->left;
      else a=a->right;
    }
  c->parent=b;
  if(b==num)sum=c;
  else{
    if(c->key<b->key)b->left=c;
    else b->right=c;
  }
}
void ma(int key)
{
  struct  Node  *x=sum;

  while(x!=num){
      if(x->key >key)
	{
	  x=x->left;
	}
      else if(x->key < key)
	{
	  x=x->right;
	}
      else{
	printf("yes\n");
	return;
      }
    }
  
  printf("no\n");
}

void zin(struct Node *rum)
{
  if(rum==num)return;
  zin(rum->left);
  printf(" %d",rum->key);
  zin(rum->right);
}
void xu(struct Node *yum)
{
  if(yum==num)return;
  printf(" %d",yum->key);
  xu(yum->left);
  xu(yum->right);
}
int main()
{
  int i,j,k;
  char tum[N];

  scanf("%d",&i);
  
  for(j=0;j<i;j++)
    {
      scanf("%s",tum);
      if(tum[0]=='i')
	{
	  scanf("%d", &k);
	  jastin(k);
	}else if(tum[0]=='f'){
	  scanf("%d", &k);
	  ma(k);
	} else{ 
	zin(sum);
	printf("\n");
	xu(sum);
	printf("\n");
      }
      
      
    }
  return 0;
}

  
  
			  
 



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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

signed main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(auto& x : a)
        cin >> x;
    vector<vector<ll>> dp(n, vector<ll>(n, 0));
    for(ll i = 0; i < n; ++i)
        for(ll j = i; j < n; ++j)
            dp[i][j] = ((n - (j - i)) % 2 == 1 ? -1e18 : 1e18);

    for(ll i = 0; i < n; ++i)
        dp[i][i] = (dp[i][i] < 0 ? 1 : -1) * a[i];

    for(ll k = 1; k < n; ++k){
        for(ll i = 0, j = k; j < n; ++i, ++j){
            bool sente = (n - (j - i)) % 2;
            if(sente){
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j]);
            }else{
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j]);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}


Measured memory_bytes: 72576
#include <bits/stdc++.h>
using namespace std;
vector<int> Zalgo(string S){
int n=S.size(), i=1, w=0, k; vector<int> Z(n); Z[0]=n;
while(i<n){
   while(i+w<n && S[w]==S[i+w]){ w++; }
   Z[i]=w; if(w==0){ i++; continue; }
   for(k=1; i+k<n && k+Z[k]<w; k++){ Z[i+k]=Z[k]; }
   i+=k; w-=k;
}
return Z;
}

int main(){
int N, ans=0; cin >> N;
string S; cin >> S;
for(int i=0; i<N-1; i++){
vector<int> Z(N-i); Z=Zalgo(S.substr(i));
for(int j=1; j<N-i; j++){ if(j>=Z[j]){ ans=max(ans, Z[j]); } }
}
cout << ans << "\n";
}

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

int a[2000];

signed main(){

  int n,k; cin >> n >> k;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    a[i] += a[i-1];
  }

  vector<int> vec;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j <= n; j++){
      vec.push_back(a[j] - a[i]);
      //cout << a[j] - a[i] << endl;
    }
  }

  int ans = 0;
  for(int i = 40; i >= 0; i--){
    int cnt = 0;
    int mask = ans + (1LL << i);
    for(int j = 0; j < vec.size(); j++){
      if((mask & vec[j]) == mask) cnt++;
    }
    if(cnt >= k) ans += pow(2,i);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6384
#include<cstdio>
#include<vector>
using namespace std;
const int MAX = 200010;
vector<int> v[MAX];
bool vis[MAX];
int val[MAX];
int ans[MAX];

void dfs(int x, int s = 0) {
    s += val[x];
    ans[x] = s;
    vis[x] = true;
    for(auto e: v[x]) {
        if(vis[e]) continue;
        dfs(e, s);
    }
}

int main () {
    int n, q;
    scanf("%d %d", &n, &q);
    for(int i = 0 ; i < n-1 ; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    while(q--) {
        int x, y;
        scanf("%d %d", &x, &y);
        val[x] += y;
    }
    dfs(1);
    for(int i = 1 ; i <= n ; i++) {
        printf("%d ", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 21120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 10;

struct node{ int x, w, id; } b[N];
inline bool operator < (const node &a, const node &b) {
	return (a.x < b.x) || (a.x == b.x && a.w < b.w) || (a.x == b.x && a.w == b.w && a.id < b.id);
}
int a[N];
int main() {
	int n, l, t; scanf("%d%d%d",&n,&l,&t);
	int x0, w0, ans = 1;
	rep(i,1,n) {
		scanf("%d",a + i); 
		int w; scanf("%d",&w);
		if (w == 1) b[i].x = ((a[i] + t) % l + l) % l;
		else b[i].x = ((a[i] - t) % l + l) % l;

		b[i].w = -w; b[i].id = i;

		if (i == 1) x0 = a[i], w0 = w;
		else if (w != w0) {
			if (w0 == 1) {
				int dis = (a[i] - x0 + l) % l;
				if (t * 2 >= dis) ans = (ans + (t * 2 - dis) / l + 1) % n;
			} else {
				int dis = (x0 - a[i] + l) % l;
				if (t * 2 >= dis) ans = (ans - (t * 2 - dis) / l - 1 + n) % n;
			}
		}
	}
	sort(b + 1, b + n + 1);
	int delta = 0;
	rep(i,1,n) if (b[i].id == 1) {
		delta = (i - ans + n) % n;
		break;
	}
	rotate(b + 1, b + 1 + delta, b + n + 1);
	rep(i,1,n) printf("%d\n",b[i].x);
	return 0;
}


Measured memory_bytes: 2816
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

	int N;
	char S[312345];

int main() {

	scanf("%d%s", &N, S);

	int count = 0;
	rep(i, N) if (i && S[i] == 'E') count++;
	int ans = count;

	rep(i, N - 1) {
		if (S[i] == 'W') count++;
		if (S[i + 1] == 'E') count--;
		ans = min(ans, count);
	}

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

	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var S = IO.GetString().ToCharArray();
            var T = IO.GetString().ToCharArray();
            var ans = 0;
            for(int i=0;i<3;i++)
            {
                if (S[i] == T[i])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 13140
from collections import deque
S=input()
N=int(input())
q = deque()
A = [input().split()]
for n in range(N-1):
  A.append(input().split())
for s in S:
  q.append(s)
top = True
for n in range(N):
  if A[n][0]=="1":
    top = not top
  elif A[n][1]=="1" and top or A[n][1]=="2" and not top:
    q.appendleft(A[n][2])
  else:
    q.append(A[n][2])
T = ""
while len(q)>0:
  if top:
    T+=q.popleft()
  else:
    T+=q.pop()
print(T)

Measured memory_bytes: 42740
// Author: Moulik
// Date Created: 07 June 2020
// Filename: A.cpp
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define what_is(x) cerr << "DEBUG::BEGIN\n\tVariable name:\n\t\t" << #x << "\n\tdata:\n\t\t" << x << "\nDEBUG::END" << endl;
#else
#define what_is(x) ;
#endif

// DEFINE OSTREAMS HERE

template<typename T1, typename T2>
ostream & operator<<(ostream &os, const pair<T1,T2> p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}

template<typename T>
ostream & operator<<(ostream &os, const vector<T> p){
    os << "{ ";
    for(auto i:p){
        os << i << ",";
    }
    os << "\b";
    os << "}";
    return os;
}

// DEFINE ISTREAMS HERE

template<typename T1, typename T2>
istream & operator >> (istream &in, pair<T1,T2> & p){
    in >> p.first >> p.second;
    return in;
}

// Sorts array in the given order {key is 0 indexed}
template<typename T>
void keySort(vector<T> & arr, vector<int> & key){
    int n = arr.size();
    if(key.size()!=n){
        throw runtime_error("Size of data array not equals to size of key array");
    }
    vector<T> ans(n);
    int ar[n];
    for(int i = 0; i < n; i++){
        ar[key[i]]=i;
    }
    for(int i = 0; i < n; i++){
        ans[i] = arr[ar[i]];
    }
    arr = ans;
}
void solve();

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}


void solve(){
    int arr[3];
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr,arr+3);
    if(arr[0]==5 && arr[1]==5 && arr[2]==7){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    ll a,b,c,x,y;
    ll min_p = INF * 10000000;
    cin >> a >> b >> c >> x >> y;
    for(ll i = 0; i <=  max(x, y) ; i ++) {
        ll p = max(x - i, (long long)0) * a + max(y - i, (long long)0) * b + i * c * 2;
        min_p = min(min_p, p);
    }
    cout << min_p << endl;
         
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 200010
#define int long long
#define ld long double
#define inf 2147483647
using namespace std;

struct point{
  ld x , y;
}now[MAXN] , forL[MAXN] , forR[MAXN] , t[MAXN];
int N;

bool cmp(point a , point b){
  return a.x < b.x;
}

ld solve(int l , int r){
  if(l == r)
    return inf;
  int mid = l + r >> 1;
  ld dir = (now[mid].x + now[mid + 1].x) / 2 , d1 = solve(l , mid) , d2 = solve(mid + 1 , r) , d = min(d1 , d2);
  int cntL = 0 , cntR = 0;
  for(int i = l ; i <= mid ; i++)
    if(dir - now[i].x <= d)
      forL[++cntL] = now[i];
  for(int i = mid + 1 ; i <= r ; i++)
    if(now[i].x - dir <= d)
      forR[++cntR] = now[i];
  int k = 1;
  for(int i = 1 ; i <= cntL ; i++){
    while(k <= cntR && forL[i].y - forR[k].y > d)
      k++;
    for(int j = k ; j <= cntR && forR[j].y - forL[i].y <= d ; j++)
      d = min(sqrt((forR[j].x - forL[i].x) * (forR[j].x - forL[i].x) + (forR[j].y - forL[i].y) * (forR[j].y - forL[i].y)) , d);
  }
  int p1 = l , p2 = mid + 1 , p3 = l;
  while(p1 <= mid && p2 <= r)
    if(now[p1].y < now[p2].y)
      t[p3++] = now[p1++];
    else
      t[p3++] = now[p2++];
  while(p1 <= mid)
    t[p3++] = now[p1++];
  while(p2 <= r)
    t[p3++] = now[p2++];
  for(int i = l ; i <= r ; i++)
    now[i] = t[i];
  return d;
}

main(){
  cin >> N;
  for(int i = 1 ; i <= N ; i++)
    cin >> now[i].x >> now[i].y;
  sort(now + 1 , now + N + 1 , cmp);
  cout << fixed << setprecision(9) << solve(1 , N);
  return 0;
}



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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] * a[1] / 2<< endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(pii& a, pii& b) {
	return a.first > b.first;
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

LL mod = 1000000007LL;

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

  LL N, M;
  cin >> N >> M;
  vector<LL> A(N);
  vector<LL> B(M);
  vector<pii> AA(N);
  vector<pii> BB(M);
  REP(i,N){
    cin >> A[i];
    AA[i] = make_pair(A[i], i);
  }
  REP(i,M){
    cin >> B[i];
    BB[i] = make_pair(B[i], i);
  }

  XSORT(AA);
  XSORT(BB);

  AA.push_back(make_pair(0, 0));
  BB.push_back(make_pair(0, 0));

  LL sum = 1;

  LL AA_idx = 0;
  LL BB_idx = 0;



  for (LL num = N * M; num >= 1;--num){
    LL placed_num = N * M - num;
    if(AA[AA_idx].first>num||BB[BB_idx].first > num){
      sum = 0;
      break;
    }
    if (AA[AA_idx].first == num && BB[BB_idx].first == num)
    {
      AA_idx++;
      BB_idx++;
    }else
    if(AA[AA_idx].first==num){
      AA_idx++;
      sum *= BB_idx;
      sum %= mod;
    }
    else
    if(BB[BB_idx].first==num){
      BB_idx++;
      sum *= AA_idx;
      sum %= mod;
    }else{
      sum *= AA_idx * BB_idx - placed_num;
      sum %= mod;
    }
  }

  cout << sum%mod << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int num[5001];
/*
int sum(int a,int b){
  int s=0;
  for(int i=0;i<b;i++){
    s+=num[a+i];
  }
  return s;
}
*/
int main(){
  int max;
  int n,sum;
  
  while(cin>>n,n){
    max=-10000000;
    // int sum=-10000000;
    for(int i=0;i<n;i++){
      cin>>num[i];
    }
    for(int i=0;i<n;i++){
      sum=0;
      for(int j=i;j<n;j++){
	sum+=num[j];
	if(max<sum)max=sum;
      }
    }
    cout<<max<<endl;
  }
}

Measured memory_bytes: 1176
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int k,n,i;
ll ans,s[nmax],gs[nmax],a[nmax],x;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>k;
    for(i=1;i<=n;i++)
	{
		cin>>a[i];
		s[i]=s[i-1]+a[i];
		gs[i]=gs[i-1]+max(0LL,a[i]);
	}
	for(i=n;i>=k;i--)
	{
		ans=max(ans,gs[i-k]+max(0LL,s[i]-s[i-k])+x);
		x+=max(0LL,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560