akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T> T input() {T t; cin>>t; return t;}
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
#define cspace ' '
#define sspace " "
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};


int main()
{
    ll n, k, ans = 1ll;
    cin>>n>>k;
    VLL a(n);
    int npos = 0, nzero = 0, nneg = 0;
    REP(i,n) {
        cin>>a[i];
        if (a[i] > 0) npos++;
        else if (a[i] < 0) nneg++;
        else nzero++;
    }
    SORT(a);

    if (npos == 0) {
        if (k % 2 == 0) {
            REP(i,k) {
                ans = (ans * a[i]) % MOD;
            }
        } else {
            if (nzero > 0){
                ans = 0;
            } else {
                REP(i,k) {
                    ans = (ans * a[n-1-i]) % MOD;
                }
            }
        }
    } else {
        int l = 0, r = n-1;
        REP(i,k/2) {
            if (a[l] * a[l+1] >= a[r] * a[r-1]) {
                ans = (ans * (a[l] * a[l+1] % MOD)) % MOD;
                l += 2;
            } else {
                ans = (ans * (a[r] * a[r-1] % MOD)) % MOD;
                r -= 2;
            }
        }

        if (k % 2 == 1) {
            ans = (ans * a[r]) % MOD;
        }
    }
    cout<<(ans+MOD)%MOD<<endl;


    return 0;
}


Measured memory_bytes: 4836
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct site
{
    int t;
    int x,y;
};
int main()
{
    int i,j,k,n,flag=1,p,q;
    scanf("%d",&n);
    struct site s[n+1];
    s[0].t=0;
    s[0].x=0;
    s[0].y=0;
    for(i=1;i<n+1;i++)
    {
        scanf("%d%d%d",&s[i].t,&s[i].x,&s[i].y);
        p=s[i].t-s[i-1].t;
        q=abs(s[i].x-s[i-1].x)+abs(s[i].y-s[i-1].y);
        if((p-q)%2==1||p<q)flag=0;
    }
    if(flag)
        printf("Yes");
    else printf("No");
    return 0;
}

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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  int ans = 1;
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    if (ans == x) ans++; 
  }

  ans--;
  ans = n - ans;
  if (ans == n) ans = -1;
  cout << ans << '\n';
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

//prototype declaration
int getint();
long long getllint();
double getdint();
char getch();
void setstring(char *s);
void showint(int i);
void showllint(long long i);
void showdouble(double i);
void showchar(char c);
void showstring(char *s);

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int min(int a, int b) {
	return a < b ? a : b;
}

int main(void) {
	int x[3], y[3];
	x[1] = getint();
	y[1] = getint();
	x[2] = getint();
	y[2] = getint();
	x[0] = x[2] - x[1];
	y[0] = y[2] - y[1];
	printf("%d %d %d %d\n", x[2] - y[0], y[2] + x[0], x[1] - y[0], y[1] + x[0]);
	return 0;
}

int getint() {
	int i;
	scanf("%d", &i);
	return i;
}

long long getllint() {
	long long i;
	scanf("%lld", &i);
	return i;
}

double getdint() {
	double i;
	scanf("%lf", &i);
	return i;
}

char getch() {
	char c;
	scanf("%c", &c);
	return c;
}

void setstring(char *s) {
	scanf("%s", s);
}

void showint(int i) {
	printf("%d\n", i);
}

void showllint(long long i) {
	printf("%lld\n", i);
}

void showdouble(double i) {
	printf("%lf\n", i);
}

void showchar(char c) {
	printf("%c\n", c);
}

void showstring(char *s) {
	printf("%s\n", s);
}


Measured memory_bytes: 128
import * as fs from "fs";

function main(input: string[]) {
  const windowWidth = parseInt(input[0]);
  const cartainWidth = parseInt(input[1]) * 2;

  const coveredWidth = Math.min(windowWidth, cartainWidth);
  console.log(windowWidth - coveredWidth);
}

main(fs.readFileSync("/dev/stdin", "utf8").split(" "));


