akhauriyash/Code-Regression huggingface dataset:
/* Alohomora */
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define mod1        987654319 
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll fact(ll n){ if(n==0){return 1;}return (n*fact(n-1))%mod1;}
ll power(ll x, ll y,ll mod){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod1-2,mod1);}
ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
ll a[2000000];
void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){for(j=i*i;j<1000001;j+=i){a[j]=1;}}}}
map<ll,vector<ll> >m1;
vector<ll>v1;
bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second);
} 
ll level[1000000];
vector<ll>root;
void comp()
{
	ll i,j,l,r,n,q,k,u,v,c,d;
	vector<ll>v1;
	cin>>n>>k;
	fl(i,n-1)
	{
		cin>>u>>v;
		m1[u].pb(v);
		m1[v].pb(u);
	}
	ll vis[n+1]={0};
	vector<ll>v2(n+1);
	v2[1]=k;
	queue<ll>q1;
	vis[1]=1;
	fl(i,m1[1].size())
	{
		if(vis[m1[1][i]]==0)
		{
			q1.push(m1[1][i]);
			v2[m1[1][i]]=k-i-1;
			vis[m1[1][i]]=1;
		}
	}
	ll temp;
	while(q1.size()>0)
	{
		temp=q1.front();
		q1.pop();
		j=0;
		fl(i,m1[temp].size())
		{
			if(vis[m1[temp][i]]==0)
			{
				q1.push(m1[temp][i]);
				v2[m1[temp][i]]=k-j-2;
				vis[m1[temp][i]]=1;
				j++;
			}
		}
	
	}
	ll ans=1;
	fli(i,1,n+1)
	{
		ans=ans*v2[i];
		ans%=1000000007;
	}
	cout<<ans<<"\n";
} 
int main()
{
	speedup;
	ll i=0,t;
	ll n;
	//cin>>t;
	t=1;
	while(t--)
	{
	 comp();
	}
}

Measured memory_bytes: 16372
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<long> a(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> a[i];
    }
    ll count = 0;
    ll num=1;
    ll idx=0;
    while(idx!=N)
    {
        if(a[idx]==num)
        {
            num++;
            idx++;
        }else
        {
            count++;
            idx++;
        }
    }
    if(count==N) cout << -1 << endl;
    else cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

Measured memory_bytes: 61528
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
struct p{
	int i,val;
	p(int A,int B)
	{
		i=A;val=B;
	}
	p(){}
	friend bool operator <(p s1,p s2)
	{
		if(s1.i!=s2.i)
			return s1.i<s2.i; 
		if(s1.i==s2.i)
			return s1.val>s2.val; 
	}
	friend bool operator ==(p s1,p s2)
	{
		return s1.val==s2.val&&s1.i==s2.i;	
	} 
};
const int N=3e5+7;
vector<int> x;
vector<int> y;
map<p,int> mm;
int r[N],l[N];
int main()
{
	int m,n,c;
	cin>>m>>n>>c;
	int mw=-1,mh=-1;
	for(int i=1;i<=c;i++)
	{
		int h,w;
		cin>>h>>w;
		r[h]++;l[w]++;
		mm[p(h,w)]=1;
	}
	int maxr=-1,maxl=-1;
	for(int i=1;i<=max(m,n);i++)
	{
		maxr=max(maxr,r[i]);
		maxl=max(maxl,l[i]);
	} 
	for(int i=1;i<=max(m,n);i++)
	{
		if(maxr==r[i])
			x.push_back(i);
		if(maxl==l[i])
			y.push_back(i);
	}
	for(int i=0;i<x.size();i++)
	{
		for(int j=0;j<y.size();j++)
		{
			int xxx=x[i],yyy=y[j];
			int nmsl=mm.count(p(xxx,yyy));
			if(!nmsl)
			{
				cout<<maxr+maxl;
				return 0;	
			} 
		} 
	}
	cout<<maxr+maxl-1;
	return 0;
}

