akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int h = tmp[0], w = tmp[1];
	
	string[] canvas = new string[h+2];

	canvas[0] = "";
	canvas[h+1] = "";
	for (int i = 0; i <= w+1; i++)
	{
	    canvas[0]   += ".";
	    canvas[h+1] += ".";
	}

	for(int i = 1; i <= h; i++)
	{
	    canvas[i] = "." + ReadLine() + ".";
	}

	for (int i = 1; i <=  h; i++)
	{
	    for (int j = 1; j <= w; j++)
	    {
		if (canvas[i][j] == '#' &&
		    canvas[i-1][j] != '#' &&
		    canvas[i+1][j] != '#' &&
		    canvas[i][j-1] != '#' &&
		    canvas[i][j+1] != '#' )
		{
		    WriteLine("No");
		    return;
		}
	    }
	}
	WriteLine("Yes");
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
class UnionFind
{
  public:
    /* 親の番号を格納する。親だった場合は-(その集合のサイズ) */
    vector<int> Parent;

    // 作る時はParentの値を全て-1にする
    // こうすると全てバラバラになる
    UnionFind(int N)
    {
        Parent = vector<int>(N, -1); // 要素数Nのベクトルの要素を全て-1で初期化
    }
     
    int root(int A)
    {
        if (Parent[A] < 0){  
            return A;
        }
        return Parent[A] = root(Parent[A]);
    }

    int size(int A)
    {
        return -Parent[root(A)]; //親をとってきたい
    }

    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)をくっつけたい
        //代償が逆だったらひっくり返しちゃう。
        if (size(A) < size(B)){
            swap(A, B);
        }
        // Aのサイズを更新する
        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
}; 
int main(){
    int N, M; 
    cin >> N >> M;
    vector<int> A(M), B(M);
    for (int i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    vector<long long> ans(M);
    ans[M - 1] = (long long)N * (N - 1) / 2;

    UnionFind Uni(N);

    for (int i = M - 1; i>= 1; i--)
    {
        ans[i - 1] = ans[i];

        // 繋がって無かったのが繋がった時
        if (Uni.root(A[i]) != Uni.root(B[i])) {
            ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
            Uni.connect(A[i], B[i]);
        }
    }
    for (int i = 0; i < M; i++)
    {
        cout << ans[i] << endl;
    }
}


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

const int mod = 1e9+7;


int dp[100005];

int main()
{
    dp[1] = 1;

    for(int i = 2 ; i<=1e5+2 ; i++)
    {
        dp[i] = (1ll*dp[i-1]*i)%mod;
    }


    int n , m;

    cin >> n >> m;

    if(abs(n-m)>1)
    {
        cout << "0";
        return 0;
    }

    else if(n==m)
    {
        long long  ans = (1ll*dp[n]*dp[m])%mod;
        ans = (2ll*ans)%mod;
        cout << ans;
        return 0;
    }
    else
    {
        long long  ans = (1ll*dp[n]*dp[m])%mod;
        cout << ans;
        return 0;
    }


}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
using ll = long long;

#define REP(i,s,N) for(ll i=s;i<N;++i)

void print(const vector<ll> &x) {
	REP(i,0,x.size()) {
		if (i == 0) printf("%lld", x[i]);
		else printf(" %lld", x[i]);
	}
	cout << endl;
}

void sort(vector<ll> &x) {
	REP(i,0,x.size()) {
		ll j = i-1;
		ll key = x[i];
		while (j >= 0 && key < x[j]) {
			x[j+1] = x[j];
			--j;
		}
		x[j+1] = key;
		print(x);
	}
}

int main() {
	ll n;
	cin >> n;
	vector<ll> x(n,0);
	REP(i,0,n) scanf("%lld", &x[i]); 
	sort(x);
	return 0;
}




Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }


int main(void){
    // Your code here!
    int N; cin >> N;
    vector<ll> a(N);
    vector<ll> b(N);
    vector<ll> c(N);
    rep(i,N) cin >> a[i] >> b[i] >> c[i];
    vector<vector<ll>> dp(N+1,vector<ll>(3));
    rep(i,N) {
        dp[i+1][0] = max(dp[i][1],dp[i][2]) + a[i];
        dp[i+1][1] = max(dp[i][0],dp[i][2]) + b[i];
        dp[i+1][2] = max(dp[i][0],dp[i][1]) + c[i];
    }
    cout << max(dp[N][0],max(dp[N][1],dp[N][2])) << endl;
}

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

const int N = 1010;
const int M = 2010;
typedef long long LL;

int n, m;

struct Edge{
	int to, id;
	Edge(){}
	Edge(int to, int id):to(to),id(id){}
};
vector<Edge> V[N];
vector<int> G[N];
bool vis_edge[M];
bool ok[N];
int dis[M];

void init(){
	for(int i=1; i<=n; i++){
		ok[i] = 0;
	}
	queue<int> Q;
	Q.push(n);
	ok[n] = 1;
	while(!Q.empty()){
		int x = Q.front(); Q.pop();
		for(int i=0; i<G[x].size(); i++){
			int j = G[x][i];
			if(!ok[j]){
				ok[j] = 1;
				Q.push(j);
			}
		}
	}
}

