akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>
#include <cctype>
#include <cassert>
using namespace std;
int parse();
size_t cur = 0; // 解析開始位置
string S;

char readchar() {
  assert(cur < S.size());
  char ret = S[cur];
  cur += 1;
  return ret;
  // return S[cur++]; と一行で書くこともできる
}
char peek() { // 1 文字読むが cur を進めない
  assert(cur < S.size());
  return S[cur];
}

int digit() {
  assert(isdigit(peek())); // S[cur] が数字であることを確認
  int n = readchar() - '0'; // ’0’ を 0 に変換
  return n;
}

int number() {
  int n = digit();
  while (cur < S.size() && isdigit(peek())) // 次も数字か 1 文字先読
    n = n*10 + digit();
  return n;
}

int factor();
int term() {
  int a = factor();
  while (cur < S.size() && peek() != ')' && (peek() == '*' || peek() == '/')) {
    char op = readchar();
    int b = factor();
    if (op == '*') a *= b; else a /= b;
  }
  return a;
}

int expression(); // 前方宣言
int factor() {
  if (peek() != '(') return number();
  cur += 1;
  int n = expression();
  assert(peek() == ')');
  cur += 1;
  return n;
}

int expression() {
  int a = term();
  while (cur < S.size() && (peek() == '+' || peek() == '-')) { // 足し算か引き算が続く間
    char op = readchar();
    int b = term();
    if (op == '+') {
      a += b;
    }
    else
    {
      a -= b;
    }
  }
  return a;
}



