akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
 
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(){
  int i,n,a[128];
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d",&a[i]);}
  qsort(a,n,sizeof(int),sortfncsj);
  printf("%d",a[n-1]-a[0]);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <vector>
using namespace std;
int main(){

	int A=0,B=0,M=0,temp=0;
	int minA = INT_MAX, minB = INT_MAX, WARI_MIN=0;
	vector<int> a,b,waribiki;

	cin >> A >> B >>M;

	for(int i=0,m=0; i<=A && m<B; i==A ? m++ : i++){
		cin >> temp;
		if(i!=A){
			if(minA > temp) minA = temp;
			a.push_back(temp);
		}else{
			if(minB > temp) minB = temp;
			b.push_back(temp);
		}
	}
	WARI_MIN = minA+minB;
	//waribiki
	for(int i=0;i<M;i++){
		cin >> A >> B >> temp;
		if(a[A-1]+b[B-1]-temp < WARI_MIN)
			WARI_MIN = a[A-1]+b[B-1]-temp;
	}
	cout << WARI_MIN << endl;
	return 0;
}

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

int main()
{
    //データ定義
    int matrix[101][101];
    int row;
    int column;
    int i;
    int j;
    int w_num;
    int row_total[101] = {0};
    int column_total[101] = {0};
    int sum = 0;

    //データ入力
    cin >> row >> column;

    for(i = 0; i < row; i++)
    {
        for(j = 0; j < column; j++)
        {
            cin >> w_num;
            cout << w_num << " ";
            
            row_total[i] += w_num;
            column_total[j] += w_num;
        }
        cout << row_total[i] << endl;
        sum += row_total[i];
    }
    for(j = 0; j < column; j++)
    {
        cout << column_total[j] << " ";
    }
    
    cout << sum << endl;

    return 0;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> m(n);
  rp(i,n) {cin >> m.at(i);
           x-=m.at(i);}
  sort(m.begin(),m.end());
  cout << n+(x/m.at(0)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
struct Point{
    int x, y;
};
int dist(Point a, Point b){
    return abs(a.x - b.x) + abs(a.y - b.y);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M;
    cin >> N >> M;
    Point points[N];
    Point gather[M];
    for(int i = 0; i < N; ++i){
        cin >> points[i].x >> points[i].y;
    }
    for(int i = 0; i < M; ++i){
        cin >> gather[i].x >> gather[i].y;
    }
    int ans[N];
    for(int i = 0; i < N; ++i){
        int now = 1e9;
        int idx;
        for(int j = 0; j < M; ++j){
            if(now > dist(points[i], gather[j])){
                now = dist(points[i], gather[j]);
                idx = j+1;
            }
        }
        ans[i] = idx;
    }
    
    for(int x : ans) cout << x << endl;
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    vector<bool> water(F+1, false), sugar(F+1, false);
    for(int i=0; i<=30; i++){
        for(int j=0; j<=30; j++){
            int tmp = 100*A*i+100*B*j;
            if(tmp <= F)
                water[tmp] = true;
        }
    }
    for(int i=0; i<=3000; i++){
        for(int j=0; j<=3000; j++){
            int tmp = C*i+D*j;
            if(tmp <= F)
                sugar[tmp] = true;
        }
    }
    int w = 100*A, s = 0;
    for(int i=0; i<=F; i++){
        for(int j=0; j<=F-i; j++){
            if(!water[i] || !sugar[j]) continue;
            if(100*j > i*E) continue;
            if(j*(w+s) > s*(i+j)){
                w = i;
                s = j;
            }
        }
    }
    cout << w+s << " " << s << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
dp = [0,abs(H[1]-H[0])]
for i in range(N-2):
    dp.append(min(dp[i]+abs(H[i+2]-H[i]),dp[i+1]+abs(H[i+2]-H[i+1])))
print(dp[-1])

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  string al = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";

  for(int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 26; j++) {
      if (s.at(i) == al.at(j)) {
        cout << al.at(j+n);
      }
    }
  }
  cout << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll s,x,y;
  ll max = 1000000000;
  cin >> s;
  x = (max-s%max)%max;
  y = (s+x)/max;
  cout << "0 0 1000000000 1 "<< x << " "<< y << endl;
}
  
  


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadLong;
            var func = new Func();
            long A =0;
            long B =0;
            long ans = 0;
            var first = true;
            
            for(int i = 1; i<=Math.Sqrt(N); i++){
                
                A = i;
                B = N%A == 0? N/A : 0 ;
                
                if(B!=0){
                    if(first){
                        ans = func.funcA(A,B);
                        first = false;
                    }else{
                        var result = func.funcA(A,B);
                        ans = ans < result? ans : result;
                    }
                }
            }
            
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
    public class Func
    {
        public int funcA(long A, long B){
        var countA =0;
        var countB =0;
        
        while(A > 0){
            countA = countA + 1;
            A/=10;
        };
        while(B > 0){
            countB = countB + 1;
            B/=10;
        };
        return Max(countA,countB);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
 
int main(){
    int n,m; cin>>n>>m;
    int ans=1;
    FOR(i,0,m){
        ans*=2;
    }
    cout<<(1800*m+100*n)*ans;
    return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
char_c = [0] * h

for i in range(h):
    c = input()
    char_c[i] = list(c)

ans = 0
for row_bit in range(2 ** h):
    for col_bit in range(2 ** w):
        count = 0
        for row in range(h):
            if ((row_bit >> row) & 1):
                continue
            for col in range(w):
                if ((col_bit >> col) & 1):
                    continue
                #print(char_c[row][col], end='')
                if char_c[row][col] == '#':
                    count += 1
            # print()
        if count == k:
            ans += 1
print(ans)

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 998244353
#define SYOU(x) fixed<<setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol n,m,a,b,c,d;
  string s,w;
  cin >>n;
  lol ans=(n/500)*1000;
  n=n%500;
  ans+=5*(n/5);
  cout <<ans<<'\n';
  return (0);
}


Measured memory_bytes: 256
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    X = ii()
    print('Yes' if X >= 30 else 'No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9564
#include <iostream>
#include <string> 
using namespace std;
int a[10000][3];
int main()
{
	int N,H,W,sum=0;
	cin>>N>>H>>W;
	for(int i=0;i<N;i++)
	{
		cin>>a[i][0]>>a[i][1];
		if(a[i][0]>=H&&a[i][1]>=W)
			sum++;
	}	
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());

    if (N < 1000) {
      System.out.println("ABC");
    } else {
      System.out.println("ABD");
    }
  }
}

Measured memory_bytes: 24916
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, m) cin >> b[i];

  vector<ll> va(n + 1, 0), vb(m + 1, 0);
  rep(i, 0, n) va[i + 1] = va[i] + a[i];
  rep(i, 0, m) vb[i + 1] = vb[i] + b[i];

  int ans = 0, j = m;
  rep(i, 0, n + 1) {
    if (va[i] > k)
      break;
    while (vb[j] > k - va[i])
      j -= 1;
    chmax(ans, i + j);
  }

  cout << ans << endl;
}


Measured memory_bytes: 7932
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(){
	char a,b,c,d,e,f;
	scanf("%c%c%c",&a,&b,&c);
	getchar();
	scanf("%c%c%c",&d,&e,&f);
	getchar();
	if(a==f && b==e && c==d)
		printf("YES\n");
		else
			printf("NO\n");
	}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int H, N;
	cin >> H >> N;
	ll sum = 0;
	REP(i, N) {
		int A;
		cin >> A;
		sum += A;
	}
	if (sum >= H) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>

using namespace std;

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

  int n;
  cin >> n;

  list<int> l;
  for(int i = 0; i < n; i++) {
    string command;
    cin >> command;
    if(command == "insert") {
      int x;
      cin >> x;
      l.push_front(x);
    } else if(command == "delete") {
      int x;
      cin >> x;
      for(list<int>::iterator i = l.begin(); i != l.end(); i++) {
        if(*i == x) {
          l.erase(i);
          break;
        }
      }
    } else if(command == "deleteFirst") {
      l.pop_front();
    } else if(command == "deleteLast") {
      l.pop_back();
    }
  }

  list<int>::iterator i;
  for(i = l.begin(); i != --l.end(); i++) {
    cout << *i << " ";
  }
  cout << *i << endl;

  return 0;
}


