akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    int pre = 0;
    ll ans = 0;
    rep(i, n)
    {
        int a;
        cin >> a;
        if (a < pre)
        {
            ans += pre - a;
        }
        pre = max(pre, a);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <math.h>
using namespace std;

#define PI 3.14159265

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...)  printf("D(L%d) %s: ", __LINE__, __func__); printf(__VA_ARGS__)
#else
#define DPRINTF(...)
#endif // DEBUG

class Point {
public:
  Point(float x, float y) :
    x_ (x), y_(y) { }
  //Point operator- (const Point& p) const;
  float x_, y_;

private:
};

class Vector {
public:
  Vector(float x, float y) :
    x_(x), y_(y) { }
  float x_, y_;

private:
};

Point rotation60(Point p0, Point p1)
{
  /*
  R = (cos  -sin) (s)
      (sin   cos) (t)
  */
  float s = p1.x_ - p0.x_;
  float t = p1.y_ - p0.y_;

  float Rx = cos(60.f * PI / 180.f) * s - sin(60.f * PI / 180.f) * t + p0.x_;
  float Ry = sin(60.f * PI / 180.f) * s + cos(60.f * PI / 180.f) * t + p0.y_;

  return Point(Rx, Ry);
}


void kochCurve(int n, Point p0, Point p1)
{
  if (n < 1)
  {
    printf("%f %f\n", p0.x_, p0.y_);
    return ;
  }

  float vx = p1.x_ - p0.x_;
  float vy = p1.y_ - p0.y_;

  Point s(p0.x_ + vx * (1.f/3.f), p0.y_ + vy * (1.f/3.f));
  Point t(p0.x_ + vx * (2.f/3.f), p0.y_ + vy * (2.f/3.f));
  Point u = rotation60(s, t);

#if DEBUG
  DPRINTF("(%1.2f, %1.2f), ", p0.x_, p0.y_);
  printf("(%1.2f, %1.2f), ",  s.x_,  s.y_);
  printf("(%1.2f, %1.2f), ",  u.x_,  u.y_);
  printf("(%1.2f, %1.2f), ",  t.x_,  t.y_);
  printf("(%1.2f, %1.2f)\n", p1.x_, p1.y_);
#endif // DEBUG

  kochCurve(n-1, p0,  s);
  kochCurve(n-1,  s,  u);
  kochCurve(n-1,  u,  t);
  kochCurve(n-1,  t, p1);

}

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

  DPRINTF("N = %d\n", n);

  Point first(0.0, 0.0), last(100.0, 0.0);
  kochCurve(n, first, last);
  printf("%f %f\n", last.x_, last.y_);

  return 0;
}


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

using namespace std;
#define local
#ifdef local

template<class T>
void _E(T x) { cerr << x; }

void _E(double x) { cerr << fixed << setprecision(6) << x; }

void _E(string s) { cerr << "\"" << s << "\""; }

template<class A, class B>
void _E(pair<A, B> x) {
    cerr << '(';
    _E(x.first);
    cerr << ", ";
    _E(x.second);
    cerr << ")";
}

template<class T>
void _E(vector<T> x) {
    cerr << "[";
    for (auto it = x.begin(); it != x.end(); ++it) {
        if (it != x.begin()) cerr << ", ";
        _E(*it);
    }
    cerr << "]";
}

void ERR() {}

template<class A, class... B>
void ERR(A x, B... y) {
    _E(x);
    cerr << (sizeof...(y) ? ", " : " ");
    ERR(y...);
}

#define debug(x...) do { cerr << "{ "#x" } -> { "; ERR(x); cerr << "}" << endl; } while(false)
#else
#define debug(...) 114514.1919810
#endif
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f3f3f
#define ll  long long
#define db long double
#define eps 1e-3
#define bin(x) cerr << bitset<10>(x) << endl
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define endl "\n"
const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 10;
const db pi = acos(-1.0);

ll qpow(ll a, ll b) {
    ll ret = 1;
    for (; b; a = a * a % mod, b >>= 1) {
        if (b & 1) {
            ret = ret * a % mod;
        }
    }
    return ret;
}

vector<ll> f(maxn), invf(maxn);

ll inv(ll a) {
    return qpow(a, mod - 2);
}

void prework() {
    f[0] = 1;
    _rep(i, 1, maxn - 1) {
        f[i] = f[i - 1] * i % mod;
    }
    invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
    for (ll i = maxn - 2; i >= 0; i--) {
        invf[i] = invf[i + 1] * (i + 1) % mod;
    }
}

