akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    trace!(n);
    let xs: Vec<i64> = (0..n).map(|_| sc.cin()).collect();
    let ys: Vec<i64> = (0..n).map(|_| sc.cin()).collect();

    if xs.iter().sum::<i64>() < ys.iter().sum() {
        put!(-1);
        return;
    }

    let mut ds = vec![];
    // let mut is = vec![];
    let mut ans = 0;
    let mut is = 0;

    for i in 0..n {
        if xs[i] == ys[i] {
            continue;
        } else if xs[i] > ys[i] {
            ds.push(xs[i] - ys[i]);
        } else {
            ans += 1;
            is += ys[i] - xs[i];
            // is.push(ys[i] - xs[i]);
        }
    }
    ds.sort(); ds.reverse();
    for i in 0..ds.len() {
        if is <= 0 {
            break
        }
        ans += 1;
        is -= ds[i];
    }

    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 12656
#include<iostream>

using namespace std;

const int N=2e5+10;

int a[N];
long long res=0;

int main()
{
	int x,y,n;
	cin>>n>>x;
	for(int i=1;i<n;i++)
	{
		scanf("%d",&y);
		if(y<x) res+=x-y;
		else x=y;
	}
	cout<< res <<endl;
	return 0; 
}

Measured memory_bytes: 3740
#include<stdio.h>

int main(){
   int X,Y,Z;
   int tmp;

   scanf("%d %d %d",&X,&Y,&Z);
   tmp = X;
   X = Y;
   Y = tmp;
   tmp = X;
   X = Z;
   Z = tmp;

   printf("%d %d %d\n",X,Y,Z);

   return 0;
}
   

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    for(int i=1;i<S.length();i++){
        if(S[i-1] != S[i]) ans++;
    }
    cout << ans+1 << endl;
    return 0;
}

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


int main(void){

int z,i,j,r;

int A,B,C;

r=0;

scanf("%d%d%d", &A,&B,&C);

if(A==B){r=r+1;}
if(A==C){r=r+1;}
if(C==B){r=r+1;}

if(r==1){

printf("Yes");


}else{

printf("No");

}



}




Measured memory_bytes: 128
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    string s;cin >> s;
    auto c = [&](ll x){
        bool ok = true;
        ll cnt = 0;
        rrep(i,n, 0){
            if(s[i] - '0' == x % 10){
                x /= 10;
                cnt++;
            }
        }

        return cnt >= 3;
    };
    ll ans = 0;
    rep(i,0,1000){
        if(c(i))ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define N 200005
#define LL long long
#define mod 1000000007
using namespace std;
 
struct team{
	int p,v;
	friend bool inline operator < (team a,team b){
		return a.v<b.v;
	}
}Tm[N];
 
struct T_node{
	int l,r;
	LL s,t1,t2;
};
 
struct sg{
	int l,r;
	friend bool inline operator < (sg a,sg b){
		if(a.r==b.r) return a.l<b.l;
		return a.r<b.r;
	}
}a[N];
 
int n,mx[N],mn[N],flag=1;
 
LL inline pw(LL x,LL y){
	LL ret=1,tmp=x;
	while(y){
		if(y&1) ret=ret*tmp%mod;
		y>>=1,tmp=tmp*tmp%mod;
	}
	return ret;
}
 
struct segment_tree{
	T_node p[N<<3];
	void inline pushdown(int x){
		if(p[x].t1==1&&p[x].t2==0) return;
		int T1=p[x].t1,T2=p[x].t2,ls=x<<1,rs=x<<1|1;
		p[x].t1=1,p[x].t2=0;
		(p[ls].s*=T1)%=mod,(p[ls].t1*=T1)%=mod,(p[ls].t2*=T1)%=mod;
		(p[ls].s+=1LL*T2*(p[ls].r-p[ls].l+1))%=mod,(p[ls].t2+=T2)%=mod;
		(p[rs].s*=T1)%=mod,(p[rs].t1*=T1)%=mod,(p[rs].t2*=T1)%=mod;
		(p[rs].s+=1LL*T2*(p[rs].r-p[rs].l+1))%=mod,(p[rs].t2+=T2)%=mod;
	}	
	void inline build(int x,int l,int r){
		p[x].l=l,p[x].r=r,p[x].t1=1;
		if(l==r) return;
		int mid=(l+r)>>1;
		build(x<<1,l,mid),build(x<<1|1,mid+1,r);	
	}
	void inline modify(int x,int l,int r,int opt,int v){
		int L=p[x].l,R=p[x].r;
		pushdown(x);
		if(l==L&&r==R){
			if(opt==2) (p[x].s+=1LL*v*(p[x].r-p[x].l+1))%=mod,(p[x].t2+=v)%=mod;
			else (p[x].s*=v)%=mod,(p[x].t1*=v)%=mod,(p[x].t2*=v)%=mod;
			return;
		}
		int mid=(L+R)>>1;
		if(r<=mid) modify(x<<1,l,r,opt,v);
		else if(l>mid) modify(x<<1|1,l,r,opt,v);
		else modify(x<<1,l,mid,opt,v),modify(x<<1|1,mid+1,r,opt,v);
		p[x].s=p[x<<1].s+p[x<<1|1].s;
	}
	LL inline query(int x,int pos){
		pushdown(x);
		if(p[x].l==p[x].r) return p[x].s;
		int mid=(p[x].l+p[x].r)>>1;
		if(pos<=mid) return query(x<<1,pos);
		return query(x<<1|1,pos);
	}
}T;
 
void inline solve(){
	sort(a+1,a+n+1),T.build(1,1,n);
	for(int i=1;i<=n;i++){
		int l=a[i].l,r=a[i].r;
		if(flag&&l==1) flag=0,T.modify(1,l,r,2,pw(2,i-1));
		else if(!flag){
			LL tmp=(l==1)?pw(2,i-1):T.query(1,l-1);
			T.modify(1,l,r,2,tmp);
			if(l!=1) T.modify(1,1,l-1,1,2);
		}
	}
	printf("%lld\n",T.query(1,n));
}
 
int inline ckmx(int p){
	int l=1,r=p,mid;
	while(l<r){
		mid=(l+r)>>1;
		if(mx[mid]>=Tm[p].p) r=mid;
		else l=mid+1;
	}
	return l;
}
 
int inline ckmn(int p){
	int l=p,r=n,mid;
	while(l+1<r){
		mid=(l+r)>>1;
		if(mn[mid]<=Tm[p].p) l=mid;
		else r=mid-1;
	}
	return (mn[r]<=Tm[p].p)?r:l; 
}
 
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&Tm[i].p,&Tm[i].v);
	sort(Tm+1,Tm+n+1),mx[0]=0,mn[n+1]=0x3f3f3f3f;
	for(int i=1;i<=n;i++) mx[i]=max(mx[i-1],Tm[i].p);
	for(int i=n;i;i--) mn[i]=min(mn[i+1],Tm[i].p);
	for(int i=1;i<=n;i++) a[i].l=ckmx(i),a[i].r=ckmn(i);
	
	solve();
}

