akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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; }

// 約数の個数を全列挙O(NlogN)
vector<ll> divisors_count(ll a){
    vector<ll> res(a+1, 0);

    for(ll i = 1; i <= a; i++){
        for(ll j = 1; i * j <= a; j++) res[i*j]++;
    }

    return res;
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N; cin >> N;

    auto divisors = divisors_count(N);

    ll ans = 0;
    for(int i = 1; i <= N; i++){
        ans += i*divisors[i];
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 81344
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define P pair
#define M 998244353
#define fr(i,n) for(int i=0;i<n;i++)
#define M2 1000000007
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
#define Take_n ll n; cin>>n;
using namespace std;
 
int main()
{
	string s,t;
	cin>>s>>t;
	int n=s.length(),m=t.length(),i,j;
	int dp[n+1][m+1]={0};
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			if(i==0 || j==0)
			{
				dp[i][j]=0;
			}
			else if(s[i-1]==t[j-1])
			dp[i][j]=1+dp[i-1][j-1];
			else
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}

	i = n, j = m; 
	string ans="";
   while (i > 0 && j > 0) 
   { 

    	if (s[i-1] == t[j-1]) 
    	{ 
          ans = s[i-1]+ans;
          i--; j--;
    	} 
    	else if (dp[i-1][j] > dp[i][j-1]) 
        i--; 
    	else
        j--; 
   } 
   cout<<ans;
    return 0;
}

Measured memory_bytes: 38828
import java.util.*;

public class Main {
  private static final int MOD = 1_000_000_007;
  private static int[] fact;
  private static int[] ifact;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);
    
    fact = new int[N+1];
    fact[0] = 1;
    for (int i = 1; i <= N; i++) {
      fact[i] = (int)((long)i*fact[i-1]%MOD);
    }
    ifact = new int[N+1];
    for (int i = 0; i <= N; i++) {
      ifact[i] = powMod(fact[i], MOD-2);
    }
    
    long ans = 0;
    for (int a = 0; a < 2; a++) {
      for (int i = 0; i < N; i++) {
        long now = a == 0 ? A[i] : -A[i];
        ans += now*combMod(i, K-1)%MOD;
        ans %= MOD;
      }
      int[] B = new int[N];
      for (int i = 0; i < N; i++) {
        B[N-1-i] = A[i];
      }
      A = B;
    }
    
    System.out.println(ans);
  }
  
  private static int combMod(int n, int k) {
    if (k < 0 || n < k) return 0;
    return (int)(((long)fact[n]*ifact[k]%MOD)*ifact[n-k]%MOD);
  }
  
  private static int powMod(int a, int n) {
    if (n == 0) {
      return 1;
    }
    if (n%2 == 1) {
      return (int)((long)a*powMod(a,n-1)%MOD);
    }
    long half = powMod(a,n/2);
    return (int)(half*half%MOD);
  }
}

Measured memory_bytes: 48296
#include <bits/stdc++.h>
using namespace std;
long long N,ans, m[256];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    while(N--){
        string s;
        cin>>s;
        m[s[0]]++;
    }
    ans+=m['M']*m['A']*m['R'];    
    ans+=m['M']*m['A']*m['C'];    
    ans+=m['M']*m['A']*m['H'];    
    ans+=m['M']*m['R']*m['C'];    
    ans+=m['M']*m['R']*m['H'];    
    ans+=m['M']*m['C']*m['H'];    
    ans+=m['A']*m['R']*m['C'];    
    ans+=m['A']*m['R']*m['H'];    
    ans+=m['A']*m['C']*m['H'];    
    ans+=m['R']*m['C']*m['H'];    
    cout<<ans<<'\n';
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
	while (true) {
		int n, m, a;
		cin >> n >> m >> a;
		if (n == 0) return;
		vector<tuple<int, int, int>> inputs;
		REP(i, m) {
			int a, b, c;
			cin >> a >> b >> c;
			inputs.push_back(make_tuple(a, b, c));
		}
		sort(ALL(inputs));
		reverse(ALL(inputs));
		REP(i, m) {
			if (get<1>(inputs[i]) == a) {
				a = get<2>(inputs[i]);
			}
			else if(get<2>(inputs[i]) == a) {
				a = get<1>(inputs[i]);
			}
		}
		cout << a << endl;
	}
}
#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3136
#include <iostream> // {{{
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <cstdio> // }}}

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

using ll = long long;

using namespace std;

