akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

int dp[55][55][2510];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, A; cin >> n >> A;
	VE x(n); rep(i, n)cin >> x[i];
	int X = A;
	rep(i, n)chmax(X, x[i]);
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n * X; k++) {
				if (i == 0 && j == 0 && k == 0) {
					dp[i][j][k] = 1;
				}
				else if (i >= 1 && k < x[i - 1]) {
					dp[i][j][k] = dp[i - 1][j][k];
				}
				else if (i >= 1 & j >= 1 && k >= x[i - 1]) {
					dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
				}
				else {
					dp[i][j][k] = 0;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += dp[n][i][i*A];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 55424
(* q log(max a b) *)
let kInf = 20202020202
let a, b, q = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let ns = [|a; b|]
let sts = Array.init 2 @@ fun i ->
  let ds = Array.make (ns.(i) + 2) 0 in
  ds.(0) <- -kInf + i; ds.(ns.(i) + 1) <- kInf + i;
  for j = 1 to ns.(i) do ds.(j) <- Scanf.scanf " %d" @@ (+) 0 done;
  ds
let xs = Array.init q @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let is_ok i key a = a.(i) >= key
let binary_search key a =
  let left, right = ref @@ -1, ref @@ Array.length a in
  while !right - !left > 1 do
    let mid = !left + (!right - !left) / 2 in
    if is_ok mid key a then right := mid
    else left := mid done;
  !right
let g x i =
  let ps = sts.(i) in
  let yi1 = binary_search x ps in
  min (x - ps.(yi1 - 1)) @@ ps.(yi1) - x
let f x =
  let si1, ti1 = binary_search x sts.(0), binary_search x sts.(1) in
  let s0, s1, t0, t1 = sts.(0).(si1 - 1), sts.(0).(si1), sts.(1).(ti1 - 1), sts.(1).(ti1) in
  let ans = ref kInf in
  ans := min !ans @@ if s0 < t0 then x - t0 + g t0 0 else x - s0 + g s0 1;
  ans := min !ans @@ if s1 < t1 then s1 - x + g s1 1 else t1 - x + g t1 0;
  Printf.printf "%d\n" !ans
let _ = Array.iter f xs

Measured memory_bytes: 7296
#include<iostream>
#include<vector>
#include<string>
#include<iomanip>
using namespace std;
int main() {
	int n; cin >> n;
	vector<double> x(n);
	vector<string> u(n);
	double ans = 0.0;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> u[i];
		if (u[i] == "BTC") {
			x[i] = x[i] * 380000.0;
		}
		ans += x[i];
	}
	cout <<fixed<<setprecision(10)<< ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {
	
	int n;
	cin >> n;
	V<P> pa(n);
	rep(i, n) {
		int a;
		cin >> a;
		pa[i] = P(a, i);
	}

	sort(all(pa), greater<P>());

	rep(i, n) {
		if (pa[0].second != i)cout << pa[0].first << endl;
		else cout << pa[1].first << endl;
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, i, a, b, c, A; cin >> N;
long long d, ans=1, MOD=1e9+7; bool f=true;
a=b=c=0;
for(i=0; i<N; i++){
  cin >> A;
d=0; f=true;
if(a==A){d++; if(f){a++;f=false;}}
if(b==A){d++; if(f){b++;f=false;}}
if(c==A){d++; if(f){c++;f=false;}}
ans=(d*ans)%MOD;
}
cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 19


int N;
int POW[SIZE];


int main(){

	POW[0] = 1;
	for (int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d",&N);

	printf("0:\n");
	int index = 1;

	for(int state = 1; state < POW[N]; state++){
		printf("%d:",index++);
		for(int loop = 0; loop < N; loop++){
			if(state & (1 << loop)){
				printf(" %d",loop);
			}
		}
		printf("\n");
	}

	return 0;
}




Measured memory_bytes: 3216
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();
    int zero =0;//0側にゴールした時にかかる金額
    for(int i=0;i<M;i++){
      if(sc.nextInt()<X){
        zero++;
      }
    }
    System.out.println(Math.min(zero,M-zero));
  }
  

  
}

Measured memory_bytes: 21844
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        a = [LI() for _ in range(n)]
        r = 0
        for i in range(n):
            for j in range(i+1,n):
                r += min(a[i][j], a[j][i])

        rr.append(r)
        break

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <chrono>
#include <random>
#include <functional>
#include <utility>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<i64, i64>;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (c >= a && c <= b ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
     ios::sync_with_stdio(false);
     cin>>s;
     if(s.size()%2==1)
        puts("No");
     else
     {
         int flag=1;
         for(int i=0;i<s.size()/2;i++)
         {
             if(s[i*2]!='h')
                flag=0;
             if(s[i*2+1]!='i')
                flag=0;
         }
         if(flag)
            puts("Yes");
         else
            puts("No");
     }
     return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b; cin >> a >> b;

    cout << a*b -a-b+1 << endl;
}

Measured memory_bytes: 256
a,b,c,k = map(int,input().split())
sum_ans = 0
sum_ans += min(a,k)
if a>=k:
  print(sum_ans)
else:
  k -= a
  if b>= k:
    print(sum_ans)
  else:
    k -= b
    print(sum_ans-k)

Measured memory_bytes: 61844
s = list(input())
tru = 0
Ccount = 0
Lcount = 0
if s[0] != "A":
         tru = 1
for i in range(2,(len(s)-1)):
         if s[i] == "C":
                  Ccount += 1
if Ccount != 1:
         tru = 1
for j in range(len(s)):
         if s[j].isupper():
                  Lcount +=1
if Lcount != 2:
         tru = 1
if tru == 1:
         print("WA")
else:
         print("AC")



Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int[] arr = new int[5];
		for (int i = 0; i < 5; i++) {
			arr[i] = reader.nextInt();
		}
		int k = reader.nextInt();
		Arrays.sort(arr);
		String ans = ":(";
		if (arr[4]-arr[0] <= k) {
			ans = "Yay!";
		}

		System.out.print(ans);
		reader.close();
	}
}





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