Measured memory_bytes: 40576
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

const int DAT_SIZE=(1<<18)-1;

ll data[DAT_SIZE],datb[DAT_SIZE];

void add(int a,int b,int x,int k,int l,int r){
  if(a<=l&&r<=b){
    data[k]+=x;
  }
  else if(l<b&&a<r){
    datb[k]+=(min(b,r)-max(a,l))*x;
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
  }
}

//[a,b),[l,r)
ll sum(int a,int b,int k,int l,int r){
  if(b<=l||r<=a){
    return 0;
  }
  else if(a<=l&&r<=b){
    return data[k]*(r-l)+datb[k];
  }
  else{
    ll res=(min(b,r)-max(a,l))*data[k];
    res+=sum(a,b,k*2+1,l,(l+r)/2);
    res+=sum(a,b,k*2+2,(l+r)/2,r);
    return res;
  }
}


int main(){
  int n,m;
  cin>>n>>m;
  std::vector<int> v[m+1];
  int a[n+1]={};
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i>0) v[a[i]].push_back(a[i-1]);
  }

  ll ans=0;
  for(int i=1;i<n;i++){
    if((a[i]-a[i-1]+m)%m==1) ans++;
    else{
      if(a[i-1]<a[i]) add(a[i-1]+2,a[i]+1,1,0,0,m+1);
      else{
        if(a[i-1]+2<=m) add(a[i-1]+2,m+1,1,0,0,m+1);
        if(a[i-1]!=m) add(1,a[i]+1,1,0,0,m+1);
        else add(2,a[i]+1,1,0,0,m+1);
      }
    }
  }

  /*for(int i=1;i<=m;i++){
    cout<<sum(i,i+1,0,0,m+1)<<endl;
  }*/

  ll tmp=0;
  for(int i=1;i<n;i++){
    if((a[i]-a[i-1]+m)%m==1) continue;
    tmp+=min((a[i]-a[i-1]+m)%m,a[i]);
  }

  ll res=tmp;
  for(int i=2;i<=m;i++){
    ll minus=sum(i,i+1,0,0,m+1);
    ll plus=0;
    int two=i-1;
    for(int j=0;j<v[two].size();j++){
      if((two-v[two][j]+m)%m==1) continue;
      plus+=(two-v[two][j]+m)%m-1;
    }
    tmp=tmp+plus-minus;
    //cout<<i<<" "<<plus<<" "<<minus<<" "<<tmp<<endl;
    res=min(res,tmp);
  }
  ans=ans+res;
  cout<<ans<<endl;

  return 0;
}


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

