akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

int dp[100010];

signed main()
{
  int n; cin>>n;
  vi h(n);
  rep(i,n) cin>>h[i];
  
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for(int i=2; i<n; i++){
    dp[i]=min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1]);
  }
  
  cout<<dp[n-1]<<endl;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> k;
    cin >> n >> m;
    for(i=n;i<=m;i++){
        if(i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int _dp0[3010][3010];
int _dp1[3010][3010];

int N, T;
int A[3010];
int B[3010];

signed main()
{
	cin >> N >> T;
	REP(i, N) cin >> A[i + 1] >> B[i + 1];

	for (int i = 1; i <= N; i++)
	{
		for (int j = 0; j < T; j++)
		{
			if (j >= A[i])
			{
				_dp0[i][j] = max(_dp0[i - 1][j], _dp0[i - 1][j - A[i]] + B[i]);
			}
			else
			{
				_dp0[i][j] = _dp0[i - 1][j];
			}
		}

		for (int j = 0; j < T; j++)
		{
			int a = _dp1[i - 1][j];
			int b = _dp0[i - 1][j] + B[i];
			int c = (j >= A[i]) ? _dp1[i - 1][j - A[i]] + B[i] : 0;
			_dp1[i][j] = max(a, max(b, c));
		}
	}

	cout << _dp1[N][T - 1] << endl;
}




Measured memory_bytes: 141568
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N;
	cin>>N;
	map<int,int> S;
	fx(N){
		int a;
		cin>>a;
		S[a]=1;
	}
	int ans=0;
	for(int x=1;x<=100;x++){
		if(S[x]==1){
			ans++;
		}
	}
ce(ans)
}

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

int main() {
  int n;
  cin >> n;
  vector<int> r(n);
  int result = -1100100100;
  cin >> r[0];
  int min_r = r[0];
  int i;
  for (i = 1; i < n; i++) {
    cin >> r[i];
    min_r = min(min_r, r[i - 1]);
    result = max(result, r[i] - min_r);
  }
  cout << result << endl;
  return 0;
}



Measured memory_bytes: 3548
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

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

using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if (N == 1) {
		cout << "Hello World" << endl;
	}
	else {
		cout << A + B << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
N,K = map(int,input().split())

if K%2 != 0:
    pattern = N//K
    print(pattern ** 3)
else:
    k = K // 2
    p1 = N//K
    p2 = N//k
    p3 = p2-p1
    print(p2**3 - 3*p1*p3*p3 - 3* p1*p1*p3)




Measured memory_bytes: 38384
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val xy = (0 until n).map { _ =>
    readLine.split(" ").map(_.toInt) match {
      case Array(x, y) => (x, y)
    }
  }

  val p = (0 until n).permutations
  var result = 0d
  var count = 0
  for (l <- p) {
    count = count + 1
    var prev = xy(l.head)
    for (i <- l.tail) {
      val d = math.sqrt(
        math.pow(prev._1 - xy(i)._1, 2) + math.pow(prev._2 - xy(i)._2, 2)
      )
      result = result + d
      prev = xy(i)
    }
  }
  println(result / count)

}


Measured memory_bytes: 42152
import java.util.*;
import java.lang.Math;

public class Main {
//public static final int MIN_VALUE
//public static final int MAX_VALUE

/**
 * ソート済みの配列を2分探索し、indexを返す。
 * 見つからない場合は-1を返す
 * @param a
 * @param x
 * @return
 */
public static int indexOf(int[] a, int x) {
    int ret = -1;

    int l,m,r;
    l = 0;r = a.length - 1; 

    while(l <= r) {
        m = (l+r) / 2;
        if(a[m] == x) {
            ret = m;
            break;
        } else if(a[m] < x) {
            l = m + 1;
        } else {
            r = m - 1;
        }
    }

    return ret;
}

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int x,n;
    int pos,cpos;
    int lcand,rcand;
    boolean found;

    x = scan.nextInt();
    n = scan.nextInt();

    if(n == 0) {
        System.out.println(x);
        scan.close();
        return;
    }

    int[] p = new int[n];
    for(int i=0;i<n;i++) {
        p[i] = scan.nextInt();
    } 

    Arrays.sort(p);

//    System.out.println(x);
//    for(int i=0;i<n;i++) {
//        System.out.println(p[i]);
//    }

    cpos = indexOf(p,x);
    if(cpos != -1) {
        // 見つかった場合、そこから左右に伸びていく
        pos = 0;
        
        while(true) {
            pos++;
            found = false;
            lcand = Integer.MIN_VALUE;
            rcand = Integer.MAX_VALUE;
            //左
            if((cpos - pos) < 0) {
                //範囲外
                lcand = x - pos;
                found = true;
            } else {
                if(p[cpos-pos] == (x - pos)) {
                } else {
                    lcand = x-pos;
                    found = true;
                }
            }

            //右
            if((cpos + pos) >= n) {
                // 範囲外
                rcand = x + pos;
                found = true;
            } else {
                if(p[cpos+pos] == (x + pos)) {
                } else {
                    rcand = x+pos;
                    found = true;
                }
            } 
            if(found) {
                if(Math.abs(x-rcand) < Math.abs(x-lcand)) {
                    System.out.println(rcand);
                } else {
                    System.out.println(lcand);
                }
                break;
            }
        }

    } else {
        
//        System.out.println("not found");
        System.out.println(x);
    }

    scan.close();

}

};


