akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

#include <functional>
#include <limits>


using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

template<typename T>
class segment_tree{
	int n;
	T fval;
	function<T(T,T)> operation;
	vector<T> dat;
	
	T _query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l){
			return fval;
		}
		
		if(a <= l && r <= b){
			return dat[k];
		}else {
			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2 );
			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
			return operation(vl, vr);
		}
	}
	
public:
	
	segment_tree(){
		
	}
	
	segment_tree(int n_, T val, function<T(T,T)> fun){
		init(n_, val, fun);
	}
	
	~segment_tree(){
		
	}
	
	void init(int n_, T val, function<T(T,T)> fun){
		fval = val;
		
		operation = fun;
		
		n = 1;
		
		while(n < n_) n *= 2;
		
		dat.resize(2 * n - 1);
	
		for(int i = 0; i < 2 * n - 1; i++) dat[i] = fval;
	}

	void update(int k, T a){
		k += n - 1;
		dat[k] = a;
		while(k > 0){
			k = (k - 1) / 2;
			dat[k] = operation(dat[k*2 + 1],dat[k*2 + 2]);
		}
	}
	
	T query(int a, int b){
		return _query(a, b, 0, 0, n);
	}
	
};

signed main(){
	// cin.tie(nullptr);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int N, M;
	bool flag = true;
	string S;
	vector<pair<int,int>> temp;
	vector<int> ans;
	segment_tree<pair<int,int>> seg;
	
	cin>>N>>M;
	cin>>S;
	
	// seg.init(N+10,{INF, 0}, [](pair<int,int> first, pair<int,int> second){ if(first.first < second.first) return first; else second;});
	seg.init(N+10,{INF, 0}, [](pair<int,int> first, pair<int,int> second){ return min(first, second);});
	
	temp.resize(N+1, {INF,INF});
	ans;
	
	seg.update(0,{0,0});
	
	temp[0] = {0, INF};
	
	for(int i = 1; i <= N; i++){
		if(S[i] == '1') continue;
		pair<int,int> p = seg.query(max(i-M,0ll), i);
		// cout<<"i = "<<i<<" "<<max(i-M,0ll)<<" "<<p.first<<" "<<p.second<<endl;
		p.first++;
		
		temp[i] = {p.first, p.second};
		// temp[i] = {p.first, i};
		
		seg.update(i, {p.first, i} );
		
	}
	// for(int i = 0; i <= N; i++){
		// cout<<i<<" "<<temp[i].first<<" "<<temp[i].second<<endl;
	// }
	
	for(int i = N; i > 0;){
		if(temp[i].first  >= INF){
			flag = false;
			break;
		} else {
			ans.push_back(i-temp[i].second);
			i = temp[i].second;
		}
	}
	
	if(flag == false) cout<<-1<<endl;
	else {
		reverse(ans.begin(), ans.end());
		for(int i = 0; i < ans.size(); i++){
			if(i) cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 7160
#include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 10000;
typedef pair<int,int> PII;

int par[MAX_N];
int rank[MAX_N];
int t[MAX_N];
int temp[MAX_N];
int n,m;
int city;

class UF{
    public:
        void init(int n){
            rep(i,n){
                par[i]=i;
                rank[i]=0;
            }
        }

        int find(int x){
            if(par[x]==x)return x;
            return par[x]=find(par[x]);
        }
        void unite(int x,int y){
            x=find(x);
            y=find(y);
            if(x==y)return;
            if(rank[x]<rank[y])par[x]=y;
            else {
                par[y]=x;
                if(rank[x]==rank[y])rank[x]++;
            }
        }

        bool same(int x,int y){
            return (find(x)==find(y));
        }
};

int main(){
    cin>>n>>m;
    UF uf;
    int val=n;
    uf.init(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        if(!t[a])val--;
        if(!t[b])val--;
        t[a]=t[b]=1;
        uf.unite(a,b);
    }
    rep(i,n+1){
        if(t[i]){
            int p=uf.find(i);
            if(!temp[p])city++;
            temp[uf.find(i)]=1;
        }
    }
    cout<<abs(val-city)<<endl;
}

Measured memory_bytes: 1188
N = int(input())


q_li = []
for i in range(N):
    q = []
    for _ in range(int(input())):
        a, b = map(int,input().split())
        q.append((a,b)) 
    q_li.append(q)

def f(q_li, i):
    for n, q in enumerate(q_li):
        for a, b in q:
            a = a-1
            if (i >> n) & 1:
                if (i >> a) & 1 != b:
                    return 0
            #elif (i >> a) & 1 == b:
            #    return 0
    return str(bin(i)).count('1')

s_max = 0
for i in range(2 ** N):
    res = f(q_li, i)
    if res > s_max:
        s_max = res 
        
print(s_max)

Measured memory_bytes: 43116
while 1:
    N = int(input())
    if N == 0:
        break
    P = [list(map(int, input().split())) for i in range(N)]
    M = 366
    E = [[] for i in range(M)]
    dp = [[0]*(M+1) for i in range(M+1)]
    for t, (i, j, w) in enumerate(P):
        E[i-1].append((t, j, w))
    for i in range(M):
        Ei = E[i]
        for j in range(i, M):
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])
        for j in range(M-1, i, -1):
            v = dp[i+1][j+1]
            for _, k, w in Ei:
                if k < j:
                    dp[k+1][j+1] = max(dp[k+1][j+1], v + w)
                else:
                    dp[j+1][k+1] = max(dp[j+1][k+1], v + w)
        v = dp[i+1][i+1]
        for t1, k1, w1 in Ei:
            dp[i+1][k1+1] = max(dp[i+1][k1+1], v + w1)
            for t2, k2, w2 in Ei:
                if t1 <= t2:
                    break
                if k1 < k2:
                    dp[k1+1][k2+1] = max(dp[k1+1][k2+1], v + w1 + w2)
                else:
                    dp[k2+1][k1+1] = max(dp[k2+1][k1+1], v + w1 + w2)
    print(max(max(dpi) for dpi in dp))


Measured memory_bytes: 9288
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
const ll INF=99999999999999999;
ll a,b,c,d,e,f,g,ans=0;
ll beki[40];
ll saiki(ll A){
    ll x=0;
  if(A%4==1||A%4==2)x++;
    for(int i=39;i>0;i--){
        if(A-beki[i]>-1){
            x+=((A-beki[i]+1)%2)*beki[i];
            A=A-beki[i];
        }
    }
    return x;
}
int main(){
    ll A,B;

    cin>>A>>B;
    rep(i,40){
        if(i==0)beki[i]=1;
        else beki[i]=beki[i-1]*2;
    }

    cout<<((saiki(A-1))^(saiki(B)))<<endl;
  
}

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

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

    ll ans = 1;
    vector<ll> A(n);
    rep(i,n) cin >> A[i];
    sort(A.begin(), A.end());

    for (auto a : A) {
        if (sqrt(a)*sqrt(ans) > 1e9) {
            cout << -1 << endl;
            return 0;            
        }
        ans *= a;
        if (ans > (ll)1e18) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4056
# -*- coding: utf-8 -*-
import math
n, d = map(int, input().split())

x = list()
for _ in range(n):
    array = list(map(int, input().split()))
    x.append(array)

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        dist_sqrt = math.sqrt(dist)
        if dist == math.floor(dist_sqrt) ** 2:
            ans += 1

print(ans)

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

#define ll long long

ll a[100001],ct[100001];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n,sum=0;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		ct[a[i]]++;
		sum+=a[i];
	}
	ll q;
	cin>>q;
	for(ll i=0;i<q;i++){
		ll b,c;
		cin>>b>>c;
		ll t=ct[b];
		ct[c]+=t;
        ct[b]=0;
        sum-=b*t;
        sum+=c*t;
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 5088
#include <stdio.h>
const int MOD=1e9+7;
long long int pow(long long int a,int t){
    if(t==0)return 1LL;
    long long int temp=pow(a,t/2);
    temp*=temp;
    temp%=MOD;
    if(t&1){
        temp*=a;
        return temp%MOD;
    }
    return temp;
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    printf("%lld\n",pow(k,n)%MOD);
}


Measured memory_bytes: 2752
#見ながら､一応わかったつもり


def mi():return map(int,input().split())
#input
n,m,k=mi()
ab=[tuple(mi()) for _ in range(m)]
cd=[tuple(mi()) for _ in range(k)]


#class
class UnionFind:
  def __init__(self,n):
    self.parent=[i for i in range(n)]
    self.rank=[0]*n
    self.count=0
  def root(self,a):#rootを探す
    if self.parent[a]==a:
      return a
    else:
      self.parent[a]=self.root(self.parent[a])
      return self.parent[a]
  def is_same(self,a,b):#同じかどうか
    return self.root(a)==self.root(b)
  def unite(self,a,b):#根をまとめる
    ra=self.root(a)
    rb=self.root(b)
    if ra==rb:
      return
    if self.rank[ra]<self.rank[rb]:
      self.parent[ra]=rb
    else:
      self.parent[rb]=ra
    if self.rank[ra]==self.rank[rb]:
      self.rank[ra]+=1
      self.count+=1
      
            
uf=UnionFind(n)
friends=[0 for _ in range(n)]
blocks=[[] for _ in range(n)]


for a,b in ab:
  a=a-1
  b=b-1
  friends[a]+=1
  friends[b]+=1
  uf.unite(a,b)
  
  
for i in range(n):
  uf.root(i)
  
for c,d in cd:
  c-=1;d-=1
  blocks[c]+=d,
  blocks[d]+=c,
  
    
import collections 
ctr=collections.Counter()
for i in range(n):
  ctr[uf.parent[i]]+=1
  
  
ans=[0]*n
for i in range(n):
  tmp=ctr[uf.root(i)]-1-friends[i]
  for b in blocks[i]:
    if uf.is_same(i,b):
      tmp-=1
  ans[i]=tmp
print(*ans)
    
    

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

int main(){
    string S, T; cin >> S >> T;
    int ans =0;

    rep(i,3){

        if(S[i]==T[i]){
            ans++;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int a;
    cin >> a;
    cout<<a+a*a+a*a*a<<endl;
  return 0;
}

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

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

const int GEN = 1e9 + 7;

int DATA[9600]; // 10 ** 5 以下の素数の数は高々 9592 個

int main(){
  int n, m;
  scanf("%d%d",&n,&m);
  int k = ceil(sqrt(m));
  int p = 2;
  int maxD = 0; // 最大の割り切れる回数
  queue<int> times; // 素数で何回割り切れるかを記録する

  if(m % 2 == 0){ // 2で何回割り切れるか
    int a = 0;
    while(m % 2 == 0){
      m /= 2;
      a++;
    }
    times.push(a);
    if(a > maxD){ // maxDの更新
      maxD = a;
    }
  }
  p++;

  while(p <= k && p <= m){ // √ m 以下の 奇素数で何回割り切れるか
    if(m % p == 0){ // 割り切れなくなるまで
      int a = 0;
      while(m % p == 0){
        m /= p;
        a++;
      }
      times.push(a);
      if(a > maxD){ // maxDの更新
        maxD = a;
      }
    }
    p += 2;
  }
  if(m > 1){
    times.push(1); // mはこの時素数である
  }
  // Distrubute[p][q] := p人に対して, 区別のつかない q 個のものを配る通りの 10^9 + 7での余り
  vector< vector<long long int> > Distribute(n + 1);
  for(int i = 0;i <= n;i++){
    Distribute[i].resize(maxD + 1,0);
  }
  Distribute[0][0] = 1;
  for(int i = 1;i <= n;i++){
    Distribute[i][0] = 1;
    for(int j = 1;j <= maxD;j++){
      Distribute[i][j] = (Distribute[i][j - 1] + Distribute[i - 1][j]) % GEN;
    }
  }

  int ans = 1;
  while (!times.empty()) {
    int a =  times.front(); // 先頭要素を参照する
    times.pop(); // 先頭要素を削除
    ans = (ans * Distribute[n][a]) % GEN;
  }

  //答えの出力
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 27520
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
#define ms(s) memset(s, 0, sizeof(s))
const ll INF = 1e9;
inline ll read(){
    ll X = 0,w = 0 ;
    char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}
ll dat[100005];
ll sum[105][100005];
ll mod=1e9+7;
int main()
{
	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=n;i++)
	{
		cin>>dat[i];
	}
	sum[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		sum[i][0]=1;
	}
	for(ll i=1;i<=m;i++)
	{
		sum[0][i]=1;
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			if(dat[i]<=j)
			{
				sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-dat[i]-1]+mod)%mod;

			}
			else
			{
				sum[i][j]=(sum[i-1][j]+sum[i][j-1])%mod;
			}
		}
	}
  	ll ans=(sum[n][m]-sum[n][m-1]+mod)%mod;
  	cout<<ans;
  	return 0;
}

Measured memory_bytes: 80128
//ysh_gpta
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
typedef long long ll;
#define vb vector<bool>
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define mkp make_pair
#define pb push_back
#define INF 1000000000000000
#define MOD 1000000007
#define ff first
#define ss second
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//ll gcd( ll a, ll b ){if(b==0) return a; else return gcd( b, a%b );}
//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
//void printArray(vi &v){for(int i=0;i<v.size();i++) cout<<v[i]<<endl; cout<<endl; }
int main(){
   FastIO
   ll n;
   cin>>n;
   vvi v(n,vi(3));
   for(int i=0;i<n;i++)
   cin>>v[i][0]>>v[i][1]>>v[i][2];

   vvi dp(n,vi(3));
   dp[0][0] = v[0][0];
   dp[0][1] = v[0][1];
   dp[0][2] = v[0][2];
   for(int i=1;i<n;i++){
       dp[i][0] = v[i][0] + max(dp[i-1][1],dp[i-1][2]);
       dp[i][1] = v[i][1] + max(dp[i-1][0],dp[i-1][2]);
       dp[i][2] = v[i][2] + max(dp[i-1][0],dp[i-1][1]); 
   }
   cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
   return 0;
}

Measured memory_bytes: 11264
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	private final static long MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] L = new int[N];
		sc.fill(L);

		long max = 0;
		long sum = 0;
		for (int i = 0; i < L.length; i++) {
			max = Math.max(max, L[i]);
			sum += L[i];
		}

		sum -= max;

		System.out.println(max < sum ? "Yes" : "No");
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(b==1) return a;else if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    LL(n);
    if(n==1){
        out(0);
        return 0;
    }else{
        ll ans=0;
        ans=modpow(10,n,MOD);
        ans%=MOD;
        if(ans<0)ans+=MOD;
        ans-=modpow(9,n,MOD);
        ans%=MOD;
        if(ans<0)ans+=MOD;
        ans-=modpow(9,n,MOD);
        ans%=MOD;
        if(ans<0)ans+=MOD;
        ans+=modpow(8,n,MOD);
        ans%=MOD;
        if(ans<0)ans+=MOD;
        out(ans);
    }
}