ll C(ll n, ll m) {
    if (n > m || m < 0)return 0;
    if (n == 0 || m == n) return 1;
    ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
    return res;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    cout << (x == 1 ? 0 : 1) << endl;
}

Measured memory_bytes: 6280
S = gets.chomp.split('')
T = gets.chomp.split('')

result = T.length
len = T.length

0.upto(S.length - len) do |d|
    res = 0
    len.times do |i|
        if T[i] != S[d+i]
            res +=1
        end
        if res >= result
            break
        end
    end
    if res < result
        result = res
    end
end

puts result

Measured memory_bytes: 14324
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String ss = s.next(),t=s.next();
        System.out.println(t+ss);


    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

int main()
{
    string s;
    cin >> s;

    bool flag = true;
    flag &= s[0] == 'A';
    flag &= s[1] >= 'a' and s[1] <= 'z';
    flag &= s[s.size() - 1] >= 'a' and s[s.size() - 1] <= 'z';
    
    int cnt = 1;
    for (int i = 2; i < s.size() - 1; i ++)
    {
        if(i == 0) continue;
        if (s[i] >= 'a' and s[i] <= 'z') continue;
        else if (s[i] == 'C') cnt--;
        else 
        {
            flag &= false;
            break;
        }
    }


    if (cnt != 0) flag &= false;

    if (flag) 
        cout << "AC" << endl;
    else
        cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int A;

signed main(){
    cin >> A;
    cout << A + A*A + A*A*A << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#include "string"

int32_t main() {
	boost;
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < 3; i++) {
		if(s[i] != 'R')
			continue;
		int j = i;
		while(j < s.size() && s[i] == s[j])
			j++;
		ans = max(ans , j - i);
		i = j;
	} 			
	cout << ans << endl;	
}

Measured memory_bytes: 3648
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0


for i in range(n):
  if(b[i]<=a[i]):
    cnt+=b[i]
    a[i]-=b[i]
  elif(b[i]>a[i] and a[i]+a[i+1]>b[i]):
    cnt+=a[i]
    cnt+=b[i]-a[i]
    a[i+1]-=b[i]-a[i]
    a[i]=0
  else:
    cnt+=a[i]+a[i+1]
    a[i]=0
    a[i+1]=0
    
  #print(a)
    
print(cnt)

Measured memory_bytes: 19004
import java.util.Scanner;


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();


        if (a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }

        if (b > c) {
            int tmp = b;
            b = c;
            c = tmp;
        }

        if (a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }

        System.out.println(String.format("%d %d %d", a, b, c));
        sc.close();
    }
}


Measured memory_bytes: 26356
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            res = 500 * i + 100 * j + 50 * k
            if res == x:
                ans += 1
print(ans)


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