Measured memory_bytes: 35676
from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

if __name__=='__main__':
    mod = 10**9 + 7
    n = I()
    a = LI()
    ans = 0
    for i in range(60):
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
        ans += ((n-c1)*c1*(2**i)%mod)%mod
    print(ans%mod)

Measured memory_bytes: 124568
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);

    bool ok = true;
    rep(i, 0, N) {
        int a = 0;
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0) {
                ok = false;
            }
        }
    }

    if (ok) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

    return 0;
}

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

using Edge  = tuple<int, int, int>;
using State = tuple<int, int, int>;

int main(void){
    for(int n, m; cin >> n >> m, n;){
        vector<vector<Edge>> edge(n);
        rep(_, m){
            int u, v, d, c; cin >> u >> v >> d >> c;
            u--, v--;

            edge[u].push_back(Edge(v, d, c));
            edge[v].push_back(Edge(u, d, c));
        }

        vector<int> used(n);
        priority_queue<State, vector<State>, greater<State>> q;
        q.push(State(0, 0, 0));

        int res = 0;
        while(q.size()){
            int v, diff_c, sum_d;
            tie(sum_d, diff_c, v) = q.top();
            q.pop();

            if(used[v]) continue;
            used[v] = true;

            res += diff_c;

            for(auto & e : edge[v]){
                int nv, d, c;
                tie(nv, d, c) = e;

                if(used[nv]) continue;

                q.push(State(sum_d + d, c, nv));
            }
        }

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 4212
W, H = map(int, raw_input().split())
 
p_list = list()
q_list = list()
 
for i in range(W):
    p_list.append(int(raw_input()))
    
for j in range(H):
    q_list.append(int(raw_input()))
 
p_list.sort()
q_list.sort()
 
cp = H+1
cq = W+1
 
res = 0
pid = 0
qid = 0
 
while True:
    if pid == W:
        if qid == H:
            break
        else:
            choice = 'q'
    elif qid == H:
        choice = 'p'
    elif p_list[pid] < q_list[qid]:
        choice = 'p'
    else:
        choice = 'q'
    if choice == 'p':
        cq -= 1
        res += cp*p_list[pid]
        pid += 1
    else:
        cp -= 1
        res += cq*q_list[qid]
        qid += 1
 
print res 

Measured memory_bytes: 12660
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int MAXN = 100100 ;
inline int read()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + c - '0'; c = getchar();}
	return f * x;
}
int f[MAXN], n, m, q;
int getfa(int x)
{
	if (f[x] == x) return f[x];
	return f[x] = getfa(f[x]);
}
int main()
{
	n = read(); m = read();
	for (int i = 0; i < n; ++i) f[i] = i;
	for (int i = 1, u, v; i <= m; ++i)
	{
		u = read(); v = read();
		int fa1 = getfa(u);
		int fa2 = getfa(v);
		if (fa1 != fa2)
			f[fa1] = fa2;
	}
	q = read();
	for (int i = 1; i <= q; ++i)
	{
		int u, v;
		u = read(); v = read();
		int fa1 = getfa(u), fa2 = getfa(v);
		if (fa1 == fa2) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}



Measured memory_bytes: 4104
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    string N;
    cin >> N;

    cout << "ABC" << N << endl;
    return (0);
}

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