Measured memory_bytes: 3816
from collections import deque

s_list = list(input())
d = deque(s_list)
q = int(input())
reverse = False

for _ in range(q):
	query= input().split()
	if int(query[0]) == 1:
		if reverse: reverse = False
		else: reverse = True
	elif int(query[0]) == 2:
		if int(query[1]) == 1:
			if reverse:
				d.append(query[2])
			else:
				d.appendleft(query[2])
		elif int(query[1]) == 2:
			if reverse:
				d.appendleft(query[2])
			else:	
				d.append(query[2])


if reverse:
	d.reverse()
for s in d:
  print(s, end ="")


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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

vector<int> g[N];
map<pii, int> W;
int col[N];
int dist[N];
bool vis[N];

void dfs(int x, int p, int d) {
	//cout << x << " " << p << " " << d << "\n";
	vis[x] = 1;
	dist[x] = d;
	int val = dist[x] - dist[p];
	if (val % 2 == 0) {
		col[x] = col[p];
	} else {
		col[x] = 1 - col[p];
	}

	for (int y: g[x]) {
		if (!vis[y]) {
			dfs(y, x, d + W[{x, y}]);
		}
	}
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

	int n;
	cin >> n;

	for (int i = 1; i < n; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		g[x].pb(y);
		g[y].pb(x);
		W[{x, y}] = w;
		W[{y, x}] = w;
	}

	dfs(1, 0, 0);

	for (int i = 1; i <= n; i++) {
		cout << col[i] << "\n";
	}

    return 0;
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << (X - Z) / (Y + Z) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define llint long long

using namespace std;

llint n, m;
llint G[25][25];
llint sum[1<<15];
llint dp[1<<15][25];

int main(void)
{
	cin >> n >> m;
	llint u, v, w;
	for(int i = 0; i < m; i++){
		cin >> u >> v >> w;
		u--, v--;
		G[u][v] = G[v][u] = w;
	}
	
	int N = 1<<n;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				if((i&(1<<j)) && (i&(1<<k))) sum[i] += G[j][k];
			}
		}
		sum[i] /= 2;
	}
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++) dp[i][j] = -1e18;
	}
	dp[1][0] = 0;
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				if(i&(1<<k)) continue;
				if(G[j][k] > 0) dp[i|(1<<k)][k] = max(dp[i|(1<<k)][k], dp[i][j]+G[j][k]);
			}
			int S = (N-1)-i+(1<<j);
			for(int k = S; k > 0; k = (k-1)&S){
				if((k&(1<<j)) == 0) continue;
				dp[i|k][j] = max(dp[i|k][j], dp[i][j]+sum[k]);
			}
		}
	}
	cout << sum[N-1] - dp[N-1][n-1] << endl;
	
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 2005;
int n, a[MX];
ll res;

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

	cin >> n;
	forn(i, n)
		cin >> a[i];
	sort(a, a+n);

	forn(i, n) forn(j, i) {
		int x = lower_bound(a, a+n, abs(a[i] - a[j]) + 1) - a;
		int y = upper_bound(a, a+n, a[i] + a[j] - 1) - a;

		res += y - x;
		if (x <= i && i < y) res--;
		if (x <= j && j < y) res--;
	}

	cout << res / 3 << endl;

	return 0;
} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	cin >> n;

	if ((int)((int)(n / 1.08) * 1.08) == n)cout << (int)(n / 1.08) << endl;
	else if ((int)(((int)(n / 1.08) + 1) * 1.08) == n)cout << (int)(n / 1.08) + 1 << endl;
	else cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,k,i,j,tmp;
	int x[1000];

	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++) scanf("%d",&x[i]);

	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){
			if(x[j-1]>x[j]){
				tmp = x[j-1];
				x[j-1] = x[j];
				x[j] = tmp;
			}
		}
	}

	int s=0;
	for(i=0;i<k;i++) s += x[i];

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

	return 0;
}



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

