akhauriyash/Code-Regression huggingface dataset:
/*
    NO 
        TIME 
            TO 
                DIE
                    --007
                            */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define OS //single input use oeis
lli INF=1e17;
lli eps=1e-8;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y-x)>>(31))&(x^y))^y; }
int fmi(int x, int y) { return (((y-x)>>(31))&(x^y))^x; }
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,z,k,x,m;
const double pi=3.14159265358979323846;
lli add(lli a, lli b) {
 	lli res = a + b;
 
 	while (res >= mod) res -= mod;
 
 	while (res < 0) res += mod;
 
 	return res;
}
 lli me(lli a,lli b)
{
    lli res=1;
    while(b)
    {
        if(b&1)
        res=(res%mod*a%mod)%mod;
        a=a*a;
        a%=mod;
        b=b>>1;
    }
    return res;
}
lli mI(lli a)
{
    return (me(a,mod-2)%mod+mod)%mod;
}
// Thi
//matrix exponentiation is associative and distributive
// lli dp[2][2000005][2];
int lis(vector<lli> a)
{
    set < int > s;
set < int > :: iterator it;

n=a.size();

for(int i=0;i<n;i++)
{
    s.insert(a[i]);
    
    it = s.upper_bound(a[i]);

    if(it != s.end())
        s.erase(it);
}

return s.size();
}
int main()
{
 IO;
 OS;
 cin>>n;
 lli a[n+1];
 map<string,lli> ml;
 lli mx=0;
 for(int i=1;i<=n;i++)
 {
     string s;
     cin>>s;
     ml[s]++;
     mx=max(mx,ml[s]);
}
for(auto &j: ml)
{
    if(j.second==mx)
    cout<<j.first<<"\n";
}
}

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

int N;
const int MAX_N = 200005;
int as[MAX_N];
int ac[MAX_N], bcc[MAX_N];
std::vector<std::pair<int, int>> bccc;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    as[i] = v;
    ac[v]++;
  }
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    bcc[v]++;
  }
  for (int i = 0; i < MAX_N; ++i) {
    if (bcc[i]) bccc.push_back({i, bcc[i]});
  }
  bool doable = true;
  for (auto& kv: bccc) {
    if (kv.second + ac[kv.first] > N) {
      doable = false;
      break;
    }
  }
  if (!doable) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  std::vector<int> ans;
  auto eng = std::default_random_engine(12432);
  while (1) {
    auto bc = bccc;
    std::shuffle(bc.begin(), bc.end(), eng);
    auto iter = bc.begin();
    ans.clear();
    int idx = 0;
    while (bc.size()) {
      int to_remove = -1;
      if (iter->first == as[idx]) {
        iter++;
        if (bc.size() == 1) break;
        if (iter == bc.end()) iter = bc.begin();
      }
      while (as[idx] != iter->first) {
        idx++;
        iter->second--;
        ans.push_back(iter->first);
        if (iter->second == 0) {
          to_remove = iter->first;
          break;
        }
      }
      if (to_remove >= 0) {
        std::swap(*iter, *(--bc.end()));
        bc.pop_back();
        iter = bc.begin();
      }
    }
    if (ans.size() == N) break;
  }
  for (int i : ans) printf("%d ", i);
  printf("\n");
}


Measured memory_bytes: 10424
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  int n;
  long long int power = 1;
  cin >> n;
  
  for(int i = 1; i < (n+1);i++)
  {
    power *= i;
    power %= (1000000000 + 7);
  }
  cout << power;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,x,t,i,np=15,res=0;
  int p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
  int c[5];
  cin >> n;
  fill(c,c+5,0);
  for(i=0;i<np;i++){
    x=n;
    t=0;
    while(x>0){
      t+=x/p[i];
      x/=p[i];
    }
    if(t>=74)
      c[0]++;
    if(t>=24)
      c[1]++;
    if(t>=14)
      c[2]++;
    if(t>=4)
      c[3]++;
    if(t>=2)
      c[4]++;
  }
  res=c[0]+c[1]*(c[4]-1)+c[2]*(c[3]-1)+c[3]*(c[3]-1)*(c[4]-2)/2;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3620
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n;
  cin >> n;
  if (n == 1)
  {
    YES(true);
    return 0;
  }
  ll a[100010];
  rep(i, n) cin >> a[i];
  a[n] = a[0];
  ll sum = 0;
  rep(i, n) sum += a[i];
  ll sum2 = n * (n + 1) / 2;
  if (sum % sum2 != 0)
  {
    YES(false);
    return 0;
  }
  ll ope = sum / sum2;
  ll d[100010];
  rep(i, n)
  {
    d[i] = a[i + 1] - a[i];
    d[i] -= ope;
  }

  bool can = true;
  rep(i, n)
  {
    if (d[i] > 0 || d[i] % n != 0)
    {
      can = false;
      break;
    }
  }
  YES(can);
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
    if A[i]%2 == 0:
        if A[i]%3 == 0 or A[i]%5 == 0:
            count += 1
        else:
            count += 0
    else:
        count += 1