int main(void){
  char S[4];
  int cnt = 0;
  cin >> S;
  for(int i = 0; i < 4; i++){
    if(S[i] == '+')
      cnt++;
    else if(S[i] == '-')
      cnt--;
  }
  cout << cnt << "\n";
  return 0;
}


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

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

int main(){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double aa,bb,t;
    aa=(h+m/60)/12;
    bb=m/60;
    double ax,ay,bx,by;
    ax=a*sin(2*M_PI*aa);
    ay=a*cos(2*M_PI*aa);
    bx=b*sin(2*M_PI*bb);
    by=b*cos(2*M_PI*bb);
    cout<<std::fixed << std::setprecision(15)<<sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))<<endl;

    return 0;
}

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

using namespace std;

template<class T>
struct Graph
{
	struct Vertex{};
	struct Edge {
		int to;
		T cap;
		int rev;
		Edge(int x, T y, int z) : to(x), cap(y), rev(z) {}
	};
	int sz;
	vector<Vertex> v;
	vector<vector<Edge>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	// from, to, cost
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};


template<class T>
struct Dinic : public Graph<T> {
	const int FLOW_INF = INT_MAX;
	vector<int> level;
	vector<int> iter;
// a:Vertex(|V|)
	Dinic(int n) : Graph<T>(n), level(n), iter(n) {}
// x:from y:to z:capacity
	void add_edge_dinic(int x, int y, T z) {
		this->add_edge(x, y, z, this->e[y].size());
		this->add_edge(y, x, 0, this->e[x].size()-1);
	}
	T dfs(int s, int t, T f) {
		if (s == t) return f;
		for (int& i = iter[s]; i < (int) this->e[s].size(); i++) {
			auto& x = this->e[s][i];
			if (x.cap == 0 || level[s] >= level[x.to]) continue;
			T d;
			if ((d = dfs(x.to, t, min(f, x.cap))) > 0) {
				x.cap -= d;
				this->e[x.to][x.rev].cap += d;
				return d;
			}
		}
		return 0;
	}
	void bfs(int s) {
		fill(level.begin(), level.end(), -1);
		queue<pair<int, int>> q;
		q.push(make_pair(s, 0));
		while (!q.empty()) {
			auto x = q.front();
			q.pop();
			int a = x.first;
			int b = x.second;
			if (level[a] != -1) continue;
			level[a] = b;
			for (auto y : this->e[a]) {
				if (y.cap > 0) q.push(make_pair(y.to, b+1));
			}
		}
	}
	T Dinic_solve(int s, int t) {
		T res = 0;
		while (true){
			bfs(s);
			if (level[t] < 0) return res;
			fill(iter.begin(), iter.end(), 0);
			T r;
			do {
				r = dfs(s, t, FLOW_INF);
				res += r;
			} while (r);
		}
	}
};

void AOJ_GRL_6_A() {
	int n, m;
	cin >> n >> m;
	Dinic<int> D(n);
	for (int i = 0; i < m; i++) {
		int u, v, c;
		cin >> u >> v >> c;
		D.add_edge_dinic(u, v, c);
	}
	cout << D.Dinic_solve(0, n-1) << endl;
}

int main() {
	AOJ_GRL_6_A();
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<=m;i++)
#define read(n) cin>>n;
#define write(n) cout<<n;
using namespace std;
const int N=3005;
const int Mod=998244353;
int n,m,x[N],sum;
ll ans=00000000;
int dp[9005];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>x[i];
	for(int i=1;i<=n;i++)
	{
		if(x[i]<=m)ans=(ans+1ll*dp[m-x[i]]*(n-i+1)%Mod+1ll*(x[i]==m)*(n-i+1)*i%Mod)%Mod;
		for(int j=m;j>=0;j--)
			dp[j+x[i]]+=dp[j],dp[j+x[i]]%=Mod;//grow
		dp[x[i]]+=i;//add
		dp[x[i]]%=Mod;
	}
	cout<<ans<<"\n";
	return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    scanf("%d %d" , &n , &m);

    if(n == m)cout << "Yes" << endl;
    else cout << "No" << endl;

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  N, K = readline() |> split |> parseArray

  result = (sum(1:min(K, N)) do M
    2^(-ceil(log2(K/M)))
  end + max(N - K, 0)) / N

  println(result)