const int N = 2000;
int main() {
    long n,y;
    cin >> n >> y;
    rep(i,n+1){
        rep(j,(n-i)+1){
            rep(k,(n-i-j)+1){
                if(i+j+k == n && (long)(k*10000+j*5000+i*1000)==y){
                    printf("%d %d %d\n", k, j, i);
                    return 0;
                }
            }
        }
    }
    printf("%d %d %d\n", -1, -1, -1);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std;
int main(){
	int N,K,M=0,A[100005],b;
	cin>>N>>K;
	cin>>A[0];
	b=A[0];
	M=A[0];
	for(int i=1;i<N;++i){
		cin>>A[i];
		int a=A[i];
		M=max(M,A[i]);
		if(A[i]<b){
			int d=b;
			b=a;
			a=d;
		}
		int r=a%b;
		while(r!=0){
			a=b;
			b=r;
			r=a%b;
		}
	}
	if(K<=M&&K%b==0){
		cout<<"POSSIBLE"<<endl;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,r;
	cin>>h>>r;
		if(h+r<0)
			cout<<-1<<endl;
		if(h+r==0)
			cout<<0<<endl;
		if(h+r>0)
			cout<<1<<endl;
	return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>

void selectionSort(int len, int *a){
    int mini;
    int tmp;
    for (int i = 0; i < len; i++){
        mini = i;
        for (int j = i + 1; j < len; j++){
            if (a[j] < a[mini]){
                mini = j;
            }
        }
        if (mini != i){
            tmp = a[i];
            a[i] = a[mini];
            a[mini] = tmp;
        }
    }
}

int main(void){
    int counter = 0;
    int N;
    scanf("%i", &N);
    int d[N];
    for (int i = 0; i < N; i++){
        scanf("%i", &d[i]);
    }
    selectionSort(N, &d[0]);
    for (int i = 0; i < N; i++){
        if (d[i] != d[i + 1]){
            counter++;
        }
    }
    printf("%i\n", counter);
}

Measured memory_bytes: 128
n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
ls = sorted(ls, key=lambda x: x[0])

p = 0
s = 0
i = 0
while s < m:
    a, b = ls[i]
    if s + b < m:
        s += b
        p += b * a
    else:
        p += (m - s) * a
        break
    i += 1
print(p)

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

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> p(N);
  for (int i = 0; i < N; i++) {
    string s;
    int r;
    cin >> s >> r;
    p.at(i) = make_tuple(s, -r, i+1);
  }
  
  sort(p.begin(), p.end()); //このままだと点数が低い順になっている
  
  for (tuple<string, int, int> t : p) {
    string s;
    int u, v;
    tie(s, u, v) = t;
    cout << v << endl;
  }
}

Measured memory_bytes: 3580
use proconio::input;

fn main() {
    input! {
        a: char,
        b: char,
    }
    
    let mut str_a = String::from("");
    let mut str_b = String::from("");
    
    for _ in 0..(b as usize - '0' as usize) {
        str_a.push(a);
    }
    
    for _ in 0..(a as usize - '0' as usize) {
        str_b.push(b);
    }
    
    if str_a <= str_b {
        println!("{}", str_a);
    } else {
        println!("{}", str_b);
    }
}


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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll big = 1000000007ll;
const ll big2 = 1000000009ll;
ll n,m,k,q,w,h,T;

vector<ll> A;
vector<ll> B;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    cin >> n;
    rep(c1,0,n)cin >> a, A.push_back(a);
    A.push_back(2000000000);
    cin >> m;
    rep(c1,0,m)cin >> a, B.push_back(a);
    sort(all(A));sort(all(B));
    bool fail = 0;
    ll l = 0;
    for(ll c1 = 0; c1 < m; c1++){
        if(l >= n){fail = 1; break;}
        while(A[l] < B[c1])l++;
        if(A[l] > B[c1]){fail = 1; break;}
        l++;
    }

    if(fail){cout << "NO\n";}else{cout << "YES\n";}

    return 0;
}


Measured memory_bytes: 4848
object Main extends App{
  import scala.io.Source._
  val a = readLine().toInt
  val b = readLine().toInt
  val c = readLine().toInt
  val x = readLine().toInt
  println((0 to a).filter(n => n * 500 <= x).map{n => x - 500 * n}.map{newx => (0 to b).filter(n => n * 100 <= newx).map{n => newx - 100 * n}.filter{nnx => nnx % 50 == 0 && nnx / 50 <= c}.length}.sum)
}

Measured memory_bytes: 25408
a, b = [int(i) for i in input().split()]
if a < 0:
    if b < 0:
        if  (b - a + 1)%2 == 0:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Zero")
elif a == 0:
    print("Zero")
else:
    if b <= 0:
        print("Zero")
    else:
        print("Positive")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n,y,x[N],d[N],m,ret[N],t[N],p[N];
ll k;
int main() {
	scanf("%d",&n);
	rep(i,1,n+1) {
		scanf("%d",x+i);
	}
	rep(i,1,n) d[i]=x[i+1]-x[i];
	scanf("%d%lld",&m,&k);
	rep(i,1,n) p[i]=i;
	rep(i,0,m) {
		scanf("%d",&y);
		swap(p[y-1],p[y]);
	}
	rep(i,1,n) ret[i]=i;
	for (;k;k>>=1) {
		if (k&1) {
			rep(i,1,n) t[i]=ret[p[i]];
			rep(i,1,n) ret[i]=t[i];
		}
		rep(i,1,n) t[i]=p[p[i]];
		rep(i,1,n) p[i]=t[i];
	}
	ll v=x[1];
	printf("%d\n",x[1]);
	rep(i,1,n) {
		v+=d[ret[i]];
		printf("%lld\n",v);
	}
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    //input
    int x = sc.nextInt();
    int y = sc.nextInt();

    //output
    //lowest x*2, highest x*4
    if( y < x*2 || y > x*4 ){
      System.out.println("No");
    }else{ //by adding 1 turtle you are adding 2 legs, must be even
      if( y%2 == 0 ){ //if even
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }

  }
}


Measured memory_bytes: 27088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m;
    cin>>n>>m;
    if(n==1)
    {
        if(m==0)
        {
            cout<<"0";
        }
        else
        {
            ll val;
            ll s,c;
            cin>>s>>c;
            val=c;
            ll num;
            for(ll i=0;i<(m-1);i++)
            {
                cin>>s>>c;
                if(c!=val)
                {
                    cout<<"-1";
                    return 0;
                }
            }
            cout<<val;
        }
    }
    else
    {
        if(m==0)
        {
            if(n==2)
                cout<<"10";
            else
                cout<<"100";
        }
        else
        {
            vector<ll>f;
            vector<ll>s;
            vector<ll>t;
            for(ll i=0;i<m;i++)
            {
                ll s1,c;
                cin>>s1>>c;
                if(s1==1)
                    f.push_back(c);
                else if(s1==2)
                    s.push_back(c);
                else 
                    t.push_back(c);
            }
            ll flag=1;
            vector<ll>ans;
            if(f.size()==0)
            {
                ans.push_back(1);
            }
            else
            {
                ll val=f[0];
                if(val==0) 
                    flag=0;
                for(ll i=1;i<f.size();i++)
                {
                    if(f[i]!=val)
                        flag=0;
                }
                ans.push_back(val);
            }
            if(s.size()==0)
            {
                ans.push_back(0);
            }
            else
            {
                ll val=s[0];
                for(ll i=1;i<s.size();i++)
                {
                    if(s[i]!=val)
                        flag=0;
                }
                ans.push_back(val);
            }
            if(n==3)
            {
                if(t.size()==0)
                {
                    ans.push_back(0);
                }
                else
                {
                    ll val=t[0];
                    for(ll i=1;i<t.size();i++)
                    {
                        if(t[i]!=val)
                            flag=0;
                    }
                    ans.push_back(val);
                }
            }
            if(flag==0)
                cout<<-1;
            else
            {
                for(ll i=0;i<ans.size();i++)
                    cout<<ans[i];
            }
        }
    }
}

