akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007


map<ll,ll>a;
int main() {
	ll n,k;
	cin>>n>>k;
	if(n==1){
		cout << k;
		return 0;
	}
	for(long long  i=2;i*i<=k;i++){
		while(k%i==0){
			a[i]++;
			k=k/i;
		}
	}
	ll ans=1;
    for(auto itr = a.begin(); itr != a.end(); ++itr) {
        ll val=itr->second;
        ll key=itr->first;
        if(val>=n){
        	ll now=val/n;
        	key=pow(key,now);

        	ans*=key;
        }
    }
	cout <<ans;
	return 0;
}

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



int main() {
 
  string s,t;
  cin>>s>>t;
  int i=0;
  int c=0;
  int j=0;
  int ans=10000;
  int tmp=0;
  while(true){
    
    if(i>s.length())break;
    if(j>=t.length()){
      if(tmp<ans)ans=tmp;
      tmp=0;
      j=0;
      c+=1;
      i=c;
      continue;
    }
    if(s[i]!=t[j])tmp+=1;
    j+=1;i+=1;
  }
  cout<<ans<<endl;
  return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

long long gcd(long long A, long long B) {  // A>B
  if (A < B) swap(A, B);
  if (B == 0)
    return A;
  else {
    return gcd(B, A % B);
  }
}
 

int main() {
    ll A,B;
    cin >> A >> B;
    ll G =  gcd(A,B); //最大公約数
    ll cnt = 1;

    for(ll p=2;p*p<=G;p++){
      if(G%p!=0) continue;
      while(G%p==0){
        G /= p;
      }
        cnt++;
    }

    if(G!=1)cnt++;

    cout << cnt << endl;

}



Measured memory_bytes: 256
#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 n, k, c; cin >> n >> k >> c;
  string s; cin >> s;
  
  auto getPosition = [&](){
    vector<int> res;
  for(int i=0; i<n && res.size()<=k ;){
    if(s[i]=='x') i++;
    else{ res.push_back(i); i+= c+1;}
  }    
    return res;
  };
  
  vector<int> l, r;
  l = getPosition();
  reverse(s.begin(), s.end());
  r = getPosition();
  rep(i, r.size()) r[i] =n-1-r[i];
  reverse(r.begin(), r.end());

  rep(i, k){
    if(l[i] == r[i]) cout << l[i]+1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 5664
n = int(input().strip())
h = list(map(int, input().strip().split()))

dp=[10**9]*n

dp[0]=0
for i in range(n):
    if i+1<=n-1:
        dp[i+1]=min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
    if i+2<=n-1:
        dp[i+2]=min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))
print(dp[-1])

