akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;


int a[10000];

int main()
{
    int n,i,x,y,z;
    cin >> n;
    for(x = 1; x < n;x++)
    {
        for(y = 1;y < n;y++)
        {
            for(z = 1;(x*x+y*y+z*z+x*y+x*z+y*z) <= n;z++)
                a[x*x+y*y+z*z+x*y+x*z+y*z-1]++;
        }
    }
    for(i = 0;i < n;i++)
        cout << a[i] << endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

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

    ll X;
    cin >> X;
    ll r = (X-400)/200;
    cout << 8-r << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	scanf("%lld",&n);
	n=sqrt(n);
	printf("%lld",n*n);
}

Measured memory_bytes: 128
///not today

#include<bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

const int maxn = 1000* 100 + 5;
pll a[maxn];

int32_t main(){
    int n, ans = 0;
    cin >>n;
    for(int i = 0; i < n; i ++){
        cin >>a[i].F;
        a[i].S = i;
    }
    sort(a, a + n);
    for(int i = 0; i < n; i ++){
        if(a[i].S % 2 != i % 2)
            ans ++;
    }
    cout <<ans/ 2 <<endl;
    return false;
}


Measured memory_bytes: 1920
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, M, X = readnums()
    ca = [list(readnums()) for _ in range(N)]
    ans = 0
    for i in range(1, 2 ** N):
        c = bin(i)[2:]
        c = '0' * (N - len(c)) + c
        tmp = 0
        tmpl = []
        for i, x in enumerate(c):
            if int(x):
                if not tmpl:
                    tmpl += ca[i]
                else:
                    tmpl = [a + b for a, b in zip(tmpl, ca[i])]

                if all([i >= X for i in tmpl[1:]]):
                    tmp = tmpl[0]
                    if not ans:
                        ans = tmp
                    else:
                        ans = min(ans, tmp)

    print(ans if ans else -1)


if __name__ == "__main__":
    main()


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

long long N;
long long a[200005];

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		cin >> a[i];
	}

	for(long long i = 1; i < N; i++){
		a[i] += a[i-1];
	}

	long long ans = LONG_MAX;
	for(long long i = 0; i < N - 1; i++){
		ans = min(ans, abs(a[N-1] - a[i] - a[i]));
	}

	cout << ans << endl;
}


Measured memory_bytes: 1792
arr = list(map(int, input().split()))

m = max(arr)

cnt = 0

for i in range(3):
    if m - arr[i] >= 2:
        x = (m - arr[i]) // 2
        cnt += x

        arr[i] += x*2


arr.sort()

if arr[0] == arr[1] and arr[1] == arr[2]:
    pass
elif arr[0] < arr[1] and arr[1] < arr[2]:
    cnt += 3
elif arr[0] == arr[1] and arr[1] < arr[2]:
    cnt += 1
else:
    cnt += 2

print(cnt)


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    int n;
    cin>>n;
    map <ll,ll> m;
    ll ans=0;
    for (int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        ans+=m[i-x];
        m[i+x]++;
    }
    cout<<ans;





}

Measured memory_bytes: 26252
#include <bits/stdc++.h>
using namespace std;
#define tag "spoj"
#define maxn 100007
#define maxc 0
#define maxlog 17
#define oo 1000000007
#define mid ((l+r)>>1)
#define meset(a,x) memset(a,x,sizeof(a))
#define loop(x) for(int LoOpEr=1;LoOpEr<=x;LoOpEr++)
///>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
struct nodeTree{
    int anc[22];
    int depth;
    int len;
};

int n,m;

struct neigh{
    int ver,color,cost;
};
vector<neigh> adj[maxn];
#define add_edge(u,v,c,d) adj[u].push_back({v,c,d}),adj[v].push_back({u,c,d})

struct query{
    int u,v,lcanc;
    int col,wei;
    int sum,cnt;
};
vector<query> Q;
vector< vector<int> > add,sub;

vector<int> cntcol,sumcol;

vector<nodeTree> infor;
#define par(u) infor[u].anc[0]
#define ances(u,i) infor[u].anc[i]
#define depth(u) infor[u].depth
#define len(u) infor[u].len

void dfs(const int &u,const int &parent,const int &depth,const int &color,const int &cost)
{
    par(u)=parent;
    depth(u)=depth;
    len(u)=len(parent)+cost;

    for(int i=1;1<<i<n;i++) ances(u,i)=ances(ances(u,i-1),i-1);

    for(const neigh& e: adj[u])
        if(e.ver!=parent)
            dfs(e.ver,u,depth+1,e.color,e.cost);
}

void perfectQ(const int &u,const int &parent,const int &color,const int &cost)
{
    cntcol[color]+=1;
    sumcol[color]+=cost;

    for(const int &id: add[u]) Q[id].cnt+=cntcol[Q[id].col],Q[id].sum+=sumcol[Q[id].col];

    for(const int &id: sub[u]) Q[id].cnt-=2*cntcol[Q[id].col],Q[id].sum-=2*sumcol[Q[id].col];

    for(const neigh& e: adj[u])
        if(e.ver!=parent)
            perfectQ(e.ver,u,e.color,e.cost);

    cntcol[color]-=1;
    sumcol[color]-=cost;
}