if int(count) == N:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,k; cin >> n>>k;
  vi snuke(n,0);
  rep(i,k){
    int d; cin >> d;
    rep(j,d) {
      int a; cin >> a; a--;
      snuke[a]++;
    }
  }
  int ans = 0;
  rep(i,n) {
    if (snuke[i] == 0) ans++; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n;
cin >>n;
map<int,int>a;
for(int i=0;i<n;i++){
    int z;
    cin >> z;
    if(a.count(z))a.at(z)++;
    else a[z]=1;
}
int ans = 0;
for(auto z:a){
    if(z.second%2!=0)ans++;
}
cout << ans << endl;
}







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

const int MAX_K = (int)3000 + 5;

int x[MAX_K][MAX_K];
int n, k;

int getsize(int x1, int y1, int x2, int y2) {
  return x[x2][y2] - x[x2][y1] - x[x1][y2] + x[x1][y1];
}

int main() {
    scanf("%d %d", &n, &k);

    int a, b;
    char c;
    for (int i = 0; i < n; ++i) {
      scanf("%d %d %c", &a, &b, &c);
			if(c == 'W') b+=k;
      // a %= 2 * k, b %= 2 * k;
      x[a % (2 * k) + 1][b % (2 * k) + 1] += 1;
    }

    for (int i = 1; i <= 2 * k; ++i) for (int j = 1; j <= 2 * k; ++j) {
			x[i][j] = x[i][j] + (x[i - 1][j] + x[i][j - 1] - x[i - 1][j - 1]);
		}

    int ans = 0, dual, sum;

    for (int i = 1; i <= k; ++i) for (int j = 1; j <= k; ++j){
            sum = getsize(0, 0, i, j);
            sum += getsize(i, j, k + i, k + j);
            sum += getsize(k + i, k + j, 2 * k, 2 * k);
            sum += getsize(k + i, 0, 2 * k, j);
            sum += getsize(0 ,k + j, i, 2 * k);
						dual = n - sum;
						sum = max(dual, sum);
            ans = max(ans, sum);
        }

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


Measured memory_bytes: 24832
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int N = 2e5 + 7;

vector <pair <int, int>> who[N];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  for (int a = -1000; a <= 1000; ++a) {
    for (int b = -1000; b <= 1000; ++b) {
      if (a * a + b * b < N) {
        who[a * a + b * b].push_back({a, b});
      }
    }
  }

  int n, d1, d2;
  cin >> n >> d1 >> d2;
  int m = 2 * n;
  vector <vector <int>> g1(m * m), g2(m * m);
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      for (auto p : who[d1]) {
        int x = i + p.first, y = j + p.second;
        if (0 <= x && x < m && 0 <= y && y < m) {
          g1[i * m + j].push_back(x * m + y);
        }
      }
      for (auto p : who[d2]) {
        int x = i + p.first, y = j + p.second;
        if (0 <= x && x < m && 0 <= y && y < m) {
          g2[i * m + j].push_back(x * m + y);
        }
      }
    }
  }
  vector <int> c1(m * m, -1), c2(m * m, -1);
  function <void(int, vector <vector <int>> &, vector <int> &)> dfs = [&] (int u, vector <vector <int>> &g, vector <int> &c) {
    for (auto v : g[u]) {
      if (c[v] == -1) {
        c[v] = c[u] ^ 1;
        dfs(v, g, c);
      }
    }
  };
  for (int i = 0; i < m * m; ++i) {
    if (c1[i] == -1) {
      c1[i] = 0;
      dfs(i, g1, c1);
    }
  }
  for (int i = 0; i < m * m; ++i) {
    if (c2[i] == -1) {
      c2[i] = 0;
      dfs(i, g2, c2);
    }
  }
  for (int t1 = 0; t1 < 2; ++t1) {
    for (int t2 = 0; t2 < 2; ++t2) {
      vector <pair <int, int>> have;
      for (int i = 0; i < m * m; ++i) {
        if (c1[i] == t1 && c2[i] == t2) {
          have.push_back({i / m, i % m});
        }
      }
      if ((int)have.size() >= n * n) {
        for (int i = 0; i < n * n; ++i) {
          cout << have[i].first << ' ' << have[i].second << '\n';
        }
        return 0;
      }
    }
  }
}



Measured memory_bytes: 136184
n, k = map(int, input().split())
import math

def get_p(nums,k):
    p=1/(2**math.ceil(max(math.log(k/nums,2),0)))
    return p

ans=0
for nums in range(n):
    ans+=get_p(nums+1,k)
    
print("{0:.20f}".format(ans/n))

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

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

#define MAXX 500005
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long

#define mod  1000000007


map<ll, bool> mp;