using namespace std;
using ll = long long;


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];

    for(int i = k; i < n; i++) {
        cout << (a[i] > a[i - k] ? "Yes" : "No") << endl;
    }

}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2000010,ha=998244353;
int n,m,inv[N],fac[N],invfac[N];
int qpow(int a,int b)
{
    int re=1;
    while(b)
    {
        if(b&1)re=re*a%ha;
        a=a*a%ha,b>>=1;
    }
    return re;
}

int C(int x,int y)
{
    return fac[x]*invfac[y]%ha*invfac[x-y]%ha;
}
signed main()
{
    invfac[0]=fac[0]=1;
    for(int i=1;i<=2000000;i++)inv[i]=qpow(i,ha-2),fac[i]=fac[i-1]*i%ha,invfac[i]=invfac[i-1]*inv[i]%ha;
    scanf("%lld%lld",&n,&m);
    if(n>m)swap(n,m);
    int ans=n*C(n+m,n)%ha;
    for(int i=1;i<=n;i++)
        ans=(ans-C(i+i-1,i)*C(m-i+n-i,m-i)%ha+ha)%ha;
    printf("%lld",(n+m-ans*qpow(C(m+n,m),ha-2)%ha+ha)%ha);
    return 0;
}



Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 1005, MAXS = MAXN*MAXN, MOD = 1000000007;