using namespace std;

int main()
{
    int N, W;
    cin >> N;
    vector<int> X(N), Y(N);
    map<int, map<int, int>> coor;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> W;
        coor[X[i]][Y[i]] = W;
    }
    int res = 0;
    for (int i = 0; i < N; i++) {
        res = max(res, coor[X[i]][Y[i]] +
                       coor[X[i]+1][Y[i]] +
                       coor[X[i]][Y[i]+1] +
                       coor[X[i]+1][Y[i]+1]);

        res = max(res, coor[X[i]][Y[i]] +
                       coor[X[i]+1][Y[i]] +
                       coor[X[i]][Y[i]-1] +
                       coor[X[i]+1][Y[i]-1]);
    }
    cout << res << " / " << 1 << endl;
    return 0;
}

Measured memory_bytes: 50596
fn main() {
    proconio::input! {
        a: usize,
        b: usize,
        x: usize,
    }
    let ans = if a == 0 { 1 } else { 0 } + b / x - if a == 0 { 0 } else { (a - 1) / x };
    println!("{}", ans);
}


Measured memory_bytes: 2124
//合計値の約数が候補
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> divisor(ll n){
	vector<ll> ret;
	for(int i=1;i<=(int)sqrt(n);i++){
		if(n%i==0){
			ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
		}
	}
	sort(ret.begin(),ret.end());
	return(ret);
}
int main(){
ll n,k;
cin>>n>>k;
vector<ll> a(n);
ll sum=0;
for(ll i=0;i<n;i++){
    cin>>a.at(i);
    sum+=a.at(i);
}
vector<ll> res=divisor(sum);
for(int i=res.size()-1;i>=0;i--){
    vector<ll> b(n);
    ll tmp=0;
    for(int j=0;j<n;j++){
        b.at(j)=a.at(j)%res.at(i);
        tmp+=b.at(j);
    }
     tmp/=res.at(i);
    sort(b.begin(),b.end());
    ll ans=0;
    for(int j=n-1;j>=n-tmp;j--){
        ans+=(res.at(i)-b.at(j));
    }
    if(ans<=k){
        cout<<res.at(i)<<endl;
        return 0;
    }
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{int n;
cin>>n;
int x=n/100;
int y=n%100;
if(x>0&&x<13)
{if(y>0&&y<13)
cout<<"AMBIGUOUS";
else
cout<<"MMYY";}
else if(y>0&&y<13)
  cout<<"YYMM";
else cout<<"NA";}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;

void a(){
    double r; cin >> r;
    cout<< fixed <<setprecision(15) <<2*M_PI*r<<endl;
}

void b(){
    ll n,m; cin >> n >> m;
    ll sum=0;
    rep(i,m){
        ll a;
        cin >> a;
        sum+=a;
    }
    cout << ((sum<=n?n-sum:-1));
}


void c(){

}

void d(){

}

void e(){

}

int main(){
    a();
    return 0;
}

Measured memory_bytes: 3788
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int N = 0;
    int result = 0;
    
    scanf("%d",&N);
    
    result = N % 2;//割り切れるなら０が入るはず？
    
    if (result == 0) {
        printf("%d",N);
    }else{
        printf("%d",N * 2);
    }
    
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int A =sc.nextInt();
    int B =sc.nextInt();
    int C =sc.nextInt();
    int D;
    if(C==0){System.out.println("YES");}
    else{
      for(int i=1;i<B;i++){
        D = (A*i)%B;
        if(D==C){System.out.println("YES");System.exit(0);}
      }
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 27100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  int n,m; cin >> n >> m;
  int cor,pen; cor = pen = 0;
  int now[n];
  FOR(i,0,n-1) now[i] = 0;

  FOR(i,0,m-1){
    int p; string s;
    cin >> p >> s;
    --p;
    if(now[p]==-1) continue;
    else{
      if(s=="WA") ++now[p];
      else{
        pen += now[p];
        now[p] = -1;
      }
    }
  }

  FOR(i,0,n-1){
    if(now[i] == -1) ++cor;
  }

  cout << cor << " " << pen << endl;



  
}


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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n);
    vector<int> c(n);
    ll ans = (1 << 29);
    for (int i = 0; i < n; i++) {
        cin >> c.at(i);
        a.at(i).resize(m);
        for (int j = 0; j < m; j++) {
            cin >> a.at(i).at(j);
        }
    }

    //ビット全探索
    for (int i = 0; i < (1 << n); i++) {
        ll sum = 0;
        vector<int> d(m);
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                for (int k = 0; k < m; k++) {
                    d.at(k) += a.at(j).at(k);
                }
                sum += c.at(j);
            }
        }

        bool flg = true;
        for (int k = 0; k < m; k++) {
            if (d.at(k) < x) {
                flg = false;
            }
        }
        if (flg) {
            ans = min(ans, sum);
        }
        
    }

    if (ans == (1 << 29)) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

