akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
// priority_queue 二本を用いた実装

signed main(){
    

    priority_queue<int> L;
    priority_queue<int, vector<int>, greater<int> > R;
    int sumL = 0;
    int sumR = 0;
    int num = 0;
    int sumb = 0;
    L.push(-INF);
    R.push(INF);
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int com; cin >> com;
        if(com == 1){
            int a, b; cin >> a >> b;
            sumb += b;

            if(num % 2 == 0){
                R.push(a);
                sumR += a;
            }else{
                sumL += a;
                L.push(a);
            }
            num++;

            int x = R.top();
            int y = L.top();
            
            if(x < y){
                R.pop();
                L.pop();
                R.push(y);
                L.push(x);
                sumR += (y - x);
                sumL += (x - y);
            }
        }else{
            int val;
            if(num % 2 == 0) val = L.top();
            else val = R.top();
            cout << val << " " << val * (num % 2) - sumL + sumR - val * (num % 2 + (num % 2 == 1) ) + sumb << endl;
        }
    }
    
    

    return 0;
}


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

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

    set<int> ans;
    int now = 1;
    int sum = 0;
    while(1){
        if(sum >= n){
            break;
        }
        sum += now;
        ans.insert(now);
        now++;
    }

    if(sum != n){
        int k = sum - n;
        ans.erase(k);
    }

    for(auto itr = ans.begin(); itr != ans.end(); ++itr){
        cout << *itr << endl;
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

int main(){
    int N;
    cin>>N;
    int res=N;
    for(int i=0;i<=N;i++){
        int cc=0;
        int t=i;
        while(t>0)cc+=t%6,t/=6;
        t=N-i;
        while(t>0)cc+=t%9,t/=9;
        if(res>cc)res=cc;
    }
    cout<<res;
    return 0;
}
//37076,29300,21524,13748,5972,4676,3380,2084,788,59,23,14,5,4,3,2,1,0;
//7776,7776,1296,729,36,9
//6の乗数を6で割るとあまりは0であり、解は6の乗数であり続けるため。

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int lw=n, rr=-1;
  rep(i, n){
    if(s[i]=='R'){
      rr=i;
    }
  }
  for(int i=n-1; i>=0; i--){
    if(s[i]=='W'){
      lw=i;
    }
  }
  int ans=0;
  while(lw<rr){
    ans++;
    lw++;
    rr--;
    while(lw < n && s[lw]!='W'){
      lw++;
    }
    while(rr>=0 && s[rr]!='R'){
      rr--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main() {
    int a, b;
    ll x;
    cin >> a >> b >> x;
    if (x <= b*a*a/2) {
        double s = (double)x*2/(b*a);
        double theta=atan2(s, b);
        double ans = 90-180/M_PI*theta;
        cout << setprecision(10) << ans << endl;
    } else{
        x = b*a*a - x;
        double t = (double)x*2/(a*a);
        double theta = atan2(a, t);
        double ans = 90-180/M_PI*theta;
        cout << setprecision(10) << ans << endl;
    }
}

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

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main () {
    int k;
    cin >> k;
    cout << a[k - 1] << endl;
    return 0;
}




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

using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

// 3ヶ月ほど前に解説見て放置してた。解答のアイデアを思い起こして実装した。
// 要するに解説を見たということです(おいおい

ll H, W;
int N;
typedef pair<ll, ll> P;
vector<ll> ans(10);
map<P, int> val;

int main() {
    cin >> H >> W >> N;
    ans[0] = (H - 2) * (W - 2);

    for (int i = 0; i < N; i++) {
        ll x, y;
        cin >> y >> x;
        y--; x--;

        for (int dx = -1; dx <= 1; dx++) {
            for (int dy = -1; dy <= 1; dy++) {
                ll nx = x + dx, ny = y + dy;
                if (nx <= 0 || nx >= W-1 || ny <= 0 || ny >= H-1) continue;

                if (val.find(P(nx, ny)) == val.end()) {
                    val[P(nx, ny)] = 1;
                    ans[0]--;
                    ans[1]++;
                } else {
                    int aft = val[P(nx, ny)] + 1;
                    val[P(nx, ny)]++;
                    ans[aft - 1]--;
                    ans[aft]++;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e18;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  if(a<c&&c<b){
    print("Yes");
  }
  else if(b<c&&c<a){
    print("Yes");
  }
  else{
    print("No");
  }
}


Measured memory_bytes: 3480
N = int(input())
result = [0,0,0,0]
for n in range(N):
    S = input()
    if S == "AC":
        result[0] += 1
    elif S == "WA":
        result[1] += 1
    elif S == "TLE":
        result[2] += 1
    else:
        result[3] += 1
name = ["AC","WA","TLE","RE"]
for res,nam in zip(result,name):
    print("%s x %d"%(nam,res))

Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <bitset>
 
using namespace std;
 
typedef long long ll;
 
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif  
  int n;
  cin >> n;
  vector <int> x(n);
  for (int i = 0; i < n; ++i) cin >> x[i];
  vector <int> p(n);
  iota(p.begin(), p.end(), 0);
  sort(p.begin(), p.end(), [&] (int i, int j) {
    return x[i] < x[j];
  });
  vector <int> ans;
  vector <int> used(n);
  vector <int> have(n);
  for (int id : p) {
 
    for (int i : p) {
      while (ans.size() + 1 < x[id] && (!used[i] && have[i] < i)) {
        ++have[i];
        ans.push_back(i + 1);
      }
    }
    for (int i : p) {
      while (ans.size() + 1 < x[id] && (used[i] && have[i] != n)) {
        ++have[i];
        ans.push_back(i + 1);
      }
    }
 
    ans.push_back(id + 1);
    ++have[id];
    used[id] = 1;
    if (ans.size() != x[id] || have[id] != id + 1) {
      cout << "No\n";
      return 0;
    }
  } 
  for (int i = 0; i < n; ++i) {
    while (have[i] != n) {
      ans.push_back(i + 1);
      ++have[i];
    }
  }
  cout << "Yes\n";
  for (int x : ans) cout << x << ' ';
}


Measured memory_bytes: 2292
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

lint a, b, c;
int n;
map<pair<pii, int>, int> S;
set<pair<pii, int>> T;

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

bool in(int x, int y, int z){
    return 0<=x && x<a && 0<=y && y<b && 0<=z && z<c;
}

int surface(int x, int y, int z){
    int ret = 0;
    rep(i, 6){
        int nx = x+dx[i], ny = y+dy[i], nz = z+dz[i];
        ret += !in(nx, ny, nz);
    }
    return ret;
}

int main(){
    scanf("%lld%lld%lld%d", &a, &b, &c, &n);
    lint ans = (a*b + b*c + c*a) * 2;
    rep(_, n){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        if(S.find({{x, y}, z}) != S.end()) ans -= S[{{x, y}, z}];
        else ans -= surface(x, y, z);
        T.insert({{x, y}, z});

        rep(i, 6){
            int nx = x+dx[i], ny = y+dy[i], nz = z+dz[i];
            if(in(nx, ny, nz) && T.find({{nx, ny}, nz}) == T.end()){
                if(S.find({{nx, ny}, nz}) != S.end()) ++S[{{nx, ny}, nz}];
                else S[{{nx, ny}, nz}] = surface(nx, ny, nz) + 1;
                ++ans;
            }
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3596
#copy for experience
import sys
sys.setrecursionlimit(10**8)
N=int(input())
P=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
table=[[] for i in range(N)]
for i in range(N-1):
    table[P[i]-1].append(i+1)
dp=[0]*N #shiro

def tree(pa):
    for i in table[pa]:
        tree(i)
    t=len(table[pa])
    if t==0:
        return
    T=set()
    s=0
    for i in range(t):
        x=table[pa][i]
        s+=X[x]+dp[x]
        if i==0:
            if X[x]<=X[pa]:
                T.add(X[x])
            if dp[x]<=X[pa]:
                T.add(dp[x])
            continue
        S=set()
        for k in T:
            if k+X[x]<=X[pa]:
                S.add(k+X[x])
            if k+dp[x]<=X[pa]:
                S.add(k+dp[x])
        T=S
    if len(T)==0:
        print('IMPOSSIBLE')
        sys.exit()
    dp[pa]=s-max(T)
    return

tree(0)    
print('POSSIBLE')


Measured memory_bytes: 3572
#include<bits/stdc++.h>
 using namespace std;
#define ll long long
int main(){
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    double dp[n+1]={0};
    dp[0]=(1-a[0]);  dp[1]=a[0];
    
    for(int i=1;i<n;i++){
        for(int j=n;j>=0;j--){
             if(j!=0 ) dp[j]=dp[j-1]*a[i]+dp[j]*(1.0-a[i]);
             else if(j==0) dp[j]*=(1-a[i]);
        }
    }
    double sm=0;
    for(int i=n/2+1;i<=n;i++) {  sm+=dp[i]; }
    cout<<setprecision(10)<<sm<<endl;
    return 0;
}

Measured memory_bytes: 384
N=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(N):
    S=str(input())
    if S=='AC':
        ac+=1
    elif  S=='WA':
        wa+=1
    elif S=='TLE':
        tle+=1
    else:
        re+=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))


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

int main(void)
{
    string s;
    getline(cin, s);  // 1行読み込む
    for(int i = 0; i < s.size(); i++) {
        char c = s[i];
        if ('A' <= c && c <= 'Z') {
            //c = tolower(c);
            c = c + 32;
        }
        else if('a' <= c && c <= 'z') {
            c = c - 32;
        }
        cout << c;
    }
    cout << endl;
}




Measured memory_bytes: 3104
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int a, b; string s, res; cin >> a >> b >> s;
    if (s[a] == '-' && s[s.size() - b - 1] == '-' )
    {
        res = "Yes";
    }
    else
    {
        res = "No";
    }
    for (int i = 0; i < s.size(); i++)
    {
        if ( i != a && s[i] == '-')
        {
            res = "No";
        }
    }
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
const int MaxN = 1e5 + 5;

char s[MaxN], t[MaxN];
int l[MaxN], presum[MaxN];

int main() {
	int k;
	scanf("%s %d", s+1, &k); 
	int len = strlen(s+1);
	for(int i = 1; i <= len; i++) {
		if(s[i] == 'a') l[i] = 0;
		else l[i] = 'z' - s[i] + 1;
		presum[i] = presum[i-1] + l[i];
	}

	int flag = -1;
	if(presum[len] == 0) flag = len;
	for(int i = 1; i <= len; i++)
		if(presum[i] > k) { flag = i; break;}

	int d = k - presum[flag-1];
	for(int i = 1; i < flag; i++) s[i] = 'a';
	for(int i = flag; i <= len; i++) {
		if(l[i] != 0) {
			if(i == len) {
				if(d < l[i]) s[i] += d;
				else if(l[i] == d) s[i] = 'a';
				else {
					if(d < l[i]) s[i] += d;
					else if(d == l[i]) s[i] = 'a';
					else s[i] = 'a' + (d - l[i]) % 26;
				}
			}
			else if(l[i] <= d) { s[i] = 'a'; d -= l[i]; }
		}else {
			if(i == len) s[i] += d % 26;
			else continue;
		}
	}
	for(int i = 1; i <= len; i++) printf("%c", s[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main()  {
    //入力を受け取る
    int N, M, C;
    cin >> N >> M >> C;

    //長さMの配列、初期値0
    vector<int> B(M, 0);
    for(int i = 0; i < M; i++)
    {
        cin >> B[i];
    }

    //N×Mの配列を作る
    //Aは、vector<int>の長さNの配列
    //これを、vector<int>(M)で初期化（長さMの配列）
    vector<vector<int>> A(N, vector<int>(M));

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < N; i++)
    {
        int sum = 0;
        for (int j = 0; j < M; j++)
        {
            sum += A[i][j] * B[j];
        }
        sum += C;
        if(sum > 0) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
int64_t a,b;
  cin>>a>>b;
for(int i=1;i<1015;i++)
{
if(i*8/100==a & i/10==b)
{
  cout<<i;
break;
}
  else if(i==1013) {
  cout<<-1;
    break;
  }
}
 
}
 

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  string s;
  cin >> s;
  REP(i, s.size()){
    if(i % 2 == 0)
      cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 592
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>?5*8},'ruby',$0)
def dfs(c)
	H[c].each{|e|
	if Z[e]
		raise if (Z[c]-Z[e])%2<1
	else
		Z[e]=Z[c]+1
		dfs(e)
	end
	}
end
N,M=gets.split.map &:to_i
H=Hash.new{|h,k|h[k]=[]};Z={1=>0}
M.times{
a,b=gets.split.map &:to_i
H[a]<<b;H[b]<<a
}
p _=(dfs(1)&&Z.partition{|k,v|v%2<1}.map(&:size).reduce(:*) rescue N*~-N/2)-M

Measured memory_bytes: 55356
#include<stdio.h>

int main()
{
  int N,A[100];
  int i,j,flag=1,cnt=0;
  int a;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  while(flag){
    flag = 0;
    for(j=N-1;j>=1;j--){
      if(A[j] < A[j-1]){
	a = A[j];
	A[j] = A[j-1];
	A[j-1] = a;
	flag = 1;
	cnt++;
      }
      else continue;
    }
  }
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",cnt);

  return 0;
}



Measured memory_bytes: 2064
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=1e4+5;

int prime[40005];
bool isp[40005];

int main(){
	int N;
	cin>>N;
	int a[MAX];
	for(int i=N;i>=0;i--)cin>>a[i];
  
	int n=40000;
	int p = 0;
	//初期化
	for(int i=0;i<=n;i++)
		isp[i]=true;
	isp[0]=isp[1]=false;
	//2以上で素数ならふるい落とす
	for(int i=2;i<=n;i++){
		if(isp[i]){
			p++;
			prime[p]=i;
			for(int j=2*i;j<=n;j+=i) isp[j]=false;
		}
	}
	
	vi apr={};
	int x=abs(a[N]);
	rep1(i,35000){
      	int q=i+1;
		if(x%q==0){
			apr.push_back(q);
			while(x%q==0)x/=q;
		}
	}
  	if(x!=1)apr.push_back(x);
	
	set<int> ans;
	rep1(q,N)if(isp[q]){
		int b[MAX];
		rep(i,N+1)b[i]=a[i];
		for(int i=N;i>=q;i--){
			b[i-q+1]+=b[i];
		}
		bool ok=true;
		rep(i,q)if(b[i]%q!=0)ok=false;
		if(ok)ans.insert(q);
    }
	int l=sz(apr);
	rep(i,l){
		int q=apr[i];
		int b[MAX];
		rep(i,N+1)b[i]=a[i];
      	if(q<=N){
			for(int i=N;i>=q;i--){
				b[i-q+1]+=b[i];
			}
        }
		bool ok=true;
		rep(i,min(q,N))if(b[i]%q!=0)ok=false;
		if(ok)ans.insert(q);
	}
	
	for(auto itr = ans.begin(); itr != ans.end(); ++itr) {
        cout << *itr <<endl;
    }
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool flag = true;
	while (1) {
		if (flag) {
			if (b >= c) {
				cout << "Yes\n";
				return 0;
			}
			else {
				c -= b;
				flag = false;
			}
		}
		else {
			if (d >= a) {
				cout << "No\n";
				return 0;
			}
			else {
				a -= d;
				flag = true;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3624
// ABC A_173

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

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

  if (n % 1000 == 0) cout << 0 << "\n";
  else {
    int tmp = n / 1000 + 1;
    int ans = 1000 * tmp - n;

    cout << ans << "\n";
  }

  return 0;
}


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

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	String S = scan.next();
	char[] chars = S.toCharArray();

	Arrays.sort(chars);

	S = String.valueOf(chars);

	if(S.equals("abc")){
	    System.out.println("Yes");
	}else{
	    System.out.println("No");
	}
    }
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<int, int>

ll POW(ll a, ll b){
  if(b == 1) return a;
  else if(b%2 == 1) return (a*POW(a, b-1))%MOD;
  ll k = POW(a, b/2);
  return k*k%MOD;
}

int main() {
  ll n, a, b, k;
  cin >> n >> a >> b >> k;
  ll c[n+1];
  c[0] = 1;
  REP(i, n){
    c[i+1] = (c[i]*(n-i))%MOD;
    c[i+1] = (c[i+1]*POW(i+1, MOD-2))%MOD;
  }
  if(a<b) swap(a, b);
  ll m = k/a + 1;
  ll ans = 0;
  REP(i, m){
    if((k-i*a)%b == 0){
      ll r = (k-i*a)/b;
      if(r > n || i > n) continue;
      (ans += (c[i]*c[r]%MOD)) %= MOD;
    }
  } 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define LL long long
#define M 4020
using namespace std;
int read(){
	int nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
bitset<4000020>K; int n,sum,m;
int main(){
	n=read();
	for(int i=1;i<=n;i++) m=read(),sum+=m,K|=(K<<m),K[m]=1;
	for(int i=(sum+1>>1);i<=sum;i++) if(K[i]){printf("%d\n",i);return 0;}
}

Measured memory_bytes: 1792
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<int> A){
    cout << "[vector]";
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N, M;
    cin >> N >> M;
    
    vector<pair<int, int> > pairs(M);
    
    // 入力
    FOR(i, 0, M){
        int a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }

    // b順にソート
    sort(ALL(pairs), compare_by_b);

    int lastBridgeBreak = 0;
    int breakCount = 0;
    for(auto pair : pairs){
        int left = pair.first;
        int right = pair.second;
        // 今回の条件は生きている？
        if(lastBridgeBreak < left){
            if(lastBridgeBreak < right - 1){
                // 破壊されていない
                lastBridgeBreak = right - 1;
                breakCount++;
            }
        }
        else{
            // スルー
        }
    }

    // 確認
    // for(auto pair : pairs){
    //     cout << pair.first << " " << pair.second << endl;
    // }

    p(breakCount);

    return 0;
}

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

int main(){
	int n, m;
	int ans = 100000000;
	cin >> n >> m;
	int a[20], b[20];
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < m; i++) cin >> b[i];
	for(int u = 0; u < 2; u++){
		int c[20];
		int tmp = 0, pos = 0;
		for(int i = 0; i < m; i++){
			int x = (i+u)%2;
			for(int j = 0; j < b[i]; j++){
				c[pos] = x;
				pos++;
			}
		}
		int A = 0, C = 0;
		for(int i = 0; i < n; i++){
			A += a[i];
			C += c[i];
		}
		if(A != C) continue;
		for(int i = 0; i < n; i++){
			if(a[i] == 0) continue;
			for(int j = 0; j < n; j++){
				if(c[j] == 0) continue;
				tmp += abs(i-j);
				c[j] = 0;
				break;
			}
		}
		ans = min(ans,tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int N, T;
int64_t DP[3010][3010]; // i番目、t分後の最大値

void init()
{
  for (int i = 0; i < 3010; i++)
    for (int j = 0; j < 3010; j++)
      DP[i][j] = -1;
  DP[0][0] = 0;
}

int64_t ans()
{
  int64_t ans = 0;
  for (int j = 0; j <= T; j++)
    ans = max(DP[N][j], ans);
  return ans;
}

int main()
{
  cin >> N >> T;
  vector<pair<int, int>> ab(N);
  for (int i = 0; i < N; i++)
  {
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab.begin(), ab.end());
  for (int i = 0; i < N; i++)
  {
    for (int t = 0; t <= T; t++)
    {
      if (DP[i][t] == -1)
        continue;
      DP[i + 1][t] = max(DP[i + 1][t], DP[i][t]);
      if (t < T)
      {
        DP[i + 1][min(t + ab[i].first, T)] = max(DP[i + 1][min(t + ab[i].first, T)], DP[i][t] + ab[i].second);
      }
    }
  }
  cout << ans() << endl;
}

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

#define mp make_pair
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
map<ll,vector<ll> >v;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		ll a,b;
		cin >> a >> b;
		v[b].push_back(a);
	}
	ll pre = 0;
	for(auto i:v)
	{
		ll sum = 0;
		for(auto j:v[i.first])
		{
			sum += j;
		}
		pre += sum;
		if(pre>i.first){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}


Measured memory_bytes: 22144
class RMQ:
    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N + 1)
    def sum(self, i):
        s = 0
        while i > 0:
            if s < self.tree[i]:
                s = self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            if self.tree[i] < x:
                self.tree[i] = x
            i += i & -i


N, *HA = map(int, open(0).read().split())
H, A = HA[:N], HA[N:]

dp = RMQ(N)
for h, a in zip(H, A):
    dp.add(h, a + dp.sum(h))

print(dp.sum(N))

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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

template < typename T > struct WeightedUnionFind
{
  int n;
  T d;
  vector< int > r, p;
  vector< T > ws;

  WeightedUnionFind() {}

  WeightedUnionFind(int sz, T d_) : n(sz), d(d_), r(n, 1), p(n), ws(n, d) { iota(p.begin(), p.end(), 0); }

  int find(int x)
  {
    if(x == p[x]) {
      return x;
    } else {
      int t = find(p[x]);
      ws[x] += ws[p[x]];
      return p[x] = t;
    }
  }

  T weight(int x)
  {
    find(x);
    return ws[x];
  }

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

  void unite(int x, int y, T w)
  {
    w += weight(x);
    w -= weight(y);
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(r[x] < r[y]) swap(x, y), w = -w;
    r[x] += r[y];
    p[y] = x;
    ws[y] = w;
  }

  T diff(int x, int y)
  {
    return weight(y) - weight(x);
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  WeightedUnionFind< int64 > u(n, 0);
  for(int i = 0; i < m; i++) {
    int a, b, d;
    cin >> a >> b >> d;
    --a, --b;
    if(u.same(a, b)) {
      if(u.diff(a, b) != d) {
        cout << "No" << endl;
        return (0);
      }
    }
    u.unite(a, b, d);
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<map>
#include<iomanip>

using namespace std;
using ll=long long;

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

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  cin>>n;
  string s;
  //青いカード
  map<string,int> mp;
  rep(i,0,n){
    cin>>s;
    auto itr = mp.find(s);
    if( itr != mp.end() ) {
      mp[s]++;
    } else {
      mp[s]=1;
    }
  }
  cin>>n;
  //赤いカード
  rep(i,0,n){
    cin>>s;
    auto itr = mp.find(s);
    if( itr != mp.end() ) {
      mp[s]--;
    } else {
      mp[s]=-1;
    }
  }
  
  /*全要素の表示
  for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
      std::cout << "key = " << itr->first           // キーを表示
                << ", val = " << itr->second << "\n";    // 値を表示
  }
  */
  
  //最大値を見つける
  int ans=0;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
      if(ans<itr->second)ans=itr->second;
  }

  cout<<ans<<endl;
}

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

using namespace std;

int main(){
  vector<int> a;
  int s,d,f,g;
  cin >> s;
  for(int i=0;i<s;i++){
    cin >> d;
    a.push_back(d);
  }
  std::sort(a.begin(),a.end(), std::greater<int>());
  f=0;
  g=0;
  d =0;
  for(int i=0;i<s;i++){
	if(d){
    f += a.at(i);
    d=0;
    }else{
    g += a.at(i);
	d=1;
    }
  }
    cout << g-f << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i], A[i]--;
  int to[80][N];
  for (int i = 0; i < N; i++) to[0][i] = A[i];
  for (int k = 1; k < 80; k++) {
    for (int i = 0; i < N; i++) {
      to[k][i] = to[k - 1][to[k - 1][i]];
    }
  }
  int ans = 0;
  for (int j = 63; j >= 0; j--) {
    if ((K >> j) & 1) ans = to[j][ans];
  }
  cout << ans + 1 << endl;
  return 0;
}


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

using namespace std;

int main(){
    string s;
    char aux;
    int a,b, c ,parity = 0;
    deque<char> dq; 
    cin >> s >> a;
    for (int i = 0; i < s.size(); i++)
    {
        dq.push_back(s[i]);
    }
    
    for (int i = 0; i < a; i++)
    {
       cin>> b;

        if(b == 1)
            parity++;
        if(b == 2){
            cin>>c >> aux;
            if((parity%2 == 0 && c == 1) || (parity%2 == 1 && c == 2))
                dq.push_front(aux);
            if((parity%2 == 0 && c == 2) || (parity%2 == 1 && c == 1))
                dq.push_back(aux);
        }
    }
    if(parity %2 == 1)
        reverse(dq.begin(),dq.end());

    for (int i = 0; i < dq.size(); i++)
    {
        cout<<dq[i];
    }
    
    cout<< "\n";

    
    return 0;
}


Measured memory_bytes: 896
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;



//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr;	} cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-6
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define all(x) (x).begin(), (x).end()


int main()
{
	//clock_t start, end;
	//start = clock();

	ll N;
	cin >> N;

	for (ll b = 1; b <= 3500; b++) {
		//if (b % 100 == 0) cout << b << endl;
		for (ll c = b; c <= 3500; c++) {
			ll p, q, g; // p / q
			p = 4 * b * c - N * (b + c);
			if (p <= 0) continue;
			q = N * b * c;
			
			if (q % p == 0) {
				cout << q / p << " " << b << " " << c << endl;
				return 0;
			}
		}
	}
	
	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def iter_subset(_a): #aの部分集合を走る
    _bit = _a
    yield _bit
    while 1:
        _bit = (_bit-1) & _a 
        yield _bit
        if not _bit: break



n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

total = 1<<n
gscore = [0]*total
dp = [0]*(total)

for i in range(n):
    for k in range(1<<(i)):
        gscore[k^(1<<i)] += gscore[k]
        for j,c in enumerate(A[i]):
            if (1<<j)&k:
                gscore[k^(1<<i)] += c  

        l = k
        while l:
            dp[k^(1<<i)] = max(dp[k^(1<<i)], gscore[l^(1<<i)] + dp[k^l])
            l = (l-1) & k
        dp[k^(1<<i)] = max(dp[k^(1<<i)], gscore[1<<i] + dp[k])
            


print(dp[-1])        
        


Measured memory_bytes: 46696
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int a;
    int b;
    int tmp;
    cin >> a >> b;
    tmp=a*b;
    if(tmp%2!=0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
-- | Main entry point to the application.
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace
import Text.Printf

rInt :: String -> Int
rInt str = read str :: Int

condd :: Int -> Int -> Int -> String
condd a b c
    | a < b && b < c = "Yes"
    | otherwise = "No"

-- | The main entry point.
main :: IO ()
main = do
    [a, b, c] <- (map rInt . words) <$> getLine
    putStrLn $ condd a b c

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

int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	sort(a.begin(), a.end());
	deque<ll>aq;
	for (int i = 0; i < n; i++)aq.push_back(a.at(i));
	//min-start
	ll mi = 0;
	deque<ll>aqmi = aq;
	deque<ll>ami;
	ami.push_back(aqmi.front());
	aqmi.pop_front();
	bool x = true;
	while (aqmi.size() > 0) {
		if (aqmi.size() == 1)break;
		int a;
		if (x) {
			a = aqmi.back();
			ami.push_front(a);
			aqmi.pop_back();
			a = aqmi.back();
			ami.push_back(a);
			aqmi.pop_back();
			x = false;
		}
		else {
			a = aqmi.front();
			ami.push_front(a);
			aqmi.pop_front();
			a = aqmi.front();
			ami.push_back(a);
			aqmi.pop_front();
			x = true;
		}
	}
	if (aqmi.size() == 1) {
		ll a, b,c;
		a = ami.front();
		b = ami.back();
		c = aqmi.front();
		if (abs(a - c) > abs(b - c))ami.push_front(c);
		else ami.push_back(c);
	}
	ll k = ami.front();
	ami.pop_front();
	while (ami.size() > 0) {
		mi += abs(k - ami.front());
		k = ami.front();
		ami.pop_front();
	}
	//max-start
	ll ma = 0;
	deque<ll>aqma = aq;
	deque<ll>ama;
	ama.push_back(aqma.back());
	aqma.pop_back();
	x = true;
	while (aqma.size() > 0) {
		if (aqma.size() == 1)break;
		ll a;
		if (!x) {
			a = aqma.back();
			ama.push_front(a);
			aqma.pop_back();
			a = aqma.back();
			ama.push_back(a);
			aqma.pop_back();
			x = true;
		}
		else {
			a = aqma.front();
			ama.push_front(a);
			aqma.pop_front();
			a = aqma.front();
			ama.push_back(a);
			aqma.pop_front();
			x = false;
		}
	} 
	if (aqma.size() == 1) {
		ll a, b, c;
		a = ama.front();
		b = ama.back();
		c = aqma.front();
		if (abs(a - c) > abs(b - c))ama.push_front(c);
		else ama.push_back(c);
	}
	k = ama.front();
	ama.pop_front();
	while (ama.size() > 0) {
		ma += abs(k - ama.front());
		k = ama.front();
		ama.pop_front();
	}
	cout << max(mi, ma) << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  V<> x(n); for (int i = 0; i < n; i++) cin >> x[i];
  auto calc = [](int l, int r) {
    if (r <= 0) return -l;
    if (l >= 0) return r;
    return r - l + min(abs(l), abs(r));
  };
  int res = 1e9;
  for (int i = 0; i < n - k + 1; i++) {
    res = min(res, calc(x[i], x[i + k - 1]));
  }
  cout << res << '\n';
}

Measured memory_bytes: 640
use std::io;
use itertools::Itertools;

fn main() {
    let n = read_one::<usize>();
    let mut xy = Vec::new();
    for _ in 0..n { 
        let (x, y) = {
            let i = read::<isize>();
            (i[0], i[1])
        };
        xy.push((x, y));
    }

    let mut ans: f64 = 0.0;
    let mut cnt = 0;
    for route in (0..n).permutations(n) {
        cnt += 1;
        for (&i, &j) in route.iter().tuple_windows() {
            ans += (((xy[i].0 - xy[j].0).pow(2) + (xy[i].1 - xy[j].1).pow(2)) as f64).sqrt();
        }
    }
    println!("{}", ans / cnt as f64);
}

#[allow(unused)]
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(unused)]
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: 2156
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
template<class T> inline string TOSTRING(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  bool DBG = false; ull n, N, tmp;
  if (DBG){cin >> N;}
  auto check = [&](ull n){
    string rtn;
    cout << "? " << n << endl << flush;
    if (DBG){
      if ((n <= N) == (TOSTRING(n) <= TOSTRING(N))){
        rtn = "Y";
      } else {
        rtn = "N";
      }
      cout << rtn << endl;
    } else {
      cin >> rtn;
    }
    return rtn[0];
  };

  if (check(10000000000) == 'Y'){
    REP(i, 10, 1){
      n = 1;
      ull tmp = (ull) round(pow(10, i)) - 1;
      if (check(tmp) == 'N'){
        n = tmp + 1;
        break;
      }
    }
  } else {
    ull l = 1, r = 1000000000, m;
    REP(i, 1, 10){
      tmp = (ull) round(pow(10, i));
      if (check(tmp) == 'N'){
        l = tmp / 10, r = tmp - 1;
        break;
      }
    }
    while (l + 1 < r){
      m = (l + r) / 2;
      if (check(10 * m) == 'Y'){
        r = m;
      } else {
        l = m;
      }
    }
    n = r;
  }
  cout << "! " << n << endl << flush;
  return 0;
}

Measured memory_bytes: 596
n=int(input())
ns=[list(map(int,input().split())) for i in range(n)]
for i in range(n-2):
    if ns[i][0] == ns[i][1] and ns[i+1][0] == ns[i+1][1] and ns[i+2][0] == ns[i+2][1]:
        print("Yes")
        break
    if i==n-3:
        print("No")

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair

void solve(int test)
{
    string s;
    cin>>s;
    cout<<s;
    
    if(s[s.length()-1]=='s')
        cout<<"es"<<endl;
    else
        cout<<"s"<<endl;
    return;
}

int main() {

 int t = 1;
// cin>>t;
 
 for(int x=1;x<=t;x++)
 {
    solve(x); 
 }
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using namespace std;
int main(){

  int n,q,b,m,e;
  int a[1010];

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  cin >> q;
  while(q--){
    cin >> b >> m >> e;
    rotate(a+b,a+m,a+e);
  }
  
  for(int i=0;i<n;i++){
    cout << a[i];
    if(i == n-1) cout << endl;
    else cout << " ";
  }
  
  return(0);
}



Measured memory_bytes: 3132
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

def main():
    n,*a=map(int,open(0).read().split())
    b=set(a[::2])
    c=set(sorted(a)[::2])
    print(len(b^c)//2)
if __name__ == '__main__':
    main()

Measured memory_bytes: 20952
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int K = int.Parse(Console.ReadLine());
            int X = int.Parse(Console.ReadLine());
            int Y = int.Parse(Console.ReadLine());

            int cost = 0;
            for(int i = 1; i <= N; i++)
            {
                if(i > K)
                {
                    cost += Y;
                }
                else
                {
                    cost += X;
                }
            }
            Console.WriteLine(cost);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13140
import sys

MOD = 10 ** 9 + 7

h, w, k = map(int, sys.stdin.readline().split())

def main():
    if w == 1:
        return 1
        
    ok = []
    for i in range(2 ** (w - 1)):
        prev = False
        for j in range(w-1):
            if i >> j & 1:
                if prev:
                    break
                else:
                    prev = True
            else:
                prev = False
        else:
            ok.append(i)

    lcr = [(letter, 0) for letter in 'lcr']
    a = [dict(lcr) for _ in range(w)]
    for i in ok:
        j = 0
        while j < w:
            if i >> j & 1:
                a[j]['r'] += 1
                a[j+1]['l'] += 1
                j += 2
            else:
                a[j]['c'] += 1
                j += 1

    res = [0] * w
    res[0] = 1
    for _ in range(h):
        nex = [0] * w
        for j in range(w):
            if j == 0:
                nex[j] = res[j] * a[j]['c'] + res[j+1] * a[j]['r']
            elif j < w - 1:
                nex[j] = res[j-1] * a[j]['l'] + res[j] * a[j]['c'] + res[j+1] * a[j]['r']
            else:
                nex[j] = res[j-1] * a[j]['l'] + res[j] * a[j]['c']
        for j in range(w):
            nex[j] %= MOD
        res = nex

    return res[k-1]
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;
 
int main() {
    int n; cin >> n;
    vector<ll> m(n+1);
    vector<ll> y(n);
    rep(i,n+1){
        cin >> m[i];
    }
    rep(i,n){
        cin >> y[i];
    }
    ll ans = 0;
    rep(i,n){
        if(m[i]>=y[i]){
            ans += y[i];
        }else{
            ans += m[i];
            ll a = y[i]-m[i];
            if(a>=m[i+1]){
                ans += m[i+1];
                m[i+1] = 0;
            }else{
                ans += a;
                m[i+1] = m[i+1]-a;
            }
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int D;  // 全日数
int c[26];  // 満足度減少係数
int s[365][26];  // 満足度上昇値
int last[26] = {};  // 各コンテストを最後に開催した日
int t[365] = { 0 };  // 各日に開催するコンテスト

// スコア計算関数
int CalcScore() {
    int res = 0;
    int last_[26] = { 0 };
    rep(i, D) {
        res += s[i][t[i] - 1];
        last_[t[i] - 1] = i + 1;
        rep(j, 26) {
            res -= c[j] * (i+1 - last_[j]);
        }
    }
    return res;
}

// 入れ替えクエリ処理を行う関数
void Query(int d, int q) {
    t[d - 1] = q;
}

int main()
{
    clock_t start = clock();  // タイマ設定
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D) rep(j, 26) cin >> s[i][j];

    // 貪欲法
    rep(i, D) {
        int max_v = -INF;
        rep(j, 26) {
            int v = 0;
            v += s[i][j];
            rep(k, 26) {
                if (k == j) continue;
                v -= c[k] * (i + 1 - last[k]);
            }
            if (v > max_v) {
                max_v = v;
                t[i] = j + 1;
            }
        }
        last[t[i] - 1] = i + 1;
    }
    int score = CalcScore();
    
    // 乱数生成
    std::mt19937 mt{ std::random_device{}() };
    std::uniform_int_distribution<int> d_ran(1, D);  // for day
    std::uniform_int_distribution<int> q_ran(1, 26);  // for contest
    while(true) {
        clock_t end = clock();  // タイマ取得
        double time = (double)(end - start) / CLOCKS_PER_SEC;  // 経過時間計算
        if (time > 1.9) break;  // 制限時間が近づいていたらbreak
        int d = d_ran(mt);
        int q = q_ran(mt);
        int old = t[d - 1];
        Query(d, q);
        int new_score = CalcScore();
        if (new_score < score) {  // 悪化していたら元に戻す
            t[d - 1] = old;
        }
        else {  // 改善していたら更新
            score = new_score;
        }
    }

    // 結果出力
    rep(i, D) cout << t[i] << endl;
    return 0;
}


Measured memory_bytes: 3720