ll N, M, R[MAXN], C[MAXN], posRow[MAXS], posCol[MAXS], greaterRow[MAXS], greaterCol[MAXS];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> N >> M;
    for (ll i = 1; i <= N; i++) {
        cin >> R[i];
        if (posRow[i] != 0) {
            cout << "0\n";
            return 0;
        }
        posRow[R[i]] = i;
        greaterRow[R[i]-1] = 1;
    }
    for (ll i = 1; i <= M; i++) {
        cin >> C[i];
        if (posCol[C[i]] != 0) {
            cout << "0\n";
            return 0;
        }
        posCol[C[i]] = i;
        greaterCol[C[i]-1] = 1;
    }
    
    for (ll i = N*M-1; i >= 1; i--) {
        greaterRow[i] += greaterRow[i+1];
        greaterCol[i] += greaterCol[i+1];
    }
    
    ll ans = 1;
    for (ll i = N*M; i >= 1; i--) {
        if (posRow[i] == 0 && posCol[i] == 0) ans = ans*(greaterRow[i]*greaterCol[i] - (N*M-i))%MOD;
        else if (posRow[i] == 0) ans = ans*greaterRow[i]%MOD;
        else if (posCol[i] == 0) ans = ans*greaterCol[i]%MOD;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 20736
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vector<ll> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    for (int i = 0; i < N; i++) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    int a = 0, c = 0;
    ll res = 0;
    for (int b = 0; b < N; b++) {
      while (a < N && A[a] < B[b]) ++a;
      while (c < N && C[c] <= B[b]) ++c;
      res += 1ll * a * (N - c);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
 int main(void)
 {
     char o;
     int A,B;

     scanf("%d %c %d",&A,&o,&B);

     if(o=='+') printf("%d\n",A+B);
     if(o=='-') printf("%d\n",A-B);

     return 0;
 }



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cinm(char, 4, m);
    Cout(m['2']);
}





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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r=sc.nextInt();
		int g=sc.nextInt();
		int b=sc.nextInt();
		int n=sc.nextInt();
		
		int shutsuryoku = 0;
		
		for(int i=0;i<n/r+1;i++) {
			shutsuryoku += howmany(n-r*i, g, b);
		}
		System.out.print(shutsuryoku);
	}
	
	public static int howmany(int max, int a, int b) {
		int kaeru = 0;
		for(int i=0;i<max/a+1;i++) {
			if((max-a*i)%b==0) {
				kaeru++;
			}
		}
		return kaeru;
	}

}