size_t get_root(const Graph &g) {
    // stores the node type
    size_t V=g.size();
    vector<Weight> indeg(V);
    for (size_t i=0; i<V; ++i)
        for (const Edge &e: g[i])
            indeg[e.dst] += e.weight;

    for (size_t i=0; i<V; ++i)
        if (!indeg[i])
            return i;

    return 0;
}

template <class Functor>
void walk_preorder(const Graph &g, size_t root, Functor F) {
    if (root >= g.size()-1) return;

    F(root);
    for (const Edge &e: g[root])
        walk_preorder(g, e.dst, F);
}

template <class Functor>
void walk_inorder(const Graph &g, size_t root, Functor F) {
    if (root >= g.size()-1) return;

    walk_inorder(g, g[root][0].dst, F);
    F(root);
    walk_inorder(g, g[root][1].dst, F);
}

template <class Functor>
void walk_postorder(const Graph &g, size_t root, Functor F) {
    if (root >= g.size()-1) return;

    for (const Edge &e: g[root])
        walk_postorder(g, e.dst, F);

    F(root);
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n+1);
    for (size_t i=0; i<n; ++i) {
        size_t p, lch, rch;
        scanf("%zu %zu %zu", &p, &lch, &rch);

        connect(g, p, ~lch? lch:n);
        connect(g, p, ~rch? rch:n);
    }

    size_t r=get_root(g);

    auto output=[=](size_t v)->void {
        if (v < n)
            printf(" %zu", v);
    };

    printf("Preorder\n");
    walk_preorder(g, r, output);
    printf("\n");

    printf("Inorder\n");
    walk_inorder(g, r, output);
    printf("\n");

    printf("Postorder\n");
    walk_postorder(g, r, output);
    printf("\n");

    return 0;
}

Measured memory_bytes: 2696
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a[1000],sum = 0,cnt=0;
    cin>>n>>m;
    float x;
    for(int i = 0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i = 0;i<n;i++)
    {
       sum+=a[i];
    }
    for(int i = 0;i<n;i++)
    {
        x = (sum/(4.0*m));
        if(a[i] >= x)
          cnt++;
    }
    if(cnt>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <sstream>
#define ull unsigned long long
#define ll long long
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin >> n >> a;
    if(n%500<=a){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
    int a,b;
    cin >> a >> b;
    
    if((a == 1 && b == 2) || (a == 2 && b == 1)){
        puts("3");
    }else if((a == 1 && b == 3) || (a == 3 && b == 1)){
        puts("2");
    }else{
        puts("1");
    }
}

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

int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	for(int i=0;i<tx-sx;++i)cout<<"R";
	for(int i=0;i<ty-sy;++i)cout<<"U";
	for(int i=0;i<tx-sx;++i)cout<<"L";
	for(int i=0;i<ty-sy;++i)cout<<"D";
	cout<<"D";
	for(int i=0;i<tx-sx+1;++i)cout<<"R";
	for(int i=0;i<ty-sy+1;++i)cout<<"U";
	cout<<"L"<<"U";
	for(int i=0;i<tx-sx+1;++i)cout<<"L";
	for(int i=0;i<ty-sy+1;++i)cout<<"D";
	cout<<"R"<<endl;
	

}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll x;cin>>x;
  rep(a, 300)for(int b=-300; b<300; b++){
    ll a5 = pow(a, 5);
    ll b5 = pow(b, 5);
    if(a5-b5==x) {cout<<a<<' '<<b; return 0;}
  }

  return 0;
}