Measured memory_bytes: 27408
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	lint N,x;
	lint a[2010]={};
	
	cin >> N >> x;
	for(int i=0;i<N;i++)
		cin >> a[i];
	
	lint ans=1e18;
	lint b[2010]={};
	for(int i=0;i<N;i++)
		b[i]=a[i];
	for(int k=0;k<N;k++)
	{
		for(int i=0;i<N;i++)
			b[i]=min(b[i],a[(i-k+N)%N]);
		
		lint tans=x*k;
		for(int i=0;i<N;i++)
			tans+=b[i];
		ans=min(ans,tans);
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
dice = list(map(int, input().split()))
dice2 = list(map(int, input().split()))

slist = "NNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNNSNNNNWNNNNWNNNNWNNNN"

for s in slist:
    if s == "N":
        next = list("263415")
    elif s == "E":
        next = list("421653")
    elif s == "S":
        next = list("513462")
    else:
        next = list("326154")

    tmp = [0] * 6
    for i, n in enumerate(next):
        tmp[i] = dice[int(n)-1]

    dice = tmp

    if dice == dice2:
        print("Yes")
        exit()

print("No")



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int A, B, C;
    cin >> A >> B >> C;
    OUT(min(B/A,C))

    return 0;
}

Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, x[100], y[100];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &x[i]);
	for(int i = 0; i < n; i++) scanf("%d", &y[i]);
	for(int i = 1; i < 4; i++) {
		long long sum = 0;
		for(int j = 0; j < n; j++) sum += pow(abs(x[j] - y[j]), i);
		printf("%.9f\n", pow(sum, 1.0 / i));
	}
	int r = 0;
	for(int i = 0; i < n; i++) r = max(r, abs(x[i] - y[i]));
	printf("%d\n", r);
	return 0;
}

Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
typedef pair<int,int> P;
vector<P> G[100000];
int ans[100000];
int main() {
    int K;
    cin>>K;
    for(int i=0;i<K;i++) {
        G[i].emplace_back((i+1)%K,1);
        G[i].emplace_back((i*10)%K,0);
    }
    deque<int> Q;
    Q.push_back(1);
    fill(ans,ans+K,1<<30);
    ans[1]=1;
    while(!Q.empty()) {
        int v=Q.front();Q.pop_front();
        if(v==0) break;
        for(P e:G[v]) {
            if(ans[e.first]>ans[v]+e.second) {
                ans[e.first]=ans[v]+e.second;
                if(e.second) Q.push_back(e.first);
                else Q.push_front(e.first);
            }
        }
    }
    cout<<ans[0]<<endl;
}

