akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
int main(){
    ll n;cin>>n;
    vvi v(n,vi(6));
    rep(i,n)rep(j,6){
        ll a,b;cin>>a>>b;
        v[i][j]=a*60+b;
    }
    sort(all(v));
    ll ans=0;
    rep(i,1440)REP(j,i+1,1440){
        vi x,y;
        rep(k,n)if(v[k][2]<=i&&i<=v[k][3]&&v[k][4]<=j&&j<=v[k][5]){x.eb(v[k][0]);y.eb(v[k][1]);}
        sort(all(y));
        ll w=y.size()-1;
        for(int i=x.size()-1;i>=0;i--){
            while(w>=0){
                if(y[w]<x[i])break;
                w--;
            }
            chmax(ans,i-w);
        }
    }
    out(ans);
}


Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  map<int,int> ans;
  rep(i,n){
    int a;
    cin >> a;
    ans[--a] = i+1;
  }
  rep(i,n) cout << ans[i] << " ";
  cout << endl;
}


Measured memory_bytes: 5504
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
    long long a,b,n;
    cin >>n >>a >>b;

    if((a-b) % 2){
        long long move;
        long long remain;
        if(a-1 > n-b){
            move = n-b;
            move++;
            remain = n - (a+move);
        }else{
            move = a-1;
            move++;
            remain = (b-move) - 1;
        }
        printf("%lld\n", move + (remain/2));

    }else{
        printf("%lld\n", (b-a)/2);
    }

    return 0;
}

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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    ll N,X;
    cin >> N >> X;
    int m[N];
    for(ll i = 0; i < N; i++) {
        cin >> m[i];
        X -= m[i];
    }
    sort(m,m+N);
    cout << X/m[0]+N << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int di[100000];
int hi[100000];