int main(){
  int n;
  bool check = false;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    string c;
    cin >> c;
    if(c == "Y"){
      check = true;
    }
  }
  if(check == true){
	cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}
      


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int H,W;
  cin>>H>>W;
  vector<vector<char>> data(H,vector<char>(W));

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
          cin>>data.at(i).at(j);
    }
  }

    for(int i=0;i<H;i++){
       for(int j=0;j<W;j++){
          char count='0';
            if(data.at(i).at(j)=='.'){
                for(int n=-1;n<2;n++){
                    for(int m=-1;m<2;m++){
                      if(i+n>=0&&j+m>=0&&i+n<H&&j+m<W){                        
                         if(data.at(i+n).at(j+m)=='#'){
                            if(count=='0'){
                                count='1';
                            }else if(count=='1'){
                                count='2';
                            }else if(count=='2'){
                                count='3';
                            }else if(count=='3'){
                                count='4';
                            }else if(count=='4'){
                                count='5';
                            }else if(count=='5'){
                                count='6';
                            }else if(count=='6'){
                                count='7';
                            }else if(count=='7'){
                                count='8';
                            }
                         }      
                      }
                    }
                }
             data.at(i).at(j)=count; 
            }
        }
    }

	for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
          cout<<data.at(i).at(j);
      }
      cout<<endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
#include<utility>
using namespace std;
typedef long long ll;

int main(){
  int n;
  int a[2][120];
  cin >> n;
  for(int i=0; i<2; i++){
    for(int j=0; j<n; j++){
      cin >> a[i][j];
    }
  }

  int m=-1;
  for(int i=0; i<n; i++){
    int tmp = 0;
    for(int j=0; j<n; j++){
      if(j < i) tmp += a[0][j];
      else if(j>i) tmp += a[1][j];
      else if(j==i) tmp += a[0][j] + a[1][j];
    }
    if(tmp>m) m=tmp;
  }
  cout << m << endl;
  return 0;
}


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

int main(){
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d;
    cin >> n;

    ll tmp = min(q*4,h*2);
    ll min1 = min(tmp,s);
    ll min2 = min(min1*2,d);

    ll ans = (n/2)*min2 + ((n%2==0) ? 0 : min1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
      
    // receive a number
    string S;
    cin >> S;
    
    int result;
    string signs;
    
    for (int i = 0; i < (1 << 3); i++) {// 0 and 1 means + and -, respectively.
        result = (int)(S.at(0) - '0');
        signs = "";
        
        for (int j = 0; j < 3; j++) {
            if ((i >> j) & 1) {
                result -= (int)(S.at(j + 1) - '0');
                signs.push_back('-');
                
            } else {
                result += (int)(S.at(j + 1) - '0');
                signs.push_back('+');
            }
        }
        if (result == 7) {
            // show the correct equation
            for (int k = 0; k < 3; k++) {
                cout << S.at(k) << signs.at(k);
            }
            cout << S.at(3) << "=7" << endl;
            return 0;
        }
    }
    
    return 0;
}


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

using namespace std;

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

    int n;cin>>n;
    int acnt=0,ucnt=0,flag=1;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        if(s=="A") acnt++;
        else ucnt++;
        
        if(ucnt>acnt) flag=0;
    }
    if(acnt!=ucnt) flag=0;

    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

typedef struct __card {
	int number;
	char suit;
} card_t;

void bubble_sort( card_t * p, int size );
void selection_sort( card_t * p, int size );
void print_array( card_t * p, int size );
bool is_stable( card_t * b, card_t * s, int size );

int main() {
	int num;
	char str[2];
	card_t b_card[36];
	card_t s_card[36];
	cin >> num;

	for ( int i = 0 ; i < num ; i++ ) {
		cin >> b_card[i].suit >> b_card[i].number;
		s_card[i] = b_card[i];
	}

	bubble_sort( b_card, num );
	selection_sort( s_card, num );

	print_array( b_card, num );
	cout << "Stable" << endl;
	print_array( s_card, num );
	if ( is_stable( b_card, s_card, num ) ) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}
	//cout << &b_card << ":" << &s_card << endl; 

	return 0;
}

void bubble_sort( card_t * p, int size ) {
	for ( int i = 0 ; i < size ; i++ ) {
		for ( int j = size-1 ; j >= i+1 ; j-- ) {
			if ( p[j-1].number > p[j].number ) {
				card_t tmp;
				tmp = p[j-1];
				p[j-1] = p[j];
				p[j] = tmp;
			}
		}
	}	
}

void selection_sort( card_t * p, int size ) {
	int minj = 0;
	int i = 0, j = 0;
	for ( i = 0 ; i < size ; i++ ) {
		minj = i;
		for ( j = i ; j < size ; j++ ) {
			if ( p[minj].number > p[j].number ) {
				minj = j;
			}
		}
		card_t tmp;
		tmp = p[i];
		p[i] = p[minj];
		p[minj] = tmp;
	}
}

void print_array( card_t * p, int size ) {
	for ( int i = 0 ; i < size ; i++ ) {
		if ( i == size-1 ) {
			cout << p[i].suit << p[i].number << endl;
		} else {
			cout << p[i].suit << p[i].number  << " "; 
		}
	}
}