LL dp[N], ed[M];
bool vis[N];

struct Node{
	int to;
	LL d;
	Node(){}
	Node(int to, LL d):to(to),d(d){}
	bool operator < (const Node &A)const{
		return d > A.d;
	}
};

int cnt[N];

void solve(){
	LL ans;
	bool flag= 0;
	for(int i=1; i<=n; i++){
		vis[i] = 0;
		cnt[i] = 0;
	}
	priority_queue<Node> Q;
	Q.push(Node(1, 0));
	while(!Q.empty()){
		Node nd = Q.top(); Q.pop();
		if(!vis[nd.to]){
			vis[nd.to] = 1;
		} else {
			if(nd.d < dp[nd.to])	continue;
		}
		if(nd.to == n){
			if(!flag){
				ans = nd.d;
				flag = 1;
			}
			ans = max(ans, nd.d);
		}
		dp[nd.to] = nd.d;
		cnt[nd.to]++;
		if(cnt[nd.to] > n){
			puts("inf");
			return;
		}
		for(int i=0; i<V[nd.to].size(); i++){
			int j = V[nd.to][i].to;
			int k = V[nd.to][i].id;
			if(!ok[j])	continue;
			if(!vis[j] || dp[j] < nd.d + dis[k]){
				vis[j] = 1;
				dp[j] = nd.d + dis[k];
				Q.push(Node(j, dp[j]));
			}
		}
	}
	printf("%lld\n", ans);
}

int main(){
	int x, y, z;
	while(~scanf("%d %d", &n, &m)){
		for(int i=1; i<=n; i++){
			V[i].clear();
			G[i].clear();
		}
		for(int i=1; i<=m; i++){
			scanf("%d %d %d", &x, &y, dis+i);
			V[x].push_back(Edge(y, i));
			G[y].push_back(x);
		}
		init();
		solve();
	}
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	priority_queue<int, vector<int>, greater<int> > qu;
	int i,j,n,m,c,a,x; 
	long long sum;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&m);
		for(j=1;j<=m;j++){
		    scanf("%d",&c);
			qu.push(c);
		}
	    for(j=1;j<=m-1;j++){
			 qu.pop();
	    }
	}
	sum=0;
	for(i=1;i<=n;i++){
		x=qu.top();
		sum+=(long long)x;
		qu.pop();
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 4452
///******* In the name of Allah *******///

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

long int gcd(long int a, long int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void Ok()
{
    long int a[1013],b,c,d,e,f,g,h,t,s,i,j,k,l1,l2,m,n,r,sum = 0,ans_1,ans_2,ans_3,cnt = 0,Max,Min,flag,div,rcv;
    double aa,bb,cc,dd,ee,tot;
    char aaa[3013],bbb[1013],ccc[1013],num,temp;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]%2==0) cnt++;
    }
    b = cnt;
    cnt = 0;
    for(i=1;i<=n;i++)
    {
        if(a[i]%2==0 &&(a[i]%3==0 || a[i]%5==0)) cnt++;
    }
    if(b==cnt) cout<<"APPROVED"<<endl;

    else cout<<"DENIED"<<endl;


    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 256
<?php

class Simulator
{
    private $inputs;
    private $backslash = array();
    private $area_pond = array();
    private $pending_area = array();

    public function __construct()
    {
        $this->inputs = trim(fgets(STDIN));
    }

    public function calculateAreas()
    {
        $count = 0;

        for ($index = 0; $index < strlen($this->inputs); $index++) {
            if ($this->inputs[$index] == "\\") {
                $this->backslash[] = $index;
            } elseif ($this->inputs[$index] == "/" and $this->backslash) {
                $last_bs_index = array_pop($this->backslash);
                $diff = $index - $last_bs_index;
                $count += $diff;
                while ($this->area_pond and end($this->area_pond) > $last_bs_index) {
                    $diff += array_pop($this->pending_area);
                    array_pop($this->area_pond);
                }
                $this->area_pond[] = $last_bs_index;
                $this->pending_area[] = $diff;
            }
        }
        echo $count . PHP_EOL;
        echo implode(" ", array_merge([count($this->area_pond)], $this->pending_area)) . PHP_EOL;

        // echo count($this->area_pond), " ", implode(" ", $this->pending_area) . PHP_EOL;
    }
}

$simulator = new Simulator();
$simulator->calculateAreas();



Measured memory_bytes: 12148
#include <stdio.h>
#define MAX 101

int main(){
  int i,j,n;
  int k,l;
  int M[MAX][MAX];
  int id;
  scanf("%d",&n);
  for(i=0;i<n+1;i++){
    for(j=0;j<n+1;j++){
    M[i][j] = 0;
      }
  }
  
  for(i=1;i<n+1;i++){
    scanf("%d",&id);
    scanf("%d",&k);
    for(j=1;j<k+1;j++){
    scanf("%d",&l);
    M[i][l] = 1;
    }
  }
 
  for(i=1;i<n+1;i++){
    for(j=1;j<n;j++){
      printf("%d ",M[i][j]);
      }
    printf("%d\n",M[i][j]);
  }  
  
}