#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main(){
  int n, h; scanf("%d%d", &n, &h);
  int i;
  int pos = 0;
  int hp  = h;
  int cnt = 0;

  for(i = 0; i < n - 1; i++)
    scanf("%d%d", di+i, hi+i);

  while(1){
    int mxv = -1;
    int memohp  = 0;
    int memopos = 0;

    // printf("pos: %d, hp: %d\n", pos, hp);

    while(1){
      if(mxv <= MIN(h - hp, hi[pos])){
	mxv     = MIN(h - hp, hi[pos]);
	memohp  = hp;
	memopos = pos;
      }

      if((hp -= di[pos]) > 0){
	++pos;
      }else{
	break;
      }

      if(pos == n - 1){
	printf("%d\n", cnt);
	return 0;
      }
    }

    pos = memopos;
    hp  = MIN(memohp + hi[pos], h);
    cnt++;
  }
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,K;
struct pl {
    int f[100005];
    friend pl operator * (const pl &a,const pl &b) {
	pl c;
	for(int i = 1 ; i <= N ; ++i) c.f[i] = a.f[b.f[i]];
	return c;
    }
    pl inv() {
	pl c;
	for(int i = 1 ; i <= N ; ++i) {
	    c.f[f[i]] = i;
	}
	return c;
    }
}p,q,iq,ip,s,res,t,ans;
void fpow(int c) {
    for(int i = 1 ; i <= N ; ++i) res.f[i] = i;
    t = s;
    while(c) {
	if(c & 1) res = res * t;
	t = t * t;
	c >>= 1;
    }
}
void Solve() {
    read(N);read(K);
    for(int i = 1 ; i <= N ; ++i) read(p.f[i]);
    for(int i = 1 ; i <= N ; ++i) read(q.f[i]);
    ip = p.inv();iq = q.inv();
    s = q * ip * iq * p;
    fpow((K - 1) / 6);
    int x = (K - 1) % 6;
    if(x == 0) {
	ans = res * p * res.inv();
    }
    else if(x == 1) {
	ans = res * q * res.inv();
    }
    else if(x == 2) {
	ans = res * q * ip * res.inv();
    }
    else if(x == 3) {
	res = res * q;
	ans = res * ip * res.inv();
    }
    else if(x == 4) {
	res = res * q * ip;
	ans = res * iq * res.inv();
    }
    else if(x == 5) {
	res = res * q * ip;
	ans = res * iq * p * res.inv();
    }
    for(int i = 1 ; i <= N ; ++i) {
	out(ans.f[i]);space;
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 9344
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end
str = gc
puts str.join == str.reverse.join ? 'Yes' : 'No'


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n;
  cin >> n;
  ll ans = 0;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  rep(i,n-1){
    ans += max(a[i],a[i+1])-a[i+1];
    a[i+1]=max(a[i],a[i+1]);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

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

        int cnt = 0;
        REP(i, N) {
                double X, Y;
                cin >> X >> Y;
                double d = sqrt(X * X + Y * Y);
                if (d <= D) cnt++;
        }

        cout << cnt << endl;
        return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int a, b;
	cin >> a >> b;
	a += b;
	if (a % 2 == 0) cout << abs(a / 2) << endl;
	else cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

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

  if ((A+B) > (C+D)) {
    cout << "Left" << endl;
  }
  else if ((A+B) == (C+D)){
    cout << "Balanced" << endl;
  }
  else {
      cout << "Right" << endl;
  }
  

}

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

static
int u[ 100 ][ 100 ];
static
int p[ 50 ][ 50 ];
static
int n, m;

#define FOR1(A,F,T) \
  for ( (A) = (F); (A) < (T); ++(A) )
#define FOR2(A,B,F,T) \
  FOR1(A,F,T) \
  FOR1(B,F,T)
#define MIN(D,S) \
  (D) = ( (S) < (D) ? (S) : (D) )

static
void rotate (
  void
  )
{
  int t[ 50 ][ 50 ];
  int x, y;

  memcpy ( t, p, sizeof ( p ) );

  FOR2(y,x,0,m) p[ m - y - 1 ][ x ] = t[ x ][ y ];
}

static
int pred (
  int x,
  int y
  )
{
  int dx, dy;

  FOR2(dy,dx,0,m)
  {
    if ( p[ dx ][ dy ] == -1 )  continue ;
    if ( p[ dx ][ dy ] != u[ x + dx ][ y + dy ] ) {
      return ( 0 );
    }
  }

  return ( 1 );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int x, y;
    int ans = INT_MAX;
    int i;

    scanf ( "%d %d", &n, &m );
    if ( !( n | m ) )  break ;

    FOR2(y,x,0,n) scanf ( " %d", &u[ x ][ y ] );
    FOR2(y,x,0,m) scanf ( " %d", &p[ x ][ y ] );

    for ( i = 0; i < 4; ++i, rotate ( ) )
    {
      FOR2(y,x,0,n-m+1)
      {
        if ( pred ( x, y ) )
        {
          int nx;

          for ( nx = 0; p[ nx ][ 0 ] == -1; ++nx ) ;
          nx += x;
          MIN(ans,y*100+nx);
          goto CONTT;
        }
      }
CONTT: ;
    }

    if ( ans == INT_MAX )
    {
      puts ( "NA" );
    }
    else
    {
      printf ( "%d %d\n", ( ans % 100 ) + 1, ( ans / 100 ) + 1 );
    }
  }

  return ( 0 );
}

Measured memory_bytes: 476
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n,i,j,v;
long r=0,m;
char s[11];
struct l{
    char s[11];
    int b;
    struct l *a;
};
struct l *ht[500000];
struct l *p,*q;
int comp(const void *a, const void *b){return *(char*)a-*(char*)b;}
int main(){
    scanf("%d",&n);
    for(i=n;i--;){
        scanf("%s",s);
        qsort(s,10,sizeof(char),comp);
        m=0;
        for(j=0;s[j]!='\0';)m+=s[j++]*(j+1);
        m%=500000;
        j=1;
        for(p=ht[m];p!=NULL;p=p->a){
            if(!strcmp(s,(*p).s)){
                r+=(*p).b;
                (*p).b++;
                j=0;
                break;
            }
        }
        if(j){
            p=(struct l*)malloc(sizeof(struct l));
            strcpy((*p).s,s);
            (*p).b=1;
            p->a=NULL;
            if(ht[m]==NULL)ht[m]=p;
            else{
                q=ht[m];
                while(q->a!=NULL)q=q->a;
                q->a=p;
            }
        }
    }
    printf("%ld",r);
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef struct pair<int,int> P;
typedef long long ll;

ll n,k,l;

int dp1[16002][3]={};
int dp2[16002][3]={};
ll c[200001]={};
int main() {
	string s;
	string t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),greater<char>());
	if(s<t)cout<<"Yes"<<endl;
	if(t<=s)cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    al = list(map(int, input().split()))

    nums = [0] * n
    for i in range(n, 0, -1):
        if sum(nums[i-1::i]) % 2 != al[i-1]:
            nums[i-1] = 1

    print(sum(nums))
    print(*[i+1 for i, e in enumerate(nums) if e == 1])


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    double p = 0.00000000000;
    cin>>n>>k;
    ll cnt;
    ll j;
    REP(i,1,n+1){
        cnt = 0;
        j = i;
        while (j<k){
            j*=2;
            cnt++;
        }
        //dbg(cnt);
        if(cnt>0){
            p += (1.00000000000/n)/pow(2,cnt);
        }else{
            p += (1.00000000000/n);
        }
        //dbg(p);
    }
    cout<<std::setprecision(10) <<p<<endl;
    return  0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)



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

