akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
long long int fact[300005];
long long int modpow(long long int a, long long int n, long long int p)
{
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 > 0)
			res = res * a % p;
		a = a * a % p;
		n /= 2;
	}
	return res;
}
long long int comb(long long int n, long long int r, long long int p)
{
	if (n < r)
		return 0;
	long long int res = fact[n];
	res = res * modpow(fact[r], p - 2, p) % p;
	res = res * modpow(fact[n - r], p - 2, p) % p;
	return res;
}
int main()
{
	long long int n, a, b, k;
	scanf("%lld %lld %lld %lld", &n, &a, &b, &k);
	long long int i;
	long long int p = 998244353;
	fact[0] = 1;
	for (i = 1; i <= n; i++)
		fact[i] = fact[i - 1] * i % p;
	long long int ans = 0;
	for (i = 0; i <= n; i++)
		if (k - a * i >= 0 && (k - a * i) % b == 0)
			ans = (ans + comb(n, i, p) * comb(n, (k - a * i) / b, p) % p) % p;
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n=s.size();
	ll ans=0;
	char b='B',w='W';
	int j=0;
	rep(i,n){
		if(s[i]==w){
			ans+=i-j;
			j++;
		}
	}
	cout << ans << endl;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}


int main() {
  ll n;cin >> n;
  ll ans=n*(n-1)/2;
  cout << ans;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

int main() {
    long double H,W,result;
    cin >> H >> W;

    if(H == 1 || W == 1){
        cout << 1 << endl;
        return 0;
    }
    result = ceil(H*W/2);

    cout << (ll)result << endl;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool visited[100000] = {};
stack<int> S;
vector< vector<int> > A;
long long dp[100000];

bool visit(int n) {
    if(!visited[n]) {
        visited[n] = true;
        for(int to : A[n]) {
            visit(to);
        }
        S.push(n);
    }
}

int main() {
    int N,M;
    cin >> N >> M;
    A.resize(N);
    for(int i=0; i<M; ++i) {
        int x,y;
        cin >> x >> y;
        A[x-1].push_back(y-1);
    }

    //topological sort
    for(int i=0; i<N; ++i) visit(i);

    //dp
    while(!S.empty()) {
        int n = S.top(); S.pop();
        for(int to : A[n]) {
            dp[to] = max(dp[to], dp[n] + 1);
        }
    }

    cout << *max_element(dp, dp+N) << endl;
    return 0;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	if (N < 11 || N == 12 || N == 14 || N == 15 || N == 16 || N == 18 || N == 20 || N == 21 || N == 24 || N == 25 || N == 27 || N == 28 || N == 30 || N == 32 || N == 35 || N == 36 || N == 40|| N == 42 || N == 45 || N == 48 || N == 49 || N == 54 || N == 56 || N == 63 || N == 64 || N == 72 || N == 81 ) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 2*10*10*10*10*10 + 1

int main(void){

    int length, ans = 0, wnum, bnum = 0;
    char stone[N];

    scanf("%d", &length);
    scanf("%s", &stone);

    for(int i=0; i<length; i++){
        if(stone[i] == '.'){
            ans++;
        }
    }

    wnum = ans;

    for(int i=0; i<length; i++){
        if(stone[i] == '#'){
            bnum++;
        } else {
            wnum--;
        }

        if((bnum + wnum) < ans){
            ans = (bnum + wnum);        
        }
    }

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/arc086/tasks/arc086_a
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n,k;cin>>n>>k;
    unordered_map<int,int> mp;
    for(int i=0;i<n;i++) {
        int x;cin>>x;
        mp[x]++;
    }
    vector<int> ar;
    for(auto &i : mp)
        ar.push_back(i.second);
    sort(ar.rbegin(), ar.rend());
    long long sum=0;
    for (int i=k;i<ar.size();i++)
        sum += ar[i];
    cout<<sum<<"\n";
}

Measured memory_bytes: 13076
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// #define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 5*(int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!

int n;

int which[2][2], ma[2][2];

int32_t main(){_

   cin>>n;
   vector<int> v;
   v.resize(n);

   for (int i = 0; i < n; ++i)
   {
      cin>>v[i];
   }

   map<int, int> freq[2];
   for (int i = 0; i < n; i++)
   {
      freq[i%2][v[i]]++;
   }

   for (int i = 0; i < 2; ++i)
   {
      for(auto it: freq[i]){
         if(it.S > ma[i][0]){
            swap(ma[i][1], ma[i][0]);
            swap(which[i][1], which[i][0]);
            ma[i][0] = it.S;
            which[i][0] = it.F;
         }
         else if(it.S > ma[i][1]){
            ma[i][1] = it.S;
            which[i][1] = it.F;
         }
      }
   }

   int ans = 2e9;
   for (int i = 0; i < 2; ++i)
   {
      int first = which[0][i];
      for (int j = 0; j < 2; ++j)
      {
         int second = which[1][j];
         if(first == second)continue;
         smin(ans, n-ma[0][i]-ma[1][j]);
      }
   }

   cout<<ans;
   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    char field[55][55];
    for (int i = 0; i < 55;i++){
        for (int j = 0; j < 55;j++){
            field[i][j] = '.';
        }
    }
    int H, W;
    cin >> H >> W;
    for (int i = 1; i <= H;i++){
            scanf("%s", field[i]);
    }

    for (int search_h = 1; search_h <= H;search_h++)
    {
        for (int search_w = 1; search_w <= W;search_w++)
        {
            if(field[search_h][search_w]=='#'){
                if (field[search_h-1][search_w] == '.' && field[search_h+1][search_w] == '.' && field[search_h][search_w-1] == '.' && field[search_h][search_w+1] == '.'){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int[] t=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long ans=0;
		for(int i=1;i<s[0];i++){ans+=Math.Min(t[i]-t[i-1],s[1]);}
		Console.WriteLine("{0}",ans+s[1]);
	}
}

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

struct UnionFind {
    int parent[200001];

    UnionFind(int n) {
        for (int i = 1; i <= n; i++) parent[i] = i;
    }

    int root(int x) {
        if (parent[x] == x) return x;
        else return parent[x] = root(parent[x]);
    }

    bool same(int x, int y) {
        return parent[x] == parent[y];
    }

    void unite(int x, int y) {
        if (same(x, y)) return;
        parent[root(x)] = root(y);
    }
};

int main() {
    int n, k, l;
    int p[100000], q[100000], r[100000], s[100000];
    cin >> n >> k >> l;
    for (int i = 0; i < k; i++) cin >> p[i] >> q[i];
    for (int i = 0; i < l; i++) cin >> r[i] >> s[i];

    UnionFind uf1(n), uf2(n);
    for (int i = 0; i < k; i++) uf1.unite(p[i], q[i]);
    for (int i = 0; i < l; i++) uf2.unite(r[i], s[i]);

    map<pair<int, int>, int> m;
    for (int i = 1; i <= n; i++) {
        m[make_pair(uf1.root(i), uf2.root(i))]++;
    }

    for (int i = 1; i <= n; i++) {
        cout << m[make_pair(uf1.root(i), uf2.root(i))] << ((i == n) ? "\n" : " ");
    }
}


Measured memory_bytes: 18016
from collections import defaultdict
import numpy as np
n,k=map(int,input().split())
a=[0]+list(np.cumsum(list(map(int,input().split()))))

dic = defaultdict(int)
c = 0
for i in range(len(a)):
    p = (a[i] - i) % k
    c += dic[p]
    dic[p] += 1
    if i >= k - 1:
        dic[(a[i - k + 1] - (i - k + 1)) % k] -= 1
print(c)

Measured memory_bytes: 44332
#include <stdio.h>

int main(){

  int a,b,c,x;
  scanf("%d %d %d",&a,&b,&c);
  if(a > b){
    x = b;
    b = a;
    a = x;
  } if(b > c){
    x = c;
    c =  b;
    b = x;
  } if(a > b){
    x = b;
    b = a;
    a = x;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
unsigned long long c[50];
int main()
{
	int n,m;
	cin>>n>>m;
	c[1]=1;
	for(int i=1;i<=32;i++)
		c[i+1]=m*c[i];
	for(int i=1;;i++)
	{
		if(n<c[i])
		{
			cout<<i-1<<endl;
			return 0;
		}
	}
} 

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

using namespace std;

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

    for(int i=0; i<S.size(); i++) {
        S[i] = (S[i] - 'A' + N) % 26 + 'A';
    }

    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn main() {
    let (n, sd) = readl!(usize, i64);
    let d = readlvec!(i64);
    let qn = readl!(usize);
    let q = readlvec!(usize);
    let mut xs = vec![0; n+1];
    xs[n] = 1;
    for i in (0..n).rev() {
        if xs[i+1] <= d[i]/2 {
            xs[i] = xs[i+1];
        } else {
            xs[i] = xs[i+1]+d[i];
        }
    }
    // debug!(xs);

    use std::cmp::{min, max};
    let mut ans = Vec::with_capacity(n);
    let mut p = sd;
    for i in 0..n {
        // debug!(i); debug!(p);
        ans.push(xs[i+1] <= p);
        p = min(p, (p-d[i]).abs());
    }

    // debug!(ans);
    for &q in &q {
        // debug!(q);
        if ans[q-1] {
            println!("YES");
        } else {
            println!("NO");
        }
    }

    // let sd = sd as usize;
    // let mut dp = vec![false; sd+1];
    // dp[0] = true;
    // for &d in d.iter().rev() {
    //     let mut nex = vec![false; sd+1];
    //     for i in 0..sd+1 {
    //         nex[i] = dp[min(i, max(i as i64 - d, d - i as i64) as usize)];
    //     }
    //     dp = nex;
    //     debug!(d);
    //     for &v in &dp {
    //         if v {
    //             print!("1 ");
    //         } else {
    //             print!("0 ");
    //         }
    //     }
    //     println!("");
    // }
}



Measured memory_bytes: 18076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    map<int, int> ma;
    ma[1] = ma[3] = ma[5] = ma[7] = ma[8] = ma[10] = ma[12] = 1;
    ma[4] = ma[6] = ma[9] = ma[11] = 2;
    ma[2] = 3;

    int x,y; cin >> x >> y;
    if(ma[x] == ma[y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	int N,K;
	scanf("%d %d",&N,&K);
	int keta = 0;
	int sum = 1;
	while(1){
		if( sum > N ){
			break;
		}
		sum = sum * K;
		keta++;
	}
	printf("%d",keta);
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int a, b;
    char op;

    while(1){
        scanf("%d %c %d", &a, &op, &b);
        if (op == '+'){
            printf("%d\n", a + b);
            }
        else if (op == '-'){
                 printf("%d\n", a - b);
            }
        else if (op == '*'){
                 printf("%d\n", a * b);
            }
        else if (op == '/'){
                 printf("%d\n", a / b);
            }
        else{
                 break;
            }
        }
        return 0;
}

Measured memory_bytes: 600
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n-1, -1, -1):
    if (a[i][0]+cnt)%a[i][1] != 0:
        cnt += a[i][1] - ((a[i][0]+cnt)%a[i][1])
print(cnt)

Measured memory_bytes: 27380
#include <stdio.h>
 
int main(){
  int s;
  int h;
  int m;

  scanf("%d", &s);

  h = s/3600;
  m = s%3600/60;
  s = s%60;

  printf("%d:%d:%d\n",h,m,s);

  return 0;
}


Measured memory_bytes: 2052
#                         author:  kagemeka 
#                         created: 2019-11-07 00:57:57(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n, d, x, *a = (int(i) for i in sys.stdin.read().split())
    d -= 1
    c = n
    for i in range(n):
        c += d // a[i]
    total = c + x
    print(total)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#define ll long long
#define mp make_pair
using namespace std;
ll dp[101][200001];
ll n,m;
const ll md=1000000007;
inline ll qp(ll a,ll b){
	ll rt=1;
	while(b){
		if(b&1) rt=(rt*a)%md;
		a=(a*a)%md;
		b>>=1;
	}
	return rt;
}
vector<int> v;
int main(){
	cin>>n>>m;
	int i,j;
	ll t=sqrt(n);
	while(t*t>n) --t;
	for(i=1;i<=t;++i) v.push_back(i),v.push_back(n/i);
	sort(v.begin(),v.end());
	dp[1][0]=1;
	for(i=1;i<v.size();++i) dp[1][i]=v[i]-v[i-1];
	ll sum=0,tsum=0;
	for(i=2;i<=m;++i){
		dp[i][v.size()-1]=(dp[i-1][0]*(v[v.size()-1]-v[v.size()-2]))%md;
		ll sum=dp[i-1][0],t=1;
		for(j=v.size()-2;~j;--j) sum=(sum+dp[i-1][t++])%md,dp[i][j]=(sum*(j==0?v[j]:(v[j]-v[j-1])))%md;
	}
/*	for(i=1;i<=m;++i){
		for(j=0;j<v.size();++j) cout<<dp[i][j]<<' ';
		cout<<endl;
	}
*/	ll ans=0;
	for(i=0;i<v.size();++i) ans=(ans+dp[m][i])%md;
	cout<<ans<<endl;
}

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

using namespace std;

int h[100005];
vector <int> edge[100005];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%d", &h[i]);
	
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	
	int res = 0;
	
	for (int i = 0; i < n; i++) {
		bool flag = 1;
		
		for (int j = 0; j < edge[i].size(); j++) {
			if (h[i] <= h[edge[i][j]]) flag = 0;
		}
		if (flag) res++;
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 9304
#include<stdio.h>
int main(){

  float x1, y1, x2, y2, x3, y3, x4, y4, a, b;
  int i, n;
  scanf("%d", &n);
  for(i=0;i<n;i++){
  scanf("%f %f %f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);

  a=(y1-y2)/(x1-x2);

  b=(y3-y4)/(x3-x4);

  if(a==b)

  printf("YES\n");

  else

  printf("NO\n");

  }

  return 0;

  }



Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
 
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
  
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
 
int main() {
  int n;
  while(cin >> n, n) {
    int f[12][12] = {};
    rep(i, n) {
      rep(j, n) {
        cin >> f[i][j];
        f[i][n] += f[i][j];
        f[n][j] += f[i][j];
        f[n][n] += f[i][j];
      }
    }
 
    rep(i, n+1) {
      rep(j, n+1) {
        printf("%5d", f[i][j]);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
bool isprime(ll v){
    for(ll i=2;i*i<=v;++i){
        if(v%i==0)return false;
    }
    return (v!=1);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b;
    cin>>a>>b;
    ll c = __gcd(a,b);
    if(c == 1){
        cout << 1 << endl;
    }else{
        set<ll> s;
        s.insert(1);
        if(isprime(c)) s.insert(c);
        for(ll i=1;i*i<=c;++i)if(c%i == 0){
            if(isprime(i)) s.insert(i);
            if(isprime(c/i)) s.insert(c/i);
        }
        cout << s.size() << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import std.stdio, std.conv, std.array;
import std.algorithm;

void main() {
  int k, x;
  readf("%d %d\n", &k, &x);

  enum MIN = -1000000;
  enum MAX = 1000000;

  int left = max(MIN, x-k+1);
  int right = min(MAX, x+k-1);

  writef("%s", left);
  foreach (i; left+1 .. right+1) {
    writef(" %s", i);
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    string step;
    cin >> step;
    
    int flag = 0;
    if(step.size())
    {
        for(int i = 1;i <= step.size();i++)
        {
            if(i % 2 == 1 && (step.at(i - 1) != 'R' && step.at(i - 1) != 'U' && step.at(i - 1) != 'D'))
            {
                flag++;
            }
            else if(i % 2 == 0 && (step.at(i - 1) != 'L' && step.at(i - 1) != 'U' && step.at(i - 1) != 'D'))
            {
                flag++;
            }
        }
    }

    if(flag == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    return 0;
}

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

int main()
{
    int n,m;
    std::cin >> n >> m;
    std::map<int,int> all;
    for(int i = 0; i < n; i++){
        int tmp;
        std::cin >> tmp;
        all[tmp]++;
    }
    for(int i = 0; i < m; i++){
        int b,c,left;
        std::cin >> b >> c;
        left = b; //何回書き換えれるか
        while(all.size() && all.begin() -> first < c && left){
            int update_num = std::min(left,all.begin()->second);//引ける量
            all.begin()->second -= update_num;
            if(all.begin()->second == 0)all.erase(all.begin());
            left -= update_num;
        }
        all[c] += b - left;
    }
    long long res = 0;
    for(auto i : all)res += (long long)i.second * i.first;
    std::cout << res << std::endl;
}

Measured memory_bytes: 4992
N, M, K = map(int, input().split())

ans = False
for n in range(N + 1):
    if 2 * n == N:
        if M * n == K:
            ans = True
            break
    else:
        num = M * n - K
        denom = 2 * n - N
        if num % denom == 0 and 0 <= num // denom <= M:
            ans = True
            break
print('Yes' if ans else 'No')


Measured memory_bytes: 2940
MOD = 10**9 + 7
S = int(input())

if S <= 2:
    print(0)
    exit(0)
dp = [1 for i in range(S + 1)]
dp[1] = 0
dp[2] = 0
for i in range(3, S + 1):
    dp[i] = sum(dp[:i - 2]) % MOD
print(dp[S] % MOD)

Measured memory_bytes: 9092
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
string S, T;

signed main(){
	cin >> N >> S >> T;
	rep(i, N) cout << S[i] << T[i];
	cout << endl;
}

Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

A, B, C, D = rl()

flag = True
while A > 0 and C > 0:
	if flag:
		C -= B
	else:
		A -= D
	flag = not flag
if A > 0:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 61920
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>

using namespace std;
#define SAY_YES cout<<"YES"<<endl;
#define SAY_Yes cout<<"Yes"<<endl;
#define SAY_NO cout<<"NO"<<endl;
#define SAY_No cout<<"No"<<endl;
#define IFYES(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} 
#define IFYes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} 
#define IFyes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} 
#define DEBUG_OUTPUT_ARRAY(XXX,ONE) for(int i=0;i<(ONE);i++){cout<<"DEBUG: i = "<<i<<" -> "<<XXX[i]<<endl;}
#define DEBUG_OUTPUT_ARRAY2(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<"<<< i = "<<i<<" >>>"<<endl;for(int j=0;j<(TWO);j++){cout<<"DEBUG: j = "<<j<<" -> "<<XXX[i][j]<<endl; } }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<i<<"  ";for(int j=0;j<(TWO);j++){cout<<XXX[i][j]<<" "; } cout<<endl;}

typedef pair<long long int,long long int> pll;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int N,K,p,q,cou=0,P[10],Q[10],normal[10]={0,1,2,3,4,5,6,7,8};
pair<long double,long double> xy[15];
int main() {
	cout << fixed << setprecision(18);
    cin>>N;
    long double res=0,tmp=0;
    for(int i=0;i<N;i++){
        cin>>P[i]>>Q[i];
    }
    
    do{
        
        bool key=false;
        for(int i=0;i<N;i++){
            if(normal[P[i]]!=Q[i]){
                key=true;
            }
        }
        if(key){continue;}
        
        for(int i=0;i<8;i++){
            for(int j=i+1;j<8;j++){
                if(abs(normal[i]-normal[j])==abs(j-i)){key=true;}
            }
        }
        if(key){continue;}
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
                if(normal[i]==j){cout<<"Q";}
                else{cout<<".";}
            }
            cout<<endl;
        }
        
    }while(next_permutation(normal,normal+8));
    
} 



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

const int inf = (1 << 28);

struct Network {
    struct Arc {
        int from, to, cap, cost, rev;

        Arc() {}
        Arc(int from, int to, int cap, int cost, int rev) :
            from(from), to(to), cap(cap), cost(cost), rev(rev) {}
    };

    int n;
    vector<vector<Arc>> graph;

    Network(int n = 0) : n(n), graph(n) {}

    void addArc(int from, int to, int cap) {
        graph[from].emplace_back(from, to, cap, 0, graph[to].size());
        graph[to].emplace_back(to, from, 0, 0, graph[from].size() - 1);
    }

    int findBlockingFlow(vector<Arc*>& hist, int s, int t) {
        vector<int> dist(n, inf), limit(n, inf);
        fill(hist.begin(), hist.end(), nullptr);

        queue<int> que;
        dist[s] = 0;
        que.push(s);

        while (!que.empty()) {
            int u = que.front(); que.pop();

            for (Arc& arc : graph[u]) {
                if (dist[arc.to] > dist[u] + 1 and arc.cap > 0) {
                    dist[arc.to] = dist[u] + 1;
                    hist[arc.to] = &arc;
                    limit[arc.to] = min(limit[u], arc.cap);
                    que.push(arc.to);

                    if (arc.to == t) break;
                }
            }
        }
        return limit[t];
    }

    int findMaximumFlow(int s, int t) {
        vector<Arc*> hist(n, nullptr);
        int sumFlow = 0, flow;

        while (flow = findBlockingFlow(hist, s, t), hist[t] != nullptr) {
            Arc* flowPtr = hist[t];
            while (flowPtr != nullptr) {
                flowPtr->cap -= flow;
                graph[flowPtr->to][flowPtr->rev].cap += flow;
                flowPtr = hist[flowPtr->from];
            }
            sumFlow += flow;
        }
        return sumFlow;
    }

    int findMinimumCut(int s, int t) {
        return findMaximumFlow(s, t);
    }
};

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

    int n, m;
    cin >> n >> m;

    Network network(n);
    for (int i = 0; i < m; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        network.addArc(u, v, c);
    }
    cout << network.findMaximumFlow(0, n - 1) << endl;

    return 0;
}


Measured memory_bytes: 3292
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll ans = 0;
  int min_AB = min(A + B, 2 * C);

  if (X > Y) {
    ans += Y * min_AB;
    if (A > 2 * C) {
      ans += (X - Y) * 2 * C;
    } else {
      ans += (X - Y) * A;
    }
  } else {
    ans += X * min_AB;
    if (B > 2 * C) {
      ans += (Y - X) * 2 * C;
    } else {
      ans += (Y - X) * B;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
PS = [line.split() for line in readlines()]

AC = [False] * (N+1)
WA_cnt = [0] * (N+1)

penal = 0
for p,s in PS:
    p = int(p)
    if AC[p]:
        continue
    if s == b'WA':
        WA_cnt[p] += 1
    else:
        AC[p] = True
        penal += WA_cnt[p]

ac = sum(AC)
print(ac, penal)


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

string s;

int main(){
	cin >> s;
	int len = s.size();
	bool flagF = 0, flagC = 0;
	for(int i = 0; i < len; i ++){
		if(s[i] == 'C') flagC = 1;
		if(flagC && s[i] == 'F') flagF = 1;
		if(flagF){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

while True:
    n = int(input())
    if n == 0:
        break
    a = [int(input()) for _ in range(n)]
    cnt = Counter(i for i in range(7))
    for v in a:
        if v < 10:
            cnt[0] += 1
        elif v < 20:
            cnt[1] += 1
        elif v < 30:
            cnt[2] += 1
        elif v < 40:
            cnt[3] += 1
        elif v < 50:
            cnt[4] += 1
        elif v < 60:
            cnt[5] += 1
        else:
            cnt[6] += 1
    for i in range(7):
        print(cnt[i]-1)

Measured memory_bytes: 15984
#include <stdio.h>

int parent(int i) {
	if (i) return (i - 1) /4;
	else return 0;
}

int child(int i, char c) {
	switch (c) {
	case 'A':
		return i*4 + 1;
		break;
	case 'C':
		return i*4 + 2;
		break;
	case 'G':
		return i*4 + 3;
		break;
	case 'T':
		return i*4 + 4;
		break;
	default:
		return -1;
	}
}

unsigned char H[2100000];

int index(int i) {
	return i / 8;
}

int offset(int i) {
	return i % 8;
}

void Set(int i) {
	int j = index(i);
	int off = offset(i);
	H[j] = H[j] | (1 << off);
}

int Get(int i) {
	int j = index(i);
	int off = offset(i);
	return H[j] & (1 << off);
}

void Insert(const char *s) {
	int nd = 0;
	const char *p;
	for (p = s; *p != '\0'; p++) {
		nd = child(nd, *p);
	}
	Set(nd);
}

int Find(const char *s) {
	int nd = 0;
	const char *p;
	for (p = s; *p != '\0'; p++) {
		nd = child(nd, *p);
	}
	return Get(nd);
}

int main(int argc, char **argv)
{
	int n, i;
	char s[32];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", s);
		if (s[0] == 'i') {
			scanf("%s", s);
			Insert(s);
		} else {
			scanf("%s", s);
			if (Find(s)) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1852
package main
import (
  "container/heap"
  "fmt"
)
const INF = 1000000000
func main() {
  var h,w,k int
  var s string
  fmt.Scan(&h,&w,&k)
  g := make([][]int,h*w+1)
  opened := make([]bool,h*w)
  x,y := -1,-1
  uf := NewUnionFind(h*w)
  for i:=0;i<h;i++ {
    fmt.Scan(&s)
    for j:=0;j<w;j++ {
      id := w*i+j
      if s[j:j+1] != "#" { opened[id] = true }
      if s[j:j+1] == "S" { x,y = i,j }
      if i == 0 || i == h-1 || j == 0 || j == w-1 {
        g[h*w] = append(g[h*w],id)
      }
      if i != 0 {
        g[id] = append(g[id],w*(i-1)+j)
        g[w*(i-1)+j] = append(g[w*(i-1)+j],id)
        if opened[id] && opened[w*(i-1)+j] { uf.Unite(id,w*(i-1)+j) }
      }
      if i != h-1 {
        g[id] = append(g[id],w*(i+1)+j)
        g[w*(i+1)+j] = append(g[w*(i+1)+j],id)
        if opened[id] && opened[w*(i+1)+j] { uf.Unite(id,w*(i+1)+j) }
      }
      if j != 0 {
        g[id] = append(g[id],w*i+j-1)
        g[w*i+j-1] = append(g[w*i+j-1],id)
        if opened[id] && opened[w*i+j-1] { uf.Unite(id,w*i+j-1) }
      }
      if j != w-1 {
        g[id] = append(g[id],w*i+j+1)
        g[w*i+j+1] = append(g[w*i+j+1],id)
        if opened[id] && opened[w*i+j+1] { uf.Unite(id,w*i+j+1) }
      }
    }
  }
  c := dijkstra(g,h*w)
  m := INF
  st := w*x+y
  for i:=0;i<h;i++ {
    for j:=0;j<w;j++ {
      id := w*i+j
      if abs(i-x)+abs(j-y) <= k && uf.Same(st,id) { m = min(m,(c[id]+k-1)/k+1) }
    }
  }
  fmt.Println(m)
}
func abs(n int) int {
  if n < 0 { return -n }
  return n
}
func min(n,m int) int {
  if n < m { return n }
  return m
}
func dijkstra(g [][]int,start int) []int {
  n := len(g)
  c := make([]int,n)
  for i:=0;i<n;i++ { c[i] = INF }
  var pq PriorityQueue
  heap.Init(&pq)
  heap.Push(&pq,&Item{start,-1})
  c[start] = -1
  for pq.Len() > 0 {
    s := heap.Pop(&pq).(*Item)
    if s.cost > c[s.pos] { continue }
    for _,e := range g[s.pos] {
      if c[e] > s.cost+1 {
        c[e] = s.cost+1
        heap.Push(&pq,&Item{e,c[e]})
      }
    }
  }
  return c
}
type Item struct { pos,cost int }
type PriorityQueue []*Item
func(pq PriorityQueue) Len() int { return len(pq) }
func(pq PriorityQueue) Less(i,j int) bool { return pq[i].cost < pq[j].cost }
func(pq PriorityQueue) Swap(i,j int) { pq[i],pq[j] = pq[j],pq[i] }
func(pq *PriorityQueue) Push(x interface{}) {
  item := x.(*Item)
  *pq = append(*pq,item)
}
func(pq *PriorityQueue) Pop() interface{} {
  old := *pq
  n := len(old)
  item := old[n-1]
  *pq = old[0:n-1]
  return item
}
type UnionFind struct { par,rank []int }
func NewUnionFind(n int) UnionFind {
  par := make([]int,n)
  rank := make([]int,n)
  for i:=0;i<n;i++ { par[i] = i }
  return UnionFind{par,rank}
}
func(u UnionFind) Find(i int) int {
  if u.par[i] == i { return i }
  u.par[i] = u.Find(u.par[i])
  return u.par[i]
}
func(u UnionFind) Same(i,j int) bool { return u.Find(i) == u.Find(j) }
func(u UnionFind) Unite(i,j int) {
  i,j = u.Find(i),u.Find(j)
  if i == j { return }
  if u.rank[i] < u.rank[j] { u.par[i] = j;return }
  u.par[j] = i
  if u.rank[i] == u.rank[j] { u.rank[i]++ }
}

Measured memory_bytes: 99072
n = int(input())
a = list(map(str, input().split()))
ans = ""
if n % 2 == 0:
    for i in range(n-1, -1, -2):
        ans += a[i] + " "
    for i in range(0, n, 2):
        ans += a[i] + " "
else:
    for i in range(n-1, -1, -2):
        ans += a[i] + " "
    for i in range(1, n, 2):
        ans += a[i] + " "
print(ans)


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

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main(){
    int N, K;
    cin >> N >> K;
    int dp[1000000];
    dp[0] = 0;
    int h[1000000];
    rep(i,N){
        cin >> h[i];
        if(i>0) dp[i] = INF;
    }

    int cost = 0;
    for(int i=0; i<N; i++){
        for(int k=1; k<=K; k++){
            if(i+k<N){
                cost = dp[i] + abs(h[i]-h[i+k]);
                dp[i+k] = min(dp[i+k] , cost);
            }
        }
    }
    cout << dp[N-1];
    return 0;
}

Measured memory_bytes: 6400
import java.util.Scanner;

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

        while(true) {
            String x = sc.next();
            if (x.equals("0")) break;
            
            int sum = 0;
            for (int i = 0; i < x.length(); i++) {
                sum += (x.charAt(i) -'0');
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 26348
use std::cmp::*;

#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, weight) = get!(usize, usize);
    let mut weightv = Vec::with_capacity(n);
    let mut valuev = Vec::with_capacity(n);
    for _ in 0..n {
        let (w, v) = get!(usize, usize);
        weightv.push(w);
        valuev.push(v);
    }
    let mut dp = vec![vec![0; weight + 1]; n + 1];
    for i in 0..n {
        for w in 0..weight + 1 {
            if weightv[i] <= w {
                dp[i + 1][w] = max(dp[i][w], dp[i][w - weightv[i]] + valuev[i]);
            } else {
                dp[i + 1][w] = dp[i][w];
            }
        }
    }
    println!("{}", dp[n][weight]);
}


Measured memory_bytes: 106748
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,a[SZ];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	a[0]=-1;
	for(int i=1;i<=n;++i)
		if(a[i]>a[i-1]+1)
		{
			puts("-1"); return 0;
		}
	ll su=0;
	for(int i=n;i>=1;--i)
		if(a[i])
		{
			su++;
			if(a[i]!=a[i-1]+1) su+=a[i]-1;
		}
	printf("%lld\n",su);
}


Measured memory_bytes: 1024
from functools import reduce
def cmb(n,r,p):
    r=min(n-r,r)
    if r==0:
        return 1
    number=reduce(lambda x,y: (x*y)%p,range(n,n-r,-1))
    denom=reduce(lambda x,y: (x*y)%p,range(1,r+1))
    return (number*pow(denom,p-2,p))%p

p=10**9+7
n,a,b=map(int,input().split())
ans=pow(2,n,p)-1
ans-=cmb(n,a,p)+cmb(n,b,p)
print(ans%p)

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

long long n,a[1000000];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int dem=0;
    for(int i=1;i<=n;i++)
    {
        while (a[i]==i)
        {
            swap(a[i],a[i+1]);
            i=i+1;
            dem++;
        }
    }
     cout<<dem;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifndef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define test  \
	int t;    \
	cin >> t; \
	while (t--)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve()
{
	int n;
	cin >> n;
	vector<pair<string, int>> v(n);
	map<pair<string, int>, int> mp;
	rep(i, 0, n - 1)
	{
		cin >> v[i].fi >> v[i].se;
		mp[{v[i].fi, v[i].se}] = i + 1;
	}
	sort(all(v), [](const pair<string, int> &a, const pair<string, int> &b) {
		if (a.fi == b.fi)
			return a.se > b.se;
		return a.fi < b.fi;
	});
	rep(i, 0, n - 1) cout << mp[{v[i].fi, v[i].se}] << "\n";
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// test
	solve();
	return 0;
}


Measured memory_bytes: 3640
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

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

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 998244353

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

ll dp[3003][3003];
ll arr[3003];
ll S;

ll solve(ll pos, ll sum)
{
	if(sum > S) return 0;

	ll &ret = dp[pos][sum];

	if(ret != -1) return ret;

	if(pos == 0) return ret = (sum == S);

	ret = (solve(pos - 1, sum + arr[pos]) + solve(pos - 1, sum) * 2) % mod;

	return ret;
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

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

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

    while(cin >> n >> S)
    {
		memset(dp,-1,sizeof dp);

		for(i = 1; i <= n; i++) slld(arr[i]);

		ans = solve(n,0);

		cout << ans << '\n';
    }


}




Measured memory_bytes: 74380
"use strict";
const main = arg => {
  	const rows = arg.trim().split("\n");
  	const is3or5 = (n)=> {return (n%3||n%5)}
  	let N = rows[0]*1;
   	let targetArr = rows[1].split(" ").map(x => x*1).filter(x => {return !(x%2)});
  	let ans = "APPROVED";	
  	for(let i = 0; i < targetArr.length; i++){
    	if(!(targetArr[i]%3 ==0 || targetArr[i]%5 ==0)){
        	ans = "DENIED";
        }
    }
  console.log(ans);
  	
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999


//note that this is 1-index
template<class T>
class BIT{
private:
    vector<T> sum_of_section_;
    int elements_count_;
    T init_;
    
public:
    BIT(int elements_count=0 , T init=0):elements_count_(elements_count*2),init_(init),sum_of_section_(elements_count*2+1,0){
        for(int i=0;i<elements_count_;i++){
            add(i+1,init);
        }
    }
    
    T sum(int i){   //(1,i)
        int sum=0;
        while(i>0){
            sum+=sum_of_section_[i];
            i -= i&-i;
        }
        return sum;
    }
    
    void add(int i,T val){
        while(i<=elements_count_){
            sum_of_section_[i]+=val;
            i += i&-i;
        }
    }
};


int main(){
    int n,q;
    cin>>n>>q;
    BIT<int> bit(n);
    
    rep(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0){
            bit.add(x,y);
        }
        else{
            cout<<bit.sum(y)-bit.sum(x-1)<<endl;
        }
    }
}

Measured memory_bytes: 3540
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

const int MAX_LIMIT = 1000006;

bool isPrime[MAX_LIMIT];
std::vector<int> prime;
void sieve()
{
	int limit = MAX_LIMIT, i, j;
	memset(isPrime, 0, sizeof(isPrime));
	for(i = 2; i < limit + 1; i++)
		isPrime[i] = 1;

	int inLimit = sqrt(limit);
	inLimit++;

	for(i = 2; i < inLimit; i++)
	{
		if(isPrime[i]==1)
		{
			for(j=i*i; j<limit; j+=i)
				isPrime[j] = 0;
		}
	}

	for(i = 2; i < MAX_LIMIT; i++)
		if(isPrime[i])
			prime.push_back(i);

	return;
}

ll numPrimes = 0;
ll uniquePrimes = 0;
ll dp[100005][55];

ll rec(int ind, int x) {
	if (ind == 1 || x == 0) {
		return 1;
	}

	ll &ret = dp[ind][x];
	if (ret != -1) {
		return ret;
	}

	ret = (
		rec(ind - 1, x) + rec(ind, x - 1)) % MOD;
	return ret;
}

ll N, M;
map<ll, int> mp;

int main()
{
	memset(dp, -1, sizeof(dp));
	sieve();
	scanf("%lld %lld", &N, &M);

	for (int i = 0; i < prime.size(); i++) {
		while(M % prime[i] == 0) {
			// cout << prime[i] << "\n";
			M /= prime[i];
			mp[prime[i]]++;
		}
	}

	if (M != 1) {
		mp[M]++;
	}

	ll ans = 1;

	for (map<ll, int>::iterator itr = mp.begin(); itr != mp.end(); itr++) {
		// cout << (rec(N, itr->second)) % MOD << "\n";
		ans = (ans * rec(N, itr->second)) % MOD;
	}

	printf("%lld\n", ans);


	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 49272
// A - Connection and Disconnection
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

ll f(const string &S, int K){//文字列の操作回数を求める
	string T; rp(i, 0, K) T += S;//T=S*K
	ll c = 0;
	rp(i, 1, T.size()) if(T[i-1] == T[i]) c++, i++;
	return c;
}

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

  int c = 0;
  if(K > 100){
    c = K - 100;
    if(c & 1) c++;
    K -= c;
  }

  ll s1 = f(S, K);
	ll s3 = f(S, K+2);
  ll d = s3 - s1;
  ll ans = s1 + d * (c / 2);
  cout<< ans <<endl;
}

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

double dp[3010][3010];

int main(){
  int n;
  cin >> n;
  dp[0][0] = 1;
  double p[3010];
  rep(i,n) cin >> p[i+1];
  for(int i = 1; i <= n; i++){
    for(int j = 0; j <= n; j++){
      dp[i][j] = 0;
      dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
    }
  }
  
  double ans = 0;
  for(int i = 0; i<=n; i++){
    if(i > n-i) ans += dp[n][i];
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  string S;
  cin >> S;
  llong ans = 0, a = S[0] == 'R';
  for (int i = 1; i < 3; i++) {
    if (S[i] == 'R') {
      a++;
    }
    else {
      ans = max(ans, a);
      a = 0;
    }  }

  cout << max(ans, a) << endl;

  return 0;
}

Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
int main() {
	int l, r, ans = 1 << 30;
	scanf("%d%d", &l, &r);
	if (l / 2019 != r / 2019) {
		puts("0");
		return 0;
	}
	rep(i, l, r + 1) {
		rep(i2, i + 1, r + 1) {
			ans = min(ans, (i % 2019 * (i2 % 2019)) % 2019);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = {}
for _ in range(n):
    s = input()
    if s not in d.keys():
        d[s] = 0
    d[s] += 1
m = int(input())
for _ in range(m):
    s = input()
    if s in d.keys():
        d[s] -= 1
d = sorted(d.items(), key=lambda x:x[1])
if d[-1][1] == - (m - 1) or (d[-1][1] < 0): print(0)
else: print(d[-1][1])

Measured memory_bytes: 3064