Measured memory_bytes: 4040
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		sc.close();

		System.out.println(3*r*r);
	}
}


Measured memory_bytes: 23892
#include <iostream>
using namespace std;
const int mod = 1000000007,maxn = 100001;
string S; int dp[maxn][13],ans;
int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin>>S; dp[S.size()][0] = 1;
    for (int i = (int)S.size()-1,p = 1;i >= 0;i--,p*=10,p%=13) for (int j = 0;j < 13;j++) {
        if (S[i] == '?') for (int k = 0;k <= 9;k++) dp[i][j] += dp[i+1][((j-k*p)%13+13)%13],dp[i][j]%=mod;
        else dp[i][j] += dp[i+1][((j-(S[i]-'0')*p)%13+13)%13],dp[i][j]%=mod;
    }
    printf("%d\n",dp[0][5]);
}


Measured memory_bytes: 5584
fun main(args: Array<String>) {

    val num = readLine()!!.split(" ").map { it.toString() }.toMutableList()
    var cnt = 0
    var hp = num[0].toInt()
    val dm = num[1].toInt()

    while (hp > 0) {
        hp -= dm
        cnt++
    }

    print(cnt)
}

Measured memory_bytes: 38000
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)
        cout<<(n-2)*(b-a)+1<<endl;
    else
        cout<<0<<endl; 
 }

Measured memory_bytes: 256
/*
	*	Created By: 'Present_Sir'
	*	Created On: Friday 14 August 2020 01:06:08 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;


void solve(){
    int n;
    cin>>n;

    string s;
    cin>>s;
    
    map<char,int>  mp;
    for(int i=0; i<n; ++i){
        mp[s[i]]++;
    }

    int ans = 1;
    for(auto x: mp){
        ans *= x.second;
    }
    if( ans == 0 or  mp.size() <= 2){
        cout<<"0"<<endl;
        return;
    }
    //cout<<ans<<endl;
    for(int i=0; i<n; ++i){
        for(int j=i+1; j<n; ++j){
            if(s[i] == s[j]){
                continue;
            }
            int k = 2*j-i;
            if(k < n and s[i] != s[k] and s[j] != s[k]){
                --ans;
            }
        }
    }
    cout<<ans<<endl;
}

int32_t main(){
    IOS;
    //int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3552
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int a, b;
    cin>>a>>b;
    int i;
    bool is = false;
    FOR(i, 1, 2e3+1)
    {
        if(i*8/100 == a &&  i/10 == b)
        {
            is = true;
            break;
        }
    }
    if(!is) cout<<-1<<endl;
    else 
    {
        cout<<i<<endl;
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let extgcd x y =
        let rec eg r0 r1 a0 a1 b0 b1 =
            if r1 = 0 then a0 else
                let q1 = r0 / r1 in
                eg r1 (r0 mod r1) a1 (a0 - q1 * a1) b1 (b0 - q1 * b1)
        in
        eg x y 1 0 0 1
    in
    let inv x y = (* 1/x in mod y *)
        let c = extgcd x y in
        if c < 0 then c + y else c
    in
    let z = 998244353 in
    let ( +@) a b = (a + b) mod z in
    let ( -@) a b = (((a - b) mod z) + z) mod z in
    let ( *@) a b = (a * b) mod z in
    let ( /@) a b = a *@ inv b z in

    let modpow a b =
        let rec loop r i acc =
            if i = 0 then acc else loop (r *@ r) (i lsr 1) (if i land 1 = 1 then r *@ acc else acc)
        in
        loop a b 1
    in

    let rec loop a b cur acc =
        let acc = acc +@ cur in
        if b * 2 = n then acc else
            loop (a - 1) (b + 1) (cur *@ 2 *@ a /@ b) acc
    in
    let ans = loop n 1 2 0 in
    Printf.printf "%d\n" @@ modpow 3 n -@ ans
)

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

using namespace std;
typedef long long ll;

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

int main()
{

    string s, t;
    cin >> s >> t;

    cout << (s == t.substr(0, s.size()) ? "Yes" : "No") << '\n';

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int N, M;
int a[55], b[55];
int c[55], d[55];

signed main()
{
    cin >> N >> M;
    REP(i,N) cin >> a[i] >> b[i];
    REP(i,M) cin >> c[i] >> d[i];

    REP(i,N) {
        int minDist = 1e9;
        int ans;
        REP(j,M) {
            int dist = abs(c[j] - a[i]) + abs(d[j] - b[i]);
            if (dist < minDist) {
                minDist = dist;
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
const main = (inputs) => {
  var N = inputs[0]-0;
  var arr = inputs[1].split(" ").map(v=>v-0);
  var ans = [];
  for(var i=N;i>0;i--){
    if(i*2<=N){
      var cnt = 0;
      for(var j=i*2;j<=N;j+=i){
        if(ans[j]==1) cnt++;
      }
      if(cnt%2==arr[i-1]) ans[i] = 0;
      else ans[i] = 1;
    }else{
      if(arr[i-1] == 1){
        ans[i] = 1;
      }else{
        ans[i] = 0;
      }
    }
  }
  ans = ans.map((v,i)=>v?i:0).filter(v=>v);
  console.log(ans.length);
  if(ans.length){
    console.log(ans.join(" "));
  }

}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 40144
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string n;
	cin >> n;
	if (n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3]){ cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    if n ==1:
        print("Yes")
    else:
        now = ls[0]-1
        for i in range(1,n):
            if ls[i]-1>now:
                now = ls[i]-1
            elif ls[i]-1==now:
                pass
            else:
                if ls[i]==now:
                    pass
                else:
                    print("No")
                    exit()
        print("Yes")

        
if __name__ == '__main__':
    main()

Measured memory_bytes: 63984
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    const C = parseInt(arg[0].split(" ")[2]);
    
    let answer = "NO";
    
    for(let i=0; i<B; i++) {
        let temp = (A * i) % B;
        // console.log((A * i) % B);
        
        if(temp === C) {
            answer = "YES";
            break;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
// clang-format off
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {
  REP(i, v.size()) print(v[i]);
}
template <typename T> inline void print(const vector<T>& v, string s = " ") {
  REP(i, v.size()) {
    if (i != 0) cout << s;
    cout << v[i];
  }
  cout << '\n';
}
// clang-format on
/* }}} */

