akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXH=500;
const int MAXW=500;

int H,W,h,w;
int ret[MAXH][MAXW];


bool solve() {
	if(H%h==0&&W%w==0) return false;
	REP(x,H) REP(y,W) ret[x][y]=x%h==h-1&&y%w==w-1?-1:0;
	int sum=0; REP(x,H) REP(y,W) sum+=ret[x][y];
	if(H%h!=0) {
		int times=-sum+1;
		REP(x,H) if(x%h==0) ret[x][0]+=times; else if(x%h==h-1) ret[x][w-1]-=times;
	} else {
		int times=-sum+1;
		REP(y,W) if(y%w==0) ret[0][y]+=times; else if(y%w==w-1) ret[h-1][y]-=times;
	}
	return true;
}

void run() {
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(!solve()) { printf("No\n"); return; }
	printf("Yes\n");
	REP(x,H) { REP(y,W) { if(y!=0) printf(" "); printf("%d",ret[x][y]); } puts(""); }
}

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


Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int sum = 0;
		if(n<=k){
		    sum = x*n;
		}
		else {
			sum = k*x + (n-k)*y;
		}
		// 出力
		System.out.println(sum);
	}
}

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

    if(a%1000!=0)cout <<1000-a%1000 << endl;
    else{cout << 0 << endl;}
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<lint> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  V<> idx(n);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int i, int j) { return a[i] < a[j]; });
  lint res = 0;
  for (int i : idx) {
    if (m <= b[i]) {
      res += a[i] * m;
      break;
    } else {
      res += a[i] * b[i];
      m -= b[i];
    }
  }
  cout << res << '\n';
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n; cout << (n+1)/2;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int n; cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    int v1 = arr[n/2],v2 = arr[n/2 - 1];
    cout<<v1-v2<<endl;
    return 0;
}

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

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

char c[MAX];

int main(){
	scanf ("%s",c);
	int n=strlen(c);
	REP(i,n) if (c[i]=='7'){
		puts("Yes");
		return 0;
	}
	puts ("No");
	
	return 0;
}


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

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



	int a[5];
	for(int i = 0 ; i<5 ; i++){
		cin>>a[i];
		if(a[i]==0){
			cout<<i+1;
		}
	}

}


Measured memory_bytes: 3640
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 1e5 + 10;
int a[maxn];

int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  return 1;
}

void solve() {
  long long res = 0;
  int x = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] > x) {
      if (a[i] == x + 1) {
        ++x;
      } else {
        res += (a[i] - 1) / (x + 1);
        x = max(x, 1);
      }
    }
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n + 2];
    for (int i = 1; i < n + 1; i++) cin >> a[i];
    a[0] = 0, a[n + 1] = 0;

    ll s = 0;
    rep(i, n + 1) s += abs(a[i + 1] - a[i]);

    for (int i = 1; i < n + 1; i++) {
        cout << s + abs(a[i - 1] - a[i + 1]) -
                    abs(abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]))
             << endl;
    }
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  string ans = "Positive";
  
  int count=0;
  
  if(a<=0&&b>=0)ans="Zero";
  else if(b<0&&(b-a)%2==0)ans="Negative";
  
  cout << ans << endl;
  
}

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

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
		return false;
	}
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

signed main(){
	int n=read();
	
	int ans=0;
	
	for(register int i=1;i<n;i++){
		ans+=n/i;
		if(n%i==0)
			ans--;
	}
	
	writeln(ans);
	return 0;
}

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

using namespace std;