bool is_stable( card_t * b, card_t * s, int size ) {
	for ( int i = 0 ; i < size ; i++ ) {
		if ( b[i].suit != s[i].suit ) {
			return false;
		}
	}
	return true;
}



Measured memory_bytes: 3096
#include<stdio.h>
int main(void)
{
	long long a,b,yaku,bai,c,box;
	int i;
	while(scanf("%ld %ld",&a,&b)!=EOF){
		for(i=1;i<=b;i++){
			if(a*i%b==0){
				bai=a*i;
				break;
			}
		}
		if(a<b){
			box=a;
			a=b;
			b=box;
		}
		while(a%b>0){
			c=a%b;
			a=b;
			b=c;
		}
		yaku=b;
		printf("%ld %ld\n",yaku,bai);
	}
	return 0;
}


Measured memory_bytes: 2060
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

template<typename T>
struct BIT {
	int n;
	vector<T>dat;
	BIT(int n = 0) {
		initialize(n);
	}
	void initialize(int temp) {
		n = temp;
		dat.resize(n);
		rep(i, 0, n)dat[i] = 0;
	}
	T sum(int i) {
		T s = 0;
		while (i >= 0) {
			s += dat[i];
			i = (i & (i + 1)) - 1;
		}
		return s;
	}
	T sum_between(int i, int j) {
		if (i > j)return 0;
		return sum(j) - sum(i - 1);
	}
	void plus(int i, T x) {
		while (i < n) {
			dat[i] += x;
			i |= i + 1;
		}
	}
	int lower_bound(T x) {
		if (sum(n - 1) < x)return -1;
		else if (sum(0) >= x)return 0;
		int ng = 0, ok = n - 1;
		while (ok - ng > 1) {
			int mid = (ok + ng) / 2;
			if (sum(mid) >= x)ok = mid;
			else ng = mid;
		}
		return ok;
	}
};
ll dp[2020][2020];
vector<pair<char,int>>v(4040);
map<pair<char, int>, int>mp;
int cntw[4040][2020],cntb[4040][2020];


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

	int N;
	cin >> N;
	for (int i = 0; i < 2 * N; i++) {
		cin >> v[i].first >> v[i].second;
		mp[{v[i].first,v[i].second}] = i;
	}
	for (int i = 0; i < 2020; i++) {
		for (int j = 0; j < 2020; j++) {
			dp[i][j] = inf;
		}
	}

	BIT<ll>bitw(2020), bitb(2020);
	for (int i = 2 * N - 1; i >= 0; i--) {
		for (int j = 1; j <= N; j++) {
			cntw[i][j] = bitw.sum_between(0,j);
			cntb[i][j] = bitb.sum_between(0,j);
		}
		if (v[i].first == 'W')bitw.plus(v[i].second,1);
		else bitb.plus(v[i].second,1);
	}
	
	dp[0][0] = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++){
			ll cost1 = cntw[mp[{'W',i+1}]][i] + cntb[mp[{'W',i+1}]][j];
			ll cost2 = cntw[mp[{'B',j+1}]][i] + cntb[mp[{'B',j+1}]][j];
			dp[i+1][j] = min(dp[i+1][j],dp[i][j]+cost1);
			dp[i][j+1] = min(dp[i][j+1],dp[i][j]+cost2);
		}
	}
	puts(dp[N][N]);

	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  int k,a,b;
  cin >> k >> a >> b;

  FOR(i,a,b+1){
    if(i%k==0){
      cout << "OK" << endl;
      return(0);
    }
  }
  cout << "NG" << endl;
  

}



Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    string st;
    cin>>st;
    int ans=0;
    int l=0;
    REP(i,st.size()){
        if(st[i]!='A'&&st[i]!='T'&&st[i]!='G'&&st[i]!='C'){
            chmax(ans,i-l);
            l=i+1;
        }
    }
    chmax(ans,(int)st.size()-l);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(raw_input())
s=raw_input()
stack=[]
stidx=[]
ins=[]
for i in xrange(n):
    if s[i]=="(":
        stack.append(s[i])
        stidx.append(i)
    else:
        if len(stack)==0:
            ins.append(i)
        else:
            stack.pop()
            stidx.pop()
tmp=list(s)
for i in stidx:
    tmp[n-1]=tmp[n-1]+")"
for i in xrange(len(ins)):
    tmp[0]="("+tmp[0]
