akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int INF = 0x3f3f3f3f;

template <typename T=int>
struct Segtree {
    int n; // leaf [n, 2n), view as original [0, n)
    int sz_v;
    const T ID;
    vector<T> v; //tree
    
    Segtree(int _n = 100005) : n(_n), sz_v(n<<1), ID() {
        v.resize(sz_v);
    }
    void init() {// set leaf value
        for (int i = 0; i < n; i++) {
            v[i+n].x = INF;
        }
        build();
    }
    void build() {
        for (int i = n-1; i >= 0; i--) {
            v[i] = v[i<<1] + v[i<<1|1];
        }
    }
    // Note only when range-assign, single-access not interfere. e.g max
    inline void update(int l, int r, T val) {
        for (l += n, r += n; l < r; l >>= 1, r >>= 1){
            if (l & 1) { v[l++] = val; }
            if (r & 1) { v[--r] = val; }
        }
    }
    inline T query(int p){
        T res(ID);
        for (p += n; p > 0; p >>= 1) { res += v[p]; }
        return res;
    }
};

struct Node {// monoid
    int x;
    Node(int _=0) : x(INF) {} // DO!! identity
    Node(const Node& _r) : x(_r.x) {}// DO!! set
    Node& operator = (const Node& _r) {// DO!! set
        x = _r.x;
        return *this;
    }
    Node& operator += (const Node& _r) {// DO!! may not communitative
        x = min(x, _r.x);
        return *this;
    }
    friend Node operator + (const Node& _lhs, const Node& _rhs) {
        return Node(_lhs) += _rhs; // derive from +=
    }
};

typedef Segtree<Node> Seg;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> s(n), t(n), x(n);
    for (int i = 0; i < n; i++) {
        int a,b,c; cin >> a>>b >>c;
        s[i] = max(0, a-c);
        t[i] = max(0, b-c);
        x[i] = c;
    }
    vector<int> d(q);
    for (auto& i: d) {
        cin >> i;
    }
    vector<int> T; T.reserve(2*n+q+2);
    T.emplace_back(0);
    for (int i = 0; i < n; i++) {
        T.emplace_back(s[i]);
        T.emplace_back(t[i]);
    }
    for (int i = 0; i < q; i++) {
        T.emplace_back(d[i]);
    } T.emplace_back(INF);
    sort(T.begin(), T.end());
    T.erase(unique(T.begin(), T.end()), T.end());
    int sz = T.size();
    map<int, int> id;
    for (int i = 0; i < sz; i++) {
        id[T[i]] = i;
    }
    vector<int> id_by_x(n);
    iota(id_by_x.begin(), id_by_x.end(), 0);
    sort(id_by_x.begin(), id_by_x.end(), [&](int u, int v){
            return x[u] > x[v];
            });
    Seg seg(sz); seg.init();
    for (int i: id_by_x) {
        Node tmp; tmp.x = x[i];
        seg.update(id[s[i]], id[t[i]], tmp);
    }
    for (int i = 0; i < q; i++) {
        int res = seg.query(id[d[i]]).x;
        if (res == INF) res = -1;
        cout << res << "\n";;
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 40320
#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;
struct edge {
    int to, cost;
};

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);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  deque<int>ans;
  rep(i,n){
    if(i%2!=n%2){
      //mae
      ans.push_front(a[i]);
    }
    else{
      //usiro
      ans.push_back(a[i]);
    }
  }
  rep(i,n){
    cout<<ans.front()<<' ';
    ans.pop_front();
  }

}


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