Measured memory_bytes: 7372
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n;  cin >> n;
    vector<pair<int, int> >a(n);
    vector<pair<int, int> >b(n);
    rep(i, n){
        cin >> a[i].first;
        a[i].second = i;
    }
    rep(i, n){
        cin >> b[i].first;
        b[i].second = i;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    //回数無視
    rep(i, n){
        if(a[i].first > b[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    //変換可能か
    rep(i, n-1){
        if(b[i].first >= a[i+1].first){
            cout << "Yes" << endl;
            return 0;
        } 
    }
    //n-1回swapしたかどうか
    vector<int>tmp(n);
    rep(i, n){
        tmp[a[i].second] = b[i].second;
    }
    int len = 1;
    int pos = tmp[0];
    while(pos != 0){
        pos = tmp[pos];
        len++;
    }
    if(len < n){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int deco(string s)
{
    int ret = 0;
    int tmp = 1;
    rep(i, s.size())
    {

        if ('2' <= s[i] && s[i] <= '9')
        {
            tmp = s[i] - '0';
        }
        else
        {

            if (s[i] == 'm')
                ret += 1000 * tmp;
            if (s[i] == 'c')
                ret += 100 * tmp;
            if (s[i] == 'x')
                ret += 10 * tmp;
            if (s[i] == 'i')
                ret += tmp;
            tmp = 1;
        }
    }
    return ret;
}

string enco(int n)
{
    string ret = "";
    string s = "0123456789";
    string d = "mcxi";
    int k = 1000;
    int kk = 0;
    rep(i, 4)
    {
        int t = n / k;
        if (t != 0)
        {
            if (t == 1)
                ret += string() + d[kk];
            else
                ret += string() + s[t] + d[kk];
        }
        n %= k;
        k /= 10;
        kk++;
    }
    //cerr << string() + s[0] + "123" << endl;
    return ret;
}

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    rep(i, n)
    {
        string s1, s2;
        cin >> s1 >> s2;

        //cerr << deco(s1) << "," << deco(s2) << endl;
        cout
            << enco(deco(s1) + deco(s2)) << endl;
    }
    return 0;
}



Measured memory_bytes: 3020
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (200000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // accumulate
  int acc_max_ls[MAX_N], acc_max_rs[MAX_N];
  acc_max_ls[0] = as[0];
  for (int i = 1; i < N; i++) {
    acc_max_ls[i] = max(acc_max_ls[i - 1], as[i]);
  }
  acc_max_rs[N - 1] = as[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    acc_max_rs[i] = max(acc_max_rs[i + 1], as[i]);
  }

  // solve
  printf("%d\n", acc_max_rs[1]);
  for (int i = 1; i < N - 1; i++) {
    printf("%d\n", max(acc_max_ls[i - 1], acc_max_rs[i + 1]));
  }
  printf("%d\n", acc_max_ls[N - 2]);
  
  return 0;
}


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

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

    if(S.at(0)==S.at(1)){
        cout << "Bad" << endl;
    }

    else if(S.at(1)==S.at(2)){
        cout << "Bad" << endl;
    }

    else if(S.at(2)==S.at(3)){
        cout << "Bad" << endl;
    }

    else{
        cout << "Good" << endl;
     }


}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
double N, X, T;
int res;
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N >> X >> T;
	res = ceil(N / X) * T;
	cout << res;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    string s;
    ll x= 0 , y = 0 ;
    cin >> s ;
    forn(i , 0 , s.len-1){
      if(s[i] == 'o') ++x;
      else ++y;
    }
    ll rem = 15 - s.len;
    if(rem + x >=8){
        cout << "YES\n";
        ro ;
    }
    else cout << "NO\n";
    ro ;

}































Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define len(s) s.length()
#define forp(i,a,b) for( i=a;i<=b;i++)
#define rep(i,n)    for( i=0;i<n;i++)
#define ren(i,n)    for( i=n-1;i>=0;i--)
#define forn(i,a,b) for( i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define b(v) v.begin()
#define e(v) v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vii vector<int>
#define vll vector<long long>
#define gl(cin,s)  getline(cin,s);
#define bitc(n) __builtin_popcountll(n)
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define SIZE 110
#define SZ 100010

typedef long long  ll;
typedef unsigned long long ull;
typedef long double  ldo;
typedef double  db ;
using namespace std;
int N,K;
int A[SIZE];
long long dp[SZ];
long long pref[SZ];
int main()
{
    /* #ifndef ONLINE_JUDGE
    freopen(fi, "r", stdin);
    #endif */
    //freopen("route.in","r",stdin);
    //freopen("route.out","w",stdout);
    //cin.ignore();
    //cin.clear();
    boost;
    //cin.tie(0);
    //cout<<"Case "<<tt<<": ";
    cin>>N>>K;
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }
    dp[0] = 1;
    pref[0] = dp[0];
    for(int i=1;i<=K;i++){
        pref[i] = pref[i-1] + dp[i];
    }
    for(int i=1;i<=N;i++){
        dp[0] = 1;
        for(int j=1;j<=K;j++){
            int mn = 0;
            int mx = min(A[i],j);
            int Mn = j-mx;
            int Mx = j;
            if(Mn){
                dp[j] = pref[Mx] - pref[Mn-1];
            }
            else{
                dp[j] = pref[Mx];
            }
            if(dp[j] < 0)
                dp[j] += MOD;
        }
        pref[0] = dp[0];
        for(int j=1;j<=K;j++){
            pref[j] = pref[j-1] + dp[j];
            pref[j] %= MOD;
        }
    }
    cout<<dp[K]<<endl;
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
mosters = list(map(int, input().split()))
heros = list(map(int, input().split()))
cnt = 0

for i in range(N):
    if heros[i] <= mosters[i]:
        cnt += heros[i]
    else:
        cnt += mosters[i]
        if (heros[i] - mosters[i]) >= mosters[i+1]:
            cnt += mosters[i+1]
            mosters[i+1] = 0
        else:
            cnt += heros[i] - mosters[i]
            mosters[i+1] -= (heros[i] - mosters[i])

print(cnt)

Measured memory_bytes: 18624
#include<iostream>

using namespace std;

int main(){
    int a,b;
    char c;
    for(int i=0; ;i++){
        
        cin>>a>>c>>b;
        
        if(c=='?')break;
         if(c=='+')cout<<a+b<<endl;
        if(c=='-')cout<<a-b<<endl;
         if(c=='*')cout<<a*b<<endl;
          if(c=='/')cout<<a/b<<endl;
    }
    
    return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    set<int> se;

    for (int i = 0; i < n; ++i) {
        int a; cin >> a;

        se.insert(a);
    }

    if (se.size() == n) {
        puts("YES");
    } else {
        puts("NO");
    }
}

Measured memory_bytes: 9600
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace ConsoleApp
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var x = ReadLine().Split().Select(int.Parse).ToArray();

            var dp = new long[n + 1,110];
            
            dp[0, 0] = 0;
            for (int i = 0; i < n;i++)
            {
                for (int j = 1; j <= 100;j++)
                {
                    dp[i + 1, j] = dp[i, j] + (x[i]-j)*(x[i]-j);
                }
            }

            long min = dp[n, 1];
            for (int i = 1; i <= 100;i++)
            {
                if(min > dp[n,i])
                    min = dp[n, i];
            }

            WriteLine(min);

        }

      


    }

}