int lca(int x,int y)
{
    if(depth(x)<depth(y)) swap(x,y);
    while(depth(x)>depth(y)) x=ances(x,(int)log2(depth(x)-depth(y)));

    int lg=log2(depth(x));

    while(x!=y)
    {
        while(lg>0 && ances(x,lg)==ances(y,lg)) --lg;
        x=ances(x,lg),y=ances(y,lg);
    }
    return x;
}

int answer(const query &q)
{
    return len(q.u)+len(q.v)-2*len(q.lcanc) - q.sum + q.wei*q.cnt;
}

void data()
{
    infor.resize(n+1);
    add.resize(n+1);
    sub.resize(n+1);
    cntcol.resize(n+1);
    sumcol.resize(n+1);
    for(auto &mation: infor) meset(mation.anc,0);
}
int main()
{
    #ifdef dmdd
    freopen(tag".inp","r",stdin); freopen(tag".out","w",stdout);
    #endif //dmdd
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin>>n>>m;
    data();

    int u,v,c,d;

    for(int i=1;i<n;i++) cin>>u>>v>>c>>d,add_edge(u,v,c,d);

    dfs(1,0,1,0,0);

    for(int i=0;i<m;i++)
        cin>>c>>d>>u>>v,
        Q.push_back({u,v,lca(u,v),c,d,0,0}),
        sub[lca(u,v)].push_back(i),
        add[u].push_back(i),add[v].push_back(i);

    perfectQ(1,0,0,0);

    for(const auto &q: Q) cout<<answer(q)<<"\n";

    return 0;
}


Measured memory_bytes: 32976
s=list(input())
s.reverse()
s_len = len(s)

list = [0 for _ in range(2019)]
ans = 0
mod = 2019
li = [0]
digit = 0
for i in range(s_len):
    li.append((li[i] + int(s[i])*pow(10,digit,mod))%mod)
    digit+=1
for i in range(s_len+1):
    list[li[i]]+=1
for i in range(2019):
    x = list[i]
    ans += x*(x-1)/2
print(int(ans))

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

#define ll long long
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;

const ll mod = (ll)(1e9 + 7);

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

    ll n;
    cin >> n;

    vll v(n);
    ll cur = 0;
    ll s = 0;

    for(ll i = 0; i < n; i++) cin >> v[i];

  	ll sum[n];
  	sum[0] = v[0];
  
    for(ll i = 1; i < n; i++){
        sum[i] = sum[i-1] + v[i];
    }

    for(ll i = 0; i < n; i++){
        cur = sum[n-1] - sum[i];

        s = ((s%mod) + (((v[i]%mod)*(cur%mod))%mod)%mod)%mod;
    }

    cout << s;


    return 0;
}


Measured memory_bytes: 6324
#include <iostream>

using namespace std;

int main(){
	int n;
	bool flag = false;
	cin >> n;

	if(n < 10){
		flag = true;
	}else if(n > 81){
		flag = false;
	}else{
		for(int i = 2; i <= 9; i++){
			if(n % i == 0 && n / i <= 9)
				flag = true;
		}
	}

	if(flag)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

fn main() {
    input!{
        H: usize,
        W: usize,
        S: [chars; H],
    }
    let mut L = vec![vec![0; W]; H];
    let mut R = vec![vec![0; W]; H];
    let mut D = vec![vec![0; W]; H];
    let mut U = vec![vec![0; W]; H];
    let mut max = 0;
    for h in 0..H {
        for w in 0..W {
            if S[h][w] == '#' {
                continue;
            }
            if w == 0 {
                L[h][w] = 1;
            } else if w > 0 {
                L[h][w] = L[h][w-1] + 1;
            }
            if h == 0 {
                U[h][w] = 1;
            } else if h > 0 {
                U[h][w] = U[h-1][w] + 1;
            }
        }
    }
    for h in (0..H).rev() {
        for w in (0..W).rev() {
            if S[h][w] == '#' {
                continue;
            }
            if w == W-1 {
                R[h][w] = 1;
            } else if w < W-1 {
                R[h][w] = R[h][w+1] + 1;
            }
            if h == H-1 {
                D[h][w] = 1;
            } else if h < H-1 {
                D[h][w] = D[h+1][w] + 1;
            }
        }

        for w in 0..W {
            max = std::cmp::max(max, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3);
        }
    }

    println!("{}", max);
}



Measured memory_bytes: 86268
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  int m,d;
  cin >> m >> d;
  vector<int> a;
  for(int i = 22;i <= d;i++){
    int j_10 = i/10;
    int j = i%10;
    if(j > 1 && j_10 > 1)
      a.push_back(j_10*j);
  }
  int count = 0;
  for(int i = 0;i < a.size();i++){
    if(a[i] >= 4 && a[i] <= m) count++;
  }
  cout << count << endl;
}


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