int main() {
	int n,x,m,sm=0,mm=1001;
	cin >> n >> x;
	for(int i = 0;i < n;i++)
	{
		cin >> m;
		sm += m;
		mm = min(mm,m);
	}
	int k = (x - sm) / mm;
    cout << k + n << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
N=int(input())

def dfs(u,par):
  col=1
  for v in graph[u]:
    if col==par:
      col+=1
    color_dic[(u,v)]=col
    dfs(v,col)
    col+=1

elist=[]
graph=[[] for _ in range(N+1)]
for _ in range(N-1):
  a,b=map(int,input().split())
  graph[a].append(b)
  elist.append((a,b))
#print(graph)

color_dic={}
dfs(1,-1)
#print(color_dic)

K=len(set(color_dic.values()))
print(K)
for e in elist:
  print(color_dic[e])

Measured memory_bytes: 76716
import java.util.*
import java.io.PrintWriter

val pw = PrintWriter(System.out)
val MOD = 1000000007L
val INF = 2147483647
val LINF = 9223372036854775807L

fun main(args: Array<String>){
    solve()
    pw.flush()    
}

fun solve(){
    val (n, d, a) = nextIntList()
    val ary = Array(n) { LongArray(2) { 0 } }
    repeat(n) { 
        val (x, h) = nextLongList()
        ary[it][0] = x
        ary[it][1] = h
    }
    val mons = ary.sortedBy { it[0] }   // X基準でソート

    val bomb = IntArray(n)  // モンスターiを左端としたとき、右端となるモンスター
    for (i in mons.indices) {
        val border = mons[i][0] + 2 * d
        var ok = -1
        var ng = mons.size
        while(abs(ok - ng) > 1){
            val mid = (ok + ng) / 2
            if(mons[mid][0] <= border){
                ok = mid
            } else {
                ng = mid
            }
        }
        bomb[i] = ok
    }

    var ans = 0L
    val damage = LongArray(n + 1)   // 爆風のダメージ imos法による累積和
    for (i in mons.indices) {
        if(i >= 1){
            damage[i] += damage[i - 1]
        }
        if(mons[i][1] - damage[i] <= 0) continue    // 既にHが0になっているなら無視
        val count = ((mons[i][1] - damage[i]) + (a - 1)) / a
        ans += count
        damage[i] += count * a
        damage[bomb[i] + 1] -= count * a
    }

    println(ans)

}

// Print
fun println(v: String){
    pw.println(v)
}
fun print(v: String){
    pw.print(v)
}

// Read
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map{ it.toInt() }
fun nextLongList() = next().split(" ").map{ it.toLong() }
fun nextDoubleList() = next().split(" ").map{ it.toDouble() }
fun nextAryln(n: Int) = Array(n){ next() }
fun nextIntAryln(n: Int) = IntArray(n){ nextInt() }
fun nextLongAryln(n: Int) = LongArray(n){ nextLong() }
fun nextDoubleAryln(n: Int) = DoubleArray(n) { nextDouble() }

// Math
fun abs(n: Int) : Int = Math.abs(n)
fun abs(n: Long) : Long = Math.abs(n)
fun abs(n: Double) : Double = Math.abs(n)
fun max(a: Long = -LINF, b: Long = -LINF, c: Long = -LINF, d: Long = -LINF, e: Long = -LINF): Long = listOf(a, b, c, d, e).max()!!.toLong()
fun min(a: Long = LINF, b: Long = LINF, c: Long = LINF, d: Long = LINF, e: Long = LINF): Long = listOf(a, b, c, d, e).min()!!.toLong()
fun prime(from: Long, to: Long = from) : List<Long>{
    return (from..to).filter{ i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all{ j -> i % j != 0L}
    }
}
fun gcd(a: Long, b: Long) : Long = if(a % b == 0L) b else gcd(b, (a % b))
fun lcm(a: Long, b: Long) : Long = a / gcd(a, b) * b
fun modpow(a: Long, n: Long, p:Long = MOD) : Long {
    var res = 1L
    var ar = a
    var nr = n
    while(nr > 0){
        if((nr and 1) == 1L) res = res * ar % p
        ar = ar * ar % p
        nr = nr shr 1
    }
    return res
}
fun modinv(a: Long, p: Long = MOD) : Long = modpow(a, p - 2, p)
fun ncr(n: Long, r: Long) : Long {
    var a = 1L
    var b = 1L
    for (i in 1..r) {
        a = a * (n + 1 - i) % MOD
        b = b * i % MOD
    }
    return modinv(b, MOD) * a % MOD
}


Measured memory_bytes: 120140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main() {
  int N;
  scanf("%d\n",&N );

  int n=-1;
  for (size_t i = 1; i <1000; i++) {
    if(N==i*(i-1)/2){
      n=i;
      break;
    }
  }
  if(n==-1){
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  printf("%d\n",n );

  std::vector<std::vector<int> > a;
  a.resize(n);		// ()内の数字が要素数になる
  for( int i=0; i<n; i++ ){
    a[i].resize(n);
  }
  int count=1;
  for (size_t i = 0; i < n; i++) {
    for (size_t j = 1+i; j < n; j++) {
      a[i][j]=count;
      a[j][i]=count;
      count++;
    }
  }
  for (size_t i = 0; i < n; i++) {
    printf("%d",n-1);
    for (size_t j = 0; j < n; j++) {
      if(i!=j){
        printf(" %d",a[i][j] );
      }
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    char s[h][w];
    rep(i,h){
        rep(j,w) cin>>s[i][j];
    }
    int right=0,down=0;
    rep(i,h){
        rep(j,w){
            if(i<h-1&&s[i][j]=='#'&&s[i+1][j]=='#') down++;
            if(j<w-1&&s[i][j]=='#'&&s[i][j+1]=='#') right++;
        }
    }
    if(right==w-1&&down==h-1) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int ans;
  ans = a+b+c-max(a,max(b,c));
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
    int n, r; cin >> n >> r;
    if(n<10) cout << r+100*(10-n) << endl;
    else cout << r << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
const int MOD=1e9+7;
struct mint{int x;mint(int x=0):x(x){}};
inline mint operator+  (mint a,mint b){return a.x+b.x<MOD?a.x+b.x:a.x+b.x-MOD;}
inline mint operator-  (mint a){return MOD-a.x;}
inline mint operator-  (mint a,mint b){return a+-b;}
inline mint operator*  (mint a,mint b){return 1LL*a.x*b.x%MOD;}
inline mint operator<< (mint x,int y){mint r=1;for(;y;y>>=1,x=x*x)if(y&1)r=r*x;return r;}
inline mint operator~  (mint x){return x<<MOD-2;}
inline mint operator/  (mint a,mint b){return a*~b;}
inline mint&operator+= (mint&a,mint b){return a=a+b;}
inline mint&operator-= (mint&a,mint b){return a=a-b;}
inline mint&operator*= (mint&a,mint b){return a=a*b;}
inline mint&operator<<=(mint&x,int y){return x=x<<y;}
inline mint&operator/= (mint&a,mint b){return a=a/b;}
#define MN 200000
struct edge{int nx,t,w;}e[MN*2+5];
int h[MN+5],en,d[MN+5],z[MN+5],q[MN+5],qn,sv,se,vq[MN+5],f[MN+5],fa[MN+5];
mint ans=1,s1,s2,ff[MN+5],F[MN+5],RF[MN+5];
vector<int> v[MN+5];
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,w};h[y]=en;
}
void dfs(int x,int fa)
{
	z[d[x]=d[fa]+1]=x;vq[++sv]=x;
	for(int i=h[x];i;i=e[i].nx,++se)if(e[i].t!=fa)
		if(d[e[i].t]){if(!qn)for(int j=d[e[i].t];j<=d[x];++j)q[++qn]=z[j];}
		else dfs(e[i].t,x);
}
void build(int x,int fr)
{
	v[x].clear();
	for(int i=h[x];i;i=e[i].nx)if(e[i].t!=fr)
	{
		if(e[i].w<f[x])v[fa[e[i].t]=x].push_back(e[i].t);
		if(d[e[i].t]>=0)f[e[i].t]=e[i].w,build(e[i].t,x);
	}
}
void dp(int x,int fa)
{
	ff[x]=1;
	for(int i=0;i<v[x].size();++i)
		dp(v[x][i],x),
		ff[x]*=ff[v[x][i]]*RF[d[v[x][i]]],
		d[x]+=d[v[x][i]];
	ff[x]*=F[d[x]++];
}
int main()
{
	int n=read(),i,j,x,y;
	for(i=1;i<=n<<1;++i)x=read(),y=read(),ins(x,y+n,x+y);
	for(n<<=1,F[0]=i=1;i<=n;++i)F[i]=F[i-1]*i;
	for(RF[i=n]=~F[n];i--;)RF[i]=RF[i+1]*(i+1);
	for(i=1;i<=n;++i)if(!d[i])
	{
		dfs(i,qn=sv=se=0);
		if(sv<<1!=se)return 0*puts("0");
		for(j=1;j<=qn;++j)for(d[q[j]]=-1,x=h[q[j]];x;x=e[x].nx)if(e[x].t==q[j%qn+1])f[q[j]]=e[x].w;
		for(j=1;j<=qn;++j)build(q[j],0);
		for(j=1;j<=sv;++j)d[vq[j]]=0;
		for(s1=F[sv],j=1;j<=sv;++j)if(!d[vq[j]])
		{
			for(x=vq[j];fa[x];)x=fa[x];
			dp(x,0);s1*=ff[x]*RF[d[x]];
		}
		for(j=1;j<=sv;++j)v[vq[j]].clear(),fa[vq[j]]=0;
		for(j=1;j<=qn;++j)for(d[q[j]]=-1,x=h[q[j]];x;x=e[x].nx)if(e[x].t==q[j%qn+1])f[e[x].t]=e[x].w;
		for(j=1;j<=qn;++j)build(q[j],0);
		for(j=1;j<=sv;++j)d[vq[j]]=0;
		for(s2=F[sv],j=1;j<=sv;++j)if(!d[vq[j]])
		{
			for(x=vq[j];fa[x];)x=fa[x];
			dp(x,0);s2*=ff[x]*RF[d[x]];
		}
		for(j=1;j<=sv;++j)v[vq[j]].clear(),fa[vq[j]]=0;
		ans*=(s1+s2)*RF[sv];
	}
	printf("%d",ans*F[n]); 
}

Measured memory_bytes: 23808
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  end((scanElem+scanElem)*scanElem/2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int n; cin>>n;
	vector<int> a(n);
	fore(i,0,n) cin>>a[i]; //sort(ALL(a));
	int ans=0;
	fore(i,0,n) fore(j,i+1,n) fore(k,j+1,n){
		vector<int> v={a[i],a[j],a[k]};
		sort(ALL(v));
		if(v[0]+v[1]>v[2]&&v[0]!=v[1]&&v[1]!=v[2]){
			ans++;
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

bool solve() {
	int n; cin >> n;
	int t[n]; REP (i,n) cin >> t[i];
	int ans = t[0];
	FOR (i,1,n) {
		ans = (ans / GCD(ans,t[i])) * (t[i] / GCD(ans,t[i])) * GCD(ans,t[i]);
	}
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

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

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]){
  bool all_visited = true;

  for(int i = 0; i < N; ++i){
    if(visited[i] == false) all_visited = false;
  }

  if(all_visited) return 1;

  int ret = 0;
  for(int i = 0; i < N; ++i){
    if(graph[i][v] == false) continue;
    if(visited[i]) continue;
    visited[i] = true;
    ret += dfs(i, N, visited);
    visited[i] = false;
  }
  return ret;
}

int main(){
  int N, M;
  cin >> N >> M;
  for(int i = 0; i < M; ++i){
    int A, B;
    cin >> A >> B;
    graph[A-1][B-1] = graph[B-1][A-1] = true;
  }
  bool visited[nmax];
  for(int i = 0; i < N; ++i) visited[i] = false;
  visited[0] = true;
  cout << dfs(0, N, visited) << endl;
}


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

int main() {
	
	ll n;
	vector<ll> a(5);
	cin >> n;
	rep(i, 5){
		cin >> a[i];
	}
	
	ll m = a[0];
	for(int i=1; i<5; i++){
		m = min(m, a[i]);
	}
	
	cout << (n + m - 1) / m + 4 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define N 6

typedef struct{
  double x;
  double y;
}P;
void kock(int,P,P);
int main(){
  int n;
  P p1,p2;
  p1.x=0;
  p1.y=0;

  p2.x=100;
  p2.y=0;
  
  scanf("%d",&n);
  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  return 0;
}
void kock(int n,P p1,P p2){
  P s,t,u;
  
  if(n==0)return;

  s.x=(2*p1.x+p2.x)/3;
  s.y=(2*p1.y+p2.y)/3;

  t.x=(2*p2.x+p1.x)/3;
  t.y=(2*p2.y+p1.y)/3;
  
  u.x=fabs((t.x-s.x)/2-(t.y-s.y)*sqrt(3)/2+s.x);
  u.y=fabs((t.x-s.x)*sqrt(3)/2+(t.y-s.y)/2+s.y);

  
  kock(n-1, p1, s);
  printf("%f %f\n",s.x,s.y);
  kock(n-1, s, u);
  printf("%f %f\n",u.x,u.y);
  kock(n-1, u, t);
  printf("%f %f\n",t.x,t.y);
  kock(n-1, t, p2);
}

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

int main()
{
	int n;
	cin>>n;
	int a[n+1];
	long long sum=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++)sum+=a[i]*a[j];
	}
	cout<<sum<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

struct mint {
    ll v;
    ll mod;
    mint() : v(0) {}
    mint(signed v, ll mod = MOD) : v(v), mod(mod) {}
    mint(ll t, ll mod = MOD) : mod(mod) {
        v = t % mod;
        if (v < 0)
            v += mod;
    }

    mint pow(ll k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }

    mint inv() { return pow(mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += mod - a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = 1LL * v * a.v % mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(MOD - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<mint>> dp(
        n, vector<mint>(
               n, 0)); // used i digits, j digits left which are smaller than ith digit
    for (int i = 0; i < n; ++i) {
        dp[0][i] = 1;
    }
    vector<vector<mint>> sum(n, vector<mint>(n, 0));
    sum[0][0] = dp[0][0];
    for (int i = 1; i < n; ++i) {
        sum[0][i] += sum[0][i - 1] + dp[0][i - 1];
    }
    for (int i = 1; i < n; ++i) {
        if (s[i - 1] == '>') {
            for (int j = 0; j < n; ++j) {
                dp[i][j] = sum[i - 1][n - 1] - sum[i - 1][j];
            }
        } else {
            for (int j = 0; j < n - i; ++j) {
                dp[i][j] = sum[i - 1][j];
            }
        }
        sum[i][0] = dp[i][0];
        for (int j = 1; j < n; ++j) {
            sum[i][j] += sum[i][j - 1] + dp[i][j];
        }
    }
    cout << dp[n - 1][0].v << "\n";
    return 0;
}

Measured memory_bytes: 281728
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int sum = 100 * r + g * 10 + b;
        if (sum % 4 == 0) {
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
//const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

const int mod = 1000000000+7;
int N;
char field[210];
ll dp[210][210][210];

ll dfs(int pos,int u,int d){
  if(dp[pos][u][d]>=0)return dp[pos][u][d];
  ll res = 0;
  if(pos == N){
    if(u == 0 && d == 0)res = 1;
  }
  else{
    if(field[pos] == '-')res = dfs(pos+1,u,d);
    else if(field[pos]=='U'){
      // ここに割り当て可能なのは、ここより下にあるDと、ここより上にあるUのうちどれかひとつ
      if(u>0)res = (res + (dfs(pos+1,u-1+1,d)*u)%mod )%mod;
      // ここで割り当てるDは下にあるDのうちどれか一つ
      res = (res + (dfs(pos+1,u+1,d+1))%mod)%mod;
    }
    else if(field[pos]=='D'){
      // ここに割り当て可能なのは、ここより下にあるDと、ここより上にあるU
      // このdは消化されたものとして扱う
      if(d>0){
        // 今回のパターンは、どれに割り当てられたかで場合分けが必要
        if(u>0)res = (res + (dfs(pos+1,u-1,d-1)*u)%mod)%mod;
        res = (res + (dfs(pos+1,u,d))%mod)%mod;
        res = (res * d) % mod;
      }
    }
  }
  return dp[pos][u][d] = res;
}

int main(){

  cin>>N;
  for(int i=0;i<N;i++)cin>>field[i];
  memset(dp,-1,sizeof(dp));
  cout<<dfs(0,0,0)<<endl;
  
  return 0;
}

Measured memory_bytes: 73532
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e3+5;
ll dp[N][N];
ll go(int x, int y){
	if(x<=1 and y<=1 ) return dp[x][y] = 0;
	int ret = dp[x][y];
	if(ret!=-1)return ret;
	ret = 0;
	for(int i=1;i<100;i++){
		if(x>=2*i){
			if(go(x-2*i,y+i)==0)return dp[x][y] = 1;
		}
		if(y>=2*i){
			if(go(x+i,y-2*i)==0)return dp[x][y] = 1;
		}
	}
	return dp[x][y] = 0;
}
void solve(){
	ll x,y; 
	cin>>x>>y; 
	ll dis = abs(x-y);
	if(dis<=1){
		cout<<"Brown"<<endl;
	}
	else{
		cout<<"Alice"<<endl;
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

  int A,B,C,X;
  cin >> A >> B >> C >> X;

  int ans = 0;

  REP(k,A+1){
    REP(i,B+1){
      REP(j,C+1){
        int fh = k * 500;
        int h  = i * 100;
        int f  = j * 50;
        if(fh + h + f == X){
          ans++;
        }
      }
    }
  }

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


Measured memory_bytes: 256
#include<stdio.h>
 #include<stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
  
 int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
bool X[N][N];
  
void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i]=FREE,col[i]=FREE;
  }
}
  
void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
    if(row[i]!=j)return;
      }
    }
  }
  for( i=0;i<N;i++){
    for(j=0;j<N;j++){
      printf((row[i]==j)?"Q":".");
    }
    printf("\n");
  }
}
  
 void recursive(int i){
   int j;
   if(i==N){
     printBoard();
     return;
   }
   for(j=0;j<N;j++){
     if(NOT_FREE==col[j] ||NOT_FREE==dpos[i+j] || NOT_FREE==dneg[i-j+N-1] )continue;
  
     row[i]=j;
     col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
  
     recursive(i+1);
  
     row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
   }
 }
  
 int main(){
   initialize();
   int i,j;
   for(i=0;i<N;i++){
     for(j=0;j<N;j++)X[i][j]=false;
   }
   int k;
   scanf("%d",&k);
   for(i=0;i<k;i++){
     int r,c;
     scanf("%d%d",&r,&c);
     X[r][c]=true;
   }
  
   recursive(0);
   return 0;
 }



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

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

    int x = n % 10;

    switch (x) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
    }
}


Measured memory_bytes: 3624
a, b = list(map(int, input().split()))
e=[0]*(b+1) 

for x in range(a):
    c=list(map(int, input().split()))
    d=0 
    for y in range(b):
        d+=c[y]
        e[y]+=c[y]
    c.append(d)
    e[b]+=c[b]
    print(*c)
print(*e)
        


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

vector<vector<int>> v;
vector<int> d, t;

void bfs(){
  int time = 0;
  queue<int> q;
  q.push(0);

  while(!q.empty()){
    int node = q.front();
    q.pop();

    for(int i=0; i<v.size(); ++i){
      if(v[node][i] == 1 && t[i] == -1){
         q.push(i);
         t[i] = t[node] + 1;
       }
    }
  }
}

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

  v.resize(n);
  d.resize(n);
  t.resize(n);
  for(int i=1; i<n; ++i) t[i] = -1;

  for(int i=0; i<n; ++i) v[i].resize(n);

  for(int i=0; i<n; ++i){
    int u, k; cin >> u >> k;
    while(k--){
      int x; cin >> x;
      v[u-1][x-1] = 1;
    }
  }

  bfs();

  for(int i=0; i<n; ++i){
      cout << i+1 << " " << t[i] << endl;
  }
}



Measured memory_bytes: 3132
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int N, temp;
	vector<int> V, C;

	cin >> N;

	REP(i, N) {
		cin >> temp;
		V.push_back(temp);
	}

	REP(i, N) {
		cin >> temp;
		C.push_back(temp);
	}

	temp = 0;
	REP(i, N) {
		if (V[i] > C[i]) {
			temp += (V[i] - C[i]);
		}
	}

	cout << temp << endl;

	return 0;
}

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

	if(c=='a' ||c== 'i' ||c== 'u' ||c== 'e' ||c== 'o'){
	cout << "vowel" << endl;
	}

	else{
	cout << "consonant" << endl;
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string a,t;
  cin>>n;
  t="Three";
  for(int i=0;i<n-1;i++){
    cin>>a;
    if(a=="Y")
      t="Four";
  }
  cout<<t<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int N;
    long long X[200000];
    long long Y[200000];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        Y[i]=X[i];
    }
    sort(X,X+N);
    for (int i = 0; i < N; i++) {
        if(Y[i]>X[(N/2)-1]){
            cout << X[(N/2)-1] << endl;   
        }else{
            cout << X[(N/2)] << endl;   
        }
    }
}