Measured memory_bytes: 256
let () =
  let rec read () =
    let n = read_int () in
    if n = 0 then ()
    else
      begin
        let rec loop sum = function
            0 -> sum
          | i ->
             let m = read_int () in
             loop (sum+m) (i-1)
        in
        Printf.printf "%d\n" (loop 0 (n/4));
        read ()
      end
  in
  read ();;

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

int main() {
   int N,D,X;
  cin >> N >> D >> X;
  int ans=X;
  for(int i=0; i<N; i++) {
    int a;
    cin >> a;
    ans+=(D-1)/a+1;
  }
  cout << ans << endl;
}


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

using namespace std;

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

    int ans = 3*max({A, B, C}) - A - B - C;
    if(ans%2 == 0) {
        cout << ans/2 << endl;
    } else {
        cout << (ans+3) / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N=int(input())
ans=0
A=[]
for i in range(N):
  a=int(input())
  A.append(a)
for i in range(N-1):
  ans+=(A[i]//2)
  if A[i]%2==1 and A[i+1]>0:
    ans+=1
    A[i+1]-=1
    
ans+=(A[N-1]//2)

print(ans)

Measured memory_bytes: 7072
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

const int MOD = 1e9 + 7;

int N,K; vector<vector<int>> to;

vector<int> visited; vector<int> depth;
//-1を未到達とする

void BFS(int x){ //xを根とする
  visited = vector<int> (N,-1); depth = vector<int> (N);
  queue<int> Q; Q.push(x); visited[x] = K; //根の塗り方はK通り
  depth[x] = 0;
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    int cnt = 0; //cntはノード毎に使用
    for(int j = 0; j < to[p].size(); j++){
      //pから繋がるleafの塗り方を考える
     if( depth[p] == 0 && visited[to[p][j]] == -1)
       { visited[to[p][j]] = K - 1 - cnt; cnt++; Q.push(to[p][j]); 
         depth[to[p][j]] = depth[p] + 1;}
     else if( depth[p] != 0 && visited[to[p][j]] == -1)
       { visited[to[p][j]] = K - 2 - cnt; cnt++; Q.push(to[p][j]);
          depth[to[p][j]] = depth[p] + 1;}
       //更新するのは、まだ訪れていない時　親が根かそうでないかで場合分け可能
    }} }
     


int main(){
  cin >> N >> K; long long  ans = 1;
  
  to = vector<vector<int>> (N);
  
  for(int  i= 0; i< N -1 ; i++){
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b); to[b].push_back(a);} //隣接リスト作成
  
  BFS(0);
  
  for(int i = 0; i < N; i++){
    ans *= visited[i]; ans = ans % MOD;}
  
  cout << ans << endl; return 0;}
  

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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////
signed main() {
  int n,h;
  cin>>n>>h;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n){
    cin>>a[i]>>b[i];
  }

  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int i=0,damage=0,kaisuu=0;
  while(a[0]<b[i]&&i<=n-1){
    damage+=b[i];
    kaisuu++;
    if(damage>=h){
      cout<<kaisuu<<endl;
      exit(0);
    }
    i++;
  }
  cout<<kaisuu+(int)ceil((double)(h-damage)/a[0])<<endl;
}


Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define $ ios::sync_with_stdio(0);
using namespace std;
const int MAXN = 3123;
const int mod = 1e9 + 7;
int dp[MAXN], sum[MAXN];