int h, w;
char s[10][10];
bool vis[10][10];

bool dfs(int y, int x) {
  vis[y][x] = true;
  if (mp(y, x) == mp(h - 1, w - 1)) {
    bool flg = true;
    REP(i, h) REP(j, w) {
      if (s[i][j] == '#') {
        if (!vis[i][j]) {
          flg = false;
        }
      }
    }
    return flg;
  }
  bool ret = false;
  REP(i, 2) {
    int ny = y + dy[i], nx = x + dx[i];
    if (!inside(ny, nx, h, w)) continue;
    if (s[ny][nx] == '.') continue;
    ret |= dfs(ny, nx);
    vis[ny][nx] = false;
  }
  return ret;
}

signed main() {
  cin >> h >> w;
  REP(i, h) cin >> s[i];
  print(dfs(0, 0) ? "Possible" : "Impossible");

  return 0;
}


Measured memory_bytes: 256
A,B = map(int,input().split())
S = input()

flag = True
if not(len(S) == A+B+1):
    flag = False
if not(S[A] == '-'):
    flag = False
for i in range(A+B+1):
    if i != A:
        if not(48<=ord(S[i])<=57):
            flag = False
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    int r,D,x[20];
    cin>>r>>D>>x[0];

    for(int i=1;i<=10;++i){
        x[i]=r*x[i-1]-D;
        cout<<x[i]<<endl;

    }
        
    return 0;
}

Measured memory_bytes: 256
n,x,m=map(int,input().split())
l=[-1]*m
s=[0]*m
t=p=0
while l[x]<0:
  t+=1
  l[x]=t
  s[x]=s[p]+x
  p=x
  x=pow(p,2,m)
T=t+1-l[x]
S=s[p]+x-s[x]
if n<l[x]:
  print(s[l.index(n)])