Measured memory_bytes: 13976
// inputに入力データ全体が入る
function Main(input) {
  input = input.split('\n');
  var size = input[0];
  var i, j, pi, xi, yi, xj, yj, d;
  var result = 0;
  for(i = 1; i <= size; i++) {
    pi = input[i].split(' ');
    xi = pi[0];
    yi = pi[1];
    for(j = i + 1; j <= size; j++) {
      pj = input[j].split(' ');
      xj = pj[0];
      yj = pj[1];
      d = Math.sqrt((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj))
      result += d;
    }
  }
  console.log(result * 2 / size);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  string s; cin >> s;
  rep(i, s.size()){
    if(s[i] == '?') s[i] = 'D';
  }
  cout << s << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int p, q, r;
  cin >> p >> q >> r;
  cout << min({ p + q, q + r, r + p }) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

void print(string x){
    cout << x << endl;
}

const int MAX_V = 1e5;
vector<int> es[MAX_V];
vector<bool> used(MAX_V, false);

bool flag = false;

void dfs(int now, int pre, int s){
    used[now] = true;
    for(auto &e: es[now]){
        if(e == pre) continue;
        if(e == s) flag = true;
        if(used[e]) continue;
        dfs(e, now, s);
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    rep(i, M){
        int u, v; cin >> u >> v; u--, v--;
        es[u].pb(v), es[v].pb(u);
    }
    vector<int> four, six;
    rep(i, N){
        int n = sz(es[i]);
        if(n&1) {print("No"); return 0;}
        elif(n == 4) four.pb(i);
        elif(n >= 6) six.pb(i);
    }
    if(sz(six) || sz(four) >= 3) {print("Yes"); return 0;}
    if(sz(four) <= 1){print("No"); return 0;}
    int s = four[0], t = four[1];
    used[t] = true;
    dfs(s, -1, s);
    if(flag) print("Yes");
    else print("No");
}

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

int main() {
  int N;
  cin >> N;
  long long T = 16;
  long long A = 16;
  long long G = 15;
  long long C = 14;
  long long AC = 3;
  long long AG = 4;
  long long GA = 4;
  long long AGO = 3;
  long long AGA = 1;
  long long AOG = 3;
  long long AAG = 1;
  long long AGG = 1;
  long long AO = 15;
  long long AA = 4;
  long long x,P;
  for (int i=3; i<N; i++) {
    P = (A + G + C + T) % 1000000007;
    C = (P - AG - GA - AGO - AOG + AGA + AGG + AAG + 4000000028) % 1000000007;
    AGO = (AG * 3) % 1000000007;
    AGA = AG % 1000000007;
    AOG = (AO - AC + 1000000007) % 1000000007;
    AAG = AA % 1000000007;
    AGG = AG % 1000000007;
    AG = A % 1000000007;
    AO = (A * 4 - GA + 1000000007) % 1000000007;
    AA = A % 1000000007;
    x = AC % 1000000007;
    AC = (A - GA + 1000000007) % 1000000007;
    GA = G % 1000000007;
    T = P % 1000000007;
    A = P % 1000000007;
    G = (P - x + 1000000007) % 1000000007;
  }
  cout << (A + G + C + T) % 1000000007 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int selectionSort(int *,int);
void swap(int *,int *);
int main(void){
	int i,n;
	int count;
	int a[100];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	count=selectionSort(a,n);
	
	for(i=0;i<n;i++){
		printf("%d",a[i]);
		if(i<n-1)
			printf(" ");
	}
	printf("\n");
	printf("%d\n",count);
	
	
	return 0;
}

int selectionSort(int *a,int n){
	int i,j;
	int minj,count=0;
	
	for(i=0;i<n;i++){
		minj=i;
		for(j=i;j<n;j++){
			if(a[j]<a[minj])
				minj=j;
		}
		if(a[i]!=a[minj]){
			swap(&a[i],&a[minj]);
			count++;
		}
	}
	
	return count;
}


void swap(int *px,int *py){
	int tmp=*px;
	*px=*py;
	*py=tmp;
}

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

int main(){
  ll point;
  cin >> point;
  cout << 10-point/200 << endl;
}

Measured memory_bytes: 3616
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())
    SW = [list(map(int, input().split()))[1:] for _ in range(M)]
    P = list(map(int, input().split()))

    num = 0
    for i in range(2**N):
        ng = False
        for j, sw in enumerate(SW):
            n = 0
            for k in sw:
                if i & 2**(k-1):
                    n = n + 1
            if n%2 != P[j]:
                ng = True
                break
        else:
            num = num + 1
    
    print(num)



# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc128","c",main)

Measured memory_bytes: 3064
from collections import deque
n,q=map(int,input().split())
A=[[] for i in range(n)] #繋がっている頂点
for i in range(n-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  A[a].append(b)
  A[b].append(a)
B=[0]*n #コスト
for i in range(q):
  p,q=map(int,input().split())
  p=p-1
  B[p]=B[p]+q
#BFSの時間じゃああああ!!!!!!
C=deque([0])
D=[0]*n #visited枠
while len(C)>0:
  c=C[0]
  C.popleft()
  D[c]=1
  for i in range(len(A[c])):
    if D[A[c][i]]==0:
      C.append(A[c][i])
      B[A[c][i]]+=B[c]
for i in range(n):
  print(B[i],end=" ")
print()

Measured memory_bytes: 105804
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second



int main() {
	int n, a, b, c, ans = 0;
	string s, t;
	cin >> a >> b;
	if (b >= a)cout << a << endl;
	else cout << a - 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#define int long long
#define MAX(a,b) ((a) > (b)) ? (a) : (b)
#define MIN(a,b) ((a) < (b)) ? (a) : (b)
using namespace std;

signed main()
{
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a % 2 == 1)
		{
			cnt++;
		}
	}
	if (cnt % 2 == 0)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 384
#![allow(unused_imports)]
use petgraph::unionfind::UnionFind;
use proconio::*;
use std::cmp::*;
use std::fs;
use std::io::*;

#[fastout]
fn main() {
   input! {
      mut n: usize,
   }
   let ans = (1..(n+1)).fold(0, |sum, a| {
       sum + match (a%3, a%5) {
           (_,0) => 0,
           (0,_) => 0,
           _ => a,
       }
   });
   println!("{}", ans);
}


Measured memory_bytes: 2180
#-------最強ライブラリSCC(Python) ver25252------
class scc_graph:
  # n 頂点数
  def __init__(s, n): 
    s._n = n
    s.g = [[] for _ in range(n)]
    s.rg = [[] for _ in range(n)]
  def num_vertices(s): return s._n
  # 辺を追加 frm 矢元 to 矢先
  # O(1)
  def add_edge(s, frm, to): 
    s.g[frm].append(to)
    s.rg[to].append(frm)

  # グループの個数と各頂点のグループidを返す
  def scc_ids(s):
    def dfs(v):
      stack = [v]
      while stack:
        t = stack.pop()
        vis[t] = True
        for i in s.g[t]:
          if not vis[i]:
            stack.append(t)
            stack.append(i)
            break
        else:
          vs.append(t)

    def rdfs(v, n):
      stack = [v]
      vis[v] = True
      ids[v] = n
      while stack:
        t = stack.pop()
        vis[t] = True
        for i in s.rg[t]:
          if not vis[i]:
            ids[i] = n
            stack.append(i)

    vis = [False] * s._n 
    vs = []
    ids = [-1] * s._n
    for i in range(s._n):
      if not vis[i]:
        dfs(i)
    group_num = 0
    vis = [False] * s._n 
    for i in vs[::-1]:
      if not vis[i]:
        rdfs(i, group_num)
        group_num += 1
    return group_num, ids 

  # 強連結成分となっている頂点のリストのリスト トポロジカルソート済み
  # O(n + m)
  def scc(s):
    ids = s.scc_ids()
    group_num = ids[0]
    counts = [0] * group_num
    for x in ids[1]: counts[x] += 1
    groups = [[] for _ in range(group_num)]
    for i in range(s._n):
      groups[ids[1][i]].append(i)
    return groups

#-------最強ライブラリここまで------

import sys
def main():
  input = sys.stdin.readline

  n, m = list(map(int, input().split()))
  ab = [list(map(int, input().split())) for _ in range(m)]

  g = scc_graph(n)

  for i in range(m):
    u, v = ab[i]
    g.add_edge(u, v)

  scc = g.scc()

  print(len(scc))

  for v in scc:
    print(len(v), end = " ")
    for x in v:
      print(x, end = " ")
    print("")

main()

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

using namespace std;
using ll = long long;

int GCD(int x, int y, int z)
{
    int gcd = 1, current = 1, last = min(min(x, y), z);
    while (current <= last)
    {
        if ((x % current == 0) && (y % current == 0) && (z % current == 0))
        {
            gcd = current;
        }
        current++;
    }
    return gcd;
}

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

    ll sum = 0;
    for (int i = 1; i <= number; i++)
    {
        for (int j = i; j <= number; j++)
        {
            for (int k = j; k <= number; k++)
            {
                if (i == j && j == k)
                {
                    sum += GCD(i, j, k);
                }
                else if (i == j || k == j || i == k)
                {
                    sum += (GCD(i, j, k) * 3);
                }
                else
                {
                    sum += (GCD(i, j, k) * 6);
                }
            }
        }
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scanner= new Scanner(System.in);
        int N = scanner.nextInt();
        int m = 0;
        String s = String.valueOf(N);
        for(int i = 0; i < s.length(); i++){
            m += s.charAt(i) - '0';
        }
        if(N % m == 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> a(3 * N);
    REP(i, 3 * N) { cin >> a.at(i); }

    ll ans = 0;

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> front_use;
    vector<pair<int, int>> back;
    vector<bool> back_use(3 * N);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> back_unuse;

    REP(i, N) {
        front_use.push(make_pair(a[i], i)); // 使う部分
        ans += a[i];
    }
    FOR(i, N, 3 * N) { back.emplace_back(a[i], i); }
    sort(ALL(back));
    REP(i, N) {
        back_use[back[i].second] = true; // 使う部分をture
        ans -= back[i].first;
    }
    FOR(i, N, 2 * N) { back_unuse.push(back[i]); } // 使わない部分を保存

    ll tmp = ans;
    // cout << ans << endl; // debug
    FOR(i, N, 2 * N) {
        // cout << "i:" << i << " back_use:" << back_use[i] << " tmp:" << tmp << endl; // debug
        if (back_use[i]) { // backが使っていたら、backから取り上げてfrontへ
            tmp += 2 * a[i];
            front_use.push(make_pair(a[i], i));
            tmp -= front_use.top().first; // frontの最小を取り上げる
            front_use.pop();
            while (back_unuse.top().second <= i) {
                back_unuse.pop();
            }
            tmp -= back_unuse.top().first; // backにunsedの最小値を加える
            back_use[back_unuse.top().second] = true;
            back_unuse.pop();
        } else {
            tmp += a[i];
            tmp -= front_use.top().first; // frontの最小を取り上げる
            front_use.pop();
        }
        // cout << " tmp:" << tmp << endl;
        chmax(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;

vector<int> g[maxn];

void solve() {
    int n;
    cin >> n;

    vector<int> v(n);
    for (int i = 1; i < n; ++i) {
        cin >> v[i];
        g[v[i]].push_back(i + 1);
    }
    for (int i = 1; i <= n; i++)cout << g[i].size() << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 15500
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007ll
using namespace std;

int r1,c1,r2,c2,pw[2000010],rev[2000010];

inline int my_pow(int a,int b)
{
	if(b==0ll) return 1ll;
	if(b==1ll) return a;
	int res=my_pow(a,b/2);
	if(b%2ll==0ll) return (res*res)%MOD;
	else return (((res*res)%MOD)*a)%MOD; 
} 

inline int calc(int r,int c)
{
	int val=(pw[r+c]*rev[r])%MOD;
	return (val*rev[c])%MOD;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>r1>>c1>>r2>>c2;
	pw[0]=1ll;rev[0]=1ll;
	for(int i=1;i<=r2+c2+5;i++){
		pw[i]=(pw[i-1]*i)%MOD;
		rev[i]=my_pow(pw[i],MOD-2ll);
	}
	int res=0ll;
	for(int i=r1;i<=r2;i++){
		int cur=calc(i+1,c2)-calc(i+1,c1-1);
		if(cur<0ll) cur+=MOD;
		res+=cur;
		if(res>=MOD) res-=MOD;
	}
	cout<<res<<endl;
	return 0;
}

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

int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
char f[200][200];
int d[200][200];

struct st {
	int x, y, c;
};
bool operator<(st a, st b) { return a.c > b.c; }
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		memset(f, '.', sizeof(f));
		int gx, gy;
		for (int i = 1; i <= m; i++) {
			scanf("%s", f[i] + 1);
			f[i][n + 1] = '.';
			for (int j = 1; j <= n; j++) {
				if (f[i][j] == '&')gx = i, gy = j;
			}
		}
		m++; n++;
		priority_queue<st>que;
		memset(d, 0x3f, sizeof(d));
		d[0][0] = 0; que.push({ 0,0,0 });
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (p.c != d[p.x][p.y])continue;
			rep(i, 4) {
				int nx = p.x + dx[i], ny = p.y + dy[i];
				if (!(0 <= nx&&nx <= m && 0 <= ny&&ny <= n))continue;
				if (f[p.x][p.y] != '#'&&f[nx][ny] == '#') {
					if (d[nx][ny] > p.c + 1) {
						d[nx][ny] = p.c + 1;
						que.push({ nx,ny,d[nx][ny] });
					}
				}
				else {
					if (d[nx][ny] > p.c) {
						d[nx][ny] = p.c;
						que.push({ nx,ny,d[nx][ny] });
					}
				}
			}
		}
		printf("%d\n", d[gx][gy]);
	}
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

// セグメントツリー
class SegmentTree {
private:
    Int n;
    vector<Int> node;
    Int ident = 0;
    Int f(Int x, Int y) {
        return max(x, y);
    }
public:
    SegmentTree(vector<Int> v) {
        Int v_size = v.size();
        n = 1;
        while (n < v_size) {
            n *= 2;
        }
        node.resize(2 * n, ident);
        for (Int i = 0; i < v_size; i++) {
            node[n + i] = v[i];
        }
        for (Int i = n - 1; i >= 1; i--) {
            node[i] = f(node[i * 2], node[i * 2 + 1]);
        }
    }
    void update(Int x, Int val) {
        x += n;
        node[x] = val;
        while (x > 1) {
            x /= 2;
            node[x] = f(node[x * 2], node[x * 2 + 1]);
        }
    }
    // [a, b) での答え
    Int query(Int a, Int b, Int k = 1, Int l = 0, Int r = -1) {
        //cout << l << " " << r << endl;
        if (r < 0) {
            r = n;
        }
        if (r <= a or b <= l) {
            return ident;
        }
        if (a <= l and r <= b) {
            return node[k];
        }
        Int vl = query(a, b, 2 * k, l, (l + r) / 2);
        Int vr = query(a, b, 2 * k + 1, (l + r) / 2, r);
        return f(vl, vr);
    }
};

int main() {
    Int n;
    cin >> n;
    vector<Int> h(n), a(n);
    for (Int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<Int> dp(n + 1, 0);
    SegmentTree seg(dp);
    for (Int i = 0; i < n; i++) {
        Int ma = seg.query(0, h[i]);
        seg.update(h[i], ma + a[i]);
    }
    dump(seg.query(0, n + 1));
    return 0;
}

Measured memory_bytes: 10624
#include<cstdio>
#include<iostream>
using namespace std;
struct tur{
	int x,y;
}q[100001];
int c[501][401],n,m,ans,a[401][401];
inline bool check(int x,int y){
	if (a[x][y]) return false;
	if (a[x][0]||a[y][0]) return false;
	for (int i=1; i<=n; i++)
		if (c[x][i]&&c[y][i]) return false;
	return true;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1; i<=m; i++)
		scanf("%d%d",&q[i].x,&q[i].y),
		a[q[i].x][q[i].y]=a[q[i].y][q[i].x]=1;
	for (int i=1; i<=n; i++){
		c[i][i]=1;
		for (int j=m; j>=1; j--){
			if (c[i][q[j].x]&&c[i][q[j].y]){a[i][0]=1; break;}
			if (c[i][q[j].x]) c[i][q[j].y]=1;
			else if (c[i][q[j].y]) c[i][q[j].x]=1;
		}
	}
	for (int i=1; i<=n; i++)
		for (int j=1+i; j<=n; j++)
			if (check(i,j)) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2304
#include "stdio.h"
int main()
{
	int h,w,n,end,max;
	scanf("%d",&h);
	scanf("%d",&w);
	scanf("%d",&n);
	if(h<w)
		max=w;
	else
		max=h;
	end=n/max;
	if(n%max!=0)
		end++;
	printf("%d\n",end);
	return 0;
}

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

int main() {
  int N, M; cin >> N >> M;
  vector< pair<int, int> > lr(N);
  for(int i=0; i<N; i++) lr[i] = make_pair(i, i);

  vector< pair<int, int> > info(M);
  for(int i=0; i<M; i++) {
    cin >> info[i].first >> info[i].second;
  }
  sort(info.begin(), info.end());

  for(int i=0; i<M; i++) {
    int y = info[i].second;
    auto &A = lr[y-1], &B = lr[y];

    int mi = min(A.first, B.first);
    int ma = max(A.second, B.second);

    pair<int, int> newElem(mi, ma);
    A = B = newElem;
  }

  for(int i=0; i<N; i++) {
    cout << lr[i].second - lr[i].first + 1 << " \n"[i+1==N];
  }
  return 0;
}



Measured memory_bytes: 5124
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define F first
#define S second
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define all(vec) vec.begin(), vec.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 2e5 + 10;
const int INF = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int RANDOM_GEN = uniform_int_distribution<int>(0, 10000)(rng);
int t = 1;


void solve()
{
	int a, b ,c ,d;
	cin >> a >> b >> c >> d;
	int at = c / b + (c%b == 0 ? 0 : 1);
	int bt = a / d + (a%d == 0 ? 0 : 1);
	if(at <= bt) cout << "Yes" << '\n';
	else cout << "No" << '\n';
}


signed main()
{
    FAST
    int Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
		//cout<<"Case #"<<(t++)<<": ";  
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
import time
n, k = map(int, input().split())
w = [0] * n
for i in range(n):
    w[i] = int(input())


def check(p):
    remain_track = k - 1
    remain_p = p
    for a in range(n):
        if w[a] > p:
            return False
        if remain_p >= w[a]:
            remain_p -= w[a]
        else:
            if remain_track == 0:
                return False
            else:
                remain_track -= 1
                remain_p = p - w[a]
        # print(a, w[a], remain_p, remain_track)
    return True


next = 10 ** 9
prev = next


for i in range(200):
    if check(next):
        prev = next
        next = next // 2
    else:
        next = (next + prev) // 2
print(prev)


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

const ll INF = (1ll<<60);
ll dp[60][2];

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

    REP(i, 60)REP(j, 2) dp[i][j]= -INF;
    dp[0][1] = 0;

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> dig;
    while(1){
    	dig.push_back(K%2);
    	K /= 2;
    	if(K==0) break;
    }
    reverse(dig.begin(), dig.end());
    ll M = dig.size();


    ll res = 0;
    REP(i, N){
    	res += (A[i] - A[i]%(1ll<<M));
    }

    vector<ll> ons(M, 0);
    REP(i, M){
    	REP(j, N){
    		ons[M-1-i] += A[j]%2;
    		A[j] /= 2;
    	}
    }

    REP(i, M){
    	REP(j, 2){
    		ll val = (j==0 ? ons[i] : N-ons[i]) * (1ll<<(M-1-i));
    		chmax(dp[i+1][0], dp[i][0] + val);
    		if(j<dig[i])chmax(dp[i+1][0], dp[i][1]+val);
    		//chmax(dp[i+1][1], dp[i][0]);
    		if(j==dig[i])chmax(dp[i+1][1], dp[i][1]+val);
    	}
    }

    res += max(dp[M][0], dp[M][1]);

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <map>

using namespace std;
typedef long long int lint;

int GCD(int a, int b)
{
	int na, nb, buf;
	na = a;
	nb = b;
	while (a % b != 0){
		a = a % b;
		buf = a;
		a = b;
		b = buf;
	}
	return b;
}

class pairInt {
public:
	int rem; //余り
	int num; //何桁目に出現したか
	int q;

	pairInt(int r, int n, int x){
		rem = r;
		num = n;
		q = x;
	}
};

void solve(int p, int q)
{
	int g = GCD(p, q);
	p /= g; q /= g;

	set<int> s;
	vector<pairInt> vec;
	int begin, end;	//循環開始と終了
	
	begin = end = -1;
	int r = 0;
	int digit = 0;
	int x = p / q; //0.
	while (1){
		r = p - q * x;
		p = r * 10;
		x = p / q;
		if (r == 0) break;
		if (binary_search(s.begin(), s.end(), r)){
			end = digit;
			for (int i = 0; i < vec.size(); i++){
				if (vec[i].rem == r){
					begin = vec[i].num;
					break;
				}
			}
			break;
		}
		s.insert(r);
		vec.push_back(pairInt(r, digit, x));
		digit++;
	}
	for (int i = 0; i < vec.size(); i++){
		cout << vec[i].q;
	}
	cout << endl;
	if (begin != -1){
		for (int i = 0; i < vec.size(); i++){
			if (begin <= i && i <= end){
				cout << '^';
			}
			else cout << ' ';
		}
		cout << endl;
	}
}

int main()
{
	int p, q;
	while (cin >> p >> q){
		solve(p, q);
	}

	return 0;
}

Measured memory_bytes: 1204
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
for i in range(len(abcd)):
    abcd[i][0] -= 1
    abcd[i][1] -= 1
    
options = ["A","B"]   
all_patterns = options

for i in range(N+M-2):
    all_patterns = [i+j for j in options for i in all_patterns if str(i+j).count("A") <=N and str(i+j).count("B") <= M-1]

for i in range(len(all_patterns)):
    num = []
    count = 1
    for j in range(N+M-1):
        if all_patterns[i][j] == "A":
            num.append(count)
        else:
            count+=1
    all_patterns[i] = num

all_scores = [0 for _ in range(len(all_patterns))]
for i, char in enumerate(all_patterns):
    for a,b,c,d in abcd:
        if int(char[b]) - int(char[a]) == c:
            all_scores[i]+= d

print(max(all_scores))

Measured memory_bytes: 115776
import java.util.*;

public class Main {

    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        System.out.println( solve(N) );
    }

    private static int solve(long N) {
        return rec(N, N, new HashMap<>());
    }

    private static int rec(long X, long S, Map<Key, Integer> memo) {
        Key key = new Key(X, S);
        if( memo.containsKey(key) ) {
            return memo.get(key);
        } else {
            int ans = calc(X, S, memo);
            memo.put(key, ans);
            return ans;
        }
    }

    private static int calc(long X, long S, Map<Key, Integer> memo) {
        if( S == 0 ) return 1; // (a, b) = (0, 0)

        // こういう写像感のある漸化式、なんと呼ぶのか

        // even_even(a=2a', b=2b')
        // a + b = 2a' + 2b' <= S
        // a' + b' <= S/2
        // a ^ b = 2a' ^ 2b' <= X
        // a' ^ b' <= X/2
        int even_even = rec(X/2, S/2, memo);

        // odd_even(a=2a'+1, b=2b')
        // a + b = 2a'+1 + 2b' <= S
        // a' + b' <= (S-1)/2
        // a ^ b = (2a'+1) ^ 2b' <= X
        // a' ^ b' <= (X-1)/2
        int odd_even = rec((X-1)/2, (S-1)/2, memo);

        // odd_odd(a=2a'+1, b=2b'+1)
        // a + b = 2a'+1 + 2b'+1 <= S
        // a'+ b' <= (S-2)/2
        // a ^ b = (2a'+1) ^ (2b'+1) <= X
        // a' ^ b' <= 2/X
        int odd_odd;
        if( S >= 2 ) {
            odd_odd = rec(X/2, (S-2)/2, memo);
        } else {
            odd_odd = 0;
        }

        return (int)(((long)even_even + odd_even + odd_odd)% MOD);
    }

    private static class Key {
        private final long x;
        private final long s;

        public Key(long x, long s) {
            this.x = x;
            this.s = s;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Key key = (Key) o;
            return x == key.x &&
                    s == key.s;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, s);
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long

int take() {
    int n;
    scanf("%d",&n);
    return n;

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done {return 0}
#define fr(n) for(int i=1;i<=n;i++)
#define FR(a,b,x) for(int i=(a);i<=(b);i+=(x))
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR {struct info}
#define debug(x) {cout<<"ekhane"<<x<<endl}
#define  SS second
#define  FF first
#define PQ priority_queue
#define great greater
#define less lesser
#define mii map<int,int>
#define mil map<int,ll>
#define mll map<ll,ll>
#define msb map<string,bool>
#define M 200005
//////////////////////////////////////////

int cnt[M];

int main(){
    int n=Int,k=Int,v;
    set<int>s1;
    set<int>::iterator it;
    PQ<int,vi,great<int>>q;

    fr(n){
        cnt[v=Int]++;
        s1.insert(v);
    }
    it=s1.begin();

    if(s1.size()<=k) printf("0\n");
    else{
     int ans=0;
     while(it!=s1.end()){
        q.push(cnt[*it]);
        it++;
     }
     k=s1.size()-k;

     while(k){
        ans+=q.top();
        k--;
        q.pop();
     }
     printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 11516
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int n;
  int *a;

  scanf("%d", &n);
  a = (int *)malloc(sizeof(int) * n);
  if(a == NULL) {
    printf("malloc() failed.\n");
    return 1;
  }

  int i;
  for(i=0;i<n;i++) {
    scanf("%d", &a[i]);
  }

  long int s_sunuke = a[0], s_racoon = 0;
  for(i=1;i<n;i++) {
    s_racoon += a[i];
  }
  long int diff = s_sunuke - s_racoon;
  long int diff_min = labs(diff);
  for(i=1;i<n-1;i++) {
    diff += 2 * a[i];
    long int temp = labs(diff);
    if(diff_min > temp) diff_min = temp;
  }
  printf("%ld", diff_min);
  free(a);
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
    int q,x;
    char op[20];
    list<int> v;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>op;
        if(op[0]=='i')
        {
            cin>>x;
            v.push_front(x);
        }
        else if(op[6]=='L')
            v.pop_back();
        else if(op[6]=='F')
            v.pop_front();
        else if(op[0]=='d')
        {
            cin>>x;
            for(list<int>::iterator it=v.begin();it!=v.end();it++)
                if(*it==x)
                {
                    v.erase(it);
                    break;
                }
        }
    }
    int i=0;
    for(list<int>::iterator it=v.begin();it!=v.end();it++)
    {
        if(i++)
            cout<<" ";
        cout<<*it;
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 34244
#include <stdio.h>
#include <string.h>

int main(void){
	char x[200];
	int i,n;

	fgets(x,200,stdin);
	n=strlen(x);

	for(i=0;i<n;i++){
		if('a'<=x[i] && x[i]<='z')x[i]-='a'-'A';
	}

	printf("%s",x);

	return 0;
}

Measured memory_bytes: 520
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>
#include <queue>
#include <set>

using namespace std;


int main(){
	int n, cnt[50][26]{},m[26];
	string s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		for (int j = 0; j < s.size(); j++) {
			cnt[i][s[j] - 'a']++;
		}
	}
	for (int i = 0; i < 26; i++) {
		m[i] = 999999;
		for (int j = 0; j < n; j++) {
			m[i] = min(m[i], cnt[j][i]);
		}
	}
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < m[i]; j++) {
			char c ='a' + i;
			cout << c;
		}
	}
	cout << endl;
 	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;


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

    ll count=0;
    
    vector<ll> divisor;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0){
            divisor.push_back(i);
        }
    }
    int len=divisor.size();
    if(divisor.at(len-1) == sqrt(n)){
        count = 2*divisor.at(len-1) - 2;
    }
    else{
        ll div1 = divisor.at(len-1);
        ll div2 = n/(divisor.at(len-1));
        count = div1 + div2 - 2;
    }

    cout << count << endl;
    
}

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

int main() {
  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> x1 >> y1 >> x2 >> y2;
  x3 = x2 + y1 - y2;
  y3 = y2 + x2 - x1;
  x4 = x3 + x1 - x2;
  y4 = y3 + y1 - y2;
  cout << x3 << " " <<y3 <<" " <<x4 <<" " <<y4 <<endl;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int H, W, h, w; cin >> H >> W >> h >> w;
	if (H % h == 0 && W % w == 0) {
		print("No");
	} else {
		int a = (H/h) * (W/w);
		print("Yes");
		F0R(i, H) {
			F0R(j, W) {
				int x = i % h;
				int y = j % w;

				if (x == h-1 && y == w-1) cout << - h * w - a;
				else if (x == 0 && y == 0) cout << 1 + a;
				else cout << 1;
				cout << " ";
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  string s[2]; cin>>s[0]>>s[1];
	bool flg = true;
	rep(i,3){
		if(s[0][i]!=s[1][2-i]) flg=false;
	}
	if(flg) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] box = new int[n];
 
        for(int a = 0; a < n;a++) {
            box[a] = scanner.nextInt();
 
        }
 
        for(int a = n - 1;a >= 0 ;a--) {
            System.out.print(box[a]);
            if(a != 0 ) {
                System.out.print(" ");
            }
        }
        System.out.println();
 
    }
}

Measured memory_bytes: 26464
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<numeric>

using namespace std;

long long MOD = 1000000007;

int n,m;
long long in[100005];
long long diff[100005];
long long x,y;

long long ans(int k){
  for(int i=0;i<k-1;i++){
    diff[i] = in[i+1]-in[i];
  }
  long long ret = 0;
  for(int i=0;i<k-1;i++){
    long long tmp = diff[i] * (long long)(i+1);
    tmp %= MOD;
    tmp *= (long long)(k-1-i);
    tmp %= MOD;
    ret += tmp;
    ret %= MOD;
  }
  return ret;
}

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

  for(int i=0;i<n;i++){
    cin>>in[i];
  }
  x = ans(n);

  for(int i=0;i<m;i++){
    cin>>in[i];
  }
  y = ans(m);

  cout<<((x*y)%MOD)<<endl;

  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

bool isPrime(int n) {
    for (int i = 2; i * i < n; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

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

    while (!isPrime(n)) {
        n++;
    }
    cout << n;
    return 0;
}

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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};

using namespace std;
map<int ,int>A;
int main(){
    int s,l;
    cin>>s;
    while(s--){
       cin>>l;
       if(A[l]==0)
          A[l]=1;
       else
          A[l]=0;
    }
     int sum=0;
    for(auto x:A){
      sum+=x.second;
    }
   cout<<sum;
    return 0;
}


Measured memory_bytes: 4992
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            s = a * 500 + b * 100 + c * 50
            # print(a, b, c, s)
            if s == X:
                count += 1

print(count)

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

int main() {
  int n,x,count=1,d=0,j=0;
  cin>>n>>x;
  vector<int> v(n);
  cin>>v.at(0);
  for(int i=1;i<n;i++){
    cin>>v.at(i);
    v.at(i)+=v.at(i-1);
  }
  for(int i=0;i<n;i++){
     if(v.at(i)<=x){
       count++;
     }
    else{
      break;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;


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

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<ld> vld;

#define fi first
#define se second

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const ll inf = ll(1e18);
const int MOD = (1e9 + 7);

int main() 
{

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
	#ifdef DEBUG_
		freopen("input.txt","r",stdin);
		clock_t start = clock();
	#endif
	cout.setf(ios::fixed), cout.precision(20);
	//code begins here

	ll n;
	cin >> n;
	vpll arr[n];
	ll ar[n];
	ll a,b;
	for(int i=0;i<n;i++){
		cin >> ar[i];
		for(int j=0;j<ar[i];j++){
			cin >> a >> b;
			a--;
			arr[i].push_back(make_pair(a,b));
		}
	}
	ll ans = 0; 
	for(int i=(1<<n) - 1;i>=0;i--){
		bool cc = true;
		for(int j=0;j<n && cc;j++){
			if((1<<j)&i){
				for(int k=0;k<ar[j];k++){
					ll xx = arr[j][k].first;
					ll yy = arr[j][k].second;
					ll tt = (((1<<xx)&i)) ? 1 : 0;
					if(tt != yy) {
						// /cout<<i<<" "<<j<<" "<<xx<<" "<<yy<<" "<<"" <<"\n";
						cc = false;
						break;
					}
				}
			}
		}
		if(cc)
		{
			ll cnt =0;
			for(int hh=0;hh<n;hh++){
				if((1<<hh)&i) cnt++;
			}
			//ans = cnt;
			ans=max(ans,cnt);
		}
	}
	cout<<ans<<"\n";
	//End of code 
	#ifdef DEBUG_
		cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#define MAXN 100010
#define LL long long
using namespace std;

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

int n,root;
int g[MAXN],nume;
int d[MAXN];
LL a[MAXN],delta[MAXN];

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

bool dfs(int x,int p){
	if(d[x]==1){
		delta[x]=a[x];
		return 1;
	}
	LL temp=0,ts=0,tmax=0;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			if(!dfs(e[i].to,x)) return 0;
			temp+=delta[e[i].to];
			tmax=max(tmax,delta[e[i].to]);
		}
	ts=temp;
	if(ts-tmax<tmax) ts-=tmax-(ts-tmax);
	ts/=2;
	temp-=a[x];
	if(temp<0) return 0;
	if(temp>ts) return 0;
	delta[x]=a[x]-temp;
	return 1;
}

int main(){
#ifdef DEBUG
	freopen("C.in","r",stdin);
#endif
	memset(g,-1,sizeof g);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",a+i);
	if(n==2){
		if(a[1]==a[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
		d[u]++; d[v]++;
	}
	for(int i=1;i<=n;i++)
		if(d[i]!=1){
			root=i;
			break;
		}
	if(!dfs(root,0) || delta[root]!=0) puts("NO");
	else puts("YES");
	return 0;
}


Measured memory_bytes: 9344