int main()
{
	FAST;
	int n;
	cin >> n;
	
	int m ;
	bool flag = true;
	for(int i = 0; i < n; i ++){
		int a;
		cin >> a;
		if(i == 0){
			m = a;
		}
		else{
			m = __gcd(m, a);
		}
		if(flag){
			for(int j = 2; j * j <= a; j ++){
			if(a % j == 0){
				int k1 = a / j;
				if(mp[k1]){
					flag = false;
				}
				if(mp[j] && j != k1){
					flag = false;
				}
				mp[k1] = true;
				mp[j] = true;
			}
		}
		
			if(mp[a] == true){
				flag = false;
			}
			if(a != 1)
				mp[a] = true;
			
		}
		
	}
	
	
	
	
	if(flag){
			cout << "pairwise coprime";
			return 0;
	}
		if(m == 1){
			cout <<  "setwise coprime";
			return 0;
		}
	
	
		cout << "not coprime"; return 0;
	
	
		
	
	
	return 0;
}

Measured memory_bytes: 8564
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
 
typedef struct Eachtop {
  double x;
  double y;
  struct Eachtop *n;
} Top;
 
Top *tenode, *lnode, *tnode;
 
void makenewpoint(Top* a, Top* b){
  Top *fnode, *snode, *thnode;
  fnode = (Top*)malloc(sizeof(Top));
  fnode->x = (b->x - a->x)/ 3.0+a->x;
  fnode->y = (b->y - a->y)/ 3.0+a->y;
  snode = (Top*)malloc(sizeof(Top));
  snode->x = (b->x - a->x)/ 3.0*2+a->x;
  snode->y = (b->y - a->y)/ 3.0*2+a->y;
  thnode = (Top*)malloc(sizeof(Top));
  thnode->x =1/sqrt(3.0)* ((b->x - a->x) * cos(M_PI/6.0) - (b->y - a->y)*sin(M_PI/6.0)) + a->x;
  thnode->y =1/sqrt(3.0)* ((b->x - a->x) * sin(M_PI/6.0) + (b->y - a->y)*cos(M_PI/6.0)) + a->y;
  a->n = fnode;
  fnode->n = thnode;
  thnode->n = snode;
  snode->n = b;
  tnode = b;
}
int main(void){
  int m, i;
  scanf("%d", &m);
  tenode = NULL;
  lnode = NULL;
  tenode = (Top*)malloc(sizeof(Top));
  tenode->x = 0;
  tenode->y = 0;
  lnode = (Top*)malloc(sizeof(Top));
  lnode->x = 100;
  lnode->y = 0;
  tnode = tenode;
  tenode->n = lnode;
  lnode->n = NULL;
  for(i=0; i<m ;i++){
    tnode = tenode;
    while(tnode != lnode)
      makenewpoint(tnode, tnode->n);
  }
  tnode = tenode;
  while(tnode != NULL){  
    printf("%f %f\n", tnode->x, tnode->y);
    tnode = tnode->n;
  }
  return 0;
}



Measured memory_bytes: 2112
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
  int v[100],c[100];
int main(){
  int n;cin>>n;
  int i;
  for(i=0;i<n;i++){
    cin>>v[i];
  }
  for(i=0;i<n;i++){
    cin>>c[i];
  }
  int ans=0;
  for(i=0;i<n;i++){
    if(v[i]>c[i]) ans+=v[i]-c[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i, n) {
    cin >> v[i];
  }
  double value=0;
  sort(v.begin(), v.end());

  value = (v[0] + v[1]) / 2;
  if(n > 2) {
    for(int i = 2; i < n; ++i) {
      value = (value + v[i]) / 2;
    }
  }

  cout << value << endl;

  return 0;
}


Measured memory_bytes: 256
K = int(input())
lun = [0,1,2,3,4,5,6,7,8,9]

if K <= 9 :
    print(lun[K])
else :
    def dfs(digit, max_digit, cur, K) :
        if digit == max_digit :
            lun.append( "".join(cur) )
            if len(lun) == K :
                return True
            return False
        elif digit > max_digit :
            return False

        c = int(cur[-1])
        for i in [-1,0,1] :
            if c+i < 0 or c+i > 9 :
                continue
            cur.append(str(c+i) )
            if dfs(digit+1, max_digit, cur, K) :
                return True
            cur.pop()
        return False

    max_digit = 2
    stop = False
    while True :
        for i in range(1, 10) :
            cur = [str(i)]
            if dfs(1, max_digit, cur, K+1) :
                stop = True
                break 
        if stop :
            break 
        max_digit += 1

    print(lun[-1])

Measured memory_bytes: 10156
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n, m = map(int, sys.stdin.readline().split())
    lrds = ((map(int, line.split())) for line in sys.stdin.readlines())

    g = tuple([] for _ in range(n))
    x = [None] * n

    for l, r, d in lrds:
        l -= 1
        r -= 1
        g[l].append((r, d))
        g[r].append((l, -d))

    for i in range(n):
        if x[i] is not None:
            continue
        stack = [i]
        x[i] = 0
        while len(stack):
            v = stack.pop()
            for u, d in g[v]:
                if x[u] is None:
                    stack.append(u)
                    x[u] = x[v] + d

    for v in range(n):
        for u, d in g[v]:
            if x[v] + d != x[u]:
                print('No')
                sys.exit()

    print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 77380
import java.io.IOException;
import java.util.Scanner;
 
public class Main {
 public static void print(int a,int b,int c){
	 System.out.print(a);
	 System.out.print(" ");
	 System.out.print(b);
	 System.out.print(" ");
	 System.out.println(c);
 }
    public static void main(String[] args) throws IOException {
             
       Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      
      if(a<=b && b<=c){
    	print(a,b,c);
      }
      else if(b<=c && c<=a){
    	 print(b,c,a);
      }
      else if(c<=a && a<=b){
     	 print(c,a,b);
       }
      else if(a<=c && c<=b){
     	 print(a,c,b);
       }
      else if(b<=a && a<=c){
     	 print(b,a,c);
       }
      else if(c<=b && b<=a){
     	 print(c,b,a);
      	
       }
     	 
      } 
   
    }

Measured memory_bytes: 17300
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 220000;

int main() {
  const int INF = 1100000000;
  int n, r[MAX];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> r[i];

  int maxv = -INF;
  int minv = r[0];

  for(int i = 1; i < n; i++) {
    maxv = max(maxv, r[i] - minv);
    minv = min(minv, r[i]);
  }

  cout << maxv << endl;
  return 0;
}



Measured memory_bytes: 3856
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;


int main(int argc, char *args[]) {
	int N;
	int a[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int A_counter = 0;
	int B_counter = 0;
	sort(a, a + N,greater<int>());
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			A_counter = A_counter + a[i];
		}
		else {
			B_counter = B_counter + a[i];
		}
	}
	int diff = A_counter - B_counter;
	cout << diff << endl;
}


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