int main(){

	int n;
	while (std::cin >> n, n){

		std::vector<std::vector<int> >v(31);
		std::pair<int, std::string> res[21];

		for (int i = 0; i < 31; i++)v[i].clear();
		for (int i = 0; i < 21; i++)res[i].first = 0;

		for (int i = 0; i < n; i++){
			int m;
			std::cin >> res[i].second >> m;

			for (int j = 0; j < m; j++){
				int d;
				std::cin >> d;
				v[d].push_back(i);
			}
		}

		for (int i = 0; i < 31; i++){
			int point = n - (v[i].size() - 1);
			for (int j = 0; j < v[i].size(); j++){
				int id = v[i][j];
				res[id].first += point;
			}
		}

		std::sort(res, res + n);

		std::cout << res[0].first << " " << res[0].second << std::endl;

	}
	return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
#define SORT(A) std::sort(A.begin(), A.end())
#define RSORT(A) std::sort(A.begin(), A.end(), std::greater<>())
#define FR(A, e) for (auto& e : A)
#define SHOW(A) for (auto& e : A) {cout << e << " ";}; cout << endl;
#define within(x,_left,_right) (_left <= x && x <= _right)
#define rwithin(x, _l, _r) (_l < x && x < _r)
#define ALL(A) A.begin(),A.end()
#define RALL(A) (A).rbegin(),(A).rend()
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define sz(x) ((int)x.size())
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define bitcnt(x) (__builtin_popcountll(x))
#define fi first
#define se second
#define bg(A) A.begin()
#define ed(A) A.end()
#define rbg(A) A.rbegin()
#define red(A) A.rend()
using LL = long long;
using db = double;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VL = vector<LL>;
using VVL = vector<VL>;
const LL MOD = 1e9 + 7;
const LL LMAX = 0x7fffffffffffffff;
const LL LMIN = 0x8000000000000000;
typedef std::pair<int, int> PII;
typedef std::pair<LL, LL> PLL;
typedef std::pair<int, char> PIC;
// int dx[4] = {1, -1, 0, 0}; // 冯诺依曼型邻居
// int dy[4] = {0, 0, 1, -1};
// int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; // 摩尔型邻居
// int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
// #include<iomanip> cout << fixed <<  setprecision(k) 输出k位精度

int N, K;
VL pos, neg, zero;

void mul(LL& a, LL b){
    a = a*b % MOD;
}

int main(){
    std::cin >> N >> K;

    pos.clear(), neg.clear(), zero.clear();

    int t;
    for (int i = 0; i < N; ++ i){
        cin >> t;
        if (t > 0) pos.emplace_back(t);
        else if (t == 0) zero.emplace_back(t);
        else neg.emplace_back(t);
    }

    RSORT(pos);
    SORT(neg);

    int a = sz(pos), b = sz(neg), c = sz(zero);
    LL res = 1;

    if (a + b < K){
        cout << 0 << endl;
        return 0;
    }

    if (a + b == K){
        if ((b & 1) && c != 0){
            cout << 0 << endl;
        }else {
            for (auto &x: pos) res = (res * 1LL * x) % MOD;
            for (auto &x: neg) res = ((res * 1LL * x) + MOD) % MOD;
            cout << (res + MOD) % MOD << endl;
        }
        return 0;
    }

    int pp = 0, pn = 0;
    if ((K & 1) && a != 0){
        res = (1LL * res * pos[pp++]) % MOD;
        -- K;
    }
    else if ((K & 1) && a == 0 && c != 0){
        cout << 0 << endl;
        return 0;
    }else if ((K & 1) && a == 0 && c == 0){
        for (int i = 0, x = 0; i < K; ++ i) x = neg[b - 1 - i], res = ((res * 1LL * x) + MOD) % MOD;
        cout << (res + MOD) % MOD << endl;
        return 0;
    }

    while (K){
        LL pmax = 0, nmax = 0;
        if (pp + 1 < a) pmax = pos[pp] * pos[pp + 1];
        if (pn + 1 < b) nmax = neg[pn] * neg[pn + 1];

        if (pmax >= nmax){
            // res = (1LL * res * pmax) % MOD;
            mul(res, pmax % MOD);
            pp += 2;
        }else {
            // res = (1LL * res * nmax) % MOD;
            mul(res, nmax % MOD);
            pn += 2;
        }
        K -= 2;
    }

    cout << (res + MOD) % MOD << endl;

    return 0;
}

Measured memory_bytes: 5592
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    if A[i]%2==0:
        if A[i]%3==0 or A[i]%5==0:
            continue
        else:
            print("DENIED ")
            exit()
    else:
        continue
        
print("APPROVED ")

Measured memory_bytes: 3060
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########

def resolve():
    n = ii()
    tar = n % 1000
    print(1000 - tar if tar != 0 else 0)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9004
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setpercision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
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;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll H,N;cin>>H>>N;
    pl info[N];
    rep(i,N)cin>>info[i].fi>>info[i].se;
    ll dp[N+1][H+1];
    rep(i,N+1)rep(j,H+1)dp[i][j]=INF;
    dp[0][0]=0;
    repl(i,1,N+1)rep(j,H+1){
        ll p=info[i-1].fi,q=info[i-1].se;
        if(j-p>=0){
            dp[i][j]=min(dp[i-1][j],dp[i-1][j-p]+q);
            dp[i][j]=min(dp[i][j],dp[i][j-p]+q);
        }
        else{
            dp[i][j]=min(dp[i-1][j],(j+p-1)/p*q);
        }
    }
    cout<<dp[N][H]<<endl;
    return 0;
}

