akhauriyash/Code-Regression huggingface dataset:
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
using mat = vector<vector<ll>>;
using vec = vector<ll>;
#define INF1  INT_MAX
#define INF2  LLONG_MAX
const double  PI =  acos(-1);
#define MOD 1000000007
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){

int N;
cin>>N;
ll A[N],ans=0;
rep(i,N)cin>>A[i];
ll tmp=0;
rep(i,N){
    if(A[i]>0)tmp+=A[i];
    else {
        ans+=tmp/2;
    tmp=0;
    }
}
ans+=tmp/2;


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

Measured memory_bytes: 4356
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, a, b, c = LI()
fac = [1] * (2 * n + 1)
inv = [1] * (2 * n + 1)
for j in range(1, 2 * n + 1):
    fac[j] = fac[j-1] * j % mod

inv[2 * n] = pow(fac[2 * n], mod-2, mod)
for j in range(2 * n - 1, -1, -1):
    inv[j] = inv[j+1] * (j+1) % mod

memoA = [1] * (n + 1)
memoB = [1] * (n + 1)
for i in range(1, n + 1):
    memoA[i] = memoA[i - 1] * a % mod
    memoB[i] = memoB[i - 1] * b % mod

def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


ret = 0
for i in range(n, 2 * n):
     numerator = comb(i - 1, n - 1) * (memoA[n] * memoB[i - n] + memoA[i - n] * memoB[n]) * i * 100 % mod
     divisor = pow(pow(a + b, i, mod), mod - 2, mod) * pow(100 - c, mod - 2, mod)
     ret = (ret + numerator * divisor) % mod


print(ret)

Measured memory_bytes: 48620
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	char X, Y;
	cin >> X >> Y;
	if (X > Y) {
		cout << ">" << endl;
	}
	else if (X < Y) {
		cout << "<" << endl;
	}
	else {
		cout << "=" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  string A,B;
  cin >> A >> B;
  if(A.size()>B.size()) cout << "GREATER" << endl;
  else if(A.size()<B.size())  cout << "LESS" << endl;
  else if(A.size()==B.size()){
    for(int i=0;i<A.size();i++){
      if(A.at(i)>B.at(i)){
        cout << "GREATER" << endl;
        return 0;
      }
      else if(A.at(i)<B.at(i)){
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
  }
  
  return 0;
}


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

using namespace std;

int n, dp[100005];

int main(){
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++){
		dp[i] = dp[i - 1] + 1;
		int v = 6;
		while(i - v >= 0){
			dp[i] = min(dp[i], dp[i - v] + 1);
			v *= 6;
		}
		v = 9;
		while(i - v >= 0){
			dp[i] = min(dp[i], dp[i - v] + 1);
			v *= 9;
		}
	}
	
	printf("%d\n", dp[n]);
}


Measured memory_bytes: 640
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let v: Vec<u64> = read_vec();
    let n = v[0];
    let k = v[1];
    let ab: Vec<Vec<u64>> = read_vec2(n as u32);

    let mut tbl: Vec<u64> = vec![0; 100000];
    for tmp in ab {
        tbl[(tmp[0] - 1) as usize] += tmp[1];
    }

    let mut cnt: u64 = 0;

    for i in 0..100000 {
        cnt += tbl[i];
        if cnt >= k {
            println!("{}", i + 1);
            break;
        }
    }
}


Measured memory_bytes: 10492
//file_name:ABC68_C.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    int c[m] = {};
    int d[m] = {};
    int countc = 0;
    int countd = 0;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        if(a==1){
            c[countc] = b;
            countc++;
        }
        if(b==n) {
            d[countd] = a;
            countd++;
        }
    }
    sort(c,c+countc);
    sort(d,d+countd);
    int i = 0;
    int j = 0;
    while(true){
        if(c[i]==0||d[j]==0)break;
        if(c[i]==d[j]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
        if(c[i]<d[j]){
            i++;
        }else{
            j++;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}



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


int main() {
  int r, d, x;
  cin >> r >> d >> x;
  rep(i,10){
    x = r*x-d;
    cout << x <<endl;
  }
  return 0;
}

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

using namespace std;

#define USE_IOSTREAM \
{\
	ios::sync_with_stdio(false);\
	cin.tie(0);\
	cout.tie(0);\
}

#define pii pair<int, int>
#define mp make_pair

typedef long long ll;

const int N = 2e5 + 100;

vector<int> g1[N];
vector<int> g2[N];
int com1[N];
int com2[N];
int ans[N];

void dfs1(int u, int c)
{
	com1[u] = c;
	
	for (auto v : g1[u])
	{
		if (!com1[v])
		{
			dfs1(v, c);
		}
	}
}

void dfs2(int u, int c)
{
	com2[u] = c;
	for (auto v : g2[u])
	{
		if (!com2[v])
		{
			dfs2(v, c);
		}
	}
}

int main()
{
	// USE_IOSTREAM;
	int n, m1, m2, u, v, i;
	
	scanf("%d%d%d", &n, &m1, &m2);
	for (i = 1; i <= m1; i++)
	{
		scanf("%d%d", &u, &v);
		g1[u].push_back(v);
		g1[v].push_back(u);
	}
	
	for (i = 1; i <= m2; i++)
	{
		scanf("%d%d", &u, &v);
		g2[u].push_back(v);
		g2[v].push_back(u);
	}
	
	int num1 = 0, num2 = 0;
	for (u = 1; u <= n; u++)
	{
		if (!com1[u])
		{
			dfs1(u, ++num1);
		}
	}
	
	for (u = 1; u <= n; u++)
	{
		if (!com2[u])
		{
			dfs2(u, ++num2);
		}
	}
	
	map<int, int> cntMap1;
	map<int, int> cntMap2;
	map<pii, int> dupMap;
	for (i = 1; i <= n; i++)
	{
		//cntMap1[com1[i]]++;
		//cntMap2[com2[i]]++;
		dupMap[mp(com1[i], com2[i])]++;
	}
	
	for (i = 1; i <= n; i++)
	{
		//ans[i] = cntMap1[com1[i]] + cntMap2[com2[i]] - dupMap[mp(com1[i], com2[i])];
		ans[i] = dupMap[mp(com1[i], com2[i])];
	}
	
	for (i = 1; i <= n; i++)
	{
		printf("%d ", ans[i]);
	}
	
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 28672
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>

using namespace std;

typedef vector<int> vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

typedef pair<int, int> pi;
#define mp make_pair
#define f  first
#define s  second

typedef long long ll;
typedef long double ld;

/*
const int MOD = 1e9+7;
const int MX =  2e5+5;
const ll  INF = 1e18;
const ld  PI = acos((ld)-1);
*/

template <class array>
inline void array_input(array a[], size_t  n){
  for(size_t i = 0; i < n; i++)
    cin >> a[i];
}

template <class array>
inline void array_init(array a[], array value, size_t n){
  for(size_t i = 0; i < n; i++)
    a[i] = value;
}


int main(){/*
  int t;

  cin >> t;
 
  while(t--)*//*for(int m = 1; m <= t; m++)*/{
    /* input for each test case */
    int n;
    cin >> n;
    
    /* calcultion for each test case */
    int ans = 0;
    if(n >= 400 && n <= 599) ans = 8;
    else if(n >= 600 && n <=  799) ans = 7;
    else if(n >= 800 && n <=  999) ans = 6;
    else if(n >= 1000 && n <=  1199) ans = 5;
    else if(n >= 1200 && n <=  1399) ans = 4;
    else if(n >= 1400 && n <=  1599) ans = 3;
    else if(n >= 1600 && n <=  1799) ans = 2;
    else if(n >= 1800 && n <=  1999) ans = 1;
    
    /* output of each test ca*/
    cout << ans << '\n';
    
  }

  return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while(cin>>n){
        if(n==0)return 0;
        vector<int> v(n,0);
        for(int &e:v){
            cin>>e;
        }
        sort(v.begin(),v.end());
        cout<<accumulate(v.begin()+1,v.end()-1,0)/(n-2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3044
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	int i;

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	string s;
	cin >> s;
	REP(i,13){
		if(i<=3) cout << s[i];
		else if(i==4) cout << ' ';
		else cout << s[i-1];
	}

	cout << endl;



	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

double abs(int x) { return (x<0)?-x:x; }
double dp[21][2*100000+1];

int main() {
    for(int i=0; i<21; ++i)
        for(int j=0; j<=2*100000; ++j)
            dp[i][j] = 1e10;

    int n,a;
    cin>>n>>a;
    for(int i=1; i<=2*100000; ++i)
        dp[0][i] = (double)abs(i-a)/a;

    for(int i=1; i<n; ++i) {
        cin>>a;
        for(int p=1; p<=2*100000; ++p)
            for(int j=1; p*j<=2*100000; ++j)
                dp[i][p*j] = min(dp[i][p*j],max(dp[i-1][p],(double)abs(p*j-a)/a));
    }

    double ans = 1e10;
    for(int p=1; p<=2*100000; ++p)
        ans = min(dp[n-1][p], ans);
    printf("%.12f\n", ans);
}

Measured memory_bytes: 32000
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  int k=0;
  while(a>0 && c>0){
  	if(k%2 == 0){
  		c-=b;
  		k++;
  	}
  	else{
  		a-=d;
  		k++;
  	}
  }
  if(a<=0)
  	cout<<"No";
  else
  	cout<<"Yes";
  return 0;
}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int n;
  cin >> n;
  vt<int> a(n);
  rep(i, 0, n) cin >> a[i];

  int MAX = max_element(all(a)) - a.begin();
  int MIN = min_element(all(a)) - a.begin();
  if(MAX == MIN) return cout << 0 << endl, 0;

  cout << 2 * n - 1 << endl;
  if(abs(a[MAX]) > abs(a[MIN])) {
    rep(i, 0, n) {
      cout << MAX + 1 << " " << i + 1 << endl;
    }
    rep(i, 1, n) {
      cout << i << " " << i + 1 << endl;
    }
  }
  else {
    rep(i, 0, n) {
      cout << MIN + 1 << " " << i + 1 << endl;
    }
    for(int i = n - 1; i > 0; --i) {
      cout << i + 1 << " " << i << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	pair<int, int>v[100005];
	for (int i = 0; i < n; i++) {
		cin >> v[i].first;
		v[i].second = i + 1;
	}
	sort(v, v + n);
	for (int i = 0; i < n; i++) {
		cout << v[i].second << " ";
	}
	return 0;
}

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

int main(){
	
	int a,b,cnt=0,q,w,e,r;
	
	cin>>a>>b;

	for(int i=a;i<=b;i++){
		q=i/10000;            //10000
		w=(i%10000)/1000;       //1000
		e=(i%100)/10;     //10
		r=i%10;
		
		if(q==r&&w==e) cnt++;
		
	}
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
 #include <vector>
 #include <map>
 #include <string>
 #include <algorithm>
 using namespace std;

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

 typedef long long ll;
 const long long INF = 1LL << 60;



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

    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    for(int i = 0; i < n- 1; i++)
    {
        if(a[i] == a[i+1])
        {
            puts("NO");
            return 0;
        }
    }

    puts("YES");


    return 0;
 }

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define maxn 1010
using namespace std;
int n;
struct P{
    int x,y;
}p[maxn];
int a[maxn],cnt;
char ans[maxn],top;
void work(int x,int y)
{
    top=0;
    for(int i=cnt;i>=1;i--)
    {
        if(abs(x)>abs(y))
        {
            if(x<0)
            {
                x+=a[i];
                ans[++top]='L';
            }
            else{
                x-=a[i];
                ans[++top]='R';
            }
        }
        else{
            if(y<0)
            {
                y+=a[i];
                ans[++top]='D';
            }
            else{
                y-=a[i];
                ans[++top]='U';
            }
        }
    }
    for(int i=top;i>=1;i--)  printf("%c",ans[i]);
    puts("");
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)  cin>>p[i].x>>p[i].y;
    int com=((p[1].x+p[1].y)&1);
    for(int i=1;i<=n;i++)
    {
        if(((p[i].x+p[i].y)&1)!=com)
        {
            puts("-1");
            return 0;
        }
    }
    int mx=0;
    for(int i=1;i<=n;i++)  mx=max(mx,p[i].x+p[i].y-(!com));
    if(com==0)  a[++cnt]=1;
    for(int i=0;;i++)
    {
        if((1ll<<i)>mx)  break;
        a[++cnt]=(1<<i);
    }
    printf("%d\n",cnt);
    for(int i=1;i<=cnt;i++)  printf("%d ",a[i]);
    puts("");
    for(int i=1;i<=n;i++)  work(p[i].x,p[i].y);
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
s = input()

#indexより右のr,g,bの数を持つ配列を作る
r_list = [0] * n
g_list = [0] * n
b_list = [0] * n
s = s[::-1]
for i,v in enumerate(s):
    if v == "R":
        r_list[i]=1
    elif v=="G":
        g_list[i]=1
    else:
        b_list[i]=1




from itertools import accumulate
#[1,3,6,10,15]
r_list = list(accumulate(r_list))
b_list = list(accumulate(b_list))
g_list = list(accumulate(g_list))

r_list.reverse()
g_list.reverse()
b_list.reverse()
s = s[::-1]

ret = 0
for i,v in enumerate(s[0:n-1]):
    if v=="R":
        ret+=(g_list[i+1] * b_list[i+1])
    elif v=="G":
        ret+=(r_list[i+1] * b_list[i+1])
    else:
        ret+=(r_list[i+1] * g_list[i+1])
    step = 0
    while True:
        step+=1
        if i+step*2 >= n:
            break
        if v!=s[i+step] and v!= s[i+step*2] and s[i+step]!=s[i+step*2]:
            ret-=1

print(ret)

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

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

	int ans = 0;
	int temp = (str.length()) / 2 - 1;
	for (int i = 1; i <= temp; i++)
	{
		if (str.substr(0, i) == str.substr(i, i))
		{
			ans = 2 * i;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
#include<cstdio>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e9
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007
#define MAX_H 110
#define MAX_W 110

int h,w;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,1,-1};
/*左、右、上、下*/
int xs,ys,xg,yg,color;
int mp[MAX_H][MAX_W];
bool ans = false;


void dfs(int y,int x){

    if(y == yg && x == xg){
        /*ゴールについた*/
        ans = true;
        return;
    }
    //今いるところを置き換える
    mp[y][x] = -1;
    //移動方向をループ
    for(int i = 0;i < 4;i++){
        //x方向にdx,ｙ方向にdy移動した場所を(ny,nx)とする
        int nx = x + dx[i], ny = y + dy[i];
        if(1 <= nx && nx <= w && 1 <= ny && ny <= h && mp[ny][nx] == color){/*同じ色なら進める*/
            dfs(ny,nx);
        }
    }
    return;/*全て調べ終わり、1つ深さを戻す*/
}




void solve(){

    for(int i = 1;i <= h;i++){
        for(int j = 1;j <= w;j++){
            if(mp[i][j] == color){
                dfs(i,j);
                if(ans){
                    /*dfsによってゴールに着いた*/
                    return;
                }
            }
        }
    }
}



int main(){

    while(cin >> w >> h,w){
        cin >> xs >> ys >> xg >> yg;

        int c,d,x,y,n;
        cin >> n;

        REP(i,n){

            cin >> c >> d >> x >> y;
            if(d == 0){
                /*横長*/
                for(int j = y;j < y+2;j++){
                    for(int k = x;k < x+4;k++){
                        mp[j][k] = c;
                    }
                }
            }else{
                /*縦長*/
                for(int j = y;j < y+4;j++){
                    for(int k = x;k < x+2;k++){
                        mp[j][k] = c;
                    }
                }
            }
        }

        color = mp[ys][xs];
    
        if(mp[ys][xs] == 0 || mp[yg][xg] == 0){
            ans = false;
        }else{
            /*横方向がx、縦方向がy*/
            dfs(ys,xs);
        }

        if(ans){
            cout << "OK" << endl;
        }else{
            cout << "NG" << endl;
        }
       
        /*初期化*/
        ans = false;
        for(int i = 1;i <= MAX_H;i++){
            for(int j = 1;j <= MAX_W;j++){
                mp[i][j] = 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

signed main() {
    INIT;
    cin >> W >> A >> B;
    if (A > B)
        swap(A, B);
    cout << max(0LL, B - (A + W)) << endl;
}

Measured memory_bytes: 3632
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var c = nextstr();
  var r = 0;
  for(var i = 0; i < n; i++){
    if(c[i] === "R")r++;
  }
  var ans = r;
  for(var i = 0; i < r; i++){
    if(c[i] === "R")ans--;
  }
  return ans;
}

Measured memory_bytes: 32540
#include<stdio.h>
int main(){
	double r;
	double S=0.0,L=0.0,pi=3.14159265359;
	scanf("%lf",&r);
	S=r*r*pi;
	L=2*r*pi;
	printf("%.6lf %.6lf\n",S,L);
	return 0;
}

Measured memory_bytes: 2668
import sys
m=10**6;a=[1]*m;a[0:2]=0,0
for i in range(2,999):
 if a[i]>0:
  for j in range(i*2,m,i):a[j]=0
for i in range(m):a[i]+=a[i-1]
for e in sys.stdin:print(a[int(e)])


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

int main() {
	int a, b;
	while (cin >> a >> b) {
		int tmp = a + b;
		for (int i = 1;;i++) {
			if (tmp < 10) {
				cout << i << endl;
				break;
			}
			tmp = tmp / 10;
		}
	}
}

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

public class Main 
{
	static int count = 0;
	static long best = 0;
	static void make(int x, int[] cur)
	{
		if(x < n)
		{
			int lastel = 1;
			if(x > 0)lastel = cur[x-1];
			
			for(int k = lastel; k <= m; k++)
			{
				int[] ncur = cur.clone();
				ncur[x] = k;
				make(x+1, ncur);
			}
		}
		else
		{
			long cor = 0;
			
			for(int i = 0; i < q; i++)
			{
				if(cur[b[i]] - cur[a[i]] == c[i])
					cor+=d[i];
			}
			best = Math.max(best, cor);
			count++;
//			System.out.println(Arrays.toString(cur));
		}
	}
	
	static int n, m, q;
	static int[] a, b, c;
	static long[] d;

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		n = sc.nextInt();
		m = sc.nextInt();
		q = sc.nextInt();
		
		a = new int[q];
		b = new int[q];
		c = new int[q];
		d = new long[q];
		for(int i = 0; i < q; i++)
		{
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		
		make(0,new int[10]);
		
		System.out.println(best);
	}

}


Measured memory_bytes: 38296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
int x[100010], y[100010];
int cnt[100010];
int flag[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
  }
  fill_n((int*)cnt, 100010, 1);
  flag[0] = 1;
  for (int i = 0; i < M; i++) {
    cnt[x[i]]--; cnt[y[i]]++;
    if (flag[x[i]] == 0) continue;
    if (cnt[x[i]] == 0) flag[x[i]] = 0;
    flag[y[i]] = 1;
  }
  cout << accumulate(flag, flag + N, 0) << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<cmath>
#include<iostream>
using namespace std;
int k,n,ans=0;
int main()
{
	cin>>k>>n;
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=k&&i+j<=n;j++)
		{
			if(n-i-j<=k)
			{
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
c = [list(map(int, input().split())) for _ in range(3)]

ans = "Yes"
for i in range(2):
  for j in range(2):
    if c[i + 1][j + 1] - c[i][j + 1] != c[i + 1][j] - c[i][j]:
      ans = "No"
      break
    if c[i + 1][j + 1] - c[i + 1][j] != c[i][j + 1] - c[i][j]:
      ans = "No"
      break

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#define debug(x) cout << #x << "==" << x << endl;
using namespace std;

const int INF = 1e+8;

//??\???
#define MAX_N 50000
#define MAX_M 20
int N;
int M;
int C[MAX_M];

// dp ????????????
int dp[MAX_N + 1];

void print_dp_array(int n) {
  for(int i = 0; i <= n; i++) {
    if(dp[i] == INF) {
      cout <<  "INF ";
    } else {
      cout << setw(3) << dp[i];
    }
  }
  cout << endl;
}

int main() {
  ios::sync_with_stdio(false);

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

  // ?????????
  fill(dp, dp + MAX_N + 1, INF);
  dp[0] = 0;


  for(int s = 0; s <= N ; s++) {

    if(dp[s] != INF) {
      for(int i = 0; i < M; i++) {
        dp[s + C[i]] = min(dp[s + C[i]], dp[s] + 1);
      }
    }
  }


  cout << dp[N] << endl;


  return 0;
}

Measured memory_bytes: 3296
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		System.out.println(f(s.nextLong(),0));
	}
	private long f(long n,int d){
		return (1L<<d)+(n==1?0:f(n/2,d+1));
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <cstring>

int vis[10005];
const long long mod= 1000000007;
int main(){
    int t;
    std::cin >>t;
    std::string str;
    std::cin >> str;
    for(auto it : str) vis[it - 'a']++;
    long long res = 1;
    for(int i = 0; i < 26; i ++){
        res = res * (vis[i] + 1) % mod;
    }
    res = res % mod;
    std::cout << res - 1 << std::endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, 0, N){
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a.begin(), a.end());
    int b;
    if (N%2==0){
        b = a[N/2 -1];
    }else{
        b = a[(N+1)/2 -1];
    }
    ll ans = 0;
    rep(i, 0, N) {
        ans += abs(a[i] - b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::f64::consts::PI;

fn main() {
    input!{
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    };

    let ht = PI * h / 6.0 + PI * m / 30.0 / 12.0;
    let mt = PI * m / 30.0;
    let c2 = a * a + b * b - 2.0 * a * b * (ht - mt).cos();
    println!("{}", c2.sqrt());
}


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

#define mp(x,y) make_pair(x,y) 
#define M 1000000007
#define endl "\n"
#define pb(x) push_back(x)
#define llip(t) long long t ; cin >> t ;
#define llip2(a,b) long long a,b ; cin >> a >> b ;
#define dip(a) double a ; cin >> a ;
#define dip2(a,b) double a,b ; cin >> a >> b ; 
#define pll pair<long long,long long>  
typedef long long ll;
 
int main(){ 
    ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    llip2(n,k) ;
    vector<ll> heights(n) ;
    for(int i = 0 ; i < n ; i++){
        cin >> heights[i] ;
    }
    vector<ll> dp(n,1000000000000) ;
    dp[0] = 0LL ;
    for(int i = 0 ; i < n ; i++){
        for(int j = i+1 ; j < min(n,i+k+1) ; j++){
            dp[j] = min(dp[i]+abs(heights[i]-heights[j]),dp[j]) ;
        }
    }
    cout << dp[n-1] << endl ;

}
 

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

const int N=1e5+20;
int n,m,dp[N];
char a[N];
set <int> safe;
vector <int> ans;

int main()
{
	scanf("%d%d %s",&n,&m,a);

	safe.insert(0);
	for(int i=1;i<=n;i++)
	{
		if(a[i]=='1') continue;
		//check if there is any safe square [i-m,i-1]
		auto it=safe.lower_bound(i-m);
		if(it!=safe.end()) safe.insert(i),dp[i]=*it;
	}

	if(safe.find(n)==safe.end()) return 0 * printf("-1");
	for(int i=n;i!=0;i=dp[i]) ans.push_back(i-dp[i]);
	reverse(ans.begin(),ans.end());
	for(auto i:ans) printf("%d ",i);
}

Measured memory_bytes: 6136
# ABC087B

A = int(input())
B = int(input())
C = int(input())
x = int(input())

LIMIT = 20000
count = 0
for a in range(A + 1):
    if a * 500 > x:
        break
    for b in range(B + 1):
        if a * 500 + b * 100 > x:
            break
        for c in range(C + 1):
            fee = a * 500 + b * 100 + c * 50
            if fee > x:
                break
            elif fee == x:
                count += 1
print(count)


Measured memory_bytes: 3060
#include<stdio.h>

int main(){
    int K,A,B;
    scanf("%d", &K);
    scanf("%d %d", &A, &B);
    int i, f;
    f = 0;

    for (i = K; i <= 1000; i+=K){
        if(i>=A&&i<=B){
            f = 1;
            break;
        }
    }
    if(f) printf("OK\n");
    else  printf("NG\n");
    
    return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL << 60;
const int MOD = (int) 1e9 + 7;

signed main() {
    string s;
    int k;
    cin >> s >> k;
    double day = 5e11;
    for(char c : s) {
        int digit = c - '0';
        if (day * log(digit) >= log(k)) {
            cout << c << "\n";
            return 0;
        }
        k -= (int)pow(digit, day);
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i, s, n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9+7;

int main() {
  int x;
  scanf("%d", &x);
  printf("%d\n", 48 - x);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int mod=1e9+7;
inline void add(int &x,int y) { x+=y; if(x>=mod) x-=mod; }
int f[51][101][101];
int a[101],n;
int main() {
	rd(n);
	for(int i=1;i<=2*n-1;++i) rd(a[i]);
	sort(a+1,a+2*n);
	f[n][1][1]=1;
	for(int x=n;x>1;--x)
		for(int y=1;y<=2*(n-x)+1;++y)
			for(int z=1;z<=y;++z) if(f[x][y][z]) {
				int ty=y,tz=z;
				if(a[n-(n-x+1)]!=a[n-(n-x)]) ty++,tz++;
				if(a[n+(n-x+1)]!=a[n+(n-x)]) ty++;
				for(int p=1;p<=ty;++p) {
					if(p<=tz) add(f[x-1][ty-max(0,tz-p-1)][p],f[x][y][z]);
					else add(f[x-1][ty-max(0,p-tz-1)][tz+1],f[x][y][z]);
				}
			}
	int ans=0;
	for(int y=1;y<2*n;++y)
		for(int z=1;z<=y;++z)
			add(ans,f[1][y][z]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.nextLine();
		int answer = 0;
		String max;
		int w =0;
		while(w != n.length()){
			char c = n.charAt(w);
			int i = Character.getNumericValue(c);
			answer += i; 
			w++; 
		}
		if(answer % 9 == 0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 41408
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int N; cin >> N;
  vector<long long> A(N);
  map<long long, long long> mp;
  set<long long> st;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    st.insert(A[i]);
    mp[A[i]]++;
  }

  long long sum = 0;
  for(auto s: st) {
    sum += mp[s] * (mp[s]-1) / 2;
  }

  for(int i = 0; i < N; i++) {
    cout << sum - mp[A[i]] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 17920
/* ***********************************************
Author        :guanjun
Created Time  :2016/10/10 12:01:32
File Name     :1.cpp
************************************************ */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
	int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
	}
};

bool cmp(int a,int b){
    return a>b;
}
string t="CODEFESTIVAL2016";
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    string s;
	while(cin>>s){
		int num=0;
		for(int i=0;i<s.size();i++){
			if(s[i]!=t[i])num++;
		}
		cout<<num<<endl;
	}
    return 0;
}


Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let mut cnt = [[[0i32; 10]; 3]; 4];
    let n = sc.read();
    for _ in 0..n {
        let b: usize = sc.read();
        let f: usize = sc.read();
        let r: usize = sc.read();
        let v: i32 = sc.read();
        cnt[b-1][f-1][r-1] += v;
    }
    for b in 0..4 {
        for f in 0..3 {
            for r in 0..10 {
                print!(" {}", cnt[b][f][r]);
            }
            println!("");
        }
        if b != 3 {
            for _ in 0..20 {
                print!("#");
            }
            println!("");
        }
    }
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define pb push_back
typedef long long ll;
typedef long double ld;

using namespace std;
#define int long long
const int md = 1e9 + 7;
ll gcdex(ll a, ll mod = md) {
	ll g = mod, r = a, x = 0, y = 1;
	while (r != 0) {
		ll q = g / r;
		g %= r;
		swap(g, r);
		x -= q * y;
		swap(x, y);
	}
	return x < 0 ? x + mod : x;
}
signed main(){
    int n , m , k;
    cin >> n  >> m  >> k;
    k-=2;
    vector < int > fact(n*m+1);
    fact[0]  = 1;
    for(int i = 1; i <= n*m;++i){
        fact[i] = fact[i-1]*i;
        fact[i]%=md;
    }
    int answer = fact[n*m-2]*gcdex((fact[n*m-k-2]*fact[k])%md);
    answer %= md;
    int ans = 0;
    for(int i= 0  ;i  < n; ++i){
        for(int j = 0; j < m ; ++j){
            int now = j*(j+1)/2;
            now *= n , now %= md;
            int second = (m-j-1)*(m-j)/2;
            second *= n , second %= md;
            ans += now + second , ans %= md;

            now = i*(i+1)/2;
            now *= m , now %= md;
            second = (n-i-1)*(n-i)/2;
            second *= m , second %= md;
            ans += now + second , ans %= md;
        }
    }
    ans *= answer;
    ans %= md;
    ans *= gcdex(2);
    ans %= md;
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
#include <stack>
#include <queue>

typedef long long ll;
#define ALL(obj) (obj).begin(),(obj).end()
#define MOD 1000000007


using namespace std;

long long GCD(long long x, long long y){
   long long r, tmp;
   if(x < y){
       tmp = x;
       x = y;
       y = tmp;
   }
   while(y!=0){
       r = x%y;
       x = y;
       y = r;
   }
   return x;
}
long long LCM(long long x, long long y){
   long long lcm = (x*y)/GCD(x, y);
   return lcm;
}

int bubblesort(int n){
    vector<int> data(n);
    int num=0;
    for(int end = n-1; end>0; end--){
        for(int j=0; j<end; j++){
            if(data[j+1] < data[j]){
                int temp = data[j];
                data[j] = data[j+1];
                data[j+1] = temp;
                num++;
            }
        }
    }
    return num;
}


int main(){
    ll n;
    cin >> n;
    ll ans = n-1;
    for(ll i=2; i<n; i++){
        ans+=n/i;
        if(n%i==0){
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N, M, C; cin >> N >> M >> C;
  
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }

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

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


Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<int> > A(H, vector<int>(W));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> A[i][j];
		}
	}
	vector<pair<int, int> > ord;
	for (int i = 0; i < H; ++i) {
		if (i % 2 == 0) {
			for (int j = 0; j < W; ++j) {
				ord.push_back(make_pair(i, j));
			}
		}
		else {
			for (int j = W - 1; j >= 0; --j) {
				ord.push_back(make_pair(i, j));
			}
		}
	}
	int pre = -1;
	vector<vector<int> > ops;
	for (int i = 0; i < ord.size(); ++i) {
		if (A[ord[i].first][ord[i].second] % 2 == 0) continue;
		if (pre == -1) pre = i;
		else {
			for (int j = pre; j < i; ++j) {
				ops.push_back({ ord[j].first, ord[j].second, ord[j + 1].first, ord[j + 1].second });
			}
			pre = -1;
		}
	}
	cout << ops.size() << endl;
	for (vector<int> i : ops) {
		cout << i[0] + 1 << ' ' << i[1] + 1 << ' ' << i[2] + 1 << ' ' << i[3] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 12012
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	int a[N], cnt = 1;
	for (int i = 0; i < N; ++i) scanf("%d", &a[i]);
	for (int i = 0; i < N; ++i) {
		if (a[i] == cnt) ++cnt;
	}
	if (cnt == 1) printf("-1");
	else printf("%d", N - cnt + 1);
	return 0;
}

Measured memory_bytes: 896
n = int(input())
s = list(input())
ans = ''
for i in s:
  o = ord(i) + n
  if i.islower():
    r = (o-97) % 26
    ans = ans + chr(97+r)
  elif i.isupper():
    r = (o-65) % 26
    ans = ans + chr(65+r)
print(ans)

Measured memory_bytes: 3060
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
b=max(a)
c=a.index(b)
a.pop(c)
d=max(a)
for i in range(n):
    if (i==c):
        print('{0}'.format(d))
    else:    
        print('{0}'.format(b))

Measured memory_bytes: 12532
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
struct opt{int t,id;}Q[N];
bool cmp(opt a,opt b){return a.t<b.t;}
int X,n,q,a[N],ans[N],pre,suf,pre_V,suf_V;
int last,sig;
int main()
{
	scanf("%d%d",&X,&n);
	for (int i=1;i<=n;i++) scanf("%d",&Q[i].t);
	scanf("%d",&q);
	for (int i=1;i<=q;i++) scanf("%d%d",&Q[n+i].t,&a[i]),Q[n+i].id=i;
	sort(Q+1,Q+n+q+1,cmp);
	pre=pre_V=0;suf=suf_V=X;sig=-1;
	for (int i=1;i<=n+q;i++){
		int d=sig*(Q[i].t-last);last=Q[i].t;
		pre_V+=d;suf_V+=d;
		if (pre_V<0) pre=min(pre-pre_V,X),pre_V=0;
		pre_V=min(pre_V,X);
		if (suf_V>X) suf=max(suf+X-suf_V,0),suf_V=X;
		suf_V=max(suf_V,0);
		if (pre>=suf) pre=X,suf=0;
		if (Q[i].id){
			int id=Q[i].id;
			if (a[id]<=pre) ans[id]=pre_V;else
			if (a[id]>=suf) ans[id]=suf_V;else
			ans[id]=pre_V+a[id]-pre;
		}
		else sig=-sig;
	}
	for (int i=1;i<=q;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,l,t,x,w,ans[100001],p,s;
int main(){
	scanf("%d%d%d",&n,&l,&t);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x,&w);
        if(w==2)p=x-t;
        else p=x+t;
        if(p>0)s=(s+p/l)%n;
        if(p<0)s=(s+(p+1)/l-1)%n;
        ans[i]=(p%l+l)%l;
    }
    sort(ans+1,ans+n+1);
    if(s>=0)s=s%n;
    else{
    	p=(s+1)/n+1;
    	s=s+p*n;
	}
    for(int i=s+1;i<=n;i++)printf("%d\n",ans[i]);
    for(int i=1;i<=s;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 1536
#ABC-141-D
def main():
    n,m=map(int,input().split(" "))
    s=list(map(int,input().split(" ")))
    
    s.sort(reverse=True)
    while m!=0:
        tmp=s[0]//2
        s[0]=tmp
        m-=1
        for j in range(1,n):
            if m==0:
                break
            else:
                if s[j]>=tmp:
                    s[j]=s[j]//2
                    m-=1
                else:
                    break
        s.sort(reverse=True)
        if s[0]==0:
            break
    print(sum(s))
    
main()

Measured memory_bytes: 63708