print "".join(tmp)


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  ll sum = 0;
  vector<int> a(n);
  rep(i, n){
    int in;
    cin >> in;
    sum += in;
    a.at(i) = in;
  }
  ll l = 0, r = sum;
  ll ans = 1e18;
  rep(i, n-1){
    l += a.at(i);
    r -= a.at(i);
    // cerr << l << " " << r << endl;
    ans = min(ans, abs(l-r));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <map>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str, s = "10";
	int64_t n;
	long int nmax = 0, sum = 0;
	cin >> n;
	str = to_string(n);
	FOR(i, 0, str.size()) {
		FOR(j, 0, str.size()) {
			sum += str[j] - '0';
		}
		nmax = max(nmax, sum);
		if (str.size() - i > 1) {
			n -= stoll(s);
			str = to_string(n);
			str[str.size() - i - 1] = '9';
			n = stoll(str);
			s += '0';
		}
		sum = 0;
	}
	FOR(i, 0, str.size()) {
		sum += str[i] - '0';
	}
	nmax = max(nmax, sum);
	cout << nmax;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
	int main(){
		int N,R,hasil;
		
		scanf ("%d %d",&N,&R);
		if (N<10){
			hasil = 100*(10-N);
			hasil = R + hasil;
		}
		else {
			hasil= R;
		}
		printf ("%d", hasil);
	}


Measured memory_bytes: 1700
n=int(input())
l=[int(input()) for i in range(n)]
ans=0
for i in range(len(l)-1):
    ans+=l[i]//2
    l[i]=l[i]%2
    tmp=min(l[i],l[i+1])
    ans+=tmp
    l[i+1]-=tmp
ans+=l[-1]//2
print(ans)

Measured memory_bytes: 7072
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	int a[m], b[m], t, t2;
	for (int i = 0; i < m; i++){
		scanf("%d %d", &a[i], &t);
		b[i] = 0;
		for (int j = 0; j < t; j++){
			scanf("%d", &t2);
			b[i] |= (1 << (t2 - 1));
		}
	}
	int dp[m + 1][1 << n];
	for (int i = 0; i <= m; i++){
		for (int j = 0; j < (1 << n); j++){
			dp[i][j] = 2147483647;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < m; i++){
		for (int j = 0; j < (1 << n); j++){
			if (dp[i][j] == 2147483647) continue;
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			int temp = (j | b[i]);
			dp[i + 1][temp] = min(dp[i + 1][temp], dp[i][j] + a[i]);
		}
	}
	if (dp[m][(1 << n) - 1] == 2147483647) dp[m][(1 << n) - 1] = -1;
	printf("%d\n", dp[m][(1 << n) - 1]);
}

Measured memory_bytes: 16128
#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])
//我一直以为这题很难，直到我看见了n<=5k
int n;
ll mi[5555][5555]; pii g[5555];
bool cmp(pii a,pii b) {return a.fi+a.se<b.fi+b.se;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&g[i].fi,&g[i].se);
	sort(g+1,g+1+n,cmp);
	memset(mi,127/3,sizeof mi);
	mi[0][0]=0;
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<=n;++j)
		{
			mi[i][j]=min(mi[i][j],mi[i-1][j]);
			if(mi[i-1][j]<=g[i].fi)
				mi[i][j+1]=min(mi[i][j+1],mi[i-1][j]+g[i].se);
		}
	}
	ll big=1e17;
	for(int i=n;i>=0;--i)
		if(mi[n][i]<=big)
		{
			printf("%d\n",i);
			return 0;
		}
}


Measured memory_bytes: 241408
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const ll MOD = 1000000007;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int n, m; cin >> n >> m;
    vector<bool> broken(n);

    rep(i, m) {
        int a; cin >> a;
        broken[a] = true;
    }

    vector<ll> dp(n + 1, 0);

    dp[0] = 1;
    if (broken[1]) dp[1] = 0;
    else dp[1] = 1;

    for (int i=2;i<=n;++i) {
        if (broken[i]) dp[i] = 0;
        else dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
    }

    cout << (dp[n] % MOD) << endl;
}

Measured memory_bytes: 1024
n, m = map(int,input().split())
cnt = [0]*(m+1)
for _ in range(n):
    a = list(map(int,input().split()))
    for i in range(a[0]):
        cnt[a[i+1]] += 1
ans = 0
for i in cnt:
    if i == n:
        ans += 1
print(ans)

Measured memory_bytes: 3060
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//long.Parseはstringをlongに変換。
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] a = new long[n];
    long[] b = new long[n];
    string answer = "";

    for(long i = 0; i < n; i++)
    {
      a[i] += 20000*i+1;
      b[n-1-i] += 20000*i+1;
      a[nums[i]-1] += i;
    }
/*
    answer = a[0].ToString();
    for(long i = 1; i < n; i++)
    {
      answer += " "+a[i].ToString();
    }
    Console.WriteLine(answer);

    Console.WriteLine(string.Join(" ", a));

    answer = b[0].ToString();
    for(long i = 1; i < n; i++)
    {
      answer += " "+b[i].ToString();
    }
    Console.WriteLine(answer);
    */
    Console.WriteLine(string.Join(" ", a));
    Console.WriteLine(string.Join(" ", b));
	}
}