int main() {$
    int n, m, k;
    string s;
    cin >> n >> s;
    s = "00" + s;
    dp[1] = 1;
    for (int i = 2; i<=n+1; ++i) {
        for (int j = 1; j<=n; ++j) {
            sum[j] = sum[j-1] + dp[j];
            if (sum[j] >= mod) sum[j] -= mod;
        }
        if (i <= n) {
            for (int j = 1; j<=i; ++j) {
                if (s[i] == '<') {
                    dp[j] = sum[j-1];     
                } else {
                    dp[j] = sum[n]-sum[j-1];
                    if (dp[j] < 0) dp[j] += mod;
                }
            }
        }
    }

    cout << sum[n] << '\n';

}


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


int x;//????????¬?????????????????°
int y;//???????????°
int z;//???????????????????????°
int v[4];//????????¬?????????????????????????????°
pair<int, int> n[51];//??????????????????(first:?¨???? second:??? ?????????:????????????)
double dp[51][6000] = { { 1 } };


void solve(){
	for (int i = 0; i < y; i++){
		for (int j = 0; j < 6000; j++){
			if (dp[i][j] == 0) continue;
			for (int k = 0; k < x; k++){
				int event = n[min(y, i + v[k])].first;
				int value = n[min(y, i + v[k])].second;
				if (event == 0){
					dp[min(y, i + v[k])][j] += dp[i][j] / x;
				}
				if (event == 1){
					dp[min(y, i + v[k] + value)][j] += dp[i][j] / x;
				}
				if (event == 2){
					dp[min(y, i + v[k])][j + value] += dp[i][j] / x;
				}
				if (event == 3){
					dp[min(y, i + v[k])][max(0, j - value)] += dp[i][j] / x;
				}
			}
		}
	}
}


void clear(){
	for (int i = 0; i < 51; i++){
		n[i] = { 0, 0 };
	}
	for (int i = 0; i < 51; i++){
		for (int j = 0; j < 6000; j++){
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
}


int main(){
	while(cin >> x >> y >> z, x + y + z){
		for (int i = 0; i < x; i++) cin >> v[i];
		for (int i = 0; i < z; i++){
			int trout, kind, value;
			cin >> trout >> kind >> value;
			n[trout] = { kind, value };
		}

		solve();

		double ans = 0;
		for (int i = 0; i < 6000; i++){
			ans += dp[y][i] * i;
		}

		cout << (int)ans << endl;

		clear();
	}

	return 0;
}

Measured memory_bytes: 5444
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200005

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 924844033;

char a[4]={'.','.','#','#'};
char b[4]={'.','#','.','#'};
int main(){
	int n;
	cin>>n;
	string s1,s2;
	char ch;
	bool bigfl=false;
	int sz=0;
	string str;
	while(sz<=n){
		bool flag=false;
		for(int i=0;i<4;i++){
			string hoge,fuga;
			hoge=s1+a[i];
			fuga=s2+b[i];
			cout<<hoge<<"\n"<<fuga<<"\n"; fflush(stdout);
			cin>>str;
			ch=str[0];
			if(ch=='e')goto HOGE;
			if(ch=='T'&&!flag){
				sz++;
				flag=true;
				s1=hoge;
				s2=fuga;
				goto A;
			}
		}
		if(!flag){
			break;
		}
	  A:;
	}
	while(sz<=n){
		bool flag=false;
		for(int i=0;i<4;i++){
			string hoge,fuga;
			hoge=a[i]+s1;
			fuga=b[i]+s2;
			cout<<hoge<<"\n"<<fuga<<"\n"; fflush(stdout);
			cin>>str;
			ch=str[0];
			if(ch=='e')goto HOGE;
			if(ch=='T'&&!flag){
				sz++;
				flag=true;
				s1=hoge;
				s2=fuga;
			}
		}
		if(!flag){
			break;
		}
	}
  HOGE:;
}


Measured memory_bytes: 724
import scala.io.StdIn.readLine
import scala.collection.immutable.Queue

object Main {

  def loop(n:Int,q:Queue[(String,Int)]):Queue[(String,Int)] = {
    if(n==0) q
    else {
      val m = readLine.split(" ")
      loop(n-1,q.enqueue((m(0),m(1).toInt)))
    }
  }

  def rrobin(q:Queue[(String,Int)],total:Int,qt:Int):Unit = {
    if(q.isEmpty) return
    else {
      val ((p,t),r) = q.dequeue
      val (newQ,newT) =
          if(t>qt) (r.enqueue((p,t-qt)),qt)
          else {
            println(p + " " + (t+total))
            (r,t)
          }
      rrobin(newQ,total+newT,qt)
    }
  }

  def main(args:Array[String]) = {
    val l = readLine.split(" ").map(_.toInt)
    val q = loop(l(0),Queue[(String,Int)]())

    rrobin(q,0,l(1))
  }
}

Measured memory_bytes: 126932
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, count=0;
  cin >> N;
  queue<int> a;
  for(int i=0;i<N;i++){
    int aa;
    cin >> aa;
    a.push(aa);
  }
  for(int i=0;i<N;i++){
    if((i+1)%2!=0&&a.front()%2!=0)
      count++;
    a.pop();
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

// DAME: 

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];
    sort(A.begin(), A.end());
    vector<ll> sum(n+1);
    rep(i, n+1){
        if (i==0) sum[i] = 0;
        else{
            sum[i] = sum[i-1] + A[i-1];
        }
    }
    ll l=1; ll r=2*1e5+5;
    ll nums = 0; ll ans = 0;
    ll k = (l+r)/2;
    while(l<r-1){
        nums = 0;
        ans = 0;
        k = (l+r)/2;
        rep(i, n){
            auto iter = lower_bound(A.begin(), A.end(), k-A[i]);
            nums += A.end() - iter;
            ans += (A[i])*(A.end()-iter) + sum[n] - sum[iter-A.begin()];
        }
        if (nums < m){
            r = k;
        }else{
            l = k;
        }
    }
    
    // l のほうで計算する
    nums = 0;
    ans = 0;
    rep(i, n){
        auto iter = lower_bound(A.begin(), A.end(), l-A[i]);
        nums += A.end() - iter;
        ans += (A[i])*(A.end()-iter) + sum[n] - sum[iter-A.begin()];
    }
    ans -= l*(nums-m);
    std::cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int x;
    cin >> x;

    int pattern = 0;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                int sum = 500 * i + 100 * j + 50 * k;
                if (sum == x)
                    ++pattern;
            }
        }
    }

    cout << pattern << '\n';
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
W = list(map(int,input().split()))