else:
  print(S*((n-l[x])//T)+s[l.index(l[x]+(n-l[x])%T)])

Measured memory_bytes: 13736
n = int(input())
a = list(map(int,input().split()))
limit = 10 ** 18

a = sorted(a, reverse=False)
ans = a[0]
for i in range(1, n):
    ans *= a[i]
#    logging.debug("i = {},a[i]= {},ans = {}".format(i,a[i],ans))#
    if ans > limit:
        print("-1")
        exit()
print(ans)

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

// Union Find
class UFT{
private:
  int n;
  vector<int> par;
  vector<int> sz; // sz[i]:iをルートとする木のノード数
public: // コンストラクタ
  UFT(int n){
    this->n = n;
    par = vector<int>(n);
    sz = vector<int>(n);
    for (int i=0; i<n; i++){
      par[i]=i;
      sz[i]=1;
    }
  }
private:
  int rootOf(int x){ // xがいるグループのルート
    if (x == par[x]) return x;
    return par[x] = rootOf(par[x]);// ついでに木を平たくする
  }
public:
  int size(int x){ // xがいるグループの要素数
    return sz[rootOf(x)];
  }
  void unite(int x, int y){
    int rx, ry;
    rx = rootOf(x);
    ry = rootOf(y);
    if (rx==ry) return; // すでに同じグループ
    if (sz[rx]>sz[ry]){ // xの木のほうがデカい
      par[ry] = rx; // yの木をxのルートにぶら下げる
      sz[rx] += sz[ry];
    } else { // yの木のほうがデカい
      par[rx] = ry;
      sz[ry] += sz[rx];
    }
  }
  bool isSameGroup(int x, int y){
    return rootOf(x) == rootOf(y);
  }
};


int main(void){
  long long n,m, pen;
  vector<pair<int,int> > brg; // bridges
  vector<long long> ans;
  UFT *uft;
  
  cin >> n >> m;
  uft = new UFT(n);
  for (int i=0; i<m; i++){
    int a,b;
    cin >> a >> b;
    brg.push_back(make_pair(a-1,b-1));
  }
  pen = n*(n-1)/2;
  for (int i=m-1; i>=0; i--){
    int a,b;
    a = brg[i].first; b = brg[i].second;
    ans.push_back(pen);
    //cout << a << " " << b << " : " << uft->size(a) << " " << uft->size(b) << endl;
    if (!uft->isSameGroup(a,b)){
      pen -= uft->size(a) * uft->size(b);
      uft->unite(a,b);
    }
  }
  for (int i=m-1; i>=0; i--) cout << ans[i] << endl;
  return 0;
}


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

int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    long long sum = 0;
    for(long long i = 0; i < N; i++){
        cin >> A[i];
        sum += (A[i] - 1);
    }
    cout << sum << "\n";
}

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

int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int ans = 0;
    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                if (i * 500 + j * 100 + k * 50 == X)
                {
                    ans += 1;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  vll ans(100010);
  rep(i,n){
    rep(j,3){
      ans[a[i]+j]++;
    }
  }
  ll cu=0;
  ll v=0;
  rep(i,sz(ans)){
    cu=max(ans[i],cu);
  }
  COUT(cu);
  
}
      


Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

long long N, H;
vector<pair<int, int>> all_swords;
vector<pair<int, int>> swords;
long long total_throw_damage;
long long max_wield;


// struct cmp1 {
//   bool operator< (const pair<int, int> &lhs, const pair<int, int> &rhs) const {
//     return lhs.second > right.second;
//   }
// };

int throw_all() {
  sort(swords.begin(), swords.end(),
       [](const pair<int, int> &lhs, const pair<int, int> &rhs) {
	 return  lhs.second > rhs.second;
       });

  int cnt = 0;
  long long damage = 0;
  for(auto &p: swords) {
    damage += p.second;
    cnt += 1;
    if (damage >= H) {
      return cnt;
    }
  }
}

int wield() {
  long long remain = H - total_throw_damage;
  int cnt = remain / max_wield;
  if (remain % max_wield != 0) {
    cnt++;
  }
  return swords.size() + cnt;
}

int main() {
  cin >> N >> H;

  int w , t;
  for (int i = 0; i < N; i++) {
    cin >> w >> t;
    all_swords.push_back(make_pair(w, t));
    if (w > max_wield) {
      max_wield = w;
    }
  }
  
  for (auto &p: all_swords) {
    if (p.second < max_wield) {
      continue;
    }
    total_throw_damage += p.second;
    swords.push_back(p);
  }
  

  if (total_throw_damage >= H) {
    cout << throw_all() << endl;
  } else {
    cout << wield() << endl;
  }
  
  return 0;
}


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

long long n, w;
long long dp[100][100005] = {0};
long long data[105][2] = {0};

long long solve();

int main() {
  cin >> n >> w;
  for(int i = 0; i < n; ++i)
    cin >> data[i][0] >> data[i][1];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int i = 0; i < n; ++i)
    for(int j = 1; j <= w; ++j) {
      if(i == 0 && j >= data[i][0]) dp[i][j] = data[i][1];
      if(i != 0 && j >= data[i][0])
        dp[i][j] =
            max(dp[i - 1][j],
                dp[i - 1][j - data[i][0]] + data[i][1]);
      else if(i != 0)
        dp[i][j] = dp[i - 1][j];
      if(i == n - 1) ans = max(ans, dp[i][j]);
    }
  return ans;
}