long long a[100010], b[100010];
long long l[100010], r[100010];
long long dp[100010];
long long sum[100010];
vector <long long> all;

struct Segment_tree{
	struct Node{
		int col;
	}T[400010];
	void pushdown(int now){
		if (T[now].col == 0) return ;
		int v = T[now].col; T[now].col = 0;
		T[now << 1].col = T[now << 1 | 1].col = v;
	}
	void Build(int now, int l, int r){
		T[now].col = 0;
		if (l == r){
			T[now].col = -1;
			return ;
		}
		int mid = l + r >> 1;
		Build(now << 1, l, mid), Build(now << 1 | 1, mid + 1, r);
	}
	void Update(int now, int l, int r, int L, int R, int x){
		if (L > R) return ;
		if (l == L && r == R){
			T[now].col = x;
			return ;
		}
		pushdown(now);
		int mid = l + r >> 1;
		if (R <= mid) Update(now << 1, l, mid, L, R, x);
		else if (L > mid) Update(now << 1 | 1, mid + 1, r, L, R, x);
		else Update(now << 1, l, mid, L, mid, x), Update(now << 1 | 1, mid + 1, r, mid + 1, R, x);
	}
	int Query(int now, int l, int r, int pos){
		if (l == r) return T[now].col;
		pushdown(now);
		int mid = l + r >> 1;
		if (pos <= mid) return Query(now << 1, l, mid, pos);
		return Query(now << 1 | 1, mid + 1, r, pos);
	}
}seg;

int main(){
	int n, k; scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++){
		scanf("%lld%lld", &a[i], &b[i]);
		sum[i] = sum[i - 1] + a[i];
		if (b[i] == 2){
			l[i] = 0, r[i] = k - 1;
			continue;
		}
		if (a[i] * 2 > k){
			printf("-1\n");
			return 0;
		}
		l[i] = (-2 * sum[i - 1]) % k + k, r[i] = (-2 * sum[i]) % k + k;
		all.push_back(l[i]), all.push_back(r[i]);
	}
	sort(all.begin(), all.end()), all.resize(unique(all.begin(), all.end()) - all.begin());
	int tot = all.size();
	for (int i = 1; i <= n; i++){
		l[i] = lower_bound(all.begin(), all.end(), l[i]) - all.begin();
		r[i] = lower_bound(all.begin(), all.end(), r[i]) - all.begin();
	}
	dp[n] = 0;
	seg.Build(1, 0, tot - 1);
	for (int i = n; i >= 1; i--){
		int pos = seg.Query(1, 0, tot - 1, l[i]);
		if (pos != -1) dp[i] = dp[pos] + (all[l[pos]] - all[l[i]] + k) % k;
		else dp[i] = 0;
		if (l[i] <= r[i]){
			seg.Update(1, 0, tot - 1, 0, l[i] - 1, i), seg.Update(1, 0, tot - 1, r[i] + 1, tot - 1, i);
		}
		else seg.Update(1, 0, tot - 1, r[i] + 1, l[i] - 1, i);
	}
	long long ans = dp[1];
	for (int i = 0; i < tot; i++){
		int pos = seg.Query(1, 0, tot - 1, i);
		if (pos != -1) ans = min(ans, dp[pos] + (all[l[pos]] - all[i] + k) % k);
		else ans = 0;
	}
	printf("%lld\n", ans + sum[n] * 2);
	return 0;
}

Measured memory_bytes: 8176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i]; 
  }
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=n-1;i>=0;i--){
    if(i%2==0)ans+=a[i];
    else ans-=a[i];
  }
  if(ans<0)ans*=-1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

ll mod = 1000000007;


void swap(ll &a, ll &b){
    ll c = a;
    a = b;
    b = c;
}

ll modadd(ll a, ll b){
    return (a+b)%mod;
}

ll modsub(ll a, ll b){
    ll c = (a-b)%mod;
    if(c < 0){
        c += mod;
    }
    return c;
}

ll modmul(ll a, ll b){
    return ((a%mod) * (b%mod)) % mod;
}

ll modinv(ll a) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

ll moddiv(ll a, ll b) {
    return ((a%mod) * (modinv(b))) % mod;
}


ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = modmul(res, a);
        a = modmul(a,a);
        n >>= 1;
    }
    return res;
}

ll modcomb(ll a, ll b){
    ll x = 1;
    for(int i=0; i<b; i++){
        x = modmul(x, modsub(a,i));
    }
    ll y = 1;
    for(int i=0; i<b; i++){
        y = modmul(y, modsub(b,i));
    }
    return moddiv(x,y);
}