Measured memory_bytes: 5376
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,t;
  cin >> n >> t;
  vector<int>c(n);
  vector<int>s(n);
  rep(i,n)cin >> c.at(i) >> s.at(i);
  int mi = 10000;
  rep(i,n){
    if(s.at(i) <= t){
      mi = min(mi,c.at(i));
    }
  }
  if(mi==10000) cout<<"TLE"<<endl;
  else cout<<mi<<endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#define INF 1e16
#define N (1000000000+7)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;


ll gcd(ll a, ll b) {
    if(b==0) return abs(a);
	else return gcd(b, a%b);
}


int main(void){
    int n,m;
    cin>>n>>m;
    vector<ll>x(m);
    for(int i=0;i<m;i++)cin>>x[i];
    if(m<=n){
        cout<<0<<endl;
        return 0;
    }
    if(m==1){
        cout<<0<<endl;
        return 0;
    }
    sort(x.begin(),x.end());
    vector<ll>d;
    ll sum = 0;
    for(int i=0;i<m-1;i++){
        d.push_back(x[i+1]-x[i]);
        sum+=x[i+1]-x[i];
    }
    sort(d.begin(),d.end(),greater<ll>());
    for(int i=0;i<n-1;i++)sum-=d[i];
    cout<<sum<<endl;
    return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long n;
    long long abc[3];
    cin>>n;
    rep(l,3)cin>>abc[l];

    char ans[n];
    string d[n];
    char ABC[3]={'A','B','C'};
    //最大引く回数
    int m_abc[3]={};
    //最大足す回数
    int M_abc[3]={};
    rep(i,n){
        cin>>d[i];
    }
    rep(i,n){
        int now[2];
        int p=0;
        rep(l,2){
            rep(k,3){
                if(d[i][l]==ABC[k]){
                now[p++]=k;
                }
            }
        }
        //int m=min(abc[now[0]],abc[now[1]]);
        //int M=max(abc[now[0]],abc[now[1]]);
        if(abc[now[0]]==0 && abc[now[1]]==0){
            cout<<"No"<<endl;
            return 0;
        }
        else{
            if(abc[now[0]]<abc[now[1]]){
                abc[now[0]]++;
                abc[now[1]]--;
                ans[i]=ABC[now[0]];
            }
            else if(abc[now[0]]>abc[now[1]]){
                abc[now[1]]++;
                abc[now[0]]--;
                ans[i]=ABC[now[1]];
            }
            else{
                char ne;
                int ch=now[0];
                if(i+1<n){
                    rep(l,2)rep(j,2){
                        if(d[i][l]==d[i+1][j]){
                            ne=d[i][l];
                        }
                    }
                    
                    rep(l,3){
                        if(ABC[l]==ne)ch=l;
                    }
                }
                if(ch==now[0]){
                abc[now[0]]++;
                abc[now[1]]--;
                ans[i]=ABC[now[0]];
                }
                else{
                abc[now[1]]++;
                abc[now[0]]--;
                ans[i]=ABC[now[1]];
                }
            }
        }
    }

    cout<<"Yes"<<endl;

    rep(i,n){
        cout<<ans[i]<<endl;
    }
    return 0;

}
/*


*/