Measured memory_bytes: 2112
n = int(input())
edges = {}
dist = {}
con = {}

for i in range(n-1):
  a, b, c = map(int, input().split())
  edges[frozenset([a, b])] = c
  if a not in con:
    con[a] = {}
  if b not in con:
    con[b] = {}
  con[a][b] = True
  con[b][a] = True

q, k = map(int, input().split())
## setup

dist[k] = 0
frontier = [k]
while len(dist.keys()) != n:
  frontier_new = []
  for f in frontier:
    for neigh in con[f]:
      if con[f][neigh]:
        dist[neigh] = dist[f] + edges[frozenset([neigh, f])]
        frontier_new.append(neigh)
        con[f][neigh] = False
        con[neigh][f] = False
  frontier = frontier_new[:]

for qq in range(q):
  x, y = map(int, input().split())
  print(dist[x] + dist[y])


Measured memory_bytes: 125400
#include<bits/stdc++.h>
#define maxn 100050
using namespace std;

const int inf=1<<30;

struct node {
    int l,r;
    bool operator < (const node& N) const   {
        return l<N.l;
    }
} I[maxn];

int n;

int rmn[maxn],rmx[maxn];
int lmn[maxn],lmx[maxn];

int main()  {
    scanf("%d",&n);
    int rj=1;
    for (int i=1;i<=n;++i)  {
        scanf("%d%d",&I[i].l,&I[i].r);
        if (I[rj].r>I[i].r)
            rj=i;
    }
    swap(I[1],I[rj]);
    sort(I+2,I+n+1);
    rmn[n+1]=lmn[0]=inf;
    rmx[n+1]=rmx[0]=-inf;

    for (int i=n;i;--i) {
        rmn[i]=min(rmn[i+1],I[i].r);
        rmx[i]=max(rmx[i+1],I[i].l);
    }

    for (int i=1;i<=n;++i)  {
        lmn[i]=min(lmn[i-1],I[i].r);
        lmx[i]=max(lmx[i-1],I[i].l);
    }

    int ans=0;
    for (int i=1;i<n;++i)   {
        int t=max(I[1].r-I[i].l+1,0)+max(rmn[i+1]-rmx[i+1]+1,0);
        ans=max(ans,t);
        // cout<<i<<":"<<t<<" "<<max(I[1].r-I[i].l+1,0)<<"+"<<max(rmn[i+1]-rmx[i+1]+1,0)<<endl;
    }

    for (int i=1;i<=n;++i)  {
        int l=max(lmx[i-1],rmx[i+1]),r=min(lmn[i-1],rmn[i+1]);
        int t=max(r-l+1,0)+I[i].r-I[i].l+1;
        // cout<<i<<":"<<max(r-l+1,0)+I[i].r-I[i].l+1<<" "<<max(r-l+1,0)<<"+"<<I[i].r-I[i].l+1<<endl;
        ans=max(ans,t);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2560
N = int(input())

S = ""
if N != 0:
    while N != 0:
        remainder = N % -2
        if remainder < 0:
            remainder += 2
            N = (N // -2) + 1
        else:
            N //= -2
        S = str(remainder) + S
else:
    S = "0"

print(S)


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

int main() {
    char s[4]; cin >> s;
    int a = 0, b = 0;
    for (auto c : s) {
        a += c == 'A';
        b += c == 'B';
    }
    cout << (a != 3 && b != 3 ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3600
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
struct Node{
    int x;
    int y;
}a[100005];
int n,m,ans,du[100005],h[100005],f[100005];
vector<int>v[100005],k[100005];
stack<int>q;
int main(){
    in(n);in(m);
    for(int i=1;i<=m;i++){
        in(a[i].x);in(a[i].y);
        v[a[i].x].push_back(a[i].y);
        k[a[i].y].push_back(a[i].x);
        du[a[i].y]++;
    }
    for(int i=1;i<=n;i++)if(du[i]==0)q.push(i),h[++h[0]]=i;
    while(!q.empty()){
        int l=q.top();
        q.pop();
        for(int i=0;i<v[l].size();i++){
            int u=v[l][i];
            du[u]--;
            f[u]=max(f[u],f[l]+1);
            if(du[u]==0){
                q.push(u);
                h[++h[0]]=u;
            }
        }
    }
    for(int i=1;i<=n;i++)ans=max(ans,f[i]);
    printf("%d\n",ans);
	return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	int n, a, b; cin >> n >> a >> b;

	while (true) {
		// Move A
		if (b != a + 1) {
			a++;
		} else {
			if (a == 1) {
				cout << "Borys" << endl;
				return 0;
			} else {
				a--;
			}
		}

		// Move B
		if (b != a + 1) {
			b--;
		} else {
			if (b == n) {
				cout << "Alice" << endl;
				return 0;
			} else {
				b++;
			}
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void){
  ll A, B;
  IN(A);
  IN(B);
  PRINT(6-A-B);
}


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

int D,N;
int main(){
	cin >> D >> N;
	if(D==0){
		if(N!=100) cout << N << endl;
		else cout << N+1 << endl;
	}
	else if(D==1){
		if(N!=100) cout << 100*N << endl;
		else cout << (N+1)*100 << endl;
	}
	else{
		if(N!=100) cout << 10000*N << endl;
		else cout << (N+1)*10000 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    char S[25];
    cin >> S;
    int a,b,c;
    c = 0;
    for (a = 0;a <= 25;a++){
      for (b = 0;b <= 25;b++){
        if (S[a] == S[b])
          if (a != b)
            if (S[a] != '\0')
              c = c+1;
      }
    }
    if (c == 0)
      cout << "yes\n";
    else
      cout << "no\n";
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<vector<int>> adj;
bool ok = true;
vector<int> v;

int dfs(int n=0, int p=-1) {
  int result = 1, count = 0;
  for (auto x: adj[n]) {
    if (x!=p) {
      v[x] = !v[n];
      int tmp = dfs(x,n);
      result += tmp;
      count += tmp%2;
    }
  }
  if (count>=2) ok = false;
  return result;
}

int main() {
  int N; cin >> N;
  adj.resize(N);
  v.resize(N,-1); v[0] = 0;
  rep(i,N-1) {
    int a, b; cin >> a >> b; a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  dfs();
  int oe = 0; rep(i,N) oe += v[i] ? 1 : -1;
  if (oe) ok = false;
  string result = (!ok) ? "First" : "Second";
  cout << result << endl;
  return 0;
}

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

using namespace std;
using ll = long long int;

int main(void) {
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    string s;
    cin >> s;
    ll n = s.size();

    map<ll,ll> m;

    auto pow = [&](ll x, ll n) {
        ll r = 1;
        while(n) {
            if(n&1) (r *= x) %= 2019;
            (x *= x) %= 2019;
            n /= 2;
        }
        return r;
    };

    ll t = 0, r = 0;
    m[0]++;
    for(ll i=n-1; i>=0; i--) {
        ll u = (s[i]-'0')*pow(10,n-i);
        t = (t + u) % 2019;
        r += m[t];
        m[t]++;
    }
    cout << r << endl;
}


Measured memory_bytes: 3780
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int T[2000000] = {0};
int text[2000000] = {0};
int main(){
    int n, t, i;
    while(cin >> n >> t){
        for(i = 0; i < n; i++){
            cin >> T[i];
            if(i!=0&&T[i]-T[i-1]<t){
                text[i] = T[i]-T[i-1];
            }else if(i!=0&&T[i]-T[i-1]>=t){
                text[i] = t;
            }
        }
        text[n] = t;
        int sum = 0;
        for(i = 1; i <= n; i++){
            sum+=text[i];
        }
        cout << sum << endl;
    }
    return 0;
}

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

int main() {
//	freopen("data.in", "r", stdin);
//	freopen("data.out", "w", stdout);
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	int a[n][2], b[m][2];
	for (int i = 0; i < n; ++i) {
		cin >> a[i][0] >> a[i][1];
	}
	for (int j = 0; j < m; ++j) {
		cin >> b[j][0] >> b[j][1];
	}
	for (int i = 0; i < n; ++i) {
		double mi = 1e9;
		int g = i;
		for (int j = 0; j < m; ++j) {
			double dis = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]);
			if (dis < mi) {
				mi = dis;
				g = j+1;
			}
		}
		cout << g << endl;
	}
}



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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B;
    cin >> A >> B;

    int ans = A + B;
    if (ans < A - B) {
        ans = A - B;
    }
    if (ans < A * B) {
        ans = A * B;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

	ll n;
	cin >> n;
	cout << n * (n - 1) / 2 << endl;
}

Measured memory_bytes: 256
Q,H,S,D = map(int,input().split())
N = int(input())
mincost2 = min(8*Q,4*H,2*S,D)
mincost1 = 0
if N%2 == 1:
  mincost1 = min(4*Q,2*H,S)
print(int((N//2)*mincost2+mincost1))

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string s; cin>>s;
    int n; cin>>n;
    int rize=0;
    rep(i,n){
        string gotiusa; cin>>gotiusa; rep(i,10)gotiusa+=gotiusa;
        for(int j=0; j<gotiusa.size()-s.size()-1;j++){
            string tiya;
            for(int k=j; k<j+s.size();k++)
                tiya.push_back(gotiusa[k]);
            if(tiya==s){rize++;break;}
        }
    }
    cout<<rize<<endl;
}

Measured memory_bytes: 3148
#include <iostream>


using namespace std;

int main(){

  int n;
  cin>>n;
  
  int m=n,keta=0;
  while(m!=0){
    keta+=m%10;
    m/=10;
   
  }

  if(n%keta){
  cout<<"No"<<endl;
  }else{
  cout<<"Yes"<<endl;
  }


}

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

using namespace std;

int main(){	
	int l,r,d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i < r + 1; i++){
		if (i % d == 0){
			++ans;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3628
def num(pos,list1):
    count = 0
    val = list1[pos]
    for x in range(pos+1,len(list1)):
        if list1[x]<=val:
            count+=1
            val=list1[x]
        else:
            return count
    return count
maximum = 0
n = int(input())
list1 = [int(i) for i in input().split()]
y = 0
while y<len(list1):
    ans = num(y,list1)
    if ans>maximum:
        maximum = ans
    y+=ans+1
print(maximum)

Measured memory_bytes: 14252
if __name__ == '__main__':

    N = int(input())
    x = []
    y = []

    for _ in range(N):
        x_, y_ = map(int, input().split())
        x.append(x_)
        y.append(y_)
    xpy = [a + b for a, b in zip(x, y)]
    xmy = [a - b for a, b in zip(x, y)]
    max_1 = max(xpy)
    min_1 = min(xpy)
    max_2 = max(xmy)
    min_2 = min(xmy)
    print(max(max_1 - min_1,max_2 - min_2))




Measured memory_bytes: 123844
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;


public class Main{
   
   

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=A+B;
        int D=A-B;
        int E=A*B;
        int F=Math.max(C,D);
        int G=Math.max(E,F);
        System.out.println(G);

        
        

    }

        
        
    }


Measured memory_bytes: 21844
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++)
      A[i] = sc.nextInt();
    sc.close();

    long[] A1 = new long[N];
    long[] A2 = new long[N];
    for (int i = 0; i < N; i++) {
      if (i + A[i] < N) A1[i + A[i]]++;
      if (-1 < i - A[i]) A2[i - A[i]]++;
    }

    long ans = 0;
    for (int i = 0; i < N; i++)
      ans += A1[i] * A2[i];

    System.out.println(ans);
  }
}


Measured memory_bytes: 60096
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;

string str;
int main() {
    cin>>str;
    int len=str.size();

    int g=0,p=0;
    int res=0;
    for(int i=0; i<len; i++){
        if(str[i]=='g'){
            if(p<g){
                res++;
                p++;
            }
            else
                g++;
        }
        else{
            if(p>g){
                g++;
                res--;
            }
            else
                p++;
        }
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

// n次元上のm個の点列のうち、マンハッタン距離が最も遠い点対の距離をO(2^n・m)で求める
ll LongestManhattanDistance(vector<vector<ll>>& P){
    ll n = P[0].size();
    ll m = P.size();
    
    vector<ll> a(1<<n,-LINF);
    for(int i = 0; i < m;i++){
        for(int s = 0; s < (1<<n); s++){
            ll y = 0;
            for(int j = 0; j < n;j++){
                if((s>>j)&1){
                    y += P[i][j];
                }else{
                    y -= P[i][j];
                }
            }
            a[s] = max(a[s],y);
        }
    }
    ll ret = -LINF;
    for(unsigned s = 0; s < (1<<n); s++){
        unsigned t = ~s & ((1<<n)-1);
        ret = max(ret,a[s] + a[t]);
    }
    return ret;
}

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<vector<ll>> P;
    for(int i = 0; i < N;i++){
        ll x,y; cin >> x >> y;
        
        P.push_back(vector<ll>{x,y});
    }
    
    res = LongestManhattanDistance(P);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int main(){

int a,b,c,d,e,f;

cin >> a >> b >> c >> d >>e >> f;
if(a + 5*b + c*10 + d*50 + e*100 + f*500 >= 1000){
cout << "1\n";
}
else{
cout << "0\n";
}


return 0;
}

Measured memory_bytes: 1128
using System;
namespace HelloWorld
{
    internal class Vector
    {
        internal double x { get; set; }
        internal double y { get; set; }
    }
    class Program
    {
        static void Main()
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                double[] num = Array.ConvertAll(line.Split(','), double.Parse);
                Vector a = new Vector { x = num[0], y = num[1] };
                Vector b = new Vector { x = num[2], y = num[3] };
                Vector c = new Vector { x = num[4], y = num[5] };
                Vector p = new Vector { x = num[6], y = num[7] };
                Console.WriteLine((Check(a, b, c, p) * Check(a, b, p, c) * Check(a, c, p, b) * Check(b, c, p, a)) == 0 ? "NO" : "YES");
            }
        }
        public static int Check(Vector a, Vector b, Vector c, Vector p)
        {
            var ab = MkVector(b, a);
            var bc = MkVector(c, b);
            var ca = MkVector(a, c);
            var ap = MkVector(p, a);
            var bp = MkVector(p, b);
            var cp = MkVector(p, c);
            var c1 = ab.x * bp.y - ab.y * bp.x;
            var c2 = bc.x * cp.y - bc.y * cp.x;
            var c3 = ca.x * ap.y - ca.y * ap.x;
            if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0))
                return 0;
            else
                return 1;
        }
        public static Vector MkVector(Vector a, Vector b)
        {
            var c = new Vector();
            c.x = a.x - b.x;
            c.y = a.y - b.y;
            return c;
        }
    }
}


Measured memory_bytes: 17908
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define vec vector 
#define vi vector <ll> 
#define vvi vector <vector <ll> > 
#define vvvi vector < vector <vector <ll> > >
/*
vi a(n);
vvi a(n, vi(m));
vvvi a(n, vvi(m, vi(u)));
for(int h = 0; h < n; ++h){
for(auto h : b){
*/
int check (int x, vi &a){
    for(int j : a){
        if((x^j) < x)x = x^j;
    }
    return x;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int z=1; 
    cin >> z;
    while(z--){
        int n = 5;
        cin >> n;
        //cout << fixed << setpresion(10);
        //cout << 0.1 << '\n';
        vi a(n);
        for(int i = 0; i < n; ++i){
            cin >> a[i];
        }
        string s;
        cin >> s;
        int winer = 0;
        vi b,c;
        for(int i = n-1;i >= 0; --i){
            if(s[i] == '1'){
                if(check(a[i],c) != 0) winer = 1; 
            }
            else {
                c.push_back(check(a[i], c));
            }
        }
        cout << winer << '\n';
    }
}


Measured memory_bytes: 3644
import sys

n = int(input())
sys.setrecursionlimit(2*10**9+1)


def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    map<string, int> a;
    set<string> b;
    
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        a[s]++;
    }
    
    int mx = -1;
    for (auto it : a)
        mx = max(mx, it.second);
    
    for (auto it : a)
        if (it.second == mx)
            b.insert(it.first);
        
    for (auto each : b)
        cout << each << "\n";
    
    return 0;
}


Measured memory_bytes: 33280
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) {if(y < x) x = y;}
template<typename T, typename U> inline void mxze(T &x, U y) {if(x < y) x = y;}

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
template<typename T>
void _scan( vector<T> &v ){
	for(int i=0; i<(int)v.size(); i++) _scan(v[i]);
}
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h)
	{ cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++;
	cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<" = "; for(auto _i:x) cerr<<_i<<", ";cerr<<"\n";}}
#define debuga(x, sz) {{cerr<<#x<<" = ";for(int _i=0;_i<sz;_i++)cerr<<x[_i]<<", ";cerr<<"\n";}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

ll MOD = 1e9+7;

inline ll Msum(ll x){return x;}
template<typename... Rest>
inline ll Msum(ll x, Rest... rest){ return (x + Msum(rest...)) % MOD; }

inline ll Mprod(ll x){return x;}
template<typename... Rest>
inline ll Mprod(ll x, Rest... rest){ return x * Mprod(rest...) % MOD; }

inline ll Mnorm(ll x){ return (x%MOD + MOD) %MOD; }

inline ll Msq(ll x){ return (x*x) %MOD; }
inline ll Mpot(ll x, ll e){
	if(!e) return 1;
	return Msq(Mpot(x, e>>1)) * (e & 1 ? x : 1)%MOD;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

const int MAXN = 1e5+5;

int n, m;
int p[MAXN];

int rep[MAXN];
int find(int v){
	if(rep[v] == v) return v;
	return rep[v] = find(rep[v]);
}
void unite(int v, int u){
	v = find(v); u = find(u);
	rep[v] = u;
}

int main(){
	scan(n, m);
	for(int i=0; i<n; i++){
		scan(p[i]);
		p[i]--;
	}
	for(int i=0; i<n; i++) rep[i] = i;
	for(int i=0; i<m; i++){
		int v,u; scan(v,u); v--; u--;
		unite(v, u);
	}
	int ans=0;
	for(int i=0; i<n; i++) if(find(i) == find(p[i])) ans++;
	printf("%d\n", ans);
}


Measured memory_bytes: 1024
#include <stdio.h>
int maxmin(int a, int b, int c){
	int max = a;
	int min = a;
	if(b > max){
		max = b;
	}else if(b < min){
		min = b;
	}
	if(c > max){
		max = c;
	}else if(c < min){
		min = c;
	}
	return max - min;
}

int T(int H, int W){
	int case1, case2, upperHeight, leftWidth;
	upperHeight = H / 3;
	leftWidth = W / 2;
	int S1 = upperHeight * W;
	int S2 = (H - upperHeight) * leftWidth;
	int S3 = (H - upperHeight) * (W - leftWidth);
	case1 = maxmin(S1, S2, S3);
	
	upperHeight = H / 3 + 1;
	S1 = upperHeight * W;
	S2 = (H - upperHeight) * leftWidth;
	S3 = (H - upperHeight) * (W - leftWidth);
	case2 = maxmin(S1, S2, S3);
	
	if(case1 < case2){
		return case1;
	}else{
		return case2;
	}
}

int rotatedT(int H, int W){
	return T(W, H);
}


int main(void) {
	// your code goes here
	int H, W;
	scanf("%d", &H);
	scanf("%d", &W);
	
	if(H % 3 == 0 || W % 3 == 0){
		printf("0\n");
	}else{
		int min = T(H, W);
		if(min > rotatedT(H, W)){
			min = rotatedT(H, W);
		}
		if(min > H){
			min = H;
		}
		if(min > W){
			min = W;
		}
		printf("%d\n", min);
	}
	return 0;
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

const int dy[8]={1,1,1,0,-1,-1,-1,0};
const int dx[8]={1,0,-1,-1,-1,0,1,1};
int main(){
    ll h,w; cin>>h>>w;
    vector<vector<char>>a(h,vector<char>(w));
    rep(i,h){
        rep(j,w)cin>>a[i][j];
    }
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#')continue;
            ll cnt=0;
            rep(k,8){
                if(i+dy[k]<0||i+dy[k]>=h)continue;
                else if(j+dx[k]<0||j+dx[k]>=w)continue;
                if(a[i+dy[k]][j+dx[k]]=='#')cnt++;
            }
            char c='0'+cnt;
            a[i][j]=c;
        }
    }
    rep(i,h){
        rep(j,w){
            cout<<a[i][j];
        }
        cout<<endl;
    }
}


























































































Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String line = br.readLine();
			String[] input = line.split(" ", 0);

			int N = Integer.parseInt(input[0]);
			int A = Integer.parseInt(input[1]);
			int B = Integer.parseInt(input[2]);

			int mn = 0;
			if (A + B > N) {
				mn = (A + B) - N;
			}
			int mx = Math.min(A, B);
			
			System.out.println(mx + " " + mn);

		} catch (Exception exp) {
			exp.printStackTrace();
		}
	}
}

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

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

    int N = 0;
    int remain = 0;
    while (L > 0)
    {
        remain += (L % 2) << N;
        N++;
        L /= 2;
    }
    // remain = L_init
    remain -= 1 << (N - 1);

    vector<vector<int>> edges;
    for (int i = 1; i < N; i++)
    {
        edges.push_back(vector<int>{i, i + 1, 0});
        edges.push_back(vector<int>{i, i + 1, 1 << (N - i - 1)});
    }

    bitset<32> b(remain);
    int w = 1 << (N - 1);
    for (int i = 25; i >= 0; i--)
    {
        if (b[i])
        {
            edges.push_back(vector<int>{1, N - i, w});
            w += 1 << i;
        }
    }

    cout << N << " " << edges.size() << endl;
    for (auto itr = edges.begin(); itr != edges.end(); itr++)
    {
        cout << (*itr)[0] << " " << (*itr)[1] << " " << (*itr)[2] << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>//
#include<cstdlib>//  8_A.cpp
#include<string>//
#include<iostream>//
using namespace std;//  Created by 杵鞭俊 on 2018/07/10.
struct node{
    int key;
    node *right,*left,*parent;
};

node *root,*NIL;

void insert(int k){
    node *y=NIL;
    node *x=root;
    node *z;
    z=(node *)malloc(sizeof(node));

    z->key=k;
    z->left=NIL;
    z->right=NIL;
    
    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        
        }else{
            x=x->right;
        }
        
    }
    z->parent=y;
    if(y==NIL){
        root=z;
    }else{
        if(z->key<y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}

void inorder(node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(node *u){
    if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}



int main(){
    int n,i,x;
    string com;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        cin >> com;
        if(com=="insert"){
            scanf("%d",&x);
            insert(x);
        }else if(com=="print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        
        
        }
    }
    return 0;
}



Measured memory_bytes: 26732
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
#include <fstream>
using namespace std;
#define MOD 1000000007 //10^9 + 7

//#define ReadFromFile Y
#define FileName "read.txt"

int main()
{
#ifdef ReadFromFile
    std::ifstream in(FileName);
    std::cin.rdbuf(in.rdbuf());
#endif
    long long int N, M;
    cin >> N >> M;
    long long int S[N + 1];
    long long int T[M + 1];
    vector<int> p;
    for (int i = 1; i <= N; i++)
    {
        cin >> S[i];
    }
    for (int j = 1; j <= M; j++)
    {
        cin >> T[j];
    }
    int sum[N + 1][M + 1];
    for (int i = 0; i <= N; i++)
    {
        sum[i][0] = 0;
    }
    for (int j = 0; j <= M; j++)
    {
        sum[0][j] = 0;
    }
    int dp[N + 1][M + 1];
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= M; j++)
        {
            if (S[i] == T[j])
            {
                dp[i][j] = sum[i - 1][j - 1] + 1;
            }
            else
            {
                dp[i][j] = 0;
            }
            sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % MOD;
        }
    }
    if (sum[N][M] + 1 < 0)
        cout << sum[N][M] + 1 + MOD << endl;
    else
        cout << sum[N][M] + 1 << endl;
    return 0;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast_I_O ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod = 1e9+7 , INF = 1e9 ,  mx = 100005 ;