Measured memory_bytes: 23252
#include <cstdio>

const int MAX = 45;

int fib_num[MAX];

int fib(int n)
{
  if (fib_num[n] != 1)
    return fib_num[n];

  if (n == 0 || n == 1)
    return 1;
  else
    return fib_num[n] = fib(n - 1) + fib(n - 2);
}

int main()
{
  for (int i = 0; i < MAX; ++i)
    fib_num[i] = 1;

  int n;
  scanf("%d", &n);
  printf("%d\n", fib(n));

  return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int N;
  cin >> N;
  map<string, int> mp;
  for (int i = 0; i < N; i++)
  {
    string S;
    cin >> S;
    mp[S]++;
  }
  int maxv = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++)
  {
    maxv = max(maxv, itr->second);
  }
  for (auto itr = mp.begin(); itr != mp.end(); itr++)
  {
    if (itr->second == maxv)
      cout << itr->first << endl;
  }
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */



signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int A,B,C;
  cin >> A >> B >> C;
  cout << min({A+B,B+C,C+A}) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define int long int
#define hell (int)(1e9+7)


using namespace std;

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

void solve(){
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector < vector <int> > dp(n,vector <int> (64,0));
    bitset <64> b(a[n-1]);
    for(int i=0;i<64;i++)
        dp[n-1][i]=b[i];
    int ans=0;
    for(int i=n-2;i>=0;i--){
        bitset <64> bb(a[i]);
        for(int j=0;j<64;j++){
            int next;
            if(bb[j]==0)
                next=dp[i+1][j];
            else
                next=n-1-i-dp[i+1][j];
            ans=(ans+power(2,j)*next)%hell;
            dp[i][j]=dp[i+1][j]+bb[j];
        }
    }
    cout<<ans;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 164352
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),OUT(YES),OUT(NO))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 998244353;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
LL A[SIZE],B[SIZE],C[SIZE];
LL solve(){
	int N;
	string s;
	cin >> N;
	cin >> s;
	int alpha='z'-'a'+1;
	REP(i,s.size()){
		s[i]=(s[i]-'A'+N)%alpha+'A';
	} 
	cout <<s << endl;
	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	string s;
	LL T;
	DEFAULT;
	
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}