Measured memory_bytes: 19296
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define vc vector
int n,a[1<<18];
map<int,int>M;
vector<int>edge[(1<<18)];
priority_queue<P>que;
int main(){
	scanf("%d",&n);
	rep(i,1<<n){
		scanf("%d",&a[i]);
		M[-a[i]]++;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<(1<<i);j++){
			edge[j].pb(j+(1<<i));
		}
	}
	que.push(mp(edge[0].size(),0));
	for(auto it:M){
		if(que.size() < it.sc){
			puts("No");
			return 0;
		}
		vector<P>nxt;
		rep(x,it.sc){
			P p = que.top() ; que.pop();
			for(auto u:edge[p.sc]) nxt.pb(P(edge[u].size(),u));
		}
		for(auto a:nxt) que.push(a);
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 25084
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val s = (0 until m).map {
        (0 until sc.next().toInt()).map { sc.next().toInt() - 1 }
    }
    val p = (0 until m).map { sc.next().toInt() }
    println(problem128c(n, m, s, p))
}

fun problem128c(
    n: Int,
    m: Int,
    s: List<List<Int>>,
    p: List<Int>
): Int {
    /**
     * 整数を「どのアイテムを選ぶのか」を表すListに変換
     * @param bit 集合を表す整数
     * @param n 何個のものについて考えているか
     */
    fun integerToList(bit: Int, n:Int): List<Int> {
        val s = mutableListOf<Int>()
        for(i in 0 until n) {
            if (bit and (1 shl i) != 0) {
                s.add(i)
            }
        }
        return s
    }

    var res = 0
    var exist = false
    var bit = 0
    while(bit < (1 shl n)) {
        val selected = integerToList(bit, n)
        var ok = true
        for (i in 0 until m) {
            val pi = p[i]
            var count = 0
            for (j in s[i]) {
                if (selected.contains(j)) count++
            }
            if (count % 2 != pi) ok = false
        }
        if (ok) res++
        bit++
    }
    return res
}

Measured memory_bytes: 32284
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

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

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

    vector<P> G[N];
    for(int i=0; i<N-1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u--;v--;
        G[u].push_back(P(v, w));
        G[v].push_back(P(u, w));
    }

    int ans[N];
    fill(ans, ans+N, -1);

    queue<tuple<int, int, int>>q;
    q.push(make_tuple(0, 0, -1));
    while(!q.empty()){
        tuple<int, int, int> tp = q.front();
        int now = get<0>(tp);
        int d = get<1>(tp);
        int p = get<2>(tp);
        // cout << now << " " << d << " " << p << endl;
        q.pop();

        if(d % 2 ==0) ans[now] = 0;
        for(auto e: G[now]){
            int next = e.first;
            int adc = e.second;
            if(next == p) continue;
            q.push(make_tuple(next, d+adc, now));
        }
    }

    for(int i=0; i<N; i++){
        if(ans[i] == -1) ans[i] = 1;
        cout << ans[i] << endl;
    }

    return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll a,b,k;
    cin >> a >> b >> k;
    for(int i=min(a,b);i>=1;i--){
        if(a%i==0 && b%i==0)k--;
        if(k==0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int INF = 1e9;

int n, k;
const int nx = 1e5+5;
ll ac[nx][2];
ll dp[105][nx];
ll knapsack(ll i, ll w){
	if(i == n) return 0;
	if(w>k) return -INF;
	if(dp[i][w] != -1) return dp[i][w];
	ll& ans = dp[i][w];
	ans = max(ans, knapsack(i+1,w));
	if(w+ac[i][0]<=k) ans = max(knapsack(i+1,w+ac[i][0])+ac[i][1],ans);
	return ans;
}
int main(){

	cin>>n>>k;
	memset(dp, -1, sizeof dp);
	for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1];
	cout<<knapsack(0,0)<<"\n";
}


Measured memory_bytes: 82304
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	Vec a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll k;
	cin >> k;
	co(a[--k]);

	return 0;
}


Measured memory_bytes: 256
s = str(input())
n = len(s)
ni = int((n-1)/2)
np = int((n+1)/2)
si = s[0:ni]
sp = s[np:]
if s == s[::-1]:
  if si == si[::-1]:
    if sp == sp[::-1]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

#define MAX 100001
#define INFTY 10000000

typedef struct{
  int prev;
  int next;
  int cost;
} Edge;

Edge G[500000];
int d[MAX];

void Dijkstra(int,int);

int main(void){
  int i, j, k, n, v, u, c;
  int count=0;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    for(j=0; j<k; j++){
      G[count].prev = u;
      scanf("%d%d", &G[count].next, &G[count].cost);
      count++;
    }
  }

  Dijkstra(n,count);

  

  return 0;
}

void Dijkstra(int n, int count){
  int i, min = 1;
  int d[MAX];

  d[0] = 0;
  for(i=1; i<n; i++){
    d[i] = INFTY;
  }

  while(min != 0){
    min = 0;

    for(i=0; i<count; i++){
      if(d[G[i].prev] + G[i].cost < d[G[i].next]){
        d[G[i].next] = d[G[i].prev] + G[i].cost;
        min = 1;
      }
    }
  }

  for(i=0; i<n; i++) printf("%d %d\n", i, d[i]);

  return;
}