Measured memory_bytes: 78464
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a[] = new int[10];
		for(int i = 0;i <=9;i++){
			 String s = br.readLine();	 
			a[i] = Integer.parseInt(s);
		}
		java.util.Arrays.sort(a);
		for(int i = 9;i >=7;i--){
			System.out.println(a[i]);
		}
		System.exit(0);
	}
}

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

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

    int ans = A + B + C + D + E;
    int remain[5] = {
        A % 10 == 0 ? 0 : 10 - A % 10,
        B % 10 == 0 ? 0 : 10 - B % 10,
        C % 10 == 0 ? 0 : 10 - C % 10,
        D % 10 == 0 ? 0 : 10 - D % 10,
        E % 10 == 0 ? 0 : 10 - E % 10};
    sort(remain, remain + 5);
    for (int i = 0; i < 4; i++)
    {
        ans += remain[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
from fractions import gcd
n, x, d = map(int, input().split())
"""
数列からi個選ぶことを考えると
i*xに加えて足されるdの数はi(i-1)/2 〜 i(2n-1-i)/2 の任意の個数
i > j なるjで代替されるような和はこのうちどのような条件を満たすものか？
g = gcd(x, d). l = lcm(x, d)として
(g*l = x*d)
i*x + k*d が条件を満たすとすると
i*x + k*d = (i - d/g)x + (k + x/g)d が成り立つ
(i - d/g)(2n - 1 - i + d/g)/2 >= (k + x/g) となるような最大のkを求めれば，
k以下はすべてかぶる，k+1以上はすべてかぶらない

x<0 のときは
(i - d//g) * (i - d//g - 1)//2 <= (k + x//g) <= (i - d//g) * (2*n - 1 - i + d//g)//2
(i - d//g) * (i - d//g - 1)//2 - x//g <= k <= (i - d//g) * (2*n - 1 - i + d//g)//2 - x//g
となるようなkにおいてはかぶる
"""
if x == 0 and d == 0:
	print(1)
	sys.exit()
elif d == 0:
	print(n+1)
	sys.exit()

if x < 0 and x + (n-1) * d < 0:
	x, d = -x, -d

if x >= 0 and d < 0:
	x, d = x + (n-1) * d, -d

#print(x, d)
g = gcd(x, d)

ans = 1
if x >= 0:
	for i in range(1, n+1):
		#print((i - d//g) * (2*n - 1 - i + d//g) // 2 - x//g)
		k = max((i - d//g) * (2*n - 1 - i + d//g) // 2 - x//g, i * (i-1) // 2 - 1)
		#print(k)
		ans += max((i * (2*n-1-i)) // 2 - k, 0)

else:
	for i in range(1, n+1):
		overlap_u = min((i - d//g) * (2*n - 1 - i + d//g) // 2 - x//g, i * (2*n-1-i) // 2)
		overlap_l = max((i - d//g) * (i - d//g - 1) // 2 - x//g, i * (i-1) // 2)
		ans += i * (2*n-1-i) // 2 - i * (i-1) // 2 + 1 - max(overlap_u - overlap_l + 1, 0)

print(ans)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    for(int i=1;i<=5;i++)
    cin>>arr[i];
    for(int i=1;i<=5;i++){
        if(!arr[i]){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
  for(int y=0;;y++){
    
int n,m;
cin>>n>>m;
int ans=0;
    if(n==0) break;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
for(int k=j+1;k<=n;k++){
if(i+j+k==m){
ans++;
}
}
}
}
cout<<ans<<endl;
}
}


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

int main() {
	int k;
	scanf ("%d", &k);
	char str[101];
	scanf ("%s", &str);
	
	int len = strlen(str);
	if (len <= k) {
		printf ("%s", str);
	}
	else {
		for (int i = 0; i < k; i++) {
			printf ("%c", str[i]);
		}
		puts ("...");
	}
	return 0;
}

Measured memory_bytes: 1728
#include<stdio.h>
int main()
{
    int a;
    long b,n,ans;
    scanf("%d%ld%ld",&a,&b,&n);
    if(n<b)
    {
        ans=(a*n)/b;
        printf("%ld",ans);
    }
    else
    {
        ans=(a*(b-1))/b;
        printf("%ld",ans);
    }
}

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

using namespace std;

int main() {
  string s, t; cin >> s >> t;
  bool flg = true;
  for(int i = 0; i < t.size(); i++) s.push_back(s[i]);
  for(int i = 0; i < t.size(); i++) {
    if(s[i] != t[0]) continue;
    for(int j = 0; j < t.size(); j++) {
      if(s[i + j] != t[j]) {
        flg = false; break;
      }
    }
    if(flg) break;
  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

int main(){
	float a , b , f ;
	int c , d ;
	cin >> a;
	cin >> b;
	c = a;
	d = b;
	if (((a+b)/2)-((c + d)/2) >= ((((c + d)/2)+1)-((a+b)/2))){
		cout << ((c + d)/2)+1;}
	if (((a+b)/2)-((c + d)/2) < ((((c + d)/2)+1)-((a+b)/2))){
		cout << ((c + d)/2);}
}

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

void solve() {
    int n; cin>>n;
    if (n % 1000 == 0)
        cout << 0;
    else
        cout << 1000-n % 1000;
}

int main() {
    int t = 1;// scanf("%d", &t);
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3680
#include<iostream>
#include<functional>
#include<algorithm>
#include<vector>
#include<tuple>
#include<queue>

#define LL long long
#define INF (1<<30)
#define LINF (1000000000000000)
#define PP std::pair<int,int>

int X, Y, Z;
int main() {
	std::cin >> X >> Y >> Z;
	X -= Z;
	std::cout << X / (Y + Z) << std::endl;
	return 0;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

string S,T;
int L,i;
inline void solve(){
  IN2(S,T);
  L=S.size();
  REP(i,L){
    rotate(S.begin(),S.begin()+1,S.end());
    if(S==T){
      OUT("Yes");
      return;
    }
  }
  OUT("No");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
bool vis[110];

int main()
{
    int n,k;  cin >> n >> k;
    while(k--){
        int d,x;  cin >> d;
        for(int i= 0;i<d;i++)  cin >> x , vis[x] = true;
    }
    int Ans = 0;
    for(int i = 1;i<=n;i++)  Ans+=(!vis[i]);
    cout << Ans;
    return 0;
}


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

using namespace std;

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

    int tmp, c = 1;
    tmp = n % 10;
    n /= 10;
    for (int i = 0; i < 3; i++) {
        if (tmp == n % 10) {
            c++;
        } else {
            tmp = n % 10;
            c = 1;
        }
        if (c == 3) break;
        n /= 10;
    }

    if (c == 3) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 3608
#include<stdio.h>

typedef struct {
  char suit ;
  int num ;
  int idx ;
} card ;

void bubble_sort( card bubble[], int n )
{
  int i, j, s ;
  card tmp ;
  for( i = 0 ; i < n-1 ; i++ ){ // iは未ソート部の先頭
    for( j = n-1 ; j > i ; j-- ){
      if( bubble[j-1].num > bubble[j].num ){
        tmp = bubble[j-1] ;
        bubble[j-1] = bubble[j] ;
        bubble[j] = tmp ;
      }
    }
  }
  for( i = 0 ; i < n ; i++ ){
    if( i < n-1 ){
      printf("%c%d ", bubble[i].suit, bubble[i].num) ;
    }else{
      printf("%c%d\n", bubble[i].suit, bubble[i].num) ;
    }
  }
  s = 1 ;
  for ( i = 0; i < n ; i++) {
    if(i>0 && bubble[i].num==bubble[i-1].num && bubble[i].idx<bubble[i-1].idx){
      s = 0 ;
    }
  }
  if(s){
    printf("Stable\n") ;
  }else{
    printf("Not Stable\n");
  }
}

void select_sort( card select[], int n )
{
  int i, j, min_i, s ;
  card tmp ;
  // select_sort( n, select ) ;
  for( i = 0 ; i < n ; ++i ){  // i = 未ソート部分の先頭
    min_i = i ;
    for( j = i ; j < n ; ++j ){
      if( select[min_i].num > select[j].num ){
        min_i = j ;
      }
    }
    if( i != min_i ){
      tmp = select[i] ;
      select[i] = select[min_i] ;
      select[min_i] = tmp ;
    }
  }
  for( i = 0 ; i < n ; i++ ){
    if( i < n-1 ){
      printf("%c%d ", select[i].suit, select[i].num) ;
    }else{
      printf("%c%d\n", select[i].suit, select[i].num) ;
    }
  }
  s = 1 ;
  for( i = 0 ; i < n ; i++ ){
    if( i>0 && select[i].num==select[i-1].num && select[i].idx<select[i-1].idx){
      s = 0 ;
    }
  }
  if(s){
    printf("Stable\n") ;
  }else{
    printf("Not stable\n") ;
  }
}

int main()
{
  int n ;
  card bubble[37], select[37], tmp ;
  scanf("%d", &n) ;

  int i ;
  for( i = 0 ; i < n ; i++ ){
    scanf(" %c%d", &bubble[i].suit, &bubble[i].num) ;
    bubble[i].idx  = i ;
    select[i] = bubble[i] ;
  }

  bubble_sort( bubble, n ) ;
  select_sort( select, n ) ;

  return 0 ;
}



Measured memory_bytes: 2036
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int X = input[0];
            int t = input[1];
            Console.WriteLine(X >= t ? X - t : 0);
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <limits>
#include <random>
#include <chrono>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

ll ans1(ll a, ll b, ll x){
    ll ret = 0;
    for(ll i = a; i <= b; ++i){
        if(i % x == 0){
            ++ret;
        }
    }
    return ret;
}
ll ans2(ll a, ll b, ll x){
    ll ret;
    if(a > 0){
        // floor(a/x) gives number of integers divisible by x in [1, a];
        ret = (b/x) - ((a-1)/x); 
    }
    else {
        ret = b/x + 1; // 1 added because all integers divide 0
    }
    return ret;
}
int rand(int a, int b){
    return a + rng() % (b - a + 1);
}
int main(int argv, char **argc){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
    ll O, Q, W;
    scanf("%lld %lld %lld", &O, &Q, &W);
    printf("%lld\n", ans2(O, Q, W));
    return 0;
    int T = 0;
    while(1){
        int a = rand(0, (int)1e8);
        int b = rand(a, a + (int)1e6);
        int x = rand(1, b + 1);
        int r1 = ans1(a, b, x); 
        int r2 = ans2(a, b, x); 
        if(r1 != r2){
            break;
        }
        else {
            printf("Test %d passed\n", ++T);
        }
    }
}
//printf("%.5f\n", clock() / (float)CLOCKS_PER_SEC); time in seconds


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

// ------------------------------------------------------------------------------------------

using pii = pair<int, int>;

int N;
vec<int> A, B;
vector<pii> C;

signed main() {
  cin >> N;
  A.resize(N), B.resize(N);
  rep (i, N) {
    cin >> A[i] >> B[i];
    C.push_back({A[i] + B[i], i});
  }
  sort(all(C));
  reverse(all(C));

  int tAns = 0, aAns = 0;
  rep (i, N) {
    int index = C[i].second;
    if (i % 2 == 0) {
      tAns += A[index];
    } else {
      aAns += B[index];
    }
  }

  cout << tAns - aAns << endl;

  return 0;
}

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

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set([1])
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:#計算量的に間に合うので愚直に
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:
            roop = route[i:-1]
            print(roop[(k - i) % len(roop)])
            exit()

   


Measured memory_bytes: 49240
// -*- coding:utf-8-unix -*-

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
 // ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        s: String,
    }
    for i in 0..(1 << s.len() - 1) {
        let mut result:String = String::new();
        let mut res = 0i32;
        let mut calc = '+';
        for (j,c) in s.chars().enumerate(){
            match calc {
                '+' => res += c.to_digit(10).unwrap() as i32,
                '-' => res -= c.to_digit(10).unwrap() as i32,
                _ => ()
            }
            result.push(c);
            if j  < s.len() - 1  {
                if i & (1 << j) != 0 {
                    result.push('+');
                    calc = '+';
                } else {
                    result.push('-');
                    calc = '-';
                }    
            }
        }
        if res == 7{
            result.push_str("=7");
            println!("{}",result);
            return;
        }
    }
}


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

int main() {
  string s;
  cin>>s;
  long int x=0;
  long int ans=0;
  
  for(long int i=0;i<s.size();i++){
    if(s.at(i)=='B'){
      x++;
      }
    if(s.at(i)=='W'){
      ans+=x;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
from math import factorial

MOD = 10 ** 9 + 7

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

invsum = [0] * (N + 1)
for i in range(1, N + 1):
    invsum[i] = (invsum[i - 1] + pow(i, MOD - 2, MOD)) % MOD

ans = 0
for i in range(1, N + 1):
    ans += (A[i - 1] * (invsum[i] + invsum[N - i + 1] - 1)) % MOD

ans *= factorial(N)
print(ans % MOD)

Measured memory_bytes: 15020
#include <stdio.h>

int main(void) {
	int r, c, s;
	scanf("%d %d", &r, &c);
	int cell[r + 1][c + 1];
	for (int i = 0; i < r; i++) {
		s = 0;
		for (int j = 0; j < c; j++) {
			scanf("%d", &cell[i][j]);
			s += cell[i][j];
		}
		cell[i][c] = s;
	}
	for (int j = 0; j < c + 1; j++) {
		s = 0;
		for (int i = 0; i < r; i++) {
			s += cell[i][j];
		}
		cell[r][j] = s;
	}
	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c + 1; j++) {
			printf("%d", cell[i][j]);
			if (j < c) {
				printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b; cin >> a >> b; string ans;
if(a>0){ ans="Positive"; }
else if(a<=0 && b>=0){ ans="Zero"; }
else{ ans=((b-a)%2)?"Positive":"Negative"; }  
cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
int main() {
	string S;
	cin >> S;
	for (int i = 0; i <= 2; i++) {
		if (S[i] == S[i + 1]) { cout << "Bad"; return 0; }
	}
	cout << "Good";
}

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

dp=[0]*(k+1)

for i in range(1,k+1):
    for j in a:
        if(j<=i):
            if(dp[i-j]==0):
                dp[i]=1


if(dp[k]==1):
    print('First')
else:
    print('Second')


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

using namespace std;
typedef unsigned long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    cin >> N;

    ll mx = -1;
    for(ll i = 1; i <= sqrt(N); i++){
        mx = i * i;
    }
    cout << mx << endl;

}

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

int main()
{
    int N, K;
    cin >> N >> K;

    double probability = 0;

    for (double roll = 1; roll <= N; roll++)
    {
        int throwTimes = ceil(log2(K / roll));
        if (throwTimes < 0)
            throwTimes = 0;

        //probability += pow(0.5, throwTimes);
        probability += pow(2, -throwTimes);
    }

    cout << setprecision(13) << probability / N;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		int X = Integer.parseInt(W);





		int ans = 0;

		int hand = (int)X/100;
		if(hand == 0){
			ans = 0;
		}else{
			if(hand*5 < Integer.valueOf(W.substring(W.length()-2))){
				ans = 0;
			}else{
				ans = 1;
			}
		}

		System.out.println(ans);



	}


}


Measured memory_bytes: 21204
H , W = map(int,input().split())

if H == 1 or W ==1:
    print(1)
    exit()

if H %2 == 0:
    tate = H/2
    ans = tate * W

else:
    tate1 = H // 2 + 1
    tate2 = H // 2
    if W % 2 == 0:
        ans = (tate1 + tate2) * W/2
    else:
        ans = tate1*((W//2)+1) + tate2*(W//2)
print(int(ans))


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;


public class Main {

	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int A = sc.nextInt();
			final int B = sc.nextInt();
			final int C = sc.nextInt();
			
			if((A == B || B == C || C == A) && !(A == B && B == C)) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N;
    int nosolve = -1;
    int upplim = -1;
    int index = 1;
    cin >> N;
    while(N >= 0){
        N -= index;
        index++;
    }
    nosolve = abs(N);
    for(int i = 1; i < index; i++){
        if(i != nosolve) printf("%d\n", i);
    }

    return 0;
}

void solve(){}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    NI = lambda : int(sys.stdin.readline())

    N = NI()

    a = []
    for i in range(3,30001):
        if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
            a.append(i)

    ans = []
    s = 0
    for x in a[:N-2]:
        ans.append(x)
        s += x
    i = N-2
    while (s + a[i]) % 2:
        i += 1
    ans.append(a[i])
    s += a[i]

    i += 1
    while (s + a[i]) % 30 > 0:
        i += 1
    ans.append(a[i])

    print(*ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 78148
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

string odd = "RUD";
string even = "LUD";

bool judge(char ch,bool o) {
	bool y = false;
	if (o) {
		for (int j = 0; j < odd.size(); j++) {
			if (ch == odd.at(j)) {
				y = true;
			}
		}
	}
	else {
		for (int j = 0; j < even.size(); j++) {
			if (ch == even.at(j)) {
				y = true;
			}
		}
	}
	return y;
}

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		char c = s.at(i);
		bool ans;
		if (i % 2 == 0) {
			ans = judge(c, true);
		}
		else {
			ans = judge(c, false);
		}
		if (!ans) {
			cout << "No";
			break;
		}
		else if (ans && i == s.size() - 1) {
			cout << "Yes";
		}
	}
}

Measured memory_bytes: 256
# D - String Formation
from collections import deque


def main():
    S = input().rstrip()
    Q = int(input())
    queue = deque(S)
    to_beginning, to_end = queue.appendleft, queue.append
    is_reversed = 0
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            is_reversed ^= 1
            continue
        com, c = query[1], query[2]
        if com == "1":
            if not is_reversed:
                to_beginning(c)
            else:
                to_end(c)
        else:
            if not is_reversed:
                to_end(c)
            else:
                to_beginning(c)
    ans = "".join(queue) if not is_reversed else "".join(reversed(queue))
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

#define hash sodnf9843bsd
#define ll long long
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define YESNO(ans) cout << (ans?"YES":"NO") << endl
#define prec(x) cout << fixed << setprecision(x)
#define pqueue priority_queue
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll dp[111][100005] = {};

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

    int n, w;cin>>n>>w;
    int iw[111], iv[111];
    _fi(n) cin>>iw[i+1]>>iv[i+1];

    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= w;j++){
            if (j < iw[i]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-iw[i]]+iv[i]);
        }
    }
    
    cout << dp[n][w] << endl;

    return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    vector<string> v(N);
    REP(i, N) {
        cin >> v[i];
        SORT(v[i]);
    }
    SORT(v);
    v.push_back("");
    LLI cnt = 0;
    int p = 0;
    FOR(i, 0, N + 1) {
        if(v[p] != v[i]) {
            LLI l = i - p;
            p = i;
            if(l < 2)
                continue;
            if(l % 2 == 1) {
                cnt += l / 2 * (l);
            } else {
                cnt += l / 2 * (l - 1);
            }
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int N;

int main() {
	cin >> N;
	vector<long long int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	int ans = 0;
	int now = 0;
	for (int i = 1; i < N; i++) {
		if (H[i] <= H[i - 1]) { now++; }
		else {
			ans = max(ans, now);
			now = 0;
		}
	}
	cout << max(ans, now) << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  vector<string> str;
  while (1) {
    cin >> s;
    if (s == "-")
      break;
    int n, m;
    cin >> n;
    rep(i, n) {
      cin >> m;
      string t;
      t = s.substr(0, m);
      s.erase(0, m);
      s += t;
    }
    str.push_back(s);
  }

  rep(i, str.size()) cout << str[i] << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> PII;

const int MAXN = 3e5 + 10;

int n, m;

class BITree{
public:
    static const int SIZE = 100010, BIAS = 5;
    int u[SIZE];
    void clear(){
        memset(u,0,sizeof(u));
    }
    void modify(int x, int v){
        for(x+=BIAS;x<SIZE;x+=x&-x) u[x]+=v;
    }
    int getsum(int x){
        int s=0;
        for(x+=BIAS;x;x-=x&-x) s+=u[x];
        return s;
    }
} honoka;

int ans[MAXN];
vector<int> E[MAXN];
vector<PII> F[MAXN];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		E[y].emplace_back(x);
	}
	ans[1] = 0;
	for(int i = 2; i <= m; i++){
		ans[i] = 0;
		for(int j = 0; j < m; j += i){
			F[min(j+i-1,m)].emplace_back(PII(i,j+1));
		}
	}
	for(int i = 0; i <= m; i++){
		for(int j = 0; j < E[i].size(); j++)
			honoka.modify(E[i][j]+1, -1),honoka.modify(-1, 1);
		for(int j = 0; j < F[i].size(); j++)
			ans[F[i][j].first] += honoka.getsum(F[i][j].second);
	}
	for(int i = 1; i <= m; i++)
		printf("%d\n", n - ans[i]);
	return 0;
}


Measured memory_bytes: 32760
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int A[n]={};
    int MaxA = 0;
    int MinA = 1e9;
    int ans;
    for(int i=0;i<n;i++){
        cin >>A[i];
        // if(i==0){
        //     MaxA=A[i];
        //     MinA=A[i];
        // }
        MaxA=max(MaxA,A[i]);
        MinA=min(MinA,A[i]);
    }
    // sort(A, A+n);
    cout << MaxA-MinA <<endl;
    // cout << A[n-1] - A[0] <<endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())

class human:
    def __init__(self, a):
        self.a = a
        self.x = [None for i in range(a)]
        self.y = [None for i in range(a)]

humans = [[]for i in range(n)]
for i in range(n):
    a = int(input())
    humans[i] = human(a)
    for j in range(a):
        x, y = map(int, input().split())
        humans[i].x[j] = x
        humans[i].y[j] = y

loop_n = 2**n


def solve(bit_true):
    for i, bit in enumerate(bit_true):
        if bit == '1':
            for j, x in enumerate(humans[i].x):
                if int(bit_true[x-1]) == int(humans[i].y[j]):
                    pass
                elif int(bit_true[x-1]) != int(humans[i].y[j]):
                    return 0
    return sum(map(int, list(bit_true)))


i = 0
true_n = 0
while i < loop_n:
    bit_true = format(i, 'b').zfill(n)
    true_n = max(true_n, solve(bit_true))
    i += 1

print(true_n)

Measured memory_bytes: 48732