Measured memory_bytes: 13312
#include<stdio.h>
int main()
{
  int R;
  scanf("%d", &R);
  
  if (R<1200)
  {
    printf("ABC");
  }
  
  else if (R>=2800)
  {
    printf("AGC");
  }
  
  else
  {
    printf ("ARC");
  }
  
  return 0;
}

Measured memory_bytes: 128
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
A = l()
ruiseki = [0]+list(itertools.accumulate(A))
i = bisect.bisect_left(ruiseki,sum(A)/2)
print(min(abs(sum(A[:i])-sum(A[i:])),abs(sum(A[:i-1])-sum(A[i-1:]))))


Measured memory_bytes: 32448
#include <bits/stdc++.h>
using namespace std;
 
int N;
string S;
 
//0がSで1がW
 
vector<int> zoo(int i,int j){
  vector<int> T(N+1);
  T[0]=i,T[1]=j;
  for(int i=1;i<N;++i){
    if(S[i]=='o' && T[i]==0) T[i+1]=T[i-1];
    if(S[i]=='o' && T[i]==1) T[i+1]=1-T[i-1];
    if(S[i]=='x' && T[i]==0) T[i+1]=1-T[i-1];
    if(S[i]=='x' && T[i]==1) T[i+1]=T[i-1];
  }
 
  return T;
}
 