int main(){
	int n, m;
 	cin >> n >> m;
	vector<vector<bool>> s(m, vector<bool>(n, 0));
  	for(int i = 0; i < m; ++i){
    	int ki;
      	cin >> ki;
      	for(int j = 0; j < ki; ++j){
        	int x;
          	cin >> x;
          	s[i][x - 1] = 1;
        }
    }
    vector<int> p(m);
    for(int i = 0; i < m; ++i){
    	cin >> p[i];
    }
    
    int res = 0;
    for(int mask = 0; mask < (1 << n); ++mask){
      	vector<int> q(m, 0);
      	for(int j = 0; j < n; ++j){
        	if( (mask & (1 << j)) != 0 ){
            	for(int bulb = 0; bulb < m; ++bulb){
              		if(s[bulb][j]){
                    	q[bulb]++;
                    }
                }
            }
        }
      	
      	bool is = true; 
      	for(int bulb = 0; bulb < m; ++bulb){
          	if(q[bulb] % 2 != p[bulb] % 2){
              	is = false;
              	break;
            }
        }
        
        if(is) res++;
    }
    cout << res;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		boolean sw2=false;
		boolean sw3=false;
		int answer=0;
		//String answer="Heisei";
		//List<Integer> h=new ArrayList<Integer>();
		//int t[]=new int[(int)Math.pow(10,5)];
		int max=Integer.MIN_VALUE;
		int min=Integer.MAX_VALUE;
		//入力
		Scanner sc = new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int h=sc.nextInt();
		int w=sc.nextInt();
		//X=sc.nextDouble();
		//int A[]=new int[N];
		//List<Integer> l=new ArrayList<Integer>();
		//List<Integer> w=new ArrayList<Integer>();
		//for(int i=0;i<N;i++)
		//{
		//	l.add(sc.nextInt());
		//}
		//String S=sc.next();
		
		//処理
		if(H==h)
		{
			if(W==w)
			{
				answer=0;
			}
		}
		int a=H*W;
		int b=(h*W)+(w*H)-(h*w);
		answer=a-b;
		// 出力
		//System.out.println(Arrays.toString(X));
		//System.out.println(Arrays.deepToString(a));
		//System.out.println(Arrays.toString(A.toArray()));
		System.out.println(answer);
	}
}

Measured memory_bytes: 23764
//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "debug.cpp"
#else
#define debug(...)
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    ll n,x,t; cin >> n >> x >> t;
    cout << ((n-1)/x + 1) * t << endl;
}

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


int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

//long long  factorial(long long n) {
//    if (n > 0) {
//        return n * factorial(n - 1);
//    } else {
//        return 1;
//    }
//}
long long  factorial(long long n, long long depth) {
    if (n > 1) {
        depth++;
        return factorial(n / 2, depth);
    } else {
        return depth;
    }
}

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

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}



//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
  int  a ,b, c, d, e, X, Y ,r;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
// long long  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
//  int  C[100003][100001]={};
  int  C[100003]={};

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p=0,q=0;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  long long min =100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  long long  ans=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  long long sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
  double per=0; 
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
  scanf("%s", &s);
  if(strcmp(s,"AAA")==0 ||strcmp(s,"BBB")==0) printf("No\n");
  else printf("Yes\n");
  
  
return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[]ss  = S.toCharArray();
 
    int n = S.length();
    int cou = 0;
    for(int i=0; i<n/2; i++){
            if(ss[i] != ss[S.length()-1-i]){
            cou++;
    }
}
    System.out.println(cou);
    }
}

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