if(N%2==1){
  cout<<"No"<<endl;
  return 0;
}
ll ff=1;
for(ll i=0;i<N/2;i++){
  if(S[i]!=S[N/2+i]){
    ff=0;
  }
}

if(ff==0){
  cout<<"No"<<endl;
}
else{
  cout<<"Yes"<<endl;
}




}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a,b,c,i,count;
  count=0;
  scanf("%d %d %d",&a,&b,&c);
  for(i=a;i<=b;i++){
    if(c%i==0){
      count++;
    }  
  }
  printf("%d\n",count);

  return 0;
}


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

int main(){
  int n, y, i, j, ch = 0;
  cin >> n >> y;
  for(i=0; i<=n; i++){
    for(j=0; j<=n-i; j++){
      int sum = 10000*i + 5000*j + 1000*(n-i-j);
      if(sum == y){
        cout << i << " " << j << " " << n-i-j << endl;
        ch = 1;
        i=n;
        break;
      }
    }
  }
  if(ch == 0) cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using std::abs;
using std::min;
int main(){
	int n,k,a[100010],mn=1e9;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",a+i);
	for(int i=k-1;i<n;i++){
		mn = std::min(mn,min(abs(a[i]),abs(a[i-k+1]))+a[i]-a[i-k+1]);
	}
	printf("%d\n",mn);
}

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

int where(int x, vector<int>& v) {
	return lower_bound(v.begin(), v.end(), x) - v.begin();
}

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

	vector<int> num(n);
	for(int &i : num) cin >> i;

	vector<int> v = num;
	sort(v.begin(), v.end());

	int ans = 0;
	for(int i=0; i<n; i++) {
		int d = abs(i - where(num[i], v));
		if(d % 2) ans++;
	}

	cout << ans / 2;
}

Measured memory_bytes: 1024
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int[] A = new int[3];
  sc.scan(A[0], A[1], A[2]);

  sort(A);

  int cost = 0;

  cost += A[1] - A[0];
  cost += A[2] - A[1];

  writeln(cost);
}


Measured memory_bytes: 256
<?php
while(true){
    fscanf(STDIN,"%d %d",$h,$w);
    if( $w === 0 && $h === 0 ) break;
    for( $i = 0 ; $i < $h ; $i++ ){
        for ( $j = 0 ; $j < $w ; $j++){
            echo "#";
        }
        echo PHP_EOL;
    }
    echo PHP_EOL;
}

Measured memory_bytes: 15004
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#define maxn 35
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
#define E 1e-8
#define mod 1000000007
#define P pair<int,int>
using namespace std;