Measured memory_bytes: 6272
#import sys
#input = sys.stdin.readline
def main():
    H, W = map( int, input().split())
    ans = min(H,W)
    if H%3 == 0 or W%3 == 0:
        ans = 0
    for i in range(1,H):
        L = [W*i]
        L.append(W//2*(H-i))
        if W%2 == 1:
            L.append((W//2+1)*(H-i))
        if max(L) - min(L) < ans:
            ans = max(L) - min(L)
    for i in range(1,W):
        L = [H*i]
        L.append(H//2*(W-i))
        if H%2 == 1:
            L.append((H//2+1)*(W-i))
        if max(L) - min(L) < ans:
            ans = max(L) - min(L)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  if(n<=111) puts("111");
  else if(n<=222) puts("222");
  else if(n<=333) puts("333");
  else if(n<=444) puts("444");
  else if(n<=555) puts("555");
  else if(n<=666) puts("666");
  else if(n<=777) puts("777");
  else if(n<=888) puts("888");
  else if(n<=999) puts("999");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int W, H;
char c;
int main() {
  cin >> W >> H >> c;
  // Ue
  cout << '+';
  for (int i = 1; i < W - 1; i++) {
    cout << '-';
  }
  cout << '+' << '\n';
  // Naka
  for (int i = 1; i < H - 1; i++) {
    cout << '|';
    if (i == (H - 2) / 2 + 1) {
      for (int j = 1; j < W / 2; j++) {
        cout << '.';
      }
      cout << c;
      for (int j = W / 2 + 1; j < W - 1; j++) {
        cout << '.';
      }
    } else {
      for (int j = 1; j < W - 1; j++) {
        cout << '.';
      }
    }
    cout << '|' << '\n';
  }
  // Shita
  cout << '+';
  for (int i = 1; i < W - 1; i++) {
    cout << '-';
  }
  cout << '+' << '\n';
  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int n,a[200004],K;
bool check(int x){
	int num=0;
	for(int i=0;i<n;i++){
		num+=(a[i]+x-1)/x-1;
		if(num>K)return 0;
	}
	return 1;
}
int main(){
	cin>>n>>K;
	for(int i=0;i<n;i++)cin>>a[i];
	int l=0,r=1e9+1;
	while(r>l+1){
		int mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid;
	}
	cout<<r;
}

Measured memory_bytes: 4344
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M;
struct Edge{
    ll from,to,cost;
};
vector<Edge> edgeList;
ll dist[1010];
ll pre[1010];

bool checked[1010]={};
bool Closed(ll n){
    if(checked[n]){
        return true;
    }
    checked[n]=true;
    if(n==0 && pre[0]==0) return false;
    return Closed(pre[n]);
}
int main(){
    cin>>N>>M;
    for(ll i=0;i<M;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        edgeList.push_back(Edge{a,b,-c});
    }
    for(ll i=0;i<N;i++)dist[i]=INF;
    dist[0]=0;
    for(ll i=0;i<N;i++){
        for(auto e:edgeList){
            if(dist[e.to]>dist[e.from]+e.cost){
                dist[e.to]=dist[e.from]+e.cost;
                pre[e.to]=e.from;
            }
        }
    }
    if(Closed(N-1)){
        cout<<"inf"<<endl;
        return 0;
    }
    cout<<-dist[N-1]<<endl;
    return 0;
}

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

using namespace std;

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

    if (A - B >= 0) {
        cout << "delicious" << endl;
    } else if (A + X - B >= 0) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

// 0始まりで0に戻るの本質だったのか

signed main(){
    int n;cin>>n;
    vector<int> l(n),r(n);
    rep(i,n)cin>>l[i]>>r[i];
    l.push_back(0);r.push_back(0);
    sort(ALL(l));reverse(ALL(l));
    sort(ALL(r));
    ll ans=0;
    rep(i,n+1){
        if(l[i]>r[i])ans+=2*(l[i]-r[i]);
    }
    cout<<ans<<endl;
    return 0;
}

/*

区間を損なく置ける場合，
res = 2*(sum(l of r)-sum(r of l))
損なく置く
->端の方の区間から処理していって損しない

sample 2
3
1 2
3 4
5 6

[1,2][3,4][5,6]

l:5 3 1 0 
r:0 2 4 6

2*(5-0)
0->->->->->5
 <-<-<-<-<-

2*(3-2)
2->3
 <-
*/


Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n = 100;
    ll x;
    cin >> x;
    ll ans = 0;
    while (n < x) {
        n *= 1.01;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
using namespace std;

int main(void) {
    int X;cin>>X;
    int ma = -1;
    if (X == 1) {
        cout << 1 << endl;
        return 0;
    }
    for (int i = 2; i <= 40; i++) {
        int p = 2;
        int po = pow(i, p);
        while (po <= X) {
            if (ma < po) {
                ma = po;
            }
            p++;
            po = pow(i, p);
        }
    }
    cout << ma << endl;
    return 0;
}

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

using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
int main(){
    int n; cin >> n;
	cpp_int a[n];cpp_int res = 1;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a+n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		res = res*a[i];
		if(res > 1000000000000000000)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 6856
/*
  Author: @yash_31
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long int
#define eb emplace_back
#define fatafat ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define ft first
#define sd second
#define vpi vector<pair<int,int> >
#define vpl vector<pair<ll,ll> >
#define mkpr make_pair
#define todec() to_ulong()
#define toldec() to_ullong()
#define deb(x) std::cout<<#x<<":"<<x<<endl;
#define whole(x) (x).begin(),(x).end()
#define revwhole(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define fbo find_by_order
#define ook order_of_key
 
using namespace std; 
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> gharKaSet;
 
const int maxlimit=5e5+2;
const ll inf=1e12;
 
ll dp[(1<<21)+1][22];
int n;
ll allset;
 
vector<int> cpht[21];
//can person have this topic
 
ll getAns(int mask,int tillass){
  // all got topics
  if(mask==allset)return 1;
  //topics finished
  if(tillass==21)return 0;
  if(dp[mask][tillass]!=-1)return dp[mask][tillass];
  ll ans=0;
  for(auto &st :cpht[tillass]){
    if((mask & (1<<st))==0){
      ans= (ans+getAns(mask | (1<<st),tillass+1))%MOD;
    }
  }
  dp[mask][tillass] = ans;
  return ans;
}
 
int main()
{
  fatafat
  bool interested;
  cin>>n;
  allset=(1LL<<n)-1;
  for(int i=0;i<21;i++)cpht[i].clear();
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>interested;
      if(interested)cpht[j].eb(i);
    }
  }
  memset(dp,-1,sizeof(dp));
  cout<<getAns(0,0)<<endl;
  return 0;
} 


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

int main() {

    int shift;

    scanf("%d",&shift);
    char str[10020]={};
    scanf("%s",str);

    int size = strlen(str);
    for(int i=0;i<size;i++){
        str[i]-='A';
        str[i] = (str[i]+shift)%26;
        str[i] += 'A';
    }

    printf("%s\n",str);

    return 0;
}


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

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

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

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

   ll cnt = 0;
   int n = s.size();
   char c = s[0];
   for (int i = 1; i< n; i++) {
      if (c != s[i]) cnt++;
      c = s[i];
   }

   cout << cnt << endl;


   return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
#define All(v) v.begin(),v.end()
using namespace std;
ll f[1000001];
ll bigmod(ll b,ll p ,ll m)
{
    if(p==0)
        return 1;
    if(p%2 == 0)
    {
        ll temp = bigmod(b,p/2,m);
        return (temp*temp)%m;
    }
    return (bigmod(b,p-1,m)*(b%m))%m;
}
ll InverseEuler(ll n, ll MOD)
{
    return bigmod(n,MOD-2,MOD);
}
ll c(ll n, ll r, ll MOD)
{

    return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
int main()
{
 f[0] = 1;
 for(int i=1; i<=200000; i++)
   f[i] = (f[i-1]*i)%1000000007;
 int n;
 cin>>n;
 int a[n+10];
 int b[n+10];
 int st = 0 , En = 0;
 memset(b,0,sizeof(b));
 for(int i=1;i<=n+1;i++)
 {
     scanf("%d",&a[i]);
     if(b[a[i]]!=0)
     {
         st = b[a[i]];
         En = i;
     }
     b[a[i]] = i;
 }
 int mod = 1e9+7;
 cout<<n<<endl;
 for(int i=2;i<=n+1;i++)
 {
     ll ans = 0;
     ans = c(n+1,i,mod);
     if(st-1+(n+1-En) >= i-1)
     ans-=c(st-1+(n+1-En) , i-1,mod);

     if(ans < 0)
        ans+=mod;
     ans%=mod;
     cout<<ans<<endl;
 }


}



Measured memory_bytes: 3584
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B; cin >> A >> B;
  if (A == B) cout << 2 * A << endl;
  else if (A > B) cout << 2 * A - 1 << endl;
  else cout << 2 * B - 1 << endl;
}


Measured memory_bytes: 3608
n = int(input())
s = []
for i in range(n):
    s.append(input())
m = int(input())
t = []
for i in range(m):
    t.append(input())

word_list = []
for i in s:
    if (i in word_list):
        continue
    else:
        word_list.append(i)

max_value = 0
for i in word_list:
    value = s.count(i) - t.count(i)
    if (max_value < value):
        max_value = value
print(max_value)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
int main(){
  int N, k;
  cin >> N >> k;
  long long tv = INF;
  long long fv = -1;
  while (tv - fv > 1){
    long long mid = (tv + fv) / 2;
    long long x = mid;
    for (int i = 0; i < N - 1; i++){
      if (x % k == 0){
        x++;
      }
      x -= x / k + 1;
    }
    if (x > 0){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << fv << endl;
}


Measured memory_bytes: 3080
#演習1-13 Max Prifit
li=[int(input()) for i in range(int(input()))]

max_val=-10**15
min_val=li[0]
for i in range(1,len(li)):
    max_val=max(max_val,li[i]-min_val)
    min_val=min(min_val,li[i])
    
print(max_val)


Measured memory_bytes: 13592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.StringTokenizer;

public class Main {
    static int max(int a, int b) {
        if (a>b) {
            return a;
        } else {
            return b;
        }
    }
    static int max_2(int a, int b, int c) {
        if (a>=b && a>=c) {
            return a;
        } else if (b>=a && b>=c){
            return b;
        } else {
            return c;
        }
    }
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int N = in.nextInt();
        int T = in.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = in.nextInt();
            B[i] = in.nextInt();
        }
        // long[][][] dp = new long[N+1][T+1][2];
        int[][][] dp = new int[N+1][T+1][2];
        for (int i=1;i<=N;i++) {
            for (int j=1;j<=T-1;j++) {
                if (j-A[i-1]>=0) {
                    int b = B[i-1];
                    int a = A[i-1];
                    // dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j-A[i-1]][0]+B[i-1]);
                    // dp[i][j][1]=max(dp[i-1][j][1], dp[i-1][j][0]+B[i-1]);
                    // dp[i][j][1]=max(dp[i][j][1], dp[i-1][j-A[i-1]][1]+B[i-1]);
                    dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j-a][0]+b);
                    dp[i][j][1]=max_2(dp[i-1][j][1], dp[i-1][j][0]+b, dp[i-1][j-a][1]+b);
                    // dp[i][j][1]=max(dp[i-1][j][1], dp[i-1][j][0]+b);
                    // dp[i][j][1]=max(dp[i][j][1], dp[i-1][j-a][1]+b);
                } else {
                    dp[i][j][0]=dp[i-1][j][0];
                    dp[i][j][1]=max(dp[i-1][j][1], dp[i-1][j][0]+B[i-1]);
                }
            }
        }
        out.println(dp[N][T-1][1]);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

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

  int cnt = 0;
  for(int i=1;i<n-1;++i) {
    if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=998244353;
const ll INF=9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

class mint {
    //from https://qiita.com/ue_sho/items/1ee5c3e665c72c035880
public:
    long long x;
    constexpr mint(long long x=0) : x((x%inf+inf)%inf) {}
    constexpr mint operator-() const { 
      return mint(-x);
    }
    constexpr mint& operator+=(const mint& a) {
        if ((x += a.x) >= inf) x -= inf;
        return *this;
    }
    constexpr mint& operator-=(const mint& a) {
        if ((x += inf-a.x) >= inf) x -= inf;
        return *this;
    }
    constexpr mint& operator*=(const mint& a) {
        (x *= a.x) %= inf;
        return *this;
    }
    constexpr mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime inf
    constexpr mint inv() const {
        return pow(inf-2);
    }
    constexpr mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
};
ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
}

mint dp[220000];

int main(){cout<<fixed<<setprecision(20);
		   ll n,k;
           cin>>n>>k;
           vector<ll> l(k),r(k);
           rep(i,0,k)cin>>l[i]>>r[i];
           //dp,imos
           dp[1]=1;
           dp[2]=-1;
           rep(i,1,n+1){
             dp[i]=(dp[i]+dp[i-1]);
             rep(j,0,k){
              if(i+l[j]<n+2)dp[i+l[j]]=(dp[i+l[j]]+dp[i]);
              if(i+r[j]+1<n+2)dp[i+r[j]+1]=(dp[i+r[j]+1]-dp[i]);
             }
           }
           cout<<dp[n]<<endl;
}



Measured memory_bytes: 5192
#include<bits/stdc++.h>
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scl1(a) scanf("%lld",&a)
#define scl2(a,b) scanf("%lld%lld",&a,&b)
#define scl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr1(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d ",a,b)
#define pr3(a,b,c) printf("%d %d %d ",a,b,c)
#define mii map<int,int>
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define mii map<int,int>
#define ll long long
#define ii pair<int,int>
#define loop(i,a,b) for(int i=(a);i<(b);i++)
#define rloop(i,a,b) for(int i=(a);i>(b);i--)
#define tr(it,c) for(decltype((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define ft first
#define sd second
#define mod 998244353
#define mod2 1000000007
#define mem(a,b) memset(a,b,sizeof(a))
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL)
 
using namespace std;
int gcd(int a,int b)
{
	if(a<b)
	swap(a,b);
	if(b==0)
	return a;
	while((a=a%b)!=0)
	{
		swap(a,b);
	}
	return b;
}
ll modpow(ll x,int y)
{
	ll res=1;
	while(y>0)
	{
		if(y&1)
		res=res*x%mod2;
		y=y>>1;
		x=x*x%mod2;
	}
	return res;
}
ll ncr(int n,int r)
{
	ll f1=1,f2=1;
	loop(i,n-r+1,n+1)
	f1=f1*i%mod;
	loop(i,1,r+1)
	f2=f2*i%mod;
	return f1*modpow(f2,mod-2)%mod;
}
int *sieve(int n)
{
	int *lpf=new int[n+1];
	for(int i=1;i<=n;i++)
	lpf[i]=i;
	int rt=(int)floor(sqrt(n))+1;
	loop(i,2,rt)
	{
		if(lpf[i]!=i)
		continue;
		for(int j=i*i;j<=n;j+=i)
		{
			if(lpf[j]==j)
			lpf[j]=i;
		}
	}
	return lpf;
}









void solve()
{
	int k;
	cin>>k;
	ll rem=7%k,rot=1;
	if(rem==0)
	{
		cout<<1;
		return;
	}
	loop(i,2,1200000)
	{
		rot=rot*10%k;
		rem=(rem+7*rot)%k;
		if(rem==0)
		{
			cout<<i;
			return;
		}
	}
	cout<<-1;
}

int main()
{
	SYNC;
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int t=1;
	//cin>>t;
	while(t--)
	{
		//cout<<"Case #"<<z+1<<": ";
		solve();
		cout<<"\n";
	}
}


Measured memory_bytes: 3684
N = int(input())
S = [list(input()) for _ in range(N)]

for s in S:
    s.sort()
S.sort()

k = 1
ans = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        k += 1
    else:
        ans += k * (k - 1) // 2
        k = 1
ans += k * (k - 1) // 2

print(ans)


Measured memory_bytes: 24652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
typedef long long ll;
using namespace std;
void read(int &x){int f=1;x=0;char s=getchar();while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}x*=f;}
void write(int x){if(x<0){putchar('-');x=-x;}if(x>9)write(x/10);putchar(x%10+'0');}
int mod=10007;
int pown(int x,int y){
	int h=1;
	while(y){
		if(y&1)
			h=h*x%mod;
		y>>=1;
		x=x*x%mod;
	}
	return h;
}
int main(){
	int n,a[105],x;
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int ans=0;
	for(int i=1;i<=n-1;i++){
		if(x>=a[i]){
			ans++;
			x-=a[i];
		}
	}
	if(x==a[n])ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
using namespace std;

int main() {
int N, Ans = 0;cin >> N;
string S;
map<string, int> P;
for(int i = 0; i < N; i++){
cin >> S;
P[S]++;
}

for(auto x : P){
Ans++;
}
cout << Ans << endl;
}

Measured memory_bytes: 19176
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i = 0; i < n; i++)cin >> a[i];
        int ma = 0, mi = 0;
        for(int i = 0; i < n-1; i++){
            if(a[i] < a[i+1]){
                ma = max(ma, a[i+1] - a[i]);
            }else{
                mi = max(mi, a[i] - a[i+1]);
            }
        }
        cout << ma << " " << mi << endl;
    }
}



Measured memory_bytes: 3076
*coins, X = [int(input()) for _ in range(4)]

price = [500, 100, 50]
payable = []

for a in range(coins[0]+1):
    for b in range(coins[1]+1):
        for c in range(coins[2]+1):
            payable.append(a*price[0] + b*price[1] + c*price[2])
            
print(payable.count(X))

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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int min_total = 1 << 30;
  for (int i = 0; i <= 100000; i++) {
    int buy_a = max(0, x - i);
    int buy_b = max(0, y - i);
    int total = i * 2 * c + a * buy_a + b * buy_b;
    min_total = min(min_total, total);
  }

  cout << min_total << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;
typedef long long s64;

const int ONE = 200005;
const int INF = 2147483640;

int get()
{
		int res = 1, Q = 1; char c;
		while( (c = getchar()) < 48 || c > 57)
			if(c == '-') Q = -1;
		if(Q) res = c - 48;
		while( (c = getchar()) >= 48 && c <= 57)
			res = res * 10 + c - 48;
		return res * Q;
}

int n;
int a[ONE];

struct point
{
		int id, val;
		friend bool operator <(point a, point b)
		{
			if(a.val != b.val) return a.val < b.val;
			return a.id < b.id;
		}
};
point res;

namespace Seg
{
		struct power {point odd, eve;} Node[ONE * 4];
		
		void Build(int i, int l, int r)
		{
			Node[i].odd.val = Node[i].eve.val = INF;
			if(l == r)
			{
				if(l & 1) Node[i].odd = (point){l, a[l]};
				else Node[i].eve = (point){l, a[l]};
				return;
			}
			int mid = l + r >> 1;
			Build(i << 1, l, mid), Build(i << 1 | 1, mid + 1, r);
			Node[i].odd = min(Node[i << 1].odd, Node[i << 1 | 1].odd);
			Node[i].eve = min(Node[i << 1].eve, Node[i << 1 | 1].eve);
		}

		void Query(int i, int l, int r, int L, int R, int opt)
		{
			if(L <= l && r <= R)
			{
				if(opt == 1) res = min(res, Node[i].odd);
				else res = min (res, Node[i].eve);
				return;
			}
			int mid = l + r >> 1;
			if(L <= mid) Query(i << 1, l, mid, L, R, opt);
			if(mid + 1 <= R) Query(i << 1 | 1, mid + 1, r, L, R, opt);
		}
}

struct power
{
		int l, r, val;
		bool operator <(power a) const
		{
			if(a.val != val) return a.val < val;
			return a.l < l;
		}
};
priority_queue <power> q;

point Get(int l, int r, int opt)
{
		res = (point){n + 1, INF};
		Seg::Query(1, 1, n, l, r, opt);
		return res;
}

void Add(int l, int r)
{
		if(l > r) return;
		q.push((power){l, r, Get(l, r, l % 2).val});
}

int main()
{
		n = get();
		for(int i = 1; i <= n; i++)
			a[i] = get();

		Seg::Build(1, 1, n);
		Add(1, n);

		for(int i = 1; i <= n / 2; i++)
		{
			power u = q.top(); q.pop();
			point A = Get(u.l, u.r - 1, u.l % 2);
			point B = Get(A.id + 1, u.r, u.r % 2);
			printf("%d %d ", A.val, B.val);

			Add(u.l, A.id - 1), Add(A.id + 1, B.id - 1), Add(B.id + 1, u.r);
		}
}

Measured memory_bytes: 13176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Double> sdList = new ArrayList<>();
		
		while (true) {
		try {
			int n = Integer.parseInt(br.readLine());
			if(n == 0) {
				break;
			}
			String[] score = br.readLine().split("\\s");
			double average = 0;
			double sum = 0;
			for (int i = 0; i < score.length; i++) {
				sum += Double.parseDouble(score[i]);
			}
			average = sum / n;
			double a = 0;
			for (int i = 0; i < n; i++) {
				a += Math.pow((Double.parseDouble(score[i]) - average), 2);
			}
			a = Math.sqrt(a/(double)n);
			sdList.add(a);
		} catch (NumberFormatException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		}
		for (double sd : sdList) {
			System.out.printf("%.10f\n", sd);
		}
	}

}



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

int ix;
int INF = 1001001001;

struct card{
    char suit;
    int value; 
};

int partitionx(vector<card> &A, int p, int r){
    int x = A[r].value;
    ix = p-1;
    for (int j = p; j < r; j++){
        if(A[j].value <= x){
            ix++;
            swap(A[ix], A[j]);
        }
    }
    swap(A[ix+1], A[r]);
    return ix+1;
}

void quickSortx(vector<card> &A, int p, int r){
    if (p < r){
        int q = partitionx(A, p, r);
        quickSortx(A, p, q-1);
        quickSortx(A, q+1, r);
    }
}

void mergex(vector<card> &A, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<card> L(n1+1), R(n2+1);
    rep(i, n1){
        L[i] = A[left+i];
    }
    rep(i, n2){
        R[i] = A[mid+i];
    }
    L[n1].value = INF;
    R[n2].value = INF;

    int i = 0;
    int j = 0;

    for(int k = left; k < right; k++){
        if (L[i].value <= R[j].value){
            A[k] = L[i];
            i += 1;
        } else {
            A[k] = R[j];
            j += 1;
        }
    }
    return;
}

void mergexSort(vector<card> &A, int left, int right){
    if(left+1 < right){
        int mid = (left + right) / 2;
        mergexSort(A, left, mid);
        mergexSort(A, mid, right);
        mergex(A, left, mid, right);
    }
    return;
}

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

    vector<card> A(n), B(n);
    rep(i, n){
        cin >> A[i].suit >> A[i].value;
    }
    rep(i, n){
        B[i].suit = A[i].suit;
        B[i].value = A[i].value;
    }

    quickSortx(A, 0, n-1);
    mergexSort(B, 0, n);

    bool check = true;
    rep(i, n){
        if(A[i].suit != B[i].suit){
            check = false;
            cout << "Not stable" << endl;
            break;
        }
    }
    if(check) cout << "Stable" << endl;

    rep(i, n){
        cout << A[i].suit << " " << A[i].value << endl;
    }

    return 0;
}


Measured memory_bytes: 5148
N = int(input())
T, A = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]

result = 0
rd = 100000000000000000000000

for i, x in enumerate(H):
    t = T - 0.006 * x
    d = abs(A - t)
    if d < rd:
        rd = d
        result = i + 1

print(result)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    string s;
    cin>>s;
    int n = s.length();
    LL sm = 0;
    loop(i,0,n) sm += (s[i] - '0');

    if(sm % 9 == 0) cout<<"Yes\n";
    else cout<<"No\n";

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using pll = pair<ll,ll>;
const ll INF64 = 1LL << 60;
const int INF = (1 << 29);

int main(){
    int h,w,n; cin >> h >> w >> n;
    vector<int> a(n+1);
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }

    int now_i = 1;
    int cnt_i = a[1];
    int ans[h][w];
    rep(i,h){
        if(i%2==0){
            rep(j,w){
                ans[i][j] = now_i;
                cnt_i--;
                if(cnt_i==0){
                    now_i++;
                    cnt_i = a[now_i];
                }
            }
        }else{
            for(int j=w-1; j>=0; j--){
                ans[i][j] = now_i;
                cnt_i--;
                if(cnt_i==0){
                    now_i++;
                    cnt_i = a[now_i];
                }
            }
        }
    }

    rep(i,h){
        rep(j,w){
            cout << ans[i][j];
            if(j<w-1) cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 3680
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

void solve(){
	int A, B, X;
	cin >> A >> B >> X;

	if(A <= X && X <= A+B){
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)

template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }


#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;


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

  cin >> n >> s >> q;
  vector<set<int>> vs(30);

  REP(i, s.length()) {
    vs[s[i] - 'a'].insert(i + 1);
  }

  REP(i, q) {
    int t;
    cin >> t;
    if(t == 1) {
      int p;
      char c;
      cin >> p >> c;
      int pp = s[p - 1] - 'a';
      s[p - 1] = c;

      vs[pp].erase(p);
      vs[c - 'a'].insert(p);
    } else {
      int l, r;
      cin >> l >> r;

      int c = 0;
      REP(j, 26) {
        auto lit = vs[j].lower_bound(l);
        auto rit = vs[j].upper_bound(r);

        if(lit != vs[j].end() && lit != rit) {
          c++;
        }
      }

      cout << c << endl;
    }
  }
}


Measured memory_bytes: 27248
//  Created by conan1024hao on 2019/11/23.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;
    cin>>n;
    vector<ll>a(n+1);
    for(ll i=1;i<=n;i++)
        cin>>a[i];
    vector<ll>l(n+2);
    vector<ll>r(n+2);
    vector<ll>m(n+2);
    sort(all(a));
    l[0]=0;
    r[n+1]=0;
    for(int i=0;i<n;i++){
        l[i+1]=GCD(l[i],a[i]);
    }
    for(int i=n;i>1;i--){
        r[i]=GCD(r[i+1],a[i]);
    }
    for(int i=1;i<=n;i++){
        m[i]=GCD(l[i],r[i+1]);
    }
    ll ans=-1;
    for(int i=1;i<=n;i++){
        chmax(ans,m[i]);
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  double t,x,ans;
  cin >> t >> x;
  cout << t/x << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
	int n;
	cin>>n;
	cout<<"?";
	for(int i=0; i<n; i++){
		cout<<" "<<i+1;
	}
	cout<<endl;
	string res;
	cin>>res;
	bool myon=0;
	if(res=="Red") myon=1;
	int l=0, r=n;
	while(r-l>1){
		int m=(l+r)/2;
		cout<<"?";
		for(int i=0; i<n-m; i++){
			cout<<" "<<i+1;
		}
		for(int i=0; i<m; i++){
			cout<<" "<<2*n-m+1+i;
		}
		cout<<endl;
		cin>>res;
		if(myon){
			if(res=="Red") l=m;
			else r=m;
		}else{
			if(res=="Red") r=m;
			else l=m;
		}
	}
	string ans;
	for(int i=0; i<2*n; i++) ans+='.';
	if(myon) ans[n-l-1]='R', ans[2*n-l-1]='B';
	else ans[n-l-1]='B', ans[2*n-l-1]='R';
	for(int i=0; i<2*n; i++){
		if(i==n-l-1 || i==2*n-l-1) continue;
		if(n-l<=i && i<2*n-l-1){
			cout<<"?";
			for(int j=n-l-1; j<=2*n-l-1; j++){
				if(j==i) continue;
				cout<<" "<<j+1;
			}
			cout<<endl;
			cin>>res;
			if(res=="Red") ans[i]='B';
			else ans[i]='R';
		}else{
			cout<<"?";
			for(int j=0; j<2*n; j++){
				if(j>n-l-1 && j<2*n-l-1) continue;
				if(j==i) continue;
				cout<<" "<<j+1;
			}
			cout<<endl;
			cin>>res;
			if(res=="Red") ans[i]='B';
			else ans[i]='R';
		}
	}
	cout<<"! "<<ans<<endl;
	return 0;
}

Measured memory_bytes: 724
from collections import deque
n=int(input())
a=list(map(int,input().split()))
s=deque()
for i in range(n):
    if i%2==0:
        s.append(str(a[i]))
    else:
        s.appendleft(str(a[i]))
s=list(s)
if n%2==1:
    s=s[::-1]
print(' '.join(s))

Measured memory_bytes: 39584
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100010];

int main() {
    int N; cin >> N;
    vector<long long> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];
    
    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;
    
    // 初期条件
    dp[0] = 0;
    
    // ループ
    for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    
    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    T = str(input().strip())

    if not set(T) <= set(S):
        return -1

    n = len(S)
    d = defaultdict(list)
    for i, s in enumerate(S, start=1):
        d[s].append(i)

    cnt = 0
    pos = 0
    for t in T:
        if pos >= d[t][-1]:
            cnt += 1
            pos = d[t][0]
        else:
            left = 0
            right = len(d[t])
            while left < right:
                mid = (left + right) // 2
                np = d[t][mid]
                if np <= pos:
                    left = mid + 1
                else:
                    right = mid
            pos = d[t][left]

    return n * cnt + pos


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 7924