end

main()


Measured memory_bytes: 174084
from statistics import median

n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
m_a = median(A)
m_b = median(B)

if n%2 == 0:
    ans = (m_b - m_a)*2 + 1
else:
    ans = m_b - m_a + 1
print(int(ans))


Measured memory_bytes: 28788
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
string s;
/**********************************/

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

    int len = s.size();
    FORD(l, len-1, 2) {
        if(l%2==1) continue;
        if(s.substr(0, l/2) == s.substr(l/2, l/2)) {
            cout << l << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import collections

n=int(input())
g=[[] for _ in range(n+1)] 
for _ in range(n-1):
  a,b,w=map(int,input().split())
  g[a].append((b,w))
  g[b].append((a,w))
q=collections.deque()
q.append(1)
checked=[0]*(n+1)
ans=[0]*(n+1)
ans[1]=0
while len(q)!=0:
  v=q.popleft()
  checked[v]=1
  for u,w in g[v]:
    if checked[u]==0:
      if w%2==0:
        ans[u]=ans[v]
      else:
        ans[u]=ans[v]^1
      q.append(u)
for i in range(1,n+1):
  print(ans[i])

Measured memory_bytes: 39956
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

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

struct UF{
    static const int MAX_N = 100000;
    int p[MAX_N];
    int r[MAX_N];

    void init(int n){
        REP(i,n){
            p[i]=i;
            r[i]=0;
        }
    }
    int find(int x){
        if(p[x]==x)return x;
        return p[x] = find(p[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)return;
        if(r[x] < r[y])swap(x,y);
        if(r[x]==r[y])r[x]++;
        p[y]=x;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

int main() {
    int n,m,q;
    cin >> n >> m;
    UF g;
    g.init(n);
    REP(i,m){
        int a,b;
        cin >> a >> b;
        g.unite(a,b);
    }
    cin >> q;
    REP(i,q){
        int a,b;
        cin >> a >> b;
        if(g.same(a,b))cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}


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

int n, k, has[105];

int main() {
	cin >> n >> k;
	int d, a;	
	for (int i=0; i<k; i++) {
		cin >> d;
		for (int j=0; j<d; j++) {
			cin >> a;
			has[a] = 1;
		}
	}
	int ans = 0;
	for (int i=1; i<=n; i++) {
		if (!has[i]) ans++;
	}
	cout << ans;
}

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

int main()
{
  int64_t N, n = 0, s = 0;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    if (A[i] < 0)
      n++;
    s += abs(A[i]);
  }
  sort(A.begin(), A.end());
  if (N == 2)
  {
    cout << A[1] - A[0] << endl;
    cout << A[0] << ' ' << A[1] << endl;
    return 0;
  }
  if (n == 0)
  {
    cout << s - 2 * A[0] << endl;
    cout << A[0] << ' ' << A[1] << endl;
    int64_t f = A[0] - A[1]; // minus
    for (int i = 2; i < N - 1; i++)
    {
      cout << f << ' ' << A[i] << endl;
      f -= A[i];
    }
    cout << A[N - 1] << ' ' << f << endl;
  }
  else if (n == N)
  {
    cout << s + 2 * A[N - 1] << endl;
    cout << A[N - 2] << ' ' << A[N - 1] << endl;
    int64_t l = A[N - 1] - A[N - 2];
    for (int i = 1; i < N - 2; i++)
    {
      cout << l << ' ' << A[i] << endl;
      l -= A[i];
    }
    cout << l << ' ' << A[0] << endl;
  }
  else
  {
    cout << s << endl;
    int64_t f = A.at(0), l = A.at(N - 1);
    for (int i = 1; i < N - 1; i++)
    {
      if (A.at(i) < 0)
      {
        cout << l << ' ' << A.at(i) << endl;
        l -= A.at(i);
      }
      else
      {
        cout << f << ' ' << A.at(i) << endl;
        f -= A.at(i);
      }
    }
    cout << l << ' ' << f << endl;
  }
}


Measured memory_bytes: 4032
#include <iostream>
void airConditioner(int temp, bool &acOn){
	if (temp >= 30)
		acOn = true;
}
int main()
{
  int X = 0;
  bool isAirConditioner = false;
	std::cin >> X;
	airConditioner(X, isAirConditioner);
		if(isAirConditioner)
			std::cout << "Yes";
		else
			std::cout << "No";
  return 0;
}

Measured memory_bytes: 3096
n,m,l=input().split()
n,m,l=[int(n),int(m),int(l)]
A=[0]*n
B=[0]*m
for i in range(n):
    A[i]=list(map(int, input().split()))
for i in range(m):
    B[i]=list(map(int, input().split()))
C=[[0]*l for i in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j]+=A[i][k]*B[k][j]
for i in range(n):
    results=" ".join([str(c) for c in C[i]])
    print(results)


Measured memory_bytes: 6896
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

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

Measured memory_bytes: 19004
s = input()

if s == "SUN":
	print(7)
elif s == "MON":
	print(6)
elif s == "TUE":
	print(5)
elif s == "WED":
	print(4)
elif s == "THU":
	print(3)
elif s == "FRI":
	print(2)
else:
	print(1)

Measured memory_bytes: 61780
parseInt(x) = parse(Int32, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function bsearch(a,x);l,r=0,length(a)+1;while r-l>1;m=(r+l)>>1;if a[m]<x;l=m;else;r=m;end;end;r;end

function main()
	mod = 10^9+7
	n,k = readline() |> split |> parseMap
	sq = floor(Int,sqrt(n))
	t = n+1
	a = Int[]
	for i in 1:sq
		if div(n,i)!=t
			push!(a,i)
			if i!=div(n,i)
				push!(a,div(n,i))
			end
			t = div(n,i)
		end
	end
	a = sort(a)
	m = length(a)
	b = Int[div(n,a[i]) for i in 1:m]
	c = Int[bsearch(a,b[i]) for i in 1:m]
	push!(a,0)
	a = sort(a)
	dp = zeros(Int,k,m)
	for i in 1:m
		dp[1,i] = a[i+1]-a[i]
	end
	tmp = zeros(Int,m)
	for i in 1:k-1
		tmp = zeros(Int,m)
		tmp[m] = dp[i,1]
		for j in 1:m-1
			tmp[m-j] = (tmp[m-j+1]+dp[i,j+1])%mod
		end
		for j in 1:m
			dp[i+1,j] = (tmp[j]*(a[j+1]-a[j]))%mod
		end
	end
	ans = 0
	for i in 1:m
		ans = (ans+dp[k,i])%mod
	end
	println(ans)
end

main()

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

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b;
  cin >> a >> b;
  if (a == 1) {
    a = 14;
  }

  if (b == 1) {
    b = 14;
  }

  if (a == b) {
    cout << "Draw" << '\n';
  } else if (a > b) {
    cout << "Alice" << '\n';
  } else {
    cout << "Bob" << '\n';
  }

  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int n; cin >> n;
	string s; cin >> s;
	int cnt = 0;
	int ans = 0;
	rep(i, n){
		if(s[i] == 'I') cnt++;
		else cnt--;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int n, y, i, j, k;
    int ans1=-1, ans2=-1, ans3=-1;
    scanf("%d%d", &n, &y);
    for(i=0;i<=n;i++){
        for(j=0;j<=n-i;j++){
            k=n-i-j;
            if(i*10000+j*5000+k*1000==y){
                ans1=i;
                ans2=j;
                ans3=k;
            }
        }
    }
    printf("%d %d %d\n", ans1, ans2, ans3);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.nextLine().toCharArray();
        for (int i=0; i<s.length; ++i) {
            String x = String.valueOf(s[i]);
            if (x.equals(x.toUpperCase())) {
                System.out.print(x.toLowerCase());
            } else if (x.equals(x.toLowerCase())) {
                System.out.print(x.toUpperCase());
            } else {
                System.out.print(x);
            }
        }
        System.out.println("");
        sc.close();
    }
}


Measured memory_bytes: 27280
# -*- coding: utf-8 -*-

class Node_Class():
    def __init__(self, c_list):
        self.c_list = c_list

n = int(raw_input())
node_dic = {}
p_list = [0]*n
d_list = [0]*n
t_list = ['']*n
root = 0
for i in range(n):
    root += i
for i in range(n):
    line = map(str, raw_input().split())
    if int(line[1]) > 0:
        node_dic[int(line[0])] = Node_Class(map(int, line[2:]))
    else:
        node_dic[int(line[0])] = Node_Class([])
#parent
for i in range(n):
    for j in node_dic[i].c_list:
        p_list[j] = i
        root -= j
p_list[root] = -1
#depth
for i in range(n):
    j = i
    while p_list[j] > -1:
        j = p_list[j]
        d_list[i] += 1
#type
for i in range(n):
    if p_list[i] == -1:
        t_list[i] = t_list[i] + "root"
    else:
        if len(node_dic[i].c_list):
            t_list[i] = t_list[i] + "internal node"
        else:
            t_list[i] = t_list[i] + "leaf"
#print
for i in range(n):
    s = "node %d: parent = %d, depth = %d, %s," %(i, p_list[i], d_list[i], t_list[i])
    print s, node_dic[i].c_list

Measured memory_bytes: 62756
#include <stdio.h>
#include <stdlib.h>
#define size (int)(1e5)

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

int main(){
	int N, i;
	scanf("%d", &N);
	int *num = (int *)malloc(sizeof(int) * size);
	for(i = 0; i < size; i++){
		num[i] = 0;
	}
	int a;
	for(i = 0; i < N; i++){
		scanf("%d", &a);
		if(a != 0){
			num[a - 1]++;
		}
		num[a]++;
		num[a + 1]++;
	}
	int ans = 0;
	for(i = 0; i < size; i++){
		ans = max(ans, num[i]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
// link:https://atcoder.jp/contests/dp/tasks/dp_a
// [prajwal1721]
// g++ -Wall -Wextra -Wshadow filename.cpp
// ./a.out >input <output
/*comments:
*/



#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b))
#define bits(x) __builtin_popcountll(x)
#define vi              vector<int>
#define vl              vector<ll>
#define all(v)          v.begin(),v.end()
#define UNIQUE(X)       (X).erase(unique(all(X)),(X).end())



typedef long long int ll;
void solve()
{
    ll n,t,m;cin>>n>>m;
    vector<ll> v;
    for(int i=0;i<n;i++){cin>>t;v.push_back(t);}
    ll ans[n+1]={0};
    for(int i=1;i<=n;i++)ans[i]=INT32_MAX;
    ans[1]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            if(i+j<=n)ans[i+j]=min(ans[i+j],abs(v[i+j-1]-v[i-1])+ans[i]);
    }
    cout<<ans[n]<<'\n';

}


int main()
{ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // ll t;cin>>t;
    // cout<<t<<"Hi test complete\n";
    // while(t--)
        {
            solve();
        }


    return 0;
}

Measured memory_bytes: 5120
import math , sys

def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)

    if temp!=1:
        arr.append(1)

    if arr==[]:
        arr.append(1)

    return arr
def sta ( x ):
    return int( 0.5* (-1 + math.sqrt(1+8*x)))
N = int( input() )

if N == 1:
    print(0)
    sys.exit()
if N == 2 or N ==3:
    print(1)
    sys.exit()
Is = fac( N )
ans = sum( [ sta(j) for j in Is])
print(max(ans,1))

Measured memory_bytes: 63780
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;cin>>n;
	for(;n--;)
	{
		double a,b,c,d,e,f,g,h;cin>>a>>b>>c>>d>>e>>f>>g>>h;
		cout<<(abs((d-b)*(g-e)-(h-f)*(c-a))<1e-10?"YES":"NO")<<endl;
	}
}



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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)
char g[101][101];
void solve()
{
    int H, W;
    cin >> H >> W;
    vector<int> row, col;
    REP0 (i, H)
    {
        bool isskip = true;
        REP0 (j, W)
        {
            cin >> g[i][j];
            if (g[i][j] == '#')
                isskip = false;
        }
        if (isskip)
            continue;

        row.push_back(i);
    }

    REP0 (j, W)
    {
        bool isskip = true;
        REP0 (i, H)
        {
            if (g[i][j] == '#')
                isskip = false;
        }
        if (isskip)
            continue;

        col.push_back(j);
    }

    for (auto i : row)
    {
        for (auto j : col)
        {
            cout << g[i][j];
        }
        cout << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
	        #define ll long long int
	        using namespace std;
	        #define mod 1000000007
	        #define pb push_back
	        #define fi first
	        #define si second
	        #define mp make_pair
	        #define f(n) for(ll i=0;i<n;i++)
	        #define ff(m) for(ll j=0;j<m;j++)
	        #define fr(i,p,n) for(ll i=p;i<n;i++)
	        #define in insert
	        ll exp(ll a,ll b,ll m);
	        #define vl vector<ll> 
	        #define pll pair <ll,ll>
	
	    
	        void solve(){
	
				ll n,k;
				cin>>n>>k;
				ll ans1,ans2;
				ans1=n%k;
				ans2=abs(ans1-k);
				cout<<min(ans1,ans2)<<endl;
	
	
	
	        }
	 
	       int main(){
	            ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	 
	 	    
	 
	            int t=1;
	 			//cin>>t;
	            while(t--)
	               solve();
	    
	    		return 0;
			}
	 
			ll exp(ll a,ll b,ll m)
			{
				if(b==0)
				{
					return 1;
				}
				ll temp =exp(a,b/2,m);
				temp=(temp*temp)%m;
				if(b&1)
				{
					return (temp*(a%m))%m;
				}
				return temp;
			}

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

namespace geo
{
  const double EPS = 1e-10;

  class Point
  {
  public:
    double x, y;

    Point(double _x = 0.0, double _y = 0.0)
      :x(_x), y(_y) {}

    inline double abs() const
    {
      return sqrt(x*x + y*y);
    }

    // 内積
    inline double dot(const Point& p) const
    {
      return (x*p.x + y*p.y);
    }

    // 外積
    inline double cross(const Point& p) const
    {
      return (x*p.y - y+p.x);
    }

    // 直交
    inline bool orthogonal(const Point& p) const
    {
      if (dot(p) == 0.0)
	return true;
      return false;
    }

    // 平行
    inline bool parallel(const Point& p) const
    {
      if (cross(p) < EPS)
	return true;
      return false;
    }

    Point operator +(const Point& p) const
    {
      return Point(x+p.x, y-p.y);
    }

    Point operator -(const Point& p) const
    {
      return Point(x-p.x, y-p.y);
    }

    Point operator =(const Point& p)
    {
      x = p.x;
      y = p.y;
    }

    bool operator ==(const Point& p) const
    {
      if ((*this - p).abs() < EPS)
	return true;
      return false;
    }
  };
}

using namespace geo;

int main()
{
  double xA, yA, xB, yB, xC, yC, xD, yD;
  while (cin >> xA >> yA >> xB >> yB >> xC >> yC >> xD >> yD) {
    Point AB(xA-xB, yA-yB), CD(xC-xD, yC-yD);
    if (AB.orthogonal(CD))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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


	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	cout << (h2 - h1) * 60 + m2 - m1 - k << endl;


	return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n;
	cin >> n;
	vll a(n);
	rep(i, n) cin >> a[i];

	sort(all(a));
	cout << abs(a.front() - a.back()) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b
  
def solve():
    N, M = map(int, line_input())
    food_liked = [0] * M
    for i in range(N):
        person_i = list(map(int, line_input()))
        for a in person_i[1:]:
            food_liked[a-1] += 1
    num_of_everyone_like = 0
    for m in range(M):
        if food_liked[m] == N:
            num_of_everyone_like += 1
    return num_of_everyone_like

  
if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 3316
import java.util.*;

public class Main {
	private String string;

	public static void main(String[] args) {
		new Main().run();
	}
	
	public void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			string = scan.next();
			
			int joi = 0, ioi = 0;
			for (int i = 0; i < string.length()-2; i++) {
				String str = string.substring(i, i + 3);
				
				if (str.equals("JOI")) {
					joi++;
					i++;
				}else if (str.equals("IOI")) {
					ioi++;
					i++;
				}
				//System.out.println(str);
			}
			System.out.println(joi);
			System.out.println(ioi);
		}
	}

}

Measured memory_bytes: 23432
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

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

	int N, M; cin >> N >> M;
	vector<P> V;
	for (int i = 0; i < N; i++) {
		P p; cin >> p.first >> p.second;
		V.push_back(p);
	}
	sort(V.begin(), V.end());
	ll ans = 0;

	priority_queue<int> Q;
	int num = 0;
	for (int i = 1; i <=M; i++) {
		while (num <N && V[num].first <= i) {
			Q.push(V[num].second);
			num++;
		}

		if (!Q.empty()) {
			ans += Q.top();
			Q.pop();
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second

        int const N = 100009;
        long long const mod = 1e9 + 7;
        long long dp[N][2];
        vector<int> adj[N];
        void dfs(int v,int p)
        {
            dp[v][0] = 1;
            dp[v][1] = 1;
            for(int u:adj[v])
            {
                if(u != p)
                {
                    dfs(u, v);
                    dp[v][0] = (dp[v][0] * ((dp[u][0] + dp[u][1])%mod))%mod;
                    dp[v][1] = (dp[v][1] * dp[u][0])%mod;
                }
            }
        }
        int main()
        {
        // clock_t begin = clock();
        // #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        // #endif
        tani_nachi_ke  

        int n;
        cin >> n;
        for(int i = 1 ; i < n ;i++)
        {
            int aa,bb;
            cin >> aa >> bb;
            adj[aa].push_back(bb);
            adj[bb].push_back(aa);
        }
        dfs(1,-1);
        cout << (dp[1][0] + dp[1][1])%mod << endl;





        // #ifndef ONLINE_JUDGE 
        // clock_t end = clock();
        // cout<<endl<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
        // #endif 
        // return 0;
        }

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int S[2020];
int T[2020];
ll num[2020][2020];
ll sum[2020][2020];
ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>S[i];
	FOR(i,M) cin>>T[i];
	
	FOR(x,2020) sum[x][0]=sum[0][x]=1;
	ll ret=1;
	FOR(x,N) FOR(y,M) {
		if(S[x]==T[y]) {
			num[x+1][y+1]=(sum[x][y])%mo;
			ret+=num[x+1][y+1];
		}
		sum[x+1][y+1]=(sum[x][y+1]+sum[x+1][y]+mo-sum[x][y]+num[x+1][y+1])%mo;
	}
	
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 63744
#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define For(i, a, b)    for(int i = (a); (i) < (b) ; ++(i))
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void sortVector(vector<T> &v, bool lesser = true) { lesser ? sort(all(v)) : sort(all(v), greater<T>()); }
bool isPrime(int n){
    if(n < 2) return false; else if(n == 2) return true; else if(n%2 == 0) return false;
    double sqrtNum = sqrt(n); for(int i = 3;i <= sqrtNum; i += 2) if(n%i == 0) return false;
    return true; }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    cout << (n + 1) / 2 << endl;

return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-5;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
int n;
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	cout << a[n-1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

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

	if (B%A == 0) {
		cout << A+B << endl;
	}
else{
		cout << B-A << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
r=m//n
if r>=10**7:
  for i in range(n,r):
    if m%i==0:
      print(m//i)
      break
else:
  for i in range(r):
    if m%(r-i)==0 and m//(r-i)>=n:
      print(r-i)
      break

Measured memory_bytes: 3060
#include "bits/stdc++.h"

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    ll ans = 0;
    for(int i = 0; i < N; i++) cin >> A[i];
    
    for(int i = 0; i < 60; i++){
        ll one = 0;
        for(int j = 0; j < N; j++){
            if(A[j] >> i & 1) one++;
        }
        ll now = one * (N - one) % MOD;
        
        for(int j = 0; j < i; j++) now = now * 2 % MOD;
        ans += now;
        ans %= MOD;
    }
    
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}
/****** define variable start ******/
ll k;
/******* define variable end *******/
int solve() {
	cin >> k;
	ll ans = 0;
	REP(a, k){
		REP(b, k){
			REP(c, k){
				ans += gcd(a+1, gcd(b+1, c+1));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for(long long i = (long long)(n - 1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using ll = long long;

int main()
{
	string s;
	cin >> s;

	bool a = false, b = false;
	for (auto x : s)
	{
		if (x == 'A') a = true;
		else b = true;
	}

	if (a && b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 256