W_cumsum = np.array(W).cumsum()
solver = []
for i in range(N-1):
  var = abs(W_cumsum[-1] - 2 * W_cumsum[i])
  solver.append(var)
  
print(min(solver))

Measured memory_bytes: 21620
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    int           MAX        = 10000001;
    boolean       is_prime[] = new boolean[MAX];
    int           prime[]    = new int[MAX];
    List<Integer> primeList  = new ArrayList<Integer>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Main main = new Main();
        main.calcPrime();
        while (scanner.hasNext()) {
            int ans = 0;
            int input = scanner.nextInt();
            if (input == 0) {
                break;
            }
            for (int i = 2; i < input; i++) {
                if (main.is_prime[i]) {
                    int b = input - i;
                    if (i > b) {
                        break;
                    }
                    if (main.is_prime[b]) {
                        ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }

    public void calcPrime() {
        int p = 0;
        for (int i = 2; i < MAX; i++)
            is_prime[i] = true;
        for (int i = 2; i < MAX; i++) {
            if (is_prime[i]) {
                prime[p++] = i;
                for (int j = 2 * i; j < MAX; j += i)
                    is_prime[j] = false;
            }
        }
    }
}

Measured memory_bytes: 71504
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    for(int i=0; i<3; i++){
        int pre=0,suzu=0;
        int h,m,s;
        cin >> h >> m >> s;
        pre = h*3600 + m*60 + s;
        cin >> h >> m >> s;
        suzu = h*3600 + m*60 + s;
        suzu -= pre;
        cout << suzu/3600 << " " << (suzu%3600)/60 << " " << (suzu%3600)%60 << enld;
    }
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(a, 1, 3500) {
        rep(b, 1, 3500) {
            int m = 4 * a * b - n * a - n * b;
            if(m <= 0) continue;
            int lo = 1, hi = 3500;
            while(lo < hi) {
                int mi = lo + (hi - lo) / 2;
                int x = mi * m;
                if(x < n * a * b) {
                    lo = mi + 1;
                } else {
                    hi = mi;
                }
            }
            int x = lo * m;
            if(x == n * a * b) {
                cout << a << " " << b << " " << lo << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intInputInfoArry = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int[,] intBecAArray = new int[intInputInfoArry[0], intInputInfoArry[1]];

            int[] intInputBecAArray;
            for (int n = 0; n < intInputInfoArry[0]; n++)
            {
                intInputBecAArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

                for (int m = 0; m < intInputInfoArry[1]; m++)
                {
                    intBecAArray[n, m] = intInputBecAArray[m];
                }
            }

            int[] intBecBArray = new int[intInputInfoArry[1]];

            int intInputBecBArray;
            for (int m = 0; m < intInputInfoArry[1]; m++)
            {
                intInputBecBArray = int.Parse(Console.ReadLine());
                intBecBArray[m] = intInputBecBArray;
            }

            int[] intResultArry = new int[intInputInfoArry[0]];
            for (int n = 0; n < intInputInfoArry[0]; n++)
            {
                for (int m = 0; m < intInputInfoArry[1]; m++)
                {
                    intResultArry[n] += intBecAArray[n, m] * intBecBArray[m];
                }
                Console.WriteLine(intResultArry[n]);
            }

        }
    }
}



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

int main() {
	int n; cin >> n;
	tuple<int, int, int> t[n];
	for(int i = 0; i < n; ++i) {
		int x, y; cin >> x >> y;
		t[i] = make_tuple(x, y, i);
	}
	sort(t, t + n);
	dsu uf(n);
	set<pair<int, int>> st;
	for(auto& [_x, y, idx] : t) {
		int mini = y, midx = idx;
		for(auto itr = st.begin(); itr != st.end();) {
			if(itr->first < y) {
				uf.merge(idx, itr->second);
				if(itr->first < mini) {
					mini = itr->first;
					midx = itr->second;
				}
				itr = st.erase(itr);
			} else {
				break;
			}
		}
		st.emplace(mini, midx);
	}
	for(int i = 0; i < n; ++i) {
		cout << uf.size(i) << '\n';
	}
	return 0;
}


Measured memory_bytes: 11032
#include<bits/stdc++.h>
#define pb push_back 
#define mp make_pair
using namespace std;

const int maxn=2e5+7;
typedef long long ll;

int n,m;
ll a[maxn];

int main()
{
	int i,k;
	ll j;
	scanf("%d",&n);
	for(i=1;i<=n;++i) scanf("%lld",&j),a[i]=a[i-1]+j;
	
	ll minv=1e18;
	
	for(i=1;i<n;++i)
	{
		minv=min(minv,abs(a[i]*2-a[n]));
	}
	
	printf("%lld",minv);
	
	
	return 0;
}


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

ll gcd(ll a, ll b) {
  return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}
int main() {
  int n;
  ll l, s;
  ll a[100];
  s = 0;
  cin >> n;
  rep(i, n)
  {
    cin >> a[i];
  }
  l = 1;
  rep(i, n)
  {
    l = lcm(l, a[i]);
  }
  rep(i, n)
  {
    s += l / a[i];
  }
  cout << ((double) l / s);
  return 0;
}

Measured memory_bytes: 256
import random
import time

def search(day, c, s):
    schedule = []
    satisfy = []
    score = 0
    date = [0] * 26
    
    for d in range(day):
        tmp = 0
        contest = 0
        nmax = -float('inf')
        for i in range(26):
            tmp += c[i] * (d + 1 - date[i])
        for i in range(26):
            tmp2 = s[d][i] - tmp + c[i] * (d + 1 - date[i])
            if nmax < tmp2:
                nmax = tmp2
                contest = i
        
        satisfy.append(tmp - c[contest] * (d + 1 - date[contest]))
        date[contest] = d + 1
        schedule.append(contest)
        score += s[d][contest] - satisfy[d]

    return score, schedule, satisfy

def change(day, contest,D, c, s, schedule, satisfy):
    ret = 0
    date = [0] * 26

    for d in range(D):
        if d == day:
            now = contest + 1
            date[now - 1] = d + 1
        else:
            now = schedule[d] + 1
            date[now - 1] = d + 1
        if d < day:
            ret += satisfy[d]
            continue

        tmp = 0
        for i in range(26):
            tmp += c[i] * (d+1 - date[i])
        ret += tmp
        satisfy[d] = tmp

    return ret

def Main():
    D = int(input())
    c = tuple(map(int, input().split()))
    s = [tuple(map(int, input().split())) for _ in range(D)]
    
    dissatisfy=[]
    schedule = []
    score = 0
    start = time.time()

    ans, schedule, dissatisfy = search(D, c, s)
    
    for i in range(D):
        score += s[i][schedule[i]]

    while time.time() - start < 1.95:
        contest = random.randint(0, 25)
        day = random.randint(0, D - 1)
        if schedule[day] == contest:
            continue

        save = dissatisfy.copy()
        dec2 = change(day,contest,D,c, s, schedule, dissatisfy)
        score2 = score - s[day][schedule[day]] + s[day][contest]

        if ans < score2 - dec2:
            ans = score2 - dec2
            score = score2
            schedule[day] = contest
        else:
            dissatisfy = save

    for i in range(D):
        print(schedule[i] + 1)

if __name__ == "__main__":
    Main()

Measured memory_bytes: 9672
#include<iostream>
#include<map>
#include<string>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int x[100001],n,X,ans;
int gcd(int x,int y)
{
	while(y)
	{
		int t=y;
		y=x%y;
		x=t;
	}
	return x;
}
int main()
{
	scanf("%d%d",&n,&X);
	scanf("%d",&x[0]);
	ans=abs(X-x[0]);
	for(int i=1;i<n;i++)
	{
		scanf("%d",&x[i]);
		x[i]=abs(X-x[i]);
		ans=gcd(ans,x[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
const int MAX=50;
int main(){
   int n,m,a,b,c[MAX]={};
   cin>>n>>m;
   for(int i=0;i<m;i++){
       cin>>a>>b;
       c[a-1]++;
       c[b-1]++;
   }
   for(int i=0;i<n;i++){
       cout<<c[i]<<endl;
   }
   return 0;
}

Measured memory_bytes: 764
#include <stdio.h>

  int main(void){
      char sets[20];
      int i;
      for(i=0; i<20; i++){
       sets[i] = getchar();
     }
      for(i=19; i>=0; i--){
       printf("%c",sets[i]);
}
     printf("\n");
    return 0;
}

Measured memory_bytes: 520
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
/*
    make expression
    
*/
void input()
{
    cin>>N;
    A.resize(N);
    B.resize(N);
    rep(i,0,N-1){
        cin>>A[i];
    }
    rep(i,0,N-1){
        cin>>B[i];
    }
}
void solve()
{
    int asum = 0;
    for(auto x : A){
        asum += x;
    }
    int bsum = 0;
    for (auto x : B){
        bsum += x;
    }

    if (asum < bsum) {
        cout<<-1<<endl;
        return;
    }
    vector<int> c(N,0);
    rep(i,0,N-1){
        c[i] = A[i] - B[i];
    }
    sort(all(c));

    int minusc = 0;
    int ans = 0;
    for(auto x : c){
        if (x < 0) minusc += -x, ans++;
    }

    rrep(i, N-1, 0){
        if (c[i] <= 0 || minusc <= 0) break;
        ans++;
        minusc -= c[i];
    }

    cout<<ans<<endl;


    


}
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a,b,c,x;cin>>a>>b>>c>>x;
  int ans=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x)ans++;
      }
    }
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
N=int(input())
W=[int(a) for a in input().split()]
ans=10**21

for t in range(N-1):
    S1=sum(W[:t+1])
    S2=sum(W[t+1:])
    val=abs(S1-S2)
    
    if ans>val:
        ans=val

print(ans)

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

int main () {
  int N, M;
  cin >> N >> M;
  int a[60];
  int b[60];
  int answer[N] = {0};
  for (int i=0;i<M;++i) {
    cin >> a[i] >> b[i];
  }
  for (int i=0;i<M;++i) {
    answer[a[i] - 1] += 1;
    answer[b[i] - 1] += 1;
  }
  for (int i=0;i<N;++i) {
    cout << answer[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 1000000007
#define pii pair<int, int>
#define PI 2*acos(0.0)

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

int main()
{
    io;
    ll po[200005] = {1};
    for(int i = 1; i< 200005; i++)
        po[i] = po[i-1]*2%mod;
    ll ans = -1, n;
    cin>>n;
    map<pair<ll, ll> , pair<int, int> > cnt;
    while(n--)
    {
        ll x, y;
        cin>>x>>y;
        if( !x && !y)
        {
            ans++;
            continue;
        }
        if(pair<ll, ll> (x, y) < pair<ll, ll> (0, 0))
        {
            x = -x;
            y = -y;
        }
        ll g = gcd(abs(x), abs(y));
        x/= g; y /= g;
        if(y > 0)
            cnt[{x, y}].first++;
        else
            cnt[{-y, x}].second++;
    }
    ll res = 1;
    for(auto p: cnt)
        res = res*(po[p.second.first] + po[p.second.second] - 1)%mod;
    cout<< (ans+res+mod)%mod;
    return 0;
}


Measured memory_bytes: 17520
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int board[510][510];

string yes = "Yes", no = "No";

signed main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;

	rep(y, H) rep(x, w) board[y][x] = 1000;
	board[h - 1][w - 1] = -1000 * (h * w - 1) - 1;

	rep(y, H) rep(x, W) {
		board[y][x] = board[y % h][x % w];
	}

	int sum = 0;
	rep(y, H) rep(x, W) {
		sum += board[y][x];
	}
	if (sum <= 0) {
		cout << no << endl;
	} else {
		cout << yes << endl;
		rep(y, H) {
			rep(x, W) {
				cout << board[y][x];
				if (x < W - 1) cout << ' ';
			}
			cout << endl;
		}
	}

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

const ll mod = 1e9 + 7;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  V<int> a(n);
  rep(i, n) cin >> a[i];

  ll single = 0;
  rep(j, n) rep(i, j) {
    if (a[i] > a[j]) single++;
  }
  int num = 0;
  rep(i, n) rep(j, n) {
    if (a[i] > a[j]) num++;
  }
  ll tmp = k * (k - 1) / 2 % mod;
  tmp = tmp * num % mod;

  ll ans = single * k % mod;
  ans += tmp;
  ans %= mod;

  cout << ans << endl;
}


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

typedef long long ll;
const int maxn = 100010;
int n; ll a[maxn];
vector<int> G[maxn];

ll dfs(int v, int f) {
    if (G[v].size() == 1) return a[v];
    ll sum = 0;
    vector<ll> V;
    for (int u : G[v]) if (u ^ f) {
        ll t = dfs(u, v);
        assert(t >= 0);
        sum += t, V.push_back(t);
    }
    ll ub = sum - a[v];
    if (ub < 0) printf("NO\n"), exit(0);
    for (ll x : V) {
        ll t = min(x, sum - x);
        if (t + (sum - x - t) / 2 < ub) printf("NO\n"), exit(0);
    }
    a[v] -= ub, sum -= ub * 2;
    if (a[v] < 0 || sum < 0) printf("NO\n"), exit(0);
    if (!f && sum) printf("NO\n"), exit(0);
    a[v] -= sum;
    if (a[v]) printf("NO\n"), exit(0);
    return sum;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    if (n == 2) {
        printf("%s\n", a[1] == a[2] ? "YES" : "NO"), exit(0);
    }
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d %d", &u, &v);
        G[u].push_back(v), G[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        if (G[i].size() > 1) { dfs(i, 0); break; }
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

int main(){
    int T, D;
    while(cin >> T >> D) {
        int ta, tb, da, db;
        cin >> ta >> tb >> da >> db;
        double res = 1e16;
        for(int i = 0; da * i <= D; i++) {
            for(int j = 0; da * i + db * j <= D; j++) {
                if(i + j == 0) continue;
                double a = 1.0 * (ta * da * i + tb * db * j) / (da * i + db * j);
                res = min(res, abs(T - a));
            }
        }
        printf("%.12f\n", res);
    }
    return 0;
}

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

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl '\n'

int main() {
  fast_io;
  vector<int> x(5);
  for (int i = 0; i < 5; i++)
    cin >> x[i];
  sort(ALL(x));
  int ans = INT_MAX;
  do {
    int t_now = 0;
    int diff = 0;
    for (int i = 0; i < 5; i++) {
      t_now += diff;
      t_now += x[i];
      diff = (10 - (x[i] % 10)) % 10;
    }
    ans = min(ans, t_now);
  } while (next_permutation(ALL(x)));
  cout << ans << endl;
  return 0;
}


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

const int white = 0;
const int red = 1;
const int blue = 2;
const int W = 3;
const int H = 3;

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int Ex, Ey;

class Cube
{
public:
	int front, top, left;

	Cube()
		:front(red), top(white), left(blue)
	{}

	void rotL()
	{
		swap(top, left);
	}

	void rotT()
	{
		swap(front, top);
	}
};

Cube field[3][3];
int goal[3][3];

void Init()
{
	for(int i=0; i<9; i++) {
		int x = i%3;
		int y = i/3;

		field[x][y] = Cube();
	}
}

int calc(int ex, int ey)
{
	int res = -1;
	for(int i=0; i<9; i++) {
		int x = i%3;
		int y = i/3;

		if(field[x][y].top != goal[x][y]) {
				res++;
		}
	}

	if(ex == Ex && ey == Ey) res--;

	return res;
}

int md(int ex, int ey)
{
	int A = abs(Ex-ex) + abs(Ey-ey);
	A = max(A, calc(ex,ey));

	return A;
}

bool isGoal(int ex, int ey)
{
	if(ex != Ex || ey != Ey) return false;

	for(int i=0; i<9; i++) {
		int x = i%3;
		int y = i/3;

		if(x == Ex && y == Ey) continue;
		if(field[x][y].top != goal[x][y]) return false;
	}

	return true;
}

bool dfs(int ex, int ey, int cost, int limit, int d)
{
	if(isGoal(ex,ey)) return true;
	if(cost + md(ex, ey) > limit) return false;

	for(int i=0; i<4; i++) {
		int nx = ex + dx[i];
		int ny = ey + dy[i];

		if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;

		if( d == 0 && i == 1 || d == 1 && i == 0) continue;
		if( d == 2 && i == 3 || d == 3 && i == 2) continue;
		
		Cube c = field[nx][ny];
		field[ex][ey] = c;
		if(i < 2) field[ex][ey].rotL();
		else field[ex][ey].rotT();

		if(dfs(nx,ny,cost+1, limit, i)) return true;

		field[nx][ny] = c;
	}

	return false;
}


int solve(int ex, int ey)
{

	int limit=30, res = -1;

	
	for(int i=0; i<=limit; i++) {
		Init();
		if(dfs(ex,ey,0,i,-1)) {

			res = i;
			break;
		}
	}

	return res;
}

int main()
{
	int ex,ey;
	while(cin >> ex >> ey, (ex||ey)) {
		for(int i=0; i<3; i++)
		for(int j=0; j<3; j++) {
			char c;
			cin >> c;
			if(c == 'W') goal[j][i] = white;
			if(c == 'R') goal[j][i] = red;
			if(c == 'B') goal[j][i] = blue;
			if(c == 'E') {
				Ex = j;
				Ey = i;
				goal[j][i] = -1;
			}
		}

		cout << solve(ex-1, ey-1) << endl;
	}
}

Measured memory_bytes: 868