int main()
{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        if(a==b&&b==c) printf("0\n");
        else
        {
            int sum = a+b+c;
            int MAX = max(max(a,b),max(b,c));
            for(int i=1;; ++i)
            {
                if((sum+2*i)%3==0&&(sum+2*i)/3>=MAX)
                {
                    printf("%d\n",i);
                    break;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
std::vector<long long> dijkstra(std::vector<std::vector<std::pair<int, long long>>> const& adj, int v0) {
    int n = adj.size();
    std::vector<long long> cost(n, -1);
    std::priority_queue<std::pair<long long, int>> pq;
    pq.push({0, v0});
    cost[v0] = 0;
    while (!pq.empty()) {
        auto x = pq.top();
        pq.pop();
        long long c = -x.first;
        int v = x.second;
        if (c > cost[v])
            continue;
        cost[v] = c;
        for (auto next : adj[v]) {
            if (cost[next.first] == -1 || cost[next.first] > c + next.second) {
                cost[next.first] = c + next.second;
                pq.push({-(c + next.second), next.first});
            }
        }
    }
    return cost;
}
int main() {
  int K;
  cin >> K;
  vector<vector<pair<int,long long>>> G(K);
  for (int i = 0; i < K; i++) {
    G[i].push_back({(i+1)%K,1});
    G[i].push_back({(10*i)%K,0});
  }
  cout << dijkstra(G,1)[0]+1;
}

Measured memory_bytes: 12012
from __future__ import division
import sys
if sys.version_info[0]>=3: raw_input=input

X=4
Y=2
i=0
m={}
prev={}
v=[]
for i in range(X*Y): v.append(str(i))
m[''.join(v)]=[0,0]
prev[''.join(v)]=[''.join(v),None]
q=[v]
while len(q)>0:
	v=q.pop(0)
	coor=m[''.join(v)][0]
	x=coor%X
	y=coor//X
	depth=m[''.join(v)][1]
	nextstr=''.join(v)
	if 0<x:
		v[coor],v[coor-1]=v[coor-1],v[coor]
		if ''.join(v) not in m:
			m[''.join(v)]=[coor-1,depth+1]
			q.append(v[:])
			prev[''.join(v)]=[nextstr,'R']
		v[coor],v[coor-1]=v[coor-1],v[coor]
	if x<X-1:
		v[coor],v[coor+1]=v[coor+1],v[coor]
		if ''.join(v) not in m:
			m[''.join(v)]=[coor+1,depth+1]
			q.append(v[:])
			prev[''.join(v)]=[nextstr,'L']
		v[coor],v[coor+1]=v[coor+1],v[coor]
	if 0<y:
		v[coor],v[coor-X]=v[coor-X],v[coor]
		if ''.join(v) not in m:
			m[''.join(v)]=[coor-X,depth+1]
			q.append(v[:])
			prev[''.join(v)]=[nextstr,'D']
		v[coor],v[coor-X]=v[coor-X],v[coor]
	if y<Y-1:
		v[coor],v[coor+X]=v[coor+X],v[coor]
		if ''.join(v) not in m:
			m[''.join(v)]=[coor+X,depth+1]
			q.append(v[:])
			prev[''.join(v)]=[nextstr,'U']
		v[coor],v[coor+X]=v[coor+X],v[coor]

try:
	while True:
		v=raw_input().split()
		print(m[''.join(v)][1])
except EOFError:
	pass

Measured memory_bytes: 17692
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second 
//#pragma GCC optimize "trapv"
char a[1000+10][1000+10];
int vi[1000+10][1000+10];
	int ch,cw,dh,dw;
	int h,w;
	int mrk[1004][1004];
void bfs(int x,int y)
{
	priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> q;
	q.push({0,{x,y}});
	vi[x][y]=0;
	while(!q.empty())
	{
		int x1 = q.top().se.fi;
		int y1 = q.top().se.se;

		q.pop();
		if(mrk[x1][y1]==1)
			continue;
		mrk[x1][y1]=1;

		for(int i=-1;i<=1;i++)
		{
			for(int j=-1;j<=1;j++)
			{
				if(abs(i)==abs(j))
					continue;
				int x2 = x1 + i;
				int y2 = y1 + j;
				if(x2<0 || x2 >=h || y2 <0 ||y2 >=w )
					continue;

				if(a[x2][y2]=='#')
					continue;

				if((vi[x2][y2]>vi[x1][y1])|| vi[x2][y2]==-1)
				{
					vi[x2][y2] = vi[x1][y1];
					q.push({vi[x2][y2],{x2,y2}});
				}

			}
		}


		for(int i=-2;i<=2;i++)
		{
			for(int j=-2;j<=2;j++)
			{
				int x2 = x1+i;
				int y2 = y1 + j;
				if(x2<0 || x2 >=h || y2 <0 ||y2 >=w )
					continue;

				if(a[x2][y2]=='#')
					continue;

				if((vi[x2][y2]>vi[x1][y1]+1 )|| vi[x2][y2]==-1)
				{
					vi[x2][y2] = vi[x1][y1]+1;
					q.push({vi[x2][y2],{x2,y2}});

				}

			}
		}




	}

}




int main()
{
	// ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
	cin>>h>>w;
	cin>>ch>>cw;
	cin>>dh>>dw;
	ch--;
	cw--;
	dh--;
	dw--;
	// memset(vi,-1,sizeof(vi));
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			vi[i][j] = -1;	
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	{
		cin>>a[i][j];
	}

	bfs(ch,cw);
	if(vi[dh][dw]!=-1)
			cout<<vi[dh][dw]<<"\n";
	else
		cout<<"-1\n";

}


Measured memory_bytes: 12464
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi=vector<int>;
using vii=vector<vi>;
using vl=vector<ll>;
using vll=vector<vl>;
using tpi=tuple<int, int, int>;

int main() {
    using vp=vector<pii>;
    int N, W;
    cin >> N >> W;
    vp items(1);
    for (auto i = 0; i < N; i++) {
        int w, v;
        cin >> w >> v;
        items.emplace_back(w, v);
    }

    vll dp(N + 1, vl(W + 1));
    for (auto i = 1; i <= N; i++) {
        for (auto j = 1; j <= W; j++) {
            ll tmp = 0;
            if (j - items.at(i).first >= 0) {
                tmp = dp.at(i - 1).at(j - items.at(i).first) + items.at(i).second;
            }
            dp.at(i).at(j) = max(dp.at(i - 1).at(j), tmp);

        }
    }

    cout << dp.at(N).at(W) << endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

vector<int> make_prime_list(int n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;

    vector<int> prime_list;
    for (int i = 2; i < n + 1; ++i) {
        if (!is_prime[i]) { continue; }
        prime_list.emplace_back(i);

        for (int j = i + i; j < n + 1; j += i) {
            is_prime[j] = false;
        }
    }
    return prime_list;  // 素数のリスト
    //return is_prime;  // すべての数値について素数かどうか
}

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

    auto prime_list = make_prime_list(55555);

    vector<int> ans;
    FOE(p, prime_list) {
        if (p % 5 == 1) {
            ans.emplace_back(p);
        }
        if (ans.size() == N) {
            break;
        }
    }
    print_vec(ans);

    return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(2 * m);
  for (int i = 0; i < 2 * m; i++)
  {
    cin >> a[i];
  }
  vector<int> count(n);
  for (int j = 0; j < n; j++)
  {

    
    for (int i = 0; i < 2 * m; i++)
    {
      if (a[i] == j+1)
      {
        count[j] += 1;
      }
    }

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


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

using namespace std;

int main(){
    int n;
    cin >> n;
    long long min_num = 10000000000;
    long long diff = -10000000000;

    for(int i=0;i<n;i++){
        long long tmp;
        cin >> tmp;
        
        diff = max(diff,tmp-min_num);
        min_num = min(tmp,min_num);

        }
        cout << diff << endl;
    }


Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;

int n, s, c;

void func(int n, int sum, int max){
	if (n){
		for (int i = max + 1; i < 10; i++){
			func(n - 1, sum + i, i);
		}
	}
	else if (sum==s){
		c++;
		return;
	}
	return;
}

int main(){
	while (cin >> n >> s){
		if (n == 0)break;
		c = 0;
		func(n,0,-1);
		cout << c << "\n";
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    int L[N];
    for(int i = 0; i < N; i++) cin >> L[i];
    sort(L, L+N);
    int a = L[N-1];
    int sum = 0;
    for(int i = 0; i < N-1; i++) {
        sum += L[i];
    }
    if(sum > a) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main extends App {
  val n = readInt
  var minv = readInt
  var maxv = Int.MinValue

  for(i<-1 until n) {
    val r = readInt
    val m = r-minv

    if(m > maxv)
      maxv = m
    if(m < 0)
      minv = r
  }
  println(maxv)
}

Measured memory_bytes: 63712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int h, w, k; cin >> h >> w >> k;
  vector<string> g(h);
  for (auto& row: g) {
    cin >> row;
  }

  int ans = 0;
  for (int rmask = 0; rmask < (1 << h); rmask++) {
    for (int cmask = 0; cmask < (1 << w); cmask++) {
      auto cpy = g;
      for (int i = 0; i < h; i++) {
        if (rmask & (1 << i)) {
          for (int j = 0; j < w; j++) {
            cpy[i][j] = '$';
          }
        }
      }
      for (int j = 0; j < w; j++) {
        if (cmask & (1 << j)) {
          for (int i = 0; i < h; i++) {
            cpy[i][j] = '$';
          }
        }
      }
      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (cpy[i][j] == '#') {
            cnt++;
          }
        }
      }
      if (cnt == k) ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    int cnt = 0;
    bool exists1 = false;
    int cnt3 = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        cnt += A[i] % 2;
        if (A[i] == 1) exists1 = true;
        if (A[i] % 2 == 1 && A[i] > 2) cnt3++;
    }
    if (exists1 || cnt3 >= 2 || (cnt % 2 != 0)) {
        cout << "first" << endl;
    } else {
        cout << "second" << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var K, S, r int
	fmt.Scan(&K, &S)
	for i := 0; i <= K; i++ {
		for j := max(S-i-K, 0); j <= min(K, S-i); j++ {
			r++
		}
	}
	fmt.Println(r)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}


Measured memory_bytes: 512
# coding: utf-8

class Node:
    def __init__(self, me, left, right):
        self.me = me
        self.left = left
        self.right = right
        self.parent = None

class NodeTree:
    def __init__(self, root=None):
        self.root = root
        
    def insert(self,z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.me < x.me:
                x = x.left
            else:
                x = x.right
        z.parent = y
        
        if y == None:
            self.root = z
        elif z.me < y.me:
            y.left = z
        else:
            y.right = z
    
    def getPreorder(self, node, ans):
        ans.append(node)
        if node.left != None:
            self.getPreorder(node.left, ans)
        if node.right != None:
            self.getPreorder(node.right, ans)
            
    def getInorder(self, node, ans):
        if node.left != None:
            self.getInorder(node.left, ans)
        ans.append(node)
        if node.right != None:
            self.getInorder(node.right, ans)

        
def printAns(ans):
    for a in ans:
        print(" " + str(a.me),end="")
    print()
    
m = int(input().rstrip())
nt = NodeTree()
for i in range(m):
    line = input().rstrip().split()
    if line[0] == "insert":
        nt.insert(Node(int(line[1]),None,None))
    else:
        ans = []
        nt.getInorder(nt.root,ans)
        printAns(ans)
        ans = []
        nt.getPreorder(nt.root,ans)
        printAns(ans)


Measured memory_bytes: 109048
using System;

namespace abc160B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            long A = long.Parse(Console.ReadLine());
            long B = A / 500;
            long C = A % 500;
            long D = C / 5;
            Console.WriteLine(B * 1000 + D * 5);
        }
    }
}


Measured memory_bytes: 13140
INF = int(1e9+7)


def modadd(a, b):
    # aとbを足した値をmodする(a + b mod p)
    return (a + b) % INF


def main():
    N, M, *a = map(int, open(0).read().split())
    a = set(a)
    dp = [0] * (N + 1)
    dp[:2] = 1, 1 if 1 not in a else 0
    for i in range(2, N + 1):
        if i not in a:
            dp[i] = modadd(dp[i - 1], dp[i - 2])
    print(dp[N])
    return


main()


Measured memory_bytes: 14180
from itertools import product
h, w, k = map(int, input().split())
grid = [input() for _ in range(h)]

a = [i for i in range(h)]
b = [i for i in range(w)]


def cnt(i, j):
    ret = 0
    for k in range(len(i)):
        for t in range(len(j)):
            if i[k] == 0 or j[t] == 0:
                continue
            if grid[k][t] == "#":
                ret += 1

    return ret

ans = 0
for i in product([0, 1], repeat=h):
    for j in product([0, 1], repeat=w):
        if cnt(i, j) == k:
            ans += 1

print(ans)

Measured memory_bytes: 9160
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

	vector<pair<int, vector<int> > > books(n);
	int c;
	for (int i = 0; i < n; ++i) {
		cin >> c;
		int a;
		books[i] = {c, vector<int> (m)};
		for (int j = 0; j < m; ++j) {
			cin >> books[i].second[j];
		}
	}

	int min_price = INT_MAX;
	for (int i = 1; i < (1 << n); ++i) {
		int total_price = 0;
		vector<int> knowledge(m);
		for (int j = 0; j < n; ++j) {
			if ((1 << j) & i) {
				total_price += books[j].first;
				for (int k = 0; k < m; ++k) {
					knowledge[k] += books[j].second[k];
				}
			}
		}

		bool valid = true;
		for (int j = 0; j < m; ++j) {
			if (knowledge[j] < x) {
				valid = false;
				break;
			}
		} 

		if (valid) {
			min_price = min(min_price, total_price);
		}
	}

	(min_price != INT_MAX) ? cout << min_price << "\n" : cout << "-1\n";

	return 0;

}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
using ull = unsigned long long;
using ll = long long;
using ld = long double;
int main(){
 ll D,T,S;
  cin>>D>>T>>S;
 if(T*S>=D) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

#define MAX_S 200000
char S[MAX_S+1];
int len;

int main() {
  scanf("%s", S);
  for (; S[len]; ++len);

  long total{};
  for (int i{}, cnt{}; i < len; ++i) {
    if (S[i] == 'W') {
      total += cnt;
    } else {
      ++cnt;
    }
  }

  printf("%ld\n", total);
  return 0;
}


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

using namespace std;
using ll = long long;
const ll inf = 1e18 + 5;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, W, V = 0;
  cin >> n >> W;
  vector<int> w(n), v(n);  
  for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
  for(int i = 0; i < n; i++) V += v[i];
  vector<vector<ll>> dp(n + 1, vector<ll> (V + 1, inf));
  for(int i = 0; i <= n; i++) dp[i][0] = 0LL;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= V; j++) {
      if(j >= v[i - 1] && dp[i - 1][j - v[i - 1]] < inf) {
        dp[i][j] = min(dp[i - 1][j], (ll)w[i - 1] + dp[i - 1][j - v[i - 1]]);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  ll ans = 0;
  for(int j = 1; j <= V; j++) {
    if(dp[n][j] <= W) ans = j;
  }
  cout << ans << '\n';
  return 0;
}
      


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

int main(void) {
    long long N;
    cin >> N;
    long long a = sqrt((long double)N);
    long long b = 1;
    for (int i = a; i > 0; i--) {
        if (N % i == 0) {
            b = i;
            break;
        }
    }
    printf("%lld\n", (b - 1) + (N / b) - 1);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int c[10],n;
void dfs(int _n,int m,int v){
	if(_n==0){
		printf("%0*d\n",n,v);
		exit(0);
	}
	int i=0;
	for(;i<10;i++)if(m>=c[i])dfs(_n-1,m-c[i],v*10+i);
}
	
int main(){
	int m,i;
	scanf("%d%d",&n,&m);
	for(i=0;i<10;i++)scanf("%d",c+i);
	dfs(n,m,0);
	puts("NA");
	exit(0);
}


Measured memory_bytes: 608
N, M = map(int, input().split())
A_list = [input() for _ in range(N)]
B_list = [input() for _ in range(M)]

b_str = ''.join(B_list)
def judge_same(str1, str2):
    return str1 == str2
judge = False
finish = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        a_str = ''.join([A_list[i + x][j:(j+M)] for x in range(M)])
        judge = judge_same(a_str, b_str)
        if judge:
            finish = True
            break
    if finish:
        break
if judge:
    print('Yes')
else:
    print('No')

        





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

typedef long long ll;

int main(){
  int N;
  cin >> N;
  int cnt = 0;
  ll ans = 0;
  ll tmpmin = 1000000000;
  for(int i = 0; i < N; i++){
    ll tmp;
    cin >> tmp;
    if(tmp < 0){
      cnt++;
      tmp = -tmp;
    }
    ans += tmp;
    if(tmp < tmpmin){
      tmpmin = tmp;
    }
  }
  
  if(cnt % 2 == 0){
    cout << ans << endl;
  } else { 
    cout << ans - 2*tmpmin << endl;
  } 
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long seg_tree[seg_size*4];
long long updates[seg_size*4];
long long seg_find(int now,int n_l,int n_r,int w_l,int w_r){
    if(updates[now] != -1){
        seg_tree[now] = updates[now];
        updates[now*2] = updates[now];
        updates[now*2+1] = updates[now];
        updates[now] = -1;
    }
    if(w_l <= n_l&&n_r <= w_r) return seg_tree[now];
    if(n_r <= w_l||w_r <= n_l) return (1LL << 31LL) - 1;
    return min(seg_find(now*2,n_l,(n_l+n_r)/2,w_l,w_r),seg_find(now*2+1,(n_l+n_r)/2,n_r,w_l,w_r));
}
long long seg_add(int now,int n_l,int n_r,int w_l,int w_r,int settings){
    if(updates[now] != -1){
        seg_tree[now] = updates[now];
        updates[now*2] = updates[now];
        updates[now*2+1] = updates[now];
        updates[now] = -1;
    }
    if(w_l <= n_l&&n_r <= w_r){
        updates[now] = settings;
        seg_tree[now] = settings;
        return seg_tree[now];
    }
    if(n_r <= w_l||w_r <= n_l) return (1LL << 31LL) - 1;
    return min(seg_add(now*2,n_l,(n_l+n_r)/2,w_l,w_r,settings),seg_add(now*2+1,(n_l+n_r)/2,n_r,w_l,w_r,settings));
}
int main(){
    int n,query;
    cin >> n >> query;
    for(int i = 0;i < seg_size*2;++i){
        updates[i] = -1;
        seg_tree[i] = (1LL << 31LL) - 1;
    }
    REP(i,query){
        int a;
        cin >> a;
        if(a == 0){
            int a,b,c;
            cin >> a >> b >> c;
            seg_add(1,0,seg_size,a,b+1,c);
        }else{
            int b;
            cin >> b;
            cout << seg_find(1,0,seg_size,b,b+1) << endl;
        }
    }
}


Measured memory_bytes: 21016
n = int(input())
t, a = map(int, input().split())
H = list(map(int, input().split()))

ans = -1
dif = 10**6
for i in range(n):
    if abs(t-0.006*H[i]-a) < dif:
        dif = abs(t-0.006*H[i]-a)
        ans = i+1
print(ans)

Measured memory_bytes: 38384
/*1 initialize()
2   top = 0
3
4 isEmpty()
5   return top == 0
6
7 isFull()
8   return top >= MAX - 1
9
10 push(x)
11   if isFull()
12     エラー（オーバーフロー）
13   top++
14   S[top] = x
15
16 pop()
17   if isEmpty()
18     エラー（アンダーフロー）
19   top--
20   return S[top+1]
*/

#include <stdio.h>
#include <stdlib.h>

int top = 0 , stack[100];
void push ( int );
int pop ( void);

int main(){
  int x , y , flag =0 , ini ,suuji , res ;
  char c , t , input[100];

  while( scanf("%s", input) != EOF){
    //printf("top %d\n" , top);
    if ( input[0]  == '+' ){
      //printf("one two  %d  %d\n" , stack[top] , stack [top-1] );
      //      top--;
      //printf("res  %d\n", res);
      x = pop();
      y =pop();
      res = x + y;
      push( res);
    } else if ( input[0]== '-' ){
     x = pop();
      y =pop();
      res = y -x;
      push( res);
    } else if ( input[0] == '*' ){
          x = pop();
      y =pop();
      res = x * y;
      push( res);
    
      //  }else if (  == ' '){continue;
      //  }   else if ( c == '\n'){break;
      //}else if ( !(input[0] >= '0' && input[0] <= '9')  ){break;
    }else {
    //  suuji = (int) (c - '0');
    //  while (  1 ){/
    //scanf ("%c" , &t);
    //  if ( !( c >= '0' && c <= '9')){break;}
    //printf("test");
    //	suuji*= 10; suuji += (int) ( t - '0');
    //printf("%d", suuji);
    //  }
      //  suuji  = atoi(input);
      //  printf("suuji %d\n" , suuji);
      //stack[top] = suuji;
      //top++;
      res = atoi(input);
      push (res);
    }
  }
  printf("%d\n", pop());
  return 0;
}

void push ( int in ){
  top++;
  stack[ top] = in;
}

int pop (){
  int ret ;
  ret = stack [ top];
  top--;
  return ret;
}


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

const int mod = 1e9+7;

using namespace std;

template <typename T>
void print(T vec) { for(auto i : vec) cout<<i<<" ";}
template <typename T>
void print2D(T matrix) {for(auto vec:matrix) {print(vec);cout<<'\n';}}

int main() {
    int n,k;
    cin>>n>>k;
    vector<int> A(n + 1);
    for(int i = 1; i < n + 1;i++) cin>>A[i];
    vector<vector<int>> dp(n + 1, vector<int>(k+1, 0));
    for(int i = 1; i<=k; i++) {
        dp[0][k] = 0;
    }
    dp[0][0] = 1;
    for(int i = 1; i<=n;i++) {
        vector<int> sums(k+1);
        sums[0] = dp[i -1][0];
        for(int j = 1; j<=k;j++) {
            sums[j] = (sums[j-1] + dp[i - 1][j]) % mod;
        }
        for(int j = 0; j<=k;j++) {
            int tr = sums[j];
            int unreachable = j - A[i] - 1;
            if(unreachable >= 0) {
                tr = (tr - sums[unreachable] + mod) % mod;
            }
            dp[i][j] = tr;
        }
    }
    //print2D(dp);
    cout<<dp[n][k]<<'\n';
    return 0;

}

Measured memory_bytes: 40192
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int len;
string s;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    len = s.length();
    int cnt = 0;
    for (int i = 0; i < len/2; i++) {
        if (s[i] != s[len - 1 - i]) cnt++;
    }
    cout << cnt << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

ll dp[3010][3010][2];
int main(void) {
    ll n, t;
    cin >> n >> t;
    vector<ll> a(n), b(n);
    REP(i, n) cin >> a[i] >> b[i];

    REP(i, n+1) REP(j, t) REP(k, 2) dp[i][j][k] = -INF;
    dp[0][0][0] = 0;
    REP(i, n) REP(j, t) REP(k, 2) {
        chmax(dp[i+1][j][k], dp[i][j][k]);
        if(j+a[i]<t) chmax(dp[i+1][j+a[i]][k], dp[i][j][k]+b[i]);
        if(k==0) chmax(dp[i+1][j][1], dp[i][j][k]+b[i]);
    }

    ll ret = 0;
    REP(i, t) chmax(ret, dp[n][i][1]);
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 141568