Measured memory_bytes: 6852
def resolve():
    '''
    code here
    '''
    import math
    N, M = [int(item) for item in input().split()]
    S = input()
    T = input()

    res = N * M // math.gcd(N,M)

    cycle_s = res // N
    cycle_t = res // M
    cycle_overlap = cycle_s * cycle_t // math.gcd(cycle_s, cycle_t)

    for i in range(res//cycle_overlap):        
        if T[i*cycle_overlap//cycle_t] == S[i*cycle_overlap//cycle_s]:
            pass
        else:
            res = -1
            break

    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9392
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];

int main() {
   string a,b,c;
   cin>>a>>b>>c;
   cout<<a.at(0)<<b.at(0)<<c.at(0)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define MM <<" "<<
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setpercision(x)
using ll=long long;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using pl=pair<ll,ll>;
template<class T> inline bool chmin(T& a, T b){
    if(a>b){a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){
    if(a<b){a=b;return true;}return false;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};

int main(){
    int A,B,C;cin>>A>>B>>C;
    if(A<B)swap(A,B);
    if(B<C)swap(B,C);
    if(A<B)swap(A,B);
    int ans=A-B;
    C+=ans;
    if((A-C)%2){
        ans++;
        A++;
    }
    ans+=(A-C)/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ARC073_D___Simple_Knapsack
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var NW = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var N = (int)NW[0];
            var W = NW[1];
            var wv1 = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var w1 = wv1[0];
            if (w1 > W) return 0;
            var v1 = wv1[1];

            var DP = new long[N + 1, N + 1, 1000 + 1];
            for (int i = 0; i < 1000 + 1; i++) DP[1, 1, i] = v1;

            for (int item = 2; item < N + 1; item++)
            {
                var wv = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                var w = (int)(wv[0] - w1);
                var v = wv[1];
                for (int count = 1; count <= item; count++)
                {
                    for (int weight = 0; weight < 1000 + 1; weight++)
                    {
                        DP[item, count, weight] = weight >= w ? Math.Max(DP[item - 1, count, weight], DP[item - 1, count - 1, weight - w] + v) : DP[item - 1, count, weight];
                    }
                }
            }

            long result = 0;
            var countMin = W / (w1 + 3);
            var countMax = Math.Min(W / w1, N);
            for (long c = countMin; c <= countMax; c++)
                result = Math.Max(result, DP[N, c, Math.Min(1000, W - w1 * c)]);

            return result;
        }
    }
}


Measured memory_bytes: 90848
#include <bits/stdc++.h>
 
#define pf printf
#define sc scanf
#define endl "\n"
#define dbug(x) cout << #x << ": " << x << endl
#define gi(k) scanf("%d",&k)
#define gl(k) scanf("%lld",&k) 
#define pb push_back
#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define rep(i,n) for(int i = 1; i <= n; i++)
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,cur) N=(N|(1LL<<cur))
#define Reset(N,cur) N=(N&(~(1LL<<cur)))
#define Check(N,cur) (!((N&(1LL<<cur))==0))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define NMAX 2147483647
#define LMAX 9223372036854775807LL
#define mem CLR
 