Measured memory_bytes: 7584
fun main(args: Array<String>) {
    val (A, B) = listOfInt()
    for (n in 1 .. 1101) {
        val t1 = n *  8 / 100
        val t2 = n * 10 / 100
        if (t1 == A && t2 == B) {
            println(n)
            return
        }
    }
    println(-1)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)


Measured memory_bytes: 38068
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second 
using namespace std;
typedef pair<int,int> PII; 
typedef long long ll;
const int P = 1e9+7;
const int N = 2000010;
inline void add(int &x,int y){
	x=(x+y)%P;
}
int f[N],sum;
int ans,n;
int main(){
	scanf("%d",&n);
	f[0]=1;
	for(int i =0;i<=n;i++){
		int tmp  =sum;
		for(int j =1;j<=2;j++) if(i-j>=0) add(tmp,-f[i-j]);
		add(f[i],tmp);
		add(f[i+1],f[i]);
		if(i<n-1){
			add(ans,1ll*(n-1)*(n-1)%P*f[i]%P);
		} else if(i==n-1){
			add(ans,1ll*(n-1)*f[i]%P);
		}
		add(sum,f[i]);
	}
	add(ans,f[n]);
	for(int i = n-1;i>0;i--){
		add(ans,1ll*f[i-1]*i%P);
	}
	cout<<ans<<endl;
	return 0;
}



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

int main() {
    int n; cin >> n;
    if(n%10 == 3){
        cout << "bon" << endl;
    }
    else if(n%10 == 0 or n%10 == 1 or n%10 == 6 or n%10 == 8){
        cout << "pon" << endl;
    }
    else{
        cout << "hon" << endl;
    }
}



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

int main(){
  int N;
  cin >> N;
  vector<int> type(N);
  vector<long long> sort_t(N);
  for(int i=0;i<N;i++){
    cin >> type.at(i);
    type.at(i)--;
    sort_t.at(type.at(i))++;
  }
  
  long long Total=0;
  for(int i=0;i<N;i++){
    Total += (sort_t.at(i)*(sort_t.at(i)-1) / 2);
    
  }
  for(int i=0;i<N;i++){
    cout << Total-sort_t.at(type.at(i))+1 << endl;
  }
  
}

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

int main()
{
 	string s;
  	string t;
  	cin>>s;
  	cin>>t;
  	int i;
  	int count = 0;
  	for(i = 0; i<3; i++)
    {
     	if(s[i] == t[i])
        	count++;
    }
  cout<<count;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
    int N, A, B; cin >> N >>A >> B;
    if((B-A)%2){
        cout << "Borys" << endl;
    }else{
        cout << "Alice" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ll long long
#define ld long double
const ll M =1000000007;
const int N = 10000003;
using namespace std;
const int mod = 1000000007;
ll fac[400009], mx = 2e5, inv[400009];
ll fp(ll b, ll p)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0) return fp((b * b) % mod, p / 2);
	else return (b * fp((b * b) % mod, p / 2) % mod) % mod;
}
ll ncr(ll n, ll r)
{
	ll ans = fac[n];
	ans = (ans*inv[r]) % mod;
	ans = (ans*inv[n - r]) % mod;
	return ans;
}
int main()
{
	Amr_Abdelazim
		fac[0] = 1;
	inv[0] = 1;
	for (int i = 1; i <= mx; i++)
	{
		fac[i] = (fac[i - 1] * i) % mod;
		inv[i] = fp(fac[i], mod - 2);
	}
	ll n, k;
	cin >> n >> k;
	vector<ll>v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	sort(v.begin(), v.end());
	ll smx = 0;
	ll smn = 0;
	ll ans = 0;
	for (int i = 0;i< n; i++){
		if (i >= k - 1)smx = ncr(i, k - 1);
		else smx = 0;
		if (n - i - 1 >= k - 1)smn = ncr(n - i - 1, k - 1);
		else smn = 0;
		ans += (v[i] % mod * (smx - smn) % mod) % mod;
		ans = ans%M;
	}
	cout << ans << "\n";
		return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
 
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 1000000000000000007
 
using namespace std;
#define prime 1000000007
 
#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

int n, m, v[10] = {0,2,5,5,4,5,6,3,7,6};
pair<ii, int> dp[10100];
ii c[10];
vi ans;

pair<ii, int> f(int at){
	if(at < 0) return {{-prime, -prime}, -prime};
	if(at == 0) return {{0, 0}, 0};
	if(dp[at] != mp(mp(-1, -1), -1)) return dp[at];
	pair<ii, int> res = {{-prime, -prime}, -prime};
	for (int i = 0; i < m; ++i){
        pair<ii, int> aux = f(at-c[i].ff);
        aux.ff.ff++;
        aux.ss = at-c[i].ff;
        aux.ff.ss = c[i].ss;
		if(aux > res){
			res = aux;
		}
	}
	return dp[at] = res;
}

int main(){
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i){
		int x;
		scanf("%d", &x);
		c[i] = {v[x], x};
	}
	sort(c, c+m);
	for (int i = 0; i <= n; ++i){
		dp[i] = {{-1, -1}, -1};
	}
	auto a = f(n);
	int at = n;
	while(at){
		ans.pb(dp[at].ff.ss);
		at = dp[at].ss;
	}
	if(a.ff.ff != (int)ans.size()) while(1);
	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());
	for(int l : ans) printf("%d", l);
	printf("\n");

	return 0;
}