int main(){
    ll N;
    cin >> N;
    ll a = modpow(10, N);
    ll b = modpow(9, N);
    ll c = modpow(9, N);
    ll d = modpow(8, N);
    ll ans = modadd(modsub(modsub(a, b), c), d);

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

Measured memory_bytes: 3632
// failed to generate code

#include <bits/stdc++.h>
using namespace std;

bool flg[3000][3001][2];

long long dp[3000][3001][2];
int N;
vector<int> a;

long long op(long long a,long long b,int f){
    if( f == 0 ) return max(a, b);
    else return min(a, b);
}
long long coef(int f){
    return f == 0 ? 1 : -1;
}

long long dfs(int l, int r,int f){
    if( flg[l][r][f] ) return dp[l][r][f];
    if( r - l == 1 ) return coef(f) * a[l];

    flg[l][r][f] = true;
    return dp[l][r][f] = op(dfs(l, r-1, f^1) + a[r-1] * coef(f), dfs(l+1, r, f^1) + a[l] * coef(f) , f);;
}
int main(){
    memset(dp, -1, sizeof(dp));
    ios::sync_with_stdio(false);

    cin >> N;
    a.resize(N);
    for(int i = 0 ; i < N ; i++) cin >> a[i];

    cout << dfs(0, N, 0) << endl;
}


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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
typedef long long ll;


int main(){
    ll N,M,res=0;
    cin >> N >> M;
    res =(ll) (18*M+N)*100*pow(2,M);
    cout << res << endl;
  }


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main()
{
	int scene[100][100],chip[4][50][50];
	for(int n,m;scanf("%d%d",&n,&m),n;){
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				scanf("%d",scene[i]+j);
		for(int i=0;i<m;i++)
			for(int j=0;j<m;j++)
				scanf("%d",chip[0][i]+j);

		for(int i=0;i<m;i++)
			for(int j=0;j<m;j++)
				chip[1][i][j]=chip[0][m-j-1][  i  ],
				chip[2][i][j]=chip[0][m-i-1][m-j-1],
				chip[3][i][j]=chip[0][  j  ][m-i-1];

		int xtip[4],ytip[4];
		bool b=false;
		for(int k=0;k<4;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(chip[k][i][j]!=-1){
						xtip[k]=j;
						ytip[k]=i;
						b=true;
						break;
					}
				}
				if(b)	break;
			}
		}

		bool found=false;
		int xmin=200,ymin=200;
		for(int i=0;i<n-m+1;i++){
			for(int j=0;j<n-m+1;j++){
				for(int k=0;k<4;k++){
					bool match=true;
					for(int y=0;y<m;y++){
						for(int x=0;x<m;x++){
							if(chip[k][y][x]==-1)	continue;
							if(chip[k][y][x]!=scene[i+y][j+x]){
								match=false;
								break;
							}
						}
						if(!match)	break;
					}
					if(match){
						int xx=j+xtip[k],yy=i+ytip[k];
						if(ymin>yy || (ymin==yy&&xmin>xx)){
							xmin=xx;
							ymin=yy;
						}
						found=true;
					}
				}
			}
		}
		printf(found?"%d %d\n":"NA\n",xmin+1,ymin+1);
	}

	return 0;
}

Measured memory_bytes: 832
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
#define ll long long 
#define il inline
const int maxn=200010;
vector<int> G[maxn];
int col[maxn],siz[maxn],tot;
int n,m;
int ra,rb;
void dfs(int x){
    col[x]=tot; ++siz[tot];
    for (int i=0;i<G[x].size();++i){
        int v=G[x][i];
        if (col[v]) continue;
        dfs(v);
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;++i){
        scanf("%d%d",&ra,&rb);
        G[ra].push_back(rb);
        G[rb].push_back(ra);
    }
    for (int i=1;i<=n;++i){
        if (!col[i]){
            ++tot; dfs(i);
        }
    }
    int mx=0;
    for (int i=1;i<=tot;++i){
        mx=max(mx,siz[i]);
    }
    printf("%d",mx);
}

Measured memory_bytes: 21784
#include <iostream>
#include <map>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int N;
typedef pair<int, int> P;
vector<string> mp;
vector<P> wp;

int comp(P a, P b) {
	return a.second > b.second;
}

int main() {
	bool first = true;
	while (true) {
		cin >> N;
		if (N == 0) {return 0;}
		if (!first) {
			cout << endl;
		}
		first = false;
		mp.clear();
		wp.clear();
		for (int i = 0; i < N; i++) {
			string country;
			cin >> country;
			int w, d, l;
			cin >> w >> l >> d;
			mp.push_back(country);
			wp.push_back(P(i, 3 * w + d));
		}
		stable_sort(wp.begin(), wp.end(), comp);
		for (int i = 0; i < wp.size(); i++) {
			cout << mp[wp[i].first] << "," << wp[i].second << endl;
		}
	}
}