Measured memory_bytes: 13336
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	int a1, a2, a3;
	while(scanf("%d%d%d", &a1, &a2, &a3)==3)
	{
		bool ans=((a1+a2+a3)<=21);

		printf("%s\n", ans?"win":"bust");
	}
	return 0;
}


Measured memory_bytes: 128
a,b=map(x->parse(Int,x)-1,split(readline()))
println("40 100")
for i=0:9
	for j=1:50
		if a>0
			a-=1
			print("#.")
		else
			print("##")
		end
	end
	println()
	println("####################################################################################################")
end
for i=0:9
	println("....................................................................................................")
	for j=1:50
		if b>0
			b-=1
			print("#.")
		else
			print("..")
		end
	end
	println()
end


Measured memory_bytes: 168940
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

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

static uint32_t A[100000];

int compare_int(const void *a, const void *b) {
	return (int)((int32_t)*((uint32_t *)b) - (int32_t)*((uint32_t *)a));
}

int main(void) {
	uint32_t N;

	scanf("%"PRIu32"\n", &N);
	for (uint32_t idx = 0; idx < N; idx++) {
		scanf(idx != N - 1 ? "%"PRIu32" " : "%"PRIu32, &(A[idx]));
	}

	qsort(A, N, sizeof(uint32_t), compare_int);

	uint32_t bar[3] = { 0,0,0 };
	size_t pos = 0;
	size_t sameNumCount = 1;
	for (size_t i = 1; i < N && pos < 2; i++) {
		if (A[i] == A[i - 1]) {
			sameNumCount++;
		}
		if (A[i] != A[i - 1] || i == N - 1) {
			if (2 <= sameNumCount && sameNumCount < 4) {
				bar[pos] = A[i - 1];
				pos++;
			}
			else if (sameNumCount >= 4) {
				bar[pos] = A[i - 1];
				bar[pos + 1] = A[i - 1];
				pos += 2;
			}

			sameNumCount = 1;
		}
	}

	printf("%"PRIu64"\n", (uint64_t)(bar[0])*(uint64_t)(bar[1]));

	return 0;
}