using namespace std;

int main()
{
	int N, X;
	cin >> N >> X;
	vector<int> m(N);
	for (auto &x : m) {
		cin >> x;
	}
	int total = accumulate(m.begin(), m.end(), 0);
	int smallest = *min_element(m.begin(), m.end());
	int ans = N + (X - total) / smallest;
	cout << ans << endl;
}


Measured memory_bytes: 256
def print_ab(sent, a, b):
    res = sent[a:b + 1]
    return res

def reverse_ab(sent, a, b):
    top = sent[:a]
    las = sent[b+1:]
    tag = sent[a:b+1]
    n = len(tag)
    rev = ""
    for i in range(n):
        rev = rev + tag[n - i - 1]
    rev = top + rev + las
    return rev

def replace_abp(sent, a, b, p):
    top = sent[:a]
    las = sent[b+1:]
    rep = top + p + las
    return rep

#print(print_ab("xyz", 0, 2))
#print(reverse_ab("abcde", 1, 3))
#print(replace_abp("xyz", 0, 2, "abc"))

sent = input()
op = int(input())
results = []
for i in range(op):
    oder = list(map(str, input().split()))
    if oder[0] == "print":
        res = print_ab(sent, int(oder[1]), int(oder[2]))
        results.append(res)
    elif oder[0] == "reverse":
        sent = reverse_ab(sent, int(oder[1]), int(oder[2]))
    else:
        sent = replace_abp(sent, int(oder[1]), int(oder[2]), oder[3])

for s in results:
    print(s)


Measured memory_bytes: 5624
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;

class UnionFind {
  public:
    UnionFind(int n): par(n, -1) { }
    int root(int x) {
      if (par[x] < 0) return x;
      else return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
      x = root(x), y = root(y);
      if (x == y) return;
      if (par[y] < par[x]) swap(x, y);
      par[x] += par[y];
      par[y] = x;
    }
    bool same(int x, int y) {
      return root(x) == root(y);
    }
    int size(int x) {
      return -par[root(x)];
    }

  private:
    vector<int> par;
};