Measured memory_bytes: 78336
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
T = inl()
M = ini()


def solve():
    tsum = sum(T)
    for i in range(M):
        p, x = inm()
        p -= 1
        ans = tsum - T[p] + x
        print(ans)


solve()


Measured memory_bytes: 9148
#include<stdio.h>
#include<string.h>

int main() {
	int  q,a,b,i,j,k;
	char str[1001] = { 0 }, p[1001] = { 0 }, qes[10] = {0},x;

	scanf("%s %d",str,&q);

	for (i = 0; i < q; i++) {
		scanf("%s %d %d",qes,&a,&b);

		if (strcmp(qes,"print")==0) {
			for (j = a; j <= b; j++) {
				printf("%c", str[j]);
			}
			printf("\n");
		}
		else if (strcmp(qes, "reverse") == 0) {
			for (j = a,k=0; k <= (b-a)/2; j++,k++) {
				x = str[j];
				str[j] = str[b - k];
				str[b - k] = x;
			}
		}
		else {
			scanf("%s", p);
			
			for (j = a, k = 0; j <= b; j++, k++) {
				str[j] = p[k];
			}
		}
	}

	return 0;
}


Measured memory_bytes: 2100
# import numpy as np
import sys
input = sys.stdin.readline

N = int(input())
a = list(map(int,input().split()))

k = 1

seta = set(a)
if k not in seta:
    print(-1)
    sys.exit()

res = 0

for i in range(N):
    if a[i] == k:
        k += 1
    else:
        res += 1

print(res)


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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans(n);
	rep(i,n-1){
		if(s[i] == s[i+1]) ans--;
	}
	cout << ans<< endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<double,double> pd;
#define MAXN 100005

ll LCM(ll a,ll b){
    return a*b/__gcd(a,b);
}

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

    ll A,B;
    cin >> A >> B;
    cout << LCM(A,B) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    char ch;
    int cnt[500];
    for (int i = 0; i < 500; i++){
        cnt[i] = 0;
    }
    while (scanf(" %c", &ch) != EOF){
        if (ch >= 'A' && ch <= 'Z'){
            ch += 'a' - 'A';
        }
        cnt[ch]++;
    }
    for (int i = 'a'; i <= 'z'; i++){
        printf("%c : %d\n", i, cnt[i]);
    }
    return 0;
}