Measured memory_bytes: 0
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        es: [(usize1, usize1); n - 1]
    }
    let d = 1000000007;
    let mut t = vec![vec![]; n];
    for &(a, b) in &es {
        t[a].push(b);
        t[b].push(a);
    }
    let mut dp = vec![vec![vec![0, 0]; 2]; n];
    dfs(0, 0, &t, &mut dp, d);
    println!("{}", (dp[0][0][1] + d - dp[0][0][0]) % d);
}

fn dfs(v: usize, par: usize, t: &Vec<Vec<usize>>, dp: &mut Vec<Vec<Vec<usize>>>, d: usize) -> usize {
    dp[v][1][0] = 1;
    let mut n = 1;
    for &c in &t[v] {
        if c == par {
            continue;
        }
        let nv = dfs(c, v, t, dp, d);
        let mut next = vec![vec![0, 0]; n + nv + 1];
        for i in 1..n + 1 {
            for j in 0..nv + 1 {
                for p in 0..2 {
                    for q in 0..2 {
                        next[i + j][p] = (next[i + j][p] + dp[v][i][q] * dp[c][j][p ^ q]) % d;
                    }
                }
            }
        }
        dp[v] = next;
        n += nv;
    }
    let mut g = 1;
    let mut i = 2;
    while i <= n {
        g = g * (i - 1) % d;
        for p in 0..2 {
            dp[v][0][p] = (dp[v][0][p] + g * dp[v][i][1 - p]) % d;
        }
        i += 2;
    }
    n
}