int parse() { return expression(); }
int main() {
  int N;
  cin >> N;
  for (int i=0; i<N; ++i) {
    cur = 0;
    cin >> S;
    S.resize(S.size()-1); // 最後の=を無視
  cout << expression() << endl;
  }
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


const ll mod = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N;
    cin >> N;
    vector<string> G(2);
    REP(i, 2) cin >> G[i];

    ll ret = (G[0][0] == G[1][0]) ? 3 : 6;
    for (int i = 1; i < N; i++) {
        if (G[0][i] == G[0][i - 1]) continue;
        if (G[0][i] == G[1][i]) {
            if (G[0][i - 1] == G[1][i - 1]) {
                ret = (ret * 2) % mod;
            }
        } else {
            if (G[0][i - 1] != G[1][i - 1]) {
                ret = (ret * 3) % mod;
            } else {
                ret = (ret * 2) % mod;
            }
        }

    }
    cout << ret << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

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

    vector<ll> a(n+1,0);
    for(int i = 1; i < n+1; i++){
        cin >> a[i];
    }

    vector<ll> oddf(n+1,0),oddb(n+1,0);
    for(int i = 1; i < n+1; i++){
        oddf[i] = oddf[i-1];
        if(a[i]%2 == 1){
            oddf[i]++;
        }
    }
    oddb[n] = a[n]%2;
    for(int i = n-1; i >= 0; i--){
        oddb[i] = oddb[i+1] + a[i]%2;
    }

    vector<ll> even(n+1,0);
    for(int i = 1; i < n+1; i++){
        even[i] = even[i-1];
        if(a[i]%2 == 0){
            even[i]++;
        }
    }

    vector<ll> sum(n+1,0);
    for(int i = 1; i < n+1; i++){
        sum[i] = a[i] + sum[i-1];
    }

    vector<ll> zero(n+1,0);
    for(int i = 1; i < n+1; i++){
        zero[i] = zero[i-1];
        if(a[i] == 0){
            zero[i]++;
        }
    }

    priority_queue<ll,vector<ll>,greater<ll>> pq,bret;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> fret;

    for(int i = 1; i < n; i++){
        fret.push(make_pair(sum[i-1] + (zero[n] - zero[i-1])*2 + oddf[n] - oddf[i-1],(ll)i));
    }
    pq.push(even[n-1]);
    bret.push(zero[n]*2 + oddf[n]);
    ll ans = sum[n] - a[n];
    for(int i = n-1; i > 0; i--){
        while(fret.top().second > i){
            fret.pop();
        }
        ll t = pq.top() - even[i] + fret.top().first - (zero[n] - zero[i])*2 -(oddf[n] - oddf[i]);
        ll t2 = pq.top() - even[i] + sum[i-1];
        if(a[i] > 2 && a[i]%2 == 1){
            t--;
        }
        ans = min(ans,min(t2,t));
        bret.push(zero[i]*2 + oddf[i] + sum[n] - sum[i]);
        pq.push(even[i-1] + bret.top() - zero[i-1]*2 - oddf[i-1] - (a[i] > 2 && a[i]%2 == 1 ? 1 : 0));
        pq.push(sum[n] - sum[i] + even[i-1]);
    }

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

Measured memory_bytes: 23148
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string ss;
    cin>>ss;
    int ans = 1e8;
    for(char c = 'a';c<='z';c++){
        string s = ss;
        int ret = 0;
        bool pos = false;
        int n = s.size();
        bool same = true;
        for(int i=0;i<n;i++){
            if(s[i] == c)pos=1;
            else same = false;
        }
        if(same){
            cout << 0 << endl;
            return 0;
        }
        if(!pos)continue;
        while(true){
            string t;
            int n = s.size();
            int cnt = 0;
            for(int i=0;i<n-1;i++){
                if(s[i]==c||s[i+1]==c){
                    cnt++;
                    t+=c;
                }
                else t += '.';
            }
            ret++;
            if(cnt == n-1)break;
            swap(t,s);
        }
        chmin(ans,ret);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int R,G,B,N;cin>>R>>G>>B>>N;
    int ans=0;
    REP(i,N/R+1){
        REP(j,N/G+1){
            if(N-R*i-G*j>=0&&(N-R*i-G*j)%B==0)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        long answer = 0;
        if (K % 2 == 1) {
            long t = (long) N / K;
            answer = t * t * t;
        } else {
            long t = (long) N / K;
            long u = (long) (N + K / 2) / K;
            answer += t * t * t + u * u * u;
        }
        System.out.println(answer);
    }
}


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

int main()
{
    int n,k;
    char s[55];
    cin>>n>>k;
//    cin>>s;
    cin.ignore();
    cin.getline(s,55);
    s[k-1]=char((int)s[k-1]+32);
    cout<<s;
    return 0;
}


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

int main(void){
	int N;
	cin>>N;
	vector<int> T(N);
	vector<int> A(N);
	for(int i=0; i<N; ++i){
		cin>>T[i];
	}
	for(int i=0; i<N; ++i){
		cin>>A[i];
	}
	int result=1;
	//左端
	if(T[0]>A[0]){
		result=0;
		//cerr<<"mujun1"<<endl;
		goto owari;//矛盾
	}
	if(N==1){
		//cerr<<"N=1"<<endl;
		goto owari;
	}
	//中
	for(int i=1; i<N-1; ++i){
		//bool kimari=false;//その山の高さが確定しているか
		if(T[i]>T[i-1]){
			//kimari=true;
			if(T[i]>A[i]){
				result=0;
				//cerr<<"mujun2"<<endl;
				goto owari;
			}
			continue;
		}
		if(A[i]>A[i+1]){
			//kimari=true;
			if(A[i]>T[i]){
				result=0;
				//cerr<<"mujun3"<<endl;
				goto owari;
			}
			continue;
		}
		//確定しなかった場合
		int pat=min(T[i],A[i]);
		long long tmp = (long long)result*pat;
		result=(int)(tmp%1000000007);
		//cerr<<i<<" "<<result<<endl;
	}
	//右端
	if(A[N-1]>T[N-1]){
		result=0;
		//cerr<<"mujun4"<<endl;
		goto owari;//矛盾
	}
	
	owari: //抜けるときのラベル
	//cerr<<"owari"<<endl;
	cout<<result<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;int N,a,b,i,V[1<<20],f[1<<20];pair<int,int>R[1<<20];main(){cin>>N;for(;i<N;i++){cin>>a>>b;R[i]={a,a+b};}sort(R,R+N);V[N]=1;for(;i--;){for(a=i+1;a<N&&R[a].first<R[i].second;a=f[a]);V[i]=(V[i+1]+V[f[i]=a])%998244353;}cout<<*V;}

Measured memory_bytes: 5888
from math import ceil

n = int(input())
a = 1
b = 1

for i in range(n):
    s,t = map(int,input().split())
    #x = max([ceil(a/s), ceil(b/t)])
    x = max((a+s-1)//s, (b+t-1)//t)

    a = x*s
    b = x*t

print(a+b)

Measured memory_bytes: 3060
import sys
from collections import deque

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    visited = [[-1]*W for _ in range(H)] 
    q = deque([])
    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                visited[i][j] = 0
                q.append([i, j])
                
                dx_dy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
                while q:
                    nx, ny = q.popleft()
                    for k in range(4):
                        x, y = nx + dx_dy[k][0], ny + dx_dy[k][1]
                        if 0 <= x < H and 0 <= y < W and S[x][y] != '#' and visited[x][y] == -1:
                            visited[x][y] = visited[nx][ny] + 1
                            q.append([x, y])
                
                for l in range(H):
                    for m in range(W):
                        ans = max(ans, visited[l][m])
                
                q = deque([])
                visited = [[-1]*W for _ in range(H)] 
                
                
                
    
    print(ans)
                    
                
                
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int x,y;

		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		y = sc.nextInt();
		System.out.println((x*y) +" "+(x*2 + y*2));

		sc.close();
	}

}

Measured memory_bytes: 25944
import java.util.*;

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

		// 求める長方形の座標
		int x1 = 0;
		int x2 = w;
		int y1 = 0;
		int y2 = h;
		
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();
			
			if (a == 1) x1 = Math.max(x, x1);
			if (a == 2) x2 = Math.min(x, x2);
			if (a == 3) y1 = Math.max(y1, y);
			if (a == 4) y2 = Math.min(y2, y);
		}
		
		if (x2 > x1 && y2 > y1) {
			System.out.println((x2 - x1) * (y2 - y1));
		} else {
			System.out.println(0);
		}
		

		
	}
}