int main()
{
  int N;
  cin >> N;
  vector<P> v;
  REP(i, N) {
    ll x, y;
    cin >> x >> y;
    v.PB(MP(x, y));
  }

  ll ans = LLINF;
  for (int i1 = 0; i1 < N; i1++) {
    for (int i2 = 0; i2 < N; i2++) {
      ll p = v[i2].FI - v[i1].FI;
      ll q = v[i2].SE - v[i1].SE;
      UnionFind uf(N);
      for (int j1 = 0; j1 < N; j1++) {
        for (int j2 = 0; j2 < N; j2++) {
          if (v[j2].FI - v[j1].FI == p && v[j2].SE - v[j1].SE == q) uf.unite(j1, j2);
        }
      }
      map<int, int> mp;
      REP(i, N) mp[uf.root(i)]++;
      ans = min(ans, (ll)mp.size());
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((x-r)>=0 && (x+r)<=W && (y-r)>=0 && (y+r)<=H){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define LL long long
const LL mod=1e9+7;
#define maxn 305
using namespace std;
struct node{
	int l,num;
	node(int l,int num):l(l),num(num){}
};
vector<node>e[maxn];
LL dp[maxn][maxn][maxn];
int n,m;
bool check(int r,int g,int b){
	int k=max(r,max(g,b));
	for(int i=0;i<e[k].size();i++){
		int cnt=0;
		int left=e[k][i].l;
		if(r>=left) cnt++;
		if(g>=left) cnt++;
		if(b>=left) cnt++;
		if(cnt!=e[k][i].num) return false;
	}
	return true;
}
int main(){
//	freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int l,r,x;
		cin>>l>>r>>x;
		e[r].push_back(node(l,x));
	}
	LL ans=0;
	dp[0][0][0]=1;
	for(int r=0;r<=n;r++){
		for(int g=0;g<=n;g++){
			for(int b=0;b<=n;b++){
				LL c=dp[r][g][b];
				if(!c) continue;
				if(!check(r,g,b)){
					dp[r][g][b]=0;
					continue;
				}
				int k=max(r,max(g,b))+1;
				if(k==n+1){
					ans+=dp[r][g][b];
					ans%=mod;
				}
				dp[k][g][b]=(dp[k][g][b]+dp[r][g][b])%mod;
				dp[r][k][b]=(dp[r][k][b]+dp[r][g][b])%mod;
				dp[r][g][k]=(dp[r][g][k]+dp[r][g][b])%mod;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 221440
from collections import deque
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
tre = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    tre[a-1].append(b-1)
    tre[b-1].append(a-1)

cnt = [0]*N
for i in range(Q):
    p,x = map(int,input().split())
    cnt[p-1] += x

q = deque([0])
judge = [False]*N
while q:
    root = q.pop()
    judge[root] = True
    for i in tre[root]:
        if judge[i]:
            continue
        cnt[i] += cnt[root]
        q.append(i)

print(*cnt)


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

using vi=vector<int>;
using vvi=vector<vi>;
int h,w;
int dfs(vvi &f,int x,int i);
vi flags;
bool check(const vvi &f,int k,int l){
    for(int i=max(k-1,0);i+1<h && i<=k+1;i++){
        for(int j=max(l-1,0);j+1<w && j<=l+1;j++){
            int zcnt=0;
            set<int> s;
            for(int di=0;di<2;di++){
                for(int dj=0;dj<2;dj++){
                    if(f[i+di][j+dj]!=0) s.insert(f[i+di][j+dj]);                      
                }
            }
            if(zcnt+s.size()==4) return false;
        }
    }
    return true;
}
int impl(vvi &f,int i,int j,int x){
    int res=0;
    int k=1;
    if(0<=i+k-1 && i+k<h && f[i+k-1][j]==f[i+k][j]){
        f[i+k-1][j]=f[i+k][j]=x;
        if(check(f,i,j)) res+=dfs(f,x+1,i);
        f[i+k-1][j]=f[i+k][j]=0;
    }
    if(0<=j+k-1 && j+k<w && f[i][j+k-1]==f[i][j+k]){
        f[i][j+k-1]=f[i][j+k]=x;
        if(check(f,i,j)) res+=dfs(f,x+1,i);
        f[i][j+k-1]=f[i][j+k]=0;
    }
    return res;
}
int dfs(vvi &f,int x,int i){
    if(i==h) return 1;
    for(int j=0;j<w;j++){
        if(!f[i][j]){
            return impl(f,i,j,x);
        }
    }
    return dfs(f,x,i+1);
}
int solve(){
    flags.assign(h*w,0);
    vvi tmpf(h,vi(w,0));
    return dfs(tmpf,1,0);
}

int main(){
    while(cin>>h>>w,h){
        cout<<solve()<<endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
char srx[100001];
int main(){
    gets(srx);
    int i,zjq=0;
    for(i=1;i<strlen(srx);i++)
    if(srx[i]!=srx[i-1])
    zjq++;
    printf("%d\n",zjq);
    return 0;
}

Measured memory_bytes: 384
using Microsoft.VisualBasic.CompilerServices;
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            int n = int.Parse(In[0]);
            k = int.Parse(In[1]);
            double ans = 0;
            for(int i = 1; i <= n; i++)
            {
                double t= Math.Pow(2, T(i));
                ans += 1 / (n * t);
            }
            Console.WriteLine(ans);
        }
        static public int k;
        static public int T(int m)
        {
            int cnt = 0;
            while (k>m)
            {
                m *= 2;
                cnt++;
            }
            return cnt;
        } 
    }
}


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

using namespace std;

#define cerr if(true)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int N, M, Q;
int mat[50][4]; 
int ans = 0;

int calc(vector<int>& subs){
	int cal = 0;
	for(int i = 0; i < Q; i++){
		if((subs[mat[i][1]] - subs[mat[i][0]]) == mat[i][2])
			cal += mat[i][3];
	}
	return cal;
}

void solve(int indx, int siz, vector<int>& subs){
	if(siz == N){
		ans = max(ans, calc(subs));
		return;
	}
	if(indx > M)return;

	//No usarlo
	solve(indx + 1, siz, subs);

	//Usarlo
	subs.push_back(indx);
	solve(indx, siz + 1, subs);
	subs.pop_back();
}


int main(){

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

	cin >> N >> M >> Q;
	for(int i = 0; i < Q; i++){
		cin >> mat[i][0] >> mat[i][1] >> mat[i][2] >> mat[i][3];
		mat[i][0] -= 1;
		mat[i][1] -= 1;
	}

	vector<int> subs;
	solve(1, 0, subs);
	cout << ans << endl;

	return 0;
}

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

int main()
{
	FASTIO;
	ll n,i,sum=0;
	cin>>n;
	for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
            sum=sum+i;
    }
    cout<<sum;

}


Measured memory_bytes: 3648
/** 
 *  Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split()))).reshape(n, 1)
mod = 10**9 + 7
bit = np.arange(64).reshape(1, 64)
b = np.sum((a >> bit) & 1, axis=0)
b *= n - b
b %= mod
b *= (1 << np.arange(64)) % mod
b %= mod
ans = 0
for x in b:
    ans += x
    ans %= mod

print(ans)



Measured memory_bytes: 318180
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

string S,T;
int main(){
    cin>>S>>T;
    ll ans=INF;
    for(ll i=0;i+T.length()<=S.length();i++){
        string ss=S.substr(i,T.length());
        ll cnt=0;
        for(ll j=0;j<T.length();j++){
            cnt+=(T[j]!=ss[j]);
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;

    return 0;
}

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

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	long long n; cin >> n;
	vector<long long> a(n);
	for(auto &i : a) cin >> i;
	sort(a.begin(), a.end());
	
	long long first = a.front(), last = a.back(), d = last - first;
	
	if(d > 1) return cout << "No", 0;
	else if(!d){
		if(first == n - 1 || 2 * last <= n) return cout << "Yes", 0;
		else return cout << "No", 0;
	}
	else {
		long long x = 0, y = 0;
		for(auto it : a){
			if(it == first) x++;
			else y++;
		}	
		if(x < last && last <= x + (y / 2)) return cout << "Yes", 0;
		else return cout << "No", 0;
	}	
    
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;

    if (x1 != 1) {
        cout << 1 <<endl;
    }
    if (x2 != 2) {
        cout << 2 <<endl;
    }
    if (x3 != 3) {
        cout << 3 <<endl;
    }
    if (x4 != 4) {
        cout << 4 <<endl;
    }
    if (x5 != 5) {
        cout << 5 <<endl;
    }
}

Measured memory_bytes: 3624
#include <stdio.h>
#define DIV 1000000007
int main(){
  char S[200000];
  long long int a,b,c,n;
  int N;
  
  scanf("%s",S);
  while(S[++N]!='\0') ;

  a=1;b=c=n=0;  
  for(int i=0;i<N;i++)
    switch(S[i]){
    case 'A':
      b=(b+a)%DIV;
      break;
    case 'B':
      c=(c+b)%DIV;
      break;
    case 'C':
      n=(n+c)%DIV;
      break;
    case '?':
      n=(n*3+c)%DIV;
      c=(c*3+b)%DIV;
      b=(b*3+a)%DIV;
      a=a*3%DIV;
      break;
    }
        
  printf("%lld\n",n);

  return 0;
}


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

int main() {
  int n, k;
  cin>>n>>k;
  int h[n];
  for (int i=0; i<n; i++) cin>>h[i];
  sort(h, h + n);
  reverse(h, h + n);
  long long cnt = 0;
  for (int i=k; i<n; i++) {
    cnt += h[i];
  }
  cout<<cnt<<endl;
}

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

using namespace std;
template <typename T> void print(T vec) {for(auto d: vec) cout<<d<<' ';cout<<'\n';}
template<typename T> void print2D(T mat) {for(auto vec:mat) print(vec);}

typedef long long int ll;

int n;

void solve(vector<int> &vec) {
    vector<vector<ll>> dp(n + 2, vector<ll> (n + 2));
    for(int L = n; L > 0; L--) {
        // cout<<L<<'\n'; 
        for(int R = L; R <= n; R++) {
            // cout<<"L "<<L<<" R "<<R<<'\n';
            if(L == R) dp[L][R] = 0;
            else{
                dp[L][R] = 1e14;
                ll sum = 0;
                for(int i = L ; i <= R; i++) {
                    sum += vec[i];
                }
                // cout<<sum<<'\n';
                for(int i = L ; i <= R; i++) {
                    
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + sum);
                }
            }
        }
        // cout<<"L "<<L<<'\n';  
    }
    // print2D(dp);
    cout<<dp[1][n]<<'\n';
}



int main() {
    cin>>n;
    vector<int> A(n + 1);
    for(int i = 1; i <= n ;i++) cin>>A[i];
    solve(A);
    return 0;
}

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

vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int a,b;
	cin >> a >> b;
	
	if(a+b < a-b && a*b < a-b){
		cout << a-b << endl;
	}else if(a+b < a*b){
		cout << a*b << endl;
	}else{
		cout << a+b << endl;

	}
}

Measured memory_bytes: 3624
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
acc = [0] + list(accumulate(P))
ans = 0
for a, b in zip(acc, acc[K:]):
  exp = (b - a + K) / 2
  ans = max(exp, ans)
print(ans)

Measured memory_bytes: 32072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	
	 static Scanner in = new Scanner(System.in);
	 
   
	public static void main(String args[])throws IOException  {
    while(in.hasNext())
    {
    	
  
    	int []a=new int[4+1];
    	int []vis=new int[11];
    	for(int i=1;i<=4;i++)
    	{
          a[i]=in.nextInt();
          vis[a[i]]++;
    	}
    	if(vis[1]==1&&vis[7]==1&&vis[9]==1&&vis[4]==1)
     	System.out.println("YES");
    	else
    		System.out.println("NO");	
     	
    }

	}
	
 
	
}

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

using namespace std;

int main() {
    string s1, s2;

    cin >> s1 >> s2;
    for (int i = 0; i < s1.size();) {
        i = s1.find(s2, i);
        if (i == -1) {
            break;
        }
        cout << i++ << endl;
    }

    return 0;
}

Measured memory_bytes: 1192
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => long.Parse(elem)).ToArray();
            var A = items[0];
            var B = items[1];
            var N = items[2];
            var x = (N >= B - 1) ? B - 1 : N;
            var answer = A * x / B - A * (x / B);
            Console.WriteLine(answer.ToString());
        }
    }
}


Measured memory_bytes: 28240
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		 Scanner scan = new Scanner(System.in);
	     String str = scan.nextLine();
	     String[] chars = str.split("");
	     boolean oddFlag = true;
	     for(String c : chars) {
	    	 if(oddFlag) {
	    		 if(c.equals("L")) {
	    			 System.out.println("No");
	    			 return;
	    		 }
	    	 }
	    	 else {
	    		 if(c.equals("R")) {
	    			 System.out.println("No");
	    			 return;
	    		 }
	    	 }
	    	 oddFlag = !oddFlag;
	     }
	     System.out.println("Yes");
	}

}


Measured memory_bytes: 23892
// https://beta.atcoder.jp/contests/abc110

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

int main() {
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end(), greater<>());
    auto ans = 10 * v[0] + v[1] + v[2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
    int x;
    cin >> x;
    if (x == 0) cout << 1 << endl;
    else cout << 0 << endl;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	string s;
	cin >> s;
	LL ans = 0;
	for (int i = 0; i < s.size(); i++) { // 偶数で0
		if ('0' + (i % 2) != s[i]) {
			ans++;
		}
	}
	LL tmp = 0;
	for (int i = 0; i < s.size(); i++) {
		if ('0' + ((i+1) % 2) != s[i]) {
			tmp++;
		}
	}
	cout << min(ans, tmp) << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c)              c.begin(), c.end()
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define EPS 1e-9
using namespace std;

int main()
{
    FastRead
    string s,s1;
    cin >> s >> s1;
    cout << s1 << s<<endl;
}


Measured memory_bytes: 256
N=int(input())
W=[int(i) for i in input().split()]
group1=[W[0]]
group2=[W[N-1]]
p1=0
p2=N-1

while len(group1)+len(group2)<N:
    if sum(group1)<=sum(group2):
        p1+=1
        group1.append(W[p1])
    else:
        p2-=1
        group2.append(W[p2])

print(abs(sum(group1)-sum(group2)))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <queue>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

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;
}

ll weights[110], values[110];
ll dp[110][100100] = { 0 };

signed main() {
    ll N, W; cin >> N >> W;
    for (ll i = 0; i < N; i++) {
        cin >> weights[i] >> values[i];
    }

    for (ll i = 0; i < N; i++) {
        for (ll w = 0; w <= W; w++) {
            if (w - weights[i] >= 0) {
                chmax(dp[i + 1][w], dp[i][w - weights[i]] + values[i]);
            }

            chmax(dp[i + 1][w], dp[i][w]);
        }
    }

    cout << dp[N][W] << endl;

}

Measured memory_bytes: 79360
#dfs#ans
n=int(input())

def dfs(s):
    #end
    if int(s)>n:
        return 0
    
    for c in "753":
        ret=1 if all(s.count(c)>0 for c in "753")else 0
    for c in "753":
        ret+=dfs(s+c)
    return ret
print(dfs('0'))

Measured memory_bytes: 3060
import collections

n,k=map(int,input().split())
a=list(map(int,input().split()))
sa = [0]
for i in range(n):
    sa.append(sa[i]+a[i])
    sa[i+1] -= 1
    sa[i+1] %= k
cd = collections.defaultdict(lambda:0)
res = 0
for i in range(n+1):
    cd[sa[i]] += 1
    if i >= k:
        cd[sa[i-k]] -= 1
    res += cd[sa[i]] - 1
print(res)

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

int main() {
	int a = 0, b = 0, c = 0, h[10];
        for(int i = 0; i < 10; ++i){
             cin >> h[i];
		if(a < h[i]){
			c = b;
			b = a;
			a = h[i];
		}
		else if(b < h[i]){
		    c = b;
		    b = h[i];
		}
		else if(c < h[i]){
			c = h[i];
		}
	}
	cout << a << endl << b << endl << c << endl;
	return 0;
}

Measured memory_bytes: 1164
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll  i,j,k,l,n;
    string s;
    cin>>n;
   // if()
    cout<<(n-1)/2<<endl;
    return 0;
}





Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double n = sc.nextDouble();
        int k = sc.nextInt();
        sc.close();
        
        double winRatio = 0;
        for(int i = 1; i <= n; i++){
            int x = i;
            double m = 1;
            while(x < k) {
                x*=2;
                m*=2;
            }
            winRatio += (1d / n) / m;
        }
        System.out.println(winRatio);
    }
}


Measured memory_bytes: 23252
S=input()
A=["dreamer","dream","eraser","erase"]
endIndex=len(S)
while endIndex > 0:
  for s in A:
    if S.endswith(s, 0, endIndex):
      endIndex -= len(s)
      break
  else:
    print("NO")
    exit()
else:
  print("YES")
  

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

#define ll long long
#define pll pair<ll, ll>
#define rep(x, l, r) for (x = l; x < r; x++)

const ll mod=1000000007;
const char nl='\n';


void solve()
{
	ll i, j, k, l, m, n, u, v,x,y,z,c,r,g;
    cin>>n;
    cout<<(1000-(n%1000))%1000;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
//    cin >> t;
	while (t--)
	{
		solve();

	}
	return 0;
}
/*
10
1 0
0 0
0 1
1000 0
0 1000
999 999
882 456
345 234
12 45
345 56
*/


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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===




int main()
{
	int N;
	cin >> N;
	unordered_map<int, int> m;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		--a;
		m[a] = i;
	}

	for (int i = 0; i < N - 1; ++i) {
		cout << m[i] + 1 << " ";
	}
	cout << m[N - 1] + 1 << endl;

	return 0;
}

Measured memory_bytes: 4900
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

int n;
int magic_square[ 115 ][ 115 ];
int x, y;

int main() {
	while ( ~scanf( "%d", &n ) && n ) {
		memset( magic_square, 0, sizeof( magic_square ) );
		y = n / 2 + 1;
		x = n / 2;
		for ( int i = 1; i <= n * n - 1; i++ ) {
			magic_square[ y ][ x ] = i;
			y++;
			x++;
			y %= n;
			x %= n;
			while ( magic_square[ y ][ x ] != 0 ) {
				y++;
				x--;
				y %= n;
				if ( x < 0 ) {
					x += n;
				}
			}
			
		}
		magic_square[ y ][ x ] = n * n;
		for ( int i = 0; i < n; i++ ) {
			for ( int j = 0; j < n; j++ ) {
				if ( magic_square[ i ][ j ] / 10 == 0 ) {
					printf( "   " );
				}
				else if ( magic_square[ i ][ j ] / 100 == 0 ) {
					printf( "  " );
				}
				else {
					printf( " " );
				}
				printf( "%d", magic_square[ i ][ j ] );
			}
			printf( "\n" );
		}
	}
	return 0;
}

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

void solve(int&mxc1,int&mxc2,int&mxn1,int&mxn2,unordered_map<int,int>&m){
	for(auto&&i:m){
		if(mxc1<i.second){
			mxc2=mxc1;
			mxn2=mxn1;
			mxc1=i.second;
			mxn1=i.first;
		}
		else if(mxc2<i.second){
			mxc2=i.second;
			mxn2=i.first;
		}
	}
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>v(n); for(auto&&i:v)cin>>i;
	unordered_map<int,int>me,mo;
	for(int i=0;i<n;++i){
		if(i&1)++mo[v.at(i)];
		else ++me[v.at(i)];
	}
	int mxec=0,mxen=0,mxec2=0,mxen2=0;
	solve(mxec,mxec2,mxen,mxen2,me);
	int mxoc=0,mxon=0,mxoc2=0,mxon2=0;
	solve(mxoc,mxoc2,mxon,mxon2,mo);
	int ans=n;
	if(mxen!=mxon){
		ans-=mxec+mxoc;
	}
	else{
		if(mxec+mxoc2>mxoc+mxec2)ans-=mxec+mxoc2;
		else ans-=mxoc+mxec2;
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 7536