Measured memory_bytes: 34368
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
  char a;
  cin >> a;
  if(a>=97 && a<=122)
  {
    a='a';
  }
  else if(65<=a &&a<=90)
  {
    a='A';
  }
  cout <<a;
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main(){
  int x, a;
  cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N, M, P[Nmax], X[Nmax], Y[Nmax];

class UnionFind{
	vector<int> par, rnk, cnt;
	public:
	UnionFind(int n){
		par=vector<int>(n);
		rnk=vector<int>(n,0);
		cnt=vector<int>(n,1);
		for(int i=0; i<n; i++) par[i]=i;
	}
	int root(int i){
		if(par[i]==i) return i;
		return par[i]=root(par[i]);
	}
	void unite(int i, int j){
		int ri = root(i);
		int rj = root(j);
		if(ri==rj) return;

		if(rnk[ri]==rnk[rj]){
			cnt[rj] += cnt[ri];
			par[ri] = rj;
			rnk[rj]++;
		}
		else if(rnk[ri] < rnk[rj]){
			cnt[rj] += cnt[ri];
			par[ri] = rj;
		}
		else{
			cnt[ri] += cnt[rj];
			par[rj] = ri;
		}
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	int count(int i){
		return cnt[root(i)];
	}
};

int main(){
	cin >> N >> M;
	for(int i=0; i<N; i++){
		cin >> P[i];
		P[i]--;
	}
	for(int i=0; i<M; i++){
		cin >> X[i] >> Y[i];
		X[i]--; Y[i]--;
	}

	UnionFind uf(N);
	for(int i=0; i<M; i++){
		uf.unite(X[i], Y[i]);
	}

	int ans = 0;
	for(int i=0; i<N; i++){
		if(uf.same(P[i], i)) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int n, s[100];
int sum = 0;
bool can[10001] = {};

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

	can[0] = true;
	for (int i = 0; i < n; i++){
		for (int j = sum; j >= 0; j--){
			if (can[j]){
				can[s[i] + j] = true;
			}
		}

		sum += s[i];
	}

	while (1){
		if (can[sum] && (sum % 10 != 0 || sum == 0)){
			cout << sum << endl;
			break;
		}
		sum--;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int x,y,z;
	x=a+b,y=a-b,z=a*b;
	int max=x;
	if(y>max) max=y;
	if(z>max) max=z;
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int main()
{
 int n,m,k;
 long long int a[200002],b[200002];//
 int possa=0;
 long long int ssx=0,ax;//
 scanf("%d %d %d",&n,&m,&k);
 for(int i=1;i<=n;i++)
 {
	scanf("%lld",&a[i]);
	ssx+=a[i];
	if(ssx<=k){possa=i; ax=ssx;}//possaはAだけ読んだ時に読める本の数 その時にかかる時間がax
 }
 for(int i=1;i<=m;i++)
 {
	scanf("%lld",&b[i]);
 }
 int nj=1;
 long long int bx=0;//
 int ans=possa;
 for(int i=possa;i>=0;i--)
 {
	for(int j=nj;j<=m;j++)
	{
	 if(ax+bx+b[nj]<=k){bx+=b[nj]; nj++; ans=max(ans,(i+j));}
	 else{break;}
	}
 ax-=a[i]; //axはiを読むまでにかかる時間を表す
 }
 printf("%d",ans);
}

Measured memory_bytes: 6948
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(I,N) for (int I = 0; I < (N); ++I)
#define fornd(I,N) for (int I = (N) - 1; I >= 0; --I)
#define forab(I,A,B) for (int I = (A); I <= (B); ++I)
#define forabd(I,A,B) for (int I= (B); I >= (A); --I)
#define FOREACH(I,A) for (__typeof__(A)::iterator I=A.begin(); I<A.end(); I++)
#define all(V) (V).begin(), (V).end()
#define pb push_back
#define mp make_pair

typedef long long int ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

const ll mod = 1000000007;

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

  if (A < B) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define last last2

using namespace std;

typedef long long ll;

ll pow_mod(ll x,int k) {
  ll ans=1;
  while (k) {
  	if (k&1) ans=ans*x%MOD;
  	x=x*x%MOD;
  	k>>=1;
  }
  return ans;
}

ll inv[405];

void pre(int k) {
  inv[0]=1;
  for(int i=1;i<=k;i++) inv[i]=inv[i-1]*(k-i+1)%MOD;
  for(int i=1;i<=k;i++) inv[i]=pow_mod(inv[i],MOD-2);
}

int f[25005][405],sum[25005][405];

void dp(int n,int k) {
  f[1][1]=sum[1][1]=k;
  for(int i=2;i<=n;i++) {
    for(int j=1;j<k;j++) f[i][j]=((ll)f[i-1][j-1]*(k-j+1)+sum[i-1][j])%MOD;
    for(int j=k-1;j>0;j--) sum[i][j]=(sum[i][j+1]+f[i][j])%MOD;
  }
}

int solve1(int n,int m,int l,int r) {
  int ans=0;
  for(int i=1;i<=n-m+1;i++)
    ans=(ans+(ll)sum[i+l-1][l]*sum[n-(i-1)-m+r][r])%MOD;
  return ans*inv[l]%MOD*inv[r]%MOD;
}

int solve2(int n,int m,int k) {
  int ans=0;
  for(int i=1;i<=n-m+1;i++)
    for(int j=m;j<min(i+m,k);j++)
      ans=(ans+(ll)f[i+m-1][j]*sum[n-(i-1)-m+j][j]%MOD*inv[j])%MOD;
  return ans*inv[m]%MOD;
}

int num[25005],last[25005];

int main() {
  int n,m,k;
  scanf("%d%d%d",&n,&k,&m);
  pre(k);
  dp(n,k);
  for(int i=1;i<=m;i++) scanf("%d",&num[i]);
  memset(last,0,sizeof(last));
  int l=1,s=pow_mod(k,n-m)*(n-m+1)%MOD;
  for(int i=1;i<=m;i++) {
  	int x=num[i];
  	if (last[x]>=l) l=last[x]+1;
  	last[x]=i;
  	if (i-l+1>=k) {
  		printf("%d\n",s);
  		return 0;
	  }
  }
  if (l!=1) {
  	memset(last,0x3f,sizeof(last));
  	int r=m;
  	for(int i=m;i>0;i--) {
  		int x=num[i];
  		if (last[x]<=r) r=last[x]-1;
  		last[x]=i;
	  }
	printf("%d\n",(s-solve1(n,m,r,m-l+1)+MOD)%MOD);
  }
  else printf("%d\n",(s-solve2(n,m,k)+MOD)%MOD);
  return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    for (int i = 13; i <= 1010; i++)
    {
        int ans8 = i * 0.08;
        int ans10 = i * 0.1;
        if (ans8 == A && ans10 == B)
        {
            cout << i << endl;
            return 0;
        }
        if (ans8 > A || ans10 > B)
        {
            cout << -1 << endl;
            return 0;
        }
        
        
    }
    
    
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
  int i;
  int n; 
  ll sum=0;
 
  cin >> n;
  
  for(i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0)
      sum += i;
    
  }
 
  cout << sum;
}

Measured memory_bytes: 3628
N=int(input())
H=list(map(int, input().split()))

ans=tmp=0
for i in range(N-1):
    if(H[i] >= H[i+1]):
        tmp+=1
    else:
        if(tmp>ans):
            ans=tmp
        tmp=0
if(tmp>ans):
    ans=tmp
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '{';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "}");
    return o;
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

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

    int n;
    cin >> n;
    vi hs(n);
    F0R (i, n)
        cin >> hs[i];
    vi dp(n);
    dp[n - 1] = 0;
    dp[n - 2] = abs(hs[n - 1] - hs[n - 2]);
    for (int i = n - 3; ~i; --i)
        dp[i] = min(dp[i + 1] + abs(hs[i] - hs[i + 1]),
                    dp[i + 2] + abs(hs[i] - hs[i + 2]));
    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 1024
from collections import deque
n = int(input())

g = [[] for i in range(n)]

for i in range(n-1):
  u, v, w = map(int, input().split())
  u, v  = u-1, v-1
  g[u].append([v, w])
  g[v].append([u, w])

c = [-1]*n
c[0] = 0

queue = deque([0])

while queue:
  x = queue.popleft()
  for x_, w_ in g[x]:
    if c[x_] == -1:
      if w_%2 == 0:
        c[x_] = c[x]
      else:
        c[x_] = 1-c[x]
      queue.append(x_)
    else:
      continue

print(*c, sep='\n')
  



Measured memory_bytes: 81824
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
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 MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int f[n][10], p[n][11];
	rep(i, n) rep(j, 10) cin >> f[i][j];
	rep(i, n) rep(j, 11)cin >> p[i][j];
	int ans = -INF;
	for (int i = 1; i < (1 << 10); i++) {
		int cc = 0;
		for (int j = 0; j < n; j++) {
			int c = 0;
			rep(k, 10) {
				if (i & (1 << k) and f[j][k] == 1) c++;
			}
			cc += p[j][c];
		}
		chmax(ans, cc);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b,c = map(int, input().split())
    if a<c<b or b<c<a:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var st = new Stack<char>();
        var s = Console.ReadLine().Trim();
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] != 'B') st.Push(s[i]);
            else if (st.Count() > 0) st.Pop();
        }
        var rr = new char[st.Count()];
        var p = 0;
        while (st.Count()>0)
        {
            rr[p++] = st.Pop();
        }
        Array.Reverse(rr);
        Console.WriteLine(new string(rr));
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	ll n, d;
	cin >> n >> d;
	
	vi x(n), y(n);
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
	
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ll dist = x[i] * 1ll * x[i] + y[i] * 1ll * y[i];
		if(d * 1ll * d >= dist) ans++;
	}
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 4836
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

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

  if(a >= 13){
    cout << b << endl;
  } else if(a < 13 && a >= 6){
    cout << b/2 << endl;
  }else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  if(K==1){
	cout << 0 << endl;
  }else{
  	int max=N-K+1-1;
  	cout << max << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll t;
ll ret = 0;

void input() {
  IN(N);
}

void solve() {
  double p = (double)((N+1)/2) / (double)N;
  PRINT(p);
}

int main(void){
  input();
  solve();
}


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

int main()
{
  long long x, y;
  cin >> x >> y;

  if (x % y == 0)
  {
    cout << -1 << endl;
    return 0;
  }
  else
  {
    for (int i = 1; i < INT_MAX; i++)
    {
      if ((x * i) % y != 0)
      {
        cout << x * i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig

sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    S = input(str)
    n = ceil(len(S) / 2) + 1
    ans = 0
    for x, y in zip(S[:n], S[:-n:-1]):
        ans += 1 if not x == y else 0
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 5680
def find_prime_factor(num):
    if num & 1 == 0:
        return 2
    for i in range(3, int(num ** (1 / 2)) + 1):
        if num % i == 0:
            return i
    return num


def prime_factorization(num):
    subtract = num
    result = []
    while subtract > 1:
        factor = find_prime_factor(subtract)
        result.append(factor)
        subtract //= factor
    return result


n = int(input())

# prime and prime's power.
power = {}
for i in range(1, n + 1):
    for prime in prime_factorization(i):
        if prime in power:
            power[prime] += 1
        else:
            power[prime] = 1

count75 = sum(1 for count in power.values() if count >= 74)
count25 = sum(1 for count in power.values() if count >= 24)
count15 = sum(1 for count in power.values() if count >= 14)
count5 = sum(1 for count in power.values() if count >= 4)
count3 = sum(1 for count in power.values() if count >= 2)

ans = count75 \
      + count25 * (count3 - 1) \
      + count15 * (count5 - 1) \
      + (count5 * (count5 - 1) * (count3 - 2)) // 2

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;


void input(){
	int a, b, c;
	cin>>a>>b>>c;
	if(a+b+c > 21)cout<<"bust";
	else cout<<"win";
}

void solve(){

}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    solve2
  }


  def solve2(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, k = sc.nextInt
    val a = new Array[Long](n)
    for (i <- 0 until n) {
      a(i) = sc.nextLong
    }

    // 左からk個ずつとってみて、最小を求めてみる
    var ans = Long.MaxValue
    for (i <- 0 to n - k) {
      val x = a(i)
      val y = a(i + k - 1)

      val dist = math.abs(y - x)
      ans = math.min(ans, math.min((math.abs(x) + dist), (math.abs(y) + dist)))

    }
    println(ans)
  }


  // これだとTLE!!!!!
  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, k = sc.nextInt
    val a = new Array[Long](n)
    for (i <- 0 until n) {
      a(i) = sc.nextLong
    }

    // 左からk個ずつとってみて、最小を求めてみる
    var ans = Long.MaxValue
    for (i <- 0 to n - k) {
      val part = a.slice(i, i + k)
      val min = part.min
      val max = part.max
      val (greater, lesser) = if (min.abs >= max.abs) (min.abs, max.abs) else (max.abs, min.abs)

      if ((min < 0 && max < 0) || (min > 0 && max > 0)) {
        ans = math.min(ans, greater)
      } else {
        ans = math.min(ans, greater + 2 * lesser)
      }
    }
    println(ans)
  }
}


Measured memory_bytes: 52336
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007


signed main(){
    fast;
    // #ifndef ONLINE_JUDGE
    //     freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
    //     freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    // #endif
    int n, m;
    cin>>n>>m;
    int arr[m+1]={0};
    for(int i=0; i<n; i++){
        int k;
        cin>>k;
        For(j, 0, k){
            int a;cin>>a;arr[a]++;
        }
    }
    int ans = 0;
    For(i, 1, m+1){
        if(arr[i]==n){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;
void prllString(ll n)
{
    char str[50]; // To store result (Excel column name)
    ll i = 0; // To store current index in str which is result

    while (n > 0) {
        // Find remainder
        ll rem = n % 26;

        // If remainder is 0, then a 'Z' must be there in output
        if (rem == 0) {
            str[i++] = 'z';
            n = (n / 26) - 1;
        }
        else // If remainder is non-zero
        {
            str[i++] = (rem - 1) + 'a';
            n = n / 26;
        }
    }
    str[i] = '\0';

    // Reverse the string and prll result
    reverse(str, str + strlen(str));
    cout << str << endl;

    return;
}
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ll n;cin>>n;
        prllString(n);

}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      if (N == i * j) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main(){
    long int mod = 1000000007;
    long int n, k;
    cin >> n >> k;
    vector<long int> g[n];
    for(int i = 0; i < n - 1; i++){
        long int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int color[n];
    for(int i = 0; i < n; i++) color[i] = 0;
    color[0] = 1;
    queue<long int> q;
    q.push(0);
    long int ans = k;
    while(true){
        if (q.size() == 0) break;
        long int e = q.front();
        int s = g[e].size();
        int decided = 1;
        for(int i = 0; i < s; i++){
            if (color[g[e][i]] != 0) {
                decided++;
            }
        }
        for(int i = 0; i < s; i++){
            if (color[g[e][i]] == 0) {
                color[g[e][i]] = 1;
                ans *= k - decided;
                decided++;
                ans %= mod;
                q.push(g[e][i]);
            }
        }
        // cout << decided << endl;
        q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 7668
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>
using ll = long long;
using namespace std;

int d[15][15];
int dp[1 << 15][15];
int main(void)
{
    int V, E;
    cin >> V >> E;
    for (int i = 0; i < V; ++i)
        for (int j = 0; j < V; ++j)
            d[i][j] = 1e8;
    for (int i = 0; i < E; ++i)
    {
        int s, t, ds;
        cin >> s >> t >> ds;
        d[s][t] = ds;
    }

    for (int S = 0; S < 1 << V; ++S)
    {
        for (int i = 0; i < V; ++i)
        {
            dp[S][i] = 1e8;
        }
    }

    dp[(1 << V) - 1][0] = 0;

    for (int S = (1 << V) - 2; S >= 0; S--)
    {
        for (int v = 0; v < V; ++v)
        {
            for (int u = 0; u < V; ++u)
            {
                if (!(S >> u & 1))
                {
                    dp[S][v] = min(dp[S][v], dp[S | 1 << u][u] + d[v][u]);
                }
            }
        }
    }
    if (dp[0][0] != 1e8)
        cout << dp[0][0] << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 4996
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=105;
int s[maxn],sum=0;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        sum+=s[i];
    }
    sort(s,s+n);
    if(sum%10){
        cout<<sum<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        if(s[i]%10!=0){
            cout<<sum-s[i]<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INT_INF 1000000000
#define DOUBLE_INF 1e18
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 100001

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main()
{
  int H, W, N, A[MAX_N], B[MAX_N];
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
  }

  map<P, ll> count;
  for (int i = 0; i < N; i++) {
    int x = A[i], y = B[i];
    for (int dx = -1; dx <= 1; dx++) {
      for (int dy = -1; dy <= 1; dy++) {
        if (1 <= x+dx && x+dx <= H-2 &&
            1 <= y+dy && y+dy <= W-2) {
          count[P(x+dx, y+dy)]++;
        }
      }
    }
  }
  map<int, ll> ans;
  ans[0] = (ll)(H-2) * (ll)(W-2);
  for (auto itr = count.begin(); itr != count.end(); ++itr) {
    ans[itr->second]++;
  }

  ll sum = 0;
  for (int i = 1; i < 10; ++i) {
    sum += ans[i];
  }
  ans[0] -= sum;

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

  return 0;
}


Measured memory_bytes: 57216
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppi                      pair <int , pii>               
#define    sp(x)                    setprecision(x)

int32_t main()
{
    speed upp
    int n,a=0,b,x,y;
    string s;
    deque<char>q1,q2;
    cin>>s;
    cin>>n;
    f(i,1,n)
    {
        cin>>x;
        if(x==1)
        {
            a=(a+1)%2;
        }
        else
        {
            char c;
            cin>>y>>c;
            if(y==1 && a==0)
            {
                q1.push_front(c);
            }
            else if(y==1 && a==1)
            {
                q2.push_back(c);
            }
            else if(y==2 && a==0)
            {
                q2.pb(c);
            }
            else
            {
                q1.push_front(c);
            }
        }
      
    }
    
    if(a==0)
    {
        for(auto i: q1)
        cout<<i;
        cout<<s;
        for(auto i: q2)
        cout<<i;  
    }
    else
    {
        
        while(!q2.empty())
        {
            cout<<q2.back();
            q2.pop_back();
            
        }
      r(i,sz(s)-1,0)
              cout<<s[i];
         while(!q1.empty())
        {
            cout<<q1.back();
            q1.pop_back();
            
        }
    }
    
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-5;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const int64 mod = 1e9+7;

int main(void) {
	int64 A, B;
	cin >> A >> B;
	cout << max({A+A-1, B+B-1, A+B}) << endl;
}


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

typedef long long ll;

#define MOD 1000000007LL

int n;
ll f[100002];
int t[100002];
ll bit[100002];

ll sum(int i){
  ll res = 0;
  while(i > 0){
    res += bit[i];
    i -= i & -i;
  }
  return res;
}

void add(int i, ll x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}

void mkFact(){
  f[0] = 1;
  for(int i = 1; i <= 100000; i++){
    f[i] = f[i - 1] * i;
    f[i] %= MOD;
  }
}

void solve(){
  memset(bit, 0, sizeof(bit));

  ll res = 0;

  for(int i = n - 1; i >= 0; i--){
    res += f[n - i - 1] * sum(t[i]);
    res %= MOD;
    add(t[i], 1);
  }

  cout << res << endl;
}

int main(){
  mkFact();

  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      t[i] = i + 1;
    }

    int m;
    cin >> m;

    for(int i = 0; i < m; i++){
      int a, b;
      cin >> a >> b;
      swap(t[a - 1], t[b - 1]);
    }

    solve();
  }
}

Measured memory_bytes: 3116