using namespace std;
 
 
#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
 
inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

 
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-9;
 
 
int t,n; 

int f(vlong lf, vlong ri, vlong x) {
	vlong a = (lf/x) * x;
	if(a < lf) a += x;

	if(a >= lf && a <= ri) return 1;
	return 0;
}
 
int main () {
 	
 	#ifdef forthright48
    freopen ( "00_input.txt", "r", stdin ); //freopen ( "00_output.txt", "w", stdout );
 	#endif

    vlong low,high,x,y,ar[100005];
    int flag = 0;

 	cin >> n;
 	rep(i,n) gl(ar[i]);

 	low = high = 2;

 	ROF(i,1,n) {
 		if(!f(low,high,ar[i])) {
 			flag = 1;
 			break;
 		}

 		x = (low/ar[i]) * ar[i]; if(x < low) x += ar[i];
 		y = (high/ar[i]) * ar[i]; y += ar[i]-1;

 		low = x;
 		high = y;
 	}

 	if(flag) pf("-1");
 	else cout << low << " " << high;
 	nl;

 
 
    return 0;
}

Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
# include <cmath>
# include <tuple>
# include <vector>
# include <queue>
# include <string>
# include <map>

typedef unsigned long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w; cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) cin >> s[i];
    int d[h][w];
    for (int i = 0; i < h; i++) fill(d[i], d[i]+w, 0);
    d[0][0] = 1;
    int dx[4] = {0, 0, 1, -1};
    int dy[4] = {1, -1, 0, 0};
    queue<pair<int, int>> q;
    q.push({0, 0});
    while (!q.empty()) {
        auto f = q.front();
        q.pop();
        int ch = f.first;
        int cw = f.second;
        if (cw == h-1 && ch == w-1) break;
        for (int i = 0; i < 4; i++) {
            int nh = ch + dy[i];
            int nw = cw + dx[i];
            if (nh >= 0 && nh < h && nw >= 0 && nw < w && d[nh][nw] <= 0 && s[nh][nw] == '.') {
                d[nh][nw] = d[ch][cw] + 1;
                q.push({nh, nw});
            }
        }
    }
    int t = d[h-1][w-1];
    if (t <= 0) cout << -1 << endl;
    else {
        int c = 0;
        for (auto &ss: s) for (auto &sss: ss) if (sss == '.') c++;
        cout << c - t << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))
	    puts("Yes");
	else
	    puts("No");
	return 0;
}