main()
{
    fast_I_O;
    int i,j,n,m,x=INT_MAX,y,sum=0,p=0,l,k;
    string s,t;
    cin>>s>>t;
    n=s.length();
    m=t.length();
    for(i=0;i<n-m+1;i++)
    {
        l=0 , k=i;
        for(j=0;j<m;j++)
        {
            if(s[k]!=t[j]) ++l;
            ++k;
        }
        x=min(x,l);
    }
    cout<<x;
    return 0;
}

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

int n, m;
int bit[100001];

void add(int k, int x) {
	while (k <= m) {
		bit[k] += x;
		k += k &-k;
	}
}
int sum(int k) {
	int res = 0;
	while (k > 0) {
		res += bit[k];
		k -= k&-k;
	}
	return res;
}
int main() {
	scanf("%d%d", &n, &m);
	vector<P>v;
	rep(i, n) {
		int l, r; scanf("%d%d", &l, &r);
		v.push_back(P(r - l + 1, l));
	}
	sort(v.begin(), v.end());
	int s = 0;
	for (int i = 1; i <= m; i++) {
		while (s < v.size() && v[s].first < i) {
			add(v[s].second, 1); add(v[s].second + v[s].first, -1);
			s++;
		}
		int ans = n - s;
		for (int j = 0; j <= m; j += i)ans += sum(j);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 4464
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ans = 0
a = [None]*n
b = [None]*n

for i in range(n):
    a[i],b[i] = map(int, input().split())
for aa,bb in zip(a[::-1], b[::-1]):
    aa += ans
    ans += bb*(aa//bb + (aa%bb!=0)) - aa
#     print(ans)
print(ans)

Measured memory_bytes: 79920
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	S = input()
	S = S[:-1]
	ans = ""
	for i in S:
		ans += "x"
 
	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

int main(){
    int n;
    cin >> n;
    int d[101] = {0};
    rep(i, 0, n){
        int temp;
        cin >> temp;
        d[temp] = 1;
    }
    int ans = 0;
    rep(i, 0, 101){
        if(d[i] == 1) ans += 1;
    }
    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 REP(i, n) for(int i = 1; i <= n; i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

using namespace std;

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

/////////////////////////////////////////////////

string S;

void input()
{
    cin >> S;
}

void solve()
{
    int j;
    string day[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    rep(i, 7)
    {
        if(day[i] == S)
        {
            j = i;
        }
    }
    cout << 7-j << endl;
}

/////////////////////////////////////////////////

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

Measured memory_bytes: 256
from sys import stdin
import math as m
input = stdin.readline

r,c = map(int,input().split())

if r==1 or c==1:
  print("1")
else:
  total = m.ceil(c/2) * m.ceil(r/2) + m.floor(c/2)* m.floor(r/2)

  print(total)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll x, y, a;
  in2(x, y);
  vector<ll> c(1000009, 0), d(1000009, 0);
  rep(i, 1000009){
    while(x % (i + 2) == 0){
      x /= (i + 2);
      c[i]++;
    }
    while(y % (i + 2) == 0){
      y /= (i + 2);
      d[i]++;
    }
  }
  a = 1;
  rep(i, 1000009){
    if(c[i] != 0 && d[i] != 0)
      a++;
  }
  if(x == y && x != 1)
    a++;
  out(a);
  memi;
}


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

using namespace std;

long long LCM(int a , int b) {
    return a * 1ll * b / __gcd(a , b);
}

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

    int n , m;
    cin >> n >> m;

    long long lcm = 1;
    vector<int> a(n);
    for (int i = 0 ;i < n ;i++) {
        cin >> a[i];
        lcm = LCM(lcm , a[i] / 2);
    }

    for (int i = 0 ;i < n ;i++)
        if ((2 * lcm / a[i]) % 2 == 0)
            return cout << 0 , 0;

    int cnt = m / lcm;

    cout << (cnt + 1) / 2;
}

Measured memory_bytes: 640
# 2020/07/24
# AtCoder Beginner Contest 081 - B

# Input
n = int(input())
a = list(map(int,input().split()))

# Calc
tflg = True
ans = 0
while(tflg):
    ans = ans + 1
    for i in range(n):
        if a[i] % 2 == 1:
            ans = ans - 1
            tflg = False
            break
        else:
            a[i] = a[i] / 2

# Output
print(ans)


Measured memory_bytes: 9180
def powmod(b,r,mod)
  a = 1
  while r > 0
    if r%2 == 1
      a = a * b % mod
    end
    b = b * b % mod
    r /= 2
  end
  a
end

def invmod(f, mod)
  powmod(f, mod-2, mod)
end

require "prime"
N,*A = `dd`.split.map &:to_i
Mod = 10**9 + 7
qs = {}
PD = A.map{ |a|
  pd = a.prime_division
  pd.each{ |q,d| qs[q] = [qs[q] || 0, d].max }
  pd
}
LCM = qs.map{ |q,d| powmod(q,d,Mod) }.reduce(1){ |a,b| a * b % Mod }
p PD.reduce(0){ |a,pd|
  divisor = pd.map{ |q,d| powmod(q,d,Mod) }.reduce(1){ |a,b| a * b % Mod }
  (a + (LCM * invmod(divisor,Mod))) % Mod
}

Measured memory_bytes: 7816