Measured memory_bytes: 892
///
// File:  c.cpp
// Author: ymiyamoto
//
// Created on Sat Dec 23 21:48:23 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

uint64_t pow(uint64_t n)
{
  uint64_t ret = 1;
  for (uint64_t i = 0; i < n; i++) {
    ret *= 2;
  }
  return ret;
}

int32_t main()
{
  uint64_t X, Y;
  cin >> X >> Y;

  for (uint64_t i = 1; true; i++) {
    if (pow(i) * X > Y) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,h,w;

int main(){
    cin >> n >> h >> w;
    ll ans = 0;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        if(h <= a && w <= b)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

char S[55][55];

int main() {
  int N, M, i, j, k, c, cnt, row;
  scanf("%d%d", &N, &M);
  for (i = 0; i < N; i++) {
    scanf("%s", S[i]);
  }
  int ans = 999999;
  for (i = 1; i <= N-2; i++) {
    for (j = 1; i+j <= N-1; j++) {
      cnt = 0;
      row = 0;
      for (k = 0; k < i; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'W') cnt++;
        }
        row++;
      }
      for (k = 0; k < j; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'B') cnt++;
        }
        row++;
      }
      for (k = 0; k < N-i-j; k++) {
        for (c = 0; c < M; c++) {
          if (S[row][c] != 'R') cnt++;
        }
        row++;
      }
      if (cnt < ans) ans = cnt;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 2760
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll a,b,x;
int main(){
    cin >> a >> b >> x;
    if(a == 0) cout << b/x + 1 << '\n';
    else cout << b/x - (a-1)/x << '\n';
}

Measured memory_bytes: 256
s = input()

s2 = s
word_list = ['dream', 'dreamer', 'erase', 'eraser']
while len(s2) > 0:
  match_flg = False
  for word in word_list:
    if s2[-len(word):] == word:
      s2 = s2[:(len(s2)-len(word))]
      match_flg = True
      break
  if not match_flg:
    break
if len(s2) == 0:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 3316
#include<stdio.h>
#define MAX 100

int main(){
    int a[MAX][MAX], b[MAX][MAX], n, m, l, i, j, k;
    long long int c[MAX][MAX] = {};
    scanf("%d %d %d", &n, &m, &l);
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(i = 0; i < m; i++){
        for(j = 0; j < l; j++){
            scanf("%d", &b[i][j]);
        }
    }

    for(i = 0; i < n; i++){
        for(j = 0; j < l; j++){
            for(k = 0; k < m; k++){
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < l; j++){
            printf("%Ld", c[i][j]);
            if(j < l - 1) printf(" ");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2000
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;
using pi = pair<int, int>;
using vp = vector<pi>;
using Graph = vector<vector<int>>;

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

#define P (1'000'000'007)

signed main() {
    int n, k;
    cin >> n >> k;

    Graph g(n, vi());

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> dp(n, -1);

    queue<int> q;
    q.push(0);
    dp[0] = 0;
    int ans = k;

    while (!q.empty()) {
        auto u = q.front(); q.pop();
        for (auto v: g[u]) {
            if (dp[v] == -1) {
                dp[u] += 1;
                dp[v] = 1;
                ans *= (k - dp[u]);
                ans %= P;
                q.push(v);
            }
        }
    }

    cout << ans;
 
    return 0;
}


Measured memory_bytes: 10808
use std::io;


fn main() {
    let s = read_one::<String>().chars()
        .collect::<Vec<char>>();
    let w = read_one::<usize>();
    let mut ans = String::new();

    for i in 0..s.len() {
        if i % w == 0 { ans += s[i].to_string().as_str(); }
    }

    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}

i64 pmod(i64 x, i64 m) {
    return (x % m + m) % m;
}

using P = pair<i64, i64>;
int main() {
    i64 N, L, T;
    cin >> N >> L >> T;
    vector<P> data(N);
    for(P&d : data) {
        cin >> d.first >> d.second;
        if(d.second == 2) d.second = -1;
    }
    i64 a0, w0, x0;
    vector<i64> ans(N);
    for(int i = 0; i < N; i++) {
        i64 x, w;
        tie(x, w) = data[i];
        ans[i] = pmod(x + w * T, L);
    }
    tie(x0, w0) = data[0];
    a0 = ans[0];
    sort(WHOLE(ans));
    int k;
    for(int i = 0; i < N; i++) {
        if(ans[i] == a0) {
            k = i;
            if(w0 == -1) break;
        }
    }
    i64 shift = 0;
    for(int i = 1; i < N; i++) {
        if(w0 != data[i].second) {
            i64 D;
            if(w0 == 1) {
                D = data[i].first - x0;
            } else {
                D = x0 + L - data[i].first;
            }
            if(D <= 2 * (T % L)) shift++;
            if(D + L <= 2 * (T % L)) shift++;
            shift += 2 * (T / L);
            shift %= N;
        }
    }
    for(int i = 0; i < N; i++) {
        cout << ans[pmod(k - w0 * shift + i, N)] << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
'use strict'

/////////////////////////////////////
//コピペスペース//////////////////////

//定数
const INF  =  900719925474099 // Math.floor(Number.MAX_SAFE_INTEGER / 10);

//スペース区切りの数字列を数字の配列にして返す
function mapint(line){return line.split(' ').map((v)=>parseInt(v));}

function lower_bound(d,a,b,e){
    for(var c;1<b-a;)
        d[c=0|(a+b)/2]<e ? a=c : b=c;
    return d[a]<e?b:a
};

const MOD = 1000000007;
const N109 = 1000000000;

//コピペスペース//////////////////////
/////////////////////////////////////

function Main(input){
	let temp = input.trim();
	let ab = mapint(temp);
	let a = ab[0];
	let b = ab[1];
	if((a+b)%2==0){
		console.log((a+b)/2);
	}else{
		console.log('IMPOSSIBLE');
	}
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7884
#include <cstdio>
#include <cstdint>
#include <vector>

int main() {
  size_t N;
  int x;
  scanf("%zu %d", &N, &x);

  std::vector<int> a(N);
  for (size_t i=0; i<N; ++i)
    scanf("%d", &a[i]);

  intmax_t res=0;
  if (a[0] > x) {
    res = a[0]-x;
    a[0] = x;
  }

  for (size_t i=1; i<N; ++i) {
    if (a[i-1]+a[i] > x) {
      int exc=a[i-1]+a[i]-x;
      res += exc;
      a[i] -= exc;
    }
  }

  printf("%jd\n", res);
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	long long i, X;
	scanf("%lld", &X);
	for (i=1LL;;i++) {
		if (X<=i*(i+1LL)/2LL) break;
	}
	printf("%lld\n", i);

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
      
       if (N != 1 && M != 1) {
       	  System.out.print(1);
       } else if (N != 2 && M != 2) {
       	  System.out.print(2);
       } else if (N != 3 && M != 3) {
       	  System.out.print(3);
       }
	
	return;

	}
}

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

using namespace std;

const int INF = 0x3f3f3f3f;

const int N = 120; 

int d[N][N];

struct Edge {
    int x, y, c;
    Edge() {}
    Edge(int _x, int _y, int _c) : x(_x), y(_y), c(_c) {}
};

void solve() {
    int n,m;
    cin >> n >> m;
    vector<Edge> es(m);
    memset(d, INF, sizeof d);
    for (int i = 0; i < m; i++) {
        int x,y,c;
        cin >> x >> y >> c;
        x--;y--;
        es.emplace_back(x,y,c);
        d[x][y] = d[y][x] = c;
    }
    for (int i = 0; i < n; i++) {
        d[i][i] = 0;
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (d[i][k] < INF && d[k][j] < INF) {// for negative
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
    }
    int cnt = 0;
    for (auto& e: es) {
        if (d[e.x][e.y] < e.c) cnt++;
    }
    cout << cnt;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var s = ReadLine().Split().Select(a => int.Parse(a)).ToArray();
        for(int i = s[0]; i <= s[1]; i++)
        {
            if(i % n == 0)
            {
                WriteLine("OK");
                return;
            }
        }
        WriteLine("NG");
    }
}


Measured memory_bytes: 19088
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;

int main(void) {
    ll k;
    cin >> k;
    
    if(k%2==0) {
        cout << k/2*k/2 << endl;
    }else {
        cout << k/2*(k+1)/2 << endl;
    }
    
}


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

int main() {
    long a, b, c, k;
    long sum = 0;
    long tmp;

    cin >> a >> b >> c >> k;
    if (k && a) {
        tmp = min(a, k);
        k -= tmp;
        sum += tmp;
    }

    if (k && b) {
        tmp = min(b, k);
        k -= tmp;
    }

    if (k && c) {
        tmp = min(c, k);
        sum -= tmp;
    }

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &a[i]);
  }
  vector<ll> b(N);
  for (ll bit = 0; bit <= 30; ++bit)
  {
    ll cnt = 0;
    for (int i = 0; i < N; ++i)
    {
      if (a[i] & (1 << bit))
        cnt++;
    }
    for (int i = 0; i < N; ++i)
    {
      if (a[i] & (1 << bit))
        b[i] += (cnt - 1LL) % 2LL * (1LL << bit);
      else
        b[i] += cnt % 2LL * (1LL << bit);
    }
  }
  for (int i = 0; i < N; ++i)
    cout << b[i] << " \n"[i == N - 1];

  return 0;
}


Measured memory_bytes: 6336
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int A, B, a, b;
	cin >> A >> B;

	int tmp = 1;
	REP(i, A - 1)
	{
		tmp = tmp * 10 + 1;
	}
	b = B * tmp;

	tmp = 1;
	REP(i, B - 1)
	{
		tmp = tmp * 10 + 1;
	}
	a = A * tmp;

	if (A < B)
		cout << a << endl;
	else
		cout << b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 3556
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

bool isPalin(string s) {
    int l = 0, r = s.length() - 1;
    while (l < r) 
    	 if (s[l++] != s[r--])
    	 	 return false;
    return true;	 	
}

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
 
    string s; cin >> s;
    int se = ((s.length() - 1) >> 1) - 1 ;
    int sb = ((s.length() + 3) >> 1) - 1;
    
    cout << (isPalin(s) && (isPalin(s.substr(0, se + 1)) && isPalin(s.substr(sb, s.length() - sb))) ? "Yes" : "No") << endl;

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A, B, C, D int
	fmt.Scan(&A, &B, &C, &D)

	var cnt int = B - A + 1
	cnt -= B/C - (A-1)/C
	cnt -= B/D - (A-1)/D
	cnt += B/(lcm(C, D)) - (A-1)/lcm(C, D)
	fmt.Println(cnt)
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define rrep(i,l,r) for(int i=(r-1);i>=(l);i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define range(i) i.begin(),i.end()
#define sum(i) accumulate(range(i),0)
#define Yes(i) out(i?"Yes":"No")
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
struct aaa{aaa(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(10);};}aaaaaaa;
inline void in() {}
template <class Head, class... Tail>
inline void in(Head&& head,Tail&&... tail){
    cin>>head;
    in(move(tail)...);
}
template <class T>
inline void out(T t) {
    cout<<t<<'\n';
}
template <class Head, class... Tail>
inline void out(Head head,Tail... tail){
    cout<<head<<' ';
    out(move(tail)...);
}

int main(){
    vector<vector<int>>train(502,vector<int>(502)),ans(502,vector<int>(502));
    INT(n,m,q);
    int a,b;
    rep(i,0,m){
        in(a,b);
        train[a][b]++;
    }
    rep(j,1,n+1){
        rrep(i,1,j+1){
            ans[i][j]=ans[i+1][j];
            rep(k,i,j+1)ans[i][j]+=train[i][k];
        }
    }
    rep(i,0,q){
        in(a,b);
        out(ans[a][b]);
    }
}









Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  cout << std::max(0, C - (A - B)) << endl;

  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  int l,l0, ct;
  cin >> s;
  l = s.size();

  ct = 0;
  for (int i=0; i<(l/2); i++) if (s[i] != s[l-i-1]) ct++;
  cout << ct << endl;  
}



Measured memory_bytes: 256
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if(a<b):
    ansa=a+(v*t)
    ansb=b+(w*t)
    if(ansa>=ansb):
        print('YES')
    else:
        print('NO')
else:
    ansa=a-(v*t)
    ansb=b-(w*t)
    if(ansa<=ansb):
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n; cin>>n;
  vll x(n), y(n);
  rep(i,n) cin>>x[i]>>y[i];
  vll s(n), d(n);
  rep(i,n){
    s[i]=abs(x[i]+y[i]);
    d[i]=x[i]-y[i];
  }
  sort(s.begin(),s.end());
  sort(d.begin(),d.end());
  ll ans_0=s[n-1]-s[0];
  ll ans_1=d[n-1]-d[0];
  ll ans=max(ans_0,ans_1);
  cout<<ans<<endl;
}


Measured memory_bytes: 9532
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		sc.close();

		for (int i = K; i < N; i++) {
			long p = A[i];
			long m = A[i - K];

			if (p > m) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}


Measured memory_bytes: 61644
#include <iostream>
#include <vector>
using namespace std;
bool ex[200005];
int arr[200005],f[200005];
pair<long long,int> dp[60][200005];
pair<long long,int> merge(pair<long long,int> a,pair<long long,int> b)
{
	return {a.first+b.first,b.second};
}
int main()
{
	int n;
	long long k;
	scanf("%d%lld",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&arr[i]);
		if (!f[arr[i]])
		f[arr[i]]=i;
	}
	for (int i=n;i>0;i--)
	{
		dp[0][i]={0,f[arr[i]]%n+1};
		if (f[arr[i]]<=i)
		dp[0][i].first++;
		if (f[arr[i]]==n)
		dp[0][i].first++;
		f[arr[i]]=i;
	}
	for (int i=1;i<60;i++)
	{
		for (int j=1;j<=n;j++)
		dp[i][j]=merge(dp[i-1][j],dp[i-1][dp[i-1][j].second]);
	}
	pair<long long,int> cur(1,1);
	for (int i=59;i>=0;i--)
	{
		auto tmp=merge(cur,dp[i][cur.second]);
		if (tmp.first<=k)
		cur=tmp;
	}
	vector<int> ans;
	while (cur.first<=k)
	{
		if (ex[arr[cur.second]])
		{
			while (ex[arr[cur.second]])
			{
				ex[ans.back()]=0;
				ans.pop_back();
			}
		}
		else
		{
			ans.push_back(arr[cur.second]);
			ex[arr[cur.second]]=1;
		}
		if (cur.second==n)
		cur.first++;
		cur.second=cur.second%n+1;
	}
	for (int i:ans)
	printf("%d ",i);
}

Measured memory_bytes: 191732
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e10
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	long long dp[n+1][m+1];
	long long d[n+1],c[m+1];
	rep(i,n+1){
		rep(j,m+1){
			if(i==0)dp[i][j]=0;
			else dp[i][j]=INF;
		}
	}
	loop(i,1,n+1)cin>>d[i];
	loop(i,1,m+1)cin>>c[i];
	loop(i,1,n+1){
		loop(j,1,m+1){
			dp[i][j]=min(dp[i][j-1],dp[i-1][j-1]+d[i]*c[j]);
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
}

Measured memory_bytes: 7496
#include <bits/stdc++.h>
#define mod 1000000007
// #define mod 998244353
#define pb push_back
#define ll long long
#define ld long double
#define ft first
#define sd second
using namespace std;

const int N = 21 + 9;
int n; 
int a[N][N];
ll dp[22][1 << 21];
ll solve(int ind, int msk) {
    if(ind < 0) return (msk == 0);
    ll &ret = dp[ind][msk];
    if(ret != -1) return ret;
    ret = 0;
    for(int i = 0; i < n; i++) {
        if((msk >> i) & 1) {
            if(a[ind][i])
                ret += solve(ind-1,msk ^ (1 << i));
        }
    }
    ret %= mod;
    return ret;
}

signed main() {

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n;
    memset(dp, -1, sizeof dp);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    cout << solve(n-1, (1<<n) - 1);



    return 0;
}

Measured memory_bytes: 360704
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    a, b = map(int, input().split())
    print(a*b)


if __name__ == '__main__':
    main()


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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void) {
    int n, count = 0;
    scanf("%d", &n);
    int p[n], q[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &p[i]);
        q[i] = p[i];
    }
    qsort(q, n, sizeof(int), compare_int);
    for(int i = 0; i < n; i++) {
        if(p[i] == q[i]) count++;
    }
    if((count + 2 == n) || (count == n)) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def topological_sort(N, dag):
    # ここからトポロジカルソート準備
    incnts = [0] * N
    outnodes = [[] for i in range(N)]
    for i in range(len(dag)):
        # 流入するノード数
        incnts[dag[i][1]] += 1
        # 流出先ノードのリスト
        outnodes[dag[i][0]].append(dag[i][1])
    # 流入ノード数が0であるノードのセットS
    S = set()
    for i in range(N):
        if incnts[i] == 0:
            S.add(i)

    # ここからトポロジカルソート
    L = []
    # 暫定セットが空になるまでループ
    while S:
        # 暫定セットから結果リストへ1つ入れる
        L.append(S.pop())
        # 確定させたノードから流出するノードでループ
        for node in outnodes[L[-1]]:
            # 流入ノード数を1減らす
            incnts[node] -= 1
            # 流入ノードが0なら暫定セットへ
            if incnts[node] == 0:
                S.add(node)
    return L

N, M = MAP()
nodes = [[] for i in range(N)]
edges = [None] * M
for i in range(M):
    x, y = MAP()
    nodes[x-1].append(y-1)
    edges[i] = ((x-1, y-1))

# この後の最大値更新で矛盾が生じないようにソートしておく
l = topological_sort(N, edges)

ans = [0] * N
for src in l:
    for dest in nodes[src]:
        ans[dest] = max(ans[dest], ans[src]+1)
print(max(ans))


Measured memory_bytes: 47128
H,W,K = map(int,input().split())
HW = [list(input()) for _ in range(H)]

ans = [[0 for _ in range(W)] for _ in range(H)]
cnt = 0
mm = []

for h in range(H):
    if not("#" in HW[h]):
        continue
    mm.append(h)
    cnt += 1
    flg = 1

    for w in range(W):
        if HW[h][w]=="#" and not(flg):
            cnt += 1

        ans[h][w]=cnt

        if flg and HW[h][w]=="#":
            flg = 0
            continue

j = 0
for h in range(H):
    if j<len(mm)-1 and h==mm[j]:
        j += 1
        continue
    else:
        ans[h] = ans[mm[j]]
        
        

for h in range(H):
    print(*ans[h])


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

using ll=long long;

int main() {
  int K; cin >>K;
  int ans=0;
  rep_eq(a,1,K) {
    rep_eq(b,1,K) {
      rep_eq(c,1,K) {
        ans+=gcd(gcd(a,b),c);
      }
    }
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3580
n = int(input())
a = list(map(int,input().split())) 
b = list(map(int,input().split())) 
c = list(map(int,input().split())) 


 
b_sum = sum(b) 


for i in range(0,n-1) :
	if a[i]+1 == a[i+1] :
		b_sum = c[a[i]-1]+b_sum 

print(b_sum) 



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

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

int main() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) {
		int K; scanf("%d", &K);
		while (K--) {
			int x; scanf("%d", &x);
			a[i] |= 1<<(x - 1);
		}
	}
	int M = 22;
	vector<int> dp(1<<M);
	rep(i, N) dp[a[i]] = a[i];
	for (int S = (1<<M) - 1; S >= 0; S--)
		rep(i, M) if (!(S>>i & 1)) {
			int _S = S | 1<<i;
			dp[S] |= dp[_S];
		}
	int ma = 0;
	rep(S, 1<<M) {
		int k1 = 0, k2 = 0;
		rep(i, M) {
			if (S>>i & 1) k1++;
			if (dp[S]>>i & 1) k2++;
		}
		int ans = k1 * k2;
		if (ans <= ma) continue;
		int cnt = 0;
		rep(i, N) if ((a[i] & S) == S) cnt++;
		if (cnt >= 3) ma = max(ma, ans);
	}
	cout << ma << endl;
}

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

#define ll long long

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;

    int count = 0;
    for (int i = 0; i < 3; i++){
        if (s[i] == t[i]) count++;
    }

    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
    int n;
    while(1){
        scanf("%d",&n);
        if(n == -1)break;
        int ans = 0;
        ans = 1150;
        if(n <= 10){printf("%d\n",4280-ans);continue;}
        n = n - 10;
        if(n <= 10){
            ans += 125*n;
            printf("%d\n",4280-ans);
            continue;
        }
        ans += 1250;
        n = n - 10;
        if(n <= 10){
            ans += 140*n;
            printf("%d\n",4280-ans);
            continue;
        }
        ans += 1400;
        n = n - 10;
        //printf("n = %d\n",n);
        ans += n*160;
        printf("%d\n",4280 - ans);
    }
    return 0;
}

Measured memory_bytes: 1028