Measured memory_bytes: 256
N,A = map(int,input().split())
X = [int(x)-A for x in input().split()]

d = {0:1}  

for x in X:
    d_tmp = d.copy()
    for k in d_tmp:        
        d[k+x] = d.get(k+x,0)+d_tmp[k]
print(d[0]-1)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

    public Main() {
    }

    private static Scanner sc;

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

    private void solve() {
        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] a = new int[N];
        int[] b = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        int[] c = new int[M];
        int[] d = new int[M];

        for (int i = 0; i < M; i++) {
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }

        for (int i = 0; i < N; i++) {
            int x = a[i];
            int y = b[i];

            int ans = 0;
            int dist = Integer.MAX_VALUE;
            for (int j = 0; j < M; j++) {
                int tmp = Math.abs(x - c[j]) + Math.abs(y - d[j]);
                if (tmp < dist) {
                    ans = j + 1;
                    dist = tmp;
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> X(n);
    vector<int> Y(m);
    for(int i = 0; i < n; i++)
        cin >> X[i];
    for(int i = 0; i < m; i++)
        cin >> Y[i];
    int xn = *max_element(X.begin(), X.end());
    int ym = *min_element(Y.begin(), Y.end());
    int z = xn + 1;
    if(z > x && z <= y && z <= ym)
        cout << "No War" << endl;
    else
        cout << "War" << endl;
}


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

int sum(int n){
   if(n==1) return 1;
   else return sum(n-1)+n;
}
int main(){
   int a,b; cin>>a>>b;
   int ans=b-a;
   cout<<sum(ans)-b<<endl;
   return 0;
}


Measured memory_bytes: 256