Measured memory_bytes: 2048
def lcs():
    x, y = raw_input(), raw_input()
    x1 = [0 for k in range(len(y)+1)]
    for i in xrange(len(x)):
        e = x[i]
        x2 = x1 + []
        for j in xrange(len(y)):
            if e == y[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    print max(x1)
 
n = input()
for i in xrange(n):
    lcs()

Measured memory_bytes: 6496
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n,m,x;
  cin >> n >> m >> x;
  vi mas(n + 1,0);
  rep(i,m) {
    int a;
    cin >> a;
    mas[a] = 1;
  }
  int sum1 = 0;
  rep(i,x) {
    sum1 += mas[i];
  }
  int sum2 = 0;
  for(int i = x + 1; i <= n; i++) sum2 += mas[i];
  cout << min(sum1,sum2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,m;
string s;
long long dp[1009][1009];
int main()
{
    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        cin>>s;
        for(int j=0;j<m;j++)
        {
            if(s[j]=='.')continue;
            dp[i][j]=0;
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if(dp[i][m-1]==0)break;
        dp[i][m-1]=1;
    }
    for(int i=m-1;i>=0;i--)
    {
        if(dp[n-1][i]==0)break;
        dp[n-1][i]=1;
    }
    for(int i=n-2;i>=0;i--)
    {
        for(int j=m-2;j>=0;j--)
        {
            if(dp[i][j]==0)continue;
            dp[i][j]=0;
            if(dp[i+1][j]!=-1)dp[i][j]+=dp[i+1][j]%mod;
            if(dp[i][j+1]!=-1)dp[i][j]+=dp[i][j+1]%mod;
        }
    }
    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    if(dp[0][0]==-1)cout<<0;
    else cout<<dp[0][0]%mod;
}


Measured memory_bytes: 8320
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T& v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

const int INF = 20000000;

void dfs(int v, int p, vector<int> &dist, vector<int> G[]) {
  if (dist[v] != INF) return;
  if (p != -1) dist[v] = dist[p] + 1;
  else dist[v] = 0;
  for (auto&u: G[v]) {
    if (u == p) continue;
    dfs(u, v, dist, G);
  }
}

void solve(int n, int s, int t, vector<int> &fromS, vector<int> fromT, vector<int> G[]) {
  vector<bool> done(n, false);
  priority_queue<pair<int, int> > Qs, Qt;
  Qs.push({ fromT[s], s });
  Qt.push({ fromS[t], t });
  while (Qs.size() and Qt.size()) {
    auto qs = Qs.top(); Qs.pop();
    while (done[qs.second] and Qs.size()) {
      qs = Qs.top(); Qs.pop();
    }
    if (done[qs.second]) {
      print("Snuke");
      return;
    }
    done[qs.second] = true;
    
    auto qt = Qt.top(); Qt.pop();
    while (done[qt.second] and Qt.size()) {
      qt = Qt.top(); Qt.pop();
    }
    if (done[qt.second]) {
      print("Fennec");
      return;
    }
    done[qt.second] = true;
    
    // print("Fennec", " ");
    // print(qs.second+1);
    // print("Snuke", " ");
    // print(qt.second+1);
    {
      for (auto &&u: G[qs.second]) {
        if (done[u]) continue;
        Qs.push({ -fromT[u], u }); // Tに近い方から取る.
      }
    }
    {
      for (auto &&u: G[qt.second]) {
        if (done[u]) continue;
        Qt.push({ -fromS[u], u }); // Sに近い方から取る.
      }
    }
  }
  
  if (Qs.size()) print("Fennec");
  else print("Snuke");
}


void solve2(int n, int s, int t, vector<int> &fromS, vector<int> &fromT, vector<int> G[]) {
  int cnt = 0;
  loop(i,0,n) {
    // TよりもSに近いところはFennecが取れる.
    cnt += fromS[i] <= fromT[i];
  }
  int cnt2 = n/2+1;
  if (cnt >= cnt2) print("Fennec");
  else print("Snuke");
}

int main() {
  int n;in(n);
  vector<int> G[n];
  loop(i,0,n-1) {
    int a, b; in(a),in(b);
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int s = 0, t = n-1;
  vector<int> fromS(n, INF), fromT(n, INF);
  dfs(s, -1, fromS, G);
  dfs(t, -1, fromT, G);
  
  solve2(n, s, t, fromS, fromT, G);
  return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
int main() {
  int n;
  cin >>n;
  vector<int>v(n),c(n),sa(n);
  rep(i,n)cin>>v[i];
  rep(i,n)cin>>c[i];
  rep(i,n)sa[i]=v[i]-c[i];
  sort(sa.rbegin(),sa.rend());
  int kotae=0;
  rep(i,n){
    if(sa[i]<=0)break;
    kotae+=sa[i];
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

int A, B, C, D;

int main() {
    cin >> A >> B >> C >> D;

    int p = 0;
    while (A > 0 && C > 0) {
        if (p % 2 == 0) C -= B;
        else A -= D;

        p++;
    }

    if (A <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3592
// AOL 1059 Mysterious Onslaught
// 2018.2.18 bal4u

#include <stdio.h>
#include <string.h>

int n;
int map[5][5][5][5];
char memo[1<<25];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int calc(int b)
{
	int r1, c1, r2, c2, k, ans;

	if (!b) return 0;
	if (memo[b] >= 0) return memo[b];

	for (k = r1 = 0; r1 < n; r1++, k += 5) for (c1 = 0; c1 < n; c1++) {
		if (b & (1<<(k + c1))) goto next;
	}
	return memo[b] = 0;
next:
	ans = 25;
	for (r2 = r1; r2 < n; r2++) for (c2 = c1; c2 < n; c2++) {
		k = b ^ map[r1][c1][r2][c2];
		k = calc(k) + 1;
		if (ans > k) ans = k;
	}
	return memo[b] = ans;
}

void init()
{
	int r1, r2, c1, c2, r, c;

	for (r1 = 0; r1 < 5; r1++) for (c1 = 0; c1 < 5; c1++)
		for (r2 = r1; r2 < 5; r2++) for (c2 = c1; c2 < 5; c2++)
			for (r = r1; r <= r2; r++) for (c = c1; c <= c2; c++)
				map[r1][c1][r2][c2] |= (1<<(r*5+c));
}

int main()
{
	int r, c, b, k;

	memset(memo, -1, sizeof(memo));
	init();
	while (n = in()) {
		b = 0;
		for (k = r = 0; r < n; r++, k += 5) for (c = 0; c < n; c++) {
			if (getchar_unlocked() & 1) b |= 1 << (k+c);
			getchar_unlocked();
		}
		k = calc(b);
		while (k--) printf("myon");
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 34472