Measured memory_bytes: 21844
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

X,N = map(int,S().split())
p = LI()
p = sorted(p)

for i in range((N+1)//2+1):
    if not (X-i in p):
        print(X-i)
        exit()
    if not (X+i in p):
        print(X+i)
        exit()

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

using namespace std;

typedef pair<int,int> pi;

const int nax=1e5+1;

vector<int> edges[nax];
vector<int> in_degree(nax,0);
vector<int> dist(nax,0);
vector<int> vis(nax,0);

void bfs(int a)
{
    vis[a]=1;
    for(int i=0; i<edges[a].size(); i++)
    {
        int b = edges[a][i];
        dist[b] = max(dist[b],dist[a]+1);
        in_degree[b]--;
        if(in_degree[b]==0)
        {
            bfs(b);
        } 
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        edges[a].push_back(b);
        in_degree[b]++;
    }
    for(int i=1; i<=n; i++)
    {
        if(vis[i]==0&&in_degree[i]==0)
            bfs(i);
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        ans= max(ans,dist[i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 11520
n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(n-2):
    if p[i]<p[i+1] and p[i+1]<p[i+2]:
        c+=1
    elif p[i]>p[i+1] and p[i+1]>p[i+2]:
        c+=1
print(c)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

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

	string S;
	cin >> S;
	int n = S.length();
	ll sum = 0;
	REP(mask, 1 << (n - 1)) {
		ll tmp = S[0] - '0';
		REP(i, n - 1) {
			if (mask & (1 << i)) {
				// '+'をiとi+1の間に入れる
				sum += tmp;
				tmp = S[i + 1] - '0';
			}
			else {
				tmp = tmp * 10 + (S[i + 1] - '0');
			}
		}
		sum += tmp;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long

const int maxn=2e3+10;
const ll mod=1e9+7;

int maxv=2000;
ll f[maxn][maxn];
ll x[maxn],y[maxn];

ll mul(ll a,ll b)
{
    ll y=1;
    while (b)
    {
        if (b&1)
            y=y*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return y;
}

ll cal(ll a,ll b)
{
    if (a<0 || b<0 || a<b)
        return 0;

    if (b==0)
    {
        if (a==0)
            return 1;
        return 0;
    }
    else if (a==0)
        return 0;

    return f[a-1][b-1];
}

int main()
{
    ll n,k,i,j;
    scanf("%lld%lld",&n,&k);

    x[0]=1;
    for (i=1;i<=maxv;i++)
        x[i]=x[i-1]*i%mod;
    for (i=0;i<=maxv;i++)
        y[i]=mul(x[i],mod-2);

    for (i=0;i<=maxv;i++)
        for (j=0;j<=i;j++)
        {
            f[i][j]=x[i]*y[j]%mod*y[i-j]%mod;
//            if (f[i][j]<0)
//            {
//                printf("W\n");
//                return 0;
//            }
        }


    for (i=1;i<=k;i++)
    {
        printf("%lld\n",cal(k,i)* (( cal(n-k,i-1) + 2*cal(n-k,i) + cal(n-k,i+1) )%mod)%mod);
        ll z=cal(k,i)* (( cal(n-k,i-1) + 2*cal(n-k,i) + cal(n-k,i+1) )%mod)%mod;
        if (z<0)
            {
                printf("W\n");
                return 0;
            }
    }
    return 0;
}
/*
2000 2000
2000 1999
2000 1
*/


Measured memory_bytes: 30208
import java.util.Scanner;

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

    	/*Scanner = テキスト入力を扱うためのクラス
		 *キーボードからの入力を受けつける場合は
		 *System.inを使って下記のように記述
		 */
		Scanner scan = new Scanner(System.in);

		//forループ文用に変数準備
		int i;
		int j;

		/*while文で無限ループ設定
		 * if文でbreakをかける
		 */

		while(true){
			int H = scan.nextInt();
			int W = scan.nextInt();

		//Constraintsの条件も追加しました。
			if(H == 0 && W == 0 || H >= 300 || W >= 300)break;
			for(j = 0; j < H; j++){
				for(i = 0; i < W; i++){

					/*奇数偶数の条件分岐をさせている。
					 * 大元を大きいif関数でくくる。
					 */

					if(i%2==0){

						//iを2で割って余りが0(偶数行)の場合の表示
						if(j%2==0) System.out.print("#");
						else System.out.print(".");

					}
					else {

						//iを2で割って余りが0でない(奇数行)の場合の表示
						if(j%2==0) System.out.print(".");
	                    else System.out.print("#");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26976
n, d, a = gets.chomp.split.map(&:to_i)
monsters = []
n.times do |i|
  monsters.push(gets.chomp.split.map(&:to_i))
end
 
#ソート（ボトルネック）
monsters.sort!
 
ans = 0
sum = 0 # ダメージの累積値を貯めていく
dam_map = Array.new(n, 0)
 
#左端から攻撃していく
i = -1
n.times do |i|
  x, h = monsters[i]
  sum += dam_map[i]
  h -= sum
  #すでに死んでいればスキップ
  next if h <= 0
  atk = h / a
  if h % a == 0
    damage = h
    ans += atk
  else
    damage = (atk + 1) * a
    ans += atk + 1
  end
  
  #他のモンスターも範囲に入っていればダメージ
  reachable = x + d * 2
  sum += damage
  #攻撃範囲を超えるポイントでダメージを相殺
  upper_bound = monsters.bsearch_index {|m| m[0] > reachable }
  dam_map[upper_bound] -= damage if upper_bound
end
 
puts ans

Measured memory_bytes: 18960
#include <iostream>

using namespace std;

//convert a integer to h:m:s
int main()
{
    int time[3];

    int S;
    cin >> S;

    int weight = 3600;
    for (int i = 0; i < 3; i++)
    {
        time[i]= S / weight;
        S -= time[i] * weight;
        weight /= 60; 
    }

    for (int i = 0; i < 3; i++)
    {
        if (i) cout << ":";           
        cout << time[i];
    }
    cout << endl;

}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int BinarySearch(int S[], int n, int key) {
  int l = 0, r = n;
  while (l < r) {
    int m = (l + r) / 2;
    if (S[m] < key) {
      l = m + 1;
    } else if (S[m] > key) {
      r = m;
    } else {
      return 1;
    }
  }

  return 0;
}

int main() {
  int n, S[100000], q, T[50000];
  cin >> n;
  for (int i = 0; i < n; i++) { cin >> S[i]; }
  cin >> q;
  for (int i = 0; i < q; i++) { cin >> T[i]; }

  int ans = 0;
  for (int i = 0; i < q; i++) {
    ans += BinarySearch(S, n, T[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, H, W;
  cin >> N >> H >> W;
  int atmp, btmp;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    cin >> atmp >> btmp;
    if (atmp >= H && btmp >= W) ++cnt;
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
/*input
1 3
*/

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

#define Fi              first
#define Se              second
#define S(n)            cin >> n
#define P(n)            cout << n
#define pb              push_back
#define pp              pop_back
#define pf              pop_front
#define sp              cout << " "
#define nl              cout << "\n"
#define MIN(con)        (*min_element(ALL(con))) 
#define MAX(con)        (*max_element(ALL(con)))
#define mem(n, a)       memset((n), (a), sizeof(n))
#define ALL(cont)       (cont).begin(),(cont).end()
#define NX(cont)        next_permutation(ALL(cont))
#define PX(cont)        prev_permutation(ALL(cont))
#define F(i, n, r)      for(int i = (n); i < (r); i ++)
#define prec(n)         cout << fixed << setprecision(n)
#define PI              3.14159265358979323846264338327951
#define fast            ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FH(it,c)   for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++ it)
 
using ll = long long;
using ss = stringstream;
using ul = unsigned long long;
 
template < typename T > inline T LCM(T a, T b)            { return (a * b) / GCD(a, b); }
template < typename T > inline T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > inline T _max(T a, T b, T c)      { return max( max( a, b ), c ); }
template < typename T > inline T _min(T a, T b, T c)      { return min( min( a, b ), c ); }
template < typename T > inline string toString(T a)       {return to_string(a); }  // Convert int to string
template < typename T > inline void toInt(string s, T &x) { ss str(s); str >> x;}  // Convert string to int

inline void lower(string &s) { 
  FH(it,s) 
    *it = tolower(*it); 
} 
 
inline void upper(string &s) { 
  FH(it,s) 
    *it = toupper(*it); 
}

const ll inf    =  999999999999999999;

bool palin(string s)
{
    string s1 = s;
    reverse(s.begin(), s.end());
    return (s == s1);
} 

ll triangle(ll n)
{
    return (n * (n + 1)) / 2;
}

bool check(ll n) 
{
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;

    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}

int main ()
{
    fast;
    ll a, b;
    cin >> a >> b;
    if(a < 0 and b > 0 or a * b == 0) {
        cout << "Zero";
    }
    else if(a > 0 and b > 0) {
        cout << "Positive";
    }
    else if((abs(b) - abs(a) + 1) % 2 == 0) {
        cout << "Positive";
    }
    else {
        cout<< "Negative";
    }
    nl;
    return 0;
}



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

int dp[100010];
const int INF = 1 << 30;
int h[100010];

int main(){
    int N, K;
    cin >> N >> K;
    for(int i=0; i<N; ++i){
        cin >> h[i];
    }

    for(int i=0; i<100010; ++i){
        dp[i] = INF;
    }

    dp[0] = 0;

    for(int i=0; i<N; ++i){
        for(int j=1; j<=K; ++j){
            if(dp[i+j] > dp[i]+ abs(h[i+j]-h[i])){
                dp[i+j] = dp[i] + abs(h[i+j]-h[i]);
            }
        }
    }

    cout << dp[N-1] << endl;

    return 0;
}

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

ll gcd(ll a, ll b){
  if(b==0)return a;
  else gcd(b,a%b);
}
ll lcm(ll x,ll y){
  return x*y/gcd(x,y);
}


int main(){
 int N, X ,L;
  cin >> N >> X;
  int ans =0;
  for(int i=0;i<=N;i++){
    ans++;
    cin >> L;
    X-=L;
    if(X<0)break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def chmax(a, b) a > b ? a : b end

N = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

res = -1
N.times do |i|
  ((i+1)...N).each do |j|
    res = chmax((a[i] - a[j]).abs, res)
  end
end

puts res


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    map<int,int> m;
    int sum = 0;
    m[0]++;
    ll ans = 0;
    ll pow10 = 1;
    rrep(i,n) {
        sum += (s[i]-'0')*pow10;
        sum %= 2019;
        pow10 = pow10*10%2019;
        ans += m[sum];
        m[sum]++;
    }
    cout << ans << endl;
}


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

int main(){
  int cnt[12];
  int i;

  for(i = 0;i < 12;i++) cnt[i] = 0;

  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  cnt[a]++;
  cnt[b]++;
  cnt[c]++;

  if(cnt[5] == 2 && cnt[7] == 1) printf("YES\n");
  else printf("NO\n");
  
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=list(map(int,list(input())))
    for i in range(1,len(N)):
        if N[i]!=9:
            ans=N[0]-1+9*(len(N)-1)
            break
    else:
        ans=N[0]+9*(len(N)-1)
    print(ans)
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {

        public static int change(int money) {
            int cnt = 0;
            if (money >= 500) { money -= 500; cnt++; }
            if (money >= 100) { cnt += money / 100;  money %= 100; }
            if (money >= 50) { cnt += money / 50; money %= 50; }
            if (money >= 10) { cnt += money / 10; money %= 10; }
            if (money >= 5) { cnt += money / 5; money %= 5; }
            cnt += money;
            return cnt;
        }

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                Console.WriteLine(change(1000-n));


            }
        }

        
    }



    
}

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

#define cerr cout
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int N = 2e5 + 10;
int dps[N], a[N], pos[N];

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

	int n; cin >> n;
	ll prd = 1;
	dps[0] = 1;
	FOR (i, 1, n) {
		cin >> a[i];
		if (pos[a[i]] == 0) {
			dps[i] = dps[i-1];
		} else if (pos[a[i]] == i - 1) {
			dps[i] = dps[i - 1];
		} else {
			dps[i] = (dps[i - 1] + dps[pos[a[i]]]) % inf;
		}
		pos[a[i]] = i;
	}

	cout << dps[n] << "\n";
	
	return 0;
}

Measured memory_bytes: 2560
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

const lint MOD = 1e9 + 7;

lint rec(lint n){
    if(n == 1){
        return 1;
    }
    return (n * rec(n-1)) % MOD;
}

int main(){
    lint n, m;
    cin >> n >> m;
    lint ans = 0;
    if(n == m){
        ans = (((rec(n) * rec(m)) % MOD) * 2) % MOD;
    }else if(abs(n-m) == 1){
        ans = (rec(n) * rec(m)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  if (N & 1) {
    for (int i = 1; i <= M; i++) {
      cout << i << " " << N + 1 - i << endl;
    }
  } else {
    for (int i = 1, len = M & 1 ? M : M - 1; len >= 1; i++, len -= 2) {
      cout << i << " " << i + len << endl;
    }
    for (int i = N - 1, len = M & 1 ? M - 1 : M; len >= 2; i--, len -= 2) {
      cout << i << " " << i - len << endl;
    }
  }
  return 0;
}


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

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 100100;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int TestCases = 1; // cin >> TestCases;
    while(TestCases--){
      int n; cin >> n;
      std::vector<string> s(n + 1);
      std::vector<int> t(n + 1);
      for(int i = 1; i <= n; i++){
          cin >> s[i] >> t[i];
      }
      string x; cin >> x;
      int ans = 0;
      for(int i = 1; i <= n; i++){
         if(s[i] == x){
            for(int j = i + 1; j <= n; j++) ans += t[j];
            break;
         }
      }
      cout << ans << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


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

int main() {
  string N;
  cin >> N;
  
  if(N.at(0) == '7' || N.at(1) == '7' ||N.at(2) == '7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;

namespace Volumen0
{
    class Program
    {
        static void Main()
        {
            string line;
            var dict = new Dictionary<char, int>();
            dict.Add('I', 1);
            dict.Add('V', 5);
            dict.Add('X', 10);
            dict.Add('L', 50);
            dict.Add('C', 100);
            dict.Add('D', 500);
            dict.Add('M', 1000);
            while ((line = Console.ReadLine()) != null)
            {
                var table = line.ToCharArray().Select(x => dict[x]).ToArray();
                int sum = 0;
                for (int i = 0; i < line.Length; ++i)
                {
                    if (i < line.Length - 1 && table[i] < table[i + 1])
                    {
                        sum -= table[i];
                    }
                    else
                    {
                        sum += table[i];
                    }
                }
                Console.WriteLine(sum);
            }
        }
    }
}



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

int main() {
	unsigned long long int n,a,b,temp=0;
	cin>>n>>a>>b;
	if(a==0)
	cout<<"0";
	else
	{
	temp=(n/(a+b))*a;
	if(n%(a+b)>=a)
	cout<<temp+a;
	else
	cout<<temp+(n%(a+b));
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int n;
	 cin>>n;
	 vector<int> v(n);
	 for(int i=0;i<n;i++)
	 {
		 cin>>v[i];
	 }
	 sort(v.begin(),v.end(),greater<int>());
	 int p = 0;
	 int val = v[p];
	 ll ans=0;
	 int cnt=1;
	 for(int i=1;i<n;i++)
	 {
		 ans+=val;
		 cnt++;
		 
		 if(cnt==2)
		 {
			 val=v[++p];
			 cnt=0;
		 }
	 }
	 cout<<ans<<'\n';
	 
	 return 0;
}


Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;

int main() {
    int n;
    cin >> n;
    int t = 1;
    for(int i = 0, x; i < n; i++) {
        cin >> x;
        if(x != t) continue;
        t++;
    }
    if(t == 1) {
        cout << -1 << endl;
    } else {
        cout << n - t + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = [0]*10010

for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            v = x*x + y*y + z*z + x*y + y*z + z*x
            if v <= 10005:
                ans[v] += 1
for i in range(1, N+1):
    print(ans[i])

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

using namespace std;
using ll = long long;

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

    double theta = 0.0;
    if (x > a * a * b / 2) {
        theta = atan(2 * (a * a * b - x) / (a * a * a));
    } else {
        theta = atan((a * b * b) / (2 * x));
    }

    theta = theta * 180 / M_PI;
    cout << fixed << setprecision(10) << theta;

    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int bitpopcount(ll n) {
    int res = 0;
    while (n) {
        if (n & 1) res++;
        n >>= 1;
    }
    return res;
}

int main() {
    int n; cin >> n;
    vector<vector<int>> c(n, vector<int>(n, -1));
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++) {
            int x, y; cin >> x >> y;
            c[i][x - 1] = y;
        }
    }
    int ans = 0;
    for (int i = 1; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                bool f = false;
                for (int k = 0; k < n; k++) {
                    if (c[j][k] == 1) {
                        if ((i & (1 << k)) == 0) {
                            f = true;
                            break;
                        }
                    }
                    else if (c[j][k] == 0) {
                        if ((i & (1 << k)) != 0) {
                            f = true;
                            break;
                        }
                    }
                }
                if (f) break;
            }
            if (j == n - 1) {
                int t = bitpopcount(i);
                if (ans < t) {
                    ans = t;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main( void ) {

	int n, a[100], i, max = 0;

	for ( i = 0; i < 100; i++ ) { a[i] = 0; }

	while ( scanf( "%d", &n ) != EOF ) { a[n]++; }

	for ( i = 0; i < 100; i++ ) { if ( a[i] > max ) { max = a[i]; } }

	for ( i = 0; i < 100; i++ ) { if ( a[i] == max ) { printf( "%d\n", i ); } }

	return 0;

}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n,m;
vector<int> a[100010];
vector<pair<int,int> > edge;
int check[100010];
int main(){
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int x,y;
        cin >> x >> y;
        a[x].push_back(y);
        a[y].push_back(x);
        edge.push_back(make_pair(x,y));
    }
    queue<int> q;
    q.push(1);
    check[1] = 1;
    ll cnta = 1, cntb = 0;
    while(!q.empty()){
        int x = q.front();
        q.pop();
        for(int i=0;i<a[x].size();i++){
            int y = a[x][i];
            if(check[y] && (check[x]+1-check[y])%2){
                check[y] = 0;
                printf("%lld\n",(ll)n*(n-1)/2-(ll)m);
                return 0;
            }
            if(!check[y]){
                q.push(y);
                check[y] = check[x] + 1;
                if(check[y]%2) cnta++;
                else cntb++;
            }
        }
    }
    ll l = 0;
    for(int i=0;i<m;i++){
        int x = edge[i].first;
        int y = edge[i].second;
        if(!((check[x]-check[y])%2)) l++;
    }
    ll ans = (ll)n*(n-1)/2-cnta*(cnta-1)/2-cntb*(cntb-1)/2-m+l;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7028
#include<stdio.h>
#include<string.h>
int main()
{
  char s[300000],t[400000];
  int i,n;
  n=0;
  scanf("%s", &s);
  scanf("%s", &t);
  
  for (i=0;i<=strlen(s);i++)
  {
    if (s[i] != t[i]) 
    {
      n+=1;
    }
  }
    printf("%d",n);
    return 0;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

//拡張ユークリッドの互除法
int extgcd(int a, int b, int& x, int& y) {
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

// mod逆元
int mod_inverse(int a, int m) {
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}
// 階乗、階乗逆元テーブル
int fact[1100000], fact_inv[1100000], inv[1100000];
int mod_fact(int n, int m) {
    fact[0] = fact_inv[0] = 1;
    inv[1] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i % m;
        inv[i] = m - inv[m % i] * (m / i) % m;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % m;
    }
}

int N;
int A[110000];
int imos[110000];
int mod = 1e9 + 7;
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++)cin >> A[i];
    mod_fact(110000, mod);
    for (int i = 1; i < 110000; i++) {
        imos[i] = fact[N] * mod_inverse(i, mod) % mod;
    }
    for (int i = 2; i < 110000; i++)(imos[i] += imos[i - 1]) % mod;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        (ans += (imos[i + 1] - imos[1] + imos[N - i] + mod) % mod * A[i] % mod) %= mod;
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int res = A[0];
  for (int i = 1; i < N; i++)
    res = gcd(res, A[i]);
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
#include<fstream>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
struct edge { int to, cost; };

signed main() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0)cout << (a + b) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const int MAX_N = 1e5+1;

int main() {
  bool is_prime[MAX_N];
  fill(is_prime, is_prime + MAX_N, true);
  is_prime[0] = is_prime[1] = false;

  int count[MAX_N+1];
  count[0] = 0;
  rep(i, MAX_N) {
    if (is_prime[i]) {
      for (int j = i*2; j < MAX_N; j += i)
        is_prime[j] = false;
    }
  }
  rep(i, MAX_N) {
    count[i+1] = count[i] + ((is_prime[i] && is_prime[(i+1)/2]) ? 1 : 0);
  }
  cin.tie(0); ios::sync_with_stdio(false);
  int Q; in(Q);

  rep(i, Q) {
    int l; in(l);
    int r; in(r);
    out(count[r+1] - count[l]);
  }

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int r;
  cin >> r;
  if(r<1200)puts("ABC");
  else if(r<2800)puts("ARC");
  else puts("AGC");
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int w, h, n;
    cin >> w >> h >> n;
    int x_l = 0, x_r = w, y_l = 0, y_r = h;

    int x, y, a;
    rep(i, n) {
        cin >> x >> y >> a;
        if (a == 1) {
            x_l = max(x_l, x);
        }
        if (a == 2) {
            x_r = min(x_r, x);
        }

        if (a == 3) {
            y_l = max(y_l, y);
        }

        if (a == 4) {
            y_r = min(y_r, y);
        }
    }

    if (x_r - x_l <= 0 || y_r - y_l <= 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << (x_r - x_l) * (y_r - y_l) << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define modd               1e9+7
#define ff                 first
#define ss                 second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define rep(i,l,r)         for(int i=l;i<r;i++)
#define rer(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
using namespace std;
int32_t main(){

    int n;
    cin >> n;
    string a,b;
    cin >> a >> b;
    string ans;
    int cnt=0,i=0,j=0;
    while(i<n && j<n){
    	if(cnt%2==0){
    		ans.pb(a[i]);
    		i++;
    	}
    	else
    	{
    		ans.pb(b[j]);
    		j++;
    	}
      cnt++;
    }
    ans.pb(b[j]);
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
def resolve():
    '''
    code here

    '''
    import math

    N, M = [int(item) for item in input().split()]

    deff = N - M

    if deff == -1:
        N, M = M, N

    if deff == 0:
        temp = math.factorial(N)
        res = (temp**2 * 2) % (10**9+7)

    elif abs(deff) == 1:
        res = (math.factorial(N) **2 // N ) % (10**9+7)

    else:
        res = 0
    
    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 4748