bool check(vector<int> T){
  if(T[0]==0){
    if(S[0]=='o' && T[N-1]==T[1]) return true;
    if(S[0]=='x' && T[N-1]!=T[1]) return true;
    else return false;
  }
    if(T[0]==1){
    if(S[0]=='o' && T[N-1]==T[1]) return false;
    if(S[0]=='x' && T[N-1]!=T[1]) return false;
    else return true;
  }
}
 
 
int main(){
  cin>>N;
  cin>>S;
  bool frag=false;
  for(int i=0;i<2;++i){
    for(int j=0;j<2;++j){
      vector<int> T(N+1);
      T=zoo(i,j);
      if(T[0]==T[N] && check(T)){
        for(int i=0;i<N;++i){
          if(T[i]) cout<<'W';
          else cout<<'S';
        }
        cout<<endl;
        frag=true;
      }
      if(frag) break;
    }
    if(frag) break;
  }
 
  if(!frag) cout<<-1<<endl;
 
}

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

using namespace std;
typedef long long ll;

int main(int argc, char const *argv[])
{
	string S;
	string ans = "Yes";
	cin >> S;
	for (int i = 0; i < S.size(); i = i+2)
	{
		if (S[i] == 'L')
		{
			ans = "No";
		}
	}

	for (int i = 1; i < S.size(); i= i+2)
	{
		if (S[i] == 'R')
		{
			ans = "No";
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

cnt=0
temp=1
pre_str=a[0]
for i in range(1,n):
    if a[i]==pre_str:
        temp+=1
    else:
        pre_str=a[i]
        temp=1

    if temp%2==0:
        cnt+=1
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int lim = 100;

string solve(string hs){
    int from_y, from_x, to_y, to_x;
    cin >> from_y >> from_x >> to_y >> to_x;
    // init
    char board[lim][lim];
    for(int i=0; i<lim; i++){
        for(int j=0; j<lim; j++) board[i][j] = ' ';
    }

    //盤面を復元
    int y = 0;
    int x = 0;
    for(char c: hs){
        if(c == 'b'){
            board[y][x] = 'b';
            x++;
        } 
        else if(c == '/'){
            y++;
            x = 0;
        }
        else {
            int num = (c - '0');
            for(int i=0; i<num; i++){
                board[y][x] = '.';
                x++;
            }
        }
    }

    //ボールを移動
    board[to_y-1][to_x-1] = 'b';
    board[from_y-1][from_x-1] = '.';
    

    //圧縮
    string ret = "";
    for(int i=0; i<=y; i++){
        for(int j=0; j<x; j++){
            if(board[i][j] == '.'){
                int cnt = 0;
                int nx = j;
                while(board[i][nx] == '.'){
                    cnt++;
                    nx++;
                }
                ret += to_string(cnt);
                j = nx-1;
            }
            else if(board[i][j] == 'b') ret += "b";
        }
        if(i != y) ret += "/";
    }
    return ret;
}

int main(){
    while(true){
        string hs;
        cin >> hs;
        if(hs == "#") return 0;
        cout << solve(hs) << endl;
    }
    
}


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

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  int n,m;
  cin>>n>>m;
  vi a(n);
  rep(i,n) cin>>a[i];
  sort(all(a)); reverse(all(a));
  int p=0;
  rep(i,n) p+=a[i];
  YesNo(a[m-1]*4*m>=p);
}

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


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>
#include <complex>

using namespace std;
typedef long long li;
typedef pair <li, li> pi;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef complex<double> pt;

struct ShortestPath {
    struct edge { int to; double cost; };
    int v;
    vector<vector<edge> > g;
    ShortestPath(int _v): v(_v), g(v) {}
    void add_edge (int from, int to, double cost) {
        g[from].push_back((edge){to, cost});
    }
    vector<double> shortest_path(int init) {
        vector<double> min_cost(v, 1e100);
        priority_queue<pair<double, int> > q;
        min_cost[init] = 0;
        q.push(make_pair(0, init));
        while (not q.empty()) {
            double cost = -q.top().first;
            int pos = q.top().second;
            q.pop();

            for (int i = 0; i < g[pos].size(); ++i) {
                int npos = g[pos][i].to;
                double ncost = cost + g[pos][i].cost;
                if (ncost < min_cost[npos]) {
                    min_cost[npos] = ncost;
                    q.push(make_pair(-ncost, npos));
                }
            }
        }
        return min_cost;
    }

    double shortest_path(int s, int t) {
        return shortest_path(s)[t];
    }
};

pt read() {
    double x, y;
    cin >> x >> y;
    return pt(x, y);
}

int main() {
    const pt start = read();
    const pt goal = read();

    int n;
    cin >> n;

    vector<pt> c(n);
    vector<double> r(n);

    rep(i, n) {
        c[i] = read();
        cin >> r[i];
    }

    c.push_back(start);
    r.push_back(0);
    c.push_back(goal);
    r.push_back(0);

    n += 2;
    ShortestPath sp(n);

    rep(i, n) {
        rep(j, i) {
            double cost = max(0., abs(c[i] - c[j]) - r[i] - r[j]);
            sp.add_edge(i, j, cost);
            sp.add_edge(j, i, cost);
        }
    }

    cout.precision(12);
    cout << sp.shortest_path(n - 2, n - 1) << endl;


    return 0;
}


Measured memory_bytes: 20612
#include <iostream>
#include <vector>
#include <algorithm>
#define pii pair<int, int>
#define fst first
#define snd second
#define pub push_back
#define vi vector<int>
#define ll long long

using namespace std;

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b; cin >> a >> b;
	cout << a * b << "\n";
	return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,h;
    cin>>n>>h;
    vector<ll> a(n),b(n);

    rep(i,n){
        cin>>a[i]>>b[i];
    }

    sort(all(a),greater<ll>());
    sort(all(b),greater<ll>());

    for(ll bi:b){
        if(bi < a[0] || h <= 0)break;
        h -= bi;
        ++ans;
    }
    ans += max(0LL,(a[0]+h-1)/a[0]);

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 1792