Measured memory_bytes: 1024
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<iomanip>

#define all(v) (v).begin(),(v).end() 
#define rall(v) (v).rbegin(),(v).rend() 
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPE(i,n,s) for(int i=(s);i<(n);i++)

using namespace std;

int main(void){
	int n;
	stringstream ss;
	while(cin >> n && n){
		string str;
		cin >> str;
		stringstream ss;
		for(int i=0;i<n;i++){
			int cnt = 1;
			char bef = str[0];
			for(int j=1;j<str.size();j++){
				if(bef == str[j]){
					cnt++;
				}else{
					ss << cnt <<bef;
					cnt = 1;
					bef = str[j];
				}
			}
			ss << cnt << bef;
			str = ss.str();
			ss.str("");
		}
		cout << str << endl;
	}
	return 0;
/*
	11   11
	21    12
	1211    1121
	111221   122111
	312211    112213
	13112221   12221131
*/
}

Measured memory_bytes: 1384
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;


int main(){

    //時計回りと反時計回り、時計回りに途中まで行って戻るのとその反対の4パターンを調べる

    int n;
    ll c;
    cin >> n >> c;

    vector<pair<ll,ll>> sushi;

    rep(i,n){
        ll x,v;
        cin >> x >> v;

        sushi.pback(mpair(x,v));
    }

    vector<ll> clockwork(1);
    vector<ll> anticlockwork(1);
    vector<ll> clockwork_round(1);
    vector<ll> anticlockwork_round(1);

    ll ans = 0;
    ll move = 0;

    rep(i,n){
        clockwork.pback(clockwork[i] + (sushi[i].second - (sushi[i].first - move)));
        move = sushi[i].first;
        CERR << clockwork[i + 1] << " ";
    }
    CERR << endl;

    move = 0;

    rep(i,n){
        anticlockwork.pback(anticlockwork[i] + (sushi[n - 1 - i].second - (c - sushi[n - 1 - i].first - move)));
        move = c - sushi[n - 1 - i].first;
        CERR << anticlockwork[i + 1] << " ";
    }
    CERR << endl;

    move = 0;

    rep(i,n){
        clockwork_round.pback(clockwork_round[i] + (sushi[i].second - (sushi[i].first * 2 - move)));
        move = sushi[i].first * 2;

        CERR << clockwork_round[i + 1] << " "; 
    }
    CERR << endl;

    move = 0;

    rep(i,n){
        anticlockwork_round.pback(anticlockwork_round[i] + (sushi[n - 1 - i].second - ((c - sushi[n - 1 - i].first) * 2 - move)));
        move = (c - sushi[n - 1 - i].first) * 2;

        CERR << anticlockwork_round[i + 1] << " "; 
    }
    CERR << endl;

    vector<ll> clockwork_max(1);
    vector<ll> anticlockwork_max(1);

    rep(i,n){
        clockwork_max.pback(max(clockwork_max[i], clockwork[i + 1]));
        CERR << clockwork_max[i + 1] << " ";
    }
    CERR << endl;

    rep(i,n){
        anticlockwork_max.pback(max(anticlockwork_max[i], anticlockwork[i + 1]));
        CERR << anticlockwork_max[i + 1] << " ";
    }
    CERR << endl;

    rep(i,n + 1){
        ans = max(ans, clockwork_round[i] + anticlockwork_max[n - i]);
    }

    rep(i,n + 1){
        ans = max(ans, anticlockwork_round[i] + clockwork_max[n - i]);
    }

    /*
    sort(ALL(clockwork));

    ans = max(ans, clockwork[n]);

    sort(ALL(anticlockwork));

    ans = max(ans, anticlockwork[n]);

    */

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

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

typedef long long int int64;

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

void run(void){
  char s[201];
  scanf("%s",s);
  int n=0;
  while(s[n]!='\0') n++;
  int i;
  for(i=0;i<n;i++) s[i+n]=s[i];
  char t[101];
  scanf("%s",t);
  for(i=0;i<n;i++){
    int j;
    for(j=0;j<n;j++){
      if(t[j]!=s[i+j]) break;
    }
    if(j>=n){
      printf("Yes\n");
      return;
    }
  }
  printf("No\n");
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128