Measured memory_bytes: 390268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll sumR[n + 1] = {}, sumG[n + 1] = {}, sumB[n + 1] = {};
    rep(i, n) {
        sumR[i + 1] += sumR[i] + (s[i] == 'R' ? 1 : 0);
        sumG[i + 1] += sumG[i] + (s[i] == 'G' ? 1 : 0);
        sumB[i + 1] += sumB[i] + (s[i] == 'B' ? 1 : 0);
    }
    ll ans = 0;
    rep(i, n) {
        if(s[i]=='R'){
            ans +=
                sumG[i] * (sumB[n] - sumB[i]) + sumB[i] * (sumG[n] - sumG[i]);
            for (int j = 1; j < n - 1; j++){
                if (i - j < 0 || n <= i + j) break;
                if ((s[i + j] == 'G' && s[i - j] == 'B') ||
                    (s[i + j] == 'B' && s[i - j] == 'G')) {
                    ans--;
                }
            }
        } else if (s[i] == 'G') {
            ans +=
                sumR[i] * (sumB[n] - sumB[i]) + sumB[i] * (sumR[n] - sumR[i]);
            for (int j = 1; j < n - 1; j++) {
                if (i - j < 0 || n <= i + j) break;
                if ((s[i + j] == 'R' && s[i - j] == 'B') ||
                    (s[i + j] == 'B' && s[i - j] == 'R')) {
                    ans--;
                }
            }
        } else {
            ans +=
                sumG[i] * (sumR[n] - sumR[i]) + sumR[i] * (sumG[n] - sumG[i]);
            for (int j = 1; j < n - 1; j++) {
                if (i - j < 0 || n <= i + j) break;
                if ((s[i + j] == 'G' && s[i - j] == 'R') ||
                    (s[i + j] == 'R' && s[i - j] == 'G')) {
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3684
using System;
class Project3
{
    public static void Main(string[] args)
    {
        string a = Console.ReadLine();
        int b = a.Length - 1;
        if (a[b] == '2' || a[b] == '4' || a[b] == '5' || a[b] == '7' || a[b] == '9')
        {
            Console.WriteLine("hon");
        }
        else if (a[b] == '0' || a[b] == '1' || a[b] == '6' || a[b] == '8')
        {
            Console.WriteLine("pon");
        }
        else if (a[b] == '3')
        {
            Console.WriteLine("bon");
        }
    }
}

Measured memory_bytes: 17380
#include<iostream>
using namespace std;
int main(){
    int H, W,b = 0;
    while(b == 0){
    cin >> H >> W;
    if(H == 0 && W == 0)
    break;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
        if((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
        cout << "#";
        else if ((i % 2 == 0 && j % 2 != 0) || (i % 2 != 0 && j % 2 == 0))
        {
            cout << ".";
        }
        if(j == W - 1)
        cout << endl;
        }
    }
    cout << endl;
}
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  ll N, M; cin >> N >> M;
  string S, T; cin >> S >> T;
  ll L = boost::lcm(N, M);
  map<ll, char> m{};
  for (int i = 0; i < N; ++i) {
    m[L / N * i + 1] = S[i];
  }
  for (int i = 0; i < M; ++i) {
    char c = m[L / M * i + 1];
    if (c && c != T[i]) {
      cout << -1 << CRLF;
      return;
    }
  }
  cout << L << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  int n,k;
  string s;
  cin>>n>>k;
  cin>>s;

  if(s.at(k-1) =='A')s.at(k-1) = 'a';
  if(s.at(k-1) =='B')s.at(k-1) = 'b';
  if(s.at(k-1) =='C')s.at(k-1) = 'c';
  cout<<s<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;

int n;
char a[N];

int ans[N];

int ast[N];

int yans[N];

void solv()
{
    scanf("%d", &n);
    scanf(" %s", a);
    for (int i = 1; i < N; ++i)
    {
        ans[i] = ans[(i % __builtin_popcount(i))] + 1;
    }

    int q = 0;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] == '1')
            ++q;
    }

    if (q - 1 > 0)
    {
        ast[0] = 1 % (q - 1);
        for (int i = 1; i < n; ++i)
        {
            ast[i] = (ast[i - 1] * 2) % (q - 1);
        }
        int s = 0;
        for (int i = 0; i < n; ++i)
        {
            if (a[i] == '1')
            {
                s = (s + ast[n - i - 1]) % (q - 1);
            }
        }
        for (int i = 0; i < n; ++i)
        {
            if (a[i] == '1')
            {
                s = (s - ast[n - i - 1] + (q - 1)) % (q - 1);
                yans[i] = ans[s] + 1;
                s = (s + ast[n - i - 1]) % (q - 1);
            }
        }
    }
    if (q + 1 > 0)
    {
        ast[0] = 1 % (q + 1);
        for (int i = 1; i < n; ++i)
        {
            ast[i] = (ast[i - 1] * 2) % (q + 1);
        }
        int s = 0;
        for (int i = 0; i < n; ++i)
        {
            if (a[i] == '1')
            {
                s = (s + ast[n - i - 1]) % (q + 1);
            }
        }
        for (int i = 0; i < n; ++i)
        {
            if (a[i] == '0')
            {
                s = (s + ast[n - i - 1]) % (q + 1);
                yans[i] = ans[s] + 1;
                s = (s - ast[n - i - 1] + (q + 1)) % (q + 1);
            }
        }
    }
    for (int i = 0; i < n; ++i)
        printf("%d\n", yans[i]);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


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

#define ll long long

int main()
{
 	unordered_map<int,int> m;
	ll i,n,q,k,temp;
	cin>>n;
	cin>>k;
	cin>>q;
	for( i = 1 ; i <= n ; i++)
	m[i] = k-q;
	for( i = 0 ; i < q ; i++)
	{
		cin>>temp;
		m[temp]++;
	}
	for( i = 1 ; i <= n ; i++)
	{
		if(m[i] > 0)
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 4772
MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = 'aizu
  aaa aizu xxx xx x xxx aizu y yyyy a a a a a a aizu 
  aaa aa xxx WWW AAA aize aiza AIZZ AAA III a i z u aizu aizu aizu
  SSS SS S aizu AAAAAAA a a a a a x x x x aizu zia uzia uzia aizu aizu aizu aizu
  Aizu hyoooon pupupupu ohohohoh
  aa eee fff eee fff ee f f f f f f f AIZU bebebebebebe ai zu a izu aiz u
  Aizu aizu Aizu AIzU
  end_of_text
  END_OF_TEXP
  aizu Aizu
  END_OF_TEXT'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

w = line[0].downcase
s = ""
n=1
while true
  a = line[n]
  break if a=="END_OF_TEXT"
  s += a.downcase + " "
  n += 1
end

puts s.split(" ").count(w)

Measured memory_bytes: 9184
# -*- coding: utf-8 -*-
def main():
    N, K = map(int, input().split())
    if K%2==0:
        A = N//K
        B = N//(K//2)
        print(A**3+(B-A)**3)
    else:
        A = N//K
        print(A**3)
if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int h, w, d;
    cin >> h >> w >> d;
    vector<P> a(h*w+1);
    rep(i, h) {
        rep(j, w) {
            int x;
            cin >> x;
            a[x] = make_pair(i, j);
        }
    }

    vector<int> b(h*w+1, 0);
    for (int i = h * w + 1; i > 0; --i) {
        if (i + d > h * w + 1) continue;
        b[i] = abs(a[i].first - a[i + d].first) + abs(a[i].second - a[i + d].second) + b[i+d];
    }

    int q;
    cin >> q;
    rep(i, q) {
        ll ans = 0;
        int l, r;
        cin >> l >> r;
        cout << b[l] - b[r] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main(){

  int n,r[100],s[100],p[100],c[100],cnt,result=114514;
  cin>>n;
  for(int i=0;i<n;i++) cin>>r[i];
  for(int i=0;i<n;i++) cin>>s[i]>>p[i]>>c[i];
  //s
  for(int i=s[0]+1;i<=100;i++){
    int sum[100]={};
    vector <int> s1,p1,c1;
    s1.push_back(i);
    for(int j=1;j<n;j++) s1.push_back(s[j]);
    sort(s1.begin(),s1.end());
    reverse(s1.begin(),s1.end());
    for(cnt=0;cnt<n;cnt++) if(i==s1[cnt]) break;
    sum[0]+=r[cnt];
    for(int j=1;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(s[j]==s1[cnt]) break;
      sum[j]+=r[cnt];
    }
    for(int j=0;j<n;j++) p1.push_back(p[j]);
    sort(p1.begin(),p1.end());
    reverse(p1.begin(),p1.end());
    for(int j=0;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(p[j]==p1[cnt]) break;
      sum[j]+=r[cnt];
    }
    for(int j=0;j<n;j++) c1.push_back(c[j]);
    sort(c1.begin(),c1.end());
    reverse(c1.begin(),c1.end());
    for(int j=0;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(c[j]==c1[cnt]) break;
      sum[j]+=r[cnt];
    }
    int me=sum[0];
    sort(sum,sum+n);
    reverse(sum,sum+n);
    if(me>=sum[7]) result=min(result,i-s[0]);
  }
  //p
  for(int i=p[0]+1;i<=100;i++){
    int sum[100]={};
    vector <int> s1,p1,c1;
    p1.push_back(i);
    for(int j=1;j<n;j++) p1.push_back(p[j]);
    sort(p1.begin(),p1.end());
    reverse(p1.begin(),p1.end());
    for(cnt=0;cnt<n;cnt++) if(i==p1[cnt]) break;
    sum[0]+=r[cnt];
    for(int j=1;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(p[j]==p1[cnt]) break;
      sum[j]+=r[cnt];
    }
    for(int j=0;j<n;j++) s1.push_back(s[j]);
    sort(s1.begin(),s1.end());
    reverse(s1.begin(),s1.end());
    for(int j=0;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(s[j]==s1[cnt]) break;
      sum[j]+=r[cnt];
    }
    for(int j=0;j<n;j++) c1.push_back(c[j]);
    sort(c1.begin(),c1.end());
    reverse(c1.begin(),c1.end()); 
    for(int j=0;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(c[j]==c1[cnt]) break;
      sum[j]+=r[cnt];
    }
    int me=sum[0];
    sort(sum,sum+n);
    reverse(sum,sum+n);
    if(me>=sum[7]) result=min(result,i-p[0]);
  }
  //c
  for(int i=c[0]+1;i<=100;i++){
    int sum[100]={};
    vector <int> s1,p1,c1;
    c1.push_back(i);
    for(int j=1;j<n;j++) c1.push_back(c[j]);
    sort(c1.begin(),c1.end());
    reverse(c1.begin(),c1.end());
    for(cnt=0;cnt<n;cnt++) if(i==c1[cnt]) break;
    sum[0]+=r[cnt];
    for(int j=1;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(c[j]==c1[cnt]) break;
      sum[j]+=r[cnt];
    }
    for(int j=0;j<n;j++) p1.push_back(p[j]);
    sort(p1.begin(),p1.end());
    reverse(p1.begin(),p1.end());
    for(int j=0;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(p[j]==p1[cnt]) break;
      sum[j]+=r[cnt];
    }
    for(int j=0;j<n;j++) s1.push_back(s[j]);
    sort(s1.begin(),s1.end());
    reverse(s1.begin(),s1.end());
    for(int j=0;j<n;j++){
      for(cnt=0;cnt<n;cnt++) if(s[j]==s1[cnt]) break;
      sum[j]+=r[cnt];
    }
    int me=sum[0];
    sort(sum,sum+n);
    reverse(sum,sum+n);
    if(me>=sum[7]) result=min(result,i-c[0]);
  }
  if(result==114514) cout<<"Saiko"<<endl;
  else  cout<<result<<endl;
  return 0;
    
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
using namespace std;
using P = pair<int, int>;
const int inf = 2e18;
const int mod = 1e9 + 7;

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

template <class T>
vector<T> make_vec(size_t a) {
  return vector<T>(a);
}

template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template <class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
  t = v;
}

template <class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
  for (auto &e : t) fill(e, v);
}

signed main() {
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    cout << "ACL";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  int ma = 0;
  int x = 0;
  rep(i, n){
    char c;
    cin >> c;
    if(c == 'I') x++;
    else if(c == 'D') x--;
    chmax(ma, x);
  }

  cout << ma << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

int top, S[1000];

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    return S[top + 1];
}

int main(){
  int a, b;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
        a = pop();
        b = pop();
        push(a + b);
    } else if ( s[0] == '-' ){
        b = pop();
        a = pop();
        push(a - b);

    } else if ( s[0] == '*' ){
        a = pop();
        b = pop();
        push(a * b);
    } else {
       push(atoi(s));

    }
  }
  printf("%d\n", pop());
  return 0;
}


Measured memory_bytes: 2764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    N, X, M = map(int, input().split())

    if N == 1:
        print(X)
        return

    A = X
    steps = [0] * M
    sms = [0] * M
    steps[A] = 1
    sms[A] = A
    sm = A
    ans = A
    rest = 0
    for i in range(2, N+1):
        A = (A*A) % M
        sm += A
        ans += A
        if steps[A] != 0:
            P = i - steps[A]
            v = sm - sms[A]
            rest = N - i
            ans += v * (rest//P)
            rest %= P
            break
        steps[A] = i
        sms[A] = sm

    for i in range(rest):
        A = (A*A) % M
        ans += A

    print(ans)


solve()


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

int main(void) {

	int n, a,frag = 1;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0)frag = 0;
	}

	if (frag == 1)cout << "APPROVED";

	else cout << "DENIED";

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int Sum(int N);

int main(){
    int N, A, B, sum = 0;
    scanf("%d %d %d", &N, &A, &B);

    for(int i = 1; i <= N; i++){
        if(A <= Sum(i) && Sum(i) <= B){
            sum += i;
        }
    }
  
    printf("%d\n", sum);
    return 0;
}

int Sum(int N){
    int sum = 0;

    for(int i = N; i > 0; i /= 10){
        sum += i % 10;
    }

    return sum;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define X first
#define Y second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=1e9+7;
const ll MAXN=1e6+5;
const ll inf=1e18;



int main()
{
    fastio;
    char ch;
    cin>>ch;
    ch++;
    cout<<ch<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
 
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for(int i = 0; i < n; i++)
#define LL long long
const int mod = 1e9 + 7;
const int inf = 1e9;


int n;

int main() {
    //freopen("in", "r", stdin);
    scanf("%d", &n);
    bool flag = true;
    for(int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        if(x % 2 == 0) {
            if(x % 3 != 0 && x % 5 != 0) {
                flag = false;
            }
        }
    }
    if(flag) puts("APPROVED");
    else puts("DENIED");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;

int cnt[100100];

int main() {
	cin >> n;
	rep(i, n) {
		int num;
		cin >> num;
		cnt[num]++;
		if (num >= 1)cnt[num - 1]++;
		cnt[num + 1]++;
	}
	int MAX = 0;
	rep(i, 100100) {
		MAX = max(MAX, cnt[i]);
	}
	cout << MAX << endl;
}

Measured memory_bytes: 640
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
int dp[2][20010] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,N;
    cin >> H >> N;
    int A[1010], B[1010];
    rep(i,0,N) cin >> A[i] >> B[i];
    rep(j,0,20001){
        dp[0][j] = 1e9+7;
        dp[1][j] = 1e9+7;
    }
    dp[0][0] = 0;
    ll cur = 0, nxt = 1;
    rep(i,0,N){
        rep(j,0,20001){
            if(j < A[i]){
                dp[nxt][j] = dp[cur][j];
            }else{
                dp[nxt][j] = min(dp[cur][j], dp[nxt][j - A[i]] + B[i]);
            }
        }
        cur ^= 1; nxt ^= 1;
    }

    int ans = 1e9+7;
    rep(i,H,20001){
        ans = min(ans, dp[cur][i]);
    }
    print(ans);

    

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int d[100001];
int main(void){
	int	n,m;
	int s,t;
	int q;
	int i,j;
	int x,y;
	int cnt;
	vector<int>v[100001];
	queue<int>que;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>s>>t;
		v[s].push_back(t);
		v[t].push_back(s);
	}
	for(i=0;i<n;i++)	d[i]=0;
	cnt=0;
	for(i=0;i<n;i++){
		if(d[i]==0){
			cnt++;
			d[i]=cnt;
			que.push(i);
			while(!que.empty()){
				x=que.front();
				que.pop();
				for(j=0;j<v[x].size();j++){
					y=v[x][j];
					if(d[y]==0){
						d[y]=cnt;
						que.push(y);
					}
				}
			}
		}
	}
	cin>>q;
	for(i=0;i<q;i++){
		cin>>s>>t;
		cout<<((d[s]==d[t])?"yes":"no")<<endl;
	}
	
	return 0;
}
			
	


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int k;
	cin>>k;
	ll ans = 0;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			int g = __gcd(i, j);
			for(int l = 1; l <= k; l++){
				ans += __gcd(g, l);
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3652
n=int(input())
A=[0]+list(map(int, input().split()))+[0]

cost=0

for i in range(n+1):
    cost+=abs(A[i+1]-A[i])

for k in range(1, n+1):
    ans=cost+abs(A[k+1]-A[k-1])-(abs(A[k]-A[k-1])+abs(A[k+1]-A[k]))
    print(ans)

Measured memory_bytes: 14048
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXDIGITS 4

int getSum(int);

int
main(){
  int n, a, b, temp, sum = 0;
  int i;
  scanf("%d %d %d", &n, &a, &b);
  if(n < 1 || 10000 < n || a < 1 || 36 < b || b < a )
    return 1;

  for(i = 0; i <= n; i++){
    temp = getSum(i);
    if ( a <= temp && temp <= b)
      sum += i;
  }
  printf("%d\n", sum);
  return 0;
}

int
getSum(int input){
  int i, ret = 0;
  for( i = 0; i < MAXDIGITS + 1; i++){
    ret += input % 10;
    input = input / 10;
    if(!input)
      break;
  }
  return ret;
}

Measured memory_bytes: 128