int main(){
  vector<int> m(10);
  for (int i = 0; i < 10; i++) {
    cin >> m.at(i);
  }
  sort(m.begin(), m.end(), greater<int>());
  for (int i = 0; i < 3; i++) {
    cout << m.at(i) << endl;
  }
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main() {
    int m=0;
    string S;
    cin >> S;
    if (S[0] != 'A') {
		cout << "WA";
        return 0 ;
    }
    S.erase(0,1);
    for (int j = 1; j <S.size()-1 ; ++j) {
        if(S[j]=='C'&&m<=1){
            m++;
            S.erase(j,1);
            j--;
        } 
    }
	 if (m!=1){
            cout<<"WA";
            return 0;
        }
    for (int i = 0; i <S.size() ; ++i) {
        if(S[i]>=97){
            continue;
        }else{
            cout<<"WA";
            return 0;
        }
    }cout<<"AC";


}

Measured memory_bytes: 256
#include<iostream>
#define M 1000003
#define f first
#define s second
using namespace std;
int n,c[256];
int f[M];

int stoi(string s){
  int res=0;
  for(int i=0;i<s.size();i++)res*=5,res+=c[s[i]];
  return res;
}

int func1(int a){
  return a%M;
}

int func2(int a){
  return 1+a%(M-1);
}

int main(){
  string mei,str;
  c['A']=1,c['C']=2,c['G']=3,c['T']=4;
  cin>>n;
  while(n--){
    cin>>mei>>str;
    int a=stoi(str);
    int b=func1(a),c=func2(a);
    if(mei[0]=='i'){
      while(f[b])b+=c,b%=M;
      f[b]=a;    
    }
    if(mei[0]=='f'){
      int cn=0,fg=0;
      while(cn!=M&&f[b]!=a){
	b+=c,b%=M,cn++;
	if(!f[b]){fg=1;break;}
      }
      if(cn==M||fg)cout<<"no"<<endl;
      else cout<<"yes"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define inf 0x3f3f3f3f
#define REP(i,N)  for(int i=0;i<(N);i++)
#define CLR(A,v)  memset(A,v,sizeof A)
//////////////////////////////////
const int N=1e6;
const int M=1e6;

int head[M];
int pos;
struct Edge
{
    int  v,to,nex;
}edge[M];
void add(int a,int b,int c)
{
    edge[++pos]=Edge{c,b,head[a]};
    head[a]=pos;
}
struct Node
{
    int d,id;
    bool operator<(const Node& b)const
    {
        return d<b.d;
    }
};
int dis[N],vis[N];
int n;
void dijkstra(int s)
{
    rep(i,0,n+1)dis[i]=0;
    dis[s]=0;
    priority_queue<Node>q;
    q.push(Node{0,s});
    while(!q.empty())
    {
        Node u=q.top();q.pop();
        if(vis[u.id])continue;
        vis[u.id]=1;
        for(int i=head[u.id];i;i=edge[i].nex)
        {
            int v=edge[i].to;
            if(u.d+edge[i].v>dis[v])
            {
                dis[v]=u.d+edge[i].v;
                q.push(Node{dis[v],v});
            }
        }
    }
}
char s[N];
int c,k;
int a[N],cnta;
int cnt[N],aa[N],pre[N];
int main() {
    cin>>n>>k>>c;
    cin>>s+1;
    for(int i=1;i<=n-1;i++)  add(i,i+1,0);
    for(int i=1;i<=n;i++) if(s[i]!='x') a[++cnta]=i;

    for(int i=1;i<=n;i++) if(s[i]!='x') {
        int pos=lower_bound(a+1,a+1+cnta,i+c+1)-a;
        if(pos!=cnta+1&&a[pos]) {
            add(i,a[pos],1);
            pre[a[pos]]=i;
        }
    }
    dijkstra(1);
    //cout<<dis[n];
    if(dis[n]!=k-1) return 0;
    int ss=0;
    for(int i=n;i>=1;i--) if(s[i]!='x') {
        ss=i;break;
    }
    int pos=ss;
    //for(int i=1;i<=n;i++) printf("i=%d dis=%d\n",i,dis[i]);
    //memset(cnt,0,sizeof cnt);
    for(int i=dis[n];i>=0;i--) {
        int to=0;
        for(;pos>=1;pos--) {
            aa[pos]=1;
            //printf("poss=%d\n",pos);
            if(!to&&s[pos]!='x') to=pre[pos];
            if(s[pos]!='x') cnt[dis[pos]]++;
            if(dis[pos-1]!=dis[pos]) break;
        }
        if(!to) break;
        pos=to;
    }
    for(int i=1;i<=n;i++) if(s[i]!='x'&&aa[i]) {
        //printf("i=%d dis=%d cnt=%d\n",i,dis[i],cnt[dis[i]]);
        if(cnt[dis[i]]==1) printf("%d\n",i);
    }
}




Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll *v;
ll n, K;

void solve(){
    cin >> K >> n;
    ll arr[n];
    for(auto &i : arr)
        cin >> i;
    ll total = 0, _max = 0;
    for(ll i = 1; i < n; i++){
        total += abs(arr[i] - arr[i-1]);
        _max = max(_max, abs(arr[i] - arr[i-1]));
    }
    total += abs(K - arr[n-1] + arr[0]);
    _max = max(_max, abs(K - arr[n-1] + arr[0]));
    cout << total - _max << endl;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

using namespace std;

int n;

struct point{
  double x;
  double y;
};

void koch(int depth, struct point p1, struct point p2){
  if(depth < n){
    struct point s, t, u;
    double rad = 60.0 * M_PI / 180.0;

    s.x = (p1.x * 2.0 + p2.x * 1.0) / 3.0;
    s.y = (p1.y * 2.0 + p2.y * 1.0) / 3.0;
    t.x = (p1.x * 1.0 + p2.x * 2.0) / 3.0;
    t.y = (p1.y * 1.0 + p2.y * 2.0) / 3.0;
    u.x = (t.x - s.x) * cos(rad) - (t.y - s.y) * sin(rad) + s.x;
    u.y = (t.x - s.x) * sin(rad) + (t.y - s.y) * cos(rad) + s.y;

    koch(depth+1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(depth+1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);;
    koch(depth+1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(depth+1, t, p2);
  }
}

int main(){
  struct point p1 = {0.0, 0.0};
  struct point p2 = {100.0, 0.0};
  scanf("%d", &n);

  printf("%.8f %.8f\n", p1.x, p1.y);
  koch(0, p1, p2);
  printf("%.8f %.8f\n", p2.x, p2.y);

  return 0;
}



Measured memory_bytes: 2760
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;
const int N = 405, A = 405, B = 405;
const long long mod = 998244353ll;
int n, a[N], b[N], asum = 0, bsum = 0;
long long f[N][A][B], fac[B], inv[B], inv_fac[B], ans = 0ll;
int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]), asum += a[i], bsum += b[i];
	for (int i = 0; i <= asum; i++) {
		for (int j = 0; j <= bsum; j++) f[0][i][j] = 0ll;
	}
	fac[0] = 1ll;
	for (int i = 1; i <= max(asum, bsum); i++) fac[i] = fac[i - 1] * i % mod;
	inv[1] = 1ll;
	for (int i = 2; i <= max(asum, bsum); i++) inv[i] = (mod / i) * (mod - inv[mod % i]) % mod;
	inv_fac[0] = 1ll;
	for (int i = 1; i <= max(asum, bsum); i++) inv_fac[i] = inv_fac[i - 1] * inv[i] % mod;
	f[0][0][0] = mod - 1ll;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= asum; j++) {
			for (int k = 0; k <= bsum; k++) {
				f[i][j][k] = f[i - 1][j][k];
				if (j >= a[i]) {
					long long now = 1ll;
					for (int l = 0; l < b[i] && l <= k; l++, now = now * a[i] % mod) {
						f[i][j][k] = (f[i][j][k] + mod * mod - now * inv_fac[l] % mod * f[i - 1][j - a[i]][k - l]) % mod;
					}
				}
			}
		}
	}
	for (int i = 1; i <= asum; i++) {
		long long now = asum * inv[i] % mod;
		for (int j = 0; j <= bsum; j++, now = now * inv[i] % mod) ans = (ans + now * fac[j] % mod * f[n][i][j]) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 514304
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int a,b;cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

#define INF 100000000

struct edge {
	int to;
	int c, t;
};

int main() {
	int n, m, f, temp, s, k, p, q, r;
	vector<edge> g[101];
	queue<int> search;
	int mc[101][101], mt[101][101];
	edge e;
	while(1) {
		cin >> n >> m;
		if(!n&&!m) break;
		for(int i=0; i<=m; ++i) g[i].clear();
		for(int i=0; i<=m; ++i) for(int j=0; j<=m; ++j) {
			mc[i][j] = mt[i][j] = INF;
		}
		for(int i=0; i<n; ++i) {
			cin >> f >> e.to >> e.c >> e.t;
			g[f].push_back(e);
			temp = e.to; e.to = f; f = temp;
			g[f].push_back(e);
		}
		for(int i=1; i<=m; ++i) {
			search.push(i); mc[i][i] = 0;
			while(!search.empty()) {
				s = search.front(); search.pop();
				for(vector<edge>::iterator it=g[s].begin(); it!=g[s].end(); ++it) {
					if(mc[i][s]+(*it).c<mc[i][(*it).to]) {
						mc[i][(*it).to] = mc[i][s]+(*it).c;
						search.push((*it).to);
					}
				}
			}
			search.push(i); mt[i][i] = 0;
			while(!search.empty()) {
				s = search.front(); search.pop();
				for(vector<edge>::iterator it=g[s].begin(); it!=g[s].end(); ++it) {
					if(mt[i][s]+(*it).t<mt[i][(*it).to]) {
						mt[i][(*it).to] = mt[i][s]+(*it).t;
						search.push((*it).to);
					}
				}
			}
		}
		cin >> k;
		for(int i=0; i<k; ++i) {
			cin >> p >> q >> r;
			if(!p&&!q) break;
			cout << (!r?mc[p][q]:mt[p][q]) << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1392
#include<iostream>
#include<queue>

int main(){
  int n,m;
  std::cin >> n >> m;
  std::priority_queue<long long> que;
  
  int i;
  for(i=0;i<n;i++){
    long A;
    std::cin >> A;
    que.push(A);
  }
  for(i=0; i<m;i++){
    long long t = que.top();
    que.pop();
    que.push(t/2);
  }
  
  long long res = 0;
  while(!que.empty()){
    res += que.top();
    que.pop();
  }
  std::cout << res;
}

Measured memory_bytes: 1400
#include <stdio.h>
#include <stdlib.h>
int num(){
    char s[11];
    int i, n;
    for(i=0; i<sizeof(s); i++){
        s[i] = getchar();
        if(s[i] == ' ' || s[i] == '\n'){
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}
void sort(int x[], int n){
    int y, i, j;
    for(i=n; i>1; i--){
        for(j=0; j<=i-2; j++){
            if(x[j] < x[j+1]){
                y = x[j];
                x[j] = x[j+1];
                x[j+1] = y;
            }
        }
    }
}
int main(void){
    int n, k;
    int l[50];
    int i, temp=0;
    
    n = num();
    k = num();
    for(i=0; i<n; i++){
        l[i] = num();
    }
    
    sort(l, n);
    
    for(i=0; i<k; i++){
        temp += l[i];
    }
    
    printf("%d\n", temp);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

int main()
{
  ll const mod = 1000000007;
  ll i,j;
  ll x,y; cin >> x >> y;
  if((x+y)%3 != 0){cout << 0 << endl; return 0;}
  ll newx = (ll)((2 * x - y) / 3);
  ll newy = (ll)((2 * y - x) / 3);
  if(newx < 0 || newy < 0){cout << 0 << endl; return 0;}

    // nCrの計算
    cout<< comb(newx + newy, newy) << endl;

  return 0;
}


Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x>=r && y>=r && x+r<=W && y+r<=H)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}





Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    if((a == 1 && b == 2) || (a == n && b == n-1)) cout << "Borys" << endl;
    else if(abs(a-b) % 2 == 0) cout << "Alice" << endl;
    else cout << "Borys" << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        sv: [Chars; n]
    };

    let mut table = HashMap::new();
    for s in sv {
        let mut s = s;
        s.sort();
        let s = s.into_iter().rev().collect::<String>();
        *table.entry(s).or_insert(0) += 1;
    }
    let mut res = 0_u64;
    for (_, c) in table {
        res += c * (c - 1) / 2;
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 18812
import math
m=10**9+7
n,a,b=map(int,input().split())
if(a>n//2):
  a = n-a
if(b>n//2):
  b = n-b
aa=min(a,b)
bb=max(a,b)
na=1
nb=1
da=1
db=1
for i in range(aa):
  na=na*(n-i)%m
  da=da*(1+i)%m
  nb=nb*(n-i)%m
  db=db*(1+i)%m
for i in range(aa,bb):
  nb=nb*(n-i)%m
  db=db*(1+i)%m
CA=(na*pow(da,m-2,m))%m
CB=(nb*pow(db,m-2,m))%m
c=pow(2,n,m)-CA-CB-1
print(c%m)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  ll cnt = 0, tmp = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++)
  {
    if (a[i] - a[i - 1] >= 0)
    {
      cnt++;
    }
    else if (a[i - 1] - a[i] == 1)
    {
      tmp = max(a[i - 1] - 1, tmp);
      //cout << tmp << endl;
      if (tmp > a[i])
        break;
      cnt++;
    }
  }
  if (cnt == n - 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
    

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

int main()
{
	int ans=99999999;
	string s;
	cin>>s;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]!=s[i-1])
			ans=min(ans,max(i,int(s.size())-i));
	}
	cout<<min(ans,int(s.size()));

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define db(x) cout << #x << "=" << x << "  "
#define el cout << endl;
#define re(i, n) for(int i = 0; i < n; ++i)
const int MXN = 2e5 + 10;

int X, D, U, K, Q;
int R[MXN], T[MXN], A[MXN];

int clip(int x, int low = 0, int high = X) {
    return max(low, min(x, high));
}

int delta = 0, tim = 0;
void adv(int t) {
    delta += t, tim += abs(t);
    U = clip(U + t);
    D = clip(D + t);
}

int main() {
    cin >> X >> K;
    re(i, K) scanf("%d", R + i);
    cin >> Q;
    D = 0, U = X;
    int p = 0;
    re(i, Q) {
        scanf("%d %d", T + i, A + i);
        while (p < K && R[p] < T[i]) {
            adv((R[p] - tim) * ((p & 1) * 2 - 1));
            ++p;
        }
        adv((T[i] - tim) * ((p & 1) * 2 - 1));
        printf("%d\n", clip(A[i] + delta, D, U));
    }
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll n,h[N],dp[N];
int main(){
	ll i;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
	}
	memset(dp,127,sizeof(dp));
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(i=2;i<n;i++)
	{
		dp[i]=min(dp[i],min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
import sys

num = sys.stdin.readline().split(' ')
K = int(num[0])
S = int(num[1])

counter = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S-i-j <= K:
            counter += 1
        else:
            continue

print(counter)

Measured memory_bytes: 3060
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){
  string s;
  cin >> s;
  int n = len(s);
  vector<int> f(n);
  forn(i,n){
    if (s[i] == 'R') f[i]++;
    if (i and s[i] == 'R' and s[i-1] == 'R') {
      f[i] += f[i-1];
      f[i-1] = 0;
      }
  }
  for(int i=n-1;~i;i--){
    if (s[i] == 'L') f[i]++;
    if ((i+1<n) and s[i] == 'L' and s[i+1] == 'L') {
      f[i] += f[i+1];
      f[i+1] = 0;
    }
  }
  vector<int> ans(n);
  forn(i,n){
    if (f[i])
    if (s[i] == 'R'){
      int x = f[i] / 2;
      ans[i] += f[i] - x;
      ans[i+1] += x;
    } else {
      int x = f[i] / 2;
      ans[i] += f[i] - x;
      ans[i-1] += x;
    }
  }
  forn(i,n) cout << ans[i] << ' ';

}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

6
1 1
7 1
2 2
6 2
1 3
7 3

 */

Measured memory_bytes: 1488
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int H, W;
    cin >> H >> W;

    string S[H];
    REP(i, H){
        cin >> S[i];
    }

    vector<vector<int>> field(H+2, vector<int>(W+2));

    FOR(i, 1, H){
        FOR(j, 1, W){
            if (S[i-1][j-1] == '#'){
                field[i][j] = 1;
            }
            //cout << field[i][j] << endl;
        }
    }

    int res;
    bool flag = true;
    FOR(i, 1, H){
        FOR(j, 1, W){
            res = 0;
            if (S[i-1][j-1] == '#'){
                res += (field[i][j-1] + field[i][j+1] + field[i-1][j] + field[i+1][j]);
                //cout << res << endl;
                if (res == 0){
                    flag = false;
                }
            }
        }
    }

    if (flag == true){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

int main(){
	int n,c,k;
	cin >> n >> c >> k;
	vector<int> t(n);
	for(int i=0; i<n; i++) cin >> t[i];
	sort(t.begin(), t.end());
	int ans = 0;
	for(int i=0; i<n; i++){
		int limit = t[i]+k;
		for(int j=0; j<c && i<n; j++, i++){
			if(t[i] > limit) break;
		}
		i--;
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    assert_eq!(!0usize, std::usize::MAX); //🙊
    assert!(0 == 0); //😇

    let n = io.read::<usize>();
    let mut a = io.readn::<i64>(n);
    let mut ans = INF;
    for od in 0..2 {
        let mut sm = 0;
        let mut ret = 0;
        for i in 0..n {
            sm += a[i];
            if (i % 2 == 0) ^ (od == 0) {
                if sm >= 0 {
                    ret += sm + 1;
                    sm = -1;
                }
            } else {
                if sm <= 0 {
                    ret += sm.abs() + 1;
                    sm = 1;
                }
            }
        }
        ans = min(ret, ans);
    }
    io.writeln(ans);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
function Main(input) {
    const N = input.trim().split('\n')[0];

    let result = 0;
    for (let n of N) {
        result += n;
        result %= 9;
    }
    if (result) {
        console.log('No');
    } else {
        console.log('Yes');
    }

    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main()
{
    int n;
    std::cin >> n;
    std::map<char,int> map;
    std::string s;
    std::cin >> s;
    for(auto i : s)map[i]++;

    for(int i = 0 ; i < n -1 ; i++){
        std::string k;
        std::cin >> k;
        std::map<char,int> tmp;
        for(auto j : k)tmp[j]++;
        for(auto j : map){
            map[j.first] = std::min(tmp[j.first],map[j.first]);
        }
    }
    std::string ans;
    for(auto i : map){
        for(int j = 0; j < i.second; j++)ans.push_back(i.first);
    }
    std::sort(ans.begin(), ans.end());
    std::cout << ans << std::endl;
}

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

using namespace std;

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

int N, K, Q;
int A[2005];
bool valid[2005];
int main() {
  scanf("%d %d %d", &N, &K, &Q);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
  int res = 2e9;
  for (int i = 1; i <= N; i++) {
    fill(valid, valid + 1 + N, true);
    for (int j = 1; j <= N; j++) {
      if (A[j] < A[i]) {
        valid[j] = false;
      }
    }
    valid[N + 1] = false;
    vector<int> v, curr;
    for (int j = 1; j <= N + 1; j++) {
      if (!valid[j]) {
        if (!curr.empty()) {
          if (curr.size() >= K) {
            sort(curr.begin(), curr.end());
            for (int k = 0; k < curr.size() - K + 1; k++) {
              v.push_back(curr[k]);
            }
          }
          curr = vector<int>();
        }
      } else {
        curr.push_back(A[j]);
      }
    }
    if (v.size() >= Q) {
      sort(v.begin(), v.end());
      res = min(res, v[Q - 1] - A[i]);
    }
  }
  printf("%d\n", res);
  return 0;
}


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

int main() {
  char ch[60][60];
  int H, W;
  cin >> H >> W;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> ch[i][j];
    }
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (ch[i][j] == '.') {
        int cnt = 0;
        for (int k = i - 1; k <= i + 1; k++) {
          for (int l = j - 1; l <= j + 1; l++) {
            if (ch[k][l] == '#') cnt++;
          }
        }
        ch[i][j] = '0' + cnt;
      }
    }
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cout << ch[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
sub f{my$x=1;$a[$_]++or$x+=$t=&f,$z+=1-$p[$t]for@$_;$z+=$p[-2]-$p[-$x-1];$x}f$a[$_=map{push@$_,$_[--$|]for@_=split}<>]=@p=(1,map{($d*=5e8+4)%=$%=1e9+7;$.=$.*2%$%}++$d..<>);print$z%$%*$d%$%

Measured memory_bytes: 375296
#include <iostream>
using namespace std;
int main(void) {
  int n, y;
  cin >> n >> y;
  int a = -1, b  = -1, c = -1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n - i; j++) {
      if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
        a = i, b = j, c = n - i - j;
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for (int i=a; i<(b);++i)
const int INF = 1e9;

int N;
int F[100][10];
int P[100][11];
int main(){
    cin >> N;
    REP(i,N) REP(j,10) cin >> F[i][j];
    REP(i,N) REP(j,11) cin >> P[i][j];
    int ans = -INF;
    rep(bit,1,1<<10){
        int tmp = 0;
        REP(n,N){
            int cnt = 0;
            REP(i,10){
                if((bit & (1<<i)) && F[n][i]==1) ++cnt;
            }
            tmp += P[n][cnt];
        }
        ans = max(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};

struct union_find{
    vector<in> par;
    vector<in> depth;
    vector<in> siz;
    in kid;
    union_find(in n) : par(n) , depth(n,0) , siz(n,1){
        rep(i,n) par[i]=i;
        kid=n;
    }
    in find(in x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(in x,in y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        kid --;
        siz[x] +=siz[y];
        siz[y] =siz[x];
        if(depth[x]<depth[y]) par[x]=par[y];
        else{
            par[y]=par[x];
            if(depth[x]==depth[y]) depth[x] ++;
        }
    }
    bool same(in x,in y){
        return find(x)==find(y);
    }
    in size(in x){
        return siz[find(x)];
    }
    in kind(){
        return kid;
    }
};

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n;
    cin>>n;
    vector<P> a(n);
    in p,q;
    rep(i,n){
        cin>>p>>q;
        a[i]=P(p,q);
    }
    in ans=n;
    rep(i,n-1)REP(j,i+1,n){
        p=a[j].first-a[i].first;
        q=a[j].second-a[i].second;
        union_find uf(n);
        uf.unite(i,j);
        rep(x,n-1)REP(y,x+1,n){
            if(uf.same(x,y)) continue;
            in np,nq;
            np=a[x].first-a[y].first;
            nq=a[x].second-a[y].second;
            if(np==p && nq==q) uf.unite(x,y);
            else if(p==-np && q==-nq) uf.unite(x,y);
        }
        in cnt=uf.kind();
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}/*
./problem.exe
*/

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

using namespace std;
int dp[1000009];
int n,h[100000];
int bt(int i)
{
    if(i==n-1)
        return 0;
    if(i==n-2)
        return abs(h[i]-h[i+1]);
    if(dp[i]!=-1)
        return dp[i];
    int &ret=dp[i];
    ret=min(abs(h[i]-h[i+1])+bt(i+1),abs(h[i]-h[i+2])+bt(i+2));
    return ret;
}
int main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
        cin>>h[i];
    cout<<bt(0);
}


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

int main()
{
	int h,w;
	cin >> h >> w;

	vector<vector<int>> dp(10,vector<int>(10));
	for (int i=0;i<10;++i)
	{
		for (int j=0;j<10;++j)
		{
			cin >> dp[i][j];
		}
	}

	vector<vector<int>> a(h,vector<int>(w));
	vector<int> count(10);
	for (int i=0;i<h;++i)
	{
		for (int j=0;j<w;++j)
		{
			int d;
			cin >> d;
			a[i][j]=d;
			if (d!=-1)
			{
				++count[d];
			}
		}
	}

	for (int k=0;k<10;++k)
	{
		for (int i=0;i<10;++i)
		{
			for (int j=0;j<10;++j)
			{
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}

	int64_t sum=0;
	for (int i=0;i<10;++i)
	{
		sum+=(int64_t)count[i]*dp[i][1];
	}
	cout << sum << endl;
}







Measured memory_bytes: 3768
#include <algorithm>
#include <cstdlib>
#include <iostream>

using namespace std;

// Checks the sides satisfies the triangle inequality.
inline bool Ok(int a, int b, int c) {
  return a < b + c && b < a + c && c < a + b;
}

int main() {
  size_t i = 0;
  size_t obtuse = 0;
  size_t acute = 0;
  size_t right = 0;

  int a, b, c;
  for (;;) {
    cin >> a >> b >> c;
    if (!Ok(a, b, c)) {
      printf("%lu %lu %lu %lu\n", i, right, acute, obtuse);
      break;
    }
    const auto m = max({a, b, c});
    int lhs = 0;
    int rhs = 0;
    if (m == a) {
      lhs = a * a;
      rhs = b * b + c * c;
    } else if (m == b) {
      lhs = b * b;
      rhs = a * a + c * c;
    } else { // m == c
      lhs = c * c;
      rhs = a * a + b * b;
    }
    if (lhs == rhs) {
      ++right;
    } else if (lhs < rhs) {
      ++acute;
    } else {
      ++obtuse;
    }

    ++i;
  }

  return 0;
}



Measured memory_bytes: 3208
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		b=0,c=0,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> n;
	vector<ll>	a(n),d(n);
	for(i=0;i<n;i++) cin >> a[i];
	for(i=0;i<n;i+=2) b += a[i];
	for(i=1;i<n;i+=2) c += a[i];
	d[0] = abs(b-c);
	for(i=1;i<n;i++) {
		d[i] = (a[i-1]-d[i-1]/2)*2;
	}
	for(i=0;i<n;i++) cout << d[i] << " ";
	cout << endl;
	return 0;
}


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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    ll arr[n+1];
    ll suffSum[n+1];
    bool can = true;
    for(int i=0; i<=n; i++)
    {
        cin >> arr[i];
        suffSum[i] = arr[i];
    }
    for(int i=n-1; i>=0; i--)
    {
        suffSum[i] += suffSum[i+1];
    }
    ll ans = 0;
    ll mx_total = 1;
    for(int i=0; i<=n; i++)
    {
        if(i < n && arr[i] >= mx_total)
        {
            cout << -1;
            return 0;
        }
        if(i == n && arr[i] > mx_total)
        {
            cout << -1;
            return 0;
        }
        mx_total = min(suffSum[i], mx_total);
        ans += mx_total;
        mx_total = 2 * (mx_total - arr[i]);

    }
    cout << ans;
    return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n,k;
    cin >> n >> k;
    int ans = 0;
    REP(i,n){
        int x;
        cin >> x;
        ans += 2*min(x,k-x);
    }
    cout << ans << endl;
    return 0;
}    


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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < a[i]; ++j) {
      v.push_back(i + 1);
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (j) {
        cout << " ";
      }
      if (i % 2 == 0) {
        cout << v[i * w + j];
      } else {
        cout << v[i * w + w - 1 - j];
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 384
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        while (true) {
            c -= b;
            if (c <= 0) {
                System.out.println("Yes");
                return;
            }
            a -= d;
            if (a <= 0) {
                System.out.println("No");
                return;
            }
        }
    }
}


Measured memory_bytes: 35752
#include<iostream>
#include<string>
using namespace std;
int s,t,ans,min_ans;
int main()
{
	string S,T;
	cin>>S>>T;
	s=S.size(),t=T.size();
	min_ans=t;
	for(int i=0;i<s-t+1;i++)
	{
		ans=0;
		for(int j=0;j<t;j++)
			if(S[i+j]!=T[j])ans++;
		min_ans=ans<min_ans?ans:min_ans;
	}
	cout<<min_ans;
	return 0;
}

Measured memory_bytes: 3640